Sprint 1 Technical Implementation - UQdeco2800/2022-studio-1 GitHub Wiki

Link back to the main page

Spawning of Ranged Enemy

The current implementation to spawn a ranged enemy can be found in the create() section of ForestGameArea. To spawn the electric eel a while loop is run which contains an if loop checking for a position to spawn the enemy. If a position can not be found the loop is broken.

private void spawnElectricEelEnemy(){
    Entity ElectricEelEnemy = NPCFactory.createElectricEelEnemy(player);
    GridPoint2 minPos = new GridPoint2(0,0);
    GridPoint2 maxPos = terrain.getMapBounds(0);
    GridPoint2 randomPos = RandomUtils.random(minPos,maxPos);

    while (true){
      randomPos = RandomUtils.random(minPos,maxPos);
      if (this.entityMapping.wouldCollide(ElectricEelEnemy, randomPos.x, randomPos.y)
              ||entityMapping.isNearWater(randomPos.x, randomPos.y)) {
        continue;
      } else {
        break;
      }
    }
    spawnEntityAt(ElectricEelEnemy,randomPos,true,true);
  }

Creating framework for projectiles

public class ProjectileFactory {
    public static void createProjectile(Entity shooter, Entity target) {
        float x1 = shooter.getPosition().x;
        float y1 = shooter.getPosition().y;
        float x2 = target.getPosition().x;
        float y2 = target.getPosition().y;

        Vector2 Target = new Vector2(x2 - x1, y2 - y1);

        //Entity Projectile = makeProjectile();


    }

    private static Entity makeProjectile() {
        Entity projectile = new Entity()
                .addComponent(new TextureRenderComponent("images/ElectricEel.png"))
                .addComponent(new PhysicsComponent())
                .addComponent(new PhysicsMovementComponent())
                .addComponent(new ColliderComponent())
                .addComponent(new CombatStatsComponent(1,20))
                .addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 0.2f));

        return projectile;
    }

    private ProjectileFactory() {
        throw new IllegalStateException("Instantiating static util class");
    }
}