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.
Files changed (101) hide show
  1. assets/bullet_hell/enemy.py +130 -0
  2. assets/bullet_hell/enemy_bullets.py +230 -0
  3. assets/bullet_hell/main.py +11 -0
  4. assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
  5. assets/bullet_hell/old_verisons/enemy.py +226 -0
  6. assets/bullet_hell/old_verisons/game_start.py +6 -0
  7. assets/bullet_hell/old_verisons/main.py +50 -0
  8. assets/bullet_hell/old_verisons/player.py +76 -0
  9. assets/bullet_hell/player.py +89 -0
  10. assets/bullet_hell/player_bullets.py +34 -0
  11. assets/bullet_hell/setting.py +33 -0
  12. examples/animated_sprite/main.py +7 -0
  13. examples/animated_sprite/my_sprite.py +79 -0
  14. examples/bullet_hell/enemy.py +152 -0
  15. examples/bullet_hell/enemy_bullet.py +88 -0
  16. examples/bullet_hell/main.py +17 -0
  17. examples/bullet_hell/player.py +39 -0
  18. examples/bullet_hell/player_bullet.py +31 -0
  19. examples/doodle_jump/main.py +9 -0
  20. examples/doodle_jump/platforms.py +51 -0
  21. examples/doodle_jump/player.py +52 -0
  22. examples/fish/assets/bullet_hell/enemy.py +130 -0
  23. examples/fish/assets/bullet_hell/enemy_bullets.py +230 -0
  24. examples/fish/assets/bullet_hell/main.py +11 -0
  25. examples/fish/assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
  26. examples/fish/assets/bullet_hell/old_verisons/enemy.py +226 -0
  27. examples/fish/assets/bullet_hell/old_verisons/game_start.py +6 -0
  28. examples/fish/assets/bullet_hell/old_verisons/main.py +50 -0
  29. examples/fish/assets/bullet_hell/old_verisons/player.py +76 -0
  30. examples/fish/assets/bullet_hell/player.py +89 -0
  31. examples/fish/assets/bullet_hell/player_bullets.py +34 -0
  32. examples/fish/assets/bullet_hell/setting.py +33 -0
  33. examples/fish/fish.py +67 -0
  34. examples/fish/main.py +4 -0
  35. examples/getting-started/step 1 - create a sprite/main.py +11 -0
  36. examples/getting-started/step 1 - create a sprite/player.py +5 -0
  37. examples/getting-started/step 2 - control a sprite/main.py +11 -0
  38. examples/getting-started/step 2 - control a sprite/player.py +42 -0
  39. examples/getting-started/step 3 - backdrops/main.py +17 -0
  40. examples/getting-started/step 3 - backdrops/player.py +33 -0
  41. examples/getting-started/step 4 - clone a sprite/enemy.py +53 -0
  42. examples/getting-started/step 4 - clone a sprite/main.py +17 -0
  43. examples/getting-started/step 4 - clone a sprite/player.py +32 -0
  44. examples/getting-started/step 4 - clone a sprite (simple)/enemy.py +42 -0
  45. examples/getting-started/step 4 - clone a sprite (simple)/main.py +17 -0
  46. examples/getting-started/step 4 - clone a sprite (simple)/player.py +32 -0
  47. examples/getting-started/step 5 - local variables/enemy.py +52 -0
  48. examples/getting-started/step 5 - local variables/main.py +17 -0
  49. examples/getting-started/step 5 - local variables/player.py +49 -0
  50. examples/getting-started/step 6 - shared variables/enemy.py +64 -0
  51. examples/getting-started/step 6 - shared variables/main.py +17 -0
  52. examples/getting-started/step 6 - shared variables/player.py +80 -0
  53. examples/getting-started/step 7 - Referencing other sprites/enemy.py +83 -0
  54. examples/getting-started/step 7 - Referencing other sprites/hearts.py +39 -0
  55. examples/getting-started/step 7 - Referencing other sprites/main.py +23 -0
  56. examples/getting-started/step 7 - Referencing other sprites/player.py +59 -0
  57. examples/getting-started/step 8 - sprite variables/enemy.py +98 -0
  58. examples/getting-started/step 8 - sprite variables/hearts.py +39 -0
  59. examples/getting-started/step 8 - sprite variables/main.py +22 -0
  60. examples/getting-started/step 8 - sprite variables/player.py +63 -0
  61. examples/getting-started/step 9 - messages/enemy.py +98 -0
  62. examples/getting-started/step 9 - messages/hearts.py +39 -0
  63. examples/getting-started/step 9 - messages/main.py +23 -0
  64. examples/getting-started/step 9 - messages/player.py +78 -0
  65. examples/perspective_background/main.py +14 -0
  66. examples/perspective_background/player.py +52 -0
  67. examples/perspective_background/trees.py +39 -0
  68. examples/simple_pong/ball.py +72 -0
  69. examples/simple_pong/left_paddle.py +36 -0
  70. examples/simple_pong/main.py +21 -0
  71. examples/simple_pong/right_paddle.py +37 -0
  72. examples/simple_pong/score_display.py +54 -0
  73. pyscratch/__init__.py +48 -0
  74. pyscratch/event.py +263 -0
  75. pyscratch/game_module.py +1589 -0
  76. pyscratch/helper.py +561 -0
  77. pyscratch/sprite.py +1920 -0
  78. pyscratch/tools/sprite_preview/left_panel/frame_preview_card.py +238 -0
  79. pyscratch/tools/sprite_preview/left_panel/frame_preview_panel.py +42 -0
  80. pyscratch/tools/sprite_preview/main.py +18 -0
  81. pyscratch/tools/sprite_preview/main_panel/animation_display.py +77 -0
  82. pyscratch/tools/sprite_preview/main_panel/frame_bin.py +33 -0
  83. pyscratch/tools/sprite_preview/main_panel/play_edit_ui.py +64 -0
  84. pyscratch/tools/sprite_preview/main_panel/set_as_sprite_folder.py +22 -0
  85. pyscratch/tools/sprite_preview/main_panel/sprite_edit_ui.py +174 -0
  86. pyscratch/tools/sprite_preview/main_panel/warning_message.py +25 -0
  87. pyscratch/tools/sprite_preview/right_panel/back_button.py +35 -0
  88. pyscratch/tools/sprite_preview/right_panel/cut_button.py +32 -0
  89. pyscratch/tools/sprite_preview/right_panel/cut_parameter_fitting.py +152 -0
  90. pyscratch/tools/sprite_preview/right_panel/cut_parameters.py +42 -0
  91. pyscratch/tools/sprite_preview/right_panel/file_display.py +84 -0
  92. pyscratch/tools/sprite_preview/right_panel/file_display_area.py +57 -0
  93. pyscratch/tools/sprite_preview/right_panel/spritesheet_view.py +262 -0
  94. pyscratch/tools/sprite_preview/right_panel/ss_select_corner.py +208 -0
  95. pyscratch/tools/sprite_preview/settings.py +14 -0
  96. pyscratch/tools/sprite_preview/utils/input_box.py +235 -0
  97. pyscratch/tools/sprite_preview/utils/render_wrapped_file_name.py +86 -0
  98. pyscratch_pysc-1.0.3.dist-info/METADATA +37 -0
  99. pyscratch_pysc-1.0.3.dist-info/RECORD +101 -0
  100. pyscratch_pysc-1.0.3.dist-info/WHEEL +5 -0
  101. pyscratch_pysc-1.0.3.dist-info/top_level.txt +3 -0
@@ -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
+ pysc.game.broadcast_message('size_change', 0.2)
91
+ else:
92
+ pysc.game.broadcast_message('size_change', -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,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,78 @@
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)
64
+
65
+
66
+
67
+ def on_size_change(change):
68
+
69
+
70
+ each_step = change/10
71
+
72
+ for i in range(10):
73
+ player['size'] += each_step
74
+
75
+ yield 0.1
76
+
77
+ player.when_receive_message('size_change').add_handler(on_size_change)
78
+
@@ -0,0 +1,14 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+ import trees, player
4
+
5
+ sur = pysc.create_rect((169,234,126), 1280, 720)
6
+ sur_sky = pysc.create_rect((196,241,255), 1280, 200)
7
+ sur.blit(sur_sky, (0,0))
8
+
9
+ game.set_backdrops([sur])
10
+ game.switch_backdrop(0)
11
+
12
+ game.start(show_mouse_position=True, use_frame_time=True)
13
+ game.save_sprite_states()
14
+
@@ -0,0 +1,52 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+
5
+ sp = pysc.create_animated_sprite("assets/used_by_examples/perspective_background/the_red_guy_piskel")
6
+
7
+ def next_frame():
8
+ while True:
9
+ yield 0.2
10
+ sp.next_frame()
11
+ sp.when_game_start().add_handler(next_frame)
12
+
13
+ def on_game_start():
14
+ sp.x = 1280/2
15
+ sp.y = 720/2
16
+ sp.retrieve_saved_state()
17
+ sp.set_scale(3)
18
+ sp.set_draggable(True)
19
+
20
+ sp.set_rotation_style_left_right()
21
+ while True:
22
+
23
+ yield 1/game.framerate
24
+
25
+ is_running = False
26
+ if pysc.is_key_pressed('d'):
27
+ game['centre_x'] += 5
28
+ is_running = True
29
+ sp.direction=0
30
+
31
+ if pysc.is_key_pressed('a'):
32
+ game['centre_x'] -= 5
33
+ is_running = True
34
+ sp.direction=180
35
+
36
+ if pysc.is_key_pressed('w'):
37
+ game['centre_d'] += 5
38
+ is_running = True
39
+
40
+
41
+ if pysc.is_key_pressed('s'):
42
+ game['centre_d'] -= 5
43
+ is_running = True
44
+
45
+ if is_running:
46
+ sp.set_animation('run')
47
+ else:
48
+ sp.set_animation('idle')
49
+
50
+
51
+
52
+ sp.when_game_start().add_handler(on_game_start)
@@ -0,0 +1,39 @@
1
+ import numpy as np
2
+ import pyscratch as pysc
3
+ from pyscratch import game
4
+
5
+ game['centre_x'] = 1280/2
6
+ game['centre_h'] = 300
7
+ game['centre_d'] = 0
8
+ def tree_L():
9
+ sp = pysc.create_animated_sprite("assets/used_by_examples/perspective_background/tree_L")
10
+ sp['d'] = pysc.random_number(100, 2000)
11
+ sp['world_x'] = pysc.random_number(0, 1000)
12
+ sp.oob_limit=np.inf
13
+ def on_game_start():
14
+ sp.set_frame(int(pysc.random_number(0, 2.99)))
15
+ sp.set_draggable(True)
16
+ d = sp['d']-game['centre_d']
17
+ game.change_layer(sp, 1000-int(sp['d']))
18
+ while True:
19
+ yield 1/game.framerate
20
+ d = sp['d']-game['centre_d']
21
+
22
+ new_scale = pysc.cap(300/d, 0.1, 3)
23
+ if new_scale == 3:
24
+ sp.hide()
25
+ else:
26
+ sp.show()
27
+ sp.set_scale(new_scale)
28
+ if d <= 0:
29
+ sp.hide()
30
+
31
+ sp.y = -200+game.screen_height-np.arctan(d/game['centre_h'])/np.pi*game.screen_height
32
+ sp.x = ((sp['world_x']-game['centre_x'])/d + 0.5)*game.screen_width
33
+
34
+ sp.when_game_start().add_handler(on_game_start)
35
+
36
+ return sp
37
+
38
+ for i in range(50):
39
+ tree_L()
@@ -0,0 +1,72 @@
1
+ from numpy import True_
2
+ import pyscratch as pysc
3
+ from pyscratch import game
4
+
5
+ SCREEN_HEIGHT = 720
6
+ SCREEN_WIDTH = 1280
7
+
8
+ # TODO: recommend a colour picking website
9
+ ball_colour = (220, 220, 220)
10
+ ball_radius = 25
11
+ ball_sprite = pysc.create_circle_sprite(ball_colour, ball_radius, position = (SCREEN_WIDTH//2, SCREEN_HEIGHT//2))
12
+ game['ball_sprite'] = ball_sprite
13
+
14
+ top_edge, left_edge, bottom_edge, right_edge = pysc.create_edge_sprites(thickness=0)
15
+
16
+
17
+ def movement():
18
+ speed_x = 3
19
+ speed_y = 3
20
+ pong = False
21
+
22
+ while True:
23
+ yield .5/game.framerate # wait for half a frame (for smoothness)
24
+
25
+
26
+ if game['running']:
27
+
28
+ ball_sprite.show()
29
+ if ball_sprite.is_touching(top_edge):
30
+ pong = True
31
+ speed_y = abs(speed_y)
32
+
33
+ elif ball_sprite.is_touching(bottom_edge):
34
+ pong = True
35
+ speed_y = -abs(speed_y)
36
+
37
+ elif ball_sprite.is_touching(left_edge):
38
+ speed_x = abs(speed_x)
39
+ ball_sprite.broadcast_message('right_score')
40
+ game['running'] = False
41
+ pong = False
42
+
43
+ elif ball_sprite.is_touching(right_edge):
44
+ speed_x = -abs(speed_x)
45
+ ball_sprite.broadcast_message('left_score')
46
+ game['running'] = False
47
+ pong = False
48
+
49
+ elif ball_sprite.is_touching(game['right_paddle']):
50
+ pong = True
51
+ speed_x = -abs(speed_x)
52
+
53
+ elif ball_sprite.is_touching(game['left_paddle']):
54
+ pong = True
55
+ speed_x = abs(speed_x)
56
+
57
+ elif pong:
58
+ game.play_sound('pong')
59
+ pong = False
60
+
61
+
62
+ ball_sprite.x += speed_x
63
+ ball_sprite.y += speed_y
64
+ else:
65
+ ball_sprite.hide()
66
+
67
+ ball_sprite.y = SCREEN_HEIGHT//2
68
+ ball_sprite.x = SCREEN_WIDTH//2
69
+
70
+ game_start_event = ball_sprite.when_game_start()
71
+ game_start_event.add_handler(movement)
72
+
@@ -0,0 +1,36 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ SCREEN_HEIGHT = 720
5
+ SCREEN_WIDTH = 1280
6
+
7
+ paddle_colour = (200, 200, 200)
8
+ paddle_width = 20
9
+ paddle_height = 130
10
+ paddle_margin = 30
11
+
12
+
13
+ sprite = pysc.create_rect_sprite(paddle_colour, paddle_width, paddle_height, position=(paddle_margin, SCREEN_HEIGHT//2))
14
+ game['left_paddle'] = sprite
15
+ sprite.set_draggable(True)
16
+
17
+ def movement():
18
+ speed = 0
19
+ while True:
20
+ if pysc.is_key_pressed('w'):
21
+ speed = -8
22
+ if pysc.is_key_pressed('s'):
23
+ speed = 8
24
+
25
+ speed *= 0.9
26
+
27
+ sprite.y += speed
28
+
29
+ sprite.y = pysc.cap(sprite.y, 0+paddle_height/2, SCREEN_HEIGHT-paddle_height/2)
30
+
31
+ yield 1/game.framerate
32
+
33
+ game_start_event = sprite.when_game_start()
34
+ game_start_event.add_handler(movement)
35
+
36
+
@@ -0,0 +1,21 @@
1
+ import pyscratch as pysc
2
+ import pygame
3
+ from pyscratch import game
4
+
5
+ import right_paddle, left_paddle, ball, score_display
6
+
7
+ SCREEN_HEIGHT = 720
8
+ SCREEN_WIDTH = 1280
9
+
10
+
11
+ game['running']=False
12
+ game['score_left'] = 0
13
+ game['score_right'] = 0
14
+
15
+ game.load_sound('pong', 'assets/sound_effects/Metal Clang-SoundBible.com-19572601.wav')
16
+
17
+ font = pygame.font.SysFont(None, 48)
18
+ pysc.create_shared_data_display_sprite('left_score', font, size=(300, 60))
19
+
20
+ game.update_screen_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
21
+ game.start(60, use_frame_time=True)
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ SCREEN_HEIGHT = 720
5
+ SCREEN_WIDTH = 1280
6
+
7
+ paddle_colour = (200, 200, 200)
8
+ paddle_width = 20
9
+ paddle_height = 130
10
+ paddle_margin = 30
11
+
12
+ sprite = pysc.create_rect_sprite(paddle_colour, paddle_width, paddle_height, position=(SCREEN_WIDTH-paddle_margin, SCREEN_HEIGHT//2))
13
+
14
+ #sprite.set_draggable(True)
15
+
16
+ game_start_event = sprite.when_game_start()
17
+ def movement():
18
+ while True:
19
+ speed = 0
20
+
21
+ if pysc.is_key_pressed('up'):
22
+ speed -= 8
23
+ if pysc.is_key_pressed('down'):
24
+ speed += 8
25
+
26
+ sprite.y += speed
27
+
28
+ sprite.y = pysc.cap(sprite.y, 0+paddle_height//2, SCREEN_HEIGHT-paddle_height//2)
29
+
30
+
31
+ # wait for 1 frame
32
+ yield 1/game.framerate
33
+
34
+ game_start_event.add_handler(movement)
35
+
36
+
37
+ game['right_paddle'] = sprite
@@ -0,0 +1,54 @@
1
+ from attr import s
2
+ import pyscratch as pysc
3
+ import pygame
4
+ from pyscratch import game
5
+
6
+ SCREEN_HEIGHT = 720
7
+ SCREEN_WIDTH = 1280
8
+
9
+ font = pygame.font.SysFont(None, 48)
10
+
11
+
12
+ score_board = pysc.create_rect_sprite((200, 200, 200), 150, 70, position=(SCREEN_WIDTH//2,SCREEN_HEIGHT//2))
13
+ game_start_event = score_board.when_game_start()
14
+ game['left_score'] = 0
15
+ game['right_score'] = 0
16
+
17
+ def display_score():
18
+ score_board.show()
19
+ l = game['left_score']
20
+ r = game['right_score']
21
+ score_board.write_text(f'{l} - {r}', font, offset=(150//2, 70//2))
22
+
23
+ game_start_event.add_handler(display_score)
24
+
25
+
26
+ left_score_event = score_board.when_receive_message('left_score')
27
+ def left_score(data):
28
+ game['left_score'] += 1
29
+ display_score()
30
+
31
+ left_score_event.add_handler(left_score)
32
+
33
+
34
+ right_score_event = score_board.when_receive_message('right_score')
35
+ def right_score(data):
36
+ game['right_score'] += 1
37
+ display_score()
38
+
39
+ right_score_event.add_handler(right_score)
40
+
41
+
42
+ def resume_game():
43
+ game['running'] = True
44
+ score_board.hide()
45
+
46
+ def on_space_release(updown):
47
+ if updown == 'up':
48
+ resume_game()
49
+
50
+
51
+ game.when_key_pressed("space").add_handler(on_space_release)
52
+ score_board.when_this_sprite_clicked().add_handler(resume_game)
53
+
54
+
pyscratch/__init__.py ADDED
@@ -0,0 +1,48 @@
1
+ """
2
+ The reference manual is intended to provide technical specifications for the functions in this library.
3
+ If you are new to this library, visit [getting-started](../getting-started/).
4
+ # Namespace
5
+ Everything in this library are directly under the pyscratch namespace.
6
+ So for example, you can use `pyscratch.game` to refer to `pyscratch.game_module.game` or `pyscratch.Sprite` to refer to `pyscratch.sprite.Sprite` etc.
7
+
8
+ When you do `import pyscratch as pysc`, they become just `pysc.game`, `pysc.Sprite` and `pysc.random_number` etc.
9
+
10
+
11
+ # Main Objects
12
+ You will be mainly interacting of these following types of objects:
13
+ ## 1. pyscratch.game_module.game (pysc.game)
14
+ This is an object instead a type of objects. This object represents the game itself.
15
+ You use it to start the game, to play sound, change backdrops and make global changes to the game.
16
+ You can also use it to create events, but it is more convenient to create the events from the sprite.
17
+
18
+ ## 2. pyscratch.sprite.Sprite
19
+ The Sprite objects are the objects that represents the sprites in the game.
20
+
21
+
22
+ ## 3. pyscratch.event.Event & pyscratch.event.Condition
23
+ This is the object you will get when you run `my_event = sprite1.when_game_start()`
24
+ The only way you will interact with this object is to add handler functions to it and to remove it.
25
+
26
+
27
+ ## 4. Pygame objects that represents the assets
28
+ pygame is another library that this library depends on.
29
+ You only need to interact with these objects when you are loading the assets (for the sprites, backdrops and text styles)
30
+
31
+ ### 4.1. pygame.Surface
32
+ A pygame object that represents an image.
33
+ All the images in this library are represented as pygame.Surface objects.
34
+ You can use pyscratch.helper.load_image to load an image for you.
35
+
36
+ ### 4.2. pygame.font.Font
37
+ A pygame object that represent the font (or the style of the text).
38
+ Some functions require the font object to render the text.
39
+ To create a font object:
40
+ ```python
41
+ font = pygame.font.SysFont(None, 48) # None = default font, 48 = font size
42
+ ```
43
+ """
44
+
45
+ from .event import *
46
+ from .game_module import *
47
+ from .helper import *
48
+ from .sprite import *