formatting
This commit is contained in:
BIN
Amendment.class
Normal file
BIN
Amendment.class
Normal file
Binary file not shown.
@@ -1,10 +1,8 @@
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
|
||||
public class Amendment extends Collectable {
|
||||
|
||||
public Amendment(int x, int y, int w, int h) {
|
||||
super(x, y, w, h, new ImageIcon("Sprites/Amendment.png"));
|
||||
}
|
||||
|
||||
}
|
||||
BIN
Brick.class
Normal file
BIN
Brick.class
Normal file
Binary file not shown.
BIN
Collectable.class
Normal file
BIN
Collectable.class
Normal file
Binary file not shown.
BIN
Collidable.class
Normal file
BIN
Collidable.class
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class Collidable extends Sprite {
|
||||
int x, y, width, height;
|
||||
|
||||
BIN
Display.class
Normal file
BIN
Display.class
Normal file
Binary file not shown.
@@ -3,7 +3,7 @@ import javax.swing.*;
|
||||
public class Display {
|
||||
public static void main(String[] args) {
|
||||
int boardWidth = 800;
|
||||
int boardHeight = 800;
|
||||
int boardHeight = 600;
|
||||
int tileSize = 20;
|
||||
|
||||
JFrame game = new JFrame();
|
||||
@@ -12,7 +12,6 @@ public class Display {
|
||||
game.setLocationRelativeTo(null);
|
||||
game.setResizable(false);
|
||||
|
||||
|
||||
Platformer platformer = new Platformer(boardWidth, boardHeight, tileSize);
|
||||
game.add(platformer);
|
||||
game.pack();
|
||||
|
||||
BIN
Enemy.class
Normal file
BIN
Enemy.class
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
import javax.swing.ImageIcon;
|
||||
import java.util.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Enemy extends Collidable {
|
||||
int xVelo, yVelo;
|
||||
boolean alive;
|
||||
@@ -39,8 +40,7 @@ public class Enemy extends Collidable{
|
||||
if (c instanceof Tile) {
|
||||
Tile t = (Tile) c;
|
||||
// check if tile is below enemy's next position
|
||||
if (nextX + this.width > t.x && nextX < t.x + t.width &&
|
||||
t.y == this.y + this.height) {
|
||||
if (nextX + this.width > t.x && nextX < t.x + t.width && t.y == this.y + this.height) {
|
||||
edgeAhead = false;
|
||||
break;
|
||||
}
|
||||
|
||||
BIN
Flag.class
Normal file
BIN
Flag.class
Normal file
Binary file not shown.
BIN
LevelLoader.class
Normal file
BIN
LevelLoader.class
Normal file
Binary file not shown.
@@ -1,16 +1,19 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class LevelLoader {
|
||||
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};
|
||||
|
||||
public static void load(int tileSize,
|
||||
public static void load(
|
||||
int tileSize,
|
||||
ArrayList<Collidable> collidables,
|
||||
ArrayList<Collectable> collectables,
|
||||
ArrayList<Enemy> enemies,
|
||||
Flag flag,
|
||||
Player player, int level) throws IOException {
|
||||
Player player,
|
||||
int level)
|
||||
throws IOException {
|
||||
collidables.clear();
|
||||
collectables.clear();
|
||||
enemies.clear();
|
||||
@@ -26,12 +29,27 @@ public class LevelLoader {
|
||||
int x = col * tileSize;
|
||||
int y = row * tileSize;
|
||||
switch (c) {
|
||||
case 'B': collidables.add(new Brick(x, y, tileSize, tileSize)); break;
|
||||
case 'Q': collidables.add(new PowerBrick(x, y, tileSize, tileSize, 1)); 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;
|
||||
case 'B':
|
||||
collidables.add(new Brick(x, y, tileSize, tileSize));
|
||||
break;
|
||||
case 'Q':
|
||||
collidables.add(new PowerBrick(x, y, tileSize, tileSize, 1));
|
||||
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++;
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
.................................................................
|
||||
.
|
||||
.
|
||||
.................................................
|
||||
............E.....................................
|
||||
........BBBBB.............A....................................................................
|
||||
.........................QBQQQQQBBBB
|
||||
....................................................................................................
|
||||
.P.............E..............E...................E............................................................F..
|
||||
.P............................E...................E............................................................F..
|
||||
BBBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBB...BBBBBBBBBBBBBBBBBBB...BBBBBBB......................................BBBBBBBBBBBBBBBBBBBB
|
||||
BIN
Platformer.class
Normal file
BIN
Platformer.class
Normal file
Binary file not shown.
@@ -1,12 +1,10 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class Platformer extends JPanel implements KeyListener, ActionListener {
|
||||
|
||||
// constants
|
||||
@@ -43,7 +41,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
Image heart, emptyHeart, slash, amendmentImg, powerImg, pressRImg, endImg, winImg, titleImg;
|
||||
ArrayList<Image> numbers;
|
||||
|
||||
|
||||
public Platformer(int boardWidth, int boardHeight, int tileSize) {
|
||||
// setup game
|
||||
this.boardWidth = boardWidth;
|
||||
@@ -54,7 +51,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
this.setFocusable(true);
|
||||
this.setLayout(null);
|
||||
|
||||
|
||||
pressedKeys = new HashMap<>();
|
||||
jumpPressed = false;
|
||||
gameOver = false;
|
||||
@@ -79,14 +75,14 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
cameraY = 0;
|
||||
currentLevel = 0;
|
||||
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();
|
||||
amendmentImg = new ImageIcon("Sprites/Amendment.png").getImage();
|
||||
powerImg = new ImageIcon("Sprites/Powerup1.png").getImage();
|
||||
|
||||
gameTimer.start();
|
||||
|
||||
|
||||
// if i wanna add a button
|
||||
/*JButton gameStart = new JButton("Start Game");
|
||||
gameStart.addActionListener(e -> {
|
||||
@@ -112,8 +108,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
cameraY = player.y - boardHeight / 2;
|
||||
// cameraY = Math.max(0, cameraY);
|
||||
|
||||
|
||||
|
||||
// win
|
||||
allCollected = player.numAmendments >= numAm[currentLevel - 1];
|
||||
if (player.collidesWith(flag) && allCollected) {
|
||||
@@ -133,17 +127,17 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
if (Math.abs(player.xVelo) < MAXXVELO) {
|
||||
if (isKeyPressed(KeyEvent.VK_D) || isKeyPressed(KeyEvent.VK_RIGHT)) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -156,8 +150,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
player.onGround = false;
|
||||
jumpPressed = true;
|
||||
player.airJumps = 0;
|
||||
}
|
||||
else if (player.curPower == 1 && player.airJumps < 1){
|
||||
} else if (player.curPower == 1 && player.airJumps < 1) {
|
||||
player.yVelo = -15;
|
||||
player.airJumps++;
|
||||
jumpPressed = true;
|
||||
@@ -173,7 +166,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
}
|
||||
|
||||
// fall out of world
|
||||
if (player.y > boardHeight){
|
||||
if (player.y > 2000) {
|
||||
loadLevel(currentLevel);
|
||||
player.health--;
|
||||
}
|
||||
@@ -197,8 +190,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
player.curPower = pu.id;
|
||||
player.powerTimer = Player.POWER_DURATION;
|
||||
}
|
||||
}
|
||||
else if (c instanceof Amendment){
|
||||
} else if (c instanceof Amendment) {
|
||||
Amendment am = (Amendment) c;
|
||||
if (player.collidesWith(am)) {
|
||||
player.numAmendments++;
|
||||
@@ -229,8 +221,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Powerup timer
|
||||
if (player.curPower > 0) {
|
||||
player.powerTimer--;
|
||||
@@ -269,7 +259,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update enemies
|
||||
for (Enemy e : enemies) {
|
||||
e.patrol(collidables);
|
||||
@@ -327,14 +316,14 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
return;
|
||||
}
|
||||
|
||||
g.translate(-cameraX, -cameraY);
|
||||
|
||||
if (currentLevel > totalLevels) {
|
||||
g.drawImage(winImg, boardWidth / 2 - 100, boardHeight / 2 - 50, null);
|
||||
g.drawImage(pressRImg, boardWidth / 2 - 80, boardHeight / 2 + 60, null);
|
||||
return;
|
||||
}
|
||||
|
||||
g.translate(-cameraX, -cameraY);
|
||||
|
||||
player.draw(g);
|
||||
for (Collidable c : collidables) 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);
|
||||
|
||||
|
||||
int modAmt = 2000;
|
||||
int curTime = (int) System.currentTimeMillis() % modAmt;
|
||||
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(amendmentImg, 420, 10, null);
|
||||
|
||||
|
||||
// draw powerup timer
|
||||
if (player.curPower == 1) {
|
||||
int secs = player.powerTimer / 66;
|
||||
@@ -463,9 +450,9 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
player.health = 3;
|
||||
gameOver = false;
|
||||
repaint();
|
||||
return;
|
||||
gameTimer.start();
|
||||
gameStarted = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_O) {
|
||||
@@ -483,7 +470,5 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||
|
||||
// dont need
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e){
|
||||
|
||||
}
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
}
|
||||
BIN
Player.class
Normal file
BIN
Player.class
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
import javax.swing.ImageIcon;
|
||||
import java.util.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Player extends Collidable {
|
||||
|
||||
static final int JUMP_HEIGHT = 10;
|
||||
@@ -55,8 +56,7 @@ public class Player extends Collidable {
|
||||
int tileCenterX = t.x + t.width / 2;
|
||||
if (playerCenterX > tileCenterX) { // player on right side of tiile
|
||||
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.xVelo = 0;
|
||||
@@ -71,8 +71,7 @@ public class Player extends Collidable {
|
||||
this.y = t.y - this.height;
|
||||
onGround = true;
|
||||
airJumps = 0;
|
||||
}
|
||||
else { // moving up, hit underside of tile
|
||||
} else { // moving up, hit underside of tile
|
||||
this.y = t.y + t.height;
|
||||
if (other instanceof PowerBrick) {
|
||||
PowerBrick pb = (PowerBrick) other;
|
||||
|
||||
BIN
PowerBrick.class
Normal file
BIN
PowerBrick.class
Normal file
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
import javax.swing.ImageIcon;
|
||||
import java.util.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class PowerBrick extends Tile {
|
||||
int id;
|
||||
|
||||
BIN
Powerup.class
Normal file
BIN
Powerup.class
Normal file
Binary file not shown.
@@ -6,7 +6,8 @@ public class Powerup extends Collectable{
|
||||
|
||||
public Powerup(int x, int y, int w, int h, int id) {
|
||||
super(x, y, w, h, new ImageIcon("Sprites/Powerup" + id + ".png"));
|
||||
xVelo = 0; yVelo = -7;
|
||||
xVelo = 0;
|
||||
yVelo = -7;
|
||||
onGround = false;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
BIN
Projectile.class
Normal file
BIN
Projectile.class
Normal file
Binary file not shown.
BIN
Sprite.class
Normal file
BIN
Sprite.class
Normal file
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.Image;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Sprite {
|
||||
ImageIcon icon;
|
||||
|
||||
BIN
Tile.class
Normal file
BIN
Tile.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user