arctic-masher/blocks.py

38 lines
1.2 KiB
Python
Raw Normal View History

import pygame
2023-05-17 12:42:21 +00:00
import uuid
from globals import *
from enemies import *
2023-05-17 11:04:10 +00:00
class Block:
def __init__(self, id, x, y):
2023-05-17 12:42:21 +00:00
self.id = id
2023-05-17 11:04:10 +00:00
self.x = x
self.y = y
self.BLOCK = True
self.sprite = pygame.Rect((x*tile) + 2, (y*tile) + 2, tile - 2, tile - 2)
2023-05-17 11:04:10 +00:00
2023-05-17 11:40:57 +00:00
def pushed(self, x, y, caller, pusher):
2023-05-17 12:42:21 +00:00
if self.x + x > tileCountx - 1 or self.y + y > tileCounty - 1 or self.x + x < 0 or self.y + y < 0:
2023-05-17 12:09:48 +00:00
raise Exception("Cannot push off edge!")
if gameMap[self.x + x][self.y + y]:
gameMap[self.x + x][self.y + y].pushed(x, y, self, pusher)
2023-05-18 04:34:16 +00:00
gameMap[self.x][self.y] = False
self.x += x
self.sprite.x = (self.x*tile)+2
self.y += y
self.sprite.y = (self.y*tile)+2
gameMap[self.x][self.y] = self
def pulled(self, x, y):
for i in range(-1,2):
for j in range(-1,2):
if hasattr(gameMap[self.x + i][self.y + j], "ENEMY"):
2023-05-18 04:34:16 +00:00
raise Exception("Cannot pull a block that is touching an enemy")
gameMap[self.x][self.y] = False
2023-05-17 11:40:57 +00:00
self.x += x
self.sprite.x = (self.x*tile)+2
self.y += y
self.sprite.y = (self.y*tile)+2
gameMap[self.x][self.y] = self