Skip to content
3 changes: 3 additions & 0 deletions Constants/Game.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
# How close the player needs to be for the enemy to track it.
# starts to break above 15
ENEMY_AWARENESS = 40

# How often in should a star be ran
PATHING_RATE = 1.0
14 changes: 2 additions & 12 deletions Core/Character.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import arcade
import math

from Constants.Physics import PLAYER_MOVEMENT_SPEED
from Constants.Game import (
SPRITE_SCALING_PLAYER,
DOWN_FACING,
Expand All @@ -11,13 +9,11 @@
SPRITE_SIZE)
from Constants.Animation import WALK_CYCLE_LENGTH, IDLE_CYCLE_LENGTH

# from Core.Projectiles.Projectile_Manager import angle


class Character(arcade.Sprite):
""" Player Sprite"""

def __init__(self, position):
def __init__(self, main_path=''):

# Set up parent class
super().__init__()
Expand All @@ -40,17 +36,11 @@ def __init__(self, position):

# --- Load Textures ---

self.main_path = ''
self.main_path = main_path

# Set the initial texture
self.texture = None

grid_x = 20
grid_y = 25
self.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2
self.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2

self.position = position

def load_textures(self):
# Load textures for idle standing
Expand Down
76 changes: 56 additions & 20 deletions Core/Enemy.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
from typing import List, Union

import arcade
import random

import arcade
from arcade import SpriteList
from typing import List, Union

from Constants.Game import SPRITE_SIZE, SPRITE_SCALING_PLAYER, ENEMY_AWARENESS
from Constants.Game import ENEMY_AWARENESS, PATHING_RATE, SPRITE_SIZE
from Constants.Physics import PLAYER_MOVEMENT_SPEED
from Core.Character import Character


class Enemy(arcade.Sprite):
class Enemy(Character):
def __init__(self, barrier_list, game_resources):
super().__init__(
"Graphics/Character_animation/monsters_idle/skeleton1/v1/skeleton_v1_1.png",
SPRITE_SCALING_PLAYER,
)
super().__init__()
self.randomize_enemy_sprite()
self.load_textures()
self.game_resources = game_resources
self.speed = PLAYER_MOVEMENT_SPEED
self.path = [
self.game_resources.player_sprite.center_x,
self.game_resources.player_sprite.center_y,
]
self.path = []
self.obstacles = self.game_resources.wall_list

self.barrier_list = barrier_list

self.light = game_resources.game_instance.scene_renderer.light_renderer.create_point_light(
self.light = game_resources.scene_renderer.light_renderer.create_point_light(
(-1000, -1000), (1.5, 0.5, 0.25), 196
)
self.barrier_list = barrier_list

def randomize_enemy_sprite(self):
sprites = [
"Graphics/Character_animation/monsters_idle/vampire/v2/vampire_v2",
"Graphics/Character_animation/monsters_idle/skull/v2/skull_v2",
"Graphics/Character_animation/monsters_idle/skeleton2/v2/skeleton2_v2",
"Graphics/Character_animation/monsters_idle/skeleton1/v2/skeleton_v2",
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a linting error here

choice = random.choice(sprites)
self.main_path = choice

def draw(self):
if self.path:
arcade.draw_line_strip(self.path, arcade.color.BLUE, 2)

def on_death(self):
self.game_resources.game_instance.scene_renderer.light_renderer.destroy_light(self.light)
self.game_resources.scene_renderer.light_renderer.destroy_light(self.light)


def calculate_astar(self):
Expand Down Expand Up @@ -74,13 +78,19 @@ def update_position(self):
physics_engine.apply_impulse(self, impulse_force)
self.light.position = (self.center_x, self.center_y)

def on_update(self, delta_time):
self.update_position()
self.update_animation(delta_time)


class EnemyManager:
enemy_list: Union[SpriteList, List[Enemy]]

def __init__(self, game_resources):
self.game_resources = game_resources
self.enemy_list = arcade.SpriteList()
self.next_to_path = 0
self.time_elapsed = 0

def spawn_enemy(self, barrier_list, position):
# Enemy
Expand All @@ -94,9 +104,25 @@ def spawn_enemy(self, barrier_list, position):

return enemy

def spawn_random_enemy(self):
radius = self.game_resources.player_sprite.player_health.max_light_radius
player_pos = self.game_resources.player_sprite.position

rand_x = random.randint(int(player_pos[0]-radius), int(player_pos[0]+radius))
rand_y = random.randint(int(player_pos[1] - radius), int(player_pos[1] + radius))
enemy = self.spawn_enemy(self.make_barrier_list(), (player_pos[0]+100, player_pos[1]+100))
self.game_resources.projectile_manager.add_enemy(enemy)
#for floor in self.game_resources.floor_list:
# if floor.position[0] < rand_x + 100 and floor.position[0] > rand_x - 100 and floor.position[1] < rand_x + 100 and floor.position[1] > rand_x - 100:
# self.spawn_enemy(self.make_barrier_list(), floor.position)

def spawn_continual_enemies(self):
if len(self.enemy_list) < 5:
self.spawn_random_enemy()

def make_barrier_list(self):
grid_size = SPRITE_SIZE

print()
playing_field_left_boundary = self.game_resources.player_sprite.position[0] - (
ENEMY_AWARENESS * SPRITE_SIZE
)
Expand Down Expand Up @@ -129,8 +155,18 @@ def setup(self):

def on_update(self, delta_time):

# move enemies
for enemy in self.enemy_list:
position = self.game_resources.player_sprite.position
if arcade.get_distance(position[0], position[1], enemy.position[0], enemy.position[1]) < 500:
enemy.calculate_astar()
enemy.update_position()
enemy.on_update(delta_time)

# path the next enemy in line
if self.time_elapsed >= PATHING_RATE:
if self.next_to_path < len(self.enemy_list):
self.enemy_list[self.next_to_path].calculate_astar()
self.next_to_path += 1
else:
self.next_to_path = 0

self.time_elapsed += delta_time
97 changes: 12 additions & 85 deletions Core/GameInstance.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@

import arcade
import math
import arcade

from Constants.Game import SCREEN_WIDTH, SCREEN_HEIGHT
from Core.GameResources import GameResources
import ctypes
import platform
import subprocess

from Constants.Physics import PLAYER_MOVEMENT_SPEED
from Constants.Game import SCREEN_WIDTH, SCREEN_HEIGHT

from Core.GameResources import GameResources
Expand All @@ -34,40 +24,7 @@ def __init__(self, window):
# This configures the post processing stack and default lighting
self.scene_renderer = RendererFactory.create_renderer(window)

# Core game resources
self.game_resources = GameResources(self)
self.object_manager = ObjectManager(self.game_resources, self)

self.screensize = 1920,1080

# Fullscreen information get based on OS
if platform.system() == 'Linux':
print("This game expects linux users to be using a 1080p, 16:9 monitor. Other aspect ratios or resolutions on linux may cause issues.")
"""
cmd = ['xrandr']
cmd2 = ['grep', '*']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p2 = subprocess.Popen(cmd2, stdin=p.stdout, stdout=subprocess.PIPE)
p.stdout.close()
resolution_string, junk = p2.communicate()
resolution = resolution_string.split()[0]
width, height = resolution.split('x')
self.screensize[0] = width
self.screensize[1] = height
"""
self.screensize = (1920, 1080)
elif platform.system() == 'Windows':
user32 = ctypes.windll.user32
self.screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

# Physics engine
self.physics_engine = setup_physics_engine(self.game_resources)

self.horizontal_key_list = []
self.verticle_key_list = []



self.screensize = arcade.get_display_size()

# bind rendering callbacks
self.scene_renderer.draw_primary_callback = self.on_draw_scene
Expand All @@ -86,21 +43,11 @@ def __init__(self, window):
)

# dim the ambient lighting to make the player's light more vibrant
self.scene_renderer.light_renderer.ambient_light = (0.2, 0.2, 0.2)
self.scene_renderer.light_renderer.ambient_light = (0.1, 0.1, 0.1)
#self.scene_renderer.light_renderer.ambient_light = (0.01, 0.01, 0.01)

# Core game resources
self.game_resources = GameResources(self)
self.object_manager = ObjectManager(self.game_resources, self)

# Physics engine
self.physics_engine = setup_physics_engine(self.game_resources)

# create light sources
self.light_list = []



self.game_resources = GameResources(self.scene_renderer)

# torch particle system
self.torch_particle_system = TorchSystem(window.ctx)
Expand All @@ -120,17 +67,15 @@ def __init__(self, window):

for light in self.game_resources.light_list:
radius = radius_by_type.get(light.properties["type"])
self.light_list.append(
self.scene_renderer.light_renderer.create_point_light(
(light.center_x, light.center_y), # Position
(
2.5,
1.25,
0.5,
), # Color, 0 = black, 1 = white, 0.5 = grey, order is RGB This can go over 1.0 because of HDR
radius,
) # Radius
)
self.scene_renderer.light_renderer.create_point_light(
(light.center_x, light.center_y), # Position
(
2.5,
1.25,
0.5,
), # Color, 0 = black, 1 = white, 0.5 = grey, order is RGB This can go over 1.0 because of HDR
radius,
) # Radius

if light.properties["type"] == "torch":
self.torch_particle_system.add_torch((light.center_x, light.center_y))
Expand Down Expand Up @@ -194,22 +139,4 @@ def on_draw_after_post(self):

def on_update(self, delta_time):
""" Movement and game logic """

x_force = self.game_resources.player_sprite.x_force
y_force = self.game_resources.player_sprite.y_force
self.game_resources.player_sprite.on_update(delta_time)
self.game_resources.projectile_manager.projectile_physics.apply_impulse(self.game_resources.player_sprite, (x_force, y_force))

# Move the player with the physics engine
# self.physics_engine.update()

self.game_resources.enemy_manager.on_update(delta_time)

# move projectiles
self.game_resources.projectile_manager.on_update(delta_time)


# update animations
self.game_resources.player_sprite.update_animation(delta_time)
self.game_resources.object_manager.on_update(delta_time)
self.game_resources.on_update(delta_time)
Loading