Skip to content

Commit

Permalink
MenuPauseComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
TvConIdeas committed Nov 14, 2024
1 parent 1a3c8f3 commit f7443fb
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 83 deletions.
Binary file removed res/button_atlas.png
Binary file not shown.
File renamed without changes
Binary file modified res/pause_menu.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 res/resume_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/ui/ClassButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public void setHitbox(Rectangle hitbox) {
}

// ====================> METODOS <====================
private void initBounds() {
public void initBounds() {
hitbox = new Rectangle(xPos - xOffsetCenter, yPos, PB_SIZE, PB_SIZE);
}

// Cargamos las imagenes del boton
private void loadImgs() {
public void loadImgs() {
imgs = new BufferedImage[3];
BufferedImage temp = LoadSave.GetSpritesAtlas(LoadSave.PAUSE_BUTTONS);
for (int i = 0; i < imgs.length; i++)
Expand Down
29 changes: 24 additions & 5 deletions src/ui/PauseOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class PauseOverlay {
private int bgX, bgY, bgW, bgH;
private ClassButton[] buttons = new ClassButton[2];

private ClassButton menuB, replayB;
//private ResumeButton resumeB;
private ResumeButton resumeB;

// ====================> CONSTRUCTOR <====================
public PauseOverlay(Playing playing) {
Expand All @@ -35,29 +34,35 @@ private void loadButtons(){

buttons[0] = new ClassButton(replayX, bY + bgY, 0);
buttons[1] = new ClassButton(menuX, bY + bgY, 1);
//resumeB = new ResumeButton(resumeX,bY,0);
resumeB = new ResumeButton(resumeX, bY + bgY + 95);
}

private void resetButtons() {
for(ClassButton cb : buttons) { // El for, comprueba si el mouse está dentro del área del botón
cb.resetBools();
}
resumeB.resetBools();
}

private void loadBackground() {
backgroundImg = LoadSave.GetSpritesAtlas(LoadSave.PAUSE_MENU);
bgW = (int) (backgroundImg.getWidth() * Game.SCALE);
bgH = (int) (backgroundImg.getHeight() * Game.SCALE);
bgX = Game.GAME_WIDTH / 2 - bgW / 2;
bgY = (int) (70 * Game.SCALE);
bgY = (int) (130 * Game.SCALE);
}

private boolean isIn(MouseEvent e, ClassButton b) {
return b.getHitbox().contains(e.getX(), e.getY());
}

private boolean isIn(MouseEvent e, ResumeButton b) {
return b.getHitbox().contains(e.getX(), e.getY());
}

// ====================> METODOS COMUNES <====================
public void update() {
resumeB.update();
for(ClassButton cb : buttons) {
cb.update();
}
Expand All @@ -66,13 +71,17 @@ public void update() {
public void draw(Graphics g) {
// Fondo
g.drawImage(backgroundImg, bgX, bgY, bgW, bgH, null);

resumeB.draw(g);
for(ClassButton cb : buttons) {
cb.draw(g);
}
}

public void mousePressed(MouseEvent e) {
if(isIn(e, resumeB)) {
resumeB.setMousePressed(true);
}

for(ClassButton cb : buttons) {
if(isIn(e, cb)) {
cb.setMousePressed(true);
Expand All @@ -90,14 +99,24 @@ public void mouseReleased(MouseEvent e) {
playing.endLevel();
GameState.state = GameState.MENU;
}
} else if (isIn(e, resumeB)) {
if (resumeB.isMousePressed()) {
playing.setPaused(false);
}
}
resetButtons();
}

public void mouseMoved(MouseEvent e) {
resumeB.setMouseOver(false);
if (isIn(e, resumeB)) {
resumeB.setMouseOver(true); // Comprueba si el mouse está dentro del botón
}

for (ClassButton cb : buttons)
cb.setMouseOver(false); //Reinicia el estado `mouseOver` de todos los botones


for (ClassButton cb : buttons)
if (isIn(e, cb)) {
cb.setMouseOver(true); // Comprueba si el mouse está dentro del botón
Expand Down
155 changes: 80 additions & 75 deletions src/ui/ResumeButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,84 @@
import java.awt.image.BufferedImage;

import static utilz.Constants.UI.Buttons.*;
import static utilz.Constants.UI.PauseButtons.PB_DEFAULT_SIZE;
import static utilz.Constants.UI.PauseButtons.PB_SIZE;

//public class ResumeButton extends ClassButton {
//
// // ====================> ATRIBUTOS <====================
// private BufferedImage[] imgs;
// private int xOffsetCenter = B_WIDTH / 2; // El centro a lo ancho
// private int rowIndex, index;
// private boolean mouseOver, mousePressed;
//
// // ====================> CONSTRUCTOR <====================
// public ResumeButton(int x, int y, int rowIndex) {
// super(x, y, B_WIDTH, B_HEIGHT);
// this.rowIndex = rowIndex;
// loadImgs();
// }
//
// // ====================> GET | SET <====================
// public int getRowIndex() {
// return rowIndex;
// }
//
// public void setRowIndex(int rowIndex) {
// this.rowIndex = rowIndex;
// }
//
// public int getIndex() {
// return index;
// }
//
// public void setIndex(int index) {
// this.index = index;
// }
//
// public boolean isMouseOver() {
// return mouseOver;
// }
//
// public void setMouseOver(boolean mouseOver) {
// this.mouseOver = mouseOver;
// }
//
// public boolean isMousePressed() {
// return mousePressed;
// }
//
// public void setMousePressed(boolean mousePressed) {
// this.mousePressed = mousePressed;
// }
//
// // ====================> METODOS <====================
// public void update() {
// index = 0;
// if (mouseOver)
// index = 1;
// if (mousePressed)
// index = 2;
//
// }
//
// public void draw(Graphics g) {
// g.drawImage(imgs[index], x - xOffsetCenter, y, B_WIDTH, B_HEIGHT, null);
// }
//
// private void loadImgs() {
// BufferedImage temp = LoadSave.GetSpritesAtlas(LoadSave.RESUME_BUTTONS);
// imgs = new BufferedImage[3];
// for (int i = 0; i < imgs.length; i++)
// imgs[i] = temp.getSubimage(i * B_WIDTH_DEFAULT, rowIndex * B_HEIGHT_DEFAULT, B_WIDTH_DEFAULT, B_HEIGHT_DEFAULT);
// }
//
// public void resetBools() {
// mouseOver = false;
// mousePressed = false;
// }
//
//}
public class ResumeButton{
// ====================> ATRIBUTOS <====================
private int xPos, yPos, index;
private int xOffsetCenter = B_WIDTH / 2;
private boolean mouseOver, mousePressed;
private BufferedImage[][] imgs;
private Rectangle hitbox;

// ====================> CONSTRUCTOR <====================
public ResumeButton(int xPos, int yPos) {
this.xPos = xPos;
this.yPos = yPos;
loadImgs();
initBounds();
}

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


public Rectangle getHitbox() {
return hitbox;
}

public void setHitbox(Rectangle hitbox) {
this.hitbox = hitbox;
}

public boolean isMouseOver() {
return mouseOver;
}

public void setMouseOver(boolean mouseOver) {
this.mouseOver = mouseOver;
}

public boolean isMousePressed() {
return mousePressed;
}

public void setMousePressed(boolean mousePressed) {
this.mousePressed = mousePressed;
}

// ====================> METODOS <====================
public void initBounds() {
hitbox = new Rectangle(xPos - xOffsetCenter, yPos, B_WIDTH, B_HEIGHT);
}

// Cargamos las imagenes del boton
public void loadImgs() {
BufferedImage temp = LoadSave.GetSpritesAtlas(LoadSave.RESUME_BUTTONS);

imgs = new BufferedImage[1][3];
for (int j = 0; j < imgs.length; j++)
for (int i = 0; i < imgs[j].length; i++)
imgs[j][i] = temp.getSubimage(i * B_WIDTH_DEFAULT, j*B_HEIGHT_DEFAULT, B_WIDTH_DEFAULT, B_HEIGHT_DEFAULT);
}

// Dibujamos el Boton
public void draw(Graphics g) {
g.drawImage(imgs[0][index], xPos - xOffsetCenter, yPos, B_WIDTH, B_HEIGHT, null);
}

// Index, controla cuál de las imágenes del botón se muestra, según el estado del mouse.
public void update() {
index = 0; // Inactivo
if (mouseOver)
index = 1; // Sobre el Boton
if (mousePressed)
index = 2; // Presiona el Boton
}

// Reseteamos los booleanos a False
public void resetBools() {
mouseOver = false;
mousePressed = false;
}
}
7 changes: 6 additions & 1 deletion src/utilz/LoadSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
public class LoadSave {

// Constante con cada Sprite que utilizemos
// Entitys
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 Alien4_ATLAS = "alien4_sprites.png";

// Overlays / Fondos
public static final String PLAYING_BACKGROUD = "playing_background.jpg";
public static final String MENU_BUTTONS = "button_atlas.png";
public static final String PAUSE_MENU = "pause_menu.png";

// Buttons
public static final String ADMIN_BUTTONS = "admin_button.png";
public static final String MENU_BUTTONS = "menu_button.png";
public static final String PAUSE_BUTTONS = "pause_button.png";
public static final String RESUME_BUTTONS = "resume_button.png";

Expand Down

0 comments on commit f7443fb

Please sign in to comment.