summaryrefslogtreecommitdiffstats
path: root/Geometry-Dash/wall.py
blob: 74d8d14f896240591eb1e97d132716f3ebe3d42f (plain)
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
from setup import *
from colors import COLOR_BLACK
from player import Player
from platform import Platform


class Wall:
    width, height = 1, Platform.height - 1
    color = COLOR_BLACK

    def __init__(self, x, y):
        self.position = pygame.Vector2(x, y)

    def draw(self, screen, camera_x, camera_y):
        r = pygame.Rect(self.position.x + camera_x, self.position.y + camera_y, self.width, self.height)
        pygame.draw.rect(screen, self.color, r)


class WallManager:
    wall_spread = 50

    def __init__(self):
        self.walls = []

        self.next_slot = 0

    def spawn_wall_at_slot(self, slot):
        wall_position_y = 700 - slot

        wall_position_x = self.wall_spread * slot

        new_wall = Wall(wall_position_x, wall_position_y)
        self.walls.append(new_wall)

    def spawn_new_walls(self, camera_x):
        while camera_x <= SCREEN_WIDTH - (self.wall_spread * self.next_slot):
            self.spawn_wall_at_slot(self.next_slot)
            self.next_slot += 1

    def delete_old_walls(self, camera_x):
        if self.walls:

            wall = self.walls[0]

            offset = Wall.width + Player.width + camera_x

            if wall.position.x < -offset:
                self.walls.remove(self.walls[0])

    def update(self, camera_x):
        self.delete_old_walls(camera_x)
        self.spawn_new_walls(camera_x)

    def draw(self, screen, camera_x, camera_y):
        for wall in self.walls:
            wall.draw(screen, camera_x, camera_y)