Skip to content

Commit

Permalink
RankingMenu V1 to Main
Browse files Browse the repository at this point in the history
RankingState_Created
  • Loading branch information
TvConIdeas authored Nov 15, 2024
2 parents 4295691 + f8f92b6 commit 48acdc6
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 8 deletions.
Binary file added res/ranking_background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions src/gameState/Ranking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package gameState;

import main.Game;
import ui.ClassButton;
import utilz.LoadSave;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

public class Ranking extends State implements Statemethods{
// ====================> ATRIBUTOS <====================
private ClassButton back;

// ====================> CONSTRUCTOR <====================
public Ranking(Game game) {
super(game);
back = new ClassButton(Game.GAME_WIDTH- 80,Game.GAME_HEIGHT- 120,1);
}

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

// ====================> METODOS <====================
@Override
public void update() {
back.update();
}

@Override
public void draw(Graphics g) {
// Dibuja fondo y Interfaz
BufferedImage pincel = LoadSave.GetSpritesAtlas(LoadSave.RANKING_BACKGROUD);
g.drawImage(pincel, 0, 0, Game.GAME_WIDTH, Game.GAME_HEIGHT, null);

// Dibuja los nombres de los Ranking

back.draw(g);
}

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

@Override
public void mouseReleased(MouseEvent e) {
if (isIn(e, back)) {
if (back.isMousePressed()) {
GameState.state = GameState.MENU;
}
}
back.resetBools();
}

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

@Override
public void keyPressed(KeyEvent e) {

}

@Override
public void keyReleased(KeyEvent e) {

}

@Override
public void mouseClicked(MouseEvent e) {

}
}
5 changes: 5 additions & 0 deletions src/gameState/State.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gameState;

import main.Game;
import ui.ClassButton;
import ui.MenuButton;
import utilz.IRenderable;

Expand Down Expand Up @@ -29,4 +30,8 @@ public Game getGame() {
public boolean isIn(MouseEvent e, MenuButton mb){ // Method auxiliar que verifica si el mouse está dentro de la hitbox
return mb.getHitbox().contains(e.getX(), e.getY());
}

public boolean isIn(MouseEvent e, ClassButton b) {
return b.getHitbox().contains(e.getX(), e.getY());
}
}
9 changes: 9 additions & 0 deletions src/inputs/MouseInputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public void mouseMoved(MouseEvent e) {
case MENU:
gamePanel.getGame().getMenu().mouseMoved(e);
break;
case RANKING:
gamePanel.getGame().getRanking().mouseMoved(e);
break;
case PLAYING:
gamePanel.getGame().getPlaying().mouseMoved(e);
break;
Expand All @@ -55,6 +58,9 @@ public void mousePressed(MouseEvent e) {
case MENU:
gamePanel.getGame().getMenu().mousePressed(e);
break;
case RANKING:
gamePanel.getGame().getRanking().mousePressed(e);
break;
case PLAYING:
gamePanel.getGame().getPlaying().mousePressed(e);
break;
Expand All @@ -72,6 +78,9 @@ public void mouseReleased(MouseEvent e) {
case PLAYING:
gamePanel.getGame().getPlaying().mouseReleased(e);
break;
case RANKING:
gamePanel.getGame().getRanking().mouseReleased(e);
break;
default:
break;
}
Expand Down
25 changes: 17 additions & 8 deletions src/main/Game.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main;

import java.awt.Graphics;
import java.util.Random;

import gameState.*;
import json.JSONUserManager;
Expand Down Expand Up @@ -28,10 +29,11 @@ public class Game implements Runnable, IRenderable {
private final int UPS_SET = 100; // Updates Per Second

// GameStates
private Playing playing;
private Menu menu;
private Register register;
private Login login;
private Register register;
private Menu menu;
private Playing playing;
private Ranking ranking;
private Option option;
protected User userInGame;

Expand Down Expand Up @@ -80,17 +82,21 @@ public void setUserInGame(User user){
userInGame = user;
}

public Ranking getRanking() {
return ranking;
}
public User getUserInGame(){
return userInGame;
}

// ====================> METODOS <====================
/** initClasses() ==> Instancia las clases. */
private void initClasses(){
login = new Login(this);
register = new Register(this);
menu = new Menu(this);
playing = new Playing(this);
register = new Register(this);
login = new Login(this);
ranking = new Ranking(this);
option = new Option(this);
userInGame = new User();
jsonUserManager = new JSONUserManager();
Expand Down Expand Up @@ -120,9 +126,9 @@ public void update(){
break;
case OPTIONS:
option.update();
break;
case RANKING: //ranking.update() [no existe aun] break;
System.out.println(userInGame);
break;
case RANKING:
ranking.update();
break;
case QUIT:
default:
Expand All @@ -147,6 +153,9 @@ public void draw(Graphics g){
case PLAYING:
playing.draw(g);
break;
case RANKING:
ranking.draw(g);
break;
case OPTIONS:
option.draw(g);
break;
Expand Down
1 change: 1 addition & 0 deletions src/utilz/LoadSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class LoadSave {
public static final String REGISTER_BACKGROUD = "register_background.jpg";
public static final String MENU_BACKGROUD = "menu_background.jpg";
public static final String OPTION_BACKGROUD = "option_background.jpg";
public static final String RANKING_BACKGROUD = "ranking_background.jpg";
public static final String TITLE_GAME = "501_title.png";
public static final String PAUSE_MENU = "pause_menu.png";

Expand Down

0 comments on commit 48acdc6

Please sign in to comment.