Merge branch 'debug' into leaderboard
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Background entity class
|
||||
"""
|
||||
|
||||
|
||||
import pygame
|
||||
import os
|
||||
|
||||
from BackgroundLayer import BackgroundLayer
|
||||
|
||||
|
||||
class Background():
|
||||
imgDir = os.path.join(os.path.dirname(__file__), 'data')
|
||||
backgroundImage = pygame.image.load(os.path.join(imgDir, 'background.png'))#.convert()
|
||||
backgroundImages = (
|
||||
pygame.transform.scale(backgroundImage.subsurface((0, 0, 800, 150)), (3200, 600)),
|
||||
pygame.transform.scale(backgroundImage.subsurface((0, 150, 800, 150)), (3200, 600)),
|
||||
pygame.transform.scale(backgroundImage.subsurface((0, 300, 800, 150)), (3200, 600)),
|
||||
)
|
||||
for image in backgroundImages:
|
||||
image.set_colorkey((255,0,255))
|
||||
|
||||
def __init__(self, mainGameClass):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
|
||||
self.layers = (
|
||||
BackgroundLayer(Background.backgroundImages[0], mainGameClass, 0.25),
|
||||
BackgroundLayer(Background.backgroundImages[1], mainGameClass, 0.5),
|
||||
BackgroundLayer(Background.backgroundImages[2], mainGameClass, 1),
|
||||
)
|
||||
|
||||
|
||||
def update(self):
|
||||
for layer in self.layers:
|
||||
layer.update()
|
||||
|
||||
|
||||
def draw(self, surface):
|
||||
for layer in self.layers:
|
||||
layer.draw(surface)
|
||||
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
Background layer entity class
|
||||
"""
|
||||
|
||||
|
||||
import pygame
|
||||
|
||||
from BackgroundLayerFrame import BackgroundLayerFrame
|
||||
|
||||
|
||||
class BackgroundLayer():
|
||||
def __init__(self, image, mainGameClass, speedMultiplier):
|
||||
offset = image.get_width()
|
||||
|
||||
self.frames = pygame.sprite.Group()
|
||||
|
||||
self.frames.add(BackgroundLayerFrame(image, mainGameClass, (0, 0), speedMultiplier))
|
||||
self.frames.add(BackgroundLayerFrame(image, mainGameClass, (offset, 0), speedMultiplier))
|
||||
|
||||
|
||||
def update(self):
|
||||
for frame in self.frames:
|
||||
frame.update()
|
||||
|
||||
|
||||
def draw(self, surface):
|
||||
self.frames.draw(surface)
|
||||
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Background layer frame entity class
|
||||
"""
|
||||
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
class BackgroundLayerFrame(pygame.sprite.Sprite):
|
||||
def __init__(self, image, mainGameClass, offset, speedMultiplier):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
|
||||
self.image = image
|
||||
self.mainGameClass = mainGameClass
|
||||
self.speedMultiplier = speedMultiplier
|
||||
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.center = (mainGameClass.getScreenWidth()/2 + offset[0],
|
||||
mainGameClass.getScreenHeight()/2 + offset[1])
|
||||
|
||||
self.__doubleX = float(self.rect.x)
|
||||
|
||||
|
||||
def update(self):
|
||||
self.__doubleX -= self.mainGameClass.getGameSpeed() * self.speedMultiplier
|
||||
if self.__doubleX < -self.rect.width:
|
||||
self.__doubleX += self.rect.width*2
|
||||
|
||||
self.rect.x = self.__doubleX
|
||||
@@ -23,8 +23,6 @@ class Cloud(pygame.sprite.Sprite):
|
||||
mainGameClass.getScreenHeight()/2-100)+50*(2-cloudType))
|
||||
self.speed = cloudType*mainGameClass.getGameSpeed() / 6
|
||||
|
||||
|
||||
|
||||
self.__doubleX = float(self.rect.x)
|
||||
|
||||
|
||||
|
||||
+8
-3
@@ -5,9 +5,11 @@ Main game class
|
||||
|
||||
import pygame
|
||||
import random
|
||||
import os
|
||||
|
||||
from collections import deque
|
||||
|
||||
from Background import Background
|
||||
from Player import Player
|
||||
from StandingEnemy import StandingEnemy
|
||||
from FlyingEnemy import FlyingEnemy
|
||||
@@ -65,6 +67,8 @@ class Drakora():
|
||||
|
||||
|
||||
def newGame(self):
|
||||
self.background = Background(self)
|
||||
|
||||
for enemy in self.enemies:
|
||||
enemy.kill()
|
||||
|
||||
@@ -113,7 +117,7 @@ class Drakora():
|
||||
|
||||
self.targetFps = 120
|
||||
|
||||
self.floorHeight = 50
|
||||
self.floorHeight = 64
|
||||
|
||||
self.players = pygame.sprite.Group()
|
||||
self.floors = pygame.sprite.Group()
|
||||
@@ -131,7 +135,6 @@ class Drakora():
|
||||
self.isGodmode = False
|
||||
self.drawBoxes = False
|
||||
|
||||
|
||||
self.font = pygame.font.match_font('liberation mono')
|
||||
self.fontScore = pygame.font.Font(self.font, 32)
|
||||
self.fontMessage = pygame.font.Font(self.font, 56)
|
||||
@@ -166,7 +169,8 @@ class Drakora():
|
||||
|
||||
|
||||
def render(self):
|
||||
self.screen.fill((102, 153, 255))
|
||||
# self.screen.fill((102, 153, 255))
|
||||
self.background.draw(self.screen)
|
||||
for cloudGroup in self.cloudGroups: cloudGroup.draw(self.screen)
|
||||
self.enemies.draw(self.screen)
|
||||
self.players.draw(self.screen)
|
||||
@@ -304,6 +308,7 @@ class Drakora():
|
||||
|
||||
if not self.isGameOver and not self.isPaused:
|
||||
self.time += 1/self.targetFps
|
||||
self.background.update()
|
||||
|
||||
for cloudGroup in self.cloudGroups: cloudGroup.update()
|
||||
self.enemies.update()
|
||||
|
||||
@@ -11,7 +11,7 @@ class Floor(pygame.sprite.Sprite):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.Surface((mainGameClass.getScreenWidth(),
|
||||
mainGameClass.getFloorHeight()*101))
|
||||
self.image.fill((255, 204, 102))
|
||||
self.image.fill((255, 229, 180))
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.center = (mainGameClass.getScreenWidth()/2,
|
||||
mainGameClass.getScreenHeight() +
|
||||
|
||||
@@ -22,6 +22,7 @@ class FlyingEnemy(Enemy):
|
||||
for image in images:
|
||||
image.set_colorkey((255,0,255))
|
||||
|
||||
|
||||
def __init__(self, mainGameClass):
|
||||
Enemy.__init__(self, mainGameClass)
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ class Player(pygame.sprite.Sprite):
|
||||
pygame.transform.scale(playerImage.subsurface((16, 72, 16, 16)), (64, 64)),
|
||||
)
|
||||
|
||||
|
||||
for array in (walkImages, upImages, downImages, crouchImages):
|
||||
for image in array:
|
||||
image.set_colorkey((255,0,255))
|
||||
@@ -76,11 +75,6 @@ class Player(pygame.sprite.Sprite):
|
||||
self.collisionBoxes.append(collision)
|
||||
collision = CollisionBox(0, 35, 25, 40, self.rect.center)
|
||||
self.collisionBoxes.append(collision)
|
||||
# self.collisionBoxes.append(self)
|
||||
# collision = pygame.sprite.Sprite()
|
||||
# collision.rect = pygame.Rect(0, 0, 25, 80)
|
||||
# collision.rect.center = self.rect.center
|
||||
# self.collisionBoxes.append(collision)
|
||||
|
||||
|
||||
def crouch(self):
|
||||
|
||||
@@ -64,6 +64,7 @@ class StandingEnemy(Enemy):
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def __init__(self, mainGameClass):
|
||||
Enemy.__init__(self, mainGameClass)
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
Reference in New Issue
Block a user