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.
- assets/startup-assets/tutorial-steps/1-create-sprites/main.py +10 -0
- assets/startup-assets/tutorial-steps/1-create-sprites/player.py +5 -0
- assets/startup-assets/tutorial-steps/1-create-sprites-task/enemy.py +4 -0
- assets/startup-assets/tutorial-steps/1-create-sprites-task/main.py +11 -0
- assets/startup-assets/tutorial-steps/1-create-sprites-task/player.py +5 -0
- assets/startup-assets/tutorial-steps/2-basic-events/enemy.py +4 -0
- assets/startup-assets/tutorial-steps/2-basic-events/main.py +11 -0
- assets/startup-assets/tutorial-steps/2-basic-events/player.py +31 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task1/enemy.py +4 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task1/main.py +11 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task1/player.py +23 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task2/enemy.py +14 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task2/main.py +11 -0
- assets/startup-assets/tutorial-steps/2-basic-events-task2/player.py +23 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions/enemy.py +14 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions/main.py +11 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions/player.py +23 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task1/enemy.py +14 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task1/main.py +11 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task1/player.py +34 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task2/enemy.py +23 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task2/main.py +11 -0
- assets/startup-assets/tutorial-steps/3-loops-conditions-task2/player.py +41 -0
- assets/startup-assets/tutorial-steps/4-variables/enemy.py +23 -0
- assets/startup-assets/tutorial-steps/4-variables/main.py +11 -0
- assets/startup-assets/tutorial-steps/4-variables/player.py +59 -0
- assets/startup-assets/tutorial-steps/5-sprite-object/enemy.py +19 -0
- assets/startup-assets/tutorial-steps/5-sprite-object/main.py +11 -0
- assets/startup-assets/tutorial-steps/5-sprite-object/player.py +20 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task1/enemy.py +19 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task1/main.py +11 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task1/player.py +38 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task2/enemy.py +20 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task2/main.py +11 -0
- assets/startup-assets/tutorial-steps/5-sprite-object-task2/player.py +58 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites/enemy.py +32 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites/main.py +11 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites/player.py +59 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites-task/enemy.py +37 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites-task/main.py +11 -0
- assets/startup-assets/tutorial-steps/6-referencing-sprites-task/player.py +60 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events/enemy.py +37 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events/main.py +11 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events/player.py +83 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-msg/enemy.py +37 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-msg/main.py +11 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-msg/player.py +86 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-task/enemy.py +35 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-task/main.py +11 -0
- assets/startup-assets/tutorial-steps/7-parameterised-events-task/player.py +86 -0
- assets/startup-assets/tutorial-steps/8-backdrop-music/enemy.py +35 -0
- assets/startup-assets/tutorial-steps/8-backdrop-music/main.py +11 -0
- assets/startup-assets/tutorial-steps/8-backdrop-music/player.py +86 -0
- assets/startup-assets/tutorial-steps/9-polish/enemy.py +39 -0
- assets/startup-assets/tutorial-steps/9-polish/enemy_red.py +40 -0
- assets/startup-assets/tutorial-steps/9-polish/main.py +12 -0
- assets/startup-assets/tutorial-steps/9-polish/player.py +119 -0
- examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites/main.py +10 -0
- examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites/player.py +5 -0
- examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/enemy.py +4 -0
- examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/1-create-sprites-task/player.py +5 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/enemy.py +4 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events/player.py +31 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/enemy.py +4 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task1/player.py +23 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/enemy.py +14 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/2-basic-events-task2/player.py +23 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/enemy.py +14 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions/player.py +23 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/enemy.py +14 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task1/player.py +34 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/enemy.py +23 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/3-loops-conditions-task2/player.py +41 -0
- examples/fish/assets/startup-assets/tutorial-steps/4-variables/enemy.py +23 -0
- examples/fish/assets/startup-assets/tutorial-steps/4-variables/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/4-variables/player.py +59 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/enemy.py +19 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object/player.py +20 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/enemy.py +19 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task1/player.py +38 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/enemy.py +20 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/5-sprite-object-task2/player.py +58 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/enemy.py +32 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites/player.py +59 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/enemy.py +37 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/6-referencing-sprites-task/player.py +60 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/enemy.py +37 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events/player.py +83 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/enemy.py +37 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-msg/player.py +86 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/enemy.py +35 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/7-parameterised-events-task/player.py +86 -0
- examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/enemy.py +35 -0
- examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/main.py +11 -0
- examples/fish/assets/startup-assets/tutorial-steps/8-backdrop-music/player.py +86 -0
- examples/fish/assets/startup-assets/tutorial-steps/9-polish/enemy.py +39 -0
- examples/fish/assets/startup-assets/tutorial-steps/9-polish/enemy_red.py +40 -0
- examples/fish/assets/startup-assets/tutorial-steps/9-polish/main.py +12 -0
- examples/fish/assets/startup-assets/tutorial-steps/9-polish/player.py +119 -0
- examples/tutorial-day1/chest.py +21 -0
- examples/tutorial-day1/enemy.py +106 -0
- examples/tutorial-day1/friend.py +51 -0
- examples/tutorial-day1/in-steps/1-create-sprites/chest.py +5 -0
- examples/tutorial-day1/in-steps/1-create-sprites/enemy.py +5 -0
- examples/tutorial-day1/in-steps/1-create-sprites/main.py +9 -0
- examples/tutorial-day1/in-steps/2-basic-events/chest.py +24 -0
- examples/tutorial-day1/in-steps/2-basic-events/enemy.py +18 -0
- examples/tutorial-day1/in-steps/2-basic-events/main.py +9 -0
- examples/tutorial-day1/in-steps/3-flow/chest.py +25 -0
- examples/tutorial-day1/in-steps/3-flow/enemy.py +56 -0
- examples/tutorial-day1/in-steps/3-flow/friend.py +47 -0
- examples/tutorial-day1/in-steps/3-flow/main.py +9 -0
- examples/tutorial-day1/in-steps/4-variables/chest.py +37 -0
- examples/tutorial-day1/in-steps/4-variables/enemy.py +76 -0
- examples/tutorial-day1/in-steps/4-variables/friend.py +49 -0
- examples/tutorial-day1/in-steps/4-variables/main.py +9 -0
- examples/tutorial-day1/in-steps/5-backdrops/chest.py +37 -0
- examples/tutorial-day1/in-steps/5-backdrops/enemy.py +76 -0
- examples/tutorial-day1/in-steps/5-backdrops/friend.py +49 -0
- examples/tutorial-day1/in-steps/5-backdrops/main.py +26 -0
- examples/tutorial-day1/main.py +48 -0
- examples/tutorial-day1/target.py +14 -0
- examples/tutorial-day1/text.py +23 -0
- pyscratch/game_module.py +70 -27
- pyscratch/sprite.py +12 -4
- {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/METADATA +8 -1
- pyscratch_pysc-2.0.1.dist-info/RECORD +239 -0
- pyscratch_pysc-1.0.4.dist-info/RECORD +0 -101
- {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/WHEEL +0 -0
- {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.1.dist-info}/top_level.txt +0 -0
@@ -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,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,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,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,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)
|