@@ -19,3 +19,6 @@ class CollisionBox(pygame.sprite.Sprite):
|
||||
|
||||
def setY(self, y):
|
||||
self.rect.y = y + self.offset[1]
|
||||
|
||||
def setX(self, x):
|
||||
self.rect.x = x + self.offset[0]
|
||||
|
||||
+9
-7
@@ -173,10 +173,11 @@ class Drakora():
|
||||
|
||||
if self.drawBoxes:
|
||||
for player in self.players:
|
||||
for collision in self.player.getCollisionBoxes():
|
||||
pygame.draw.rect(self.screen, (255, 0, 0), collision.rect,1)
|
||||
for collision in player.getCollisionBoxes():
|
||||
pygame.draw.rect(self.screen, (255, 0, 0), collision.rect, 1)
|
||||
for enemy in self.enemies:
|
||||
pygame.draw.rect(self.screen, (255, 0, 0), enemy.rect, 1)
|
||||
for collision in enemy.getCollisionBoxes():
|
||||
pygame.draw.rect(self.screen, (255, 0, 0), collision.rect, 1)
|
||||
for floor in self.floors:
|
||||
pygame.draw.rect(self.screen, (255, 0, 0), floor.rect, 1)
|
||||
|
||||
@@ -235,11 +236,12 @@ class Drakora():
|
||||
else:
|
||||
return 300
|
||||
|
||||
|
||||
def collideCheck(self):
|
||||
if sum([1 if pygame.sprite.spritecollideany(i, self.enemies) else 0
|
||||
for i in self.player.getCollisionBoxes()]):
|
||||
if not self.isGodmode: self.isGameOver = True
|
||||
for enemy in self.enemies:
|
||||
if pygame.sprite.groupcollide(self.player.getCollisionBoxes(), enemy.getCollisionBoxes(), None, None):
|
||||
if not self.isGodmode:
|
||||
self.isGameOver = True
|
||||
break
|
||||
|
||||
if self.player.isOnFloor:
|
||||
self.player.rect.y += 1
|
||||
|
||||
@@ -16,6 +16,12 @@ class Enemy(pygame.sprite.Sprite):
|
||||
self.height = (mainGameClass.getScreenHeight()
|
||||
- mainGameClass.getFloorHeight())
|
||||
|
||||
self.collisionBoxes = pygame.sprite.Group()
|
||||
|
||||
|
||||
def getCollisionBoxes(self):
|
||||
return self.collisionBoxes
|
||||
|
||||
|
||||
def update(self):
|
||||
if (self.rect.x < -self.rect.width):
|
||||
@@ -23,3 +29,6 @@ class Enemy(pygame.sprite.Sprite):
|
||||
self.thisGame.addScore(1)
|
||||
|
||||
self.rect.x -= self.speed
|
||||
|
||||
for i in self.collisionBoxes:
|
||||
i.setX(self.rect.x)
|
||||
|
||||
@@ -9,6 +9,7 @@ import math
|
||||
import os
|
||||
|
||||
from Enemy import Enemy
|
||||
from CollisionBox import CollisionBox
|
||||
|
||||
|
||||
class FlyingEnemy(Enemy):
|
||||
@@ -41,6 +42,9 @@ class FlyingEnemy(Enemy):
|
||||
self.rect.center = (mainGameClass.getScreenWidth() + self.rect.width,
|
||||
self.height)
|
||||
|
||||
collision = CollisionBox(2, 0, self.rect.w - 28, self.rect.h - 8, self.rect.center)
|
||||
self.collisionBoxes.add(collision)
|
||||
|
||||
self.speed = self.thisGame.getGameSpeed()*2
|
||||
|
||||
|
||||
|
||||
@@ -105,14 +105,14 @@ class Player(pygame.sprite.Sprite):
|
||||
self.gameSpeed = 1
|
||||
self.updateCount = 0
|
||||
|
||||
self.collisionBoxes = []
|
||||
self.collisionBoxes = pygame.sprite.Group()
|
||||
|
||||
collision = CollisionBox(0, 20, 60, 20, self.rect.center)
|
||||
self.collisionBoxes.append(collision)
|
||||
self.collisionBoxes.add(collision)
|
||||
collision = CollisionBox(-10, 5, 30, 20, self.rect.center)
|
||||
self.collisionBoxes.append(collision)
|
||||
self.collisionBoxes.add(collision)
|
||||
collision = CollisionBox(0, 35, 25, 40, self.rect.center)
|
||||
self.collisionBoxes.append(collision)
|
||||
self.collisionBoxes.add(collision)
|
||||
|
||||
|
||||
def crouch(self):
|
||||
|
||||
+6
-2
@@ -8,6 +8,7 @@ import random
|
||||
import os
|
||||
|
||||
from Enemy import Enemy
|
||||
from CollisionBox import CollisionBox
|
||||
|
||||
|
||||
class StandingEnemy(Enemy):
|
||||
@@ -147,9 +148,9 @@ class StandingEnemy(Enemy):
|
||||
image.set_colorkey((255,0,255))
|
||||
|
||||
|
||||
self.subtype = random.randint(1, len(StandingEnemy.images))
|
||||
self.subtype = random.randint(0, len(StandingEnemy.images) - 1)
|
||||
|
||||
self.image = random.choice(StandingEnemy.images[self.subtype-1])
|
||||
self.image = random.choice(StandingEnemy.images[self.subtype])
|
||||
|
||||
self.rect = self.image.get_rect()
|
||||
self.height -= self.rect.height/2
|
||||
@@ -157,4 +158,7 @@ class StandingEnemy(Enemy):
|
||||
self.rect.center = (mainGameClass.getScreenWidth() + self.rect.width,
|
||||
self.height)
|
||||
|
||||
collision = CollisionBox(9, 3, self.rect.w - 18, self.rect.h - 6, self.rect.center)
|
||||
self.collisionBoxes.add(collision)
|
||||
|
||||
self.speed = self.thisGame.getGameSpeed()
|
||||
|
||||
Reference in New Issue
Block a user