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 #6 from LucasHazardous/dev
Browse files Browse the repository at this point in the history
New enemy - guardian, more stages, game icon
  • Loading branch information
LucasHazardous committed Oct 23, 2022
2 parents fefb8c6 + 19ead1a commit 0107f1d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
1 change: 1 addition & 0 deletions credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ https://lornn.itch.io/cyberpunk-backgrounds
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

Dialogues:
https://ttsmp3.com/
Binary file added src/assets/audio/guardian-dialogue.mp3
Binary file not shown.
Binary file added 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/icon.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/guardianMeeting.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@
"audio": "./assets/audio/cinematic-metal.mp3",
"bossPos": (700, 380),
"playerPos": (200, 380)
},
{
"category": "cutscene",
"audio": "./assets/audio/guardian-dialogue.mp3",
"background": "./assets/images/stages/guardianMeeting.jpg"
},
{
"category": "normal",
"background": "./assets/images/stages/highway.png",
"audio": "./assets/audio/cinematic-metal.mp3",
"guardianPos": (700, 380),
"playerPos": (200, 380)
}
]

Expand Down Expand Up @@ -166,6 +178,26 @@
"TELEPORT_RANGE": (100, 800)
}

guardianConfig = {
"ANIMATION_STEPS": [8, 6, 6, 4],
"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": 300,
"DAMAGE": 10,
"SPEED": 4,
"ATTACK_FRAME": 4
}

projectileConfig = {
"SPEED": 20,
"ANIMATION_STEPS": [45],
Expand Down
57 changes: 57 additions & 0 deletions src/entity/enemy/guardian.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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):
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"])
elif (attackRange.colliderect(player.body)):
self._updateAction(guardianConfig["ANIM_ATTACK"])
elif self.hit:
self._updateAction(guardianConfig["ANIM_HIT"])
else:
self._updateAction(guardianConfig["ANIM_RUN"])

current = pygame.time.get_ticks()
self.image = self.animationList[self.action][self.frameIndex]

if current - self.lastAnimationUpdateTime > self.animationCooldown:
self.frameIndex += 1
self.lastAnimationUpdateTime = current

if self.action == guardianConfig["ANIM_ATTACK"] and self.frameIndex == guardianConfig["ATTACK_FRAME"]:
if (attackRange.colliderect(player.body)):
player.health -= 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"]:
self.alive = False
elif self.action == guardianConfig["ANIM_HIT"]:
self.hit = False

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

def __moveCloserToPlayer(self, player):
if (player.body.centerx > self.body.centerx):
self.body.x += guardianConfig["SPEED"]
self.flip = False
elif (player.body.centerx < self.body.centerx):
self.body.x -= guardianConfig["SPEED"]
self.flip = True
12 changes: 10 additions & 2 deletions src/stageLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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

import pygame
Expand All @@ -25,13 +26,17 @@ def __init__(self):
self.__clock = pygame.time.Clock()

self.__screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), flags, DEPTH)

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)

Expand Down Expand Up @@ -67,7 +72,7 @@ def playCutscene(self, category, audio, background):
quit()


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

player = Player(playerPos[0], playerPos[1], self.__playerSpritesheet, self.__emp)
Expand All @@ -82,6 +87,9 @@ def loadNormalStage(self, category, background, audio, playerPos, shootingEnemie

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

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

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

pygame.display.update()

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

0 comments on commit 0107f1d

Please sign in to comment.