pyscratch-pysc 1.0.3__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/bullet_hell/enemy.py +130 -0
- assets/bullet_hell/enemy_bullets.py +230 -0
- assets/bullet_hell/main.py +11 -0
- assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- assets/bullet_hell/old_verisons/enemy.py +226 -0
- assets/bullet_hell/old_verisons/game_start.py +6 -0
- assets/bullet_hell/old_verisons/main.py +50 -0
- assets/bullet_hell/old_verisons/player.py +76 -0
- assets/bullet_hell/player.py +89 -0
- assets/bullet_hell/player_bullets.py +34 -0
- assets/bullet_hell/setting.py +33 -0
- examples/animated_sprite/main.py +7 -0
- examples/animated_sprite/my_sprite.py +79 -0
- examples/bullet_hell/enemy.py +152 -0
- examples/bullet_hell/enemy_bullet.py +88 -0
- examples/bullet_hell/main.py +17 -0
- examples/bullet_hell/player.py +39 -0
- examples/bullet_hell/player_bullet.py +31 -0
- examples/doodle_jump/main.py +9 -0
- examples/doodle_jump/platforms.py +51 -0
- examples/doodle_jump/player.py +52 -0
- examples/fish/assets/bullet_hell/enemy.py +130 -0
- examples/fish/assets/bullet_hell/enemy_bullets.py +230 -0
- examples/fish/assets/bullet_hell/main.py +11 -0
- examples/fish/assets/bullet_hell/old_verisons/bullet_hell.py +379 -0
- examples/fish/assets/bullet_hell/old_verisons/enemy.py +226 -0
- examples/fish/assets/bullet_hell/old_verisons/game_start.py +6 -0
- examples/fish/assets/bullet_hell/old_verisons/main.py +50 -0
- examples/fish/assets/bullet_hell/old_verisons/player.py +76 -0
- examples/fish/assets/bullet_hell/player.py +89 -0
- examples/fish/assets/bullet_hell/player_bullets.py +34 -0
- examples/fish/assets/bullet_hell/setting.py +33 -0
- examples/fish/fish.py +67 -0
- examples/fish/main.py +4 -0
- examples/getting-started/step 1 - create a sprite/main.py +11 -0
- examples/getting-started/step 1 - create a sprite/player.py +5 -0
- examples/getting-started/step 2 - control a sprite/main.py +11 -0
- examples/getting-started/step 2 - control a sprite/player.py +42 -0
- examples/getting-started/step 3 - backdrops/main.py +17 -0
- examples/getting-started/step 3 - backdrops/player.py +33 -0
- examples/getting-started/step 4 - clone a sprite/enemy.py +53 -0
- examples/getting-started/step 4 - clone a sprite/main.py +17 -0
- examples/getting-started/step 4 - clone a sprite/player.py +32 -0
- examples/getting-started/step 4 - clone a sprite (simple)/enemy.py +42 -0
- examples/getting-started/step 4 - clone a sprite (simple)/main.py +17 -0
- examples/getting-started/step 4 - clone a sprite (simple)/player.py +32 -0
- examples/getting-started/step 5 - local variables/enemy.py +52 -0
- examples/getting-started/step 5 - local variables/main.py +17 -0
- examples/getting-started/step 5 - local variables/player.py +49 -0
- examples/getting-started/step 6 - shared variables/enemy.py +64 -0
- examples/getting-started/step 6 - shared variables/main.py +17 -0
- examples/getting-started/step 6 - shared variables/player.py +80 -0
- examples/getting-started/step 7 - Referencing other sprites/enemy.py +83 -0
- examples/getting-started/step 7 - Referencing other sprites/hearts.py +39 -0
- examples/getting-started/step 7 - Referencing other sprites/main.py +23 -0
- examples/getting-started/step 7 - Referencing other sprites/player.py +59 -0
- examples/getting-started/step 8 - sprite variables/enemy.py +98 -0
- examples/getting-started/step 8 - sprite variables/hearts.py +39 -0
- examples/getting-started/step 8 - sprite variables/main.py +22 -0
- examples/getting-started/step 8 - sprite variables/player.py +63 -0
- examples/getting-started/step 9 - messages/enemy.py +98 -0
- examples/getting-started/step 9 - messages/hearts.py +39 -0
- examples/getting-started/step 9 - messages/main.py +23 -0
- examples/getting-started/step 9 - messages/player.py +78 -0
- examples/perspective_background/main.py +14 -0
- examples/perspective_background/player.py +52 -0
- examples/perspective_background/trees.py +39 -0
- examples/simple_pong/ball.py +72 -0
- examples/simple_pong/left_paddle.py +36 -0
- examples/simple_pong/main.py +21 -0
- examples/simple_pong/right_paddle.py +37 -0
- examples/simple_pong/score_display.py +54 -0
- pyscratch/__init__.py +48 -0
- pyscratch/event.py +263 -0
- pyscratch/game_module.py +1589 -0
- pyscratch/helper.py +561 -0
- pyscratch/sprite.py +1920 -0
- pyscratch/tools/sprite_preview/left_panel/frame_preview_card.py +238 -0
- pyscratch/tools/sprite_preview/left_panel/frame_preview_panel.py +42 -0
- pyscratch/tools/sprite_preview/main.py +18 -0
- pyscratch/tools/sprite_preview/main_panel/animation_display.py +77 -0
- pyscratch/tools/sprite_preview/main_panel/frame_bin.py +33 -0
- pyscratch/tools/sprite_preview/main_panel/play_edit_ui.py +64 -0
- pyscratch/tools/sprite_preview/main_panel/set_as_sprite_folder.py +22 -0
- pyscratch/tools/sprite_preview/main_panel/sprite_edit_ui.py +174 -0
- pyscratch/tools/sprite_preview/main_panel/warning_message.py +25 -0
- pyscratch/tools/sprite_preview/right_panel/back_button.py +35 -0
- pyscratch/tools/sprite_preview/right_panel/cut_button.py +32 -0
- pyscratch/tools/sprite_preview/right_panel/cut_parameter_fitting.py +152 -0
- pyscratch/tools/sprite_preview/right_panel/cut_parameters.py +42 -0
- pyscratch/tools/sprite_preview/right_panel/file_display.py +84 -0
- pyscratch/tools/sprite_preview/right_panel/file_display_area.py +57 -0
- pyscratch/tools/sprite_preview/right_panel/spritesheet_view.py +262 -0
- pyscratch/tools/sprite_preview/right_panel/ss_select_corner.py +208 -0
- pyscratch/tools/sprite_preview/settings.py +14 -0
- pyscratch/tools/sprite_preview/utils/input_box.py +235 -0
- pyscratch/tools/sprite_preview/utils/render_wrapped_file_name.py +86 -0
- pyscratch_pysc-1.0.3.dist-info/METADATA +37 -0
- pyscratch_pysc-1.0.3.dist-info/RECORD +101 -0
- pyscratch_pysc-1.0.3.dist-info/WHEEL +5 -0
- pyscratch_pysc-1.0.3.dist-info/top_level.txt +3 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
import random
|
2
|
+
import re, sys
|
3
|
+
import numpy as np
|
4
|
+
import pymunk
|
5
|
+
from pyscratch import game
|
6
|
+
from pyscratch.sprite import Sprite, create_rect, create_rect_sprite
|
7
|
+
from pyscratch.helper import _get_frame_dict
|
8
|
+
from pyscratch.game_module import Game
|
9
|
+
from main import *
|
10
|
+
from enemy import *
|
11
|
+
|
12
|
+
def game_start(data):
|
13
|
+
|
14
|
+
player = create_rect_sprite((0, 0, 255), 50, 30, pos=(720//2, 1200))
|
15
|
+
game._add_sprite(player)
|
16
|
+
game.create_edges()
|
17
|
+
player.set_collision_type(PLAYER_TYPE)
|
18
|
+
|
19
|
+
|
20
|
+
healthbar_red = create_rect((255, 0, 0), 60, 50)
|
21
|
+
|
22
|
+
healthbar_empty = create_rect_sprite((255, 255, 255), 60, 5, pos=(0,0))
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
game.shared_data['player'] = player
|
27
|
+
game.shared_data['inaccuracy'] = 5
|
28
|
+
|
29
|
+
player.sprite_data['health'] = 10
|
30
|
+
|
31
|
+
|
32
|
+
game._add_sprite(healthbar_empty)
|
33
|
+
healthbar_empty.lock_to(player, (0,-30))
|
34
|
+
healthbar_empty.blit(healthbar_red, (0,0))
|
35
|
+
|
36
|
+
|
37
|
+
#game.create_timer_trigger(100, 20).on_reset(lambda x: create_bullet_move_sine((355, 1), 0))
|
38
|
+
game.when_timer_reset(100, 20).on_reset(lambda x: create_bullet_attracted((355, 300)))
|
39
|
+
#game.create_timer_trigger(100, 100).on_reset(lambda x: create_bullet_type1((100, 100), 90))
|
40
|
+
|
41
|
+
#game.create_timer_trigger(100, 10)
|
42
|
+
|
43
|
+
#game.create_timer_trigger(1200).on_reset(lambda x: shoot_player_bullet((player.x, player.y), game.shared_data['inaccuracy']))
|
44
|
+
#game.create_timer_trigger(500, 30).on_reset(lambda x: create_enemy_type1((random.random()*WIDTH, 0)))
|
45
|
+
|
46
|
+
|
47
|
+
def run_forever(_):
|
48
|
+
if game.is_key_pressed(['w']):
|
49
|
+
player.move_xy((0, -5))
|
50
|
+
|
51
|
+
if game.is_key_pressed(['s']):
|
52
|
+
player.move_xy((0, 5))
|
53
|
+
|
54
|
+
if game.is_key_pressed(['a']):
|
55
|
+
player.move_xy((-5, 0))
|
56
|
+
|
57
|
+
if game.is_key_pressed(['d']):
|
58
|
+
player.move_xy((5, 0))
|
59
|
+
|
60
|
+
player.set_xy((cap(player.x, 50, WIDTH-50), cap(player.y, HEIGHT-500, HEIGHT)))
|
61
|
+
|
62
|
+
|
63
|
+
def on_health_change(change):
|
64
|
+
player.sprite_data['health'] += change
|
65
|
+
new_health = max(0, player.sprite_data['health'])
|
66
|
+
|
67
|
+
healthbar_red = create_rect((255, 0, 0), 60*(new_health/10), 50)
|
68
|
+
healthbar_empty.blit(healthbar_red)
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
game.when_timer_reset(1000/120).on_reset(run_forever)
|
73
|
+
game.when_receive_message('player_health').add_handler(on_health_change)
|
74
|
+
|
75
|
+
|
76
|
+
game.when_timer_reset(0.1, 1).on_reset(game_start)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from setting import *
|
3
|
+
|
4
|
+
|
5
|
+
def spawn_player(event_test=False):
|
6
|
+
|
7
|
+
...pyscratch# main sgame player = pysc.create_rect_sprite((0, 0, 255), 50, 30, pos=(720//2, 1200))
|
8
|
+
#pysc.game.add_sprite(player)
|
9
|
+
player.set_collision_type(PLAYER_TYPE)
|
10
|
+
|
11
|
+
|
12
|
+
# custom data
|
13
|
+
pysc.game.shared_data['player'] = player
|
14
|
+
pysc.game.shared_data['player_health'] = 10
|
15
|
+
pysc.game.shared_data['bullet_period_ms'] = 200
|
16
|
+
|
17
|
+
# behaviour
|
18
|
+
## 1. move by key press in a limited area
|
19
|
+
## 2. health changes on message
|
20
|
+
## 3. shoot bullet every n seconds (by messages)
|
21
|
+
|
22
|
+
## 1. movement
|
23
|
+
movement_event = pysc.game.when_timer_reset(1000/120)
|
24
|
+
def movement(_):
|
25
|
+
if game.is_key_pressed('w'):
|
26
|
+
player.move_xy((0, -5))
|
27
|
+
|
28
|
+
if game.is_key_pressed('s'):
|
29
|
+
player.move_xy((0, 5))
|
30
|
+
|
31
|
+
if game.is_key_pressed('a'):
|
32
|
+
player.move_xy((-5, 0))
|
33
|
+
|
34
|
+
if game.is_key_pressed('d'):
|
35
|
+
player.move_xy((5, 0))
|
36
|
+
|
37
|
+
player.set_xy((cap(player.x, 50, SCREEN_WIDTH-50), cap(player.y, SCREEN_HEIGHT-900, SCREEN_HEIGHT)))
|
38
|
+
|
39
|
+
movement_event.add_handler(movement)
|
40
|
+
|
41
|
+
|
42
|
+
## 2. health changes on message
|
43
|
+
health_change_event = pysc.game.when_receive_message('player_health')
|
44
|
+
|
45
|
+
def health_change(change):
|
46
|
+
pysc.game.shared_data['player_health'] += change
|
47
|
+
|
48
|
+
health_change_event.add_handler(health_change)
|
49
|
+
|
50
|
+
|
51
|
+
## 3. bullets
|
52
|
+
bullet_timer = pysc.Timer()
|
53
|
+
condition = lambda: (bullet_timer.read() > pysc.game.shared_data['bullet_period_ms'])
|
54
|
+
shoot_bullet_event = pysc.game.when_condition_met(condition)
|
55
|
+
|
56
|
+
def shoot_bullet(n):
|
57
|
+
pysc.game.broadcast_message('player_shoot_bullet', player)
|
58
|
+
bullet_timer.full_reset()
|
59
|
+
|
60
|
+
shoot_bullet_event.add_handler(shoot_bullet)
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
# health bar
|
65
|
+
healthbar_empty = pysc.create_rect_sprite((255, 255, 255), 60, 5, pos=(0,0))
|
66
|
+
#pysc.game.add_sprite(healthbar_empty)
|
67
|
+
healthbar_empty.lock_to(player, (0,-30))
|
68
|
+
|
69
|
+
## move the health bar
|
70
|
+
healthbar_red = pysc.create_rect((255, 0, 0), 60, 50)
|
71
|
+
healthbar_empty.blit(healthbar_red, (0,0))
|
72
|
+
|
73
|
+
# reusing the health_change_event defined about
|
74
|
+
def on_health_change(change):
|
75
|
+
new_health = max(0, pysc.game.shared_data['player_health'])
|
76
|
+
|
77
|
+
healthbar_red = pysc.create_rect((255, 0, 0), 60*(new_health/10), 50)
|
78
|
+
healthbar_empty.blit(healthbar_red)
|
79
|
+
|
80
|
+
health_change_event.add_handler(on_health_change)
|
81
|
+
|
82
|
+
if event_test:
|
83
|
+
shoot_bullet_event.remove()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
spawn_player(event_test=False)
|
89
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from setting import *
|
3
|
+
import random
|
4
|
+
|
5
|
+
def shoot_player_bullet(player):
|
6
|
+
|
7
|
+
bullet = pysc.Sprite(frames, "circle_bullets", player.body.position)
|
8
|
+
|
9
|
+
#pysc.game.add_sprite(bullet)
|
10
|
+
bullet.set_collision_type(PLAYER_BULLET_TYPE)
|
11
|
+
bullet.set_rotation(-90)
|
12
|
+
|
13
|
+
movement_timer = pysc.game.when_timer_reset(1000/240).add_handler(
|
14
|
+
lambda x: bullet.move_indir(2)
|
15
|
+
)
|
16
|
+
|
17
|
+
next_frame_timer = pysc.game.when_timer_reset(100).add_handler(
|
18
|
+
lambda x: bullet.next_frame()
|
19
|
+
)
|
20
|
+
|
21
|
+
|
22
|
+
def destroy_when_exit(x):
|
23
|
+
movement_timer.remove()
|
24
|
+
next_frame_timer.remove()
|
25
|
+
pysc.game._remove_sprite(bullet)
|
26
|
+
|
27
|
+
|
28
|
+
destroy_condition = pysc.game.when_condition_met(lambda: (bullet.y < 0), repeats=1)
|
29
|
+
destroy_condition.add_handler(destroy_when_exit)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
pysc.game.when_receive_message('player_shoot_bullet').add_handler(shoot_player_bullet)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
import pygame
|
3
|
+
|
4
|
+
SCREEN_HEIGHT = 1280
|
5
|
+
SCREEN_WIDTH = 720
|
6
|
+
|
7
|
+
|
8
|
+
ENEMY_TYPE = 3
|
9
|
+
PLAYER_TYPE = 2
|
10
|
+
PLAYER_BULLET_TYPE = 4
|
11
|
+
EDGE_TYPE = 1
|
12
|
+
|
13
|
+
def cap(v, min_v, max_v):
|
14
|
+
return max(min(max_v, v), min_v)
|
15
|
+
|
16
|
+
sprite_sheet = pygame.image.load("assets/09493140a07b68502ef63ff423a6da3954d36fd8/Green Effect and Bullet 16x16.png").convert_alpha()
|
17
|
+
|
18
|
+
font = pygame.font.SysFont(None, 24) # None = default font, 48 = font size
|
19
|
+
|
20
|
+
frames = pysc.helper._get_frame_dict(sprite_sheet, 36, 13, {
|
21
|
+
"spin": [i+4*36 for i in range(14, 17+1)],
|
22
|
+
"star_explosion": [i+4*36 for i in range(19, 22+1)],
|
23
|
+
"heal": [i+1*36 for i in range(24, 28+1)],
|
24
|
+
"circle_explosion": [i+5*36 for i in range(14, 17+1)],
|
25
|
+
|
26
|
+
|
27
|
+
"square_bullets": [i+9*36 for i in range(24, 28+1)]+[i+9*36 for i in range(27, 24, -1)],
|
28
|
+
"circle_bullets": [i+8*36 for i in range(24, 28+1)]+[i+8*36 for i in range(27, 24, -1)],
|
29
|
+
|
30
|
+
"shield": [i+5*36 for i in [17]],
|
31
|
+
|
32
|
+
"bullet1": [i+3*36 for i in range(7, 7+1)]
|
33
|
+
})
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch.game_module import is_key_pressed
|
3
|
+
|
4
|
+
|
5
|
+
# my_sprite = pysc.create_animated_sprite("assets/run")
|
6
|
+
|
7
|
+
# def animate():
|
8
|
+
# my_sprite.scale_by(5)
|
9
|
+
# while True:
|
10
|
+
# yield 0.2
|
11
|
+
# my_sprite.next_frame()
|
12
|
+
|
13
|
+
# my_sprite.when_game_start().add_handler(animate)
|
14
|
+
|
15
|
+
|
16
|
+
my_sprite = pysc.create_animated_sprite("assets/my_sprite")
|
17
|
+
my_sprite.oob_limit=100
|
18
|
+
|
19
|
+
# variables for this sprite only
|
20
|
+
my_sprite['frame_interval'] = 0.4
|
21
|
+
|
22
|
+
# Event: on game start: switch frame
|
23
|
+
def animate():
|
24
|
+
my_sprite.set_draggable(True)
|
25
|
+
my_sprite.direction = 20
|
26
|
+
my_sprite.scale_by(5)
|
27
|
+
my_sprite.set_animation("idle") # reference the folder name of the animation
|
28
|
+
while True:
|
29
|
+
yield my_sprite['frame_interval']
|
30
|
+
my_sprite.next_frame()
|
31
|
+
|
32
|
+
my_sprite.when_game_start().add_handler(animate)
|
33
|
+
#pysc.game._left_edge.hide()
|
34
|
+
|
35
|
+
# Event: on game start: movement
|
36
|
+
def movement():
|
37
|
+
speed = 10
|
38
|
+
|
39
|
+
#my_sprite.set_rotation_style_left_right()
|
40
|
+
while True:
|
41
|
+
yield 1/30
|
42
|
+
my_sprite.if_on_edge_bounce()
|
43
|
+
|
44
|
+
if pysc.is_key_pressed("d"):
|
45
|
+
my_sprite.set_animation("run")
|
46
|
+
#my_sprite.direction = 0
|
47
|
+
my_sprite.x += speed
|
48
|
+
my_sprite['frame_interval'] = 0.2
|
49
|
+
|
50
|
+
elif pysc.is_key_pressed("a"):
|
51
|
+
my_sprite.set_animation("run")
|
52
|
+
#my_sprite.direction = 180
|
53
|
+
my_sprite.x -= speed
|
54
|
+
my_sprite['frame_interval'] = 0.2
|
55
|
+
|
56
|
+
elif pysc.is_key_pressed("s"):
|
57
|
+
my_sprite.set_animation("run")
|
58
|
+
#my_sprite.direction = 180
|
59
|
+
my_sprite.y += speed
|
60
|
+
my_sprite['frame_interval'] = 0.2
|
61
|
+
|
62
|
+
elif pysc.is_key_pressed("w"):
|
63
|
+
my_sprite.set_animation("run")
|
64
|
+
#my_sprite.direction = 180
|
65
|
+
my_sprite.y -= speed
|
66
|
+
my_sprite['frame_interval'] = 0.2
|
67
|
+
|
68
|
+
elif pysc.is_key_pressed("space"):
|
69
|
+
my_sprite.set_animation("run")
|
70
|
+
#my_sprite.direction = 180
|
71
|
+
my_sprite.move_indir(speed, -180)
|
72
|
+
my_sprite['frame_interval'] = 0.2
|
73
|
+
else:
|
74
|
+
my_sprite.set_animation("idle")
|
75
|
+
my_sprite['frame_interval'] = 0.4
|
76
|
+
|
77
|
+
my_sprite.when_game_start().add_handler(movement)
|
78
|
+
|
79
|
+
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch import game
|
3
|
+
|
4
|
+
def Enemy(position, speed, frame_idx, direction, bullet_period=0.4, path="assets/used_by_examples/bullet_hell/enemy"):
|
5
|
+
enemy = pysc.create_animated_sprite(
|
6
|
+
path,
|
7
|
+
position=position
|
8
|
+
)
|
9
|
+
enemy.set_animation('normal')
|
10
|
+
enemy.direction = direction#-90
|
11
|
+
enemy.set_frame(frame_idx)
|
12
|
+
enemy.set_scale(6/speed)
|
13
|
+
|
14
|
+
|
15
|
+
def movement(_):
|
16
|
+
while True:
|
17
|
+
yield 1/game.framerate
|
18
|
+
|
19
|
+
enemy.move_indir(speed, 90)
|
20
|
+
|
21
|
+
movement_event = enemy.when_timer_above(0).add_handler(movement)
|
22
|
+
|
23
|
+
|
24
|
+
def explode_and_remove():
|
25
|
+
movement_event.remove()
|
26
|
+
enemy.set_animation('explosion')
|
27
|
+
enemy.direction=0
|
28
|
+
enemy.scale_by(1.3)
|
29
|
+
enemy.when_timer_reset(0.1, 11).add_handler(lambda _: enemy.next_frame())
|
30
|
+
enemy.when_timer_reset(0.1*11, 1).add_handler(lambda _: enemy.remove())
|
31
|
+
|
32
|
+
def touch_player_bullet(_):
|
33
|
+
player = game['player']
|
34
|
+
|
35
|
+
while True:
|
36
|
+
yield 1/game.framerate
|
37
|
+
if enemy.is_touching(player):
|
38
|
+
explode_and_remove()
|
39
|
+
return
|
40
|
+
|
41
|
+
for b in game['player_bullets']:
|
42
|
+
if enemy.is_touching(b):
|
43
|
+
b.remove()
|
44
|
+
explode_and_remove()
|
45
|
+
|
46
|
+
return
|
47
|
+
|
48
|
+
enemy.when_timer_above(0).add_handler(touch_player_bullet)
|
49
|
+
|
50
|
+
# shoot bullets
|
51
|
+
StandardBullet = game['StandardBullet']
|
52
|
+
enemy.when_timer_reset(bullet_period).add_handler(lambda _: StandardBullet((enemy.x, enemy.y), direction+90, 10))
|
53
|
+
|
54
|
+
return enemy
|
55
|
+
|
56
|
+
|
57
|
+
def spawn_standard_enemy():
|
58
|
+
|
59
|
+
x = pysc.random_number(0, game.screen_width)
|
60
|
+
y = 0
|
61
|
+
frame_idx = int(pysc.random_number(0, 9.999))
|
62
|
+
|
63
|
+
direction = pysc.random_number(-10, 10)
|
64
|
+
|
65
|
+
Enemy((x,y), pysc.random_number(2, 6), frame_idx, direction)
|
66
|
+
|
67
|
+
def spawn_line():
|
68
|
+
n = 6
|
69
|
+
margin = 20
|
70
|
+
itv = (game.screen_width-margin*2)//(n-1)
|
71
|
+
y=0
|
72
|
+
for i in range(n):
|
73
|
+
|
74
|
+
x = itv*i+margin
|
75
|
+
|
76
|
+
Enemy((x, y), 5, 0, 0, bullet_period=1)
|
77
|
+
|
78
|
+
|
79
|
+
def spawn_6_side_entry():
|
80
|
+
|
81
|
+
pos1 = (0, 200)
|
82
|
+
pos2 = (0, 400)
|
83
|
+
pos3 = (0, 600)
|
84
|
+
|
85
|
+
pos4 = (game.screen_width, 200)
|
86
|
+
pos5 = (game.screen_width, 400)
|
87
|
+
pos6 = (game.screen_width, 600)
|
88
|
+
|
89
|
+
speed = 5
|
90
|
+
fidx = 2
|
91
|
+
|
92
|
+
Enemy(pos1, speed, fidx, 45-90)
|
93
|
+
Enemy(pos2, speed, fidx, 45-90)
|
94
|
+
Enemy(pos3, speed, fidx, 45-90)
|
95
|
+
|
96
|
+
|
97
|
+
Enemy(pos4, speed, fidx, 45)
|
98
|
+
Enemy(pos5, speed, fidx, 45)
|
99
|
+
Enemy(pos6, speed, fidx, 45)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
def spawn_kamikaze():
|
105
|
+
x = pysc.random_number(0, game.screen_width)
|
106
|
+
y = 0
|
107
|
+
frame_idx = int(pysc.random_number(0, 9.999))
|
108
|
+
direction = pysc.random_number(-10, 10)
|
109
|
+
|
110
|
+
e = Enemy((x,y), 5, frame_idx, direction, bullet_period=1000)
|
111
|
+
|
112
|
+
# move towards player
|
113
|
+
e.when_timer_reset(1/game.framerate, int(10*game.framerate)).add_handler(lambda _: e.point_towards_sprite(game['player'], -90))
|
114
|
+
|
115
|
+
def spawn_laser_enemy(x, y):
|
116
|
+
|
117
|
+
e = Enemy((x,y), speed=1, frame_idx=0, direction=0, bullet_period=1000, path="assets/used_by_examples/bullet_hell/enemy")
|
118
|
+
e.set_animation('laser')
|
119
|
+
e.scale_by(0.7)
|
120
|
+
|
121
|
+
Laser = game['Laser']
|
122
|
+
#player = game['player']
|
123
|
+
e.when_timer_reset(3).add_handler(lambda _: Laser((e.x, e.y), (e.x, e.y+1000), 1))
|
124
|
+
|
125
|
+
def spawn_laser_enemy_pair(x):
|
126
|
+
spawn_laser_enemy(x, 0)
|
127
|
+
spawn_laser_enemy(game.screen_width-x, 0)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
game.when_timer_reset(2).add_handler(lambda _:spawn_standard_enemy())
|
132
|
+
|
133
|
+
game.when_timer_above(3).add_handler(lambda _: spawn_line())
|
134
|
+
game.when_timer_above(4).add_handler(lambda _: spawn_6_side_entry())
|
135
|
+
|
136
|
+
game.when_timer_reset(7).add_handler(lambda _: spawn_line())
|
137
|
+
game.when_timer_reset(6).add_handler(lambda _: spawn_6_side_entry())
|
138
|
+
|
139
|
+
game.when_timer_reset(3).add_handler(lambda _: spawn_kamikaze())
|
140
|
+
|
141
|
+
game.when_timer_reset(5).add_handler(lambda _: game['ExplodingBullet']((720/2-pysc.random_number(-50, 50), 0), 90, 5))
|
142
|
+
|
143
|
+
game.when_timer_reset(10).add_handler(lambda _: spawn_laser_enemy(pysc.random_number(0, game.screen_width), 0))
|
144
|
+
|
145
|
+
|
146
|
+
#game.when_timer_reset(1).add_handler(lambda _: game['Laser']((0, 0), (game['player'].x, game['player'].y), 1))
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import pyscratch as pysc
|
3
|
+
from pyscratch import game
|
4
|
+
|
5
|
+
|
6
|
+
def StandardBullet(position, direction, speed):
|
7
|
+
|
8
|
+
bullet = pysc.create_animated_sprite(
|
9
|
+
"assets/used_by_examples/bullet_hell/normal_bullet",
|
10
|
+
position=position)
|
11
|
+
|
12
|
+
bullet.direction = direction
|
13
|
+
bullet.set_scale(1.5)
|
14
|
+
|
15
|
+
|
16
|
+
bullet['movement_event'] = movement_event = bullet.when_timer_reset(1/game.framerate).add_handler(lambda _: bullet.move_indir(speed))
|
17
|
+
bullet.when_timer_reset(0.2).add_handler(lambda _: bullet.next_frame())
|
18
|
+
|
19
|
+
def detect_collision(_):
|
20
|
+
player = game['player']
|
21
|
+
|
22
|
+
if bullet.is_touching(player):
|
23
|
+
movement_event.remove()
|
24
|
+
bullet.when_timer_reset(0.1, 1).add_handler(lambda _: bullet.remove())
|
25
|
+
|
26
|
+
bullet.when_timer_reset(1/game.framerate).add_handler(detect_collision)
|
27
|
+
return bullet
|
28
|
+
|
29
|
+
game['StandardBullet'] = StandardBullet
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def ExplodingBullet(position, direction, lifespan):
|
34
|
+
speed = 5
|
35
|
+
main_bullet = StandardBullet(position, direction, speed)
|
36
|
+
|
37
|
+
def explode():
|
38
|
+
main_bullet['movement_event'].remove()
|
39
|
+
main_bullet.remove()
|
40
|
+
for i in range(12):
|
41
|
+
StandardBullet((main_bullet.x, main_bullet.y), i*30, speed*1.5)
|
42
|
+
|
43
|
+
|
44
|
+
main_bullet.when_timer_reset(lifespan, 1).add_handler(lambda _: explode())
|
45
|
+
|
46
|
+
|
47
|
+
game['ExplodingBullet'] = ExplodingBullet
|
48
|
+
|
49
|
+
|
50
|
+
def Laser(pos0, pos1, duration):
|
51
|
+
|
52
|
+
len_x = pos1[0]-pos0[0]
|
53
|
+
len_y = pos1[1]-pos0[1]
|
54
|
+
|
55
|
+
length = (len_x**2 + len_y**2)**(1/2)
|
56
|
+
|
57
|
+
|
58
|
+
path = "assets/used_by_examples/bullet_hell/lasers/3.png"
|
59
|
+
img = pysc.load_image(path)
|
60
|
+
w = img.get_width()
|
61
|
+
|
62
|
+
scaled_img = pysc.scale_to_fill(img, (w, length))
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
laser_sp = pysc.Sprite(dict(always=[scaled_img]))
|
67
|
+
|
68
|
+
laser_sp.direction = -np.arctan(len_x/len_y)/np.pi*180
|
69
|
+
laser_sp.x = (pos1[0]+pos0[0])/2
|
70
|
+
laser_sp.y = (pos1[1]+pos0[1])/2
|
71
|
+
laser_sp.set_transparency(0)
|
72
|
+
def change_alpha(_):
|
73
|
+
for i in range(30):
|
74
|
+
laser_sp.set_transparency(i/30)
|
75
|
+
yield 0.01
|
76
|
+
for i in range(30):
|
77
|
+
laser_sp.set_transparency(1-i/30)
|
78
|
+
yield 0.01
|
79
|
+
laser_sp.remove()
|
80
|
+
laser_sp.when_timer_above(0).add_handler(change_alpha)
|
81
|
+
|
82
|
+
|
83
|
+
game['Laser'] = Laser
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch import game
|
3
|
+
|
4
|
+
import player,player_bullet, enemy, enemy_bullet
|
5
|
+
|
6
|
+
width = 720
|
7
|
+
height = 1280
|
8
|
+
sur = pysc.create_rect((50,50,50), width, height)
|
9
|
+
|
10
|
+
|
11
|
+
game.set_backdrops([sur])
|
12
|
+
game.switch_backdrop(0)
|
13
|
+
|
14
|
+
game.update_screen_mode((width, height))
|
15
|
+
game.start(show_mouse_position=True, event_count=True)
|
16
|
+
#=game.save_sprite_states()
|
17
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch import game
|
3
|
+
|
4
|
+
player = pysc.create_single_costume_sprite("assets/used_by_examples/bullet_hell/player.png")
|
5
|
+
game['player'] = player
|
6
|
+
def movement():
|
7
|
+
player.set_scale(3)
|
8
|
+
player.set_xy((360, 1080))
|
9
|
+
|
10
|
+
|
11
|
+
speed = 8
|
12
|
+
|
13
|
+
while True:
|
14
|
+
yield 1/game.framerate
|
15
|
+
|
16
|
+
if pysc.is_key_pressed('w'):
|
17
|
+
player.y -= speed
|
18
|
+
|
19
|
+
if pysc.is_key_pressed('s'):
|
20
|
+
player.y += speed
|
21
|
+
|
22
|
+
if pysc.is_key_pressed('a'):
|
23
|
+
player.x -= speed
|
24
|
+
|
25
|
+
if pysc.is_key_pressed('d'):
|
26
|
+
player.x += speed
|
27
|
+
|
28
|
+
player.when_game_start().add_handler(movement)
|
29
|
+
|
30
|
+
|
31
|
+
def shoot_bullet():
|
32
|
+
Bullet = game['Bullet']
|
33
|
+
bullet_speed = 10
|
34
|
+
while True:
|
35
|
+
yield 0.8
|
36
|
+
|
37
|
+
Bullet(player.x, player.y-35, bullet_speed)
|
38
|
+
|
39
|
+
player.when_game_start().add_handler(shoot_bullet)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import pyscratch as pysc
|
2
|
+
from pyscratch import game
|
3
|
+
|
4
|
+
game['player_bullets'] = []
|
5
|
+
def Bullet(x, y, speed):
|
6
|
+
bullet = pysc.create_single_costume_sprite(
|
7
|
+
"assets/used_by_examples/bullet_hell/orb_bullets/6.png",
|
8
|
+
position=(x,y)
|
9
|
+
)
|
10
|
+
bullet.x = x
|
11
|
+
bullet.y = y
|
12
|
+
bullet.set_scale(0.5)
|
13
|
+
|
14
|
+
def movement(_):
|
15
|
+
while True:
|
16
|
+
yield 1/game.framerate
|
17
|
+
bullet.y -= speed
|
18
|
+
|
19
|
+
bullet.when_timer_above(0).add_handler(movement)
|
20
|
+
|
21
|
+
|
22
|
+
game['player_bullets'].append(bullet)
|
23
|
+
#return bullet
|
24
|
+
|
25
|
+
game['Bullet'] = Bullet
|
26
|
+
|
27
|
+
|
28
|
+
def clear_removed_bullet(_):
|
29
|
+
game['player_bullets'] = [b for b in game['player_bullets'] if not b.removed]
|
30
|
+
|
31
|
+
game.when_timer_reset(2).add_handler(clear_removed_bullet)
|