Completed
Push — master ( be0bb5...16e7a2 )
by Matthew
01:20
created

PhysEngine   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getObject() 0 2 1
A __init__() 0 6 1
A addObject() 0 3 1
A collisions() 0 10 3
A getLength() 0 2 1
A simulate() 0 14 2
1
from ed2d.physics import rectangle
2
from ed2d.physics import quadtree
3
4
class PhysEngine(object):
5
6
    def __init__(self):
7
        # I would love to have width and height as global constants
8
        self.quadTree = quadtree.QuadTree(0, rectangle.Rectangle(0.0, 0.0, width=800, height=600, flag='QT'))
9
        self.quadTree.clear()
10
        self.pObjects = []
11
        self.returnObjects = []
12
13
    def simulate(self, delta):
14
        '''Update all the objects'''
15
        # Update the quad tree
16
        self.quadTree.clear()
17
        for item in self.pObjects:
18
            self.quadTree.insert(item)
19
20
        # Pass this for a while, this basically add velocity to objects
21
        # But is kinda of a stupid way to do
22
        # for i in range(len(self.pObjects)):
23
        #     self.pObjects[i].update(delta)
24
25
        # Run collision check
26
        self.collisions()
27
28
    def collisions(self):
29
        objects = []
30
        self.quadTree.retriveAll(objects)
31
        for x in range(len(objects)):
32
            obj = []
33
            self.quadTree.findObjects(obj, objects[x])
34
            for y in range(len(obj)):
35
                objects[x].getCollisionModel().intersect(obj[y].getCollisionModel())
36
            del obj[:]
37
        del objects[:]
38
39
    def addObject(self, p_object):
40
        self.quadTree.insert(p_object)
41
        self.pObjects.append(p_object)
42
43
    def getObject(self, index):
44
        return self.pObjects[index]
45
46
    def getLength(self):
47
        return len(self.pObjects)
48