| 16 | |
| 17 | |
| 18 | class PWPlayer(PWConstants, PWPlayerAction): |
| 19 | def __init__(self, position): |
| 20 | self.bbox_size = 0.25 |
| 21 | |
| 22 | self.pos = glm.vec2(position.x, position.y) - self.bbox_size / 2.0 |
| 23 | self.old_pos = glm.vec2(position.x, position.y) - self.bbox_size / 2.0 |
| 24 | |
| 25 | self.bbox = PWBBox(glm.vec2(self.bbox_size), glm.vec2(self.pos.x, self.pos.y)) |
| 26 | self.bbox_advance = PWBBox(glm.vec2(self.bbox_size), glm.vec2(self.pos.x, self.pos.y)) |
| 27 | |
| 28 | self.pos_ud_v = 0.0 # Velocity |
| 29 | self.pos_ud = 0.0 # Up/Down position (tricks) |
| 30 | self.action = self.ACTION_NONE |
| 31 | |
| 32 | |
| 33 | def getCurrentAction(self): |
| 34 | return self.action |
| 35 | |
| 36 | |
| 37 | def getPosition(self): |
| 38 | position = self.pos + self.bbox_size / 2.0 |
| 39 | return glm.vec3(position.x, self.pos_ud, position.y) |
| 40 | |
| 41 | |
| 42 | def __checkCollisionX(self, move_direction, vector, wall): |
| 43 | if move_direction.x == 0: |
| 44 | return |
| 45 | |
| 46 | self.bbox_advance.updatePos(self.old_pos.x, self.old_pos.y) |
| 47 | self.bbox_advance.pos.x += vector |
| 48 | |
| 49 | if self.bbox_advance.colliderect(wall): |
| 50 | if move_direction.x > 0: |
| 51 | self.pos.x = wall.pos.x - self.bbox.wh.x |
| 52 | else: |
| 53 | self.pos.x = wall.pos.x + wall.bbox.wh.x |
| 54 | |
| 55 | |
| 56 | def __checkCollisionY(self, move_direction, vector, wall): |
| 57 | if move_direction.z == 0: |
| 58 | return |
| 59 | |
| 60 | self.bbox_advance.updatePos(self.old_pos.x, self.old_pos.y) |
| 61 | self.bbox_advance.pos.y += vector |
| 62 | |
| 63 | if self.bbox_advance.colliderect(wall): |
| 64 | if move_direction.z > 0: |
| 65 | self.pos.y = wall.pos.y - self.bbox.wh.y |
| 66 | else: |
| 67 | self.pos.y = wall.pos.y + wall.bbox.wh.y |
| 68 | |
| 69 | |
| 70 | def checkCollision(self, move_direction, walls): |
| 71 | for wall in walls: |
| 72 | if self.bbox.colliderect(wall): |
| 73 | length = glm.length(self.pos - self.old_pos) |
| 74 | offset = glm.normalize(self.pos - self.old_pos) |
| 75 | |