Skip to content

Commit

Permalink
can now pick up coins! and fixed upside-down flying!
Browse files Browse the repository at this point in the history
  • Loading branch information
Carter907 committed Nov 17, 2022
1 parent 0e85404 commit 99547ff
Show file tree
Hide file tree
Showing 38 changed files with 52 additions and 34 deletions.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Binary file modified build/libs/JetStrike-1.0-all.jar
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/InputHandler$1.class
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/InputHandler.class
Binary file not shown.
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/actors/Enemy.class
Binary file not shown.
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/actors/Player.class
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/actors/Ship$1.class
Binary file not shown.
Binary file modified core/build/classes/java/main/com/mygdx/game/actors/Ship.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/build/classes/java/main/screens/GameScreen.class
Binary file not shown.
Binary file modified core/build/classes/java/main/screens/HelpScreen$1.class
Binary file not shown.
Binary file modified core/build/classes/java/main/screens/HelpScreen.class
Binary file not shown.
Binary file modified core/build/classes/java/main/screens/SettingsScreen$1.class
Binary file not shown.
Binary file modified core/build/classes/java/main/screens/SettingsScreen.class
Binary file not shown.
Binary file modified core/build/libs/core-1.0.jar
Binary file not shown.
Binary file modified core/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
30 changes: 16 additions & 14 deletions core/src/com/mygdx/game/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public InputHandler(GameScreen game) {

@Override
public boolean keyDown(int keycode) {
System.out.println(keycode + " pressed");
//System.out.println(keycode + " pressed");
this.keycodes.add(keycode);
return keyPressed = true;
}

@Override
public boolean keyUp(int keycode) {
System.out.println(keycode + " released");
//System.out.println(keycode + " released");
this.keycodes.remove(keycode);
return keyPressed = false;
}
Expand All @@ -58,14 +58,14 @@ public boolean keyTyped(char character) {

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
System.out.println("down");
//System.out.println("down");
mousePressing = true;
return true;
}

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
System.out.println("up");
//System.out.println("up");
mousePressing = false;
return true;
}
Expand Down Expand Up @@ -94,9 +94,11 @@ public void handleInput() {
handleMousePosition();
projectiles = findProjectiles();
ships = findShips();
interactables = findInteractables();
mouseDirection = game.getPlayer().getMouseDirection(mouseXUnproj, mouseYUnproj);
updateProjectiles();
checkProjectiles();
checkInteractables();
Enemy.AgroAllEnemies(game.getPlayer().getX(), game.getPlayer().getY(), 3f);

if (!game.getDisplay().getActors().contains(game.getPlayer(), false))
Expand Down Expand Up @@ -124,15 +126,14 @@ public void handleInput() {

}
if (Enemy.enemyHandler.isRandomEnemySpawn()) {
System.out.println(game.getMapRenderer().getMapHeight());
System.out.println(game.getMapRenderer().getMapWidth());

Enemy.enemyHandler.getEnemySpawner().scheduleTask(new Timer.Task() {
@Override
public void run() {
Coin.addCoin(
(float) (Math.random() * game.getMapRenderer().getMapWidth() * 16),
(float) (Math.random() * game.getMapRenderer().getMapHeight() * 16),
Coin.CoinType.NORMAL_COIN);
Coin.CoinType.NORMAL_COIN);
Enemy.spawnEnemy(
(float) (Math.random() * game.getMapRenderer().getMapWidth() * 16),
(float) (Math.random() * game.getMapRenderer().getMapHeight()) * 16);
Expand Down Expand Up @@ -204,22 +205,23 @@ private Array<Interactable> findInteractables() {
}

private void checkInteractables() {
for (Ship ship: ships) {
for (Ship ship : ships) {
for (Interactable intera : interactables) {
ship.contains(intera.getX(), intera.getY());

game.getDisplay().getActors().removeValue(intera, false);
if (ship instanceof Player && intera instanceof Coin) {
Player player = (Player) ship;
player.setCoins(player.getCoins() + ((Coin)intera).getValue());
if (ship.contains(intera.getX(), intera.getY())) {
game.getDisplay().getActors().removeValue(intera, false);
if (ship instanceof Player && intera instanceof Coin) {
Player player = (Player) ship;
player.setCoins(player.getCoins() + ((Coin) intera).getValue());

}
}

}
}


}

private void updateKillLabel(int kills) {
game.getCoinLabel().setText("kill count: " + kills);
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/com/mygdx/game/actors/Enemy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mygdx.game.actors;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Timer;
import screens.GameScreen;
Expand All @@ -23,13 +24,13 @@ private enum EnemyAnimations {
private final Color forceFieldColor = Color.RED;
private final TextureRegion sprite = GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/enemyChoppa");
public Enemy() {
super(0,0, GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/enemyChoppa"));
super(0,0, new TextureRegion(GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/enemyChoppa")));
setForceFieldColor(forceFieldColor);
aggressive = false;
}

public Enemy(float x, float y) {
super(x,y, GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/enemyChoppa"));
super(x,y, new TextureRegion(GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/enemyChoppa")));
setForceFieldColor(forceFieldColor);
aggressive = false;
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/com/mygdx/game/actors/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public GameAnimation getAnimation() {

}
private boolean godMode;

private int coins;
private boolean dead;
private final Color forceFieldColor = Color.GREEN;
Expand All @@ -28,6 +27,7 @@ public Player() {
super(0, 0, GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/ship"));
this.dead = false;
this.godMode = false;
this.setCoins(0);
this.setForceFieldColor(forceFieldColor);
this.setAnimation(PlayerAnimations.JET_EXHAUST.getAnimation());

Expand All @@ -37,6 +37,7 @@ public Player(float x, float y) {
super(x, y, GameScreen.game.getGameStart().getTextureAtlas().findRegion("sprites/ship"));
this.dead = false;
this.godMode = false;
this.setCoins(0);
this.setForceFieldColor(forceFieldColor);
this.setAnimation(PlayerAnimations.JET_EXHAUST.getAnimation());
}
Expand All @@ -57,6 +58,7 @@ private static GameAnimation newAnimation(PlayerAnimations animation) {

public void setCoins(int coins) {
this.coins = coins;
GameScreen.game.getCoinLabel().setText("Coins Collected: " + coins);
}

public int getCoins() {
Expand Down
16 changes: 15 additions & 1 deletion core/src/com/mygdx/game/actors/Ship.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,32 @@ public Ship(float x, float y, TextureRegion sprite) {
this.health = 100;
this.sprite = sprite;
this.setBounds(x, y, sprite.getRegionWidth(), sprite.getRegionHeight());


}

@Override
public void draw(Batch batch, float parentAlpha) {

this.forceField.draw(batch, parentAlpha);
if (animation == null) {
findFlip();
batch.draw(this.sprite, getX(), getY(), getOriginX(),
getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
} else {
batch.draw(this.animation.getKeyFrame(GameScreen.game.getStateTime()), getX(), getY(), getOriginX(),
sprite = this.animation.getKeyFrame(GameScreen.game.getStateTime());
findFlip();
batch.draw(sprite, getX(), getY(), getOriginX(),
getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
}
private void findFlip() {
if (this instanceof Player)
if ((getRotation() > 90 && getRotation() < 270) && !sprite.isFlipY()) {
sprite.flip(false,true);
} else if (!(getRotation() > 90 && getRotation() < 270) && sprite.isFlipY())
sprite.flip(false,true);
}

@Override
public void setWidth(float width) {
Expand All @@ -90,6 +102,8 @@ public void moveShip(float direction, float speed) {

this.setX((float) (this.getX() + speed * Math.cos(Math.toRadians(direction))));
this.setY((float) (this.getY() + speed * Math.sin(Math.toRadians(direction))));
if (direction < 0)
direction = 360 - Math.abs(direction);
this.setRotation(direction);
}

Expand Down
2 changes: 0 additions & 2 deletions core/src/com/mygdx/game/item/projectiles/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void onShipCollision(Ship ship) {
public static void shootProjectile(Ship jet) {

if (GameScreen.game.getStateTime() * 1000 >= jet.getTimeSinceLastShot() + fireRate) {
System.out.println(jet.getRotation());
Projectile rocket = new Bullet(

(float) ((jet.getX() + jet.getOriginX()) + ((jet.getWidth() / 2 + 10) * Math.cos(Math.toRadians(jet.getRotation())))),
Expand All @@ -67,7 +66,6 @@ public static void shootProjectile(Ship jet) {
public static void shootProjectile(Ship jet, float accuracy) {

if (GameScreen.game.getStateTime() * 1000 >= jet.getTimeSinceLastShot() + fireRate) {
System.out.println(jet.getRotation());
Projectile rocket = new Bullet(

(float) ((jet.getX() + jet.getOriginX()) + ((jet.getWidth() / 2 + 10) * Math.cos(Math.toRadians(+jet.getRotation())))),
Expand Down
1 change: 0 additions & 1 deletion core/src/com/mygdx/game/item/projectiles/Rocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void onShipCollision(Ship ship) {
public static void shootProjectile(Ship jet, float accuracy) {

if (GameScreen.game.getStateTime() * 1000 >= jet.getTimeSinceLastShot() + fireRate) {
System.out.println(jet.getRotation());
Projectile rocket = new Rocket(

(float) ((jet.getX() + jet.getOriginX()) + ((jet.getWidth() / 2 + 10) * Math.cos(Math.toRadians(jet.getRotation())))),
Expand Down
18 changes: 10 additions & 8 deletions core/src/screens/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,8 @@ public void show() {
0);
mapRenderer.setSpawnPoint(spawnPoint);

player = new Player();
player.setPosition(spawnPoint.x, spawnPoint.y);
player.setOrigin(Align.center);
player.setForceField(new ForceField(player));

display.addActor(player);


coinLabel = new Label("Coins Collected: " + player.getCoins(), uiSkin);
coinLabel = new Label("Coins Collected: " + 0, uiSkin);
coinLabel.setPosition(ui.getViewport().getScreenWidth()/2f+150, ui.getViewport().getScreenHeight()-coinLabel.getHeight()-15);
coinLabel.setColor(Color.GOLD);
Image coinPng = new Image(new Texture(Gdx.files.internal("images/sprites/coin.png")));
Expand All @@ -106,6 +99,15 @@ public void show() {
deathLabel.setPosition(ui.getViewport().getScreenWidth()/2f-(deathLabel.getWidth()/2f), ui.getViewport().getScreenHeight()/2f-(deathLabel.getHeight()/2));
deathLabel.setVisible(false);

player = new Player();
player.setPosition(spawnPoint.x, spawnPoint.y);
player.setOrigin(Align.center);
player.setForceField(new ForceField(player));

display.addActor(player);




ui.getActors().add(coinLabel);
ui.getActors().add(coinPng);
Expand Down
9 changes: 5 additions & 4 deletions core/src/screens/HelpScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public void show() {
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);

Label label = new Label("JetStrike is a fighter game where you have to destroy enemy \nChoppas! Enemies will spawn near the Button left \nside of the map.\n"
+ "To click in the direction you want to fire in order\n to engage targets. Enemies will fight back \nand have a range at which they can see you", uiSkin);
Label label = new Label("JetStrike is a fighter game where you have to destroy enemy helicopters!\n Enemies spawn randomly around the map.\n"
+ "To click in the direction you want to fire in order to engage targets.\n\n Enemies will fight back \nand have a unlimited range.\n\n" +
"Collect coins around the map. See if you can get to 10 before you die. good luck!", uiSkin);
label.setAlignment(Align.left, Align.left);
label.setColor(1f,1f,0f,1f);

TextButton back = new TextButton("back", uiSkin);
back.addListener(new InputListener() {
Expand All @@ -44,15 +46,14 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, int bu

gameStart.setScreen(new TitleScreen(gameStart));
dispose();
System.out.println("clicked");
return true;
}

});

VerticalGroup ui = new VerticalGroup();
ui.space(40);
ui.setPosition(Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f, Align.center);
ui.setPosition(Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f+label.getHeight()/2, Align.center);
ui.addActor(label);
ui.addActor(back);

Expand Down
1 change: 0 additions & 1 deletion core/src/screens/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, int bu

gameStart.setScreen(new TitleScreen(gameStart));
dispose();
System.out.println("clicked");
return true;
}

Expand Down
Binary file modified desktop/build/libs/desktop-1.0-all.jar
Binary file not shown.
Binary file modified desktop/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.

0 comments on commit 99547ff

Please sign in to comment.