forked from PaulleDemon/Hunter2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.py
43 lines (30 loc) · 1.09 KB
/
background.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
import pygame
from pycollision import Collision
class Background:
def __init__(self, img: str, screen, pos=(0, 0)):
self.bg_image = pygame.image.load(img).convert_alpha()
self.bg_x, self.bg_y = pos
self.screen = screen
def update(self):
self.screen.blit(self.bg_image, (self.bg_x, self.bg_y))
def get_pos(self):
return self.bg_x, self.bg_y
def get_rect(self):
return self.bg_image.get_rect()
class BackgroundWall:
def __init__(self, img: str, screen, pos=(0, 0), split=(5, 5)):
self.img = pygame.image.load(img).convert_alpha()
self.x, self.y = pos
self.screen = screen
self.collision = Collision(
img, split, wall_collision=True, wall_padding=(1, 1, 1, 1)
)
def set_pos(self, x, y):
self.x, self.y = x, y
self.collision.setSpritePos(self.x, self.y)
def update(self):
self.screen.blit(self.img, (self.x, self.y))
def get_collision_object(self):
return self.collision
def get_rect(self) -> pygame.Rect:
return self.img.get_rect()