buttons working

master
GammelJAN 5 years ago
parent be2a195bae
commit a428223e41

@ -119,9 +119,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(screen.getId() == 0) screen = new GameScreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
else if(screen.getId() == 1) screen = new EndScreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
else if(screen.getId() == 2) screen = new MainMenuScreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
ManageButtonEvent(screen.touchDown(screenX,GAME_WORLD_HEIGHT-screenY));
return true;
}
@ -144,4 +142,18 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
public boolean scrolled(int amount) {
return false;
}
public void ManageButtonEvent(int keycode){
switch(keycode){
case 0: //GOTO MAINMENU
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
break;
case 1: //GOTO GAMESCREEN
screen = new GameScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
break;
case 2: //GOTO ENDSCREEN
screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
break;
}
}
}

@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.trs.game.view.Button;
import com.trs.game.view.Screen;
import com.trs.game.view.Text;
@ -12,8 +14,12 @@ public class EndScreen extends Screen {
public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2);
buttons.add(new Button(0,0,0,200,200,"EndScreen", Color.BLACK,Color.WHITE));
buttons.add(new Button(-1,0,0,200,200,"EndScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHREEHREEHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE));
buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));
buttons.add(new Button(2,400,800,200,100, "EndScreen", Color.BLACK,Color.WHITE));
}
@Override
@ -34,6 +40,13 @@ public class EndScreen extends Screen {
@Override
public int touchDown(int x, int y) {
Rectangle r = new Rectangle(x,y,1,1);
for(Button button : buttons){
if(Intersector.overlaps(r, button.getRect())){
System.out.println(button.getId());
return button.getId();
}
}
return 0;
}

@ -14,8 +14,12 @@ public class GameScreen extends Screen {
public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1);
buttons.add(new Button(0,0,0,200,200,"GameScreen", Color.BLACK,Color.WHITE));
buttons.add(new Button(-1,0,0,200,200,"GameScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHREEHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE));
buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));
buttons.add(new Button(2,400,800,200,100, "EndScreen", Color.BLACK,Color.WHITE));
}
@Override

@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.trs.game.view.Button;
import com.trs.game.view.Screen;
import com.trs.game.view.Text;
@ -12,8 +14,12 @@ public class MainMenuScreen extends Screen {
public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0);
buttons.add(new Button(0,0,0,200,200,"MainMenuScreen", Color.BLACK,Color.WHITE));
buttons.add(new Button(-1,0,0,200,200,"MainMenuScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE));
buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));
buttons.add(new Button(2,400,800,200,100, "EndScreen", Color.BLACK,Color.WHITE));
}
@Override
@ -34,6 +40,13 @@ public class MainMenuScreen extends Screen {
@Override
public int touchDown(int x, int y) {
Rectangle r = new Rectangle(x,y,1,1);
for(Button button : buttons){
if(Intersector.overlaps(r, button.getRect())){
System.out.println(button.getId());
return button.getId();
}
}
return 0;
}

@ -10,6 +10,7 @@ public class DesktopLauncher {
config.width = 1600;
config.height = 900;
config.samples = 8;
config.resizable = false;
new LwjglApplication(new Controller(), config);
}
}

Loading…
Cancel
Save