@@ -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))
|
mainGameClass.getScreenHeight()/2-100)+50*(2-cloudType))
|
||||||
self.speed = cloudType*mainGameClass.getGameSpeed() / 6
|
self.speed = cloudType*mainGameClass.getGameSpeed() / 6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.__doubleX = float(self.rect.x)
|
self.__doubleX = float(self.rect.x)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-3
@@ -5,9 +5,11 @@ Main game class
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
|
import os
|
||||||
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
from Background import Background
|
||||||
from Player import Player
|
from Player import Player
|
||||||
from StandingEnemy import StandingEnemy
|
from StandingEnemy import StandingEnemy
|
||||||
from FlyingEnemy import FlyingEnemy
|
from FlyingEnemy import FlyingEnemy
|
||||||
@@ -57,6 +59,8 @@ class Drakora():
|
|||||||
|
|
||||||
|
|
||||||
def newGame(self):
|
def newGame(self):
|
||||||
|
self.background = Background(self)
|
||||||
|
|
||||||
for enemy in self.enemies:
|
for enemy in self.enemies:
|
||||||
enemy.kill()
|
enemy.kill()
|
||||||
|
|
||||||
@@ -102,7 +106,7 @@ class Drakora():
|
|||||||
|
|
||||||
self.targetFps = 120
|
self.targetFps = 120
|
||||||
|
|
||||||
self.floorHeight = 50
|
self.floorHeight = 64
|
||||||
|
|
||||||
self.players = pygame.sprite.Group()
|
self.players = pygame.sprite.Group()
|
||||||
self.floors = pygame.sprite.Group()
|
self.floors = pygame.sprite.Group()
|
||||||
@@ -120,7 +124,6 @@ class Drakora():
|
|||||||
self.isGodmode = False
|
self.isGodmode = False
|
||||||
self.drawBoxes = False
|
self.drawBoxes = False
|
||||||
|
|
||||||
|
|
||||||
font = pygame.font.match_font('liberation mono')
|
font = pygame.font.match_font('liberation mono')
|
||||||
self.fontScore = pygame.font.Font(font, 32)
|
self.fontScore = pygame.font.Font(font, 32)
|
||||||
self.fontMessage = pygame.font.Font(font, 56)
|
self.fontMessage = pygame.font.Font(font, 56)
|
||||||
@@ -153,7 +156,8 @@ class Drakora():
|
|||||||
|
|
||||||
|
|
||||||
def render(self):
|
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)
|
for cloudGroup in self.cloudGroups: cloudGroup.draw(self.screen)
|
||||||
self.enemies.draw(self.screen)
|
self.enemies.draw(self.screen)
|
||||||
self.players.draw(self.screen)
|
self.players.draw(self.screen)
|
||||||
@@ -287,6 +291,7 @@ class Drakora():
|
|||||||
self.doCheats()
|
self.doCheats()
|
||||||
|
|
||||||
if not self.isGameOver and not self.isPaused:
|
if not self.isGameOver and not self.isPaused:
|
||||||
|
self.background.update()
|
||||||
for cloudGroup in self.cloudGroups: cloudGroup.update()
|
for cloudGroup in self.cloudGroups: cloudGroup.update()
|
||||||
self.enemies.update()
|
self.enemies.update()
|
||||||
self.players.update()
|
self.players.update()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Floor(pygame.sprite.Sprite):
|
|||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.image = pygame.Surface((mainGameClass.getScreenWidth(),
|
self.image = pygame.Surface((mainGameClass.getScreenWidth(),
|
||||||
mainGameClass.getFloorHeight()*101))
|
mainGameClass.getFloorHeight()*101))
|
||||||
self.image.fill((255, 204, 102))
|
self.image.fill((255, 229, 180))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = (mainGameClass.getScreenWidth()/2,
|
self.rect.center = (mainGameClass.getScreenWidth()/2,
|
||||||
mainGameClass.getScreenHeight() +
|
mainGameClass.getScreenHeight() +
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class FlyingEnemy(Enemy):
|
|||||||
for image in images:
|
for image in images:
|
||||||
image.set_colorkey((255,0,255))
|
image.set_colorkey((255,0,255))
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, mainGameClass):
|
def __init__(self, mainGameClass):
|
||||||
Enemy.__init__(self, mainGameClass)
|
Enemy.__init__(self, mainGameClass)
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ class Player(pygame.sprite.Sprite):
|
|||||||
pygame.transform.scale(playerImage.subsurface((0, 72, 16, 16)), (64, 64)),
|
pygame.transform.scale(playerImage.subsurface((0, 72, 16, 16)), (64, 64)),
|
||||||
pygame.transform.scale(playerImage.subsurface((16, 72, 16, 16)), (64, 64)),
|
pygame.transform.scale(playerImage.subsurface((16, 72, 16, 16)), (64, 64)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
for array in (walkImages, upImages, downImages, crouchImages):
|
for array in (walkImages, upImages, downImages, crouchImages):
|
||||||
for image in array:
|
for image in array:
|
||||||
image.set_colorkey((255,0,255))
|
image.set_colorkey((255,0,255))
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class StandingEnemy(Enemy):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, mainGameClass):
|
def __init__(self, mainGameClass):
|
||||||
Enemy.__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