pyscratch-pysc 1.0.4__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.
- 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 +66 -25
- pyscratch/sprite.py +12 -4
- {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.0.dist-info}/METADATA +5 -1
- pyscratch_pysc-2.0.0.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.0.dist-info}/WHEEL +0 -0
- {pyscratch_pysc-1.0.4.dist-info → pyscratch_pysc-2.0.0.dist-info}/top_level.txt +0 -0
@@ -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)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
game = pysc.game
|
3
|
+
|
4
|
+
|
5
|
+
def spwan_enemy_blue(data):
|
6
|
+
enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
|
7
|
+
|
8
|
+
enemy_blue.y = pysc.random_number(0, game.screen_height)
|
9
|
+
enemy_blue.x = 0
|
10
|
+
|
11
|
+
player1 = game['player1']
|
12
|
+
player2 = game['player2']
|
13
|
+
|
14
|
+
# a better way: break the loop when the sprite is removed
|
15
|
+
#while not enemy_blue.removed:
|
16
|
+
while True:
|
17
|
+
enemy_blue.x += 4
|
18
|
+
|
19
|
+
if enemy_blue.is_touching(player1):
|
20
|
+
enemy_blue.remove()
|
21
|
+
player1.scale_by(1.1)
|
22
|
+
|
23
|
+
if enemy_blue.is_touching(player2):
|
24
|
+
enemy_blue.remove()
|
25
|
+
player2.scale_by(1.1)
|
26
|
+
|
27
|
+
yield 1/game.framerate # must have an yield in a loop!
|
28
|
+
|
29
|
+
game.when_receive_message("spawn_enemy_blue").add_handler(spwan_enemy_blue)
|
30
|
+
|
31
|
+
def on_start():
|
32
|
+
while True:
|
33
|
+
game.broadcast_message("spawn_enemy_blue")
|
34
|
+
yield 1
|
35
|
+
|
36
|
+
game.when_game_start().add_handler(on_start)
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
game = pysc.game
|
3
|
+
|
4
|
+
|
5
|
+
def spwan_enemy_red(data):
|
6
|
+
enemy_red = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
|
7
|
+
|
8
|
+
enemy_red.y = pysc.random_number(0, game.screen_height)
|
9
|
+
enemy_red.x = 0
|
10
|
+
|
11
|
+
player1 = game['player1']
|
12
|
+
player2 = game['player2']
|
13
|
+
|
14
|
+
# a better way: break the loop when the sprite is removed
|
15
|
+
#while not enemy_blue.removed:
|
16
|
+
while True:
|
17
|
+
enemy_red.x += 4
|
18
|
+
|
19
|
+
if enemy_red.is_touching(player1):
|
20
|
+
enemy_red.remove()
|
21
|
+
game['P1 HP'] -= 1
|
22
|
+
|
23
|
+
if enemy_red.is_touching(player2):
|
24
|
+
enemy_red.remove()
|
25
|
+
game['P2 HP'] -= 1
|
26
|
+
|
27
|
+
yield 1/game.framerate # must have an yield in a loop!
|
28
|
+
|
29
|
+
game.when_receive_message("spwan_enemy_red").add_handler(spwan_enemy_red)
|
30
|
+
|
31
|
+
def on_start():
|
32
|
+
yield .5
|
33
|
+
while True:
|
34
|
+
game.broadcast_message("spwan_enemy_red")
|
35
|
+
yield 1
|
36
|
+
|
37
|
+
game.when_game_start().add_handler(on_start)
|
38
|
+
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
import enemy_red
|
5
|
+
import pygame
|
6
|
+
# start the game
|
7
|
+
WIN_WIDTH = 720 # change me
|
8
|
+
WIN_HEIGHT = 720 # change me
|
9
|
+
framerate = 60
|
10
|
+
|
11
|
+
pysc.game.update_screen_mode((WIN_WIDTH, WIN_HEIGHT))
|
12
|
+
pysc.game.start(framerate, use_frame_time=True)
|
@@ -0,0 +1,119 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch.sprite import create_shared_data_display_sprite
|
3
|
+
game = pysc.game
|
4
|
+
player1 = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
5
|
+
player2 = pysc.create_single_costume_sprite("assets/fish_orange_outline.png")
|
6
|
+
game['player1'] = player1
|
7
|
+
game['player2'] = player2
|
8
|
+
|
9
|
+
game['P1 HP'] = 10
|
10
|
+
game['P2 HP'] = 10
|
11
|
+
|
12
|
+
create_shared_data_display_sprite("P1 HP", position=(100, 100))
|
13
|
+
create_shared_data_display_sprite("P2 HP", position=(100, 200))
|
14
|
+
|
15
|
+
def move():
|
16
|
+
player1.set_rotation_style_left_right()
|
17
|
+
player2.set_rotation_style_left_right()
|
18
|
+
while True:
|
19
|
+
if pysc.is_key_pressed("d"):
|
20
|
+
player1.x += 4
|
21
|
+
player1.direction = 0
|
22
|
+
|
23
|
+
if pysc.is_key_pressed("a"):
|
24
|
+
player1.x -= 4
|
25
|
+
player1.direction = 180
|
26
|
+
|
27
|
+
if pysc.is_key_pressed("w"):
|
28
|
+
player1.y -= 4
|
29
|
+
|
30
|
+
if pysc.is_key_pressed("s"):
|
31
|
+
player1.y += 4
|
32
|
+
|
33
|
+
|
34
|
+
if pysc.is_key_pressed("right"):
|
35
|
+
player2.x += 4
|
36
|
+
player2.direction = 0
|
37
|
+
|
38
|
+
if pysc.is_key_pressed("left"):
|
39
|
+
player2.x -= 4
|
40
|
+
player2.direction = 180
|
41
|
+
|
42
|
+
if pysc.is_key_pressed("up"):
|
43
|
+
player2.y -= 4
|
44
|
+
|
45
|
+
if pysc.is_key_pressed("down"):
|
46
|
+
player2.y += 4
|
47
|
+
|
48
|
+
yield 1/60 # must have an yield in a loop!
|
49
|
+
|
50
|
+
# for the purpose of this tutorial,
|
51
|
+
# `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
|
52
|
+
game_start = player2.when_game_start()
|
53
|
+
game_start.add_handler(move)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
def move2():
|
59
|
+
player1.x = 200
|
60
|
+
player1.y = 400
|
61
|
+
|
62
|
+
player2.x = 400
|
63
|
+
player2.y = 200
|
64
|
+
|
65
|
+
while True:
|
66
|
+
if player1.is_touching(player2):
|
67
|
+
if player1.scale_factor == player2.scale_factor:
|
68
|
+
player1.hide()
|
69
|
+
player2.hide()
|
70
|
+
|
71
|
+
elif player1.scale_factor > player2.scale_factor:
|
72
|
+
player2.hide()
|
73
|
+
else:
|
74
|
+
player1.hide()
|
75
|
+
|
76
|
+
yield 1/60 # must have an yield in a loop!
|
77
|
+
|
78
|
+
# for the purpose of this tutorial,
|
79
|
+
# `player1.when_game_start()` and `player2.when_game_start()` are almost the same.
|
80
|
+
player2.when_game_start().add_handler(move2)
|
81
|
+
|
82
|
+
|
83
|
+
def message_event(data):
|
84
|
+
print("Received a message with data:", data)
|
85
|
+
player1.when_receive_message("message_topic1").add_handler(message_event)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
def player1_skill(updown):
|
91
|
+
|
92
|
+
game.broadcast_message("message_topic1", updown)
|
93
|
+
|
94
|
+
if updown == 'up':
|
95
|
+
for i in range(20):
|
96
|
+
player1.scale_by(1.025)
|
97
|
+
yield 1/game.framerate
|
98
|
+
|
99
|
+
if updown == 'down':
|
100
|
+
|
101
|
+
for i in range(20):
|
102
|
+
player1.scale_by(1/1.025)
|
103
|
+
yield 1/game.framerate
|
104
|
+
|
105
|
+
|
106
|
+
player1.when_key_pressed("space").add_handler(player1_skill)
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
def player_hp_check():
|
111
|
+
while True:
|
112
|
+
if game['P1 HP'] <= 0:
|
113
|
+
player1.hide()
|
114
|
+
|
115
|
+
if game['P2 HP'] <= 0:
|
116
|
+
player2.hide()
|
117
|
+
yield 1/game.framerate
|
118
|
+
game.when_game_start().add_handler(player_hp_check)
|
119
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
player = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
4
|
+
player.set_draggable(True)
|
5
|
+
|
6
|
+
# 1. Create a function that does the thing (any function name is fine)
|
7
|
+
def rotate_move():
|
8
|
+
|
9
|
+
player.direction += 45
|
10
|
+
player.move_indir(20)
|
11
|
+
yield 0.2
|
12
|
+
|
13
|
+
player.direction += 45
|
14
|
+
player.move_indir(20)
|
15
|
+
yield 0.2
|
16
|
+
|
17
|
+
player.direction += 45
|
18
|
+
player.move_indir(20)
|
19
|
+
yield 0.2
|
20
|
+
|
21
|
+
player.direction += 45
|
22
|
+
player.move_indir(20)
|
23
|
+
|
24
|
+
# 2. Create an event object (any event name is fine)
|
25
|
+
click_event = player.when_this_sprite_clicked()
|
26
|
+
|
27
|
+
# 3. Attach the function to the event block
|
28
|
+
click_event.add_handler(rotate_move)
|
29
|
+
|
30
|
+
# Or step 2 and 3 together in one line
|
31
|
+
#player.when_this_sprite_clicked().add_handler(rotate_move)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
player = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
4
|
+
player.set_draggable(True)
|
5
|
+
|
6
|
+
def scale_move():
|
7
|
+
|
8
|
+
player.scale_by(1.05)
|
9
|
+
player.move_indir(20)
|
10
|
+
yield 0.2
|
11
|
+
|
12
|
+
player.scale_by(1.05)
|
13
|
+
player.move_indir(20)
|
14
|
+
yield 0.2
|
15
|
+
|
16
|
+
player.scale_by(1.05)
|
17
|
+
player.move_indir(20)
|
18
|
+
yield 0.2
|
19
|
+
|
20
|
+
player.scale_by(1.05)
|
21
|
+
player.move_indir(20)
|
22
|
+
|
23
|
+
player.when_this_sprite_clicked().add_handler(scale_move)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
game = pysc.game
|
3
|
+
|
4
|
+
enemy = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
|
5
|
+
enemy.set_draggable(True) # optional: make the sprite draggable
|
6
|
+
|
7
|
+
def appear():
|
8
|
+
enemy.x = game.screen_width/2
|
9
|
+
enemy.y = game.screen_height/2
|
10
|
+
enemy.hide()
|
11
|
+
yield 3
|
12
|
+
enemy.show()
|
13
|
+
|
14
|
+
enemy.when_game_start().add_handler(appear)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
player = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
4
|
+
player.set_draggable(True)
|
5
|
+
|
6
|
+
def scale_move():
|
7
|
+
|
8
|
+
player.scale_by(1.05)
|
9
|
+
player.move_indir(20)
|
10
|
+
yield 0.2
|
11
|
+
|
12
|
+
player.scale_by(1.05)
|
13
|
+
player.move_indir(20)
|
14
|
+
yield 0.2
|
15
|
+
|
16
|
+
player.scale_by(1.05)
|
17
|
+
player.move_indir(20)
|
18
|
+
yield 0.2
|
19
|
+
|
20
|
+
player.scale_by(1.05)
|
21
|
+
player.move_indir(20)
|
22
|
+
|
23
|
+
player.when_this_sprite_clicked().add_handler(scale_move)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
game = pysc.game
|
3
|
+
|
4
|
+
enemy = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
|
5
|
+
enemy.set_draggable(True) # optional: make the sprite draggable
|
6
|
+
|
7
|
+
def appear():
|
8
|
+
enemy.x = game.screen_width/2
|
9
|
+
enemy.y = game.screen_height/2
|
10
|
+
enemy.hide()
|
11
|
+
yield 3
|
12
|
+
enemy.show()
|
13
|
+
|
14
|
+
enemy.when_game_start().add_handler(appear)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
player = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
4
|
+
player.set_draggable(True)
|
5
|
+
|
6
|
+
def scale_move():
|
7
|
+
|
8
|
+
player.scale_by(1.05)
|
9
|
+
player.move_indir(20)
|
10
|
+
yield 0.2
|
11
|
+
|
12
|
+
player.scale_by(1.05)
|
13
|
+
player.move_indir(20)
|
14
|
+
yield 0.2
|
15
|
+
|
16
|
+
player.scale_by(1.05)
|
17
|
+
player.move_indir(20)
|
18
|
+
yield 0.2
|
19
|
+
|
20
|
+
player.scale_by(1.05)
|
21
|
+
player.move_indir(20)
|
22
|
+
|
23
|
+
player.when_this_sprite_clicked().add_handler(scale_move)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
game = pysc.game
|
3
|
+
|
4
|
+
enemy = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
|
5
|
+
enemy.set_draggable(True) # optional: make the sprite draggable
|
6
|
+
|
7
|
+
def appear():
|
8
|
+
enemy.x = game.screen_width/2
|
9
|
+
enemy.y = game.screen_height/2
|
10
|
+
enemy.hide()
|
11
|
+
yield 3
|
12
|
+
enemy.show()
|
13
|
+
|
14
|
+
enemy.when_game_start().add_handler(appear)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player # Very important!
|
3
|
+
import enemy # Very important!
|
4
|
+
|
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)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
player = pysc.create_single_costume_sprite("assets/fish_brown_outline.png")
|
4
|
+
player.set_draggable(True)
|
5
|
+
|
6
|
+
def scale_move():
|
7
|
+
|
8
|
+
for i in range(20):
|
9
|
+
player.scale_by(1.025)
|
10
|
+
yield 0.03
|
11
|
+
|
12
|
+
for i in range(20):
|
13
|
+
player.scale_by(0.975)
|
14
|
+
yield 0.03
|
15
|
+
|
16
|
+
player.when_this_sprite_clicked().add_handler(scale_move)
|
17
|
+
|
18
|
+
|
19
|
+
# Remember: The function is the stack of scratch blocks without the event block at the top
|
20
|
+
def move():
|
21
|
+
while True: # the forever loop
|
22
|
+
if pysc.is_key_pressed("d"): # the sensing block: 'key [w] pressed'
|
23
|
+
player.x += 4 # the motion block: change y by [-4]
|
24
|
+
|
25
|
+
# the control block: wait [1/60] seconds
|
26
|
+
# because the frame rate is 60, this is basically to wait for one frame
|
27
|
+
yield 1/60 # must have an yield in a loop!
|
28
|
+
|
29
|
+
# Attach the function to the event
|
30
|
+
game_start = player.when_game_start()
|
31
|
+
game_start.add_handler(move)
|
32
|
+
|
33
|
+
# Or just in one line
|
34
|
+
#player.when_game_start().add_handler(move)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
|
3
|
+
spawn_button = pysc.create_single_costume_sprite("assets/button.png")
|
4
|
+
|
5
|
+
def spwan_enemy():
|
6
|
+
enemy_red = pysc.create_single_costume_sprite("assets/fish_red_outline.png")
|
7
|
+
enemy_blue = pysc.create_single_costume_sprite("assets/fish_blue_outline.png")
|
8
|
+
|
9
|
+
enemy_red.x = 0
|
10
|
+
enemy_red.y = pysc.game.screen_height/2
|
11
|
+
|
12
|
+
|
13
|
+
enemy_blue.x = pysc.game.screen_width
|
14
|
+
enemy_blue.y = pysc.game.screen_height/2
|
15
|
+
|
16
|
+
while True:
|
17
|
+
enemy_red.x += 4
|
18
|
+
enemy_blue.x -= 4
|
19
|
+
|
20
|
+
yield 1/60 # must have an yield in a loop!
|
21
|
+
|
22
|
+
spawn_button.when_this_sprite_clicked().add_handler(spwan_enemy)
|
23
|
+
|