Skip to content

Commit

Permalink
addAlien3
Browse files Browse the repository at this point in the history
  • Loading branch information
delfi-fenoy committed Nov 11, 2024
1 parent 9a9ab4b commit 36428a4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 16 deletions.
Binary file added res/alien3_sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/entities/Alien3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package entities;

import main.Game;
import utilz.LoadSave;

import java.awt.*;
import java.awt.image.BufferedImage;

import static utilz.Constants.EnemyConstants.*;

public class Alien3 extends Enemy {

// ====================> ATRIBUTOS <====================

// ====================> CONTRUCTOR <====================
public Alien3(float x, float y) {
super(x, y, Alien_WIDTH, Alien_HEIGHT, Alien3);
initHitbox(x, y, (int) (20 * Game.SCALE), (int) (20 * Game.SCALE));
loadImgs();
}

// ====================> GET | SET <====================

// ====================> METODOS <====================
public void draw(Graphics g){
g.drawImage(
animations[state][getAniIndex()],
(int)(x - xDrawOffset),
(int)(y - yDrawOffset),
Alien_WIDTH,
Alien_HEIGHT,
null);
}

/** loadImgs() ==> Separa el SpriteSheat y los ubica en una matriz. */
private void loadImgs() {
animations = new BufferedImage[2][5];
BufferedImage temp = LoadSave.GetSpritesAtlas(LoadSave.Alien3_ATLAS);
for (int j = 0; j < animations.length; j++)
for (int i = 0; i < animations[j].length; i++)
animations[j][i] = temp.getSubimage(i * Alien_WIDHT_DEFAULT, j * Alien_HEIGHT_DEFAULT, Alien_WIDHT_DEFAULT, Alien_HEIGHT_DEFAULT);
}
}
19 changes: 10 additions & 9 deletions src/entities/EnemyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class EnemyManager <T extends Enemy> {
private int alienCount = 0; // Numero de Aliens a vencer
private float alienVelocityX = 0.05f; // Velocidad de los aliens

private String curretLevel = "Easy"; // Nivel actual (inicializado en "Easy")
private String currentLevel = "Easy"; // Nivel actual (inicializado en "Easy"), INICIALIAR ESTA DE MAS

// ====================> CONSTRUCTOR <====================
public EnemyManager(Playing playing) {
Expand All @@ -39,8 +39,8 @@ public ArrayList<T> getEnemies() {
return enemies;
}

public void setCurretLevel(String curretLevel) {
this.curretLevel = curretLevel;
public void setCurrentLevel(String currentLevel) {
this.currentLevel = currentLevel;
}

// ====================> METODOS <====================
Expand All @@ -54,7 +54,7 @@ public void update(){
public void draw(Graphics g){
for(T alien : enemies){
if(alien.active){
alien.drawHitbox(g);
// alien.drawHitbox(g);
alien.draw(g);
}
}
Expand Down Expand Up @@ -92,8 +92,9 @@ public void move(){
public void loadConfigLevel(Map<String, LevelConfig> levelManager){
// Facil
Map<String, Integer> aliensEasy = new HashMap<>();
aliensEasy.put("alien1", 8);
// aliensEasy.put("alien1", 8);
aliensEasy.put("alien2", 2);
aliensEasy.put("alien3", 10);
levelManager.put("Easy", new LevelConfig(aliensEasy));

// Medio
Expand All @@ -113,7 +114,7 @@ public void loadConfigLevel(Map<String, LevelConfig> levelManager){
public void createAliens() {
enemies.clear(); // Limpiamos la lista de enemigos de niveles anteriores

LevelConfig config = playing.levelManager.get(curretLevel); // Obtenemos la configuración actual
LevelConfig config = playing.levelManager.get(currentLevel); // Obtenemos la configuración actual
Map<String, Integer> alienCounts = config.getAlienTypes(); // Tipos y cantidades de aliens

int i = 0, j = 0; // 'i' para las filas y 'j' para las columnas en cada fila
Expand Down Expand Up @@ -151,9 +152,9 @@ private T spawnAlien(String alienType, int x, int y) {
case "alien2":
alien = (T) new Alien2(x, y);
break;
// case "alien3":
// alien = (T) new Alien3(x, y);
// break;
case "alien3":
alien = (T) new Alien3(x, y);
break;
// case "alien4":
// alien = (T) new Alien4(x, y);
// break;
Expand Down
14 changes: 7 additions & 7 deletions src/gameState/Playing.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class Playing extends State {
public EnemyManager enemyManager;
private BulletManager bulletManager;

public HashMap<String, LevelConfig> levelManager = new HashMap<>();
private String curretLevel = "Easy"; // Nivel actual por defecto
public HashMap<String, LevelConfig> levelManager = new HashMap<>(); // INSTANCIAR EN initClasses
private String currentLevel = "Easy"; // Nivel actual por defecto

// ====================> CONSTRUCTOR <====================
public Playing(Game game) {
Expand All @@ -49,14 +49,14 @@ private void initClasses(){
score = 0;

enemyManager.loadConfigLevel(levelManager);
startLevel(curretLevel); // Iniciar el primer nivel con dificultad "Easy"
startLevel(currentLevel); // Iniciar el primer nivel con dificultad "Easy"
}

/** startLevel() ==> Configurar nivel con la dificultad actual. */
public void startLevel(String dificultad) {
if (levelManager.containsKey(dificultad)) { // Si existe la dificultad
curretLevel = dificultad; // Actualiza el nivel actual
enemyManager.setCurretLevel(dificultad); // Cambia la dificultad en EnemyManager
currentLevel = dificultad; // Actualiza el nivel actual
enemyManager.setCurrentLevel(dificultad); // Cambia la dificultad en EnemyManager
enemyManager.createAliens(); // Crea los aliens con la nueva configuración
score = 0; // Reinicia el puntaje si es necesario
} else {
Expand Down Expand Up @@ -84,9 +84,9 @@ public void update() {
enemyManager.update();

// Ejemplo de lógica para cambiar de nivel basado en el puntaje
if (score >= 100 && curretLevel.equals("Easy")) {
if (score >= 100 && currentLevel.equals("Easy")) {
startLevel("Medium");
} else if (score >= 200 && curretLevel.equals("Medium")) {
} else if (score >= 200 && currentLevel.equals("Medium")) {
startLevel("Hard");
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/utilz/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Constants {
public static class EnemyConstants{
public static final int Alien1 = 0; // Numero para identificar el Alien
public static final int Alien2 = 1; // Numero para identificar el Alien
public static final int Alien3 = 2; // Numero para identificar el Alien

public static final int MOVING = 0; // State = En movimiento
public static final int DEAD = 1; // State = Muerto
Expand Down Expand Up @@ -36,6 +37,13 @@ public static int GetSpriteAmount(int enemy_type, int enemy_state){
case DEAD:
return 1;
}
case Alien3:
switch (enemy_state){
case MOVING:
return 5;
case DEAD:
return 1;
}
}
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions src/utilz/LevelConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

public class LevelConfig {

// ====================> ATRIBUTOS <====================
private Map<String, Integer> alienTypes;

// ====================> CONSTRUCTOR <====================
public LevelConfig(Map<String, Integer> alienTypes) {
this.alienTypes = alienTypes;
}

// ====================> GET | SET <====================
public Map<String, Integer> getAlienTypes() {
return alienTypes;
}
Expand Down
1 change: 1 addition & 0 deletions src/utilz/LoadSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class LoadSave {
public static final String Player_ATLAS = "player_sprites.png";
public static final String Alien1_ATLAS = "alien1_sprites.png";
public static final String Alien2_ATLAS = "alien2_sprites.png";
public static final String Alien3_ATLAS = "alien3_sprites.png";
public static final String MENU_BUTTONS = "button_atlas.png";

// Funcion que retorna esas imagenes
Expand Down

0 comments on commit 36428a4

Please sign in to comment.