-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathObject.py
59 lines (47 loc) · 1.91 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
An Object is an object that is drawn to the screen.
It can have animations, position, and size.
"""
from ObjectType import ObjectType
from Vector import Vector
import pygame
class Object:
Objects = []
Left,Bottom,Top,Right = range(4)
def detectCollision(self, object):
if self == object:
return False
selfMinX = self.position.x
selfMinY = self.position.y
selfMaxX = self.position.x + self.objectType.width
selfMaxY = self.position.y + self.objectType.height
objectMinX = object.position.x
objectMinY = object.position.y
objectMaxX = object.position.x + object.objectType.width
objectMaxY = object.position.y + object.objectType.height
return not (selfMaxX <= objectMinX or selfMinX >= objectMaxX or selfMaxY <= objectMinY or selfMinY >= objectMaxY)
def detectRectCollision(self,rect):
selfMinX = self.position.x
selfMinY = self.position.y
selfMaxX = self.position.x + self.objectType.width
selfMaxY = self.position.y + self.objectType.height
return not (selfMaxX <= rect.left or selfMinX >= rect.right or selfMaxY <= rect.top or selfMinY >= rect.bottom)
def getNextFrame(self):
"""
Calculates the current animation.
"""
self.currentAnimation = self.objectType.animations['idle']
return self.currentAnimation.frame[0]
def __init__(self, whichType, position = None, flipped = False, draw = True):
"""
Creates a basic Entity of a specific type.
"""
Object.Objects.append(self)
self.flipped = flipped
self.position = position
if position == None:
self.position = Vector()
self.draw = draw
self.objectType = whichType
self.currentAnimation = self.objectType.animations['idle']
self.currentFrame = self.objectType.animations['idle'].frame[0]