-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_functions.py
71 lines (52 loc) · 2.21 KB
/
user_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import arcade
import game
def place_block(arcade_game, x_pos, block_type="assets/backgrounds/Bois2.png"):
"""
Places a block on the lowest slot available at the horizontal position passed.
Args:
arcade_game: Game object target
x_pos: horizontal position where the block should be placed, starts at 0, counted in tiles
block_type: type of the block that should be placed
Returns: None
"""
if x_pos < 0:
raise ValueError("The value must be positive.")
# Size of one tile in the grid, adapted to current level scaling
tile_size = arcade_game.tile_size * arcade_game.level_data["scaling"]
# Initialize block
new_block = arcade.Sprite(block_type)
new_block.width = new_block.height = tile_size
new_block.left = (x_pos + arcade_game.level_data["offset"]) * tile_size
# y coord of the block is the first free available
new_block.bottom = arcade_game.level_data["first_free_slots"][x_pos] * tile_size
# Increment the first row available in the modified column
arcade_game.level_data["first_free_slots"][x_pos] += 1
if new_block.bottom > game.SCREEN_HEIGHT:
raise ValueError("No room is available for this block at that position.")
# Update sprite list and render the new sprite
arcade_game.scene["Platforms"].append(new_block)
arcade_game.scene["Platforms"].draw()
def is_empty(arcade_game, x_pos, y_pos):
"""
Checks if there is a platform at the (x_pos, y_pos) position.
Args:
arcade_game: arcade game instance
x_pos: x position (int) checked
y_pos: y position (int) checked
Returns:
"""
tile_size = arcade_game.level_data["scaling"] * arcade_game.tile_size
coords = (x_pos + arcade_game.level_data["offset"]) * tile_size + 1, y_pos * tile_size + 1
return arcade.get_sprites_at_point(coords, arcade_game.scene["Platforms"]) == [] \
and arcade.get_sprites_at_point(coords, arcade_game.scene["BackgroundPlatforms"]) == []
def frog(arcade_game):
"""
Turns the character into the frog.
:param arcade_game:
:return: Nothing
"""
if not arcade_game.frog:
arcade_game.frog = True
else:
arcade_game.frog = False
arcade_game.setup()