Skip to content
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
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Java CI to create and upload release on pull request

permissions:
contents: write

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
build-number: ${GITHUB_RUN_NUMBER}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Install Maven
uses: stCarolas/setup-maven@v4
with:
maven-version: '3.9.4'

- run: mvn clean package -DskipTests

- name: Prepare Artifacts
run: |
mkdir -p staging
mv target/platformer-java-1.0-SNAPSHOT.jar target/platformer-java-${{ env.build-number }}.jar
cp target/*.jar staging

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: Package
path: staging/
retention-days: 1

- uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ github.run_number }}"
title: "Automated Build ${{ github.run_number }}"
prerelease: true
files: staging/*.jar
35 changes: 35 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.drewm</groupId>
<artifactId>platformer-java</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>com.drewm.main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,30 @@
<version>2.15.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.drewm.main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
57 changes: 50 additions & 7 deletions src/main/java/com/drewm/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class Player extends Entity {
private int health = maxHealth;
private float speed = Constants.PLAYER_STARTING_SPEED;

private int healthUpgradeLvl = 1;
private int speedUpgradeLvl = 1;
private int jumpUpgradeLvl = 1;
private int timeUpgradeLvl = 1;

public boolean invincible = false;
private long invincibilityStartTime = 0;
private final int INVINCIBILITY_DURATION = 500;
Expand Down Expand Up @@ -203,24 +208,61 @@ public void takeDamage(int amount) {
}
}

public int getHealthUpgradeCost() {
return 50*this.healthUpgradeLvl;
}

public int getSpeedUpgradeCost() {
return (int) Math.pow(2, this.speedUpgradeLvl);
}

public int getJumpUpgradeCost() {
return (int) Math.pow(3, this.jumpUpgradeLvl);
}

public int getTimeUpgradeCost() {
return 10*this.timeUpgradeLvl;
}

public int getCoinMultiplierUpgradeCost() {
return 20*this.coinMultiplier;
}

public int getAmmoUpgradeCost() {
return 30*this.pistol.getMaxBullets();
}

public void upgradeHealth() {
if (spendCoins(5)) {
if (spendCoins(getHealthUpgradeCost())) {
maxHealth += 1;
health = maxHealth;
this.healthBar = updateHudText("Health: ", health);
this.healthUpgradeLvl++;
}

}

/**
* speed: 1, 2, 5, 8, 10, 20, 60, 400, 800, 1000
* jump: 3, 10, 15, 20, 25, 50, 75, 100, 150, 200
* double jump: 600exp
* time: 10, 15(8sec), 20(14sec), 25(20sec), 30(26sec), 35(32sec), 40, 45(44sec), 50(50sec), 60(56sec), 70(62sec), 80(68sec), 90(74sec), 100(80sec), 120(86sec), 140(92sec), 160(98sec), 180(104sec)
* health: 50, 150, 200, 300
* multi: 20, 30, 40, 60, 80, 100, 150, 200, 250, 300
* ammo: 20, 40, 70, 100, 150, 200, 250, 300, 400
*/

public void upgradeSpeed() {
if (spendCoins(5)) {
if (spendCoins(getSpeedUpgradeCost())) {
speed += 0.5f;
this.speedUpgradeLvl++;
}
}

public void upgradeJumpPower() {
if (spendCoins(5)) {
jumpPower += 0.75f;
if (spendCoins(getJumpUpgradeCost())) {
jumpPower += 2.0f;
this.jumpUpgradeLvl++;
}
}

Expand All @@ -231,16 +273,17 @@ public void buyPistol() {
}

public void buyAmmo() {
if (ownsPistol && this.spendCoins(1)) {
if (ownsPistol && this.spendCoins(getAmmoUpgradeCost())) {
this.pistol.setMaxBullets(pistol.getMaxBullets()+1);
this.pistol.setBulletsRemaining(pistol.getBulletsRemaining()+1);
}
}

public void buyTimeUpgrade() {
if (spendCoins(10)) {
if (spendCoins(getTimeUpgradeCost())) {
this.maxTimeLimitSeconds += 10;
this.currentTimeLeft = this.maxTimeLimitSeconds;
this.timeUpgradeLvl++;
}
}

Expand All @@ -259,7 +302,7 @@ public void earnCoins(int amount) {
}

public void buyCoinMultiplier() {
if (spendCoins(20)) this.coinMultiplier++;
if (spendCoins(getCoinMultiplierUpgradeCost())) this.coinMultiplier++;
}

public int getCoinMultiplier() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/drewm/gamestates/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ private BufferedImage createTitleText(String text) {
}

private void loadBtns() {
btns[0] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight(), Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Play", () -> { Gamestate.state = Gamestate.PLAYING; });
btns[1] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight() + Constants.BTN_HEIGHT_SCALED + 10, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Options", () -> { Gamestate.state = Gamestate.OPTIONS; });
btns[2] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight() + (Constants.BTN_HEIGHT_SCALED + 10) * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Quit", () -> { Gamestate.state = Gamestate.QUIT; });
btns[0] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight(), Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Play", () -> { Gamestate.state = Gamestate.PLAYING; });
btns[1] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight() + Constants.BTN_HEIGHT_SCALED + 10, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Options", () -> { Gamestate.state = Gamestate.OPTIONS; });
btns[2] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, this.titleText.getHeight() + (Constants.BTN_HEIGHT_SCALED + 10) * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Quit", () -> { Gamestate.state = Gamestate.QUIT; });
}
@Override
public void update() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/drewm/gamestates/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ private BufferedImage createTitleText(String text) {
}

private void loadBtns() {
btns[0] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, window.getIsFullscreen() ? "Disable Fullscreen" : "Enable Fullscreen", () -> {
btns[0] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> window.getIsFullscreen() ? "Disable Fullscreen" : "Enable Fullscreen", () -> {
window.setIsFullscreen(!window.getIsFullscreen());
loadBtns();
});
btns[1] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.BTN_HEIGHT_SCALED * 2 + 10, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Back", () -> { Gamestate.state = Gamestate.MENU; });
btns[1] = new Button((Constants.SCREEN_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.BTN_HEIGHT_SCALED * 2 + 10, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Back", () -> { Gamestate.state = Gamestate.MENU; });
}
@Override
public void update() {
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/drewm/gamestates/Playing.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@ public class Playing implements Statemethods {
public Door currentDoor = null;

private final Modal pauseMenu = new Modal("Game Paused", new Button[]{
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Resume", () -> {
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Resume", () -> {
isPaused = false;
}),
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + Constants.BTN_HEIGHT_SCALED * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Main Menu", () -> {
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + Constants.BTN_HEIGHT_SCALED * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Main Menu", () -> {
Gamestate.state = Gamestate.MENU;
resetLevel();
})
});
private final Modal buyMenu = new Modal("Buy Menu", new Button[]{
new Button(1, "Health Upgrade [5 coins]", () -> {
new Button(1, () -> "Health Upgrade [" + player.getHealthUpgradeCost() + "coins]", () -> {
player.upgradeHealth();
}, () -> player.getCoins() >= 5),
new Button(2, "Speed Upgrade [5 coins]", () -> {
}, () -> player.getCoins() >= player.getHealthUpgradeCost()),
new Button(2, () -> "Speed Upgrade [" + player.getSpeedUpgradeCost() + "coins]", () -> {
player.upgradeSpeed();
}, () -> player.getCoins() >= 5),
new Button(3, "Jump Power Upgrade [5 coins]", () -> {
}, () -> player.getCoins() >= player.getSpeedUpgradeCost()),
new Button(3, () -> "Jump Power Upgrade [" + player.getJumpUpgradeCost() + "coins]", () -> {
player.upgradeJumpPower();
}, () -> player.getCoins() >= 5),
new Button(4, "Buy Pistol [5 coins]", () -> {
}, () -> player.getCoins() >= player.getJumpUpgradeCost()),
new Button(4, () -> "Buy Pistol [" + 5 + "coins]", () -> {
player.buyPistol();
}, () -> player.getCoins() >= 5),
new Button(5, "Buy Ammo [1 coin]", () -> {
new Button(5, () -> "Buy Ammo [" + player.getAmmoUpgradeCost() + "coin]", () -> {
player.buyAmmo();
}, () -> player.ownsPistol && player.getCoins() >= 1),
new Button(6, "Time upgrade [10 coins]", () -> {
}, () -> player.ownsPistol && player.getCoins() >= player.getAmmoUpgradeCost()),
new Button(6, () -> "Time upgrade [" + player.getTimeUpgradeCost() + " coins]", () -> {
player.buyTimeUpgrade();
}, () -> player.getCoins() >= 10),
new Button(7, "Coin multiplier upgrade [20 coins]", () -> {
}, () -> player.getCoins() >= player.getTimeUpgradeCost()),
new Button(7, () -> "Coin multiplier upgrade [" + player.getCoinMultiplierUpgradeCost() + " coins]", () -> {
player.buyCoinMultiplier();
}, () -> player.getCoins() >= 20)
}, () -> player.getCoins() >= player.getCoinMultiplierUpgradeCost())
});
private final Modal winScreen = new Modal("You Win!", new Button[]{
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + 30 + Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Restart", this::resetLevel),
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + 40 + Constants.BTN_HEIGHT_SCALED * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, "Main Menu", () -> {
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + 30 + Constants.BTN_HEIGHT_SCALED, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Restart", this::resetLevel),
new Button(Constants.MODAL_BG_X + (Constants.MODAL_BG_WIDTH - Constants.BTN_WIDTH_SCALED) / 2, Constants.MODAL_BG_Y + 40 + Constants.BTN_HEIGHT_SCALED * 2, Constants.BTN_WIDTH_SCALED, Constants.BTN_HEIGHT_SCALED, () -> "Main Menu", () -> {
Gamestate.state = Gamestate.MENU;
resetLevel();
})
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/drewm/objects/FloatingMine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class FloatingMine {
private int spriteCounter = 0;
private int spriteNum = 0;
private float speed = 1f;
private final boolean showHitbox = false;

public FloatingMine(float startX, float startY, float endX, float endY, Playing playing) {
this.playing = playing;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void draw(Graphics2D g2) {
screenY + Constants.TILE_SIZE * 2 > 0 &&
screenY < Constants.SCREEN_HEIGHT) {
g2.drawImage(spriteFrames[spriteNum], (int) screenX, (int) screenY, spriteFrames[0].getWidth() * Constants.SCALE, spriteFrames[0].getHeight() * Constants.SCALE, null);
g2.drawRect((int) screenX, (int) screenY, spriteFrames[0].getWidth() * Constants.SCALE, spriteFrames[0].getHeight() * Constants.SCALE);
if (showHitbox) g2.drawRect((int) screenX, (int) screenY, spriteFrames[0].getWidth() * Constants.SCALE, spriteFrames[0].getHeight() * Constants.SCALE);
}
}

Expand Down
Loading
Loading