Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from LucasHazardous/dev
Browse files Browse the repository at this point in the history
Guardian class update, final boss with stages added
  • Loading branch information
LucasHazardous committed Oct 26, 2022
2 parents 0107f1d + d76456c commit d758183
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 41 deletions.
1 change: 1 addition & 0 deletions credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ https://oco.itch.io/cyberpunk-character-pack-2
https://biopticmarz.itch.io/pixel-robot-enemy
https://ppeldo.itch.io/2d-pixel-art-game-spellmagic-fx
https://luizmelo.itch.io/martial-hero
https://luizmelo.itch.io/martial-hero-2

Dialogues:
https://ttsmp3.com/
Binary file added src/assets/audio/final-boss-dialogue.mp3
Binary file not shown.
Binary file added src/assets/images/entities/finalBoss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/images/entities/guardian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/stages/finalBossMeeting.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 33 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@
"audio": "./assets/audio/cinematic-metal.mp3",
"guardianPos": (700, 380),
"playerPos": (200, 380)
},
{
"category": "cutscene",
"audio": "./assets/audio/final-boss-dialogue.mp3",
"background": "./assets/images/stages/finalBossMeeting.jpg"
},
{
"category": "normal",
"background": "./assets/images/stages/exit.png",
"audio": "./assets/audio/80s-synth-wave.mp3",
"finalBossPos": (700, 380),
"playerPos": (200, 380)
}
]

Expand Down Expand Up @@ -179,11 +191,10 @@
}

guardianConfig = {
"ANIMATION_STEPS": [8, 6, 6, 4],
"ANIMATION_STEPS": [8, 6, 6],
"ANIM_DEATH": 2,
"ANIM_RUN": 0,
"ANIM_ATTACK": 1,
"ANIM_HIT": 3,
"SIZE_X": 200,
"SIZE_Y": 200,
"SCALE": 3,
Expand All @@ -198,6 +209,26 @@
"ATTACK_FRAME": 4
}

finalBossConfig = {
"ANIMATION_STEPS": [8, 4, 7],
"ANIM_DEATH": 2,
"ANIM_RUN": 0,
"ANIM_ATTACK": 1,
"ANIM_HIT": 3,
"SIZE_X": 200,
"SIZE_Y": 200,
"SCALE": 3,
"OFFSET": [85, 70],
"ANIMATION_COOLDOWN": 100,
"HITBOX_WIDTH": 96,
"HITBOX_HEIGHT": 180,
"BASE_SPEED": 5,
"BASE_HEALTH": 150,
"DAMAGE": 10,
"SPEED": 4,
"ATTACK_FRAME": 3
}

projectileConfig = {
"SPEED": 20,
"ANIMATION_STEPS": [45],
Expand Down
6 changes: 6 additions & 0 deletions src/entity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from entity.player import Player
from entity.emp import Emp
from entity.enemy.shootingEnemy import ShootingEnemy
from entity.enemy.walkingEnemy import WalkingEnemy
from entity.enemy.boss import Boss
from entity.enemy.guardian import Guardian
27 changes: 11 additions & 16 deletions src/entity/enemy/guardian.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import pygame
from time import time
from config import guardianConfig
from entity.entity import Entity
from random import randrange


class Guardian(Entity):
def __init__(self, x, y, guardianSpritesheet):
def __init__(self, x, y, guardianSpritesheet, guardianConfig):
self.guardianConfig = guardianConfig
super().__init__(x, y, guardianSpritesheet, guardianConfig)
self.hit = False

def updateAnimation(self, surface, player):
attackRange = pygame.Rect((self.body.left if self.flip else self.body.right)-self.body.width,
self.body.top-self.body.height*0.5, self.body.width*2, self.body.height*1.5)

if self.health <= 0 or not player.alive:
self.health = 0
self._updateAction(guardianConfig["ANIM_DEATH"])
self._updateAction(self.guardianConfig["ANIM_DEATH"])
elif (attackRange.colliderect(player.body)):
self._updateAction(guardianConfig["ANIM_ATTACK"])
elif self.hit:
self._updateAction(guardianConfig["ANIM_HIT"])
self._updateAction(self.guardianConfig["ANIM_ATTACK"])
else:
self._updateAction(guardianConfig["ANIM_RUN"])
self._updateAction(self.guardianConfig["ANIM_RUN"])

current = pygame.time.get_ticks()
self.image = self.animationList[self.action][self.frameIndex]
Expand All @@ -31,27 +28,25 @@ def updateAnimation(self, surface, player):
self.frameIndex += 1
self.lastAnimationUpdateTime = current

if self.action == guardianConfig["ANIM_ATTACK"] and self.frameIndex == guardianConfig["ATTACK_FRAME"]:
if self.action == self.guardianConfig["ANIM_ATTACK"] and self.frameIndex == self.guardianConfig["ATTACK_FRAME"]:
if (attackRange.colliderect(player.body)):
player.health -= guardianConfig["DAMAGE"]
player.health -= self.guardianConfig["DAMAGE"]
player.hit = True
player.body.y -= 100
self.frameIndex += 1

if self.frameIndex >= len(self.animationList[self.action]):
self.frameIndex = 0
if self.action == guardianConfig["ANIM_DEATH"]:
if self.action == self.guardianConfig["ANIM_DEATH"]:
self.alive = False
elif self.action == guardianConfig["ANIM_HIT"]:
self.hit = False

if (self.action == guardianConfig["ANIM_RUN"]):
if (self.action == self.guardianConfig["ANIM_RUN"]):
self.__moveCloserToPlayer(player)

def __moveCloserToPlayer(self, player):
if (player.body.centerx > self.body.centerx):
self.body.x += guardianConfig["SPEED"]
self.body.x += self.guardianConfig["SPEED"]
self.flip = False
elif (player.body.centerx < self.body.centerx):
self.body.x -= guardianConfig["SPEED"]
self.body.x -= self.guardianConfig["SPEED"]
self.flip = True
41 changes: 18 additions & 23 deletions src/stageLoader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from entity.player import Player
from entity.enemy.shootingEnemy import ShootingEnemy
from entity.enemy.walkingEnemy import WalkingEnemy
from entity.emp import Emp
from entity.enemy.boss import Boss
from entity.enemy.guardian import Guardian
from config import colorsConfig, gameSettings
from entity import *
from config import colorsConfig, gameSettings, guardianConfig, finalBossConfig

import pygame
from pygame.locals import DOUBLEBUF, HWSURFACE
Expand All @@ -30,15 +25,12 @@ def __init__(self):
iconImg = pygame.image.load("./assets/images/icon.png").convert()
pygame.display.set_icon(iconImg)

self.__playerSpritesheet = pygame.image.load(SPRITESHEET_PATH + "player.png").convert_alpha()
self.__shootingEnemySpritesheet = pygame.image.load(SPRITESHEET_PATH + "shootingEnemy.png").convert_alpha()
self.__projectile = pygame.image.load(SPRITESHEET_PATH + "projectile.png").convert_alpha()
self.__empSpritesheet = pygame.image.load(SPRITESHEET_PATH + "emp.png").convert_alpha()
self.__bossSpritesheet = pygame.image.load(SPRITESHEET_PATH + "boss.png").convert_alpha()
self.__walkingEnemySpritesheet = pygame.image.load(SPRITESHEET_PATH + "walkingEnemy.png").convert_alpha()
self.__guardianSpritesheet = pygame.image.load(SPRITESHEET_PATH + "guardian.png").convert_alpha()

self.__emp = Emp(0, 0, self.__empSpritesheet)
self.__spritesheets = {}
spritesheetTargets = ["player", "shootingEnemy", "projectile", "emp", "boss", "walkingEnemy", "guardian", "finalBoss"]
for target in spritesheetTargets:
self.__spritesheets[target] = pygame.image.load(SPRITESHEET_PATH + target + ".png").convert_alpha()

self.__emp = Emp(0, 0, self.__spritesheets["emp"])

def __playAudio(self, audioPath, loop=-1):
pygame.mixer.music.load(audioPath)
Expand Down Expand Up @@ -72,24 +64,27 @@ def playCutscene(self, category, audio, background):
quit()


def loadNormalStage(self, category, background, audio, playerPos, shootingEnemiesPos=[], walkingEnemiesPos=[], bossPos=None, guardianPos=None):
def loadNormalStage(self, category, background, audio, playerPos, shootingEnemiesPos=[], walkingEnemiesPos=[], bossPos=None, guardianPos=None, finalBossPos=None):
convertedBackground = pygame.image.load(background).convert()

player = Player(playerPos[0], playerPos[1], self.__playerSpritesheet, self.__emp)
player = Player(playerPos[0], playerPos[1], self.__spritesheets["player"], self.__emp)

enemies = []

for enemyPos in shootingEnemiesPos:
enemies.append(ShootingEnemy(enemyPos[0], enemyPos[1], self.__shootingEnemySpritesheet, self.__projectile))
enemies.append(ShootingEnemy(enemyPos[0], enemyPos[1], self.__spritesheets["shootingEnemy"], self.__spritesheets["projectile"]))

for enemyPos in walkingEnemiesPos:
enemies.append(WalkingEnemy(enemyPos[0], enemyPos[1], self.__walkingEnemySpritesheet))
enemies.append(WalkingEnemy(enemyPos[0], enemyPos[1], self.__spritesheets["walkingEnemy"]))

if(bossPos != None):
enemies.append(Boss(bossPos[0], bossPos[1], self.__bossSpritesheet))
enemies.append(Boss(bossPos[0], bossPos[1], self.__spritesheets["boss"]))

if(guardianPos != None):
enemies.append(Guardian(guardianPos[0], guardianPos[1], self.__guardianSpritesheet))
enemies.append(Guardian(guardianPos[0], guardianPos[1], self.__spritesheets["guardian"], guardianConfig))

if(finalBossPos != None):
enemies.append(Guardian(finalBossPos[0], finalBossPos[1], self.__spritesheets["finalBoss"], finalBossConfig))

if(audio != ""): self.__playAudio(audio)
self.__emp.finished = False
Expand Down Expand Up @@ -126,4 +121,4 @@ def loadNormalStage(self, category, background, audio, playerPos, shootingEnemie

pygame.display.update()

if(repeatThisStage): self.loadNormalStage(category, background, audio, playerPos, shootingEnemiesPos, walkingEnemiesPos, bossPos, guardianPos)
if(repeatThisStage): self.loadNormalStage(category, background, audio, playerPos, shootingEnemiesPos, walkingEnemiesPos, bossPos, guardianPos, finalBossPos)

0 comments on commit d758183

Please sign in to comment.