pyscratch-pysc 1.0.4__py3-none-any.whl → 2.0.1__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 (145) hide show
  1. assets/startup-assets/tutorial-steps/1-create-sprites/main.py +10 -0
  2. assets/startup-assets/tutorial-steps/1-create-sprites/player.py +5 -0
  3. assets/startup-assets/tutorial-steps/1-create-sprites-task/enemy.py +4 -0
  4. assets/startup-assets/tutorial-steps/1-create-sprites-task/main.py +11 -0
  5. assets/startup-assets/tutorial-steps/1-create-sprites-task/player.py +5 -0
  6. assets/startup-assets/tutorial-steps/2-basic-events/enemy.py +4 -0
  7. assets/startup-assets/tutorial-steps/2-basic-events/main.py +11 -0
  8. assets/startup-assets/tutorial-steps/2-basic-events/player.py +31 -0
  9. assets/startup-assets/tutorial-steps/2-basic-events-task1/enemy.py +4 -0
  10. assets/startup-assets/tutorial-steps/2-basic-events-task1/main.py +11 -0
  11. assets/startup-assets/tutorial-steps/2-basic-events-task1/player.py +23 -0
  12. assets/startup-assets/tutorial-steps/2-basic-events-task2/enemy.py +14 -0
  13. assets/startup-assets/tutorial-steps/2-basic-events-task2/main.py +11 -0
  14. assets/startup-assets/tutorial-steps/2-basic-events-task2/player.py +23 -0
  15. assets/startup-assets/tutorial-steps/3-loops-conditions/enemy.py +14 -0
  16. assets/startup-assets/tutorial-steps/3-loops-conditions/main.py +11 -0
  17. assets/startup-assets/tutorial-steps/3-loops-conditions/player.py +23 -0
  18. assets/startup-assets/tutorial-steps/3-loops-conditions-task1/enemy.py +14 -0
  19. assets/startup-assets/tutorial-steps/3-loops-conditions-task1/main.py +11 -0
  20. assets/startup-assets/tutorial-steps/3-loops-conditions-task1/player.py +34 -0
  21. assets/startup-assets/tutorial-steps/3-loops-conditions-task2/enemy.py +23 -0
  22. assets/startup-assets/tutorial-steps/3-loops-conditions-task2/main.py +11 -0
  23. assets/startup-assets/tutorial-steps/3-loops-conditions-task2/player.py +41 -0
  24. assets/startup-assets/tutorial-steps/4-variables/enemy.py +23 -0
  25. assets/startup-assets/tutorial-steps/4-variables/main.py +11 -0
  26. assets/startup-assets/tutorial-steps/4-variables/player.py +59 -0
  27. assets/startup-assets/tutorial-steps/5-sprite-object/enemy.py +19 -0
  28. assets/startup-assets/tutorial-steps/5-sprite-object/main.py +11 -0
  29. assets/startup-assets/tutorial-steps/5-sprite-object/player.py +20 -0
  30. assets/startup-assets/tutorial-steps/5-sprite-object-task1/enemy.py +19 -0
  31. assets/startup-assets/tutorial-steps/5-sprite-object-task1/main.py +11 -0
  32. assets/startup-assets/tutorial-steps/5-sprite-object-task1/player.py +38 -0
  33. assets/startup-assets/tutorial-steps/5-sprite-object-task2/enemy.py +20 -0
  34. assets/startup-assets/tutorial-steps/5-sprite-object-task2/main.py +11 -0
  35. assets/startup-assets/tutorial-steps/5-sprite-object-task2/player.py +58 -0
  36. assets/startup-assets/tutorial-steps/6-referencing-sprites/enemy.py +32 -0
  37. assets/startup-assets/tutorial-steps/6-referencing-sprites/main.py +11 -0
  38. assets/startup-assets/tutorial-steps/6-referencing-sprites/player.py +59 -0
  39. assets/startup-assets/tutorial-steps/6-referencing-sprites-task/enemy.py +37 -0
  40. assets/startup-assets/tutorial-steps/6-referencing-sprites-task/main.py +11 -0
  41. assets/startup-assets/tutorial-steps/6-referencing-sprites-task/player.py +60 -0
  42. assets/startup-assets/tutorial-steps/7-parameterised-events/enemy.py +37 -0
  43. assets/startup-assets/tutorial-steps/7-parameterised-events/main.py +11 -0
  44. assets/startup-assets/tutorial-steps/7-parameterised-events/player.py +83 -0
  45. assets/startup-assets/tutorial-steps/7-parameterised-events-msg/enemy.py +37 -0
  46. assets/startup-assets/tutorial-steps/7-parameterised-events-msg/main.py +11 -0
  47. assets/startup-assets/tutorial-steps/7-parameterised-events-msg/player.py +86 -0
  48. assets/startup-assets/tutorial-steps/7-parameterised-events-task/enemy.py +35 -0
  49. assets/startup-assets/tutorial-steps/7-parameterised-events-task/main.py +11 -0
  50. assets/startup-assets/tutorial-steps/7-parameterised-events-task/player.py +86 -0
  51. assets/startup-assets/tutorial-steps/8-backdrop-music/enemy.py +35 -0
  52. assets/startup-assets/tutorial-steps/8-backdrop-music/main.py +11 -0
  53. assets/startup-assets/tutorial-steps/8-backdrop-music/player.py +86 -0
  54. assets/startup-assets/tutorial-steps/9-polish/enemy.py +39 -0
  55. assets/startup-assets/tutorial-steps/9-polish/enemy_red.py +40 -0
  56. assets/startup-assets/tutorial-steps/9-polish/main.py +12 -0
  57. assets/startup-assets/tutorial-steps/9-polish/player.py +119 -0
  58. examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites/main.py +10 -0
  59. examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites/player.py +5 -0
  60. examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/enemy.py +4 -0
  61. examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/main.py +11 -0
  62. examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/player.py +5 -0
  63. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/enemy.py +4 -0
  64. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/main.py +11 -0
  65. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/player.py +31 -0
  66. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/enemy.py +4 -0
  67. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/main.py +11 -0
  68. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/player.py +23 -0
  69. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/enemy.py +14 -0
  70. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/main.py +11 -0
  71. examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/player.py +23 -0
  72. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/enemy.py +14 -0
  73. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/main.py +11 -0
  74. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/player.py +23 -0
  75. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/enemy.py +14 -0
  76. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/main.py +11 -0
  77. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/player.py +34 -0
  78. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/enemy.py +23 -0
  79. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/main.py +11 -0
  80. examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/player.py +41 -0
  81. examples/fish/assets/startup-assets/tutorial-steps/4-variables/enemy.py +23 -0
  82. examples/fish/assets/startup-assets/tutorial-steps/4-variables/main.py +11 -0
  83. examples/fish/assets/startup-assets/tutorial-steps/4-variables/player.py +59 -0
  84. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/enemy.py +19 -0
  85. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/main.py +11 -0
  86. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/player.py +20 -0
  87. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/enemy.py +19 -0
  88. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/main.py +11 -0
  89. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/player.py +38 -0
  90. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/enemy.py +20 -0
  91. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/main.py +11 -0
  92. examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/player.py +58 -0
  93. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/enemy.py +32 -0
  94. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/main.py +11 -0
  95. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/player.py +59 -0
  96. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/enemy.py +37 -0
  97. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/main.py +11 -0
  98. examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/player.py +60 -0
  99. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/enemy.py +37 -0
  100. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/main.py +11 -0
  101. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/player.py +83 -0
  102. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/enemy.py +37 -0
  103. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/main.py +11 -0
  104. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/player.py +86 -0
  105. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/enemy.py +35 -0
  106. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/main.py +11 -0
  107. examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/player.py +86 -0
  108. examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/enemy.py +35 -0
  109. examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/main.py +11 -0
  110. examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/player.py +86 -0
  111. examples/fish/assets/startup-assets/tutorial-steps/9-polish/enemy.py +39 -0
  112. examples/fish/assets/startup-assets/tutorial-steps/9-polish/enemy_red.py +40 -0
  113. examples/fish/assets/startup-assets/tutorial-steps/9-polish/main.py +12 -0
  114. examples/fish/assets/startup-assets/tutorial-steps/9-polish/player.py +119 -0
  115. examples/tutorial-day1/chest.py +21 -0
  116. examples/tutorial-day1/enemy.py +106 -0
  117. examples/tutorial-day1/friend.py +51 -0
  118. examples/tutorial-day1/in-steps/1-create-sprites/chest.py +5 -0
  119. examples/tutorial-day1/in-steps/1-create-sprites/enemy.py +5 -0
  120. examples/tutorial-day1/in-steps/1-create-sprites/main.py +9 -0
  121. examples/tutorial-day1/in-steps/2-basic-events/chest.py +24 -0
  122. examples/tutorial-day1/in-steps/2-basic-events/enemy.py +18 -0
  123. examples/tutorial-day1/in-steps/2-basic-events/main.py +9 -0
  124. examples/tutorial-day1/in-steps/3-flow/chest.py +25 -0
  125. examples/tutorial-day1/in-steps/3-flow/enemy.py +56 -0
  126. examples/tutorial-day1/in-steps/3-flow/friend.py +47 -0
  127. examples/tutorial-day1/in-steps/3-flow/main.py +9 -0
  128. examples/tutorial-day1/in-steps/4-variables/chest.py +37 -0
  129. examples/tutorial-day1/in-steps/4-variables/enemy.py +76 -0
  130. examples/tutorial-day1/in-steps/4-variables/friend.py +49 -0
  131. examples/tutorial-day1/in-steps/4-variables/main.py +9 -0
  132. examples/tutorial-day1/in-steps/5-backdrops/chest.py +37 -0
  133. examples/tutorial-day1/in-steps/5-backdrops/enemy.py +76 -0
  134. examples/tutorial-day1/in-steps/5-backdrops/friend.py +49 -0
  135. examples/tutorial-day1/in-steps/5-backdrops/main.py +26 -0
  136. examples/tutorial-day1/main.py +48 -0
  137. examples/tutorial-day1/target.py +14 -0
  138. examples/tutorial-day1/text.py +23 -0
  139. pyscratch/game_module.py +70 -27
  140. pyscratch/sprite.py +12 -4
  141. {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/METADATA +8 -1
  142. pyscratch_pysc-2.0.1.dist-info/RECORD +239 -0
  143. pyscratch_pysc-1.0.4.dist-info/RECORD +0 -101
  144. {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/WHEEL +0 -0
  145. {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,58 @@
1
+ import pyscratch as pysc
2
+
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+
6
+ def move():
7
+ while True:
8
+ if pysc.is_key_pressed("d"):
9
+ player1.x += 4
10
+
11
+ if pysc.is_key_pressed("a"):
12
+ player1.x -= 4
13
+
14
+ if pysc.is_key_pressed("w"):
15
+ player1.y -= 4
16
+
17
+ if pysc.is_key_pressed("s"):
18
+ player1.y += 4
19
+
20
+ if pysc.is_key_pressed("right"):
21
+ player2.x += 4
22
+
23
+ if pysc.is_key_pressed("left"):
24
+ player2.x -= 4
25
+
26
+ if pysc.is_key_pressed("up"):
27
+ player2.y -= 4
28
+
29
+ if pysc.is_key_pressed("down"):
30
+ player2.y += 4
31
+
32
+ yield 1/60 # must have an yield in a loop!
33
+
34
+ # for the purpose of this tutorial,
35
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
36
+ game_start = player2.when_game_start()
37
+ game_start.add_handler(move)
38
+
39
+
40
+
41
+
42
+ def move2():
43
+ player1.x = 200
44
+ player1.y = 400
45
+
46
+ player2.x = 400
47
+ player2.y = 200
48
+
49
+ while True:
50
+ if player1.is_touching(player2):
51
+ player1.hide()
52
+ player2.hide()
53
+
54
+ yield 1/60 # must have an yield in a loop!
55
+
56
+ # for the purpose of this tutorial,
57
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
58
+ player2.when_game_start().add_handler(move2)
@@ -0,0 +1,32 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ spawn_button = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
5
+ spawn_button.y = 250
6
+
7
+ # no guarantee that the `player1` and `player2` are created at this point.
8
+ # therefore, do not do this:
9
+ #player1 = game['player1']
10
+
11
+ def spwan_enemy():
12
+ enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
13
+
14
+ enemy_blue.y = pysc.random_number(0, game.screen_height)
15
+ enemy_blue.x = 0
16
+
17
+ player1 = game['player1']
18
+
19
+ # a better way: break the loop when the sprite is removed
20
+ #while not enemy_blue.removed:
21
+ while True:
22
+ enemy_blue.x += 4
23
+
24
+ if enemy_blue.is_touching(player1):
25
+ enemy_blue.remove()
26
+ player1.scale_by(1.1)
27
+
28
+ yield 1/game.framerate # must have an yield in a loop!
29
+
30
+ spawn_button.when_this_sprite_clicked().add_handler(spwan_enemy)
31
+
32
+
@@ -0,0 +1,11 @@
1
+ import pyscratch as pysc
2
+ import player # Very important!
3
+ import enemy # Very important!
4
+ import pygame
5
+ # start the game
6
+ WIN_WIDTH = 500 # change me
7
+ WIN_HEIGHT = 500 # change me
8
+ framerate = 60
9
+
10
+ pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
11
+ pysc.game.start(framerate, use_frame_time=True)
@@ -0,0 +1,59 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+ game['player1'] = player1
6
+
7
+ def move():
8
+ while True:
9
+ if pysc.is_key_pressed("d"):
10
+ player1.x += 4
11
+
12
+ if pysc.is_key_pressed("a"):
13
+ player1.x -= 4
14
+
15
+ if pysc.is_key_pressed("w"):
16
+ player1.y -= 4
17
+
18
+ if pysc.is_key_pressed("s"):
19
+ player1.y += 4
20
+
21
+ if pysc.is_key_pressed("right"):
22
+ player2.x += 4
23
+
24
+ if pysc.is_key_pressed("left"):
25
+ player2.x -= 4
26
+
27
+ if pysc.is_key_pressed("up"):
28
+ player2.y -= 4
29
+
30
+ if pysc.is_key_pressed("down"):
31
+ player2.y += 4
32
+
33
+ yield 1/60 # must have an yield in a loop!
34
+
35
+ # for the purpose of this tutorial,
36
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
37
+ game_start = player2.when_game_start()
38
+ game_start.add_handler(move)
39
+
40
+
41
+
42
+
43
+ def move2():
44
+ player1.x = 200
45
+ player1.y = 400
46
+
47
+ player2.x = 400
48
+ player2.y = 200
49
+
50
+ while True:
51
+ if player1.is_touching(player2):
52
+ player1.hide()
53
+ player2.hide()
54
+
55
+ yield 1/60 # must have an yield in a loop!
56
+
57
+ # for the purpose of this tutorial,
58
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
59
+ player2.when_game_start().add_handler(move2)
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ spawn_button = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
5
+ spawn_button.y = 250
6
+
7
+ # no guarantee that the `player1` and `player2` are created at this point.
8
+ # therefore, do not do this:
9
+ #player1 = game['player1']
10
+
11
+ def spwan_enemy():
12
+ enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
13
+
14
+ enemy_blue.y = pysc.random_number(0, game.screen_height)
15
+ enemy_blue.x = 0
16
+
17
+ player1 = game['player1']
18
+ player2 = game['player2']
19
+
20
+ # a better way: break the loop when the sprite is removed
21
+ #while not enemy_blue.removed:
22
+ while True:
23
+ enemy_blue.x += 4
24
+
25
+ if enemy_blue.is_touching(player1):
26
+ enemy_blue.remove()
27
+ player1.scale_by(1.1)
28
+
29
+ if enemy_blue.is_touching(player2):
30
+ enemy_blue.remove()
31
+ player2.scale_by(1.1)
32
+
33
+ yield 1/game.framerate # must have an yield in a loop!
34
+
35
+ spawn_button.when_this_sprite_clicked().add_handler(spwan_enemy)
36
+
37
+
@@ -0,0 +1,11 @@
1
+ import pyscratch as pysc
2
+ import player # Very important!
3
+ import enemy # Very important!
4
+ import pygame
5
+ # start the game
6
+ WIN_WIDTH = 500 # change me
7
+ WIN_HEIGHT = 500 # change me
8
+ framerate = 60
9
+
10
+ pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
11
+ pysc.game.start(framerate, use_frame_time=True)
@@ -0,0 +1,60 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+ game['player1'] = player1
6
+ game['player2'] = player2
7
+
8
+ def move():
9
+ while True:
10
+ if pysc.is_key_pressed("d"):
11
+ player1.x += 4
12
+
13
+ if pysc.is_key_pressed("a"):
14
+ player1.x -= 4
15
+
16
+ if pysc.is_key_pressed("w"):
17
+ player1.y -= 4
18
+
19
+ if pysc.is_key_pressed("s"):
20
+ player1.y += 4
21
+
22
+ if pysc.is_key_pressed("right"):
23
+ player2.x += 4
24
+
25
+ if pysc.is_key_pressed("left"):
26
+ player2.x -= 4
27
+
28
+ if pysc.is_key_pressed("up"):
29
+ player2.y -= 4
30
+
31
+ if pysc.is_key_pressed("down"):
32
+ player2.y += 4
33
+
34
+ yield 1/60 # must have an yield in a loop!
35
+
36
+ # for the purpose of this tutorial,
37
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
38
+ game_start = player2.when_game_start()
39
+ game_start.add_handler(move)
40
+
41
+
42
+
43
+
44
+ def move2():
45
+ player1.x = 200
46
+ player1.y = 400
47
+
48
+ player2.x = 400
49
+ player2.y = 200
50
+
51
+ while True:
52
+ if player1.is_touching(player2):
53
+ player1.hide()
54
+ player2.hide()
55
+
56
+ yield 1/60 # must have an yield in a loop!
57
+
58
+ # for the purpose of this tutorial,
59
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
60
+ player2.when_game_start().add_handler(move2)
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ spawn_button = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
5
+ spawn_button.y = 250
6
+
7
+ # no guarantee that the `player1` and `player2` are created at this point.
8
+ # therefore, do not do this:
9
+ #player1 = game['player1']
10
+
11
+ def spwan_enemy():
12
+ enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
13
+
14
+ enemy_blue.y = pysc.random_number(0, game.screen_height)
15
+ enemy_blue.x = 0
16
+
17
+ player1 = game['player1']
18
+ player2 = game['player2']
19
+
20
+ # a better way: break the loop when the sprite is removed
21
+ #while not enemy_blue.removed:
22
+ while True:
23
+ enemy_blue.x += 4
24
+
25
+ if enemy_blue.is_touching(player1):
26
+ enemy_blue.remove()
27
+ player1.scale_by(1.1)
28
+
29
+ if enemy_blue.is_touching(player2):
30
+ enemy_blue.remove()
31
+ player2.scale_by(1.1)
32
+
33
+ yield 1/game.framerate # must have an yield in a loop!
34
+
35
+ spawn_button.when_this_sprite_clicked().add_handler(spwan_enemy)
36
+
37
+
@@ -0,0 +1,11 @@
1
+ import pyscratch as pysc
2
+ import player # Very important!
3
+ import enemy # Very important!
4
+ import pygame
5
+ # start the game
6
+ WIN_WIDTH = 500 # change me
7
+ WIN_HEIGHT = 500 # change me
8
+ framerate = 60
9
+
10
+ pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
11
+ pysc.game.start(framerate, use_frame_time=True)
@@ -0,0 +1,83 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+ game['player1'] = player1
6
+ game['player2'] = player2
7
+
8
+ def move():
9
+ while True:
10
+ if pysc.is_key_pressed("d"):
11
+ player1.x += 4
12
+
13
+ if pysc.is_key_pressed("a"):
14
+ player1.x -= 4
15
+
16
+ if pysc.is_key_pressed("w"):
17
+ player1.y -= 4
18
+
19
+ if pysc.is_key_pressed("s"):
20
+ player1.y += 4
21
+
22
+ if pysc.is_key_pressed("right"):
23
+ player2.x += 4
24
+
25
+ if pysc.is_key_pressed("left"):
26
+ player2.x -= 4
27
+
28
+ if pysc.is_key_pressed("up"):
29
+ player2.y -= 4
30
+
31
+ if pysc.is_key_pressed("down"):
32
+ player2.y += 4
33
+
34
+ yield 1/60 # must have an yield in a loop!
35
+
36
+ # for the purpose of this tutorial,
37
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
38
+ game_start = player2.when_game_start()
39
+ game_start.add_handler(move)
40
+
41
+
42
+
43
+
44
+ def move2():
45
+ player1.x = 200
46
+ player1.y = 400
47
+
48
+ player2.x = 400
49
+ player2.y = 200
50
+
51
+ while True:
52
+ if player1.is_touching(player2):
53
+ player1.hide()
54
+ player2.hide()
55
+
56
+ yield 1/60 # must have an yield in a loop!
57
+
58
+ # for the purpose of this tutorial,
59
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
60
+ player2.when_game_start().add_handler(move2)
61
+
62
+
63
+ def test_key_event(key, updown):
64
+ print("key event:", key, updown)
65
+
66
+ player1.when_any_key_pressed().add_handler(test_key_event)
67
+
68
+
69
+ def player1_skill(updown):
70
+
71
+ if updown == 'up':
72
+ print("space pressed!")
73
+ for i in range(20):
74
+ player1.scale_by(1.025)
75
+ yield 1/game.framerate
76
+
77
+ if updown == 'down':
78
+ print("space released!")
79
+ for i in range(20):
80
+ player1.scale_by(1/1.025)
81
+ yield 1/game.framerate
82
+
83
+ player1.when_key_pressed("space").add_handler(player1_skill)
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ spawn_button = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
5
+ spawn_button.y = 250
6
+
7
+ # no guarantee that the `player1` and `player2` are created at this point.
8
+ # therefore, do not do this:
9
+ #player1 = game['player1']
10
+
11
+ def spwan_enemy():
12
+ enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
13
+
14
+ enemy_blue.y = pysc.random_number(0, game.screen_height)
15
+ enemy_blue.x = 0
16
+
17
+ player1 = game['player1']
18
+ player2 = game['player2']
19
+
20
+ # a better way: break the loop when the sprite is removed
21
+ #while not enemy_blue.removed:
22
+ while True:
23
+ enemy_blue.x += 4
24
+
25
+ if enemy_blue.is_touching(player1):
26
+ enemy_blue.remove()
27
+ player1.scale_by(1.1)
28
+
29
+ if enemy_blue.is_touching(player2):
30
+ enemy_blue.remove()
31
+ player2.scale_by(1.1)
32
+
33
+ yield 1/game.framerate # must have an yield in a loop!
34
+
35
+ spawn_button.when_this_sprite_clicked().add_handler(spwan_enemy)
36
+
37
+
@@ -0,0 +1,11 @@
1
+ import pyscratch as pysc
2
+ import player # Very important!
3
+ import enemy # Very important!
4
+ import pygame
5
+ # start the game
6
+ WIN_WIDTH = 500 # change me
7
+ WIN_HEIGHT = 500 # change me
8
+ framerate = 60
9
+
10
+ pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
11
+ pysc.game.start(framerate, use_frame_time=True)
@@ -0,0 +1,86 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+ game['player1'] = player1
6
+ game['player2'] = player2
7
+
8
+ def move():
9
+ while True:
10
+ if pysc.is_key_pressed("d"):
11
+ player1.x += 4
12
+
13
+ if pysc.is_key_pressed("a"):
14
+ player1.x -= 4
15
+
16
+ if pysc.is_key_pressed("w"):
17
+ player1.y -= 4
18
+
19
+ if pysc.is_key_pressed("s"):
20
+ player1.y += 4
21
+
22
+ if pysc.is_key_pressed("right"):
23
+ player2.x += 4
24
+
25
+ if pysc.is_key_pressed("left"):
26
+ player2.x -= 4
27
+
28
+ if pysc.is_key_pressed("up"):
29
+ player2.y -= 4
30
+
31
+ if pysc.is_key_pressed("down"):
32
+ player2.y += 4
33
+
34
+ yield 1/60 # must have an yield in a loop!
35
+
36
+ # for the purpose of this tutorial,
37
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
38
+ game_start = player2.when_game_start()
39
+ game_start.add_handler(move)
40
+
41
+
42
+
43
+
44
+ def move2():
45
+ player1.x = 200
46
+ player1.y = 400
47
+
48
+ player2.x = 400
49
+ player2.y = 200
50
+
51
+ while True:
52
+ if player1.is_touching(player2):
53
+ player1.hide()
54
+ player2.hide()
55
+
56
+ yield 1/60 # must have an yield in a loop!
57
+
58
+ # for the purpose of this tutorial,
59
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
60
+ player2.when_game_start().add_handler(move2)
61
+
62
+
63
+ def message_event(data):
64
+ print("Received a message with data:", data)
65
+ player1.when_receive_message("message_topic1").add_handler(message_event)
66
+
67
+
68
+
69
+
70
+ def player1_skill(updown):
71
+
72
+ game.broadcast_message("message_topic1", updown)
73
+
74
+ if updown == 'up':
75
+ for i in range(20):
76
+ player1.scale_by(1.025)
77
+ yield 1/game.framerate
78
+
79
+ if updown == 'down':
80
+
81
+ for i in range(20):
82
+ player1.scale_by(1/1.025)
83
+ yield 1/game.framerate
84
+
85
+
86
+ player1.when_key_pressed("space").add_handler(player1_skill)
@@ -0,0 +1,35 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ def spwan_enemy(data):
5
+ enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
6
+
7
+ enemy_blue.y = pysc.random_number(0, game.screen_height)
8
+ enemy_blue.x = 0
9
+
10
+ player1 = game['player1']
11
+ player2 = game['player2']
12
+
13
+ # a better way: break the loop when the sprite is removed
14
+ #while not enemy_blue.removed:
15
+ while True:
16
+ enemy_blue.x += 4
17
+
18
+ if enemy_blue.is_touching(player1):
19
+ enemy_blue.remove()
20
+ player1.scale_by(1.1)
21
+
22
+ if enemy_blue.is_touching(player2):
23
+ enemy_blue.remove()
24
+ player2.scale_by(1.1)
25
+
26
+ yield 1/game.framerate # must have an yield in a loop!
27
+
28
+ game.when_receive_message("spawn_enemy").add_handler(spwan_enemy)
29
+
30
+ def on_start():
31
+ while True:
32
+ game.broadcast_message("spawn_enemy")
33
+ yield 1
34
+
35
+ game.when_game_start().add_handler(on_start)
@@ -0,0 +1,11 @@
1
+ import pyscratch as pysc
2
+ import player # Very important!
3
+ import enemy # Very important!
4
+ import pygame
5
+ # start the game
6
+ WIN_WIDTH = 500 # change me
7
+ WIN_HEIGHT = 500 # change me
8
+ framerate = 60
9
+
10
+ pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
11
+ pysc.game.start(framerate, use_frame_time=True)
@@ -0,0 +1,86 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+ player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
4
+ player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
5
+ game['player1'] = player1
6
+ game['player2'] = player2
7
+
8
+ def move():
9
+ while True:
10
+ if pysc.is_key_pressed("d"):
11
+ player1.x += 4
12
+
13
+ if pysc.is_key_pressed("a"):
14
+ player1.x -= 4
15
+
16
+ if pysc.is_key_pressed("w"):
17
+ player1.y -= 4
18
+
19
+ if pysc.is_key_pressed("s"):
20
+ player1.y += 4
21
+
22
+ if pysc.is_key_pressed("right"):
23
+ player2.x += 4
24
+
25
+ if pysc.is_key_pressed("left"):
26
+ player2.x -= 4
27
+
28
+ if pysc.is_key_pressed("up"):
29
+ player2.y -= 4
30
+
31
+ if pysc.is_key_pressed("down"):
32
+ player2.y += 4
33
+
34
+ yield 1/60 # must have an yield in a loop!
35
+
36
+ # for the purpose of this tutorial,
37
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
38
+ game_start = player2.when_game_start()
39
+ game_start.add_handler(move)
40
+
41
+
42
+
43
+
44
+ def move2():
45
+ player1.x = 200
46
+ player1.y = 400
47
+
48
+ player2.x = 400
49
+ player2.y = 200
50
+
51
+ while True:
52
+ if player1.is_touching(player2):
53
+ player1.hide()
54
+ player2.hide()
55
+
56
+ yield 1/60 # must have an yield in a loop!
57
+
58
+ # for the purpose of this tutorial,
59
+ # `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
60
+ player2.when_game_start().add_handler(move2)
61
+
62
+
63
+ def message_event(data):
64
+ print("Received a message with data:", data)
65
+ player1.when_receive_message("message_topic1").add_handler(message_event)
66
+
67
+
68
+
69
+
70
+ def player1_skill(updown):
71
+
72
+ game.broadcast_message("message_topic1", updown)
73
+
74
+ if updown == 'up':
75
+ for i in range(20):
76
+ player1.scale_by(1.025)
77
+ yield 1/game.framerate
78
+
79
+ if updown == 'down':
80
+
81
+ for i in range(20):
82
+ player1.scale_by(1/1.025)
83
+ yield 1/game.framerate
84
+
85
+
86
+ player1.when_key_pressed("space").add_handler(player1_skill)