-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_object.py
34 lines (22 loc) · 1.01 KB
/
game_object.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
import pygame
from main import Game
vec = pygame.math.Vector2
rect = pygame.Rect
# My idea is to have a list that consists of all game objects, and that is looped through at the game's update and draw/render methods. When an object ceases to
# exist - for example when the player eats a bit of food - that object should be removed from the main game object-list.
class GameObject:
def __init__(self, game: Game, pos: vec, img):
self.game = game
self.pos = pos
self.img = img
self.hitbox = rect(pos.x, pos.y, img.get_width(), img.get_height())
self.is_static = False
def update(self, delta_time: float):
self.update_hitbox()
def draw(self, screen):
screen.blit(self.img, self.pos)
def override_hitbox(self, hitbox: rect):
self.hitbox = hitbox
def update_hitbox(self):
if self.is_static == False:
self.hitbox = rect(self.pos.x, self.pos.y, self.hitbox.width, self.hitbox.height)