added game over and win screens
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import java.awt.Rectangle;
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Collectable extends Collidable{
|
public class Collectable extends Collidable{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
public class Display {
|
public class Display {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import javax.swing.ImageIcon;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import java.util.Random;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.awt.Graphics;
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.time.LocalTime;
|
|
||||||
|
|
||||||
|
|
||||||
public class Platformer extends JPanel implements KeyListener, ActionListener{
|
public class Platformer extends JPanel implements KeyListener, ActionListener{
|
||||||
@@ -43,7 +40,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
boolean allCollected;
|
boolean allCollected;
|
||||||
boolean gameOver;
|
boolean gameOver;
|
||||||
boolean gameStarted;
|
boolean gameStarted;
|
||||||
Image heart,emptyHeart,slash,amendmentImg,powerImg,startImg;
|
Image heart,emptyHeart,slash,amendmentImg,powerImg,pressRImg,startImg,endImg,winImg;
|
||||||
ArrayList<Image> numbers;
|
ArrayList<Image> numbers;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,6 +65,9 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
heart = new ImageIcon("Sprites/Hearts/heart.png").getImage();
|
heart = new ImageIcon("Sprites/Hearts/heart.png").getImage();
|
||||||
emptyHeart = new ImageIcon("Sprites/Hearts/emptyHeart.png").getImage();
|
emptyHeart = new ImageIcon("Sprites/Hearts/emptyHeart.png").getImage();
|
||||||
startImg = new ImageIcon("Sprites/start.png").getImage();
|
startImg = new ImageIcon("Sprites/start.png").getImage();
|
||||||
|
endImg = new ImageIcon("Sprites/end.png").getImage();
|
||||||
|
pressRImg = new ImageIcon("Sprites/PressR.png").getImage();
|
||||||
|
winImg = new ImageIcon("Sprites/win.png").getImage();
|
||||||
gameTimer = new Timer(15,this);
|
gameTimer = new Timer(15,this);
|
||||||
player = new Player(-20,0,tileSize,tileSize);
|
player = new Player(-20,0,tileSize,tileSize);
|
||||||
collidables = new ArrayList<>();
|
collidables = new ArrayList<>();
|
||||||
@@ -105,6 +105,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
|
|
||||||
//gameloop
|
//gameloop
|
||||||
public void gameLoop(){
|
public void gameLoop(){
|
||||||
|
if (currentLevel > totalLevels) return;
|
||||||
//camera
|
//camera
|
||||||
cameraX = player.x - boardWidth / 2;
|
cameraX = player.x - boardWidth / 2;
|
||||||
cameraX = Math.max(0, cameraX);
|
cameraX = Math.max(0, cameraX);
|
||||||
@@ -121,6 +122,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
if (currentLevel > totalLevels) {
|
if (currentLevel > totalLevels) {
|
||||||
gameTimer.stop();
|
gameTimer.stop();
|
||||||
System.out.println("You win!");
|
System.out.println("You win!");
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
loadLevel(currentLevel);
|
loadLevel(currentLevel);
|
||||||
}
|
}
|
||||||
@@ -318,8 +320,21 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
|
|
||||||
//draw function
|
//draw function
|
||||||
public void draw(Graphics g){
|
public void draw(Graphics g){
|
||||||
|
//gameover screen
|
||||||
|
if (gameOver){
|
||||||
|
g.drawImage(endImg, boardWidth/2 - 100, boardHeight/2 - 150, null);
|
||||||
|
g.drawImage(pressRImg, boardWidth/2 - 80, boardHeight/2, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g.translate(-cameraX, -cameraY);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -331,7 +346,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
int amOnes = player.numAmendments % 10;
|
int amOnes = player.numAmendments % 10;
|
||||||
int amTens = player.numAmendments / 10;
|
int amTens = player.numAmendments / 10;
|
||||||
|
|
||||||
if (currentLevel > 0 && !gameOver && player.numAmendments < numAm[currentLevel-1]){
|
if (currentLevel > 0 && player.numAmendments < numAm[currentLevel-1]){
|
||||||
if (amTens > 0) g.drawImage(numbers.get(amTens),flag.x-20,flag.y-30,null);
|
if (amTens > 0) g.drawImage(numbers.get(amTens),flag.x-20,flag.y-30,null);
|
||||||
g.drawImage(numbers.get(amOnes),flag.x+5,flag.y-30,null);
|
g.drawImage(numbers.get(amOnes),flag.x+5,flag.y-30,null);
|
||||||
g.drawImage(slash,flag.x+28,flag.y-32,null);
|
g.drawImage(slash,flag.x+28,flag.y-32,null);
|
||||||
@@ -353,7 +368,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
else if (curTime >= modAmt/2 && curTime <= modAmt*3/4-1) startTime = 2;
|
else if (curTime >= modAmt/2 && curTime <= modAmt*3/4-1) startTime = 2;
|
||||||
else if (curTime >= modAmt*3/4 && curTime <= modAmt-1) startTime = 3;
|
else if (curTime >= modAmt*3/4 && curTime <= modAmt-1) startTime = 3;
|
||||||
|
|
||||||
if (currentLevel == 0 && !gameOver){
|
if (currentLevel == 0){
|
||||||
g.drawImage(startImg,340,300,null);
|
g.drawImage(startImg,340,300,null);
|
||||||
|
|
||||||
String text = "Press P to Start!";
|
String text = "Press P to Start!";
|
||||||
@@ -375,7 +390,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentLevel > 0 && !gameOver){
|
if (currentLevel > 0){
|
||||||
|
|
||||||
//draw hearts:
|
//draw hearts:
|
||||||
int heartTime = 0;
|
int heartTime = 0;
|
||||||
@@ -409,11 +424,6 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
g.drawImage(powerImg,220,10,null);
|
g.drawImage(powerImg,220,10,null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//gameover screen
|
|
||||||
if (gameOver){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//is key pressed
|
//is key pressed
|
||||||
@@ -444,14 +454,18 @@ public class Platformer extends JPanel implements KeyListener, ActionListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_R){
|
if (e.getKeyCode() == KeyEvent.VK_R){
|
||||||
|
if (gameOver) {
|
||||||
gameTimer.stop();
|
gameTimer.stop();
|
||||||
loadLevel(currentLevel);
|
loadLevel(1);
|
||||||
|
currentLevel = 1;
|
||||||
jumpPressed = false;
|
jumpPressed = false;
|
||||||
player.health=3;
|
player.health=3;
|
||||||
gameOver = false;
|
gameOver = false;
|
||||||
repaint();
|
repaint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_O){
|
if (e.getKeyCode() == KeyEvent.VK_O){
|
||||||
currentLevel++;
|
currentLevel++;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Color;
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.Timer;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Powerup extends Collectable{
|
public class Powerup extends Collectable{
|
||||||
int yVelo, xVelo, id;
|
int yVelo, xVelo, id;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import java.awt.Graphics;
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
|
||||||
|
|||||||
BIN
Sprites/PressR.png
Normal file
BIN
Sprites/PressR.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 444 B |
BIN
Sprites/end.png
Normal file
BIN
Sprites/end.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 694 B |
BIN
Sprites/win.png
Normal file
BIN
Sprites/win.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Reference in New Issue
Block a user