Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jmnorheim committed Apr 17, 2024
2 parents 4db452d + d327de7 commit 60a129a
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 42 deletions.
Binary file modified assets/ant_frame1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/ant_frame2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/ant_frame3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/ant_frame4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/magic_tower_frame1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/magic_tower_frame2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/magic_tower_frame3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions core/src/com/softwarearchitecture/GameApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.softwarearchitecture.clock.Clock;
import com.softwarearchitecture.game_client.GameClient;
import com.softwarearchitecture.launcher.GameLauncher;

Expand All @@ -15,8 +16,9 @@ public class GameApp extends ApplicationAdapter {

@Override
public void create() {
Clock.getInstance();
camera = new OrthographicCamera();
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
gameClient = GameLauncher.createGameClient(this.camera, this.viewport);
}

Expand All @@ -33,6 +35,6 @@ public void resize(int width, int height) {

@Override
public void dispose() {
//gameClient.dispose();
// gameClient.dispose();
}
}
50 changes: 50 additions & 0 deletions core/src/com/softwarearchitecture/clock/Clock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.softwarearchitecture.clock;

public class Clock {
private long currentTime;
private float animationTime = 150f;
private float movementTime = 100f;
private float attackTime = 300f;

// singleton instance
private static Clock instance = null;

public static Clock getInstance() {
if (instance == null) {

instance = new Clock();
}
return instance;
}

private Clock() {
currentTime = System.currentTimeMillis();

}

public boolean isTimeToAnimate() {
boolean timeToAnimate = System.currentTimeMillis() - currentTime >= animationTime;
if (timeToAnimate) {
currentTime = System.currentTimeMillis();
}
return timeToAnimate;
}

public boolean isTimeToMove() {

boolean timeToMove = System.currentTimeMillis() - currentTime >= movementTime;
if (timeToMove) {
currentTime = System.currentTimeMillis();
}
return timeToMove;

}

public boolean isTimeToAttack(float time) {
boolean timeToMove = System.currentTimeMillis() - currentTime >= attackTime;
if (timeToMove) {
currentTime = System.currentTimeMillis();
}
return timeToMove;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;
import java.util.Set;

import com.softwarearchitecture.clock.Clock;
import com.softwarearchitecture.ecs.ComponentManager;
import com.softwarearchitecture.ecs.ECSManager;
import com.softwarearchitecture.ecs.Entity;
Expand All @@ -30,11 +31,13 @@ public AnimationSystem() {
@Override
public void update(Set<Entity> entities, float deltaTime) {

boolean isAnimation = Clock.getInstance().isTimeToAnimate();

for (Entity entity : entities) {
Optional<SpriteComponent> spriteComponent = spriteManager.getComponent(entity);
Optional<AnimationComponent> animationComponent = animationManager.getComponent(entity);

if (spriteComponent.isPresent() && animationComponent.isPresent()) {
if (spriteComponent.isPresent() && animationComponent.isPresent() && isAnimation) {
SpriteComponent sprite = spriteComponent.get();
AnimationComponent animation = animationComponent.get();
sprite.texture_path = animation.getAnimationPath();
Expand Down
53 changes: 29 additions & 24 deletions core/src/com/softwarearchitecture/ecs/systems/EnemySystem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.softwarearchitecture.ecs.systems;


import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -26,7 +25,8 @@
import com.softwarearchitecture.math.Vector2;

/**
* This class is supposed to check if enemies are at the end of the map, and if so despawns them
* This class is supposed to check if enemies are at the end of the map, and if
* so despawns them
*
*/
public class EnemySystem implements System {
Expand All @@ -50,7 +50,6 @@ public class EnemySystem implements System {
private int maxLiveMonsters;
private int villageDamage;


public EnemySystem() {
this.positionManager = ECSManager.getInstance().getOrDefaultComponentManager(PositionComponent.class);
this.velocityManager = ECSManager.getInstance().getOrDefaultComponentManager(VelocityComponent.class);
Expand All @@ -71,11 +70,10 @@ public EnemySystem() {
this.villageDamage = 0;
}


@Override
public void update(Set<Entity> entities, float deltaTime) {
//Get tile size
Vector2 tileSize = new Vector2(0,0);
// Get tile size
Vector2 tileSize = new Vector2(0, 0);
for (Entity entity : entities) {
if (path == null) {
Optional<PathfindingComponent> possiblePath = pathfindingManager.getComponent(entity);
Expand All @@ -89,9 +87,9 @@ public void update(Set<Entity> entities, float deltaTime) {
if (sprite.isPresent() && tile.isPresent()) {
tileSize = sprite.get().size_uv;
continue;
}
}
}
/*For path not yet initialized escape early */
/* For path not yet initialized escape early */
if (path == null) {
return;
}
Expand All @@ -106,7 +104,7 @@ public void update(Set<Entity> entities, float deltaTime) {
if (!position.isPresent() || !velocity.isPresent() || !pathfinding.isPresent() || !health.isPresent()) {
continue;
}

Vector2 pos = position.get().position;
List<Tile> find = pathfinding.get().path;
Tile nextTile = pathfinding.get().targetTile;
Expand All @@ -115,7 +113,8 @@ public void update(Set<Entity> entities, float deltaTime) {
float nextTilePos_y = nextTile.getY() * tileSize.y;
Vector2 nextTilePos = new Vector2(nextTilePos_x, nextTilePos_y);

// If the enemy has reached the end of the path, move it to the start to be spawned again
// If the enemy has reached the end of the path, move it to the start to be
// spawned again
if (nextTile.getType() == TileType.END) {
pathfinding.get().targetTile = find.get(0);
float startPosition_x = find.get(0).getX() * tileSize.x;
Expand All @@ -127,38 +126,42 @@ public void update(Set<Entity> entities, float deltaTime) {
java.lang.System.out.println("RemainingEnemyHealth = " + remainingEnemyHealth);
this.villageDamage += remainingEnemyHealth;
java.lang.System.out.println("VillageDamage = " + villageDamage);
}
else if (hp <= 0) {
position.get().position = new Vector2(-1,-1);
} else if (hp <= 0) {
position.get().position = new Vector2(-1, -1);
velocity.get().velocity = new Vector2(0, 0);
liveMonsterCounter--;
}
}

spawnTimer -= deltaTime;


if (spawnTimer <= 0 && monsterCounter < waveSize) {

// Keep creating enemies under max-limit is met
if (liveMonsterCounter < maxLiveMonsters) {
mob = EnemyFactory.createEnemy(EnemyType.WOLF, path, tileSize);

// random enemy
EnemyType[] enemyTypes = EnemyType.values();
EnemyType randomEnemy = enemyTypes[(int) (Math.random() * enemyTypes.length)];

mob = EnemyFactory.createEnemy(randomEnemy, path, tileSize);
ECSManager.getInstance().addEntity(mob);
monsterCounter++;
liveMonsterCounter++;
spawnTimer = 200f;
}
}
// If the max number of enemies has been met, check if any of them are dead
else {

for (Entity entity : entities) {
Optional<PositionComponent> position = positionManager.getComponent(entity);
Optional<VelocityComponent> velocity = velocityManager.getComponent(entity);
Optional<PathfindingComponent> pathfinding = pathfindingManager.getComponent(entity);
Optional<HealthComponent> health = healthManager.getComponent(entity);
// Optional<MoneyComponent> money = moneyManager.getComponent(entity);

if (!position.isPresent() || !velocity.isPresent() || !pathfinding.isPresent() || !health.isPresent()) {

if (!position.isPresent() || !velocity.isPresent() || !pathfinding.isPresent()
|| !health.isPresent()) {
continue;
}

Expand All @@ -176,16 +179,18 @@ else if (hp <= 0) {
}
}
}
// Decrement the wave timer
// Decrement the wave timer
if (waveTimer > 0) {
waveTimer -= deltaTime;
}
// If any enemies have gotten through, damage the village
if (villageDamage > 0) {
for (Entity entity : entities) {
// If an entity has both a player and health component, it is the village and should take damage
// If an entity has both a player and health component, it is the village and
// should take damage
if (playerManager.getComponent(entity).isPresent() && healthManager.getComponent(entity).isPresent()) {
// int remainingEnemyHealth = healthManager.getComponent(entity).get().getHealth();
// int remainingEnemyHealth =
// healthManager.getComponent(entity).get().getHealth();
int villageHealth = healthManager.getComponent(entity).get().getHealth();
villageHealth -= villageDamage;
healthManager.getComponent(entity).get().setHealth(villageHealth);
Expand All @@ -203,10 +208,10 @@ else if (hp <= 0) {
}
}
// Start the next wave
if (monsterCounter >= waveSize && waveTimer<=0) {
if (monsterCounter >= waveSize && waveTimer <= 0) {
waveNumber++;
monsterCounter = 0;
waveSize+=waveNumber * 2 - 2;
waveSize += waveNumber * 2 - 2;
waveTimer = 60f;
spawnTimer = 0f;
maxLiveMonsters++;
Expand Down
43 changes: 28 additions & 15 deletions core/src/com/softwarearchitecture/game_server/EnemyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.softwarearchitecture.ecs.components.CostComponent;
import com.softwarearchitecture.ecs.components.EnemyComponent;
import com.softwarearchitecture.ecs.components.HealthComponent;
import com.softwarearchitecture.ecs.components.MoneyComponent;
import com.softwarearchitecture.ecs.components.PathfindingComponent;
import com.softwarearchitecture.ecs.components.PositionComponent;
import com.softwarearchitecture.ecs.components.SoundComponent;
Expand All @@ -19,8 +20,7 @@
public class EnemyFactory {

public enum EnemyType {
NORDIC_ANT,
WOLF, VIKING_SWORD_SHIELD, VIKING_SWORD, VIKING_AXE, VIKING_SPEAR
NORDIC_ANT, WOLF, VIKING_SWORD_SHIELD, VIKING_SWORD, VIKING_AXE, VIKING_SPEAR

}

Expand All @@ -36,6 +36,7 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
int damage = 1;
int maxHealth = 0;
String sound = "soundPath";
int money = 0;

switch (enemyType) {
case NORDIC_ANT:
Expand All @@ -45,20 +46,26 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
textures.add(TexturePack.ENEMY_ANT_FRAME4);

damage = 1;
size.set(0.025f, 0.025f);
velocity.set(0.01f, 0.01f);
size.set(0.03f, 0.03f);
velocity.set(0.02f, 0.02f);
maxHealth = 10;
sound = "soundPath"; // TODO: Add the correct sound path
money = 1;

break;
case WOLF:
textures.add(TexturePack.ENEMY_FENRIR1);
textures.add(TexturePack.ENEMY_FENRIR2);
textures.add(TexturePack.ENEMY_WOLF_FRAME1);
textures.add(TexturePack.ENEMY_WOLF_FRAME2);
textures.add(TexturePack.ENEMY_WOLF_FRAME3);
textures.add(TexturePack.ENEMY_WOLF_FRAME4);
textures.add(TexturePack.ENEMY_WOLF_FRAME5);

damage = 2;
size.set(0.075f, 0.075f);
velocity.set(0.2f, 0.2f);
velocity.set(0.05f, 0.05f);
maxHealth = 100;
sound = "soundPath"; // TODO: Add the correct sound path
money = 30;

break;

Expand All @@ -68,10 +75,11 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
textures.add(TexturePack.ENEMY_VIKING_SPEAR_FRAME3);
textures.add(TexturePack.ENEMY_VIKING_SPEAR_FRAME4);
damage = 3;
size.set(0.04f, 0.04f);
velocity.set(0.03f, 0.03f);
size.set(0.065f, 0.093f);
velocity.set(0.04f, 0.04f);
maxHealth = 100;
sound = "soundPath"; // TODO: Add the correct sound path
money = 100;

break;

Expand All @@ -81,10 +89,11 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
textures.add(TexturePack.ENEMY_VIKING_SWORD_FRAME3);
textures.add(TexturePack.ENEMY_VIKING_SWORD_FRAME4);
damage = 4;
size.set(0.05f, 0.05f);
velocity.set(0.04f, 0.04f);
size.set(0.05f, 0.08f);
velocity.set(0.03f, 0.03f);
maxHealth = 100;
sound = "soundPath"; // TODO: Add the correct sound path
money = 150;

break;

Expand All @@ -94,10 +103,11 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
textures.add(TexturePack.ENEMY_VIKING_SWORD_SHIELD_FRAME3);
textures.add(TexturePack.ENEMY_VIKING_SWORD_SHIELD_FRAME4);
damage = 5;
size.set(0.06f, 0.06f);
velocity.set(0.04f, 0.04f);
size.set(0.05f, 0.08f);
velocity.set(0.03f, 0.03f);
maxHealth = 200;
sound = "soundPath"; // TODO: Add the correct sound path
money = 200;

break;

Expand All @@ -107,10 +117,11 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
textures.add(TexturePack.ENEMY_VIKING_AXE_FRAME3);
textures.add(TexturePack.ENEMY_VIKING_AXE_FRAME4);
damage = 4;
size.set(0.07f, 0.07f);
velocity.set(0.03f, 0.03f);
size.set(0.05f, 0.08f);
velocity.set(0.023f, 0.023f);
maxHealth = 300;
sound = "soundPath"; // TODO: Add the correct sound path
money = 100;

break;

Expand All @@ -125,6 +136,7 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
SoundComponent soundComponent = new SoundComponent(sound);
VelocityComponent velocityComponent = new VelocityComponent(velocity.x, velocity.y);
PathfindingComponent PathfindingComponent = new PathfindingComponent(enemyPath);
MoneyComponent moneyComponent = new MoneyComponent(money);
// TODO: Add target component if necessary

Entity enemyEntity = new Entity();
Expand All @@ -136,6 +148,7 @@ public static Entity createEnemy(EnemyType enemyType, List<Tile> enemyPath, Vect
enemyEntity.addComponent(SoundComponent.class, soundComponent);
enemyEntity.addComponent(VelocityComponent.class, velocityComponent);
enemyEntity.addComponent(PathfindingComponent.class, PathfindingComponent);
enemyEntity.addComponent(MoneyComponent.class, moneyComponent);

return enemyEntity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static Entity createTower(CardType cardType1, CardType cardType2, Vector2
textures.add(TexturePack.TOWER_FIRE_FRAME1);
textures.add(TexturePack.TOWER_FIRE_FRAME2);
textures.add(TexturePack.TOWER_FIRE_FRAME3);
textures.add(TexturePack.TOWER_FIRE_ATTACK_FRAME1);
textures.add(TexturePack.TOWER_FIRE_ATTACK_FRAME2);
textures.add(TexturePack.TOWER_FIRE_ATTACK_FRAME3);

damage = 4;
range = 2;
attackCooldown = 40;
Expand Down

0 comments on commit 60a129a

Please sign in to comment.