2023-07-11 00:25:44 +00:00
|
|
|
import pygame
|
|
|
|
from random import choice, randint
|
|
|
|
|
|
|
|
from utils.settings import *
|
|
|
|
from utils.debug import debug
|
|
|
|
from utils.support import *
|
|
|
|
|
|
|
|
from UI.ui import UI
|
|
|
|
|
|
|
|
from effects.particles import AnimationPlayer
|
|
|
|
from effects.magic import MagicPlayer
|
|
|
|
from effects.weapon import Weapon
|
|
|
|
|
|
|
|
from terrain.tiles import Tile
|
|
|
|
|
|
|
|
from view.observer import Observer
|
|
|
|
from view.camera import Camera
|
|
|
|
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
class Level:
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
def __init__(self):
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
# General Settings
|
|
|
|
self.game_paused = False
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
# Get display surface
|
|
|
|
self.display_surface = pygame.display.get_surface()
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
# 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()
|
|
|
|
|
|
|
|
def create_map(self):
|
|
|
|
layouts = {
|
|
|
|
'boundary': import_csv_layout('../Map/FloorBlocks.csv'),
|
|
|
|
'grass': import_csv_layout('../Map/Grass.csv'),
|
|
|
|
'objects': import_csv_layout('../Map/Objects.csv'),
|
|
|
|
'entities': import_csv_layout('../Map/Entities.csv')
|
|
|
|
}
|
|
|
|
|
|
|
|
graphics = {
|
|
|
|
'grass': import_folder('../Graphics/grass'),
|
|
|
|
'objects': import_folder('../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':
|
2023-09-27 18:03:37 +00:00
|
|
|
Tile((x, y), [self.obstacle_sprites], 'invisible')
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
if style == 'grass':
|
|
|
|
random_grass_image = choice(graphics['grass'])
|
2023-09-27 18:03:37 +00:00
|
|
|
Tile((x, y), [self.visible_sprites, self.obstacle_sprites,
|
|
|
|
self.attackable_sprites], 'grass', random_grass_image)
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
if style == 'objects':
|
|
|
|
surf = graphics['objects'][int(col)]
|
2023-09-27 18:03:37 +00:00
|
|
|
Tile((x, y), [self.visible_sprites,
|
|
|
|
self.obstacle_sprites], 'object', surf)
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
if style == 'entities':
|
|
|
|
# The numbers represent their IDs in the map .csv files generated from TILED.
|
|
|
|
if col == '395':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.observer = Observer(
|
|
|
|
(x, y), [self.visible_sprites])
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
elif col == '394':
|
|
|
|
pass
|
2023-09-27 18:03:37 +00:00
|
|
|
# player generation
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
pass
|
2023-09-27 18:03:37 +00:00
|
|
|
# monster generation
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
def create_attack_sprite(self):
|
2023-09-27 18:03:37 +00:00
|
|
|
self.current_attack = Weapon(
|
|
|
|
self.player, [self.visible_sprites, self.attack_sprites])
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
def delete_attack_sprite(self):
|
|
|
|
if self.current_attack:
|
|
|
|
self.current_attack.kill()
|
|
|
|
self.current_attack = None
|
|
|
|
|
|
|
|
def create_magic_sprite(self, style, strength, cost):
|
|
|
|
if style == 'heal':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.magic_player.heal(self.player, strength, cost, [
|
|
|
|
self.visible_sprites])
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
if style == 'flame':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.magic_player.flame(
|
|
|
|
self.player, cost, [self.visible_sprites, self.attack_sprites])
|
2023-07-11 00:25:44 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
# Draw the game
|
|
|
|
self.visible_sprites.custom_draw(self.observer)
|
|
|
|
self.ui.display(self.observer)
|
2023-09-27 18:03:37 +00:00
|
|
|
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__()
|