import pygame class Wall: def __init__(self, x, y, width, height): self.x = x self.y = y self.height = height self.width = width self.halfH = height / 2 self.halfW = width / 2 def isPointOnWall(self, x, y): xIsInBetween = self.x - self.halfW <= x and x <= self.x + self.halfW yIsInBetween = self.y - self.halfH <= y and y <= self.y + self.halfH return xIsInBetween and yIsInBetween def pushedOutCoordinates(self, x, y): newX = x; newY = y; if self.x - self.halfW <= x and x <= self.x: newX = self.x - self.halfW if self.x <= x and x <= self.x + self.halfW: newX = self.x + self.halfW if self.y - self.halfH <= y and y <= self.y: newY = self.y - self.halfH if self.y <= y and y <= self.y + self.halfH: newY = self.y + self.halfH return [newX, newY] def draw(self, screen): pygame.draw.rect( screen, (0, 0, 0), (self.x - self.halfW, self.y - self.halfH, self.width, self.height) )