Skip to content
Snippets Groups Projects
Commit a7c99809 authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

#22 Added stage

parent fa970bba
No related branches found
No related tags found
1 merge request!8Resolve "ViewTournament-, ViewHighscore-, CreateJoinTournament-, State Classes"
...@@ -5,31 +5,47 @@ import com.badlogic.gdx.Gdx; ...@@ -5,31 +5,47 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.states.CreateJoinTournamentState;
import com.gameware.game.states.GameStateManager;
public class GameWare extends ApplicationAdapter { public class GameWare extends ApplicationAdapter {
SpriteBatch batch; private SpriteBatch batch;
Texture img; private GameStateManager gsm;
public static final int WIDTH = 480; public static final int WIDTH = 480;
public static final int HEIGHT = 800; public static final int HEIGHT = 800;
public static final String TITLE = "WackyWare!";
public static final String skinFilePath = "glassy/skin/glassy-ui.json";
private static GameWare instance = null;
public static GameWare getInstance(){
if( instance == null){
instance = new GameWare();
}
return instance;
}
@Override @Override
public void create () { public void create () {
gsm = new GameStateManager();
batch = new SpriteBatch(); batch = new SpriteBatch();
img = new Texture("badlogic.jpg"); //music = Gdx.audio.newMusic(Gdx.files.internal(("music.mp3")));
//music.setLooping(true);
//music.setVolume(0.1f);
//music.play();
gsm.push(new CreateJoinTournamentState(gsm));
} }
@Override @Override
public void render () { public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1); Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin(); gsm.update(Gdx.graphics.getDeltaTime());
batch.draw(img, 0, 0); gsm.render(batch);
batch.end();
} }
@Override @Override
public void dispose () { public void dispose () {
batch.dispose(); batch.dispose();
img.dispose();
} }
} }
package com.gameware.game.sprites; package com.gameware.game.sprites;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
public abstract class Sprite { public abstract class Sprite {
...@@ -12,7 +13,7 @@ public abstract class Sprite { ...@@ -12,7 +13,7 @@ public abstract class Sprite {
public abstract void reset(); public abstract void reset();
public abstract Object report(); public abstract Object report();
public abstract void draw(); public abstract void draw(SpriteBatch sb);
public abstract void update(); public abstract void update();
public abstract void dispose(); public abstract void dispose();
......
...@@ -3,50 +3,71 @@ package com.gameware.game.states; ...@@ -3,50 +3,71 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
public class CreateJoinTournamentState extends State { public class CreateJoinTournamentState extends State {
private Button backBtn;
private Vector3 androidClick; private Vector3 androidClick;
private Stage stage;
private Table table;
protected CreateJoinTournamentState(GameStateManager gsm) { private int spacingOnBottom = Gdx.graphics.getHeight()/15;
private float fontScaleX = 3f;
private float fontScaleY = 3f;
private String backBtnText = "Back";
public CreateJoinTournamentState(GameStateManager gsm) {
super(gsm); super(gsm);
cam.setToOrtho(false, GameWare.WIDTH, GameWare.HEIGHT); stage = new Stage();
backBtn = new Button(); Gdx.input.setInputProcessor(stage);
} Skin skin = new Skin(Gdx.files.internal(GameWare.skinFilePath));
skin.getFont("font").getData().setScale(fontScaleX,fontScaleY);
cam.setToOrtho(false, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
table = new Table();
table.setFillParent(true);
table.row();
TextButton loginBtn = new TextButton(backBtnText, skin);
loginBtn.addListener(new ClickListener() {
@Override @Override
protected void handleInput() { public void clicked(InputEvent e, float x, float y){
if(Gdx.input.justTouched()){ handleBtnClick();
androidClick = cam.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(),0));
if(backBtn.isBtnClicked(androidClick.x,androidClick.y)){
gsm.push(new MenuState(gsm));
} }
});
table.add(loginBtn);
stage.addActor(table);
} }
@Override
protected void handleInput() {
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
handleInput(); stage.act(dt);
backBtn.update(dt); }
cam.update(); }
@Override @Override
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
sb.setProjectionMatrix(cam.combined); stage.draw();
sb.begin();
//sb.draw(bg, cam.position.x - (cam.viewportWidth / 2),0,HeliGame_2.WIDTH,HeliGame_2.HEIGHT);
//sb.draw(heli.getSprite(),heli.getPosition().x,heli.getPosition().y);
//sb.draw(skull.getTexture(),skull.getPosition().x,skull.getPosition().y);
//posText.getFont().draw(sb, posText.getText(), 10, HeliGame_2.HEIGHT - 10);
sb.end();
} }
@Override @Override
public void dispose() { public void dispose() {
backBtn.dispose(); stage.dispose();
} }
@Override @Override
...@@ -58,4 +79,8 @@ public class CreateJoinTournamentState extends State { ...@@ -58,4 +79,8 @@ public class CreateJoinTournamentState extends State {
public Object report() { public Object report() {
return this; return this;
} }
private void handleBtnClick(){
gsm.set(new MenuState(gsm));
}
} }
package com.gameware.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MenuState extends State{
protected MenuState(GameStateManager gsm) {
super(gsm);
System.out.println("Du er i menu state :0");
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
}
@Override
public void render(SpriteBatch sb) {
}
@Override
public void dispose() {
}
@Override
public void reset() {
}
@Override
public Object report() {
return null;
}
private void optionsBtnClick(){
}
private void multiBtnClick(){
}
private void singleBtnClick(){
}
private void highscoreBtnClick(){
}
}
...@@ -3,51 +3,69 @@ package com.gameware.game.states; ...@@ -3,51 +3,69 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
public class ViewHighScoreState extends State { public class ViewHighScoreState extends State {
private Button backBtn;
private Vector3 androidClick; private Vector3 androidClick;
private Stage stage;
private Table table;
private int spacingOnBottom = Gdx.graphics.getHeight()/15;
private float fontScaleX = 3f;
private float fontScaleY = 3f;
private String backBtnText = "Back";
protected ViewHighScoreState(GameStateManager gsm) { protected ViewHighScoreState(GameStateManager gsm) {
super(gsm); super(gsm);
cam.setToOrtho(false, GameWare.WIDTH, GameWare.HEIGHT); stage = new Stage();
backBtn = new Button(); Gdx.input.setInputProcessor(stage);
} Skin skin = new Skin(Gdx.files.internal(GameWare.skinFilePath));
skin.getFont("font").getData().setScale(fontScaleX,fontScaleY);
cam.setToOrtho(false, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
table = new Table();
table.setFillParent(true);
table.row();
TextButton loginBtn = new TextButton(backBtnText, skin);
loginBtn.addListener(new ClickListener() {
@Override @Override
protected void handleInput() { public void clicked(InputEvent e, float x, float y){
if(Gdx.input.justTouched()){ handleBtnClick();
androidClick = cam.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(),0));
if(backBtn.isBtnClicked(androidClick.x,androidClick.y)){
gsm.push(new MenuState(gsm));
} }
});
table.add(loginBtn);
stage.addActor(table);
} }
@Override
protected void handleInput() {
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
handleInput(); stage.act(dt);
backBtn.update(dt);
cam.update();
} }
@Override @Override
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
sb.setProjectionMatrix(cam.combined); stage.draw();
sb.begin();
//sb.draw(bg, cam.position.x - (cam.viewportWidth / 2),0,HeliGame_2.WIDTH,HeliGame_2.HEIGHT);
//sb.draw(heli.getSprite(),heli.getPosition().x,heli.getPosition().y);
//sb.draw(skull.getTexture(),skull.getPosition().x,skull.getPosition().y);
//posText.getFont().draw(sb, posText.getText(), 10, HeliGame_2.HEIGHT - 10);
sb.end();
} }
@Override @Override
public void dispose() { public void dispose() {
backBtn.dispose(); stage.dispose();
} }
@Override @Override
...@@ -59,4 +77,8 @@ public class ViewHighScoreState extends State { ...@@ -59,4 +77,8 @@ public class ViewHighScoreState extends State {
public Object report() { public Object report() {
return this; return this;
} }
private void handleBtnClick(){
gsm.set(new CreateJoinTournamentState(gsm));
}
} }
\ No newline at end of file
...@@ -4,51 +4,69 @@ import com.badlogic.gdx.Gdx; ...@@ -4,51 +4,69 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
public class ViewTournamentState extends State { public class ViewTournamentState extends State {
private Button backBtn;
private Vector3 androidClick; private Vector3 androidClick;
private Stage stage;
private Table table;
private int spacingOnBottom = Gdx.graphics.getHeight()/15;
private float fontScaleX = 3f;
private float fontScaleY = 3f;
private String backBtnText = "Back";
protected ViewTournamentState(GameStateManager gsm) { protected ViewTournamentState(GameStateManager gsm) {
super(gsm); super(gsm);
cam.setToOrtho(false, GameWare.WIDTH, GameWare.HEIGHT); stage = new Stage();
backBtn = new Button(); Gdx.input.setInputProcessor(stage);
} Skin skin = new Skin(Gdx.files.internal(GameWare.skinFilePath));
skin.getFont("font").getData().setScale(fontScaleX,fontScaleY);
cam.setToOrtho(false, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
table = new Table();
table.setFillParent(true);
table.row();
TextButton loginBtn = new TextButton(backBtnText, skin);
loginBtn.addListener(new ClickListener() {
@Override @Override
protected void handleInput() { public void clicked(InputEvent e, float x, float y){
if(Gdx.input.justTouched()){ handleBtnClick();
androidClick = cam.unproject(new Vector3(Gdx.input.getX(),Gdx.input.getY(),0));
if(backBtn.isBtnClicked(androidClick.x,androidClick.y)){
gsm.push(new CreateJoinTournamentState(gsm));
} }
});
table.add(loginBtn);
stage.addActor(table);
} }
@Override
protected void handleInput() {
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
handleInput(); stage.act(dt);
backBtn.update(dt);
cam.update();
} }
@Override @Override
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
sb.setProjectionMatrix(cam.combined); stage.draw();
sb.begin();
//sb.draw(bg, cam.position.x - (cam.viewportWidth / 2),0,HeliGame_2.WIDTH,HeliGame_2.HEIGHT);
//sb.draw(heli.getSprite(),heli.getPosition().x,heli.getPosition().y);
//sb.draw(skull.getTexture(),skull.getPosition().x,skull.getPosition().y);
//posText.getFont().draw(sb, posText.getText(), 10, HeliGame_2.HEIGHT - 10);
sb.end();
} }
@Override @Override
public void dispose() { public void dispose() {
backBtn.dispose(); stage.dispose();
} }
@Override @Override
...@@ -60,4 +78,8 @@ public class ViewTournamentState extends State { ...@@ -60,4 +78,8 @@ public class ViewTournamentState extends State {
public Object report() { public Object report() {
return this; return this;
} }
private void handleBtnClick(){
gsm.set(new MenuState(gsm));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment