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,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,49 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
# pysc.game['player'] = player # put player as a shared variable so other sprites can access it
|
6
|
+
|
7
|
+
|
8
|
+
def on_game_start():
|
9
|
+
|
10
|
+
player.set_rotation_style_left_right()
|
11
|
+
speed_decay = 0.9
|
12
|
+
speed_y = 0
|
13
|
+
speed_x = 0
|
14
|
+
|
15
|
+
while True:
|
16
|
+
max_speed = 4
|
17
|
+
|
18
|
+
|
19
|
+
if pysc.is_key_pressed('w'):
|
20
|
+
speed_y = -max_speed
|
21
|
+
|
22
|
+
elif pysc.is_key_pressed('s'):
|
23
|
+
speed_y = max_speed
|
24
|
+
|
25
|
+
else:
|
26
|
+
speed_y *= speed_decay # speed_y = speed_y * speed_decay
|
27
|
+
|
28
|
+
if pysc.is_key_pressed('a'):
|
29
|
+
player.direction = 180
|
30
|
+
speed_x = -max_speed
|
31
|
+
|
32
|
+
elif pysc.is_key_pressed('d'):
|
33
|
+
player.direction = 0
|
34
|
+
speed_x = max_speed
|
35
|
+
else:
|
36
|
+
speed_x *= speed_decay # speed_x = speed_y * speed_decay
|
37
|
+
|
38
|
+
|
39
|
+
player.y += speed_y
|
40
|
+
player.x += speed_x
|
41
|
+
|
42
|
+
yield 1/60
|
43
|
+
|
44
|
+
|
45
|
+
game_start_event = player.when_game_start()
|
46
|
+
game_start_event.add_handler(on_game_start)
|
47
|
+
|
48
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
49
|
+
|
@@ -0,0 +1,64 @@
|
|
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
|
+
# Event: when game started, clone creation
|
10
|
+
def enemy_on_game_start():
|
11
|
+
enemy.set_rotation_style_left_right()
|
12
|
+
enemy.hide() # hide the parent
|
13
|
+
|
14
|
+
# clone itself very 2 seconds
|
15
|
+
while True:
|
16
|
+
enemy.create_clone()
|
17
|
+
yield 2
|
18
|
+
|
19
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
20
|
+
|
21
|
+
|
22
|
+
# Event: when started as clone, clone location and movement
|
23
|
+
def on_clone(clone_sprite: pysc.Sprite):
|
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
|
+
clone_sprite.move_indir(2)
|
48
|
+
|
49
|
+
yield 1/60
|
50
|
+
|
51
|
+
enemy.when_started_as_clone().add_handler(on_clone)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# Event: when started as clone, moved by the ocean current
|
56
|
+
def ocean_current_movement(clone_sprite):
|
57
|
+
while True:
|
58
|
+
|
59
|
+
clone_sprite.x += pysc.game['current_x']
|
60
|
+
clone_sprite.y += pysc.game['current_y']
|
61
|
+
|
62
|
+
yield 1/60
|
63
|
+
|
64
|
+
enemy.when_started_as_clone().add_handler(ocean_current_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,80 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
# pysc.game['player'] = player # put player as a shared variable so other sprites can access it
|
6
|
+
|
7
|
+
# Event: game start, the movement of the player
|
8
|
+
def on_game_start():
|
9
|
+
|
10
|
+
player.set_rotation_style_left_right()
|
11
|
+
speed_decay = 0.9
|
12
|
+
speed_y = 0
|
13
|
+
speed_x = 0
|
14
|
+
|
15
|
+
while True:
|
16
|
+
max_speed = 4
|
17
|
+
|
18
|
+
|
19
|
+
if pysc.is_key_pressed('w'):
|
20
|
+
speed_y = -max_speed
|
21
|
+
|
22
|
+
elif pysc.is_key_pressed('s'):
|
23
|
+
speed_y = max_speed
|
24
|
+
|
25
|
+
else:
|
26
|
+
speed_y *= speed_decay # speed_y = speed_y * speed_decay
|
27
|
+
|
28
|
+
if pysc.is_key_pressed('a'):
|
29
|
+
player.direction = 180
|
30
|
+
speed_x = -max_speed
|
31
|
+
|
32
|
+
elif pysc.is_key_pressed('d'):
|
33
|
+
player.direction = 0
|
34
|
+
speed_x = max_speed
|
35
|
+
else:
|
36
|
+
speed_x *= speed_decay # speed_x = speed_y * speed_decay
|
37
|
+
|
38
|
+
|
39
|
+
player.y += speed_y
|
40
|
+
player.x += speed_x
|
41
|
+
|
42
|
+
yield 1/60
|
43
|
+
|
44
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
45
|
+
game_start_event = player.when_game_start()
|
46
|
+
game_start_event.add_handler(on_game_start)
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
# Event: game start, ocean current changes
|
51
|
+
pysc.game['current_x'] = 0
|
52
|
+
pysc.game['current_y'] = 0
|
53
|
+
|
54
|
+
def ocean_current_change():
|
55
|
+
# slowly change the current variables every 0.5 second
|
56
|
+
while True:
|
57
|
+
pysc.game['current_x'] += pysc.random_number(-0.1, 0.1)
|
58
|
+
pysc.game['current_y'] += pysc.random_number(-0.1, 0.1)
|
59
|
+
yield 0.5
|
60
|
+
|
61
|
+
pysc.game.when_game_start().add_handler(ocean_current_change)
|
62
|
+
|
63
|
+
# option 2: almost the same as above but the event will be removed when player is removed.
|
64
|
+
# player.when_game_start().add_handler(ocean_current_change)
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# Event: game start, moved by the ocean current
|
70
|
+
def ocean_current_movement():
|
71
|
+
while True:
|
72
|
+
|
73
|
+
# you can add these two lines inside the loop in the first event as well
|
74
|
+
# but for the code readabilty,
|
75
|
+
# it can be a good idea to put it out as a separate event.
|
76
|
+
player.x += pysc.game['current_x']
|
77
|
+
player.y += pysc.game['current_y']
|
78
|
+
yield 1/60
|
79
|
+
|
80
|
+
player.when_game_start().add_handler(ocean_current_movement)
|
@@ -0,0 +1,83 @@
|
|
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
|
+
|
12
|
+
# hide the parent
|
13
|
+
enemy.hide()
|
14
|
+
|
15
|
+
# the clone appear in the same location as the parent very briefly
|
16
|
+
# when it's created before we set it to a random location.
|
17
|
+
enemy.set_xy((-200, -200))
|
18
|
+
|
19
|
+
|
20
|
+
# clone itself very 2 seconds
|
21
|
+
while True:
|
22
|
+
enemy.create_clone()
|
23
|
+
yield 2
|
24
|
+
|
25
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
26
|
+
|
27
|
+
|
28
|
+
# clone movement
|
29
|
+
#def on_clone(clone_sprite):
|
30
|
+
def on_clone(clone_sprite: pysc.Sprite):
|
31
|
+
|
32
|
+
|
33
|
+
# random height
|
34
|
+
clone_sprite.y = pysc.random_number(0, 720)
|
35
|
+
|
36
|
+
# randomly either from the left or from the right
|
37
|
+
if pysc.random_number(0, 1) > 0.5:
|
38
|
+
clone_sprite.x = 0
|
39
|
+
clone_sprite.direction = 0 # left to right
|
40
|
+
else:
|
41
|
+
clone_sprite.x = 1280
|
42
|
+
clone_sprite.direction = 180 # right to left
|
43
|
+
|
44
|
+
# random size
|
45
|
+
size = pysc.random_number(0.3, 2)
|
46
|
+
clone_sprite.set_scale(size)
|
47
|
+
|
48
|
+
# show the sprite
|
49
|
+
clone_sprite.show()
|
50
|
+
|
51
|
+
|
52
|
+
#player = pysc.game['player']
|
53
|
+
player: pysc.Sprite = pysc.game['player']
|
54
|
+
|
55
|
+
# movement
|
56
|
+
while True:
|
57
|
+
|
58
|
+
if clone_sprite.distance_to_sprite(player) < 200:
|
59
|
+
clone_sprite.point_towards_sprite(player)
|
60
|
+
|
61
|
+
clone_sprite.direction += pysc.random_number(-2, 2)
|
62
|
+
|
63
|
+
clone_sprite.move_indir(2)
|
64
|
+
yield 1/60
|
65
|
+
|
66
|
+
enemy.when_started_as_clone().add_handler(on_clone)
|
67
|
+
|
68
|
+
|
69
|
+
# clone touch the player
|
70
|
+
#def clone_touch_the_player(clone_sprite):
|
71
|
+
def clone_touch_the_player(clone_sprite: pysc.Sprite):
|
72
|
+
|
73
|
+
player: pysc.Sprite = pysc.game['player']
|
74
|
+
while True:
|
75
|
+
if clone_sprite.is_touching(player):
|
76
|
+
clone_sprite.remove()
|
77
|
+
|
78
|
+
pysc.game['health'] -= 1
|
79
|
+
|
80
|
+
|
81
|
+
yield 1/pysc.game['framerate']
|
82
|
+
|
83
|
+
enemy.when_started_as_clone().add_handler(clone_touch_the_player)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
# create the sprites
|
4
|
+
heart1 = pysc.create_animated_sprite("assets/hearts")
|
5
|
+
heart2 = pysc.create_animated_sprite("assets/hearts")
|
6
|
+
heart3 = pysc.create_animated_sprite("assets/hearts")
|
7
|
+
|
8
|
+
# variable definitons should be done outside the event to guarantee the variables is defined before any event try to access it
|
9
|
+
pysc.game['health'] = 3
|
10
|
+
|
11
|
+
def heart_display():
|
12
|
+
|
13
|
+
heart1.set_xy((100, 100))
|
14
|
+
heart1.set_scale(3)
|
15
|
+
|
16
|
+
heart2.set_xy((155, 100))
|
17
|
+
heart2.set_scale(3)
|
18
|
+
|
19
|
+
heart3.set_xy((210, 100))
|
20
|
+
heart3.set_scale(3)
|
21
|
+
|
22
|
+
|
23
|
+
while True:
|
24
|
+
if pysc.game['health'] < 3:
|
25
|
+
heart3.set_frame(1)
|
26
|
+
|
27
|
+
if pysc.game['health'] < 2:
|
28
|
+
heart2.set_frame(1)
|
29
|
+
|
30
|
+
if pysc.game['health'] < 1:
|
31
|
+
heart1.set_frame(1)
|
32
|
+
|
33
|
+
yield 1/pysc.game['framerate']
|
34
|
+
|
35
|
+
# ideally, you should do
|
36
|
+
# `pysc.game.when_game_start([heart1, heart2, heart3])`, so when any of the hearts is removed, the event is removed as well.
|
37
|
+
# but we aren't going to remove any of the hearts, so there's no need to do so there.
|
38
|
+
|
39
|
+
pysc.game.when_game_start().add_handler(heart_display)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
from numpy import deg2rad
|
2
|
+
import pyscratch as pysc
|
3
|
+
import player, enemy, hearts
|
4
|
+
|
5
|
+
# backdrop
|
6
|
+
backdrop_img = pysc.load_image('assets/my_background.jpg') # load the image(s)
|
7
|
+
pysc.game.set_backdrops([backdrop_img]) # a list of all the backdrop images
|
8
|
+
pysc.game.switch_backdrop(0) # use the backdrop at index 0
|
9
|
+
|
10
|
+
|
11
|
+
# start the game
|
12
|
+
screen_height = 720
|
13
|
+
screen_width = 1280
|
14
|
+
framerate = 60
|
15
|
+
|
16
|
+
# add these to as shared variables so other sprites might use it
|
17
|
+
pysc.game['screen_height'] = screen_height
|
18
|
+
pysc.game['screen_width'] = screen_width
|
19
|
+
pysc.game['framerate'] = framerate
|
20
|
+
|
21
|
+
pysc.game.update_screen_mode((screen_width, screen_height))
|
22
|
+
pysc.game.start(framerate)
|
23
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
pysc.game['player'] = player # add the player as a shared variable so other sprites can access it
|
6
|
+
|
7
|
+
|
8
|
+
def on_game_start():
|
9
|
+
|
10
|
+
player.set_rotation_style_left_right()
|
11
|
+
speed_decay = 0.9
|
12
|
+
speed_y = 0
|
13
|
+
speed_x = 0
|
14
|
+
|
15
|
+
while True:
|
16
|
+
max_speed = 4
|
17
|
+
|
18
|
+
|
19
|
+
if pysc.is_key_pressed('w'):
|
20
|
+
speed_y = -max_speed
|
21
|
+
|
22
|
+
elif pysc.is_key_pressed('s'):
|
23
|
+
speed_y = max_speed
|
24
|
+
|
25
|
+
else:
|
26
|
+
speed_y *= speed_decay # speed_y = speed_y * speed_decay
|
27
|
+
|
28
|
+
if pysc.is_key_pressed('a'):
|
29
|
+
player.direction = 180
|
30
|
+
speed_x = -max_speed
|
31
|
+
|
32
|
+
elif pysc.is_key_pressed('d'):
|
33
|
+
player.direction = 0
|
34
|
+
speed_x = max_speed
|
35
|
+
else:
|
36
|
+
speed_x *= speed_decay # speed_x = speed_y * speed_decay
|
37
|
+
|
38
|
+
|
39
|
+
player.y += speed_y
|
40
|
+
player.x += speed_x
|
41
|
+
|
42
|
+
yield 1/60
|
43
|
+
|
44
|
+
|
45
|
+
game_start_event = player.when_game_start()
|
46
|
+
game_start_event.add_handler(on_game_start)
|
47
|
+
|
48
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
49
|
+
|
50
|
+
|
51
|
+
def check_health():
|
52
|
+
|
53
|
+
while True:
|
54
|
+
if not pysc.game['health']:
|
55
|
+
player.remove()
|
56
|
+
yield 1/60
|
57
|
+
|
58
|
+
|
59
|
+
game_start_event.add_handler(check_health)
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
# create the sprite and initial settings
|
5
|
+
enemy = pysc.create_animated_sprite("assets/other_fishes")
|
6
|
+
|
7
|
+
|
8
|
+
def enemy_on_game_start():
|
9
|
+
enemy.set_rotation_style_left_right()
|
10
|
+
|
11
|
+
# hide the parent
|
12
|
+
enemy.hide()
|
13
|
+
|
14
|
+
# the clone appear in the same location as the parent very briefly
|
15
|
+
# when it's created before we set it to a random location.
|
16
|
+
enemy.set_xy((-200, -200))
|
17
|
+
|
18
|
+
# clone itself very 2 seconds
|
19
|
+
while True:
|
20
|
+
enemy.create_clone()
|
21
|
+
yield 2
|
22
|
+
|
23
|
+
enemy.when_game_start().add_handler(enemy_on_game_start)
|
24
|
+
|
25
|
+
|
26
|
+
# clone movement
|
27
|
+
#def on_clone(clone_sprite):
|
28
|
+
def on_clone(clone_sprite: pysc.Sprite):
|
29
|
+
|
30
|
+
|
31
|
+
# random height
|
32
|
+
clone_sprite.y = pysc.random_number(0, 720)
|
33
|
+
|
34
|
+
# randomly either from the left or from the right
|
35
|
+
if pysc.random_number(0, 1) > 0.5:
|
36
|
+
clone_sprite.x = 0
|
37
|
+
clone_sprite.direction = 0 # left to right
|
38
|
+
else:
|
39
|
+
clone_sprite.x = 1280
|
40
|
+
clone_sprite.direction = 180 # right to left
|
41
|
+
|
42
|
+
# random size
|
43
|
+
size = pysc.random_number(0.3, 2)
|
44
|
+
clone_sprite.set_scale(size)
|
45
|
+
clone_sprite['size'] = size
|
46
|
+
|
47
|
+
# show the sprite
|
48
|
+
clone_sprite.show()
|
49
|
+
|
50
|
+
|
51
|
+
#player = pysc.game['player']
|
52
|
+
player: pysc.Sprite = pysc.game['player']
|
53
|
+
|
54
|
+
# movement
|
55
|
+
while True:
|
56
|
+
|
57
|
+
|
58
|
+
if player.sprite_data['size'] > size:
|
59
|
+
clone_sprite.set_frame(1)
|
60
|
+
else:
|
61
|
+
clone_sprite.set_frame(0)
|
62
|
+
|
63
|
+
|
64
|
+
if clone_sprite.distance_to_sprite(player) < 200:
|
65
|
+
clone_sprite.point_towards_sprite(player)
|
66
|
+
|
67
|
+
if player['size'] > size:
|
68
|
+
clone_sprite.direction += 180
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
clone_sprite.direction += pysc.random_number(-2, 2)
|
73
|
+
|
74
|
+
clone_sprite.move_indir(2/size)
|
75
|
+
yield 1/60
|
76
|
+
|
77
|
+
enemy.when_started_as_clone().add_handler(on_clone)
|
78
|
+
|
79
|
+
|
80
|
+
# clone touch the player
|
81
|
+
#def clone_touch_the_player(clone_sprite):
|
82
|
+
def clone_touch_the_player(clone_sprite: pysc.Sprite):
|
83
|
+
|
84
|
+
player: pysc.Sprite = pysc.game['player']
|
85
|
+
while True:
|
86
|
+
if clone_sprite.is_touching(player):
|
87
|
+
clone_sprite.remove()
|
88
|
+
|
89
|
+
if player['size'] > clone_sprite['size']:
|
90
|
+
player['size'] += 0.2
|
91
|
+
else:
|
92
|
+
player['size'] -= 0.2
|
93
|
+
pysc.game['health'] -= 1
|
94
|
+
|
95
|
+
|
96
|
+
yield 1/pysc.game['framerate']
|
97
|
+
|
98
|
+
enemy.when_started_as_clone().add_handler(clone_touch_the_player)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
# create the sprites
|
4
|
+
heart1 = pysc.create_animated_sprite("assets/hearts")
|
5
|
+
heart2 = pysc.create_animated_sprite("assets/hearts")
|
6
|
+
heart3 = pysc.create_animated_sprite("assets/hearts")
|
7
|
+
|
8
|
+
# variable definitons should be done outside the event to guarantee the variables is defined before any event try to access it
|
9
|
+
pysc.game['health'] = 3
|
10
|
+
|
11
|
+
def heart_display():
|
12
|
+
|
13
|
+
heart1.set_xy((100, 100))
|
14
|
+
heart1.set_scale(3)
|
15
|
+
|
16
|
+
heart2.set_xy((155, 100))
|
17
|
+
heart2.set_scale(3)
|
18
|
+
|
19
|
+
heart3.set_xy((210, 100))
|
20
|
+
heart3.set_scale(3)
|
21
|
+
|
22
|
+
|
23
|
+
while True:
|
24
|
+
if pysc.game['health'] < 3:
|
25
|
+
heart3.set_frame(1)
|
26
|
+
|
27
|
+
if pysc.game['health'] < 2:
|
28
|
+
heart2.set_frame(1)
|
29
|
+
|
30
|
+
if pysc.game['health'] < 1:
|
31
|
+
heart1.set_frame(1)
|
32
|
+
|
33
|
+
yield 1/pysc.game['framerate']
|
34
|
+
|
35
|
+
# ideally, you should do
|
36
|
+
# `pysc.game.when_game_start([heart1, heart2, heart3])`, so when any of the hearts is removed, the event is removed as well.
|
37
|
+
# but we aren't going to remove any of the hearts, so there's no need to do so there.
|
38
|
+
|
39
|
+
pysc.game.when_game_start().add_handler(heart_display)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player, enemy, hearts
|
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
|
+
# add these to as shared variables so other sprites might use it
|
16
|
+
pysc.game['screen_height'] = screen_height
|
17
|
+
pysc.game['screen_width'] = screen_width
|
18
|
+
pysc.game['framerate'] = framerate
|
19
|
+
|
20
|
+
pysc.game.update_screen_mode((screen_width, screen_height))
|
21
|
+
pysc.game.start(framerate)
|
22
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/player-fish.png")
|
5
|
+
pysc.game['player'] = player # add the player as a shared variable so other sprites can access it
|
6
|
+
|
7
|
+
player['size'] = 1
|
8
|
+
|
9
|
+
def on_game_start():
|
10
|
+
|
11
|
+
player.set_rotation_style_left_right()
|
12
|
+
speed_decay = 0.9
|
13
|
+
speed_y = 0
|
14
|
+
speed_x = 0
|
15
|
+
|
16
|
+
while True:
|
17
|
+
|
18
|
+
player.set_scale(player['size'])
|
19
|
+
|
20
|
+
max_speed = 4/player['size']
|
21
|
+
|
22
|
+
|
23
|
+
if pysc.is_key_pressed('w'):
|
24
|
+
speed_y = -max_speed
|
25
|
+
|
26
|
+
elif pysc.is_key_pressed('s'):
|
27
|
+
speed_y = max_speed
|
28
|
+
|
29
|
+
else:
|
30
|
+
speed_y *= speed_decay # speed_y = speed_y * speed_decay
|
31
|
+
|
32
|
+
if pysc.is_key_pressed('a'):
|
33
|
+
player.direction = 180
|
34
|
+
speed_x = -max_speed
|
35
|
+
|
36
|
+
elif pysc.is_key_pressed('d'):
|
37
|
+
player.direction = 0
|
38
|
+
speed_x = max_speed
|
39
|
+
else:
|
40
|
+
speed_x *= speed_decay # speed_x = speed_y * speed_decay
|
41
|
+
|
42
|
+
|
43
|
+
player.y += speed_y
|
44
|
+
player.x += speed_x
|
45
|
+
|
46
|
+
yield 1/60
|
47
|
+
|
48
|
+
|
49
|
+
game_start_event = player.when_game_start()
|
50
|
+
game_start_event.add_handler(on_game_start)
|
51
|
+
|
52
|
+
# or shorter: player.when_game_start().add_handler(on_game_start)
|
53
|
+
|
54
|
+
|
55
|
+
def check_health():
|
56
|
+
|
57
|
+
while True:
|
58
|
+
if not pysc.game['health']:
|
59
|
+
player.remove()
|
60
|
+
yield 1/60
|
61
|
+
|
62
|
+
|
63
|
+
game_start_event.add_handler(check_health)
|