-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoving_entity.py
More file actions
42 lines (38 loc) · 1.68 KB
/
moving_entity.py
File metadata and controls
42 lines (38 loc) · 1.68 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, math
from entity import Entity
class MovingEntity(Entity):
def __init__(self, velocity, type, xywh = None, xyr = None):
self.velocity = velocity
Entity.__init__(self, type, xywh, xyr)
def tick(self, delta,cx=False, cy=False):
if not cx:
self.setX(self.getX() + self.velocity.x * delta)
if not cy:
self.setY(self.getY() + self.velocity.y * delta)
def getNextFrame(self, delta):
return (self.getX() + self.velocity.x * delta, self.getY() + self.velocity.y * delta)
def checkCollision(self, x, y, w,level):
sqPos = (x%30, y%30)
square = (math.floor(x/30), math.floor(y/30))
toCheck = [square]
if sqPos[0] < w:
if sqPos[1] < w:
toCheck.append((square[0] - 1, square[1]-1))
toCheck.append((square[0], square[1] -1))
if sqPos[1] > 30 - w:
toCheck.append((square[0] - 1, square[1]+1))
toCheck.append((square[0], square[1] + 1))
toCheck.append((square[0] - 1, square[1]))
elif sqPos[0] > 30 - w:
if sqPos[1] < w:
toCheck.append((square[0] + 1, square[1]-1))
toCheck.append((square[0], square[1] -1))
if sqPos[1] > 30 - w:
toCheck.append((square[0] + 1, square[1]+1))
toCheck.append((square[0], square[1] + 1))
toCheck.append((square[0] + 1, square[1]))
for t in toCheck:
type= level.level[int(t[1])][int(t[0])]
if type == 1 or type == 2 or type == 3:
return True
return False