Commit 7dfbad64 authored by Nicholas Bindela's avatar Nicholas Bindela
Browse files

Added Levels

parent eaec7ca0
......@@ -49,7 +49,7 @@ public class Laser extends Entity {
y = (float) (Math.random() * (Level1.HEIGHT - height));
try {
image = new Image("Images/laser_on.png");
image = image.getScaledCopy(Level1.WIDTH, image.getHeight());
image = image.getScaledCopy((int) width, (int) height);
} catch (SlickException ex) {
Logger.getLogger(Laser.class.getName()).log(Level.SEVERE, null, ex);
}
......
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 25, 2019
* Time: 6:58:00 PM
*
* Project: csci205FinalProject_SP19
* Package: entities
* File: Obstacle
* Description:
*
* ****************************************
*/
package entities;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import project.Level1;
/**
*
* @author njb013
*/
public class Obstacle extends Entity {
public Obstacle() {
super();
}
@Override
public void init() {
height = 50;
x = Level1.WIDTH;
y = (float) (Math.random() * (Level1.HEIGHT - height));
width = (int) (4.5 * height);
try {
image = new Image("Images/BlueLaser.png");
image = image.getScaledCopy((int) width, (int) height);
} catch (SlickException ex) {
Logger.getLogger(Obstacle.class.getName()).log(Level.SEVERE, null,
ex);
}
}
@Override
public void update(GameContainer gc, int delta) {
if (this.getEndX() > 0) {
x -= 1;
}
}
@Override
public void render(GameContainer gc, Graphics g) {
image.draw(x, y);
}
}
......@@ -21,8 +21,10 @@ import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import static project.Level.HEIGHT;
import project.Level1;
/**
......@@ -60,6 +62,19 @@ public class Player extends Entity {
@Override
public void update(GameContainer gc, int delta) {
Input input = gc.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
y -= 0.75;
}
else {
y += 0.75;
}
if (y > HEIGHT - height) {
y = HEIGHT - (height);
}
if (y < 0) {
y = 0;
}
}
......@@ -74,7 +89,10 @@ public class Player extends Entity {
image = new Image("Images/Link.png");
}
else if (sprite) {
image = new Image("Images/xeonStand.png");
playerAnimation = new Animation(spriteSheet, 75);
width = image.getWidth();
height = image.getHeight();
}
} catch (SlickException ex) {
Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
......
......@@ -97,10 +97,10 @@ public class Box {
}
public boolean hitTest(Box b) {
boolean rightB = b.getEndX() >= this.x;
boolean bottomB = b.getEndY() >= this.y;
boolean rightX = this.getEndX() >= b.x;
boolean bottomX = this.getEndY() >= b.y;
boolean rightB = b.x <= this.getEndX();
boolean bottomB = b.y <= this.getEndY();
boolean rightX = x <= b.getEndX();
boolean bottomX = y <= b.getEndY();
return (rightB && bottomB && rightX && bottomX);
}
......
......@@ -65,7 +65,7 @@ public abstract class Level extends BasicGameState {
Laser laser;
public static final int levelLength = 5000;
public static final int levelLength = 50000;
public int getTopScore() {
return topScore;
......
......@@ -16,8 +16,12 @@
package project;
import entities.Laser;
import entities.Obstacle;
import entities.Player;
import java.awt.Font;
import java.util.ArrayList;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +29,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -38,6 +43,8 @@ public class Level1 extends Level {
private Image fireImage = null;
Music mainMusic = null;
ArrayList<Obstacle> obstacles = new ArrayList<Obstacle>();
private SpriteSheet xeonSheet = null;
private Animation playerAnimation;
......@@ -45,9 +52,6 @@ public class Level1 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -63,6 +67,10 @@ public class Level1 extends Level {
private boolean isFalling = false;
Laser laser;
Font font;
TrueTypeFont ttf;
private static final int spawnInterval = 1000;
public int getTopScore() {
return topScore;
......@@ -111,6 +119,8 @@ public class Level1 extends Level {
Music sonic = new Music("Music/SonicTheme.ogg");
mainMusic = sonic;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -139,6 +149,17 @@ public class Level1 extends Level {
if (startY < 0) {
startY = 0;
}
if (pointCounter % spawnInterval == 0) {
obstacles.add(new Obstacle());
}
for (Obstacle o : obstacles) {
o.update(container, delta);
if (character.hitTest(o)) {
sbg.enterState(Main.LOSE);
}
}
pointCounter += 1;
if ((pointCounter % levelLength == 0)) {
mainMusic.stop();
......@@ -166,7 +187,8 @@ public class Level1 extends Level {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 1", Color.black);
Input input = container.getInput();
......@@ -188,6 +210,9 @@ public class Level1 extends Level {
fireImage.draw(startX + 10, startY + 80);
}
}
for (Obstacle o : obstacles) {
o.render(container, g);
}
//laser.image.draw(100, 100);
//xeonSheet.draw();
}
......
......@@ -17,7 +17,9 @@ package project;
import entities.Laser;
import entities.Player;
import java.awt.Font;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +27,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -45,9 +48,6 @@ public class Level2 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -63,6 +63,8 @@ public class Level2 extends Level {
private boolean isFalling = false;
Laser laser;
Font font;
TrueTypeFont ttf;
public int getTopScore() {
return topScore;
......@@ -114,6 +116,8 @@ public class Level2 extends Level {
mainMusic = circuit;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -169,7 +173,7 @@ public class Level2 extends Level {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 2", Color.black);
Input input = container.getInput();
......
......@@ -17,7 +17,9 @@ package project;
import entities.Laser;
import entities.Player;
import java.awt.Font;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +27,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -45,9 +48,6 @@ public class Level3 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -63,6 +63,8 @@ public class Level3 extends Level {
private boolean isFalling = false;
Laser laser;
Font font;
TrueTypeFont ttf;
public Level3(int state) {
super(state);
......@@ -107,6 +109,8 @@ public class Level3 extends Level {
mainMusic = woods;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -159,11 +163,10 @@ public class Level3 extends Level {
mainMusic.loop();
}
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 3", Color.black);
Input input = container.getInput();
if (character.hasSprite()) {
......
......@@ -17,7 +17,9 @@ package project;
import entities.Laser;
import entities.Player;
import java.awt.Font;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +27,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -45,9 +48,6 @@ public class Level4 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -64,6 +64,8 @@ public class Level4 extends Level {
private boolean isFalling = false;
Laser laser;
Font font;
TrueTypeFont ttf;
@Override
public int getID() {
......@@ -107,6 +109,8 @@ public class Level4 extends Level {
mainMusic = gerudo;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -162,7 +166,8 @@ public class Level4 extends Level {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 4", Color.black);
Input input = container.getInput();
......
......@@ -17,7 +17,9 @@ package project;
import entities.Laser;
import entities.Player;
import java.awt.Font;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +27,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -45,9 +48,6 @@ public class Level5 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -64,6 +64,8 @@ public class Level5 extends Level {
private boolean isFalling = false;
Laser laser;
Font font;
TrueTypeFont ttf;
@Override
public int getID() {
......@@ -106,6 +108,8 @@ public class Level5 extends Level {
mainMusic = halo;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -161,7 +165,8 @@ public class Level5 extends Level {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 5", Color.black);
Input input = container.getInput();
......
......@@ -17,7 +17,9 @@ package project;
import entities.Laser;
import entities.Player;
import java.awt.Font;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
......@@ -25,6 +27,7 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.StateBasedGame;
/**
......@@ -45,9 +48,6 @@ public class Level6 extends Level {
private float startX = WIDTH / 6;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
......@@ -65,6 +65,9 @@ public class Level6 extends Level {
Laser laser;
Font font;
TrueTypeFont ttf;
@Override
public int getID() {
return Main.LVL6;
......@@ -107,6 +110,8 @@ public class Level6 extends Level {
mainMusic = pkmn;
laser = new Laser();
font = new Font("Courier", Font.PLAIN, 12);
ttf = new TrueTypeFont(font, true);
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -162,7 +167,8 @@ public class Level6 extends Level {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString("Level " + Integer.toString(this.getID()), WIDTH - 70, 0);
ttf.drawString(Level.WIDTH - 70, 0, "Level 6", Color.black);
Input input = container.getInput();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment