pyscratch-pysc 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- assets/bullet_hell/enemy.py +130 -0
- assets/bullet_hell/enemy_bullets.py +230 -0
- assets/bullet_hell/main.py +11 -0
- assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- assets/bullet_hell/old_verisons/enemy.py +226 -0
- assets/bullet_hell/old_verisons/game_start.py +6 -0
- assets/bullet_hell/old_verisons/main.py +50 -0
- assets/bullet_hell/old_verisons/player.py +76 -0
- assets/bullet_hell/player.py +89 -0
- assets/bullet_hell/player_bullets.py +34 -0
- assets/bullet_hell/setting.py +33 -0
- examples/animated_sprite/main.py +7 -0
- examples/animated_sprite/my_sprite.py +79 -0
- examples/bullet_hell/enemy.py +152 -0
- examples/bullet_hell/enemy_bullet.py +88 -0
- examples/bullet_hell/main.py +17 -0
- examples/bullet_hell/player.py +39 -0
- examples/bullet_hell/player_bullet.py +31 -0
- examples/doodle_jump/main.py +9 -0
- examples/doodle_jump/platforms.py +51 -0
- examples/doodle_jump/player.py +52 -0
- examples/fish/assets/bullet_hell/enemy.py +130 -0
- examples/fish/assets/bullet_hell/enemy_bullets.py +230 -0
- examples/fish/assets/bullet_hell/main.py +11 -0
- examples/fish/assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- examples/fish/assets/bullet_hell/old_verisons/enemy.py +226 -0
- examples/fish/assets/bullet_hell/old_verisons/game_start.py +6 -0
- examples/fish/assets/bullet_hell/old_verisons/main.py +50 -0
- examples/fish/assets/bullet_hell/old_verisons/player.py +76 -0
- examples/fish/assets/bullet_hell/player.py +89 -0
- examples/fish/assets/bullet_hell/player_bullets.py +34 -0
- examples/fish/assets/bullet_hell/setting.py +33 -0
- examples/fish/fish.py +67 -0
- examples/fish/main.py +4 -0
- examples/getting-started/step 1 - create a sprite/main.py +11 -0
- examples/getting-started/step 1 - create a sprite/player.py +5 -0
- examples/getting-started/step 2 - control a sprite/main.py +11 -0
- examples/getting-started/step 2 - control a sprite/player.py +42 -0
- examples/getting-started/step 3 - backdrops/main.py +17 -0
- examples/getting-started/step 3 - backdrops/player.py +33 -0
- examples/getting-started/step 4 - clone a sprite/enemy.py +53 -0
- examples/getting-started/step 4 - clone a sprite/main.py +17 -0
- examples/getting-started/step 4 - clone a sprite/player.py +32 -0
- examples/getting-started/step 4 - clone a sprite (simple)/enemy.py +42 -0
- examples/getting-started/step 4 - clone a sprite (simple)/main.py +17 -0
- examples/getting-started/step 4 - clone a sprite (simple)/player.py +32 -0
- examples/getting-started/step 5 - local variables/enemy.py +52 -0
- examples/getting-started/step 5 - local variables/main.py +17 -0
- examples/getting-started/step 5 - local variables/player.py +49 -0
- examples/getting-started/step 6 - shared variables/enemy.py +64 -0
- examples/getting-started/step 6 - shared variables/main.py +17 -0
- examples/getting-started/step 6 - shared variables/player.py +80 -0
- examples/getting-started/step 7 - Referencing other sprites/enemy.py +83 -0
- examples/getting-started/step 7 - Referencing other sprites/hearts.py +39 -0
- examples/getting-started/step 7 - Referencing other sprites/main.py +23 -0
- examples/getting-started/step 7 - Referencing other sprites/player.py +59 -0
- examples/getting-started/step 8 - sprite variables/enemy.py +98 -0
- examples/getting-started/step 8 - sprite variables/hearts.py +39 -0
- examples/getting-started/step 8 - sprite variables/main.py +22 -0
- examples/getting-started/step 8 - sprite variables/player.py +63 -0
- examples/getting-started/step 9 - messages/enemy.py +98 -0
- examples/getting-started/step 9 - messages/hearts.py +39 -0
- examples/getting-started/step 9 - messages/main.py +23 -0
- examples/getting-started/step 9 - messages/player.py +78 -0
- examples/perspective_background/main.py +14 -0
- examples/perspective_background/player.py +52 -0
- examples/perspective_background/trees.py +39 -0
- examples/simple_pong/ball.py +72 -0
- examples/simple_pong/left_paddle.py +36 -0
- examples/simple_pong/main.py +21 -0
- examples/simple_pong/right_paddle.py +37 -0
- examples/simple_pong/score_display.py +54 -0
- pyscratch/__init__.py +48 -0
- pyscratch/event.py +263 -0
- pyscratch/game_module.py +1589 -0
- pyscratch/helper.py +561 -0
- pyscratch/sprite.py +1920 -0
- pyscratch/tools/sprite_preview/left_panel/frame_preview_card.py +238 -0
- pyscratch/tools/sprite_preview/left_panel/frame_preview_panel.py +42 -0
- pyscratch/tools/sprite_preview/main.py +18 -0
- pyscratch/tools/sprite_preview/main_panel/animation_display.py +77 -0
- pyscratch/tools/sprite_preview/main_panel/frame_bin.py +33 -0
- pyscratch/tools/sprite_preview/main_panel/play_edit_ui.py +64 -0
- pyscratch/tools/sprite_preview/main_panel/set_as_sprite_folder.py +22 -0
- pyscratch/tools/sprite_preview/main_panel/sprite_edit_ui.py +174 -0
- pyscratch/tools/sprite_preview/main_panel/warning_message.py +25 -0
- pyscratch/tools/sprite_preview/right_panel/back_button.py +35 -0
- pyscratch/tools/sprite_preview/right_panel/cut_button.py +32 -0
- pyscratch/tools/sprite_preview/right_panel/cut_parameter_fitting.py +152 -0
- pyscratch/tools/sprite_preview/right_panel/cut_parameters.py +42 -0
- pyscratch/tools/sprite_preview/right_panel/file_display.py +84 -0
- pyscratch/tools/sprite_preview/right_panel/file_display_area.py +57 -0
- pyscratch/tools/sprite_preview/right_panel/spritesheet_view.py +262 -0
- pyscratch/tools/sprite_preview/right_panel/ss_select_corner.py +208 -0
- pyscratch/tools/sprite_preview/settings.py +14 -0
- pyscratch/tools/sprite_preview/utils/input_box.py +235 -0
- pyscratch/tools/sprite_preview/utils/render_wrapped_file_name.py +86 -0
- pyscratch_pysc-1.0.3.dist-info/METADATA +37 -0
- pyscratch_pysc-1.0.3.dist-info/RECORD +101 -0
- pyscratch_pysc-1.0.3.dist-info/WHEEL +5 -0
- pyscratch_pysc-1.0.3.dist-info/top_level.txt +3 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
import random
|
2
|
+
import re, sys
|
3
|
+
import numpy as np
|
4
|
+
import pymunk
|
5
|
+
from pyscratch import game
|
6
|
+
from pyscratch.sprite import Sprite, create_rect, create_rect_sprite
|
7
|
+
from pyscratch.helper import _get_frame_dict
|
8
|
+
from pyscratch.game_module import Game
|
9
|
+
from main import *
|
10
|
+
from enemy import *
|
11
|
+
|
12
|
+
def game_start(data):
|
13
|
+
|
14
|
+
player = create_rect_sprite((0, 0, 255), 50, 30, pos=(720//2, 1200))
|
15
|
+
game._add_sprite(player)
|
16
|
+
game.create_edges()
|
17
|
+
player.set_collision_type(PLAYER_TYPE)
|
18
|
+
|
19
|
+
|
20
|
+
healthbar_red = create_rect((255, 0, 0), 60, 50)
|
21
|
+
|
22
|
+
healthbar_empty = create_rect_sprite((255, 255, 255), 60, 5, pos=(0,0))
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
game.shared_data['player'] = player
|
27
|
+
game.shared_data['inaccuracy'] = 5
|
28
|
+
|
29
|
+
player.sprite_data['health'] = 10
|
30
|
+
|
31
|
+
|
32
|
+
game._add_sprite(healthbar_empty)
|
33
|
+
healthbar_empty.lock_to(player, (0,-30))
|
34
|
+
healthbar_empty.blit(healthbar_red, (0,0))
|
35
|
+
|
36
|
+
|
37
|
+
#game.create_timer_trigger(100, 20).on_reset(lambda x: create_bullet_move_sine((355, 1), 0))
|
38
|
+
game.when_timer_reset(100, 20).on_reset(lambda x: create_bullet_attracted((355, 300)))
|
39
|
+
#game.create_timer_trigger(100, 100).on_reset(lambda x: create_bullet_type1((100, 100), 90))
|
40
|
+
|
41
|
+
#game.create_timer_trigger(100, 10)
|
42
|
+
|
43
|
+
#game.create_timer_trigger(1200).on_reset(lambda x: shoot_player_bullet((player.x, player.y), game.shared_data['inaccuracy']))
|
44
|
+
#game.create_timer_trigger(500, 30).on_reset(lambda x: create_enemy_type1((random.random()*WIDTH, 0)))
|
45
|
+
|
46
|
+
|
47
|
+
def run_forever(_):
|
48
|
+
if game.is_key_pressed(['w']):
|
49
|
+
player.move_xy((0, -5))
|
50
|
+
|
51
|
+
if game.is_key_pressed(['s']):
|
52
|
+
player.move_xy((0, 5))
|
53
|
+
|
54
|
+
if game.is_key_pressed(['a']):
|
55
|
+
player.move_xy((-5, 0))
|
56
|
+
|
57
|
+
if game.is_key_pressed(['d']):
|
58
|
+
player.move_xy((5, 0))
|
59
|
+
|
60
|
+
player.set_xy((cap(player.x, 50, WIDTH-50), cap(player.y, HEIGHT-500, HEIGHT)))
|
61
|
+
|
62
|
+
|
63
|
+
def on_health_change(change):
|
64
|
+
player.sprite_data['health'] += change
|
65
|
+
new_health = max(0, player.sprite_data['health'])
|
66
|
+
|
67
|
+
healthbar_red = create_rect((255, 0, 0), 60*(new_health/10), 50)
|
68
|
+
healthbar_empty.blit(healthbar_red)
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
game.when_timer_reset(1000/120).on_reset(run_forever)
|
73
|
+
game.when_receive_message('player_health').add_handler(on_health_change)
|
74
|
+
|
75
|
+
|
76
|
+
game.when_timer_reset(0.1, 1).on_reset(game_start)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from setting import *
|
3
|
+
|
4
|
+
|
5
|
+
def spawn_player(event_test=False):
|
6
|
+
|
7
|
+
...pyscratch# main sgame player = pysc.create_rect_sprite((0, 0, 255), 50, 30, pos=(720//2, 1200))
|
8
|
+
#pysc.game.add_sprite(player)
|
9
|
+
player.set_collision_type(PLAYER_TYPE)
|
10
|
+
|
11
|
+
|
12
|
+
# custom data
|
13
|
+
pysc.game.shared_data['player'] = player
|
14
|
+
pysc.game.shared_data['player_health'] = 10
|
15
|
+
pysc.game.shared_data['bullet_period_ms'] = 200
|
16
|
+
|
17
|
+
# behaviour
|
18
|
+
## 1. move by key press in a limited area
|
19
|
+
## 2. health changes on message
|
20
|
+
## 3. shoot bullet every n seconds (by messages)
|
21
|
+
|
22
|
+
## 1. movement
|
23
|
+
movement_event = pysc.game.when_timer_reset(1000/120)
|
24
|
+
def movement(_):
|
25
|
+
if game.is_key_pressed('w'):
|
26
|
+
player.move_xy((0, -5))
|
27
|
+
|
28
|
+
if game.is_key_pressed('s'):
|
29
|
+
player.move_xy((0, 5))
|
30
|
+
|
31
|
+
if game.is_key_pressed('a'):
|
32
|
+
player.move_xy((-5, 0))
|
33
|
+
|
34
|
+
if game.is_key_pressed('d'):
|
35
|
+
player.move_xy((5, 0))
|
36
|
+
|
37
|
+
player.set_xy((cap(player.x, 50, SCREEN_WIDTH-50), cap(player.y, SCREEN_HEIGHT-900, SCREEN_HEIGHT)))
|
38
|
+
|
39
|
+
movement_event.add_handler(movement)
|
40
|
+
|
41
|
+
|
42
|
+
## 2. health changes on message
|
43
|
+
health_change_event = pysc.game.when_receive_message('player_health')
|
44
|
+
|
45
|
+
def health_change(change):
|
46
|
+
pysc.game.shared_data['player_health'] += change
|
47
|
+
|
48
|
+
health_change_event.add_handler(health_change)
|
49
|
+
|
50
|
+
|
51
|
+
## 3. bullets
|
52
|
+
bullet_timer = pysc.Timer()
|
53
|
+
condition = lambda: (bullet_timer.read() > pysc.game.shared_data['bullet_period_ms'])
|
54
|
+
shoot_bullet_event = pysc.game.when_condition_met(condition)
|
55
|
+
|
56
|
+
def shoot_bullet(n):
|
57
|
+
pysc.game.broadcast_message('player_shoot_bullet', player)
|
58
|
+
bullet_timer.full_reset()
|
59
|
+
|
60
|
+
shoot_bullet_event.add_handler(shoot_bullet)
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
# health bar
|
65
|
+
healthbar_empty = pysc.create_rect_sprite((255, 255, 255), 60, 5, pos=(0,0))
|
66
|
+
#pysc.game.add_sprite(healthbar_empty)
|
67
|
+
healthbar_empty.lock_to(player, (0,-30))
|
68
|
+
|
69
|
+
## move the health bar
|
70
|
+
healthbar_red = pysc.create_rect((255, 0, 0), 60, 50)
|
71
|
+
healthbar_empty.blit(healthbar_red, (0,0))
|
72
|
+
|
73
|
+
# reusing the health_change_event defined about
|
74
|
+
def on_health_change(change):
|
75
|
+
new_health = max(0, pysc.game.shared_data['player_health'])
|
76
|
+
|
77
|
+
healthbar_red = pysc.create_rect((255, 0, 0), 60*(new_health/10), 50)
|
78
|
+
healthbar_empty.blit(healthbar_red)
|
79
|
+
|
80
|
+
health_change_event.add_handler(on_health_change)
|
81
|
+
|
82
|
+
if event_test:
|
83
|
+
shoot_bullet_event.remove()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
spawn_player(event_test=False)
|
89
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from setting import *
|
3
|
+
import random
|
4
|
+
|
5
|
+
def shoot_player_bullet(player):
|
6
|
+
|
7
|
+
bullet = pysc.Sprite(frames, "circle_bullets", player.body.position)
|
8
|
+
|
9
|
+
#pysc.game.add_sprite(bullet)
|
10
|
+
bullet.set_collision_type(PLAYER_BULLET_TYPE)
|
11
|
+
bullet.set_rotation(-90)
|
12
|
+
|
13
|
+
movement_timer = pysc.game.when_timer_reset(1000/240).add_handler(
|
14
|
+
lambda x: bullet.move_indir(2)
|
15
|
+
)
|
16
|
+
|
17
|
+
next_frame_timer = pysc.game.when_timer_reset(100).add_handler(
|
18
|
+
lambda x: bullet.next_frame()
|
19
|
+
)
|
20
|
+
|
21
|
+
|
22
|
+
def destroy_when_exit(x):
|
23
|
+
movement_timer.remove()
|
24
|
+
next_frame_timer.remove()
|
25
|
+
pysc.game._remove_sprite(bullet)
|
26
|
+
|
27
|
+
|
28
|
+
destroy_condition = pysc.game.when_condition_met(lambda: (bullet.y < 0), repeats=1)
|
29
|
+
destroy_condition.add_handler(destroy_when_exit)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
pysc.game.when_receive_message('player_shoot_bullet').add_handler(shoot_player_bullet)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import pygame
|
3
|
+
|
4
|
+
SCREEN_HEIGHT = 1280
|
5
|
+
SCREEN_WIDTH = 720
|
6
|
+
|
7
|
+
|
8
|
+
ENEMY_TYPE = 3
|
9
|
+
PLAYER_TYPE = 2
|
10
|
+
PLAYER_BULLET_TYPE = 4
|
11
|
+
EDGE_TYPE = 1
|
12
|
+
|
13
|
+
def cap(v, min_v, max_v):
|
14
|
+
return max(min(max_v, v), min_v)
|
15
|
+
|
16
|
+
sprite_sheet = pygame.image.load("assets/09493140a07b68502ef63ff423a6da3954d36fd8/Green Effect and Bullet 16x16.png").convert_alpha()
|
17
|
+
|
18
|
+
font = pygame.font.SysFont(None, 24) # None = default font, 48 = font size
|
19
|
+
|
20
|
+
frames = pysc.helper._get_frame_dict(sprite_sheet, 36, 13, {
|
21
|
+
"spin": [i+4*36 for i in range(14, 17+1)],
|
22
|
+
"star_explosion": [i+4*36 for i in range(19, 22+1)],
|
23
|
+
"heal": [i+1*36 for i in range(24, 28+1)],
|
24
|
+
"circle_explosion": [i+5*36 for i in range(14, 17+1)],
|
25
|
+
|
26
|
+
|
27
|
+
"square_bullets": [i+9*36 for i in range(24, 28+1)]+[i+9*36 for i in range(27, 24, -1)],
|
28
|
+
"circle_bullets": [i+8*36 for i in range(24, 28+1)]+[i+8*36 for i in range(27, 24, -1)],
|
29
|
+
|
30
|
+
"shield": [i+5*36 for i in [17]],
|
31
|
+
|
32
|
+
"bullet1": [i+3*36 for i in range(7, 7+1)]
|
33
|
+
})
|
examples/fish/fish.py
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch import game
|
3
|
+
|
4
|
+
def FishSprite():
|
5
|
+
sp = pysc.create_animated_sprite("assets/some_fishes")
|
6
|
+
|
7
|
+
def point_to_mouse():
|
8
|
+
|
9
|
+
sp.x = pysc.random_number(0, game.screen_width)
|
10
|
+
sp.y = pysc.random_number(0, game.screen_height)
|
11
|
+
|
12
|
+
while True:
|
13
|
+
yield 1/game.framerate
|
14
|
+
sp.point_towards_mouse()
|
15
|
+
sp.move_indir(5)
|
16
|
+
|
17
|
+
sp.when_game_start().add_handler(point_to_mouse)
|
18
|
+
|
19
|
+
return sp
|
20
|
+
|
21
|
+
n_fish = 20
|
22
|
+
fishes = []
|
23
|
+
for i in range(n_fish):
|
24
|
+
fishes.append(FishSprite())
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
from typing import List
|
29
|
+
import numpy as np
|
30
|
+
|
31
|
+
def get_dist(me: pysc.Sprite, others: List[pysc.Sprite]):
|
32
|
+
|
33
|
+
distances = [me.distance_to_sprite(another) if not me is another else np.inf for another in others ]
|
34
|
+
ind = np.argsort(distances)#[::-1]
|
35
|
+
|
36
|
+
ideal_dist = 200
|
37
|
+
max_speed = 5
|
38
|
+
|
39
|
+
div = ideal_dist/max_speed
|
40
|
+
for n in ind[:n_fish-1]:
|
41
|
+
n_nearest_other = others[n]
|
42
|
+
|
43
|
+
if me.x > n_nearest_other.x:
|
44
|
+
me.x += (ideal_dist - (me.x - n_nearest_other.x))/div
|
45
|
+
|
46
|
+
elif me.x < n_nearest_other.x:
|
47
|
+
me.x -= (ideal_dist - (n_nearest_other.x - me.x))/div
|
48
|
+
|
49
|
+
if me.y > n_nearest_other.y:
|
50
|
+
me.y += (ideal_dist - (me.y - n_nearest_other.y))/div
|
51
|
+
|
52
|
+
elif me.y < n_nearest_other.y:
|
53
|
+
me.y -= (ideal_dist - (n_nearest_other.y - me.y))/div
|
54
|
+
|
55
|
+
|
56
|
+
def keep_distance(_):
|
57
|
+
for f in fishes:
|
58
|
+
f.x = pysc.random_number(0, pysc.game.screen_width)
|
59
|
+
f.y = pysc.random_number(0, pysc.game.screen_height)
|
60
|
+
|
61
|
+
while True:
|
62
|
+
yield 1/pysc.game.framerate
|
63
|
+
for f in fishes:
|
64
|
+
get_dist(f, fishes)
|
65
|
+
|
66
|
+
temp_e = pysc.game.when_timer_above(0)
|
67
|
+
temp_e.add_handler(keep_distance)
|
examples/fish/main.py
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
|
6
|
+
# free to use any function name
|
7
|
+
def on_game_start():
|
8
|
+
|
9
|
+
player.set_rotation_style_left_right() # analogous to the motion block: 'set rotation style [left-right]'
|
10
|
+
while True:
|
11
|
+
if pysc.is_key_pressed('w'): # analogous to the sensing block: 'key [w] pressed'
|
12
|
+
player.y -= 4 # analogous to the motion block: change y by [-4]
|
13
|
+
|
14
|
+
if pysc.is_key_pressed('s'):
|
15
|
+
player.y += 4
|
16
|
+
|
17
|
+
if pysc.is_key_pressed('a'):
|
18
|
+
player.direction = 180 # analogous to the motion block: point in direction [180]
|
19
|
+
player.x -= 4
|
20
|
+
|
21
|
+
if pysc.is_key_pressed('d'):
|
22
|
+
player.direction = 0
|
23
|
+
player.x += 4
|
24
|
+
|
25
|
+
|
26
|
+
# this is analogous to the control block: wait [1/60] seconds
|
27
|
+
# because the frame rate is 60, this is basically to wait for one frame
|
28
|
+
yield 1/60
|
29
|
+
|
30
|
+
# unlike scratch, the wait here is necessary.
|
31
|
+
# Without waiting here, python will put everything aside
|
32
|
+
# to attempt to run the loop as quickly as possible and thus
|
33
|
+
# halt everything else in the program.
|
34
|
+
|
35
|
+
|
36
|
+
# passing the function to the event as the event handler
|
37
|
+
game_start_event = player.when_game_start()
|
38
|
+
game_start_event.add_handler(on_game_start)
|
39
|
+
|
40
|
+
# or shorter:
|
41
|
+
# player.when_game_start().add_handler(on_game_start)
|
42
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player
|
3
|
+
|
4
|
+
# backdrop
|
5
|
+
backdrop_img = pysc.load_image('assets/my_background.jpg') # load the image(s)
|
6
|
+
pysc.game.set_backdrops([backdrop_img]) # a list of all the backdrop images
|
7
|
+
pysc.game.switch_backdrop(0) # use the backdrop at index 0
|
8
|
+
|
9
|
+
|
10
|
+
# start the game
|
11
|
+
screen_height = 720
|
12
|
+
screen_width = 1280
|
13
|
+
framerate = 60
|
14
|
+
|
15
|
+
pysc.game.update_screen_mode((screen_width, screen_height))
|
16
|
+
pysc.game.start(framerate)
|
17
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
|
6
|
+
# free to use any function name
|
7
|
+
def on_game_start():
|
8
|
+
|
9
|
+
player.set_rotation_style_left_right()
|
10
|
+
while True:
|
11
|
+
if pysc.is_key_pressed('w'):
|
12
|
+
player.y -= 4
|
13
|
+
|
14
|
+
if pysc.is_key_pressed('s'):
|
15
|
+
player.y += 4
|
16
|
+
|
17
|
+
if pysc.is_key_pressed('a'):
|
18
|
+
player.direction = 180
|
19
|
+
player.x -= 4
|
20
|
+
|
21
|
+
if pysc.is_key_pressed('d'):
|
22
|
+
player.direction = 0
|
23
|
+
player.x += 4
|
24
|
+
|
25
|
+
yield 1/60 # because the frame rate is 60
|
26
|
+
|
27
|
+
|
28
|
+
game_start_event = player.when_game_start()
|
29
|
+
game_start_event.add_handler(on_game_start)
|
30
|
+
|
31
|
+
# or shorter:
|
32
|
+
# player.when_game_start().add_handler(on_game_start)
|
33
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
# create the sprite and initial settings
|
5
|
+
#enemy = pysc.create_animated_sprite("assets/other_fishes")
|
6
|
+
enemy = pysc.create_single_costume_sprite("assets/other_fishes/0.png")
|
7
|
+
|
8
|
+
|
9
|
+
def enemy_on_game_start():
|
10
|
+
enemy.set_rotation_style_left_right()
|
11
|
+
enemy.hide() # hide the parent
|
12
|
+
|
13
|
+
# clone itself very 2 seconds
|
14
|
+
while True:
|
15
|
+
enemy.create_clone()
|
16
|
+
yield 2
|
17
|
+
|
18
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
19
|
+
|
20
|
+
|
21
|
+
# clone movement
|
22
|
+
def on_clone(clone_sprite: pysc.Sprite):
|
23
|
+
screen_height = 720
|
24
|
+
|
25
|
+
# random height
|
26
|
+
clone_sprite.y = pysc.random_number(0, screen_height)
|
27
|
+
|
28
|
+
# randomly either from the left or from the right
|
29
|
+
if pysc.random_number(0, 1) > 0.5:
|
30
|
+
clone_sprite.x = 0
|
31
|
+
clone_sprite.direction = 0 # left to right
|
32
|
+
else:
|
33
|
+
clone_sprite.x = 1280
|
34
|
+
clone_sprite.direction = 180 # right to left
|
35
|
+
|
36
|
+
# random size
|
37
|
+
size = pysc.random_number(0.3, 2)
|
38
|
+
clone_sprite.set_scale(size)
|
39
|
+
|
40
|
+
# show the sprite
|
41
|
+
clone_sprite.show()
|
42
|
+
|
43
|
+
# movement
|
44
|
+
while True:
|
45
|
+
|
46
|
+
# slightly random direction
|
47
|
+
clone_sprite.direction += pysc.random_number(-2, 2)
|
48
|
+
|
49
|
+
clone_sprite.move_indir(2)
|
50
|
+
yield 1/60
|
51
|
+
|
52
|
+
enemy.when_started_as_clone().add_handler(on_clone)
|
53
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player, enemy
|
3
|
+
|
4
|
+
# backdrop
|
5
|
+
backdrop_img = pysc.load_image('assets/my_background.jpg') # load the image(s)
|
6
|
+
pysc.game.set_backdrops([backdrop_img]) # a list of all the backdrop images
|
7
|
+
pysc.game.switch_backdrop(0) # use the backdrop at index 0
|
8
|
+
|
9
|
+
|
10
|
+
# start the game
|
11
|
+
screen_height = 720
|
12
|
+
screen_width = 1280
|
13
|
+
framerate = 60
|
14
|
+
|
15
|
+
pysc.game.update_screen_mode((screen_width, screen_height))
|
16
|
+
pysc.game.start(framerate)
|
17
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
|
6
|
+
# free to use any function name
|
7
|
+
def on_game_start():
|
8
|
+
|
9
|
+
player.set_rotation_style_left_right()
|
10
|
+
while True:
|
11
|
+
if pysc.is_key_pressed('w'):
|
12
|
+
player.y -= 4
|
13
|
+
|
14
|
+
if pysc.is_key_pressed('s'):
|
15
|
+
player.y += 4
|
16
|
+
|
17
|
+
if pysc.is_key_pressed('a'):
|
18
|
+
player.direction = 180
|
19
|
+
player.x -= 4
|
20
|
+
|
21
|
+
if pysc.is_key_pressed('d'):
|
22
|
+
player.direction = 0
|
23
|
+
player.x += 4
|
24
|
+
|
25
|
+
yield 1/60 # because the frame rate is 60
|
26
|
+
|
27
|
+
|
28
|
+
game_start_event = player.when_game_start()
|
29
|
+
game_start_event.add_handler(on_game_start)
|
30
|
+
|
31
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
32
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
# create the sprite
|
5
|
+
enemy = pysc.create_single_costume_sprite("assets/other_fishes/0.png")
|
6
|
+
|
7
|
+
# Event: when_game_start, clone creation
|
8
|
+
def enemy_on_game_start():
|
9
|
+
enemy.set_rotation_style_left_right()
|
10
|
+
enemy.hide() # hide the parent
|
11
|
+
|
12
|
+
# clone itself very 2 seconds
|
13
|
+
while True:
|
14
|
+
enemy.create_clone()
|
15
|
+
yield 2
|
16
|
+
|
17
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
18
|
+
|
19
|
+
|
20
|
+
# Event: when_started_as_clone, clone movement
|
21
|
+
def clone_movement(clone_sprite):
|
22
|
+
|
23
|
+
screen_height = 720
|
24
|
+
|
25
|
+
# start the fish from the left edge at a random height
|
26
|
+
clone_sprite.y = pysc.random_number(0, screen_height)
|
27
|
+
clone_sprite.x = 0
|
28
|
+
|
29
|
+
# random size
|
30
|
+
size = pysc.random_number(0.8, 1.2)
|
31
|
+
clone_sprite.set_scale(size)
|
32
|
+
|
33
|
+
# show the clone
|
34
|
+
clone_sprite.show()
|
35
|
+
|
36
|
+
while True:
|
37
|
+
|
38
|
+
clone_sprite.move_indir(3)
|
39
|
+
|
40
|
+
yield 1/60
|
41
|
+
|
42
|
+
enemy.when_started_as_clone().add_handler(clone_movement)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player, enemy
|
3
|
+
|
4
|
+
# backdrop
|
5
|
+
backdrop_img = pysc.load_image('assets/my_background.jpg') # load the image(s)
|
6
|
+
pysc.game.set_backdrops([backdrop_img]) # a list of all the backdrop images
|
7
|
+
pysc.game.switch_backdrop(0) # use the backdrop at index 0
|
8
|
+
|
9
|
+
|
10
|
+
# start the game
|
11
|
+
screen_height = 720
|
12
|
+
screen_width = 1280
|
13
|
+
framerate = 60
|
14
|
+
|
15
|
+
pysc.game.update_screen_mode((screen_width, screen_height))
|
16
|
+
pysc.game.start(framerate)
|
17
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
|
6
|
+
# free to use any function name
|
7
|
+
def on_game_start():
|
8
|
+
|
9
|
+
player.set_rotation_style_left_right()
|
10
|
+
while True:
|
11
|
+
if pysc.is_key_pressed('w'):
|
12
|
+
player.y -= 4
|
13
|
+
|
14
|
+
if pysc.is_key_pressed('s'):
|
15
|
+
player.y += 4
|
16
|
+
|
17
|
+
if pysc.is_key_pressed('a'):
|
18
|
+
player.direction = 180
|
19
|
+
player.x -= 4
|
20
|
+
|
21
|
+
if pysc.is_key_pressed('d'):
|
22
|
+
player.direction = 0
|
23
|
+
player.x += 4
|
24
|
+
|
25
|
+
yield 1/60 # because the frame rate is 60
|
26
|
+
|
27
|
+
|
28
|
+
game_start_event = player.when_game_start()
|
29
|
+
game_start_event.add_handler(on_game_start)
|
30
|
+
|
31
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
32
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
# create the sprite and initial settings
|
5
|
+
#enemy = pysc.create_animated_sprite("assets/other_fishes")
|
6
|
+
enemy = pysc.create_single_costume_sprite("assets/other_fishes/0.png")
|
7
|
+
|
8
|
+
|
9
|
+
def enemy_on_game_start():
|
10
|
+
enemy.set_rotation_style_left_right()
|
11
|
+
enemy.hide() # hide the parent
|
12
|
+
|
13
|
+
# clone itself very 2 seconds
|
14
|
+
while True:
|
15
|
+
enemy.create_clone()
|
16
|
+
yield 2
|
17
|
+
|
18
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
19
|
+
|
20
|
+
|
21
|
+
# clone movement
|
22
|
+
def on_clone(clone_sprite: pysc.Sprite):
|
23
|
+
|
24
|
+
|
25
|
+
# random height
|
26
|
+
clone_sprite.y = pysc.random_number(0, 720)
|
27
|
+
|
28
|
+
# randomly either from the left or from the right
|
29
|
+
if pysc.random_number(0, 1) > 0.5:
|
30
|
+
clone_sprite.x = 0
|
31
|
+
clone_sprite.direction = 0 # left to right
|
32
|
+
else:
|
33
|
+
clone_sprite.x = 1280
|
34
|
+
clone_sprite.direction = 180 # right to left
|
35
|
+
|
36
|
+
# random size
|
37
|
+
size = pysc.random_number(0.3, 2)
|
38
|
+
clone_sprite.set_scale(size)
|
39
|
+
|
40
|
+
# show the sprite
|
41
|
+
clone_sprite.show()
|
42
|
+
|
43
|
+
# movement
|
44
|
+
while True:
|
45
|
+
|
46
|
+
clone_sprite.direction += pysc.random_number(-2, 2)
|
47
|
+
|
48
|
+
clone_sprite.move_indir(2)
|
49
|
+
yield 1/60
|
50
|
+
|
51
|
+
enemy.when_started_as_clone().add_handler(on_clone)
|
52
|
+
|