formatting

This commit is contained in:
2026-04-19 14:41:10 -05:00
parent 9f790813bb
commit a803f5e759
31 changed files with 793 additions and 795 deletions

BIN
Amendment.class Normal file

Binary file not shown.

View File

@@ -1,10 +1,8 @@
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
public class Amendment extends Collectable { public class Amendment extends Collectable {
public Amendment(int x, int y, int w, int h) { public Amendment(int x, int y, int w, int h) {
super(x, y, w, h, new ImageIcon("Sprites/Amendment.png")); super(x, y, w, h, new ImageIcon("Sprites/Amendment.png"));
} }
} }

BIN
Brick.class Normal file

Binary file not shown.

BIN
Collectable.class Normal file

Binary file not shown.

BIN
Collidable.class Normal file

Binary file not shown.

View File

@@ -1,6 +1,6 @@
import java.awt.Graphics;
import java.awt.Rectangle; import java.awt.Rectangle;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import java.awt.Graphics;
public class Collidable extends Sprite { public class Collidable extends Sprite {
int x, y, width, height; int x, y, width, height;

BIN
Display.class Normal file

Binary file not shown.

View File

@@ -3,7 +3,7 @@ import javax.swing.*;
public class Display { public class Display {
public static void main(String[] args) { public static void main(String[] args) {
int boardWidth = 800; int boardWidth = 800;
int boardHeight = 800; int boardHeight = 600;
int tileSize = 20; int tileSize = 20;
JFrame game = new JFrame(); JFrame game = new JFrame();
@@ -12,7 +12,6 @@ public class Display {
game.setLocationRelativeTo(null); game.setLocationRelativeTo(null);
game.setResizable(false); game.setResizable(false);
Platformer platformer = new Platformer(boardWidth, boardHeight, tileSize); Platformer platformer = new Platformer(boardWidth, boardHeight, tileSize);
game.add(platformer); game.add(platformer);
game.pack(); game.pack();

BIN
Enemy.class Normal file

Binary file not shown.

View File

@@ -1,5 +1,6 @@
import javax.swing.ImageIcon;
import java.util.*; import java.util.*;
import javax.swing.ImageIcon;
public class Enemy extends Collidable { public class Enemy extends Collidable {
int xVelo, yVelo; int xVelo, yVelo;
boolean alive; boolean alive;
@@ -39,8 +40,7 @@ public class Enemy extends Collidable{
if (c instanceof Tile) { if (c instanceof Tile) {
Tile t = (Tile) c; Tile t = (Tile) c;
// check if tile is below enemy's next position // check if tile is below enemy's next position
if (nextX + this.width > t.x && nextX < t.x + t.width && if (nextX + this.width > t.x && nextX < t.x + t.width && t.y == this.y + this.height) {
t.y == this.y + this.height) {
edgeAhead = false; edgeAhead = false;
break; break;
} }

BIN
Flag.class Normal file

Binary file not shown.

BIN
LevelLoader.class Normal file

Binary file not shown.

View File

@@ -1,16 +1,19 @@
import java.util.*;
import java.io.*; import java.io.*;
import java.util.*;
public class LevelLoader { public class LevelLoader {
static int enemyWidth[] = {0, 31, 20, 20, 20, 20, 20, 29, 29, 20, 20}; static int enemyWidth[] = {0, 31, 20, 20, 20, 20, 20, 29, 29, 20, 20};
static int enemyHeight[] = {0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; static int enemyHeight[] = {0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
public static void load(int tileSize, public static void load(
int tileSize,
ArrayList<Collidable> collidables, ArrayList<Collidable> collidables,
ArrayList<Collectable> collectables, ArrayList<Collectable> collectables,
ArrayList<Enemy> enemies, ArrayList<Enemy> enemies,
Flag flag, Flag flag,
Player player, int level) throws IOException { Player player,
int level)
throws IOException {
collidables.clear(); collidables.clear();
collectables.clear(); collectables.clear();
enemies.clear(); enemies.clear();
@@ -26,12 +29,27 @@ public class LevelLoader {
int x = col * tileSize; int x = col * tileSize;
int y = row * tileSize; int y = row * tileSize;
switch (c) { switch (c) {
case 'B': collidables.add(new Brick(x, y, tileSize, tileSize)); break; case 'B':
case 'Q': collidables.add(new PowerBrick(x, y, tileSize, tileSize, 1)); break; collidables.add(new Brick(x, y, tileSize, tileSize));
case 'A': collectables.add(new Amendment(x, y, tileSize, tileSize)); break; break;
case 'F': flag.setPosition(x, y, tileSize, tileSize); break; case 'Q':
case 'P': player.x = x; player.y = y; player.rect.x = x; player.rect.y = y; break; collidables.add(new PowerBrick(x, y, tileSize, tileSize, 1));
case 'E': enemies.add(new Enemy(x,y,enemyWidth[level],enemyHeight[level],level)); break; break;
case 'A':
collectables.add(new Amendment(x, y, tileSize, tileSize));
break;
case 'F':
flag.setPosition(x, y, tileSize, tileSize);
break;
case 'P':
player.x = x;
player.y = y;
player.rect.x = x;
player.rect.y = y;
break;
case 'E':
enemies.add(new Enemy(x, y, enemyWidth[level], enemyHeight[level], level));
break;
} }
} }
row++; row++;

View File

@@ -31,9 +31,9 @@
................................................................. .................................................................
. .
. .
................................................. ............E.....................................
........BBBBB.............A.................................................................... ........BBBBB.............A....................................................................
.........................QBQQQQQBBBB .........................QBQQQQQBBBB
.................................................................................................... ....................................................................................................
.P.............E..............E...................E............................................................F.. .P............................E...................E............................................................F..
BBBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBBBB...BBBBBBB......................................BBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBBBB...BBBBBBB......................................BBBBBBBBBBBBBBBBBBBB

BIN
Platformer.class Normal file

Binary file not shown.

View File

@@ -1,12 +1,10 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.io.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.*; import javax.swing.*;
public class Platformer extends JPanel implements KeyListener, ActionListener { public class Platformer extends JPanel implements KeyListener, ActionListener {
// constants // constants
@@ -43,7 +41,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
Image heart, emptyHeart, slash, amendmentImg, powerImg, pressRImg, endImg, winImg, titleImg; Image heart, emptyHeart, slash, amendmentImg, powerImg, pressRImg, endImg, winImg, titleImg;
ArrayList<Image> numbers; ArrayList<Image> numbers;
public Platformer(int boardWidth, int boardHeight, int tileSize) { public Platformer(int boardWidth, int boardHeight, int tileSize) {
// setup game // setup game
this.boardWidth = boardWidth; this.boardWidth = boardWidth;
@@ -54,7 +51,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
this.setFocusable(true); this.setFocusable(true);
this.setLayout(null); this.setLayout(null);
pressedKeys = new HashMap<>(); pressedKeys = new HashMap<>();
jumpPressed = false; jumpPressed = false;
gameOver = false; gameOver = false;
@@ -79,14 +75,14 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
cameraY = 0; cameraY = 0;
currentLevel = 0; currentLevel = 0;
numbers = new ArrayList<>(); numbers = new ArrayList<>();
for (int i =0; i < 10; i++) numbers.add((new ImageIcon("Sprites/Numbers/" + i + ".png")).getImage()); for (int i = 0; i < 10; i++)
numbers.add((new ImageIcon("Sprites/Numbers/" + i + ".png")).getImage());
slash = new ImageIcon("Sprites/Numbers/Slash.png").getImage(); slash = new ImageIcon("Sprites/Numbers/Slash.png").getImage();
amendmentImg = new ImageIcon("Sprites/Amendment.png").getImage(); amendmentImg = new ImageIcon("Sprites/Amendment.png").getImage();
powerImg = new ImageIcon("Sprites/Powerup1.png").getImage(); powerImg = new ImageIcon("Sprites/Powerup1.png").getImage();
gameTimer.start(); gameTimer.start();
// if i wanna add a button // if i wanna add a button
/*JButton gameStart = new JButton("Start Game"); /*JButton gameStart = new JButton("Start Game");
gameStart.addActionListener(e -> { gameStart.addActionListener(e -> {
@@ -112,8 +108,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
cameraY = player.y - boardHeight / 2; cameraY = player.y - boardHeight / 2;
// cameraY = Math.max(0, cameraY); // cameraY = Math.max(0, cameraY);
// win // win
allCollected = player.numAmendments >= numAm[currentLevel - 1]; allCollected = player.numAmendments >= numAm[currentLevel - 1];
if (player.collidesWith(flag) && allCollected) { if (player.collidesWith(flag) && allCollected) {
@@ -133,17 +127,17 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
if (Math.abs(player.xVelo) < MAXXVELO) { if (Math.abs(player.xVelo) < MAXXVELO) {
if (isKeyPressed(KeyEvent.VK_D) || isKeyPressed(KeyEvent.VK_RIGHT)) { if (isKeyPressed(KeyEvent.VK_D) || isKeyPressed(KeyEvent.VK_RIGHT)) {
player.xVelo += 1; player.xVelo += 1;
} } else if (isKeyPressed(KeyEvent.VK_A) || isKeyPressed(KeyEvent.VK_LEFT)) {
else if(isKeyPressed(KeyEvent.VK_A) || isKeyPressed(KeyEvent.VK_LEFT)){
player.xVelo -= 1; player.xVelo -= 1;
} }
} }
if (!isKeyPressed(KeyEvent.VK_D) && !isKeyPressed(KeyEvent.VK_RIGHT) && !isKeyPressed(KeyEvent.VK_A) && !isKeyPressed(KeyEvent.VK_LEFT)){ //friction if (!isKeyPressed(KeyEvent.VK_D)
&& !isKeyPressed(KeyEvent.VK_RIGHT)
&& !isKeyPressed(KeyEvent.VK_A)
&& !isKeyPressed(KeyEvent.VK_LEFT)) { // friction
if (player.xVelo > 0) { if (player.xVelo > 0) {
player.xVelo = Math.max(0, player.xVelo - FRICTION); player.xVelo = Math.max(0, player.xVelo - FRICTION);
} } else if (player.xVelo < 0) {
else if (player.xVelo < 0){
player.xVelo = Math.min(0, player.xVelo + FRICTION); player.xVelo = Math.min(0, player.xVelo + FRICTION);
} }
} }
@@ -156,8 +150,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
player.onGround = false; player.onGround = false;
jumpPressed = true; jumpPressed = true;
player.airJumps = 0; player.airJumps = 0;
} } else if (player.curPower == 1 && player.airJumps < 1) {
else if (player.curPower == 1 && player.airJumps < 1){
player.yVelo = -15; player.yVelo = -15;
player.airJumps++; player.airJumps++;
jumpPressed = true; jumpPressed = true;
@@ -173,7 +166,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
} }
// fall out of world // fall out of world
if (player.y > boardHeight){ if (player.y > 2000) {
loadLevel(currentLevel); loadLevel(currentLevel);
player.health--; player.health--;
} }
@@ -197,8 +190,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
player.curPower = pu.id; player.curPower = pu.id;
player.powerTimer = Player.POWER_DURATION; player.powerTimer = Player.POWER_DURATION;
} }
} } else if (c instanceof Amendment) {
else if (c instanceof Amendment){
Amendment am = (Amendment) c; Amendment am = (Amendment) c;
if (player.collidesWith(am)) { if (player.collidesWith(am)) {
player.numAmendments++; player.numAmendments++;
@@ -229,8 +221,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
} }
} }
// Powerup timer // Powerup timer
if (player.curPower > 0) { if (player.curPower > 0) {
player.powerTimer--; player.powerTimer--;
@@ -269,7 +259,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
} }
} }
// update enemies // update enemies
for (Enemy e : enemies) { for (Enemy e : enemies) {
e.patrol(collidables); e.patrol(collidables);
@@ -327,14 +316,14 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
return; return;
} }
g.translate(-cameraX, -cameraY);
if (currentLevel > totalLevels) { if (currentLevel > totalLevels) {
g.drawImage(winImg, boardWidth / 2 - 100, boardHeight / 2 - 50, null); g.drawImage(winImg, boardWidth / 2 - 100, boardHeight / 2 - 50, null);
g.drawImage(pressRImg, boardWidth / 2 - 80, boardHeight / 2 + 60, null); g.drawImage(pressRImg, boardWidth / 2 - 80, boardHeight / 2 + 60, null);
return; return;
} }
g.translate(-cameraX, -cameraY);
player.draw(g); player.draw(g);
for (Collidable c : collidables) c.draw(g); for (Collidable c : collidables) c.draw(g);
for (Collectable c : collectables) c.draw(g); for (Collectable c : collectables) c.draw(g);
@@ -356,7 +345,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
g.translate(cameraX, cameraY); g.translate(cameraX, cameraY);
int modAmt = 2000; int modAmt = 2000;
int curTime = (int) System.currentTimeMillis() % modAmt; int curTime = (int) System.currentTimeMillis() % modAmt;
curTime = Math.abs(curTime); curTime = Math.abs(curTime);
@@ -412,7 +400,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
g.drawImage(numbers.get(numAm[currentLevel - 1]), 390, 10, null); g.drawImage(numbers.get(numAm[currentLevel - 1]), 390, 10, null);
g.drawImage(amendmentImg, 420, 10, null); g.drawImage(amendmentImg, 420, 10, null);
// draw powerup timer // draw powerup timer
if (player.curPower == 1) { if (player.curPower == 1) {
int secs = player.powerTimer / 66; int secs = player.powerTimer / 66;
@@ -463,9 +450,9 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
player.health = 3; player.health = 3;
gameOver = false; gameOver = false;
repaint(); repaint();
return; gameTimer.start();
gameStarted = true;
} }
return;
} }
if (e.getKeyCode() == KeyEvent.VK_O) { if (e.getKeyCode() == KeyEvent.VK_O) {
@@ -483,7 +470,5 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
// dont need // dont need
@Override @Override
public void keyTyped(KeyEvent e){ public void keyTyped(KeyEvent e) {}
}
} }

BIN
Player.class Normal file

Binary file not shown.

View File

@@ -1,5 +1,6 @@
import javax.swing.ImageIcon;
import java.util.*; import java.util.*;
import javax.swing.ImageIcon;
public class Player extends Collidable { public class Player extends Collidable {
static final int JUMP_HEIGHT = 10; static final int JUMP_HEIGHT = 10;
@@ -55,8 +56,7 @@ public class Player extends Collidable {
int tileCenterX = t.x + t.width / 2; int tileCenterX = t.x + t.width / 2;
if (playerCenterX > tileCenterX) { // player on right side of tiile if (playerCenterX > tileCenterX) { // player on right side of tiile
this.x = t.x + t.width; this.x = t.x + t.width;
} } else { // player on left side of tile
else { //player on left side of tile
this.x = t.x - this.width; this.x = t.x - this.width;
} }
this.xVelo = 0; this.xVelo = 0;
@@ -71,8 +71,7 @@ public class Player extends Collidable {
this.y = t.y - this.height; this.y = t.y - this.height;
onGround = true; onGround = true;
airJumps = 0; airJumps = 0;
} } else { // moving up, hit underside of tile
else { // moving up, hit underside of tile
this.y = t.y + t.height; this.y = t.y + t.height;
if (other instanceof PowerBrick) { if (other instanceof PowerBrick) {
PowerBrick pb = (PowerBrick) other; PowerBrick pb = (PowerBrick) other;

BIN
PowerBrick.class Normal file

Binary file not shown.

View File

@@ -1,5 +1,5 @@
import javax.swing.ImageIcon;
import java.util.*; import java.util.*;
import javax.swing.ImageIcon;
public class PowerBrick extends Tile { public class PowerBrick extends Tile {
int id; int id;

BIN
Powerup.class Normal file

Binary file not shown.

View File

@@ -6,7 +6,8 @@ public class Powerup extends Collectable{
public Powerup(int x, int y, int w, int h, int id) { public Powerup(int x, int y, int w, int h, int id) {
super(x, y, w, h, new ImageIcon("Sprites/Powerup" + id + ".png")); super(x, y, w, h, new ImageIcon("Sprites/Powerup" + id + ".png"));
xVelo = 0; yVelo = -7; xVelo = 0;
yVelo = -7;
onGround = false; onGround = false;
this.id = id; this.id = id;
} }

BIN
Projectile.class Normal file

Binary file not shown.

BIN
Sprite.class Normal file

Binary file not shown.

View File

@@ -1,5 +1,5 @@
import javax.swing.ImageIcon;
import java.awt.Image; import java.awt.Image;
import javax.swing.ImageIcon;
public class Sprite { public class Sprite {
ImageIcon icon; ImageIcon icon;

BIN
Tile.class Normal file

Binary file not shown.

View File

@@ -4,7 +4,5 @@ public class Tile extends Collidable {
public Tile(int x, int y, int w, int h, ImageIcon i) { public Tile(int x, int y, int w, int h, ImageIcon i) {
super(x, y, w, h, i); super(x, y, w, h, i);
} }
} }