forked from MrNex/Matter.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.py
More file actions
42 lines (34 loc) · 1.37 KB
/
Copy pathobject.py
File metadata and controls
42 lines (34 loc) · 1.37 KB
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
import pygame.draw
class Object:
def __init__(self, xPos, yPos, xDim, yDim):
self.x_position = xPos
self.y_position = yPos
self.prev_position = (self.x_position, self.y_position)
self.dimension = (xDim, yDim)
##Checks if two objects are colliding
def is_colliding(self, object):
if(self == object): return false
objDX, objDY = object.dimension
dX, dY = self.dimension
if(self.x_position < object.x_position + objDX and self.x_position + dX > object.x_position):
if(self.y_position < object.y_position + objDY and self.y_position + dY > object.y_position):
return True
return False
##Checks if this object is to the right of the left side of the screen
#Only returns false if the object fell off the LEFT side of the screen!
def is_on_screen(self):
_dx, _dy = self.dimension
if(self.x_position + _dx <= 0): return False
return True
##Draws this object
def draw(self, _screen):
if(not self.prev_position == (self.x_position, self.y_position)):
self.clear_shape(_screen)
self.draw_shape(_screen)
def draw_shape(self, _screen):
pygame.draw.rect(_screen, self.color, ((self.x_position, self.y_position), self.dimension))
def clear_shape(self, _screen):
pygame.draw.rect(_screen, (0, 0, 0), (self.prev_position, self.dimension))
self.prev_position = (self.x_position, self.y_position)
def push_left(self, _trans):
self.x_position -= _trans