Skip to content

Commit

Permalink
Implemented base code of Turret Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Sep 9, 2023
1 parent 0162cd3 commit cff12b9
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
4 changes: 3 additions & 1 deletion source/core/src/main/com/csse3200/game/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ private Screen newScreen(ScreenType screenType) {
return new StoryScreen(this);
case LEVEL_SELECT:
return new LevelSelectScreen(this);
case TURRET_SELECTION:
return new TurretSelectionScreen(this);
default:
return null;
}
}

public enum ScreenType {
MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT
MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, TURRET_SELECTION
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void create() {
*/
private void onStart() {
logger.info("Start game");
game.setScreen(GdxGame.ScreenType.STORY_SCREEN);
game.setScreen(GdxGame.ScreenType.TURRET_SELECTION);
// game.setScreen(GdxGame.ScreenType.LEVEL_SELECT);
}

Expand Down
3 changes: 3 additions & 0 deletions source/core/src/main/com/csse3200/game/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,7 @@ public int setLayer(int layer) {
return layer;
}

public String getName() {
return this.getClass().getSimpleName();
}
}
10 changes: 10 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/StoryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void render(float delta) {
stage.draw();
}

/**
* Fixes the
* @param width
* @param height
*/
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}

@Override
public void dispose() {
batch.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.csse3200.game.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
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.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.TowerFactory;
import com.csse3200.game.physics.PhysicsService;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;

import java.util.*;

public class TurretSelectionScreen extends ScreenAdapter {

private Stage stage;
private List<String> turretList;
private TextButton confirmButton;

private GdxGame game;

private Set<String> selectedTurrets = new HashSet<>();

public TurretSelectionScreen(GdxGame game) {
this.game = game;
stage = new Stage(new ScreenViewport());
Table table = new Table();

turretList = new ArrayList<>();
// Add turrets to the list

String weaponTower = "test";
String incomeTower = "test2";
turretList.add(weaponTower);
turretList.add(incomeTower);

Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
confirmButton = new TextButton("Continue", skin);
confirmButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(GdxGame.ScreenType.MAIN_GAME);
}
});



for (String turret : turretList) {
TextButton turretButton = new TextButton(turret, skin);
turretButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (selectedTurrets.contains(turret)) {
// Turret is already selected, unselect it
selectedTurrets.remove(turret);
// You can also change the button appearance to indicate unselection
} else {
// Turret is not selected, select it
selectedTurrets.add(turret);
// You can change the button appearance to indicate selection
}
}
});
table.add(turretButton).row();
}
table.add(confirmButton).padBottom(-400).row();

stage.addActor(table);
table.setFillParent(true);
Gdx.input.setInputProcessor(stage);

}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

stage.draw();
}

@Override
public void dispose() {
stage.dispose();
}

}

0 comments on commit cff12b9

Please sign in to comment.