Reenabled Player and all animations, upgrades, attacks and spells
This commit is contained in:
parent
83ab08326e
commit
cd0333cbff
37 changed files with 1262 additions and 469 deletions
0
game/configs/game/__init__.py
Normal file
0
game/configs/game/__init__.py
Normal file
|
@ -1,3 +1,9 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../../..', 'assets')
|
||||||
|
|
||||||
magic_data = {
|
magic_data = {
|
||||||
'flame': {'strength': 5,'cost': 20,'graphic':'../Graphics/particles/flame/fire.png'},
|
'flame': {'strength': 5, 'cost': 20, 'graphic': f"{asset_path}/graphics/particles/flame/fire.png"},
|
||||||
'heal' : {'strength': 20,'cost': 10,'graphic':'../Graphics/particles/heal/heal.png'}}
|
'heal': {'strength': 20, 'cost': 10, 'graphic': f"{asset_path}/graphics/particles/heal/heal.png"}}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../../..', 'assets')
|
||||||
|
|
||||||
weapon_data = {
|
weapon_data = {
|
||||||
'sword': {'cooldown': 100, 'damage': 15,'graphic':'../Graphics/weapons/sword/full.png'},
|
'sword': {'cooldown': 100, 'damage': 15, 'graphic': f"{asset_path}/graphics/weapons/sword/full.png"},
|
||||||
'lance': {'cooldown': 400, 'damage': 30,'graphic':'../Graphics/weapons/lance/full.png'},
|
'lance': {'cooldown': 400, 'damage': 30, 'graphic': f"{asset_path}/graphics/weapons/lance/full.png"},
|
||||||
'axe': {'cooldown': 300, 'damage': 20, 'graphic':'../Graphics/weapons/axe/full.png'},
|
'axe': {'cooldown': 300, 'damage': 20, 'graphic': f"{asset_path}/graphics/weapons/axe/full.png"},
|
||||||
'rapier':{'cooldown': 50, 'damage': 8, 'graphic':'../Graphics/weapons/rapier/full.png'},
|
'rapier': {'cooldown': 50, 'damage': 8, 'graphic': f"{asset_path}/graphics/weapons/rapier/full.png"},
|
||||||
'sai':{'cooldown': 80, 'damage': 10, 'graphic':'../Graphics/weapons/sai/full.png'}}
|
'sai': {'cooldown': 80, 'damage': 10, 'graphic': f"{asset_path}/graphics/weapons/sai/full.png"}
|
||||||
|
}
|
||||||
|
|
0
game/configs/system/__init__.py
Normal file
0
game/configs/system/__init__.py
Normal file
|
@ -9,15 +9,7 @@ HITBOX_OFFSET = {
|
||||||
'object': (0, -40),
|
'object': (0, -40),
|
||||||
'grass': (0, -10),
|
'grass': (0, -10),
|
||||||
'invisible': (0, 0)
|
'invisible': (0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
# ui
|
|
||||||
BAR_HEIGHT = 20
|
|
||||||
HEALTH_BAR_WIDTH = 200
|
|
||||||
ENERGY_BAR_WIDTH = 140
|
|
||||||
ITEM_BOX_SIZE = 80
|
|
||||||
UI_FONT = '../Graphics/graphics/font/joystix.ttf'
|
|
||||||
UI_FONT_SIZE = 18
|
|
||||||
|
|
||||||
# general colors
|
# general colors
|
||||||
WATER_COLOR = '#71ddee'
|
WATER_COLOR = '#71ddee'
|
||||||
|
@ -36,22 +28,22 @@ BAR_COLOR = '#EEEEEE'
|
||||||
BAR_COLOR_SELECTED = '#111111'
|
BAR_COLOR_SELECTED = '#111111'
|
||||||
UPGRADE_BG_COLOR_SELECTED = '#EEEEEE'
|
UPGRADE_BG_COLOR_SELECTED = '#EEEEEE'
|
||||||
|
|
||||||
# weapons
|
# # weapons
|
||||||
weapon_data = {
|
# weapon_data = {
|
||||||
'sword': {'cooldown': 100, 'damage': 15,'graphic':'../Graphics/graphics/weapons/sword/full.png'},
|
# 'sword': {'cooldown': 100, 'damage': 15,'graphic':'../Graphics/graphics/weapons/sword/full.png'},
|
||||||
'lance': {'cooldown': 400, 'damage': 30,'graphic':'../Graphics/graphics/weapons/lance/full.png'},
|
# 'lance': {'cooldown': 400, 'damage': 30,'graphic':'../Graphics/graphics/weapons/lance/full.png'},
|
||||||
'axe': {'cooldown': 300, 'damage': 20, 'graphic':'../Graphics/graphics/weapons/axe/full.png'},
|
# 'axe': {'cooldown': 300, 'damage': 20, 'graphic':'../Graphics/graphics/weapons/axe/full.png'},
|
||||||
'rapier':{'cooldown': 50, 'damage': 8, 'graphic':'../Graphics/graphics/weapons/rapier/full.png'},
|
# 'rapier':{'cooldown': 50, 'damage': 8, 'graphic':'../Graphics/graphics/weapons/rapier/full.png'},
|
||||||
'sai':{'cooldown': 80, 'damage': 10, 'graphic':'../Graphics/graphics/weapons/sai/full.png'}}
|
# 'sai':{'cooldown': 80, 'damage': 10, 'graphic':'../Graphics/graphics/weapons/sai/full.png'}}
|
||||||
|
#
|
||||||
# magic
|
# # magic
|
||||||
magic_data = {
|
# magic_data = {
|
||||||
'flame': {'strength': 5,'cost': 20,'graphic':'../Graphics/graphics/particles/flame/fire.png'},
|
# 'flame': {'strength': 5,'cost': 20,'graphic':'../Graphics/graphics/particles/flame/fire.png'},
|
||||||
'heal' : {'strength': 20,'cost': 10,'graphic':'../Graphics/graphics/particles/heal/heal.png'}}
|
# 'heal' : {'strength': 20,'cost': 10,'graphic':'../Graphics/graphics/particles/heal/heal.png'}}
|
||||||
|
#
|
||||||
# enemy
|
# # enemy
|
||||||
monster_data = {
|
# monster_data = {
|
||||||
'squid': {'health': 100,'exp':100,'damage':20,'attack_type': 'slash', 'attack_sound':'../Graphics/audio/attack/slash.wav', 'speed': 3, 'resistance': 3, 'attack_radius': 80, 'notice_radius': 360},
|
# 'squid': {'health': 100,'exp':100,'damage':20,'attack_type': 'slash', 'attack_sound':'../Graphics/audio/attack/slash.wav', 'speed': 3, 'resistance': 3, 'attack_radius': 80, 'notice_radius': 360},
|
||||||
'raccoon': {'health': 300,'exp':250,'damage':40,'attack_type': 'claw', 'attack_sound':'../Graphics/audio/attack/claw.wav','speed': 2, 'resistance': 3, 'attack_radius': 120, 'notice_radius': 400},
|
# 'raccoon': {'health': 300,'exp':250,'damage':40,'attack_type': 'claw', 'attack_sound':'../Graphics/audio/attack/claw.wav','speed': 2, 'resistance': 3, 'attack_radius': 120, 'notice_radius': 400},
|
||||||
'spirit': {'health': 100,'exp':110,'damage':8,'attack_type': 'thunder', 'attack_sound':'../Graphics/audio/attack/fireball.wav', 'speed': 4, 'resistance': 3, 'attack_radius': 60, 'notice_radius': 350},
|
# 'spirit': {'health': 100,'exp':110,'damage':8,'attack_type': 'thunder', 'attack_sound':'../Graphics/audio/attack/fireball.wav', 'speed': 4, 'resistance': 3, 'attack_radius': 60, 'notice_radius': 350},
|
||||||
'bamboo': {'health': 70,'exp':120,'damage':6,'attack_type': 'leaf_attack', 'attack_sound':'../Graphics/audio/attack/slash.wav', 'speed': 3, 'resistance': 3, 'attack_radius': 50, 'notice_radius': 300}}
|
# 'bamboo': {'health': 70,'exp':120,'damage':6,'attack_type': 'leaf_attack', 'attack_sound':'../Graphics/audio/attack/slash.wav', 'speed': 3, 'resistance': 3, 'attack_radius': 50, 'notice_radius': 300}}
|
||||||
|
|
|
@ -1,49 +1,61 @@
|
||||||
import pygame
|
import pygame
|
||||||
from utils.settings import *
|
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
from configs.system.window_config import TILESIZE
|
||||||
|
|
||||||
|
from configs.game.spell_config import *
|
||||||
|
|
||||||
|
|
||||||
class MagicPlayer:
|
class MagicPlayer:
|
||||||
def __init__(self, animation_player):
|
def __init__(self, animation_player):
|
||||||
self.animation_player = animation_player
|
self.animation_player = animation_player
|
||||||
|
|
||||||
# Sound Setup
|
# Sound Setup
|
||||||
self.sounds = {
|
# self.sounds = {
|
||||||
'heal': pygame.mixer.Sound('../Graphics/audio/heal.wav'),
|
# 'heal': pygame.mixer.Sound('../Graphics/audio/heal.wav'),
|
||||||
'flame': pygame.mixer.Sound('../Graphics/audio/flame.wav')
|
# 'flame': pygame.mixer.Sound('../Graphics/audio/flame.wav')
|
||||||
}
|
# }
|
||||||
|
|
||||||
def heal(self, player, strength, cost, groups):
|
def heal(self, player, strength, cost, groups):
|
||||||
if player.energy >= cost:
|
if player.stats.energy >= cost:
|
||||||
self.sounds['heal'].play()
|
# self.sounds['heal'].play()
|
||||||
player.health += strength
|
player.stats.health += strength
|
||||||
player.energy -= cost
|
player.stats.energy -= cost
|
||||||
if player.health >= player.stats['health']:
|
if player.stats.health >= player.stats.stats['health']:
|
||||||
player.health = player.stats['health']
|
player.stats.health = player.stats.stats['health']
|
||||||
self.animation_player.generate_particles('aura', player.rect.center, groups)
|
self.animation_player.generate_particles(
|
||||||
self.animation_player.generate_particles('heal', player.rect.center + pygame.math.Vector2(0, -50), groups)
|
'aura', player.rect.center, groups)
|
||||||
|
self.animation_player.generate_particles(
|
||||||
|
'heal', player.rect.center + pygame.math.Vector2(0, -50), groups)
|
||||||
|
|
||||||
def flame(self, player, cost, groups):
|
def flame(self, player, cost, groups):
|
||||||
if player.energy >= cost:
|
if player.stats.energy >= cost:
|
||||||
player.energy -= cost
|
player.stats.energy -= cost
|
||||||
self.sounds['flame'].play()
|
# self.sounds['flame'].play()
|
||||||
|
|
||||||
if player.status.split('_')[0] == 'right':
|
if player.status.split('_')[0] == 'right':
|
||||||
direction = pygame.math.Vector2(1,0)
|
direction = pygame.math.Vector2(1, 0)
|
||||||
elif player.status.split('_')[0] == 'left':
|
elif player.status.split('_')[0] == 'left':
|
||||||
direction = pygame.math.Vector2(-1,0)
|
direction = pygame.math.Vector2(-1, 0)
|
||||||
elif player.status.split('_')[0] == 'up':
|
elif player.status.split('_')[0] == 'up':
|
||||||
direction = pygame.math.Vector2(0,-1)
|
direction = pygame.math.Vector2(0, -1)
|
||||||
else:
|
else:
|
||||||
direction = pygame.math.Vector2(0,1)
|
direction = pygame.math.Vector2(0, 1)
|
||||||
|
|
||||||
for i in range(1, 6):
|
for i in range(1, 6):
|
||||||
if direction.x:
|
if direction.x:
|
||||||
offset_x = direction.x * i * TILESIZE
|
offset_x = direction.x * i * TILESIZE
|
||||||
x = player.rect.centerx + offset_x + randint(-TILESIZE // 3, TILESIZE //3)
|
x = player.rect.centerx + offset_x + \
|
||||||
y = player.rect.centery + randint(-TILESIZE // 3, TILESIZE //3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
self.animation_player.generate_particles('flame', (x,y), groups)
|
y = player.rect.centery + \
|
||||||
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
|
self.animation_player.generate_particles(
|
||||||
|
'flame', (x, y), groups)
|
||||||
else:
|
else:
|
||||||
offset_y = direction.y * i * TILESIZE
|
offset_y = direction.y * i * TILESIZE
|
||||||
x = player.rect.centerx + randint(-TILESIZE // 3, TILESIZE //3)
|
x = player.rect.centerx + \
|
||||||
y = player.rect.centery + offset_y + randint(-TILESIZE // 3, TILESIZE //3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
self.animation_player.generate_particles('flame', (x,y), groups)
|
y = player.rect.centery + offset_y + \
|
||||||
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
|
self.animation_player.generate_particles(
|
||||||
|
'flame', (x, y), groups)
|
||||||
|
|
|
@ -1,42 +1,56 @@
|
||||||
|
import os
|
||||||
import pygame
|
import pygame
|
||||||
from utils.support import import_folder
|
|
||||||
|
from utils.resource_loader import import_folder
|
||||||
from random import choice
|
from random import choice
|
||||||
|
|
||||||
|
|
||||||
class AnimationPlayer:
|
class AnimationPlayer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
|
||||||
self.frames = {
|
self.frames = {
|
||||||
# magic
|
# magic
|
||||||
'flame': import_folder('../Graphics/graphics/particles/flame/frames'),
|
'flame': import_folder(f'{asset_path}/graphics/particles/flame/frames'),
|
||||||
'aura': import_folder('../Graphics/graphics/particles/aura'),
|
'aura': import_folder(f'{asset_path}/graphics/particles/aura'),
|
||||||
'heal': import_folder('../Graphics/graphics/particles/heal/frames'),
|
'heal': import_folder(f'{asset_path}/graphics/particles/heal/frames'),
|
||||||
|
|
||||||
# attacks
|
# attacks
|
||||||
'claw': import_folder('../Graphics/graphics/particles/claw'),
|
'claw': import_folder(f'{asset_path}/graphics/particles/claw'),
|
||||||
'slash': import_folder('../Graphics/graphics/particles/slash'),
|
'slash': import_folder(f'{asset_path}/graphics/particles/slash'),
|
||||||
'sparkle': import_folder('../Graphics/graphics/particles/sparkle'),
|
'sparkle': import_folder(f'{asset_path}/graphics/particles/sparkle'),
|
||||||
'leaf_attack': import_folder('../Graphics/graphics/particles/leaf_attack'),
|
'leaf_attack': import_folder(f'{asset_path}/graphics/particles/leaf_attack'),
|
||||||
'thunder': import_folder('../Graphics/graphics/particles/thunder'),
|
'thunder': import_folder(f'{asset_path}/graphics/particles/thunder'),
|
||||||
|
|
||||||
# monster deaths
|
# monster deaths
|
||||||
'squid': import_folder('../Graphics/graphics/particles/smoke_orange'),
|
'squid': import_folder(f'{asset_path}/graphics/particles/smoke_orange'),
|
||||||
'raccoon': import_folder('../Graphics/graphics/particles/raccoon'),
|
'raccoon': import_folder(f'{asset_path}/graphics/particles/raccoon'),
|
||||||
'spirit': import_folder('../Graphics/graphics/particles/nova'),
|
'spirit': import_folder(f'{asset_path}/graphics/particles/nova'),
|
||||||
'bamboo': import_folder('../Graphics/graphics/particles/bamboo'),
|
'bamboo': import_folder(f'{asset_path}/graphics/particles/bamboo'),
|
||||||
|
|
||||||
# leafs
|
# leafs
|
||||||
'leaf': (
|
'leaf': (
|
||||||
import_folder('../Graphics/graphics/particles/leaf1'),
|
import_folder(f'{asset_path}/graphics/particles/leaf1'),
|
||||||
import_folder('../Graphics/graphics/particles/leaf2'),
|
import_folder(f'{asset_path}/graphics/particles/leaf2'),
|
||||||
import_folder('../Graphics/graphics/particles/leaf3'),
|
import_folder(f'{asset_path}/graphics/particles/leaf3'),
|
||||||
import_folder('../Graphics/graphics/particles/leaf4'),
|
import_folder(f'{asset_path}/graphics/particles/leaf4'),
|
||||||
import_folder('../Graphics/graphics/particles/leaf5'),
|
import_folder(f'{asset_path}/graphics/particles/leaf5'),
|
||||||
import_folder('../Graphics/graphics/particles/leaf6'),
|
import_folder(f'{asset_path}/graphics/particles/leaf6'),
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf1')),
|
self.reflect_images(import_folder(
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf2')),
|
f'{asset_path}/graphics/particles/leaf1')),
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf3')),
|
self.reflect_images(import_folder(
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf4')),
|
f'{asset_path}/graphics/particles/leaf2')),
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf5')),
|
self.reflect_images(import_folder(
|
||||||
self.reflect_images(import_folder('../Graphics/graphics/particles/leaf6'))
|
f'{asset_path}/graphics/particles/leaf3')),
|
||||||
|
self.reflect_images(import_folder(
|
||||||
|
f'{asset_path}/graphics/particles/leaf4')),
|
||||||
|
self.reflect_images(import_folder(
|
||||||
|
f'{asset_path}/graphics/particles/leaf5')),
|
||||||
|
self.reflect_images(import_folder(
|
||||||
|
f'{asset_path}/graphics/particles/leaf6'))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +63,13 @@ class AnimationPlayer:
|
||||||
|
|
||||||
def create_grass_particles(self, position, groups):
|
def create_grass_particles(self, position, groups):
|
||||||
animation_frames = choice(self.frames['leaf'])
|
animation_frames = choice(self.frames['leaf'])
|
||||||
ParticleEffect(position, animation_frames,groups)
|
ParticleEffect(position, animation_frames, groups)
|
||||||
|
|
||||||
def generate_particles(self, animation_type, position, groups):
|
def generate_particles(self, animation_type, position, groups):
|
||||||
animation_frames = self.frames[animation_type]
|
animation_frames = self.frames[animation_type]
|
||||||
ParticleEffect(position, animation_frames, groups)
|
ParticleEffect(position, animation_frames, groups)
|
||||||
|
|
||||||
|
|
||||||
class ParticleEffect(pygame.sprite.Sprite):
|
class ParticleEffect(pygame.sprite.Sprite):
|
||||||
def __init__(self, position, animation_frames, groups):
|
def __init__(self, position, animation_frames, groups):
|
||||||
super().__init__(groups)
|
super().__init__(groups)
|
||||||
|
@ -62,7 +77,7 @@ class ParticleEffect(pygame.sprite.Sprite):
|
||||||
self.animation_speed = 0.15
|
self.animation_speed = 0.15
|
||||||
self.frames = animation_frames
|
self.frames = animation_frames
|
||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
self.rect = self.image.get_rect(center = position)
|
self.rect = self.image.get_rect(center=position)
|
||||||
self.sprite_type = 'magic'
|
self.sprite_type = 'magic'
|
||||||
|
|
||||||
def animate(self):
|
def animate(self):
|
||||||
|
|
|
@ -1,23 +1,33 @@
|
||||||
|
import os
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
class Weapon(pygame.sprite.Sprite):
|
class Weapon(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def __init__(self, player, groups):
|
def __init__(self, player, groups):
|
||||||
super().__init__(groups)
|
super().__init__(groups)
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
|
||||||
self.sprite_type = 'weapon'
|
self.sprite_type = 'weapon'
|
||||||
direction = player.status.split('_')[0]
|
direction = player.status.split('_')[0]
|
||||||
|
|
||||||
# Graphic
|
# Graphic
|
||||||
full_path = f"../Graphics/graphics/weapons/{player.weapon}/{direction}.png"
|
full_path = f"{asset_path}/graphics/weapons/{player._input.combat.weapon}/{direction}.png"
|
||||||
self.image = pygame.image.load(full_path).convert_alpha()
|
self.image = pygame.image.load(full_path).convert_alpha()
|
||||||
|
|
||||||
# Sprite Placement
|
# Sprite Placement
|
||||||
if direction == 'right':
|
if direction == 'right':
|
||||||
self.rect = self.image.get_rect(midleft = player.rect.midright + pygame.math.Vector2(0, 16))
|
self.rect = self.image.get_rect(
|
||||||
|
midleft=player.rect.midright + pygame.math.Vector2(0, 16))
|
||||||
elif direction == 'left':
|
elif direction == 'left':
|
||||||
self.rect = self.image.get_rect(midright = player.rect.midleft + pygame.math.Vector2(0, 16))
|
self.rect = self.image.get_rect(
|
||||||
|
midright=player.rect.midleft + pygame.math.Vector2(0, 16))
|
||||||
elif direction == 'down':
|
elif direction == 'down':
|
||||||
self.rect = self.image.get_rect(midtop = player.rect.midbottom + pygame.math.Vector2(-10, 0))
|
self.rect = self.image.get_rect(
|
||||||
|
midtop=player.rect.midbottom + pygame.math.Vector2(-10, 0))
|
||||||
else:
|
else:
|
||||||
self.rect = self.image.get_rect(midbottom = player.rect.midtop + pygame.math.Vector2(-10, 0))
|
self.rect = self.image.get_rect(
|
||||||
|
midbottom=player.rect.midtop + pygame.math.Vector2(-10, 0))
|
||||||
|
|
0
game/entities/__init__.py
Normal file
0
game/entities/__init__.py
Normal file
0
game/entities/components/__init__.py
Normal file
0
game/entities/components/__init__.py
Normal file
138
game/entities/components/_input.py
Normal file
138
game/entities/components/_input.py
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
import pygame
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
from configs.game.spell_config import magic_data
|
||||||
|
from configs.game.weapon_config import weapon_data
|
||||||
|
|
||||||
|
from .movement import MovementHandler
|
||||||
|
from .combat import CombatHandler
|
||||||
|
|
||||||
|
|
||||||
|
class InputHandler:
|
||||||
|
|
||||||
|
def __init__(self, sprite_type, status):
|
||||||
|
self.status = status
|
||||||
|
|
||||||
|
# Setup Movement
|
||||||
|
self.movement = MovementHandler(sprite_type)
|
||||||
|
self.move_cooldown = 15
|
||||||
|
self.can_move = True
|
||||||
|
self.move_time = None
|
||||||
|
|
||||||
|
# Setup Combat
|
||||||
|
self.combat = CombatHandler()
|
||||||
|
self.attacking = False
|
||||||
|
self.attack_cooldown = 400
|
||||||
|
self.attack_time = None
|
||||||
|
self.can_move = True
|
||||||
|
|
||||||
|
# Setup Special Actions
|
||||||
|
self.can_rotate_weapon = True
|
||||||
|
self.weapon_rotation_time = None
|
||||||
|
self.rotate_attack_cooldown = 600
|
||||||
|
|
||||||
|
self.can_swap_magic = True
|
||||||
|
self.magic_swap_time = None
|
||||||
|
|
||||||
|
def check_input(self, speed, hitbox, obstacle_sprites, rect, player):
|
||||||
|
|
||||||
|
if not self.attacking and self.can_move:
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
|
button = randint(0, 7)
|
||||||
|
|
||||||
|
self.move_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
|
# Movement Input
|
||||||
|
if button == 0: # keys[pygame.K_w]:
|
||||||
|
self.movement.direction.y = -1
|
||||||
|
self.status = 'up'
|
||||||
|
self.can_move = False
|
||||||
|
elif button == 1: # keys[pygame.K_s]:
|
||||||
|
self.movement.direction.y = 1
|
||||||
|
self.status = 'down'
|
||||||
|
self.can_move = False
|
||||||
|
else:
|
||||||
|
self.movement.direction.y = 0
|
||||||
|
|
||||||
|
if button == 2: # keys[pygame.K_a]:
|
||||||
|
self.movement.direction.x = -1
|
||||||
|
self.status = 'left'
|
||||||
|
self.can_move = False
|
||||||
|
elif button == 3: # keys[pygame.K_d]:
|
||||||
|
self.movement.direction.x = 1
|
||||||
|
self.status = 'right'
|
||||||
|
self.can_move = False
|
||||||
|
else:
|
||||||
|
self.movement.direction.x = 0
|
||||||
|
|
||||||
|
self.movement.move(speed, hitbox, obstacle_sprites, rect)
|
||||||
|
|
||||||
|
# Combat Input
|
||||||
|
if button == 4 and not self.attacking: # keys[pygame.K_e]
|
||||||
|
self.attacking = True
|
||||||
|
self.attack_time = pygame.time.get_ticks()
|
||||||
|
self.combat.create_attack_sprite(player)
|
||||||
|
# self.weapon_attack_sound.play()
|
||||||
|
|
||||||
|
# Magic Input
|
||||||
|
if button == 5: # keys[pygame.K_q]:
|
||||||
|
self.attacking = True
|
||||||
|
self.attack_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
|
self.combat.magic = list(magic_data.keys())[
|
||||||
|
self.combat.magic_index]
|
||||||
|
|
||||||
|
strength = list(magic_data.values())[
|
||||||
|
self.combat.magic_index]['strength'] + player.stats.magic
|
||||||
|
|
||||||
|
cost = list(magic_data.values())[
|
||||||
|
self.combat.magic_index]['cost']
|
||||||
|
print(self.combat.magic)
|
||||||
|
self.combat.create_magic_sprite(
|
||||||
|
player, self.combat.magic, strength, cost)
|
||||||
|
|
||||||
|
# Rotating Weapons
|
||||||
|
if button == 6 and self.can_rotate_weapon: # keys[pygame.K_LSHIFT]
|
||||||
|
self.can_rotate_weapon = False
|
||||||
|
self.weapon_rotation_time = pygame.time.get_ticks()
|
||||||
|
if self.combat.weapon_index < len(list(weapon_data.keys())) - 1:
|
||||||
|
self.combat.weapon_index += 1
|
||||||
|
else:
|
||||||
|
self.combat.weapon_index = 0
|
||||||
|
|
||||||
|
self.combat.weapon = list(weapon_data.keys())[
|
||||||
|
self.combat.weapon_index]
|
||||||
|
|
||||||
|
# Swap Spells
|
||||||
|
if button == 7 and self.can_swap_magic: # keys[pygame.K_LCTRL] :
|
||||||
|
self.can_swap_magic = False
|
||||||
|
self.magic_swap_time = pygame.time.get_ticks()
|
||||||
|
if self.combat.magic_index < len(list(magic_data.keys())) - 1:
|
||||||
|
self.combat.magic_index += 1
|
||||||
|
else:
|
||||||
|
self.combat.magic_index = 0
|
||||||
|
|
||||||
|
def cooldowns(self, vulnerable):
|
||||||
|
current_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
|
if self.attacking:
|
||||||
|
if current_time - self.attack_time > self.attack_cooldown + weapon_data[self.combat.weapon]['cooldown']:
|
||||||
|
self.attacking = False
|
||||||
|
if self.combat.current_attack:
|
||||||
|
self.combat.delete_attack_sprite()
|
||||||
|
|
||||||
|
if not self.can_rotate_weapon:
|
||||||
|
if current_time - self.weapon_rotation_time > self.rotate_attack_cooldown:
|
||||||
|
self.can_rotate_weapon = True
|
||||||
|
|
||||||
|
if not self.can_swap_magic:
|
||||||
|
if current_time - self.magic_swap_time > self.rotate_attack_cooldown:
|
||||||
|
self.can_swap_magic = True
|
||||||
|
|
||||||
|
if not vulnerable:
|
||||||
|
if current_time - self.hurt_time >= self.invulnerability_duration:
|
||||||
|
vulnerable = True
|
||||||
|
|
||||||
|
if not self.can_move:
|
||||||
|
if current_time - self.move_time >= self.move_cooldown:
|
||||||
|
self.can_move = True
|
69
game/entities/components/animaton.py
Normal file
69
game/entities/components/animaton.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
from math import sin
|
||||||
|
|
||||||
|
from utils.resource_loader import import_folder
|
||||||
|
from configs.system.window_config import HITBOX_OFFSET
|
||||||
|
|
||||||
|
|
||||||
|
class AnimationHandler:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.frame_index = 0
|
||||||
|
self.animation_speed = 0.15
|
||||||
|
|
||||||
|
def import_assets(self, sprite_type, position, name=None):
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../../..', 'assets', 'graphics')
|
||||||
|
if sprite_type == 'player':
|
||||||
|
|
||||||
|
character_path = f"{asset_path}/player"
|
||||||
|
|
||||||
|
# Import Graphic Assets
|
||||||
|
self.image = pygame.image.load(
|
||||||
|
f"{character_path}/down/down_0.png").convert_alpha()
|
||||||
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
|
self.hitbox = self.rect.inflate(HITBOX_OFFSET[sprite_type])
|
||||||
|
self.animations = {
|
||||||
|
'up': [], 'down': [], 'left': [], 'right': [],
|
||||||
|
'up_idle': [], 'down_idle': [], 'left_idle': [], 'right_idle': [],
|
||||||
|
'up_attack': [], 'down_attack': [], 'left_attack': [], 'right_attack': []
|
||||||
|
}
|
||||||
|
for animation in self.animations.keys():
|
||||||
|
full_path = f"{character_path}/{animation}"
|
||||||
|
self.animations[animation] = import_folder(full_path)
|
||||||
|
|
||||||
|
elif sprite_type == 'enemy':
|
||||||
|
|
||||||
|
character_path = f"{asset_path}/monsters/{name}"
|
||||||
|
self.animations = {'idle': [], 'move': [], 'attack': []}
|
||||||
|
main_path = f"{asset_path}/monsters/{name}"
|
||||||
|
|
||||||
|
for animation in self.animations.keys():
|
||||||
|
self.animations[animation] = import_folder(
|
||||||
|
f"{main_path}/{animation}")
|
||||||
|
|
||||||
|
def animate(self, status, vulnerable):
|
||||||
|
animation = self.animations[status]
|
||||||
|
|
||||||
|
self.frame_index += self.animation_speed
|
||||||
|
if self.frame_index >= len(animation):
|
||||||
|
self.frame_index = 0
|
||||||
|
|
||||||
|
# Set the image
|
||||||
|
self.image = animation[int(self.frame_index)]
|
||||||
|
self.rect = self.image.get_rect(center=self.hitbox.center)
|
||||||
|
|
||||||
|
if not vulnerable:
|
||||||
|
alpha = self.wave_value()
|
||||||
|
self.image.set_alpha(alpha)
|
||||||
|
else:
|
||||||
|
self.image.set_alpha(255)
|
||||||
|
|
||||||
|
def wave_value(self):
|
||||||
|
value = sin(pygame.time.get_ticks())
|
||||||
|
if value >= 0:
|
||||||
|
return 255
|
||||||
|
else:
|
||||||
|
return 0
|
59
game/entities/components/combat.py
Normal file
59
game/entities/components/combat.py
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from effects.weapon_effects import Weapon
|
||||||
|
from effects.magic_effects import MagicPlayer
|
||||||
|
from effects.particle_effects import AnimationPlayer
|
||||||
|
|
||||||
|
from configs.game.weapon_config import weapon_data
|
||||||
|
from configs.game.spell_config import magic_data
|
||||||
|
|
||||||
|
|
||||||
|
class CombatHandler:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
# Setup Combat
|
||||||
|
self.animation_player = AnimationPlayer()
|
||||||
|
self.magic_player = MagicPlayer(self.animation_player)
|
||||||
|
self.current_attack = None
|
||||||
|
|
||||||
|
# Spell and Weapon Rotation
|
||||||
|
self.weapon_index = 0
|
||||||
|
self.weapon = list(weapon_data.keys())[self.weapon_index]
|
||||||
|
|
||||||
|
self.magic_index = 0
|
||||||
|
self.magic = list(magic_data.keys())[self.magic_index]
|
||||||
|
|
||||||
|
# Damage Timer
|
||||||
|
self.vulnerable = True
|
||||||
|
self.hurt_time = None
|
||||||
|
self.invulnerability_duration = 300
|
||||||
|
|
||||||
|
# Import Sounds
|
||||||
|
# script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
# asset_path = os.path.join(
|
||||||
|
# script_dir, '../../..', 'assets', 'audio')
|
||||||
|
#
|
||||||
|
# self.weapon_attack_sound = pygame.mixer.Sound(
|
||||||
|
# f"{asset_path}/sword.wav")
|
||||||
|
# self.weapon_attack_sound.set_volume(0.2)
|
||||||
|
|
||||||
|
def create_attack_sprite(self, player):
|
||||||
|
self.current_attack = Weapon(
|
||||||
|
player, [player.visible_sprites, player.attack_sprites])
|
||||||
|
|
||||||
|
def delete_attack_sprite(self):
|
||||||
|
if self.current_attack:
|
||||||
|
self.current_attack.kill()
|
||||||
|
self.current_attack = None
|
||||||
|
|
||||||
|
def create_magic_sprite(self, player, style, strength, cost):
|
||||||
|
print(style)
|
||||||
|
if style == 'heal':
|
||||||
|
self.magic_player.heal(player, strength, cost, [
|
||||||
|
player.visible_sprites])
|
||||||
|
|
||||||
|
if style == 'flame':
|
||||||
|
self.magic_player.flame(
|
||||||
|
player, cost, [player.visible_sprites, player.attack_sprites])
|
41
game/entities/components/movement.py
Normal file
41
game/entities/components/movement.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
class MovementHandler:
|
||||||
|
|
||||||
|
def __init__(self, sprite_type):
|
||||||
|
|
||||||
|
self.direction = pygame.math.Vector2()
|
||||||
|
|
||||||
|
def move(self, speed, hitbox, obstacle_sprites, rect):
|
||||||
|
if self.direction.magnitude() != 0:
|
||||||
|
self.direction = self.direction.normalize()
|
||||||
|
|
||||||
|
hitbox.x += self.direction.x * speed
|
||||||
|
self.collision('horizontal', hitbox, obstacle_sprites)
|
||||||
|
hitbox.y += self.direction.y * speed
|
||||||
|
self.collision('vertical', hitbox, obstacle_sprites)
|
||||||
|
rect.center = hitbox.center
|
||||||
|
|
||||||
|
def collision(self, direction, hitbox, obstacle_sprites):
|
||||||
|
if direction == 'horizontal':
|
||||||
|
for sprite in obstacle_sprites:
|
||||||
|
# The following works for static obstacles only
|
||||||
|
if sprite.hitbox.colliderect(hitbox):
|
||||||
|
# Moving Right
|
||||||
|
if self.direction.x > 0:
|
||||||
|
hitbox.right = sprite.hitbox.left
|
||||||
|
# Moving Left
|
||||||
|
if self.direction.x < 0:
|
||||||
|
hitbox.left = sprite.hitbox.right
|
||||||
|
|
||||||
|
if direction == 'vertical':
|
||||||
|
for sprite in obstacle_sprites:
|
||||||
|
# The following works for static obstacles only
|
||||||
|
if sprite.hitbox.colliderect(hitbox):
|
||||||
|
# Moving Down
|
||||||
|
if self.direction.y > 0:
|
||||||
|
hitbox.bottom = sprite.hitbox.top
|
||||||
|
# Moving Up
|
||||||
|
if self.direction.y < 0:
|
||||||
|
hitbox.top = sprite.hitbox.bottom
|
45
game/entities/components/stats.py
Normal file
45
game/entities/components/stats.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
class StatsHandler:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.stats = {
|
||||||
|
'health': 100,
|
||||||
|
'energy': 60,
|
||||||
|
'attack': 10,
|
||||||
|
'magic': 4,
|
||||||
|
'speed': 5
|
||||||
|
}
|
||||||
|
|
||||||
|
self.max_stats = {
|
||||||
|
'health': 300,
|
||||||
|
'energy': 150,
|
||||||
|
'attack': 20,
|
||||||
|
'magic': 10,
|
||||||
|
'speed': 10
|
||||||
|
}
|
||||||
|
|
||||||
|
self.upgrade_costs = {
|
||||||
|
'health': 100,
|
||||||
|
'energy': 100,
|
||||||
|
'attack': 100,
|
||||||
|
'magic': 100,
|
||||||
|
'speed': 100
|
||||||
|
}
|
||||||
|
|
||||||
|
self.health = self.stats['health']
|
||||||
|
self.energy = self.stats['energy']
|
||||||
|
self.attack = self.stats['attack']
|
||||||
|
self.magic = self.stats['magic']
|
||||||
|
self.speed = self.stats['speed']
|
||||||
|
self.exp = 10000
|
||||||
|
|
||||||
|
def energy_recovery(self):
|
||||||
|
if self.energy < self.stats['energy']:
|
||||||
|
self.energy += 0.01 * self.stats['magic']
|
||||||
|
else:
|
||||||
|
self.energy = self.stats['energy']
|
||||||
|
|
||||||
|
def get_value_by_index(self, index):
|
||||||
|
return list(self.stats.values())[index]
|
||||||
|
|
||||||
|
def get_cost_by_index(self, index):
|
||||||
|
return list(self.upgrade_costs.values())[index]
|
9
game/entities/entity.py
Normal file
9
game/entities/entity.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import pygame
|
||||||
|
from math import sin
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class Entity():
|
||||||
|
|
||||||
|
def __init__(self, groups, position, sprite_type):
|
||||||
|
super().__init__(groups)
|
65
game/entities/observer.py
Normal file
65
game/entities/observer.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from configs.system.window_config import HITBOX_OFFSET
|
||||||
|
|
||||||
|
|
||||||
|
class Observer(pygame.sprite.Sprite):
|
||||||
|
|
||||||
|
def __init__(self, position, groups):
|
||||||
|
super().__init__(groups)
|
||||||
|
|
||||||
|
self.sprite_type = 'camera'
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
|
||||||
|
self.image = pygame.image.load(
|
||||||
|
f"{asset_path}/graphics/observer.png").convert_alpha()
|
||||||
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
|
self.hitbox = self.rect.inflate(HITBOX_OFFSET[self.sprite_type])
|
||||||
|
|
||||||
|
# Stats
|
||||||
|
self.exp = -1 # This prints OBSERVER in the UI
|
||||||
|
self.speed = 10 # Speed for moving around
|
||||||
|
|
||||||
|
# Movement
|
||||||
|
self.direction = pygame.math.Vector2()
|
||||||
|
|
||||||
|
def input(self):
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
# Movement Input
|
||||||
|
if keys[pygame.K_w]:
|
||||||
|
self.direction.y = -1
|
||||||
|
self.status = 'up'
|
||||||
|
self.can_move = False
|
||||||
|
elif keys[pygame.K_s]:
|
||||||
|
self.direction.y = 1
|
||||||
|
self.status = 'down'
|
||||||
|
self.can_move = False
|
||||||
|
else:
|
||||||
|
self.direction.y = 0
|
||||||
|
|
||||||
|
if keys[pygame.K_a]:
|
||||||
|
self.direction.x = -1
|
||||||
|
self.status = 'left'
|
||||||
|
self.can_move = False
|
||||||
|
elif keys[pygame.K_d]:
|
||||||
|
self.direction.x = 1
|
||||||
|
self.status = 'right'
|
||||||
|
self.can_move = False
|
||||||
|
else:
|
||||||
|
self.direction.x = 0
|
||||||
|
|
||||||
|
def move(self, speed):
|
||||||
|
if self.direction.magnitude() != 0:
|
||||||
|
self.direction = self.direction.normalize()
|
||||||
|
self.hitbox.x += self.direction.x * speed
|
||||||
|
self.hitbox.y += self.direction.y * speed
|
||||||
|
self.rect.center = self.hitbox.center
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.input()
|
||||||
|
self.move(self.speed)
|
67
game/entities/player.py
Normal file
67
game/entities/player.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from .components.combat import CombatHandler
|
||||||
|
from .components.stats import StatsHandler
|
||||||
|
from .components._input import InputHandler
|
||||||
|
from .components.animaton import AnimationHandler
|
||||||
|
|
||||||
|
|
||||||
|
class Player(pygame.sprite.Sprite):
|
||||||
|
|
||||||
|
def __init__(self, position, groups, obstacle_sprites, visible_sprites, attack_sprites):
|
||||||
|
super().__init__(groups)
|
||||||
|
|
||||||
|
# Setup Sprites
|
||||||
|
self.sprite_type = 'player'
|
||||||
|
self.visible_sprites = visible_sprites
|
||||||
|
self.attack_sprites = attack_sprites
|
||||||
|
self.obstacle_sprites = obstacle_sprites
|
||||||
|
self.status = 'down'
|
||||||
|
|
||||||
|
# Setup Inputs
|
||||||
|
self._input = InputHandler(
|
||||||
|
self.sprite_type, self.status)
|
||||||
|
|
||||||
|
# Setup Graphics
|
||||||
|
self.animation = AnimationHandler()
|
||||||
|
self.animation.import_assets(self.sprite_type, position)
|
||||||
|
self.animate = self.animation.animate
|
||||||
|
self.image = self.animation.image
|
||||||
|
self.animate(self.status, self._input.combat.vulnerable)
|
||||||
|
self.rect = self.animation.rect
|
||||||
|
|
||||||
|
# Setup Stats
|
||||||
|
self.stats = StatsHandler()
|
||||||
|
|
||||||
|
def get_status(self):
|
||||||
|
if self._input.movement.direction.x == 0 and self._input.movement.direction.y == 0:
|
||||||
|
if not 'idle' in self.status and not 'attack' in self.status:
|
||||||
|
self.status += '_idle'
|
||||||
|
|
||||||
|
if self._input.attacking:
|
||||||
|
self._input.movement.direction.x = 0
|
||||||
|
self._input.movement.direction.y = 0
|
||||||
|
if not 'attack' in self.status:
|
||||||
|
if 'idle' in self.status:
|
||||||
|
self.status = self.status.replace('idle', 'attack')
|
||||||
|
else:
|
||||||
|
self.status += '_attack'
|
||||||
|
else:
|
||||||
|
if 'attack' in self.status:
|
||||||
|
self.status = self.status.replace('_attack', '')
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
# Refresh objects based on input
|
||||||
|
self._input.check_input(
|
||||||
|
self.stats.stats['speed'], self.animation.hitbox, self.obstacle_sprites, self.animation.rect, self)
|
||||||
|
self.status = self._input.status
|
||||||
|
|
||||||
|
# Animate
|
||||||
|
self.get_status()
|
||||||
|
self.animation.animate(self.status, self._input.combat.vulnerable)
|
||||||
|
self.image = self.animation.image
|
||||||
|
self.rect = self.animation.rect
|
||||||
|
|
||||||
|
# Cooldowns and Regen
|
||||||
|
self.stats.energy_recovery()
|
||||||
|
self._input.cooldowns(self._input.combat.vulnerable)
|
0
game/interface/__init__.py
Normal file
0
game/interface/__init__.py
Normal file
|
@ -1,16 +1,27 @@
|
||||||
import pygame
|
import pygame
|
||||||
from utils.settings import *
|
|
||||||
|
from configs.game.weapon_config import *
|
||||||
|
from configs.game.spell_config import *
|
||||||
|
|
||||||
|
from .ui_settings import *
|
||||||
|
|
||||||
|
|
||||||
class UI:
|
class UI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
|
||||||
# General info
|
# General info
|
||||||
self.display_surface = pygame.display.get_surface()
|
self.display_surface = pygame.display.get_surface()
|
||||||
self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE)
|
self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE)
|
||||||
|
|
||||||
# Bar setup
|
# Bar setup
|
||||||
self.health_bar_rect = pygame.Rect(10, 10, HEALTH_BAR_WIDTH, BAR_HEIGHT)
|
self.health_bar_rect = pygame.Rect(
|
||||||
self.energy_bar_rect = pygame.Rect(10, 34, ENERGY_BAR_WIDTH, BAR_HEIGHT)
|
10, 10, HEALTH_BAR_WIDTH, BAR_HEIGHT)
|
||||||
|
self.energy_bar_rect = pygame.Rect(
|
||||||
|
10, 34, ENERGY_BAR_WIDTH, BAR_HEIGHT)
|
||||||
|
|
||||||
# Convert weapon dictionary
|
# Convert weapon dictionary
|
||||||
self.weapon_graphics = []
|
self.weapon_graphics = []
|
||||||
|
@ -26,7 +37,6 @@ class UI:
|
||||||
spell = pygame.image.load(path).convert_alpha()
|
spell = pygame.image.load(path).convert_alpha()
|
||||||
self.magic_graphics.append(spell)
|
self.magic_graphics.append(spell)
|
||||||
|
|
||||||
|
|
||||||
def show_bar(self, current_amount, max_amount, bg_rect, color):
|
def show_bar(self, current_amount, max_amount, bg_rect, color):
|
||||||
|
|
||||||
# Draw background
|
# Draw background
|
||||||
|
@ -44,30 +54,35 @@ class UI:
|
||||||
|
|
||||||
def show_exp(self, exp):
|
def show_exp(self, exp):
|
||||||
if exp >= 0:
|
if exp >= 0:
|
||||||
text_surf = self.font.render(f"EXP: {str(int(exp))}", False, TEXT_COLOR)
|
text_surf = self.font.render(
|
||||||
|
f"EXP: {str(int(exp))}", False, TEXT_COLOR)
|
||||||
x = self.display_surface.get_size()[0] - 20
|
x = self.display_surface.get_size()[0] - 20
|
||||||
y = self.display_surface.get_size()[1] - 20
|
y = self.display_surface.get_size()[1] - 20
|
||||||
text_rect = text_surf.get_rect(bottomright = (x,y))
|
text_rect = text_surf.get_rect(bottomright=(x, y))
|
||||||
|
|
||||||
pygame.draw.rect(self.display_surface, UI_BG_COLOR, text_rect.inflate(10, 10))
|
pygame.draw.rect(self.display_surface, UI_BG_COLOR,
|
||||||
|
text_rect.inflate(10, 10))
|
||||||
self.display_surface.blit(text_surf, text_rect)
|
self.display_surface.blit(text_surf, text_rect)
|
||||||
pygame.draw.rect(self.display_surface, UI_BORDER_COLOR, text_rect.inflate(10, 10), 4)
|
pygame.draw.rect(self.display_surface,
|
||||||
|
UI_BORDER_COLOR, text_rect.inflate(10, 10), 4)
|
||||||
else:
|
else:
|
||||||
text_surf = self.font.render(f"OBSERVER", False, TEXT_COLOR)
|
text_surf = self.font.render(f"OBSERVER", False, TEXT_COLOR)
|
||||||
x = self.display_surface.get_size()[0] - 20
|
x = self.display_surface.get_size()[0] - 20
|
||||||
y = self.display_surface.get_size()[1] - 20
|
y = self.display_surface.get_size()[1] - 20
|
||||||
text_rect = text_surf.get_rect(bottomright = (x,y))
|
text_rect = text_surf.get_rect(bottomright=(x, y))
|
||||||
|
|
||||||
pygame.draw.rect(self.display_surface, UI_BG_COLOR, text_rect.inflate(10, 10))
|
pygame.draw.rect(self.display_surface, UI_BG_COLOR,
|
||||||
|
text_rect.inflate(10, 10))
|
||||||
self.display_surface.blit(text_surf, text_rect)
|
self.display_surface.blit(text_surf, text_rect)
|
||||||
pygame.draw.rect(self.display_surface, UI_BORDER_COLOR, text_rect.inflate(10, 10), 4)
|
pygame.draw.rect(self.display_surface,
|
||||||
|
UI_BORDER_COLOR, text_rect.inflate(10, 10), 4)
|
||||||
|
|
||||||
def selection_box(self, left, top, has_rotated):
|
def selection_box(self, left, top, has_rotated):
|
||||||
bg_rect = pygame.Rect(left, top, ITEM_BOX_SIZE, ITEM_BOX_SIZE)
|
bg_rect = pygame.Rect(left, top, ITEM_BOX_SIZE, ITEM_BOX_SIZE)
|
||||||
pygame.draw.rect(self.display_surface, UI_BG_COLOR, bg_rect)
|
pygame.draw.rect(self.display_surface, UI_BG_COLOR, bg_rect)
|
||||||
if not has_rotated:
|
if not has_rotated:
|
||||||
pygame.draw.rect(self.display_surface, UI_BORDER_COLOR_ACTIVE, bg_rect, 4)
|
pygame.draw.rect(self.display_surface,
|
||||||
|
UI_BORDER_COLOR_ACTIVE, bg_rect, 4)
|
||||||
else:
|
else:
|
||||||
pygame.draw.rect(self.display_surface, UI_BORDER_COLOR, bg_rect, 4)
|
pygame.draw.rect(self.display_surface, UI_BORDER_COLOR, bg_rect, 4)
|
||||||
return bg_rect
|
return bg_rect
|
||||||
|
@ -75,24 +90,27 @@ class UI:
|
||||||
def weapon_overlay(self, weapon_index, has_rotated):
|
def weapon_overlay(self, weapon_index, has_rotated):
|
||||||
bg_rect = self.selection_box(10, 630, has_rotated)
|
bg_rect = self.selection_box(10, 630, has_rotated)
|
||||||
weapon_surf = self.weapon_graphics[weapon_index]
|
weapon_surf = self.weapon_graphics[weapon_index]
|
||||||
weapon_rect = weapon_surf.get_rect(center = bg_rect.center)
|
weapon_rect = weapon_surf.get_rect(center=bg_rect.center)
|
||||||
|
|
||||||
self.display_surface.blit(weapon_surf, weapon_rect)
|
self.display_surface.blit(weapon_surf, weapon_rect)
|
||||||
|
|
||||||
def magic_overlay(self, magic_index, has_swaped):
|
def magic_overlay(self, magic_index, has_swaped):
|
||||||
bg_rect = self.selection_box(100, 630, has_swaped)
|
bg_rect = self.selection_box(100, 630, has_swaped)
|
||||||
magic_surf = self.magic_graphics[magic_index]
|
magic_surf = self.magic_graphics[magic_index]
|
||||||
magic_rect = magic_surf.get_rect(center = bg_rect.center)
|
magic_rect = magic_surf.get_rect(center=bg_rect.center)
|
||||||
|
|
||||||
self.display_surface.blit(magic_surf, magic_rect)
|
self.display_surface.blit(magic_surf, magic_rect)
|
||||||
|
|
||||||
def display(self, player):
|
def display(self, player):
|
||||||
if player.sprite_type == 'player':
|
if player.sprite_type == 'player':
|
||||||
self.show_bar(player.health, player.stats['health'], self.health_bar_rect, HEALTH_COLOR)
|
self.show_bar(
|
||||||
self.show_bar(player.energy, player.stats['energy'], self.energy_bar_rect, ENERGY_COLOR)
|
player.stats.health, player.stats.stats['health'], self.health_bar_rect, HEALTH_COLOR)
|
||||||
self.show_exp(player.exp)
|
self.show_bar(
|
||||||
self.weapon_overlay(player.weapon_index, player.can_rotate_weapon)
|
player.stats.energy, player.stats.stats['energy'], self.energy_bar_rect, ENERGY_COLOR)
|
||||||
self.magic_overlay(player.magic_index, player.can_swap_magic)
|
self.show_exp(player.stats.exp)
|
||||||
|
self.weapon_overlay(player._input.combat.weapon_index,
|
||||||
|
player._input.can_rotate_weapon)
|
||||||
|
self.magic_overlay(player._input.combat.magic_index,
|
||||||
|
player._input.can_swap_magic)
|
||||||
if player.sprite_type == 'camera':
|
if player.sprite_type == 'camera':
|
||||||
self.show_exp(player.exp)
|
self.show_exp(player.exp)
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
|
||||||
# ui
|
# ui
|
||||||
BAR_HEIGHT = 20
|
BAR_HEIGHT = 20
|
||||||
HEALTH_BAR_WIDTH = 200
|
HEALTH_BAR_WIDTH = 200
|
||||||
ENERGY_BAR_WIDTH = 140
|
ENERGY_BAR_WIDTH = 140
|
||||||
ITEM_BOX_SIZE = 80
|
ITEM_BOX_SIZE = 80
|
||||||
UI_FONT = '../Graphics/graphics/font/joystix.ttf'
|
UI_FONT = f"{asset_path}/font/joystix.ttf"
|
||||||
UI_FONT_SIZE = 18
|
UI_FONT_SIZE = 18
|
||||||
|
|
||||||
# general colors
|
# general colors
|
|
@ -1,5 +1,7 @@
|
||||||
import pygame
|
import pygame
|
||||||
from utils.settings import *
|
|
||||||
|
from .ui_settings import *
|
||||||
|
|
||||||
|
|
||||||
class Upgrade:
|
class Upgrade:
|
||||||
|
|
||||||
|
@ -8,14 +10,15 @@ class Upgrade:
|
||||||
# General setup
|
# General setup
|
||||||
self.display_surface = pygame.display.get_surface()
|
self.display_surface = pygame.display.get_surface()
|
||||||
self.player = player
|
self.player = player
|
||||||
self.attribute_num = len(player.stats)
|
self.attribute_num = len(player.stats.stats)
|
||||||
self.attribute_names = list(player.stats.keys())
|
self.attribute_names = list(player.stats.stats.keys())
|
||||||
self.max_values = list(player.max_stats.values())
|
self.max_values = list(player.stats.max_stats.values())
|
||||||
self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE)
|
self.font = pygame.font.Font(UI_FONT, UI_FONT_SIZE)
|
||||||
|
|
||||||
# Defining upgrade boxes
|
# Defining upgrade boxes
|
||||||
self.height = self.display_surface.get_size()[1] * 0.8
|
self.height = self.display_surface.get_size()[1] * 0.8
|
||||||
self.width = self.display_surface.get_size()[0] // (self.attribute_num + 1)
|
self.width = self.display_surface.get_size()[
|
||||||
|
0] // (self.attribute_num + 1)
|
||||||
self.create_boxes()
|
self.create_boxes()
|
||||||
|
|
||||||
# Selection System
|
# Selection System
|
||||||
|
@ -67,7 +70,6 @@ class Upgrade:
|
||||||
box = Box(left, top, self.width, self.height, index, self.font)
|
box = Box(left, top, self.width, self.height, index, self.font)
|
||||||
self.box_list.append(box)
|
self.box_list.append(box)
|
||||||
|
|
||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
|
|
||||||
self.input()
|
self.input()
|
||||||
|
@ -76,15 +78,16 @@ class Upgrade:
|
||||||
for index, box in enumerate(self.box_list):
|
for index, box in enumerate(self.box_list):
|
||||||
# Get attributes
|
# Get attributes
|
||||||
name = self.attribute_names[index]
|
name = self.attribute_names[index]
|
||||||
value = self.player.get_value_by_index(index)
|
value = self.player.stats.get_value_by_index(index)
|
||||||
max_value = self.max_values[index]
|
max_value = self.max_values[index]
|
||||||
cost = self.player.get_cost_by_index(index)
|
cost = self.player.stats.get_cost_by_index(index)
|
||||||
box.display(self.display_surface, self.selection_index, name, value, max_value, cost)
|
box.display(self.display_surface, self.selection_index,
|
||||||
|
name, value, max_value, cost)
|
||||||
|
|
||||||
|
|
||||||
class Box:
|
class Box:
|
||||||
def __init__(self, l, t, w, h, index, font):
|
def __init__(self, left, top, width, height, index, font):
|
||||||
self.rect = pygame.Rect(l, t, w, h)
|
self.rect = pygame.Rect(left, top, width, height)
|
||||||
self.index = index
|
self.index = index
|
||||||
self.font = font
|
self.font = font
|
||||||
|
|
||||||
|
@ -93,10 +96,12 @@ class Box:
|
||||||
|
|
||||||
# Title
|
# Title
|
||||||
title_surf = self.font.render(name, False, color)
|
title_surf = self.font.render(name, False, color)
|
||||||
title_rect = title_surf.get_rect(midtop = self.rect.midtop + pygame.math.Vector2(0, 20))
|
title_rect = title_surf.get_rect(
|
||||||
|
midtop=self.rect.midtop + pygame.math.Vector2(0, 20))
|
||||||
# Cost
|
# Cost
|
||||||
cost_surf = self.font.render(f'Cost: {int(cost)}', False, color)
|
cost_surf = self.font.render(f'Cost: {int(cost)}', False, color)
|
||||||
cost_rect = cost_surf.get_rect(midbottom = self.rect.midbottom +- pygame.math.Vector2(0, 20))
|
cost_rect = cost_surf.get_rect(
|
||||||
|
midbottom=self.rect.midbottom + - pygame.math.Vector2(0, 20))
|
||||||
|
|
||||||
# Draw
|
# Draw
|
||||||
surface.blit(title_surf, title_rect)
|
surface.blit(title_surf, title_rect)
|
||||||
|
@ -106,30 +111,29 @@ class Box:
|
||||||
|
|
||||||
# Line setup
|
# Line setup
|
||||||
top = self.rect.midtop + pygame.math.Vector2(0, 60)
|
top = self.rect.midtop + pygame.math.Vector2(0, 60)
|
||||||
bottom = self.rect.midbottom - pygame.math.Vector2(0,60)
|
bottom = self.rect.midbottom - pygame.math.Vector2(0, 60)
|
||||||
color = BAR_COLOR_SELECTED if selected else BAR_COLOR
|
color = BAR_COLOR_SELECTED if selected else BAR_COLOR
|
||||||
|
|
||||||
# Bar setup
|
# Bar setup
|
||||||
full_height = bottom[1] - top[1]
|
full_height = bottom[1] - top[1]
|
||||||
relative_number = (value / max_value) * full_height
|
relative_number = (value / max_value) * full_height
|
||||||
value_rect = pygame.Rect(top[0] - 15, bottom[1] - relative_number, 30, 10)
|
value_rect = pygame.Rect(
|
||||||
|
top[0] - 15, bottom[1] - relative_number, 30, 10)
|
||||||
|
|
||||||
# Draw elements
|
# Draw elements
|
||||||
pygame.draw.line(surface, color, top, bottom, 5)
|
pygame.draw.line(surface, color, top, bottom, 5)
|
||||||
pygame.draw.rect(surface, color, value_rect)
|
pygame.draw.rect(surface, color, value_rect)
|
||||||
|
|
||||||
def trigger(self, player):
|
def trigger(self, player):
|
||||||
upgrade_attribute = list(player.stats.keys())[self.index]
|
upgrade_attribute = list(player.stats.stats.keys())[self.index]
|
||||||
|
|
||||||
if player.exp >= player.upgrade_costs[upgrade_attribute] and player.stats[upgrade_attribute] < player.max_stats[upgrade_attribute]:
|
|
||||||
player.exp -= player.upgrade_costs[upgrade_attribute]
|
|
||||||
player.stats[upgrade_attribute] *= 1.2
|
|
||||||
player.upgrade_costs[upgrade_attribute] *= 1.4
|
|
||||||
|
|
||||||
if player.stats[upgrade_attribute] > player.max_stats[upgrade_attribute]:
|
|
||||||
player.stats[upgrade_attribute] = player.max_stats[upgrade_attribute]
|
|
||||||
|
|
||||||
|
if player.stats.exp >= player.stats.upgrade_costs[upgrade_attribute] and player.stats.stats[upgrade_attribute] < player.stats.max_stats[upgrade_attribute]:
|
||||||
|
player.stats.exp -= player.stats.upgrade_costs[upgrade_attribute]
|
||||||
|
player.stats.stats[upgrade_attribute] *= 1.2
|
||||||
|
player.stats.upgrade_costs[upgrade_attribute] *= 1.4
|
||||||
|
|
||||||
|
if player.stats.stats[upgrade_attribute] > player.stats.max_stats[upgrade_attribute]:
|
||||||
|
player.stats.stats[upgrade_attribute] = player.stats.max_stats[upgrade_attribute]
|
||||||
|
|
||||||
def display(self, surface, selection_num, name, value, max_value, cost):
|
def display(self, surface, selection_num, name, value, max_value, cost):
|
||||||
if self.index == selection_num:
|
if self.index == selection_num:
|
||||||
|
@ -140,4 +144,5 @@ class Box:
|
||||||
pygame.draw.rect(surface, UI_BORDER_COLOR, self.rect, 4)
|
pygame.draw.rect(surface, UI_BORDER_COLOR, self.rect, 4)
|
||||||
|
|
||||||
self.display_names(surface, name, cost, self.index == selection_num)
|
self.display_names(surface, name, cost, self.index == selection_num)
|
||||||
self.display_bar(surface, value, max_value, self.index == selection_num)
|
self.display_bar(surface, value, max_value,
|
||||||
|
self.index == selection_num)
|
0
game/level/__init__.py
Normal file
0
game/level/__init__.py
Normal file
42
game/level/camera.py
Normal file
42
game/level/camera.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
class Camera(pygame.sprite.Group):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
# General Setup
|
||||||
|
self.display_surface = pygame.display.get_surface()
|
||||||
|
self.half_width = self.display_surface.get_size()[0] // 2
|
||||||
|
self.half_height = self.display_surface.get_size()[1] // 2
|
||||||
|
self.offset = pygame.math.Vector2(100, 200)
|
||||||
|
|
||||||
|
# Creating the floor
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
image_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets', 'graphics', 'tilemap', 'ground.png')
|
||||||
|
|
||||||
|
self.floor_surf = pygame.image.load(image_path).convert()
|
||||||
|
self.floor_rect = self.floor_surf.get_rect(topleft=(0, 0))
|
||||||
|
|
||||||
|
def custom_draw(self, player):
|
||||||
|
self.sprite_type = player.sprite_type
|
||||||
|
# Getting the offset
|
||||||
|
self.offset.x = player.rect.centerx - self.half_width
|
||||||
|
self.offset.y = player.rect.centery - self.half_height
|
||||||
|
|
||||||
|
# Drawing the floor
|
||||||
|
floor_offset_pos = self.floor_rect.topleft - self.offset
|
||||||
|
self.display_surface.blit(self.floor_surf, floor_offset_pos)
|
||||||
|
|
||||||
|
for sprite in sorted(self.sprites(), key=lambda sprite: sprite.rect.centery):
|
||||||
|
offset_pos = sprite.rect.topleft - self.offset
|
||||||
|
self.display_surface.blit(sprite.image, offset_pos)
|
||||||
|
|
||||||
|
def enemy_update(self, player):
|
||||||
|
enemy_sprites = [sprite for sprite in self.sprites() if hasattr(
|
||||||
|
sprite, 'sprite_type') and sprite.sprite_type == 'enemy']
|
||||||
|
for enemy in enemy_sprites:
|
||||||
|
enemy.enemy_update(player)
|
120
game/level/level.py
Normal file
120
game/level/level.py
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from random import choice, randint
|
||||||
|
|
||||||
|
from configs.game.spell_config import magic_data
|
||||||
|
from configs.game.weapon_config import weapon_data
|
||||||
|
from configs.game.monster_config import monster_data
|
||||||
|
from configs.system.window_config import TILESIZE
|
||||||
|
|
||||||
|
from utils.debug import debug
|
||||||
|
from utils.resource_loader import import_csv_layout, import_folder
|
||||||
|
|
||||||
|
from interface.ui import UI
|
||||||
|
from interface.upgrade import Upgrade
|
||||||
|
|
||||||
|
from effects.magic_effects import MagicPlayer
|
||||||
|
from effects.particle_effects import AnimationPlayer
|
||||||
|
from effects.weapon_effects import Weapon
|
||||||
|
|
||||||
|
from entities.observer import Observer
|
||||||
|
from entities.player import Player
|
||||||
|
|
||||||
|
from .terrain import Tile
|
||||||
|
from .camera import Camera
|
||||||
|
|
||||||
|
|
||||||
|
class Level:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
# General Settings
|
||||||
|
self.game_paused = False
|
||||||
|
|
||||||
|
# Get display surface
|
||||||
|
self.display_surface = pygame.display.get_surface()
|
||||||
|
|
||||||
|
# Sprite Group setup
|
||||||
|
self.visible_sprites = Camera()
|
||||||
|
self.obstacle_sprites = pygame.sprite.Group()
|
||||||
|
self.attack_sprites = pygame.sprite.Group()
|
||||||
|
self.attackable_sprites = pygame.sprite.Group()
|
||||||
|
|
||||||
|
# Sprite setup and entity generation
|
||||||
|
self.create_map()
|
||||||
|
|
||||||
|
# UI setup
|
||||||
|
self.ui = UI()
|
||||||
|
self.upgrade = Upgrade(self.player)
|
||||||
|
|
||||||
|
def create_map(self):
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
asset_path = os.path.join(
|
||||||
|
script_dir, '../..', 'assets')
|
||||||
|
layouts = {
|
||||||
|
'boundary': import_csv_layout(f"{asset_path}/map/FloorBlocks.csv"),
|
||||||
|
'grass': import_csv_layout(f"{asset_path}/map/Grass.csv"),
|
||||||
|
'objects': import_csv_layout(f"{asset_path}/map/Objects.csv"),
|
||||||
|
'entities': import_csv_layout(f"{asset_path}/map/Entities.csv")
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics = {
|
||||||
|
'grass': import_folder(f"{asset_path}/graphics/grass"),
|
||||||
|
'objects': import_folder(f"{asset_path}/graphics/objects")
|
||||||
|
}
|
||||||
|
|
||||||
|
for style, layout in layouts.items():
|
||||||
|
for row_index, row in enumerate(layout):
|
||||||
|
for col_index, col in enumerate(row):
|
||||||
|
if col != '-1':
|
||||||
|
x = col_index * TILESIZE
|
||||||
|
y = row_index * TILESIZE
|
||||||
|
if style == 'boundary':
|
||||||
|
Tile((x, y), [self.obstacle_sprites], 'invisible')
|
||||||
|
|
||||||
|
if style == 'grass':
|
||||||
|
random_grass_image = choice(graphics['grass'])
|
||||||
|
Tile((x, y), [self.visible_sprites, self.obstacle_sprites,
|
||||||
|
self.attackable_sprites], 'grass', random_grass_image)
|
||||||
|
|
||||||
|
if style == 'objects':
|
||||||
|
surf = graphics['objects'][int(col)]
|
||||||
|
Tile((x, y), [self.visible_sprites,
|
||||||
|
self.obstacle_sprites], 'object', surf)
|
||||||
|
|
||||||
|
if style == 'entities':
|
||||||
|
# The numbers represent their IDs in .csv files generated from TILED.
|
||||||
|
if col == '395':
|
||||||
|
self.observer = Observer(
|
||||||
|
(x, y), [self.visible_sprites])
|
||||||
|
|
||||||
|
elif col == '394':
|
||||||
|
# Player Generation
|
||||||
|
self.player = Player(
|
||||||
|
(x, y), [self.visible_sprites], self.obstacle_sprites, self.visible_sprites, self.attack_sprites)
|
||||||
|
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
# monster generation
|
||||||
|
|
||||||
|
def toggle_menu(self):
|
||||||
|
self.game_paused = not self.game_paused
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# Draw the game
|
||||||
|
self.visible_sprites.custom_draw(self.player)
|
||||||
|
self.ui.display(self.player)
|
||||||
|
debug(self.player.status)
|
||||||
|
if not self.game_paused:
|
||||||
|
# Update the game
|
||||||
|
# self.player.distance_direction_to_player = self.get_state()
|
||||||
|
self.visible_sprites.update()
|
||||||
|
# self.visible_sprites.enemy_update(self.player)
|
||||||
|
# self.player_attack_logic()
|
||||||
|
else:
|
||||||
|
if self.visible_sprites.sprite_type == 'player':
|
||||||
|
self.upgrade.display()
|
||||||
|
|
||||||
|
if self.player.stats.health <= 0:
|
||||||
|
self.__init__()
|
19
game/level/terrain.py
Normal file
19
game/level/terrain.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from configs.system.window_config import *
|
||||||
|
|
||||||
|
|
||||||
|
class Tile(pygame.sprite.Sprite):
|
||||||
|
|
||||||
|
def __init__(self, position, groups, sprite_type, surface=pygame.Surface((TILESIZE, TILESIZE))):
|
||||||
|
super().__init__(groups)
|
||||||
|
|
||||||
|
self.sprite_type = sprite_type
|
||||||
|
self.image = surface
|
||||||
|
if sprite_type == 'object':
|
||||||
|
# Offset
|
||||||
|
self.rect = self.image.get_rect(
|
||||||
|
topleft=(position[0], position[1] - TILESIZE))
|
||||||
|
else:
|
||||||
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
|
self.hitbox = self.rect.inflate(HITBOX_OFFSET[sprite_type])
|
47
game/main.py
Normal file
47
game/main.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import pygame
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from configs.system.window_config import WIDTH, HEIGHT, WATER_COLOR, FPS
|
||||||
|
from utils.debug import debug
|
||||||
|
|
||||||
|
from level.level import Level
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption('Pneuma')
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
self.level = Level()
|
||||||
|
|
||||||
|
# # Sound
|
||||||
|
# main_sound = pygame.mixer.Sound('../assets/audio/main.ogg')
|
||||||
|
# main_sound.set_volume(0.4)
|
||||||
|
# main_sound.play(loops=-1)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_m:
|
||||||
|
self.level.toggle_menu()
|
||||||
|
|
||||||
|
self.screen.fill(WATER_COLOR)
|
||||||
|
self.level.run()
|
||||||
|
pygame.display.update()
|
||||||
|
self.clock.tick(FPS)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
game = Game()
|
||||||
|
while True:
|
||||||
|
game.run()
|
0
game/utils/__init__.py
Normal file
0
game/utils/__init__.py
Normal file
|
@ -16,6 +16,7 @@ from terrain.tiles import Tile
|
||||||
from view.observer import Observer
|
from view.observer import Observer
|
||||||
from view.camera import Camera
|
from view.camera import Camera
|
||||||
|
|
||||||
|
|
||||||
class Level:
|
class Level:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -58,31 +59,35 @@ class Level:
|
||||||
x = col_index * TILESIZE
|
x = col_index * TILESIZE
|
||||||
y = row_index * TILESIZE
|
y = row_index * TILESIZE
|
||||||
if style == 'boundary':
|
if style == 'boundary':
|
||||||
Tile((x,y), [self.obstacle_sprites], 'invisible')
|
Tile((x, y), [self.obstacle_sprites], 'invisible')
|
||||||
|
|
||||||
if style == 'grass':
|
if style == 'grass':
|
||||||
random_grass_image = choice(graphics['grass'])
|
random_grass_image = choice(graphics['grass'])
|
||||||
Tile((x,y), [self.visible_sprites, self.obstacle_sprites, self.attackable_sprites], 'grass', random_grass_image)
|
Tile((x, y), [self.visible_sprites, self.obstacle_sprites,
|
||||||
|
self.attackable_sprites], 'grass', random_grass_image)
|
||||||
|
|
||||||
if style == 'objects':
|
if style == 'objects':
|
||||||
surf = graphics['objects'][int(col)]
|
surf = graphics['objects'][int(col)]
|
||||||
Tile((x,y), [self.visible_sprites, self.obstacle_sprites], 'object', surf)
|
Tile((x, y), [self.visible_sprites,
|
||||||
|
self.obstacle_sprites], 'object', surf)
|
||||||
|
|
||||||
if style == 'entities':
|
if style == 'entities':
|
||||||
# The numbers represent their IDs in the map .csv files generated from TILED.
|
# The numbers represent their IDs in the map .csv files generated from TILED.
|
||||||
if col == '395':
|
if col == '395':
|
||||||
self.observer = Observer((x,y), [self.visible_sprites])
|
self.observer = Observer(
|
||||||
|
(x, y), [self.visible_sprites])
|
||||||
|
|
||||||
elif col == '394':
|
elif col == '394':
|
||||||
pass
|
pass
|
||||||
#player generation
|
# player generation
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
#monster generation
|
# monster generation
|
||||||
|
|
||||||
def create_attack_sprite(self):
|
def create_attack_sprite(self):
|
||||||
self.current_attack = Weapon(self.player, [self.visible_sprites, self.attack_sprites])
|
self.current_attack = Weapon(
|
||||||
|
self.player, [self.visible_sprites, self.attack_sprites])
|
||||||
|
|
||||||
def delete_attack_sprite(self):
|
def delete_attack_sprite(self):
|
||||||
if self.current_attack:
|
if self.current_attack:
|
||||||
|
@ -91,13 +96,27 @@ class Level:
|
||||||
|
|
||||||
def create_magic_sprite(self, style, strength, cost):
|
def create_magic_sprite(self, style, strength, cost):
|
||||||
if style == 'heal':
|
if style == 'heal':
|
||||||
self.magic_player.heal(self.player, strength, cost, [self.visible_sprites])
|
self.magic_player.heal(self.player, strength, cost, [
|
||||||
|
self.visible_sprites])
|
||||||
|
|
||||||
if style == 'flame':
|
if style == 'flame':
|
||||||
self.magic_player.flame(self.player, cost, [self.visible_sprites, self.attack_sprites])
|
self.magic_player.flame(
|
||||||
|
self.player, cost, [self.visible_sprites, self.attack_sprites])
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Draw the game
|
# Draw the game
|
||||||
self.visible_sprites.custom_draw(self.observer)
|
self.visible_sprites.custom_draw(self.observer)
|
||||||
self.ui.display(self.observer)
|
self.ui.display(self.observer)
|
||||||
|
if self.game_paused:
|
||||||
|
if self.visible_sprites.sprite_type == 'player':
|
||||||
|
self.upgrade.display()
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# Update the game
|
||||||
|
self.player.distance_direction_to_player = self.get_state()
|
||||||
|
self.visible_sprites.update()
|
||||||
|
self.visible_sprites.enemy_update(self.player)
|
||||||
|
self.player_attack_logic()
|
||||||
|
|
||||||
|
if self.player.health <= 0:
|
||||||
|
self.__init__()
|
||||||
|
|
|
@ -6,13 +6,14 @@ from utils.debug import debug
|
||||||
|
|
||||||
from level import Level
|
from level import Level
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
self.screen = pygame.display.set_mode((WIDTH,HEIGHT))
|
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
pygame.display.set_caption('Pneuma')
|
pygame.display.set_caption('Pneuma')
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
@ -37,13 +38,9 @@ class Game:
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(FPS)
|
self.clock.tick(FPS)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
game = Game()
|
game = Game()
|
||||||
while True:
|
while True:
|
||||||
game.run()
|
game.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@ from utils.debug import debug
|
||||||
|
|
||||||
from objects.level import Level
|
from objects.level import Level
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
self.screen = pygame.display.set_mode((WIDTH,HEIGHT))
|
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
pygame.display.set_caption('Pneuma')
|
pygame.display.set_caption('Pneuma')
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
@ -21,7 +22,8 @@ class Game:
|
||||||
# Sound
|
# Sound
|
||||||
main_sound = pygame.mixer.Sound('../Graphics/audio/main.ogg')
|
main_sound = pygame.mixer.Sound('../Graphics/audio/main.ogg')
|
||||||
main_sound.set_volume(0.4)
|
main_sound.set_volume(0.4)
|
||||||
main_sound.play(loops = -1)
|
main_sound.play(loops=-1)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
@ -37,13 +39,10 @@ class Game:
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(FPS)
|
self.clock.tick(FPS)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
game = Game()
|
game = Game()
|
||||||
figure_file = 'rl/plots/pneuma.png'
|
figure_file = 'rl/plots/pneuma.png'
|
||||||
while True:
|
while True:
|
||||||
game.run()
|
game.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import random
|
||||||
from utils.settings import *
|
from utils.settings import *
|
||||||
from utils.support import import_folder
|
from utils.support import import_folder
|
||||||
|
|
||||||
|
|
||||||
class Camera(pygame.sprite.Sprite):
|
class Camera(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def __init__(self, position, groups):
|
def __init__(self, position, groups):
|
||||||
|
@ -11,15 +12,16 @@ class Camera(pygame.sprite.Sprite):
|
||||||
|
|
||||||
self.sprite_type = 'camera'
|
self.sprite_type = 'camera'
|
||||||
|
|
||||||
self.image = pygame.image.load('../Graphics/graphics/camera.png').convert_alpha()
|
self.image = pygame.image.load(
|
||||||
self.rect = self.image.get_rect(topleft = position)
|
'../Graphics/graphics/camera.png').convert_alpha()
|
||||||
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
self.hitbox = self.rect.inflate(HITBOX_OFFSET[self.sprite_type])
|
self.hitbox = self.rect.inflate(HITBOX_OFFSET[self.sprite_type])
|
||||||
|
|
||||||
# Stats
|
# Stats
|
||||||
self.exp = -1 # This prints OBSERVER in the UI
|
self.exp = -1 # This prints OBSERVER in the UI
|
||||||
self.speed = 10 # Speed for moving around
|
self.speed = 10 # Speed for moving around
|
||||||
|
|
||||||
#Movement
|
# Movement
|
||||||
self.direction = pygame.math.Vector2()
|
self.direction = pygame.math.Vector2()
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
|
@ -55,7 +57,6 @@ class Camera(pygame.sprite.Sprite):
|
||||||
self.hitbox.y += self.direction.y * speed
|
self.hitbox.y += self.direction.y * speed
|
||||||
self.rect.center = self.hitbox.center
|
self.rect.center = self.hitbox.center
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.input()
|
self.input()
|
||||||
self.move(self.speed)
|
self.move(self.speed)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from utils.support import import_folder
|
||||||
|
|
||||||
from objects.entity import Entity
|
from objects.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
class Enemy(Entity):
|
class Enemy(Entity):
|
||||||
|
|
||||||
def __init__(self, monster_name, position, groups, obstacle_sprites, damage_player, trigger_death_particles, add_exp, is_AI, state):
|
def __init__(self, monster_name, position, groups, obstacle_sprites, damage_player, trigger_death_particles, add_exp, is_AI, state):
|
||||||
|
@ -19,7 +20,7 @@ class Enemy(Entity):
|
||||||
self.image = self.animations[self.status][self.frame_index]
|
self.image = self.animations[self.status][self.frame_index]
|
||||||
|
|
||||||
# Movement
|
# Movement
|
||||||
self.rect = self.image.get_rect(topleft = position)
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
self.hitbox = self.rect.inflate(0, -10)
|
self.hitbox = self.rect.inflate(0, -10)
|
||||||
|
|
||||||
# Stats
|
# Stats
|
||||||
|
@ -58,12 +59,13 @@ class Enemy(Entity):
|
||||||
self.obstacle_sprites = obstacle_sprites
|
self.obstacle_sprites = obstacle_sprites
|
||||||
|
|
||||||
def import_graphics(self, name):
|
def import_graphics(self, name):
|
||||||
self.animations = {'idle':[], 'move':[], 'attack':[]}
|
self.animations = {'idle': [], 'move': [], 'attack': []}
|
||||||
main_path = f"../Graphics/graphics/monsters/{name}"
|
main_path = f"../Graphics/graphics/monsters/{name}"
|
||||||
for animation in self.animations.keys():
|
for animation in self.animations.keys():
|
||||||
self.animations[animation] = import_folder(f"{main_path}/{animation}")
|
self.animations[animation] = import_folder(
|
||||||
|
f"{main_path}/{animation}")
|
||||||
|
|
||||||
def get_player_distance_direction(self,player):
|
def get_player_distance_direction(self, player):
|
||||||
enemy_vector = pygame.math.Vector2(self.rect.center)
|
enemy_vector = pygame.math.Vector2(self.rect.center)
|
||||||
player_vector = pygame.math.Vector2(player.rect.center)
|
player_vector = pygame.math.Vector2(player.rect.center)
|
||||||
|
|
||||||
|
@ -102,12 +104,12 @@ class Enemy(Entity):
|
||||||
|
|
||||||
self.frame_index += self.animation_speed
|
self.frame_index += self.animation_speed
|
||||||
if self.frame_index >= len(animation):
|
if self.frame_index >= len(animation):
|
||||||
if self.status =='attack':
|
if self.status == 'attack':
|
||||||
self.can_attack = False
|
self.can_attack = False
|
||||||
self.frame_index = 0
|
self.frame_index = 0
|
||||||
|
|
||||||
self.image = animation[int(self.frame_index)]
|
self.image = animation[int(self.frame_index)]
|
||||||
self.rect = self.image.get_rect(center = self.hitbox.center)
|
self.rect = self.image.get_rect(center=self.hitbox.center)
|
||||||
|
|
||||||
if not self.vulnerable:
|
if not self.vulnerable:
|
||||||
alpha = self.wave_value()
|
alpha = self.wave_value()
|
||||||
|
|
|
@ -4,8 +4,9 @@ import random
|
||||||
|
|
||||||
from utils.settings import *
|
from utils.settings import *
|
||||||
|
|
||||||
|
|
||||||
class Entity(pygame.sprite.Sprite):
|
class Entity(pygame.sprite.Sprite):
|
||||||
def __init__(self, groups, is_AI, state = None):
|
def __init__(self, groups, is_AI, state=None):
|
||||||
super().__init__(groups)
|
super().__init__(groups)
|
||||||
|
|
||||||
# Animation
|
# Animation
|
||||||
|
@ -31,9 +32,10 @@ class Entity(pygame.sprite.Sprite):
|
||||||
7: ('swap_magic', None, None)
|
7: ('swap_magic', None, None)
|
||||||
}
|
}
|
||||||
self.state = state
|
self.state = state
|
||||||
self.distance_direction_to_player = [float('inf'), 0, 0, None, None, None, None, None, None, None, None, None]*5
|
self.distance_direction_to_player = [
|
||||||
|
float('inf'), 0, 0, None, None, None, None, None, None, None, None, None]*5
|
||||||
|
|
||||||
#self.agent = Agent(self.possible_actions, self.distance_direction_to_player, self.stats, self.exp, None, None)
|
# self.agent = Agent(self.possible_actions, self.distance_direction_to_player, self.stats, self.exp, None, None)
|
||||||
|
|
||||||
def move(self, speed):
|
def move(self, speed):
|
||||||
if self.direction.magnitude() != 0:
|
if self.direction.magnitude() != 0:
|
||||||
|
@ -76,22 +78,22 @@ class Entity(pygame.sprite.Sprite):
|
||||||
self.move_time = pygame.time.get_ticks()
|
self.move_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
# Movement Input
|
# Movement Input
|
||||||
if button == 0: #keys[pygame.K_w]:
|
if button == 0: # keys[pygame.K_w]:
|
||||||
self.direction.y = -1
|
self.direction.y = -1
|
||||||
self.status = 'up'
|
self.status = 'up'
|
||||||
self.can_move = False
|
self.can_move = False
|
||||||
elif button == 1: #keys[pygame.K_s]:
|
elif button == 1: # keys[pygame.K_s]:
|
||||||
self.direction.y = 1
|
self.direction.y = 1
|
||||||
self.status = 'down'
|
self.status = 'down'
|
||||||
self.can_move = False
|
self.can_move = False
|
||||||
else:
|
else:
|
||||||
self.direction.y = 0
|
self.direction.y = 0
|
||||||
|
|
||||||
if button == 2: #keys[pygame.K_a]:
|
if button == 2: # keys[pygame.K_a]:
|
||||||
self.direction.x = -1
|
self.direction.x = -1
|
||||||
self.status = 'left'
|
self.status = 'left'
|
||||||
self.can_move = False
|
self.can_move = False
|
||||||
elif button == 3: #keys[pygame.K_d]:
|
elif button == 3: # keys[pygame.K_d]:
|
||||||
self.direction.x = 1
|
self.direction.x = 1
|
||||||
self.status = 'right'
|
self.status = 'right'
|
||||||
self.can_move = False
|
self.can_move = False
|
||||||
|
@ -99,18 +101,19 @@ class Entity(pygame.sprite.Sprite):
|
||||||
self.direction.x = 0
|
self.direction.x = 0
|
||||||
|
|
||||||
# Combat Input
|
# Combat Input
|
||||||
if button == 4: #keys[pygame.K_e]:
|
if button == 4: # keys[pygame.K_e]:
|
||||||
self.attacking = True
|
self.attacking = True
|
||||||
self.attack_time = pygame.time.get_ticks()
|
self.attack_time = pygame.time.get_ticks()
|
||||||
self.create_attack_sprite()
|
self.create_attack_sprite()
|
||||||
self.weapon_attack_sound.play()
|
self.weapon_attack_sound.play()
|
||||||
|
|
||||||
# Magic Input
|
# Magic Input
|
||||||
if button == 5: #keys[pygame.K_q]:
|
if button == 5: # keys[pygame.K_q]:
|
||||||
self.attacking = True
|
self.attacking = True
|
||||||
self.attack_time = pygame.time.get_ticks()
|
self.attack_time = pygame.time.get_ticks()
|
||||||
style = list(magic_data.keys())[self.magic_index]
|
style = list(magic_data.keys())[self.magic_index]
|
||||||
strength = list(magic_data.values())[self.magic_index]['strength'] + self.stats['magic']
|
strength = list(magic_data.values())[
|
||||||
|
self.magic_index]['strength'] + self.stats['magic']
|
||||||
cost = list(magic_data.values())[self.magic_index]['cost']
|
cost = list(magic_data.values())[self.magic_index]['cost']
|
||||||
self.create_magic_sprite(style, strength, cost)
|
self.create_magic_sprite(style, strength, cost)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ class Level:
|
||||||
# General Settings
|
# General Settings
|
||||||
self.game_paused = False
|
self.game_paused = False
|
||||||
|
|
||||||
|
|
||||||
# Get the display surface
|
# Get the display surface
|
||||||
self.display_surface = pygame.display.get_surface()
|
self.display_surface = pygame.display.get_surface()
|
||||||
|
|
||||||
|
@ -62,7 +61,6 @@ class Level:
|
||||||
'objects': import_folder('../Graphics/graphics/objects')
|
'objects': import_folder('../Graphics/graphics/objects')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for style, layout in layouts.items():
|
for style, layout in layouts.items():
|
||||||
for row_index, row in enumerate(layout):
|
for row_index, row in enumerate(layout):
|
||||||
for col_index, col in enumerate(row):
|
for col_index, col in enumerate(row):
|
||||||
|
@ -70,23 +68,27 @@ class Level:
|
||||||
x = col_index * TILESIZE
|
x = col_index * TILESIZE
|
||||||
y = row_index * TILESIZE
|
y = row_index * TILESIZE
|
||||||
if style == 'boundary':
|
if style == 'boundary':
|
||||||
Tile((x,y), [self.obstacle_sprites], 'invisible')
|
Tile((x, y), [self.obstacle_sprites], 'invisible')
|
||||||
|
|
||||||
if style == 'grass':
|
if style == 'grass':
|
||||||
random_grass_image = choice(graphics['grass'])
|
random_grass_image = choice(graphics['grass'])
|
||||||
Tile((x,y), [self.visible_sprites, self.obstacle_sprites, self.attackable_sprites], 'grass', random_grass_image)
|
Tile((x, y), [self.visible_sprites, self.obstacle_sprites,
|
||||||
|
self.attackable_sprites], 'grass', random_grass_image)
|
||||||
|
|
||||||
if style == 'objects':
|
if style == 'objects':
|
||||||
surf = graphics['objects'][int(col)]
|
surf = graphics['objects'][int(col)]
|
||||||
Tile((x,y), [self.visible_sprites, self.obstacle_sprites], 'object', surf)
|
Tile((x, y), [self.visible_sprites,
|
||||||
|
self.obstacle_sprites], 'object', surf)
|
||||||
|
|
||||||
# The numbers represent their IDs in the map .csv files generated from TILED.
|
# The numbers represent their IDs in the map .csv files generated from TILED.
|
||||||
if style == 'entities':
|
if style == 'entities':
|
||||||
if col == '394':
|
if col == '394':
|
||||||
self.player = Player((x,y), [self.visible_sprites], self.obstacle_sprites, self.create_attack_sprite, self.delete_attack_sprite, self.create_magic_sprite, is_AI = True, state = self.get_state)
|
self.player = Player((x, y), [self.visible_sprites], self.obstacle_sprites, self.create_attack_sprite,
|
||||||
|
self.delete_attack_sprite, self.create_magic_sprite, is_AI=True, state=self.get_state)
|
||||||
|
|
||||||
elif col =='395':
|
elif col == '395':
|
||||||
self.camera = Camera((x,y), [self.visible_sprites])
|
self.camera = Camera(
|
||||||
|
(x, y), [self.visible_sprites])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if col == '390':
|
if col == '390':
|
||||||
|
@ -98,10 +100,12 @@ class Level:
|
||||||
else:
|
else:
|
||||||
monster_name = 'squid'
|
monster_name = 'squid'
|
||||||
|
|
||||||
Enemy(monster_name, (x,y), [self.visible_sprites, self.attackable_sprites], self.obstacle_sprites, self.damage_player, self.trigger_death_particles, self.add_exp, is_AI = False, state = None)
|
Enemy(monster_name, (x, y), [self.visible_sprites, self.attackable_sprites], self.obstacle_sprites,
|
||||||
|
self.damage_player, self.trigger_death_particles, self.add_exp, is_AI=False, state=None)
|
||||||
|
|
||||||
def create_attack_sprite(self):
|
def create_attack_sprite(self):
|
||||||
self.current_attack = Weapon(self.player, [self.visible_sprites, self.attack_sprites])
|
self.current_attack = Weapon(
|
||||||
|
self.player, [self.visible_sprites, self.attack_sprites])
|
||||||
|
|
||||||
def delete_attack_sprite(self):
|
def delete_attack_sprite(self):
|
||||||
if self.current_attack:
|
if self.current_attack:
|
||||||
|
@ -110,34 +114,41 @@ class Level:
|
||||||
|
|
||||||
def create_magic_sprite(self, style, strength, cost):
|
def create_magic_sprite(self, style, strength, cost):
|
||||||
if style == 'heal':
|
if style == 'heal':
|
||||||
self.magic_player.heal(self.player, strength, cost, [self.visible_sprites])
|
self.magic_player.heal(self.player, strength, cost, [
|
||||||
|
self.visible_sprites])
|
||||||
|
|
||||||
if style == 'flame':
|
if style == 'flame':
|
||||||
self.magic_player.flame(self.player, cost, [self.visible_sprites, self.attack_sprites])
|
self.magic_player.flame(
|
||||||
|
self.player, cost, [self.visible_sprites, self.attack_sprites])
|
||||||
|
|
||||||
def player_attack_logic(self):
|
def player_attack_logic(self):
|
||||||
if self.attack_sprites:
|
if self.attack_sprites:
|
||||||
for attack_sprite in self.attack_sprites:
|
for attack_sprite in self.attack_sprites:
|
||||||
collision_sprites = pygame.sprite.spritecollide(attack_sprite,self.attackable_sprites,False)
|
collision_sprites = pygame.sprite.spritecollide(
|
||||||
|
attack_sprite, self.attackable_sprites, False)
|
||||||
if collision_sprites:
|
if collision_sprites:
|
||||||
for target_sprite in collision_sprites:
|
for target_sprite in collision_sprites:
|
||||||
if target_sprite.sprite_type == 'grass':
|
if target_sprite.sprite_type == 'grass':
|
||||||
pos = target_sprite.rect.center
|
pos = target_sprite.rect.center
|
||||||
offset = pygame.math.Vector2(0,75)
|
offset = pygame.math.Vector2(0, 75)
|
||||||
for leaf in range(randint(3,6)):
|
for leaf in range(randint(3, 6)):
|
||||||
self.animation_player.create_grass_particles(position = pos - offset, groups = [self.visible_sprites])
|
self.animation_player.create_grass_particles(
|
||||||
|
position=pos - offset, groups=[self.visible_sprites])
|
||||||
target_sprite.kill()
|
target_sprite.kill()
|
||||||
else:
|
else:
|
||||||
target_sprite.get_damage(self.player,attack_sprite.sprite_type)
|
target_sprite.get_damage(
|
||||||
|
self.player, attack_sprite.sprite_type)
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
state = []
|
state = []
|
||||||
|
|
||||||
enemy_sprites = [sprite for sprite in self.visible_sprites if hasattr(sprite, 'sprite_type') and sprite.sprite_type == 'enemy']
|
enemy_sprites = [sprite for sprite in self.visible_sprites if hasattr(
|
||||||
|
sprite, 'sprite_type') and sprite.sprite_type == 'enemy']
|
||||||
for enemy in enemy_sprites:
|
for enemy in enemy_sprites:
|
||||||
distance, direction = enemy.get_player_distance_direction(self.player)
|
distance, direction = enemy.get_player_distance_direction(
|
||||||
state.append([(distance, direction.x, direction.y, enemy.monster_name, enemy.health, enemy.exp, enemy.speed, enemy.attack_damage, enemy.resistance, enemy.attack_radius, enemy.notice_radius, enemy.attack_type)])
|
self.player)
|
||||||
|
state.append([(distance, direction.x, direction.y, enemy.monster_name, enemy.health, enemy.exp, enemy.speed,
|
||||||
|
enemy.attack_damage, enemy.resistance, enemy.attack_radius, enemy.notice_radius, enemy.attack_type)])
|
||||||
|
|
||||||
# Sort by distance
|
# Sort by distance
|
||||||
state = sorted(state, key=lambda x: x[0])
|
state = sorted(state, key=lambda x: x[0])
|
||||||
|
@ -147,7 +158,8 @@ class Level:
|
||||||
|
|
||||||
# If there are fewer than 5 enemies, pad the state with placeholder values
|
# If there are fewer than 5 enemies, pad the state with placeholder values
|
||||||
while len(state) < 5:
|
while len(state) < 5:
|
||||||
state.append((float('inf'), 0, 0, None, None, None, None, None, None, None, None, None))
|
state.append((float('inf'), 0, 0, None, None, None,
|
||||||
|
None, None, None, None, None, None))
|
||||||
|
|
||||||
# Flatten the state to be a single list of numbers and strings
|
# Flatten the state to be a single list of numbers and strings
|
||||||
state = [item for sublist in state for item in sublist]
|
state = [item for sublist in state for item in sublist]
|
||||||
|
@ -161,10 +173,12 @@ class Level:
|
||||||
self.player.health = 0
|
self.player.health = 0
|
||||||
self.player.vulnerable = False
|
self.player.vulnerable = False
|
||||||
self.player.hurt_time = pygame.time.get_ticks()
|
self.player.hurt_time = pygame.time.get_ticks()
|
||||||
self.animation_player.generate_particles(attack_type, self.player.rect.center, [self.visible_sprites])
|
self.animation_player.generate_particles(
|
||||||
|
attack_type, self.player.rect.center, [self.visible_sprites])
|
||||||
|
|
||||||
def trigger_death_particles(self, position, particle_type):
|
def trigger_death_particles(self, position, particle_type):
|
||||||
self.animation_player.generate_particles(particle_type, position, [self.visible_sprites])
|
self.animation_player.generate_particles(
|
||||||
|
particle_type, position, [self.visible_sprites])
|
||||||
|
|
||||||
def add_exp(self, amount):
|
def add_exp(self, amount):
|
||||||
self.player.exp += amount
|
self.player.exp += amount
|
||||||
|
@ -189,39 +203,3 @@ class Level:
|
||||||
|
|
||||||
if self.player.health <= 0:
|
if self.player.health <= 0:
|
||||||
self.__init__()
|
self.__init__()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class YSortCameraGroup(pygame.sprite.Group):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
# General Setup
|
|
||||||
self.display_surface = pygame.display.get_surface()
|
|
||||||
self.half_width = self.display_surface.get_size()[0] // 2
|
|
||||||
self.half_height = self.display_surface.get_size()[1] // 2
|
|
||||||
self.offset = pygame.math.Vector2(100, 200)
|
|
||||||
|
|
||||||
# Creating the floor
|
|
||||||
self.floor_surf = pygame.image.load('../Graphics/graphics/tilemap/ground.png').convert()
|
|
||||||
self.floor_rect = self.floor_surf.get_rect(topleft = (0,0))
|
|
||||||
|
|
||||||
def custom_draw(self, player):
|
|
||||||
self.sprite_type = player.sprite_type
|
|
||||||
#Getting the offset
|
|
||||||
self.offset.x = player.rect.centerx - self.half_width
|
|
||||||
self.offset.y = player.rect.centery - self.half_height
|
|
||||||
|
|
||||||
# Drawing the floor
|
|
||||||
floor_offset_pos = self.floor_rect.topleft - self.offset
|
|
||||||
self.display_surface.blit(self.floor_surf, floor_offset_pos)
|
|
||||||
|
|
||||||
for sprite in sorted(self.sprites(), key = lambda sprite: sprite.rect.centery):
|
|
||||||
offset_pos = sprite.rect.topleft - self.offset
|
|
||||||
self.display_surface.blit(sprite.image, offset_pos)
|
|
||||||
|
|
||||||
def enemy_update(self, player):
|
|
||||||
enemy_sprites = [sprite for sprite in self.sprites() if hasattr(sprite, 'sprite_type') and sprite.sprite_type == 'enemy']
|
|
||||||
for enemy in enemy_sprites:
|
|
||||||
enemy.enemy_update(player)
|
|
||||||
|
|
|
@ -10,13 +10,15 @@ from objects.entity import Entity
|
||||||
from rl.agent import Agent
|
from rl.agent import Agent
|
||||||
from rl.rl_settings import *
|
from rl.rl_settings import *
|
||||||
|
|
||||||
|
|
||||||
class Player(Entity):
|
class Player(Entity):
|
||||||
|
|
||||||
def __init__(self, position, groups, obstacle_sprites, create_attack_sprite, delete_attack_sprite, create_magic_sprite, is_AI, state):
|
def __init__(self, position, groups, obstacle_sprites, create_attack_sprite, delete_attack_sprite, create_magic_sprite, is_AI, state):
|
||||||
super().__init__(groups, is_AI, state)
|
super().__init__(groups, is_AI, state)
|
||||||
|
|
||||||
self.image = pygame.image.load('../Graphics/graphics/player/down/down_0.png').convert_alpha()
|
self.image = pygame.image.load(
|
||||||
self.rect = self.image.get_rect(topleft = position)
|
'../Graphics/graphics/player/down/down_0.png').convert_alpha()
|
||||||
|
self.rect = self.image.get_rect(topleft=position)
|
||||||
self.hitbox = self.rect.inflate(HITBOX_OFFSET['player'])
|
self.hitbox = self.rect.inflate(HITBOX_OFFSET['player'])
|
||||||
self.sprite_type = 'player'
|
self.sprite_type = 'player'
|
||||||
|
|
||||||
|
@ -75,7 +77,8 @@ class Player(Entity):
|
||||||
# AI setup
|
# AI setup
|
||||||
self.is_AI = is_AI
|
self.is_AI = is_AI
|
||||||
if self.is_AI:
|
if self.is_AI:
|
||||||
self.agent = Agent(self.possible_actions, input_dims = (list(self.stats.values())+ self.distance_direction_to_player), batch_size = batch_size, alpha = alpha, n_epochs = n_epochs)
|
self.agent = Agent(self.possible_actions, input_dims=(list(self.stats.values(
|
||||||
|
)) + self.distance_direction_to_player), batch_size=batch_size, alpha=alpha, n_epochs=n_epochs)
|
||||||
|
|
||||||
self.health = self.stats['health']
|
self.health = self.stats['health']
|
||||||
self.energy = self.stats['energy']
|
self.energy = self.stats['energy']
|
||||||
|
@ -90,7 +93,8 @@ class Player(Entity):
|
||||||
self.obstacle_sprites = obstacle_sprites
|
self.obstacle_sprites = obstacle_sprites
|
||||||
|
|
||||||
# Import Sounds
|
# Import Sounds
|
||||||
self.weapon_attack_sound = pygame.mixer.Sound('../Graphics/audio/sword.wav')
|
self.weapon_attack_sound = pygame.mixer.Sound(
|
||||||
|
'../Graphics/audio/sword.wav')
|
||||||
self.weapon_attack_sound.set_volume(0.2)
|
self.weapon_attack_sound.set_volume(0.2)
|
||||||
|
|
||||||
def import_player_assets(self):
|
def import_player_assets(self):
|
||||||
|
@ -171,7 +175,6 @@ class Player(Entity):
|
||||||
else:
|
else:
|
||||||
self.energy = self.stats['energy']
|
self.energy = self.stats['energy']
|
||||||
|
|
||||||
|
|
||||||
def animate(self):
|
def animate(self):
|
||||||
animation = self.animations[self.status]
|
animation = self.animations[self.status]
|
||||||
self.frame_index += self.animation_speed
|
self.frame_index += self.animation_speed
|
||||||
|
@ -180,7 +183,7 @@ class Player(Entity):
|
||||||
|
|
||||||
# Set the image
|
# Set the image
|
||||||
self.image = animation[int(self.frame_index)]
|
self.image = animation[int(self.frame_index)]
|
||||||
self.rect = self.image.get_rect(center = self.hitbox.center)
|
self.rect = self.image.get_rect(center=self.hitbox.center)
|
||||||
|
|
||||||
if not self.vulnerable:
|
if not self.vulnerable:
|
||||||
alpha = self.wave_value()
|
alpha = self.wave_value()
|
||||||
|
@ -188,7 +191,6 @@ class Player(Entity):
|
||||||
else:
|
else:
|
||||||
self.image.set_alpha(255)
|
self.image.set_alpha(255)
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.input()
|
self.input()
|
||||||
self.cooldowns()
|
self.cooldowns()
|
||||||
|
@ -197,5 +199,5 @@ class Player(Entity):
|
||||||
self.move(self.stats['speed'])
|
self.move(self.stats['speed'])
|
||||||
self.energy_recovery()
|
self.energy_recovery()
|
||||||
self.distance_direction_to_player = self.state()
|
self.distance_direction_to_player = self.state()
|
||||||
#if self.is_AI:
|
# if self.is_AI:
|
||||||
# self.agent.act(self.distance_direction_to_player)
|
# self.agent.act(self.distance_direction_to_player)
|
||||||
|
|
Loading…
Reference in a new issue