pyscratch-pysc 1.0.3__py3-none-any.whl → 2.0.0__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 (146) 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/getting-started/step 7 - Referencing other sprites/enemy.py +1 -6
  116. examples/tutorial-day1/chest.py +21 -0
  117. examples/tutorial-day1/enemy.py +106 -0
  118. examples/tutorial-day1/friend.py +51 -0
  119. examples/tutorial-day1/in-steps/1-create-sprites/chest.py +5 -0
  120. examples/tutorial-day1/in-steps/1-create-sprites/enemy.py +5 -0
  121. examples/tutorial-day1/in-steps/1-create-sprites/main.py +9 -0
  122. examples/tutorial-day1/in-steps/2-basic-events/chest.py +24 -0
  123. examples/tutorial-day1/in-steps/2-basic-events/enemy.py +18 -0
  124. examples/tutorial-day1/in-steps/2-basic-events/main.py +9 -0
  125. examples/tutorial-day1/in-steps/3-flow/chest.py +25 -0
  126. examples/tutorial-day1/in-steps/3-flow/enemy.py +56 -0
  127. examples/tutorial-day1/in-steps/3-flow/friend.py +47 -0
  128. examples/tutorial-day1/in-steps/3-flow/main.py +9 -0
  129. examples/tutorial-day1/in-steps/4-variables/chest.py +37 -0
  130. examples/tutorial-day1/in-steps/4-variables/enemy.py +76 -0
  131. examples/tutorial-day1/in-steps/4-variables/friend.py +49 -0
  132. examples/tutorial-day1/in-steps/4-variables/main.py +9 -0
  133. examples/tutorial-day1/in-steps/5-backdrops/chest.py +37 -0
  134. examples/tutorial-day1/in-steps/5-backdrops/enemy.py +76 -0
  135. examples/tutorial-day1/in-steps/5-backdrops/friend.py +49 -0
  136. examples/tutorial-day1/in-steps/5-backdrops/main.py +26 -0
  137. examples/tutorial-day1/main.py +48 -0
  138. examples/tutorial-day1/target.py +14 -0
  139. examples/tutorial-day1/text.py +23 -0
  140. pyscratch/game_module.py +73 -32
  141. pyscratch/sprite.py +42 -10
  142. {pyscratch_pysc-1.0.3.dist-info → pyscratch_pysc-2.0.0.dist-info}/METADATA +8 -3
  143. pyscratch_pysc-2.0.0.dist-info/RECORD +239 -0
  144. pyscratch_pysc-1.0.3.dist-info/RECORD +0 -101
  145. {pyscratch_pysc-1.0.3.dist-info → pyscratch_pysc-2.0.0.dist-info}/WHEEL +0 -0
  146. {pyscratch_pysc-1.0.3.dist-info → pyscratch_pysc-2.0.0.dist-info}/top_level.txt +0 -0
@@ -12,11 +12,6 @@ def enemy_on_game_start():
12
12
  # hide the parent
13
13
  enemy.hide()
14
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
15
  # clone itself very 2 seconds
21
16
  while True:
22
17
  enemy.create_clone()
@@ -29,7 +24,7 @@ enemy.when_game_start().add_handler(enemy_on_game_start)
29
24
  #def on_clone(clone_sprite):
30
25
  def on_clone(clone_sprite: pysc.Sprite):
31
26
 
32
-
27
+ #clone_sprite.hide()
33
28
  # random height
34
29
  clone_sprite.y = pysc.random_number(0, 720)
35
30
 
@@ -0,0 +1,21 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
5
+
6
+ # 2. Basic Event
7
+ def game_start():
8
+ chest.set_scale(0.15)
9
+ chest.x = game.screen_width/2
10
+ chest.y = game.screen_height/2
11
+ game.move_to_back(chest)
12
+
13
+
14
+ chest.when_game_start().add_handler(game_start)
15
+
16
+ # 6. Backdrop
17
+ def game_end():
18
+ chest.hide()
19
+
20
+ chest.when_backdrop_switched(1).add_handler(game_end)
21
+
@@ -0,0 +1,106 @@
1
+ import pyscratch as pysc
2
+ import pygame
3
+ game = pysc.game
4
+
5
+ enemy = pysc.create_single_costume_sprite("assets/fish_red_skeleton_outline.png")
6
+
7
+ # 4. Variable
8
+ game['clicked'] = False
9
+ game['score'] = 0
10
+ font = pygame.font.Font('assets/Kenney Future.ttf', size=18)
11
+ score_display = pysc.create_shared_data_display_sprite('score', font)
12
+ #score_display = pysc.create_shared_data_display_sprite('score')
13
+
14
+ # 3. Flow
15
+ # 4. Variable
16
+ def movement():
17
+ """
18
+ when_game_start:
19
+ the movement of the enemy
20
+ """
21
+ score_cool_down = 0
22
+ while True:
23
+ yield 1/game.framerate
24
+
25
+ ## 4. Variable
26
+ if (score_cool_down>0):
27
+ score_cool_down -= 1/game.framerate
28
+
29
+ if game['clicked']:
30
+ continue
31
+
32
+ speed = max(1, (game['score']))
33
+ centre = (game.screen_width/2, game.screen_height/2)
34
+
35
+ ## 3. Flow Control
36
+ mouse_x, mouse_y = pysc.get_mouse_pos()
37
+ if enemy.distance_to((mouse_x, mouse_y)) < 200:
38
+ enemy.point_towards_mouse()
39
+ enemy.direction += 180
40
+ enemy.move_indir(speed)
41
+
42
+ else:
43
+ enemy.point_towards(centre)
44
+ enemy.move_indir(speed)
45
+
46
+ ## 4. Variable
47
+ if enemy.distance_to(centre) < 50 and (score_cool_down<=0):
48
+ score_cool_down = .05
49
+ game['score'] -= 1
50
+
51
+ enemy.when_game_start().add_handler(movement)
52
+
53
+
54
+ # 2. Basic Event
55
+ # 3. Flow
56
+ # 4. Variable
57
+ # 5. Sound
58
+ def clicked():
59
+ """
60
+ when the enemy is clicked:
61
+ spin and reappear
62
+ """
63
+
64
+ ##
65
+ game['score'] += 10
66
+ game['clicked'] = True
67
+
68
+ ##
69
+ game.play_sound("hit")
70
+
71
+ ## 3. Flow control (can be simplified to 2. Basic Event)
72
+ t = 1
73
+ for i in range(10):
74
+ enemy.scale_by(0.9)
75
+ enemy.direction += 30
76
+ t -= 0.1
77
+ enemy.set_transparency(t)
78
+ yield 1/game.framerate
79
+
80
+
81
+ enemy.set_scale(1)
82
+ game['clicked'] = False
83
+
84
+ # 2. Basic Event
85
+ new_x = pysc.random_number(0, game.screen_width)
86
+ new_y = pysc.random_number(0, game.screen_height)
87
+
88
+ enemy.x = new_x
89
+ enemy.y = new_y
90
+ enemy.set_transparency(1)
91
+
92
+
93
+ enemy.when_this_sprite_clicked().add_handler(clicked)
94
+
95
+
96
+ # 6. Backdrop
97
+ def game_end():
98
+ """
99
+ when_backdrop_switched:
100
+ hide the sprite
101
+ """
102
+ enemy.hide()
103
+ score_display.hide()
104
+
105
+ enemy.when_backdrop_switched(1).add_handler(game_end)
106
+
@@ -0,0 +1,51 @@
1
+ import pyscratch as pysc
2
+ import pygame
3
+ game = pysc.game
4
+
5
+ friend = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
6
+
7
+ # 3. Flow
8
+ def movement():
9
+ """
10
+ when_game_start:
11
+ the movement of the friend: always moving away from the curosr
12
+ """
13
+ centre = game.screen_width/2, game.screen_height/2
14
+ while True:
15
+ yield 1/game.framerate
16
+ mouse_x, mouse_y = pysc.get_mouse_pos()
17
+ if friend.distance_to((mouse_x, mouse_y)) < 200:
18
+ friend.point_towards_mouse()
19
+ friend.direction += 180
20
+ friend.move_indir(2)
21
+
22
+ else:
23
+ friend.point_towards(centre)
24
+ friend.move_indir(2)
25
+
26
+ friend.when_game_start().add_handler(movement)
27
+
28
+
29
+
30
+ # 3. Flow
31
+ # 4. Variable
32
+ def check_if_centred():
33
+ """
34
+ when_game_start:
35
+ move away when near the centre
36
+ """
37
+ centre = game.screen_width/2, game.screen_height/2
38
+ while True:
39
+ yield 1/game.framerate
40
+ if friend.distance_to(centre) < 50:
41
+ new_x = pysc.random_number(0, game.screen_width)
42
+ new_y = pysc.random_number(0, game.screen_height)
43
+
44
+ friend.x = new_x
45
+ friend.y = new_y
46
+ game['score'] += 10
47
+
48
+ friend.when_game_start().add_handler(check_if_centred)
49
+
50
+
51
+
@@ -0,0 +1,5 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
5
+ chest.set_draggable(True)
@@ -0,0 +1,5 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ enemy = pysc.create_single_costume_sprite("assets/fish_red_skeleton_outline.png")
5
+ enemy.set_draggable(True)
@@ -0,0 +1,9 @@
1
+ import pyscratch as pysc
2
+ import chest, enemy
3
+ game = pysc.game
4
+
5
+
6
+ game.update_screen_mode((1024, 576))
7
+ game.start(show_mouse_position=True)
8
+
9
+
@@ -0,0 +1,24 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
5
+
6
+ # 1. Create a function that does the thing (any function name is fine)
7
+ def set_size_position():
8
+ """
9
+ when game start:
10
+ set the initial position of the chest
11
+ """
12
+ chest.set_scale(0.15)
13
+ chest.x = game.screen_width/2
14
+ chest.y = game.screen_height/2
15
+ game.move_to_back(chest)
16
+
17
+ # 2. Create an event object (any event name is fine)
18
+ click_event = chest.when_this_sprite_clicked()
19
+
20
+ # 3. Attach the function to the event block
21
+ click_event.add_handler(set_size_position)
22
+
23
+ # Or step 2 and 3 together in one line
24
+ #chest.when_this_sprite_clicked().add_handler(set_size_position)
@@ -0,0 +1,18 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ enemy = pysc.create_single_costume_sprite("assets/fish_red_skeleton_outline.png")
5
+ enemy.set_draggable(True)
6
+
7
+
8
+ def clicked():
9
+ """
10
+ when the enemy is clicked:
11
+ change the enemy location
12
+ """
13
+
14
+ enemy.x = pysc.random_number(0, game.screen_width)
15
+ enemy.y = pysc.random_number(0, game.screen_height)
16
+
17
+
18
+ enemy.when_this_sprite_clicked().add_handler(clicked)
@@ -0,0 +1,9 @@
1
+ import pyscratch as pysc
2
+ import chest, enemy
3
+ game = pysc.game
4
+
5
+
6
+ game.update_screen_mode((1024, 576))
7
+ game.start(show_mouse_position=True)
8
+
9
+
@@ -0,0 +1,25 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
5
+
6
+ # 1. Create a function that does the thing (any function name is fine)
7
+ def set_size_position():
8
+ """
9
+ when game start:
10
+ set the initial position of the chest
11
+ """
12
+ chest.set_scale(0.15)
13
+ chest.x = game.screen_width/2
14
+ chest.y = game.screen_height/2
15
+ game.move_to_back(chest)
16
+
17
+ # 2. Create an event object (any event name is fine)
18
+ #click_event = chest.when_this_sprite_clicked()
19
+
20
+ # 3. Attach the function to the event block
21
+ #click_event.add_handler(set_size_position)
22
+
23
+ # Or step 2 and 3 together in one line
24
+ #chest.when_this_sprite_clicked().add_handler(set_size_position)
25
+ chest.when_game_start().add_handler(set_size_position)
@@ -0,0 +1,56 @@
1
+ import pyscratch as pysc
2
+ game = pysc.game
3
+
4
+ enemy = pysc.create_single_costume_sprite("assets/fish_red_skeleton_outline.png")
5
+ #enemy.set_draggable(True)
6
+
7
+
8
+ def clicked():
9
+ """
10
+ when the enemy is clicked:
11
+ change the enemy location with a fade out effect
12
+ """
13
+ for i in range(10):
14
+ yield 1/game.framerate
15
+ enemy.set_transparency(1-i/10) # print(1-i/10) if you find this confusing.
16
+ enemy.scale_by(0.9)
17
+
18
+ enemy.x = pysc.random_number(0, game.screen_width)
19
+ enemy.y = pysc.random_number(0, game.screen_height)
20
+
21
+ enemy.set_transparency(1)
22
+ enemy.set_scale(1)
23
+
24
+ enemy.when_this_sprite_clicked().add_handler(clicked)
25
+
26
+
27
+ def movement():
28
+ """
29
+ when_game_start:
30
+ the movement of the enemy
31
+ """
32
+
33
+ speed = 5
34
+ centre = (game.screen_width/2, game.screen_height/2)
35
+
36
+ while True:
37
+ yield 1/game.framerate
38
+
39
+ # get the distance to the mouse
40
+ mouse_x, mouse_y = pysc.get_mouse_pos()
41
+ distance_to_mouse = enemy.distance_to((mouse_x, mouse_y))
42
+
43
+ # enemy avoids the mouse when it is close to the mouse
44
+ if distance_to_mouse < 200:
45
+ enemy.point_towards_mouse()
46
+ enemy.direction += 180
47
+ enemy.move_indir(speed)
48
+
49
+ # otherwise, go to the centre of the screen
50
+ else:
51
+ enemy.point_towards(centre)
52
+ enemy.move_indir(speed)
53
+
54
+
55
+ enemy.when_game_start().add_handler(movement)
56
+
@@ -0,0 +1,47 @@
1
+ import pyscratch as pysc
2
+ import pygame
3
+ game = pysc.game
4
+
5
+ friend = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
6
+
7
+ def movement():
8
+ """
9
+ when_game_start:
10
+ the movement of the friend: always moving away from the curosr
11
+ """
12
+ centre = game.screen_width/2, game.screen_height/2
13
+ while True:
14
+ yield 1/game.framerate
15
+ mouse_x, mouse_y = pysc.get_mouse_pos()
16
+ if friend.distance_to((mouse_x, mouse_y)) < 200:
17
+ friend.point_towards_mouse()
18
+ friend.direction += 180
19
+ friend.move_indir(2)
20
+
21
+ else:
22
+ friend.point_towards(centre)
23
+ friend.move_indir(2)
24
+
25
+ friend.when_game_start().add_handler(movement)
26
+
27
+
28
+
29
+ def check_if_centred():
30
+ """
31
+ when_game_start:
32
+ move away when near the centre
33
+ """
34
+ centre = game.screen_width/2, game.screen_height/2
35
+ while True:
36
+ yield 1/game.framerate
37
+ if friend.distance_to(centre) < 50:
38
+ new_x = pysc.random_number(0, game.screen_width)
39
+ new_y = pysc.random_number(0, game.screen_height)
40
+
41
+ friend.x = new_x
42
+ friend.y = new_y
43
+
44
+ friend.when_game_start().add_handler(check_if_centred)
45
+
46
+
47
+
@@ -0,0 +1,9 @@
1
+ import pyscratch as pysc
2
+ import chest, enemy, friend
3
+ game = pysc.game
4
+
5
+
6
+ game.update_screen_mode((1024, 576))
7
+ game.start(show_mouse_position=True)
8
+
9
+
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ # import pygame
5
+ # font = pygame.font.Font('assets/Kenney Future.ttf', size=18)
6
+ # score_display = pysc.create_shared_data_display_sprite('score', font)
7
+
8
+ game['score'] = 0
9
+
10
+ # note that the score display is also a sprite
11
+ score_display = pysc.create_shared_data_display_sprite('score')
12
+ score_display.set_draggable(True)
13
+
14
+
15
+
16
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
17
+
18
+ # 1. Create a function that does the thing (any function name is fine)
19
+ def set_size_position():
20
+ """
21
+ when game start:
22
+ set the initial position of the chest
23
+ """
24
+ chest.set_scale(0.15)
25
+ chest.x = game.screen_width/2
26
+ chest.y = game.screen_height/2
27
+ game.move_to_back(chest)
28
+
29
+ # 2. Create an event object (any event name is fine)
30
+ #click_event = chest.when_this_sprite_clicked()
31
+
32
+ # 3. Attach the function to the event block
33
+ #click_event.add_handler(set_size_position)
34
+
35
+ # Or step 2 and 3 together in one line
36
+ #chest.when_this_sprite_clicked().add_handler(set_size_position)
37
+ chest.when_game_start().add_handler(set_size_position)
@@ -0,0 +1,76 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ enemy = pysc.create_single_costume_sprite("assets/fish_red_skeleton_outline.png")
5
+
6
+
7
+ def clicked():
8
+ """
9
+ when the enemy is clicked:
10
+ change the enemy location with a fade out effect
11
+ """
12
+ game['score'] += 10
13
+
14
+
15
+ for i in range(10):
16
+ yield 1/game.framerate
17
+ enemy.set_transparency(1-i/10) # print(1-i/10) if you find this confusing.
18
+ enemy.scale_by(0.9)
19
+
20
+ enemy.x = pysc.random_number(0, game.screen_width)
21
+ enemy.y = pysc.random_number(0, game.screen_height)
22
+
23
+ enemy.set_transparency(1)
24
+ enemy.set_scale(1)
25
+
26
+ enemy.when_this_sprite_clicked().add_handler(clicked)
27
+
28
+
29
+ def movement():
30
+ """
31
+ when_game_start:
32
+ the movement of the enemy
33
+ """
34
+
35
+ centre = (game.screen_width/2, game.screen_height/2)
36
+
37
+ while True:
38
+ yield 1/game.framerate
39
+
40
+ speed = 5+game['score']*0.1
41
+ speed = max(1, speed)
42
+
43
+
44
+ # get the distance to the mouse
45
+ mouse_x, mouse_y = pysc.get_mouse_pos()
46
+ distance_to_mouse = enemy.distance_to((mouse_x, mouse_y))
47
+
48
+ # enemy avoids the mouse when it is close to the mouse
49
+ if distance_to_mouse < 200:
50
+ enemy.point_towards_mouse()
51
+ enemy.direction += 180
52
+ enemy.move_indir(speed)
53
+
54
+ # otherwise, go to the centre of the screen
55
+ else:
56
+ enemy.point_towards(centre)
57
+ enemy.move_indir(speed)
58
+
59
+
60
+ enemy.when_game_start().add_handler(movement)
61
+
62
+
63
+
64
+ def reduce_score():
65
+ """
66
+ reduce the score for every 0.1 second the enemy is in the centre
67
+ """
68
+ centre = (game.screen_width/2, game.screen_height/2)
69
+
70
+ while True:
71
+ yield 0.1
72
+
73
+ if enemy.distance_to(centre) < 50:
74
+ game['score'] -= 1
75
+
76
+ enemy.when_game_start().add_handler(reduce_score)
@@ -0,0 +1,49 @@
1
+ import pyscratch as pysc
2
+ import pygame
3
+ game = pysc.game
4
+
5
+ friend = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
6
+
7
+ def movement():
8
+ """
9
+ when_game_start:
10
+ the movement of the friend: always moving away from the curosr
11
+ """
12
+ centre = game.screen_width/2, game.screen_height/2
13
+ while True:
14
+ yield 1/game.framerate
15
+ mouse_x, mouse_y = pysc.get_mouse_pos()
16
+ if friend.distance_to((mouse_x, mouse_y)) < 200:
17
+ friend.point_towards_mouse()
18
+ friend.direction += 180
19
+ friend.move_indir(2)
20
+
21
+ else:
22
+ friend.point_towards(centre)
23
+ friend.move_indir(2)
24
+
25
+ friend.when_game_start().add_handler(movement)
26
+
27
+
28
+
29
+ def check_if_centred():
30
+ """
31
+ when_game_start:
32
+ move away when near the centre
33
+ """
34
+ centre = game.screen_width/2, game.screen_height/2
35
+ while True:
36
+ yield 1/game.framerate
37
+ if friend.distance_to(centre) < 50:
38
+ game['score'] += 10
39
+
40
+ new_x = pysc.random_number(0, game.screen_width)
41
+ new_y = pysc.random_number(0, game.screen_height)
42
+
43
+ friend.x = new_x
44
+ friend.y = new_y
45
+
46
+ friend.when_game_start().add_handler(check_if_centred)
47
+
48
+
49
+
@@ -0,0 +1,9 @@
1
+ import pyscratch as pysc
2
+ import chest, enemy, friend
3
+ game = pysc.game
4
+
5
+
6
+ game.update_screen_mode((1024, 576))
7
+ game.start(show_mouse_position=True)
8
+
9
+
@@ -0,0 +1,37 @@
1
+ import pyscratch as pysc
2
+ from pyscratch import game
3
+
4
+ # import pygame
5
+ # font = pygame.font.Font('assets/Kenney Future.ttf', size=18)
6
+ # score_display = pysc.create_shared_data_display_sprite('score', font)
7
+
8
+ game['score'] = 0
9
+
10
+ # note that the score display is also a sprite
11
+ score_display = pysc.create_shared_data_display_sprite('score')
12
+ score_display.set_draggable(True)
13
+
14
+
15
+
16
+ chest = pysc.create_single_costume_sprite("assets/chatgpt-chest-open.png")
17
+
18
+ # 1. Create a function that does the thing (any function name is fine)
19
+ def set_size_position():
20
+ """
21
+ when game start:
22
+ set the initial position of the chest
23
+ """
24
+ chest.set_scale(0.15)
25
+ chest.x = game.screen_width/2
26
+ chest.y = game.screen_height/2
27
+ game.move_to_back(chest)
28
+
29
+ # 2. Create an event object (any event name is fine)
30
+ #click_event = chest.when_this_sprite_clicked()
31
+
32
+ # 3. Attach the function to the event block
33
+ #click_event.add_handler(set_size_position)
34
+
35
+ # Or step 2 and 3 together in one line
36
+ #chest.when_this_sprite_clicked().add_handler(set_size_position)
37
+ chest.when_game_start().add_handler(set_size_position)