pyscratch-pysc 1.0.3__tar.gz
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.
- pyscratch_pysc-1.0.3/PKG-INFO +37 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/enemy.py +130 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/enemy_bullets.py +230 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/main.py +11 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/old_verisons/enemy.py +226 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/old_verisons/game_start.py +6 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/old_verisons/main.py +50 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/old_verisons/player.py +76 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/player.py +89 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/player_bullets.py +34 -0
- pyscratch_pysc-1.0.3/assets/bullet_hell/setting.py +33 -0
- pyscratch_pysc-1.0.3/examples/animated_sprite/main.py +7 -0
- pyscratch_pysc-1.0.3/examples/animated_sprite/my_sprite.py +79 -0
- pyscratch_pysc-1.0.3/examples/bullet_hell/enemy.py +152 -0
- pyscratch_pysc-1.0.3/examples/bullet_hell/enemy_bullet.py +88 -0
- pyscratch_pysc-1.0.3/examples/bullet_hell/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/bullet_hell/player.py +39 -0
- pyscratch_pysc-1.0.3/examples/bullet_hell/player_bullet.py +31 -0
- pyscratch_pysc-1.0.3/examples/doodle_jump/main.py +9 -0
- pyscratch_pysc-1.0.3/examples/doodle_jump/platforms.py +51 -0
- pyscratch_pysc-1.0.3/examples/doodle_jump/player.py +52 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/enemy.py +130 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/enemy_bullets.py +230 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/main.py +11 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/old_verisons/enemy.py +226 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/old_verisons/game_start.py +6 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/old_verisons/main.py +50 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/old_verisons/player.py +76 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/player.py +89 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/player_bullets.py +34 -0
- pyscratch_pysc-1.0.3/examples/fish/assets/bullet_hell/setting.py +33 -0
- pyscratch_pysc-1.0.3/examples/fish/fish.py +67 -0
- pyscratch_pysc-1.0.3/examples/fish/main.py +4 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 1 - create a sprite/main.py +11 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 1 - create a sprite/player.py +5 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 2 - control a sprite/main.py +11 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 2 - control a sprite/player.py +42 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 3 - backdrops/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 3 - backdrops/player.py +33 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite/enemy.py +53 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite/player.py +32 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite (simple)/enemy.py +42 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite (simple)/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 4 - clone a sprite (simple)/player.py +32 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 5 - local variables/enemy.py +52 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 5 - local variables/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 5 - local variables/player.py +49 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 6 - shared variables/enemy.py +64 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 6 - shared variables/main.py +17 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 6 - shared variables/player.py +80 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 7 - Referencing other sprites/enemy.py +83 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 7 - Referencing other sprites/hearts.py +39 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 7 - Referencing other sprites/main.py +23 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 7 - Referencing other sprites/player.py +59 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 8 - sprite variables/enemy.py +98 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 8 - sprite variables/hearts.py +39 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 8 - sprite variables/main.py +22 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 8 - sprite variables/player.py +63 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 9 - messages/enemy.py +98 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 9 - messages/hearts.py +39 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 9 - messages/main.py +23 -0
- pyscratch_pysc-1.0.3/examples/getting-started/step 9 - messages/player.py +78 -0
- pyscratch_pysc-1.0.3/examples/perspective_background/main.py +14 -0
- pyscratch_pysc-1.0.3/examples/perspective_background/player.py +52 -0
- pyscratch_pysc-1.0.3/examples/perspective_background/trees.py +39 -0
- pyscratch_pysc-1.0.3/examples/simple_pong/ball.py +72 -0
- pyscratch_pysc-1.0.3/examples/simple_pong/left_paddle.py +36 -0
- pyscratch_pysc-1.0.3/examples/simple_pong/main.py +21 -0
- pyscratch_pysc-1.0.3/examples/simple_pong/right_paddle.py +37 -0
- pyscratch_pysc-1.0.3/examples/simple_pong/score_display.py +54 -0
- pyscratch_pysc-1.0.3/pyproject.toml +36 -0
- pyscratch_pysc-1.0.3/pyscratch/__init__.py +48 -0
- pyscratch_pysc-1.0.3/pyscratch/event.py +263 -0
- pyscratch_pysc-1.0.3/pyscratch/game_module.py +1589 -0
- pyscratch_pysc-1.0.3/pyscratch/helper.py +561 -0
- pyscratch_pysc-1.0.3/pyscratch/sprite.py +1920 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/left_panel/frame_preview_card.py +238 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/left_panel/frame_preview_panel.py +42 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main.py +18 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/animation_display.py +77 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/frame_bin.py +33 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/play_edit_ui.py +64 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/set_as_sprite_folder.py +22 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/sprite_edit_ui.py +174 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/main_panel/warning_message.py +25 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/back_button.py +35 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/cut_button.py +32 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/cut_parameter_fitting.py +152 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/cut_parameters.py +42 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/file_display.py +84 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/file_display_area.py +57 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/spritesheet_view.py +262 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/right_panel/ss_select_corner.py +208 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/settings.py +14 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/utils/input_box.py +235 -0
- pyscratch_pysc-1.0.3/pyscratch/tools/sprite_preview/utils/render_wrapped_file_name.py +86 -0
- pyscratch_pysc-1.0.3/pyscratch_pysc.egg-info/PKG-INFO +37 -0
- pyscratch_pysc-1.0.3/pyscratch_pysc.egg-info/SOURCES.txt +105 -0
- pyscratch_pysc-1.0.3/pyscratch_pysc.egg-info/dependency_links.txt +1 -0
- pyscratch_pysc-1.0.3/pyscratch_pysc.egg-info/requires.txt +5 -0
- pyscratch_pysc-1.0.3/pyscratch_pysc.egg-info/top_level.txt +7 -0
- pyscratch_pysc-1.0.3/readme.md +18 -0
- pyscratch_pysc-1.0.3/setup.cfg +4 -0
- pyscratch_pysc-1.0.3/setup.py +13 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pyscratch-pysc
|
3
|
+
Version: 1.0.3
|
4
|
+
Summary: A Python game development framework designed to provide an easy transitioning from Scratch to Python
|
5
|
+
Author-email: Daniel Ka-Wa Chan <kwdaniel525@protonmail.com>
|
6
|
+
License: MIT
|
7
|
+
Project-URL: Homepage, https://kwdchan.github.io/pyscratch/
|
8
|
+
Project-URL: Repository, https://github.com/kwdChan/pyscratch
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.10
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
Requires-Dist: pymunk<7
|
15
|
+
Requires-Dist: pygame<3
|
16
|
+
Requires-Dist: numpy<3
|
17
|
+
Requires-Dist: typing_extensions
|
18
|
+
Requires-Dist: pillow<12
|
19
|
+
|
20
|
+
# PyScratch
|
21
|
+
For more information, see: https://kwdchan.github.io/pyscratch/
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
## Change History
|
29
|
+
|
30
|
+
### 07 Sep 2025
|
31
|
+
**v1.0.3**
|
32
|
+
Added undeclared dependency: Pillow
|
33
|
+
Specified the versions of the dependencies
|
34
|
+
|
35
|
+
### Jul 2025
|
36
|
+
**v1.0.0**
|
37
|
+
The first version
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import random
|
3
|
+
from setting import *
|
4
|
+
from enemy_bullets import *
|
5
|
+
def spawn_line():
|
6
|
+
n = 10
|
7
|
+
margin = 20
|
8
|
+
itv = (SCREEN_WIDTH-margin*2)//(n-1)
|
9
|
+
y=0
|
10
|
+
for i in range(n):
|
11
|
+
|
12
|
+
x = itv*i+margin
|
13
|
+
|
14
|
+
create_standard_enemy((x, y), 90, False, False, 5, 1000)
|
15
|
+
|
16
|
+
|
17
|
+
def spawn_6_side_entry(_):
|
18
|
+
|
19
|
+
pos1 = (0, 200)
|
20
|
+
pos2 = (0, 400)
|
21
|
+
pos3 = (0, 600)
|
22
|
+
|
23
|
+
pos4 = (SCREEN_WIDTH, 200)
|
24
|
+
pos5 = (SCREEN_WIDTH, 400)
|
25
|
+
pos6 = (SCREEN_WIDTH, 600)
|
26
|
+
|
27
|
+
|
28
|
+
create_standard_enemy(pos1, 45, True, False, 5)
|
29
|
+
create_standard_enemy(pos2, 45, True, False, 5)
|
30
|
+
create_standard_enemy(pos3, 45, True, False, 5)
|
31
|
+
|
32
|
+
|
33
|
+
create_standard_enemy(pos4, 90+45, True, False, 5)
|
34
|
+
create_standard_enemy(pos5, 90+45, True, False, 5)
|
35
|
+
create_standard_enemy(pos6, 90+45,True, False, 5)
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def spawn_random(_):
|
43
|
+
pos = pysc.helper.random_number(0, SCREEN_WIDTH), 0
|
44
|
+
speed = pysc.helper.random_number(9, 10)
|
45
|
+
rotation = pysc.helper.random_number(90-10, 90+10)
|
46
|
+
|
47
|
+
create_standard_enemy(pos, rotation, False, False, speed)
|
48
|
+
|
49
|
+
|
50
|
+
def spawn_kamikaze(_):
|
51
|
+
pos = pysc.helper.random_number(0, SCREEN_WIDTH), 0
|
52
|
+
speed = pysc.helper.random_number(7, 12)
|
53
|
+
|
54
|
+
create_standard_enemy(pos, 90, False, True, speed, bullet_period=1000000)
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
def create_standard_enemy(position, rotation, start_point, pointing_to_player, speed, bullet_period=150):
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
# create the sprite
|
63
|
+
enemy_sprite = pysc.create_rect_sprite((255, 0, 0), 50, 30, pos=position)
|
64
|
+
#pysc.game.add_sprite(enemy_sprite)
|
65
|
+
enemy_sprite.set_collision_type(ENEMY_TYPE)
|
66
|
+
|
67
|
+
enemy_sprite.add_rotation(rotation)
|
68
|
+
|
69
|
+
if start_point:
|
70
|
+
enemy_sprite.point_towards_sprite(pysc.game.shared_data['player'])
|
71
|
+
|
72
|
+
|
73
|
+
# behaviour
|
74
|
+
## 1. move a straight line
|
75
|
+
## 2. shoot bullets (of type based on the level) at a constant interval (based on the level)
|
76
|
+
## 3. hitting a player
|
77
|
+
## 4. hit by player buller
|
78
|
+
## 5. destroyed when leaving the screen
|
79
|
+
|
80
|
+
|
81
|
+
## 1. move a straight line
|
82
|
+
movement_event = enemy_sprite.when_timer_reset(20)
|
83
|
+
movement_event.add_handler(lambda x: enemy_sprite.move_indir(speed))
|
84
|
+
|
85
|
+
if pointing_to_player:
|
86
|
+
movement_event.add_handler(
|
87
|
+
lambda x: enemy_sprite.point_towards_sprite(pysc.game.shared_data['player'])
|
88
|
+
)
|
89
|
+
|
90
|
+
|
91
|
+
## 2. shoot bullets (of type based on the level) at a constant interval (based on the level)
|
92
|
+
bullet_event = enemy_sprite.when_timer_reset(bullet_period).add_handler(lambda x: create_straight_bullet((enemy_sprite.x, enemy_sprite.y), enemy_sprite.get_rotation()))
|
93
|
+
|
94
|
+
|
95
|
+
## 3. hitting a player
|
96
|
+
when_hit_player = pysc.game.when_condition_met(lambda: game.is_touching(pysc.game, enemy_sprite, pysc.game.shared_data['player']), repeats=1, associated_sprites=[enemy_sprite])
|
97
|
+
when_hit_player.add_handler(lambda x: pysc.game.broadcast_message('player_health', -1))
|
98
|
+
|
99
|
+
## 4. hit by player buller
|
100
|
+
when_hit_by_player_bullet = pysc.game._create_type2type_collision_trigger(PLAYER_BULLET_TYPE, ENEMY_TYPE, associated_sprites=[enemy_sprite])
|
101
|
+
|
102
|
+
## 5. destroyed when leaving the screen
|
103
|
+
when_leaving_screen =pysc.game.when_condition_met(lambda: (enemy_sprite.y > SCREEN_HEIGHT), repeats=1, associated_sprites=[enemy_sprite])
|
104
|
+
|
105
|
+
### callback for 3, 4, 5
|
106
|
+
def destroy(x):
|
107
|
+
#movement_event.remove()
|
108
|
+
#bullet_event.remove()
|
109
|
+
#when_hit_player.remove()
|
110
|
+
#when_hit_by_player_bullet.remove()
|
111
|
+
#when_leaving_screen.remove()
|
112
|
+
pysc.game._remove_sprite(enemy_sprite)
|
113
|
+
|
114
|
+
def check_collision(a):
|
115
|
+
if enemy_sprite._shape in a.shapes:
|
116
|
+
destroy(None)
|
117
|
+
|
118
|
+
when_hit_by_player_bullet.add_handler(check_collision)
|
119
|
+
when_hit_player.add_handler(destroy)
|
120
|
+
when_leaving_screen.add_handler(destroy)
|
121
|
+
|
122
|
+
|
123
|
+
# testing only
|
124
|
+
pysc.game.when_timer_reset(500, 20).add_handler(spawn_random)
|
125
|
+
|
126
|
+
|
127
|
+
pysc.game.when_timer_reset(3000, 1).add_handler(spawn_6_side_entry)
|
128
|
+
pysc.game.when_timer_reset(2000, 1).add_handler(spawn_line)
|
129
|
+
|
130
|
+
|
@@ -0,0 +1,230 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import random
|
3
|
+
from setting import *
|
4
|
+
import numpy as np
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
def create_bullet_attracted(position):
|
9
|
+
bullet = pysc.Sprite(frames, "spin", position)
|
10
|
+
|
11
|
+
bullet.set_scale(2.3)
|
12
|
+
#pysc.game.add_sprite(bullet)
|
13
|
+
speed = random.random()*15+5
|
14
|
+
|
15
|
+
bullet.point_towards_sprite(pysc.game.shared_data['player'])
|
16
|
+
|
17
|
+
|
18
|
+
movement_event = pysc.game.when_timer_reset(20).add_handler(lambda x: bullet.move_indir(speed))
|
19
|
+
following_event = pysc.game.when_timer_reset(200, 5).add_handler(lambda x: bullet.point_towards_sprite(pysc.game.shared_data['player']))
|
20
|
+
|
21
|
+
frame_event = pysc.game.when_timer_reset(200).add_handler(lambda x: bullet.next_frame())
|
22
|
+
hitting_player_event = pysc.game._create_specific_collision_trigger(bullet, pysc.game.shared_data['player'])
|
23
|
+
|
24
|
+
|
25
|
+
def explode_and_destroy(a):
|
26
|
+
bullet.set_animation('star_explosion')
|
27
|
+
pysc.game.broadcast_message('player_health', -1)
|
28
|
+
movement_event.remove()
|
29
|
+
pysc.game.when_timer_reset(200, 1).add_handler(destory)
|
30
|
+
|
31
|
+
|
32
|
+
def destory(x):
|
33
|
+
movement_event.remove()
|
34
|
+
frame_event.remove()
|
35
|
+
following_event.remove()
|
36
|
+
hitting_player_event.remove()
|
37
|
+
pysc.game._remove_sprite(bullet)
|
38
|
+
|
39
|
+
when_exit_screen = pysc.game.when_condition_met(lambda: bullet.y > SCREEN_HEIGHT, repeats=1)
|
40
|
+
when_exit_screen.add_handler(destory)
|
41
|
+
hitting_player_event.add_handler(explode_and_destroy)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
def create_bullet_start_pointing(position, _):
|
46
|
+
|
47
|
+
bullet = pysc.Sprite(frames, "spin", position)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
bullet.point_towards_sprite(pysc.game.shared_data['player'])
|
52
|
+
bullet.set_scale(2.3)
|
53
|
+
#pysc.game.add_sprite(bullet)
|
54
|
+
speed = random.random()*15+5
|
55
|
+
bullet.point_towards_sprite(pysc.game.shared_data['player'])
|
56
|
+
|
57
|
+
|
58
|
+
movement_event = bullet.when_timer_reset(20).add_handler(lambda x: bullet.move_indir(speed))
|
59
|
+
#movement_event = pysc.game.create_timer_trigger(20).on_reset(lambda x: bullet.move_across_dir((random.random()-0.5)*speed*0.3))
|
60
|
+
|
61
|
+
|
62
|
+
frame_event = bullet.when_timer_reset(200).add_handler(lambda x: bullet.next_frame())
|
63
|
+
hitting_player_event = pysc.game._create_specific_collision_trigger(bullet, pysc.game.shared_data['player'])
|
64
|
+
|
65
|
+
|
66
|
+
def explode_and_destroy(a):
|
67
|
+
bullet.set_animation('star_explosion')
|
68
|
+
pysc.game.broadcast_message('player_health', -1)
|
69
|
+
movement_event.remove()
|
70
|
+
pysc.game.when_timer_reset(200, 1).add_handler(destory)
|
71
|
+
|
72
|
+
|
73
|
+
def destory(x):
|
74
|
+
movement_event.remove()
|
75
|
+
frame_event.remove()
|
76
|
+
hitting_player_event.remove()
|
77
|
+
pysc.game._remove_sprite(bullet)
|
78
|
+
|
79
|
+
when_exit_screen = pysc.game.when_condition_met(lambda: bullet.y > SCREEN_HEIGHT, repeats=1)
|
80
|
+
when_exit_screen.add_handler(destory)
|
81
|
+
hitting_player_event.add_handler(explode_and_destroy)
|
82
|
+
pass
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def create_bullet_move_sine(position, rotation):
|
88
|
+
bullet = pysc.Sprite(frames, "square_bullets", position)
|
89
|
+
bullet.set_scale(2.3)
|
90
|
+
#pysc.game.add_sprite(bullet)
|
91
|
+
bullet.set_rotation(rotation+90)
|
92
|
+
#speed = random.random()*15+5
|
93
|
+
speed = 10
|
94
|
+
|
95
|
+
|
96
|
+
bullet.sprite_data['phase'] = 0
|
97
|
+
movement_event = pysc.game.when_timer_reset(30)
|
98
|
+
def move(x):
|
99
|
+
bullet.sprite_data['phase']+=.1
|
100
|
+
angle = np.tanh(np.cos(.6*bullet.sprite_data['phase']))
|
101
|
+
|
102
|
+
|
103
|
+
bullet.add_rotation(angle)
|
104
|
+
|
105
|
+
bullet.move_indir(speed)
|
106
|
+
|
107
|
+
|
108
|
+
movement_event.add_handler(move)
|
109
|
+
|
110
|
+
|
111
|
+
frame_event = pysc.game.when_timer_reset(200).add_handler(lambda x: bullet.next_frame())
|
112
|
+
hitting_player_event = pysc.game._create_specific_collision_trigger(bullet, pysc.game.shared_data['player'])
|
113
|
+
|
114
|
+
|
115
|
+
def explode_and_destroy(a):
|
116
|
+
bullet.set_animation('star_explosion')
|
117
|
+
pysc.game.broadcast_message('player_health', -1)
|
118
|
+
movement_event.remove()
|
119
|
+
pysc.game.when_timer_reset(200, 1).add_handler(destory)
|
120
|
+
|
121
|
+
|
122
|
+
def destory(x):
|
123
|
+
movement_event.remove()
|
124
|
+
frame_event.remove()
|
125
|
+
hitting_player_event.remove()
|
126
|
+
pysc.game._remove_sprite(bullet)
|
127
|
+
|
128
|
+
when_exit_screen = pysc.game.when_condition_met(lambda: (bullet.y > SCREEN_HEIGHT) or (bullet.y < 0) or (bullet.x <0) or (bullet.x>SCREEN_WIDTH) , repeats=1)
|
129
|
+
when_exit_screen.add_handler(destory)
|
130
|
+
hitting_player_event.add_handler(explode_and_destroy)
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def create_straight_bullet(position, rotation):
|
137
|
+
"""
|
138
|
+
a bullet that moves a straight line
|
139
|
+
"""
|
140
|
+
|
141
|
+
bullet = pysc.Sprite(frames, "spin", position)
|
142
|
+
bullet.add_rotation(rotation)
|
143
|
+
bullet.set_scale(2.3)
|
144
|
+
#pysc.game.add_sprite(bullet)
|
145
|
+
speed = random.random()*15+5
|
146
|
+
#speed = 15
|
147
|
+
|
148
|
+
movement_event = bullet.when_timer_reset(20).add_handler(lambda x: bullet.move_indir(speed))
|
149
|
+
frame_event = bullet.when_timer_reset(200).add_handler(lambda x: bullet.next_frame())
|
150
|
+
hitting_player_event = bullet.create_specific_collision_trigger(pysc.game.shared_data['player'])
|
151
|
+
when_exit_screen = bullet.when_condition_met(lambda: (bullet.y > SCREEN_HEIGHT) or (bullet.y < 0) or (bullet.x <0) or (bullet.x>SCREEN_WIDTH), repeats=1,)
|
152
|
+
|
153
|
+
|
154
|
+
def explode_and_destroy(a):
|
155
|
+
bullet.set_animation('star_explosion')
|
156
|
+
pysc.game.broadcast_message('player_health', -1)
|
157
|
+
movement_event.remove()
|
158
|
+
pysc.game.when_timer_reset(200, 1).add_handler(destory)
|
159
|
+
|
160
|
+
|
161
|
+
def destory(x):
|
162
|
+
#movement_event.remove()
|
163
|
+
#frame_event.remove()
|
164
|
+
#hitting_player_event.remove()
|
165
|
+
#when_exit_screen.remove()
|
166
|
+
pysc.game._remove_sprite(bullet)
|
167
|
+
|
168
|
+
when_exit_screen.add_handler(destory)
|
169
|
+
hitting_player_event.add_handler(explode_and_destroy)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
def create_exploding_bullet(position, rotation):
|
176
|
+
"""
|
177
|
+
a bullet that explode after 1.2 second
|
178
|
+
"""
|
179
|
+
|
180
|
+
bullet = pysc.Sprite(frames, "spin", position)
|
181
|
+
bullet.add_rotation(rotation)
|
182
|
+
bullet.set_scale(2.3)
|
183
|
+
#pysc.game.add_sprite(bullet)
|
184
|
+
|
185
|
+
speed = 7
|
186
|
+
|
187
|
+
movement_event = pysc.game.when_timer_reset(20, associated_sprites=[bullet]).add_handler(lambda x: bullet.move_indir(speed))
|
188
|
+
frame_event = pysc.game.when_timer_reset(200, associated_sprites=[bullet]).add_handler(lambda x: bullet.next_frame())
|
189
|
+
hitting_player_event = pysc.game._create_specific_collision_trigger(bullet, pysc.game.shared_data['player'])
|
190
|
+
exit_screen_event = pysc.game.when_condition_met(lambda: bullet.y > SCREEN_HEIGHT, repeats=1, associated_sprites=[bullet])
|
191
|
+
explosion_event = pysc.game.when_timer_reset(1200,1, associated_sprites=[bullet])
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
def hit_and_destroy(a):
|
196
|
+
bullet.set_animation('star_explosion')
|
197
|
+
movement_event.remove()
|
198
|
+
pysc.game.when_timer_reset(200, 1).add_handler(destory)
|
199
|
+
|
200
|
+
def spawn_sub_bullets(_):
|
201
|
+
for i in range(12):
|
202
|
+
create_straight_bullet(bullet._body.position, rotation=i*30)
|
203
|
+
|
204
|
+
def delayed_spawn_sub_bullets(_):
|
205
|
+
pysc.game.when_timer_reset(200, 1).add_handler(spawn_sub_bullets)
|
206
|
+
|
207
|
+
|
208
|
+
def destory(x):
|
209
|
+
|
210
|
+
|
211
|
+
#movement_event.remove()
|
212
|
+
#frame_event.remove()
|
213
|
+
#hitting_player_event.remove()
|
214
|
+
#exit_screen_event.remove()
|
215
|
+
#explosion_event.remove()
|
216
|
+
pysc.game._remove_sprite(bullet)
|
217
|
+
|
218
|
+
exit_screen_event.add_handler(destory)
|
219
|
+
hitting_player_event.add_handler(hit_and_destroy)
|
220
|
+
hitting_player_event.add_handler(lambda: pysc.game.broadcast_message('player_health', -1))
|
221
|
+
explosion_event.add_handler(delayed_spawn_sub_bullets)
|
222
|
+
explosion_event.add_handler(hit_and_destroy)
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
create_bullet_move_sine((355, 0), 90)
|
228
|
+
|
229
|
+
|
230
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import player, player_bullets, enemy
|
3
|
+
|
4
|
+
from setting import *
|
5
|
+
|
6
|
+
pysc.game.update_screen_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
7
|
+
|
8
|
+
pysc.create_edge_sprites()
|
9
|
+
#pysc.game.shared_data['enemy_level'] = 0
|
10
|
+
|
11
|
+
pysc.game.start(60, 60, False, event_count=True)
|