Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 2 progress merge #268

Merged
merged 4 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions source/core/assets/images/ui/buttons/determination_mono_22.fnt

Large diffs are not rendered by default.

203 changes: 105 additions & 98 deletions source/core/assets/images/ui/buttons/glass.atlas

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion source/core/assets/images/ui/buttons/glass.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ com.badlogic.gdx.graphics.g2d.BitmapFont: {
markupEnabled: false
flip: false
}
determination_mono_22: {
file: determination_mono_22.fnt
scaledSize: -1
markupEnabled: false
flip: false
}
determination_mono_32: {
file: determination_mono_32.fnt
scaledSize: -1
Expand Down Expand Up @@ -402,7 +408,7 @@ com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
fontColor: White
}
small: {
font: determination_mono_18_bold
font: determination_mono_22
fontColor: White
}
}
Expand Down
Binary file modified source/core/assets/images/ui/buttons/glass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ private void onExit() {
private void onLose() {
game.setScreen(GdxGame.ScreenType.LOSING_SCREEN);
}

// private void onWin() { game.setScreen(GdxGame.ScreenType.WIN_SCREEN);} // TODO : Uncomment this once win screen implemented
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
Expand Down Expand Up @@ -33,6 +34,12 @@ public class MainGameDisplay extends UIComponent {
private Sound click;
private Sound openSound;
private GdxGame game;
private Array<TowerType> towers = new Array<>();
private ImageButton tower1;
private ImageButton tower2;
private ImageButton tower3;
private ImageButton tower4;
private ImageButton tower5;

/**
* The constructor for the display
Expand Down Expand Up @@ -77,7 +84,7 @@ private void addActors() {
};

// Fetch the selected tower types if set
Array<TowerType> towers = new Array<>();
towers = new Array<>();

for (TowerType tower : ServiceLocator.getTowerTypes()) {
towers.add(tower);
Expand All @@ -99,12 +106,11 @@ private void addActors() {
// Update the centrally located towerTypes list -
ServiceLocator.setTowerTypes(towers);

// Create the buttons - TODO This needs overhauling to pretty buttons
TextButton tower1 = ButtonFactory.createButton(towers.get(0).getTowerName());
TextButton tower2 = ButtonFactory.createButton(towers.get(1).getTowerName());
TextButton tower3 = ButtonFactory.createButton(towers.get(2).getTowerName());
TextButton tower4 = ButtonFactory.createButton(towers.get(3).getTowerName());
TextButton tower5 = ButtonFactory.createButton(towers.get(4).getTowerName());
tower1 = new ImageButton(skin, towers.get(0).getSkinName());
tower2 = new ImageButton(skin, towers.get(1).getSkinName());
tower3 = new ImageButton(skin, towers.get(2).getSkinName());
tower4 = new ImageButton(skin, towers.get(3).getSkinName());
tower5 = new ImageButton(skin, towers.get(4).getSkinName());
TextButton pauseBtn = ButtonFactory.createButton("Pause");

// Spawns a pause menu when the button is pressed.
Expand All @@ -127,8 +133,15 @@ public void clicked(InputEvent event, float x, float y) {
TowerType selected = ServiceLocator.getCurrencyService().getTower();
if (selected == towers.get(0) ) {
ServiceLocator.getCurrencyService().setTowerType(null);
tower1.setChecked(false);

} else {
ServiceLocator.getCurrencyService().setTowerType(towers.get(0));
tower1.setChecked(true);
tower2.setChecked(false);
tower3.setChecked(false);
tower4.setChecked(false);
tower5.setChecked(false);
}
click.play(0.4f);
}
Expand All @@ -145,8 +158,14 @@ public void clicked(InputEvent event, float x, float y) {
TowerType selected = ServiceLocator.getCurrencyService().getTower();
if (selected == towers.get(1) ) {
ServiceLocator.getCurrencyService().setTowerType(null);
tower2.setChecked(false);
} else {
ServiceLocator.getCurrencyService().setTowerType(towers.get(1));
tower1.setChecked(false);
tower2.setChecked(true);
tower3.setChecked(false);
tower4.setChecked(false);
tower5.setChecked(false);
}
click.play(0.4f);
}
Expand All @@ -155,41 +174,82 @@ public void clicked(InputEvent event, float x, float y) {
tower2.addListener(tower2Tooltip);

tower3.addListener(
new ChangeListener() {
new ClickListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 3 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(2));
public void clicked(InputEvent event, float x, float y) {

TowerType selected = ServiceLocator.getCurrencyService().getTower();
if (selected == towers.get(2)) {
ServiceLocator.getCurrencyService().setTowerType(null);
tower3.setChecked(false);
} else {
ServiceLocator.getCurrencyService().setTowerType(towers.get(2));
if (ServiceLocator.getCurrencyService().getScrap().getAmount()
>= Integer.parseInt(towers.get(2).getPrice())) {
tower3.setDisabled(false);
tower1.setChecked(false);
tower2.setChecked(false);
tower3.setChecked(true);
tower4.setChecked(false);
tower5.setChecked(false);
} else {
tower3.setDisabled(true);
}
}
click.play(0.4f);
}
});

TextTooltip tower3Tooltip = new TextTooltip(towers.get(3).getDescription(), getSkin());
tower3.addListener(tower3Tooltip);

tower4.addListener(
new ChangeListener() {
new ClickListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 4 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(3));
public void clicked(InputEvent event, float x, float y) {

TowerType selected = ServiceLocator.getCurrencyService().getTower();
if (selected == towers.get(3)) {
ServiceLocator.getCurrencyService().setTowerType(null);
tower4.setChecked(false);
} else {
ServiceLocator.getCurrencyService().setTowerType(towers.get(3));
tower1.setChecked(false);
tower2.setChecked(false);
tower3.setChecked(false);
tower4.setChecked(true);
tower5.setChecked(false);
}
click.play(0.4f);
}
});
TextTooltip tower4Tooltip = new TextTooltip(towers.get(3).getDescription(), getSkin());
tower4.addListener(tower4Tooltip);

tower5.addListener(
new ChangeListener() {
new ClickListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 5 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(4));
public void clicked(InputEvent event, float x, float y) {

TowerType selected = ServiceLocator.getCurrencyService().getTower();
if (selected == towers.get(4)) {
ServiceLocator.getCurrencyService().setTowerType(null);
tower5.setChecked(false);
} else {
ServiceLocator.getCurrencyService().setTowerType(towers.get(4));
tower1.setChecked(false);
tower2.setChecked(false);
tower3.setChecked(false);
tower4.setChecked(false);
tower5.setChecked(true);
}
click.play(0.4f);
}
});
TextTooltip tower5Tooltip = new TextTooltip(towers.get(4).getDescription(), getSkin());
tower5.addListener(tower5Tooltip);

// Scale all the tower build buttons down
// Add all buttons to their respective tables and position them
towerTable.add(tower1).padRight(10f);
towerTable.add(tower2).padRight(10f);
Expand All @@ -210,6 +270,41 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
@Override
public void draw(SpriteBatch batch) {
// draw is handled by the stage
if (ServiceLocator.getCurrencyService().getTower() == null) {

tower1.setChecked(false);
tower2.setChecked(false);
tower3.setChecked(false);
tower4.setChecked(false);
tower5.setChecked(false);
}
int balance = ServiceLocator.getCurrencyService().getScrap().getAmount();
if (Integer.parseInt(towers.get(0).getPrice()) > balance) {
tower1.setDisabled(true);
} else {
tower1.setDisabled(false);
}
if (Integer.parseInt(towers.get(1).getPrice()) > balance) {
tower2.setDisabled(true);
} else {
tower2.setDisabled(false);
}
if (Integer.parseInt(towers.get(2).getPrice()) > balance) {
tower3.setDisabled(true);
} else {
tower3.setDisabled(false);
}
if (Integer.parseInt(towers.get(3).getPrice()) > balance) {
tower4.setDisabled(true);
} else {
tower4.setDisabled(false);
}
if (Integer.parseInt(towers.get(4).getPrice()) > balance) {
tower5.setDisabled(true);
} else {
tower5.setDisabled(false);
}

}

@Override
Expand All @@ -221,6 +316,7 @@ public float getZIndex() {
public void dispose() {
buttonTable.clear();
towerTable.clear();
unloadSounds();
super.dispose();
}

Expand All @@ -233,4 +329,8 @@ public void loadSounds() {
click = ServiceLocator.getResourceService().getAsset(sounds[0], Sound.class);
openSound = ServiceLocator.getResourceService().getAsset(sounds[1], Sound.class);
}

public void unloadSounds() {
ServiceLocator.getResourceService().unloadAssets(sounds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class EngineerCombatTask extends DefaultTask implements PriorityTask {
// weaponCapacity is the number of shots fired before the engineer has to reload
private static final int weaponCapacity = 10;
private int shotsFired = 0; // Tracks the number of shots fired in the current cycle

private Vector2 engineerPosition = new Vector2(10, 50); // Placeholder value for the Engineer's position.

private final Vector2 maxRangePosition = new Vector2();
private PhysicsEngine physics;
private GameTime timeSource;
Expand Down Expand Up @@ -68,7 +67,8 @@ public EngineerCombatTask(float maxRange) {
public void start() {
super.start();
// Set the tower's coordinates
this.engineerPosition = owner.getEntity().getCenterPosition();
// Placeholder value for the Engineer's position.
Vector2 engineerPosition = owner.getEntity().getCenterPosition();
this.maxRangePosition.set(engineerPosition.x + maxRange, engineerPosition.y);
// Default to idle mode
owner.getEntity().getEvents().trigger(IDLE_RIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.areas.ForestGameArea;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.EntityService;
import com.csse3200.game.entities.factories.TowerFactory;
Expand All @@ -23,7 +22,7 @@
* DropInputComponent
*/
public class BuildInputComponent extends InputComponent {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);
private static final Logger logger = LoggerFactory.getLogger(BuildInputComponent.class);
private final EntityService entityService;
private final Camera camera;
private final String[] sounds = {
Expand All @@ -33,7 +32,6 @@ public class BuildInputComponent extends InputComponent {
private Sound buildSound;
private Sound errorSound;
private Array<TowerType> towers = new Array<>();
private Array<TowerType> defaultTowers = new Array<>();
private boolean multipleTowerBuild = false;

/**
Expand All @@ -46,14 +44,15 @@ public BuildInputComponent(Camera camera) {
loadSounds();
towers.addAll(ServiceLocator.getTowerTypes());

logger.debug("selected towers in buildInputComponent are " + towers);
logger.debug(String.format("selected towers in buildInputComponent are %s", towers));
TowerType[] defaultTowerTypes = {
TowerType.TNT,
TowerType.DROID,
TowerType.INCOME,
TowerType.WALL,
TowerType.WEAPON
};
Array<TowerType> defaultTowers = new Array<>();
defaultTowers.addAll(defaultTowerTypes);

if (towers.isEmpty()) {
Expand Down Expand Up @@ -85,17 +84,17 @@ public Camera getCamera() {
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {

Vector3 worldCoordinates = new Vector3((float) screenX , (float) screenY, 0);
Vector3 worldCoordinates = new Vector3(screenX , screenY, 0);
getCamera().unproject(worldCoordinates); // translate from screen to world coordinates
Vector2 cursorPosition = new Vector2(worldCoordinates.x, worldCoordinates.y);

// determine if the tile is unoccupied
boolean tileOccupied = entityService.entitiesInTile((int)cursorPosition.x, (int)cursorPosition.y);
logger.debug("Tile is occupied: " + tileOccupied );
logger.debug(String.format("Tile is occupied: %s", tileOccupied));

// check that no entities are occupying the tile
if (!tileOccupied) {
logger.debug("spawning a tower at {}, {}", cursorPosition.x, cursorPosition.y);
logger.debug(String.format("spawning a tower at %f, %f", cursorPosition.x, cursorPosition.y));
return buildTower((int)cursorPosition.x, (int)cursorPosition.y);
} else {
return false;
Expand Down Expand Up @@ -145,6 +144,7 @@ public boolean keyUp(int keycode) {
* @param keycode one of the constants in {@link Input.Keys}
* @return true if the multipleBuild key is down, otherwise false
*/
@Override
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.CONTROL_LEFT) {
multipleTowerBuild = true;
Expand Down Expand Up @@ -186,9 +186,7 @@ public boolean buildTower(int x, int y) {
};
// build the selected tower
newTower.setPosition(x, y);
EntityService entityService;

entityService = ServiceLocator.getEntityService();
if (entityService == null){
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

public class PhysicsLayer {
public static final short NONE = 0;
public static final short DEFAULT = (1 << 0);
public static final short ENGINEER = (1 << 1);
public static final short BOMBSHIP = (1 << 1);
public static final short BOMBSHIP = ENGINEER;
// Terrain obstacle, e.g. trees
public static final short OBSTACLE = (1 << 2);
// NPC (Non-Playable Character) colliders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.w3c.dom.Text;

import static com.badlogic.gdx.scenes.scene2d.ui.Table.Debug.table;
import static com.csse3200.game.ui.UIComponent.getSkin;

/**
* The game screen where you can choose a planet to play on.
Expand All @@ -46,6 +47,7 @@ public class LevelSelectScreen extends ScreenAdapter {
private Stage stage;
private AnimatedText text;
private BitmapFont font;
private static final String defaultFont = "determination_mono_32";

private Sprite background;
private String[] bgm = {
Expand All @@ -60,7 +62,7 @@ public class LevelSelectScreen extends ScreenAdapter {
private static final String BG_PATH = "planets/background.png";

public LevelSelectScreen(GdxGame game) {
font = new BitmapFont();
font = getSkin().getFont(defaultFont);
text = new AnimatedText(INTRO_TEXT, font, 0.05f);
this.game = game;

Expand Down
Loading
Loading