Commit 3a3bf6f0 authored by Nicholas Bindela's avatar Nicholas Bindela
Browse files

Merge Nick1

Conflicts:
	src/project/Main.java
	src/project/Obstacle.java
parent 976bcab4
......@@ -21,7 +21,7 @@ import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import project.Main;
import project.MainGame;
/**
*
......@@ -41,10 +41,10 @@ public class Laser extends Entity {
@Override
public void init() {
width = Main.WIDTH;
width = MainGame.WIDTH;
height = 50;
x = 0;
y = (float) (Math.random() * (Main.HEIGHT - height));
y = (float) (Math.random() * (MainGame.HEIGHT - height));
try {
image = new Image("Images/Fireball_Vertical.png");
} catch (SlickException ex) {
......
......@@ -21,7 +21,7 @@ import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import project.Main;
import project.MainGame;
/**
*
......@@ -43,8 +43,8 @@ public class Player extends Entity {
public void init() {
width = 100;
height = 100;
x = Main.WIDTH / 2;
y = (float) (Main.HEIGHT - height);
x = MainGame.WIDTH / 2;
y = (float) (MainGame.HEIGHT - height);
try {
image = new Image("Images/Link.png");
} catch (SlickException ex) {
......
......@@ -3,8 +3,8 @@
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 21, 2019
* Time: 8:35:49 PM
* Date: Apr 16, 2019
* Time: 8:35:57 PM
*
* Project: csci205FinalProject_SP19
* Package: project
......@@ -15,51 +15,39 @@
*/
package project;
import entities.Entity;
import entities.Laser;
import entities.Player;
import java.util.ArrayList;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
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.state.StateBasedGame;
/**
*
* @author njb013
*/
public class Main extends BasicGame {
public class Main extends StateBasedGame {
private ArrayList<Entity> entities;
private static final int HEIGHT = MainGame.HEIGHT;
private static final int WIDTH = MainGame.WIDTH;
private static final int MAINMENU = 0;
private static final int GAME = 1;
private Image character = null;
private Image background = null;
private Image fireImage = null;
private float startY = (float) (HEIGHT - char_Height);
private float startX = WIDTH / 2;
private float fireStartX;
private float fireStartY;
public static final int HEIGHT = 600;
public static final int WIDTH = 800;
private static int char_Width = 100;
private static int char_Height = 100;
public Main(String name) {
super(name);
this.addState(new MainMenu(MAINMENU));
this.addState(new MainGame(GAME));
}
public Main(String title) {
super(title);
@Override
public void initStatesList(GameContainer container) throws SlickException {
this.getState(MAINMENU).init(container, this);
this.getState(GAME).init(container, this);
this.enterState(MAINMENU);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
public static void main(String[] args) throws SlickException {
try {
AppGameContainer app = new AppGameContainer(new Main(
"Jetpack Joyride"));
......@@ -69,58 +57,5 @@ public class Main extends BasicGame {
} catch (SlickException e) {
e.printStackTrace();
}
}
@Override
public void init(GameContainer container) throws SlickException {
entities = new ArrayList<Entity>();
entities.add(new Player());
entities.add(new Laser());
container.setShowFPS(true);
container.setSmoothDeltas(true);
character = new Image(
"Images/Link.png");
background = new Image("Images/city.png");
character = character.getScaledCopy(char_Width, char_Height);
background = background.getScaledCopy(WIDTH, HEIGHT);
fireImage = new Image("Images/Fireball_Vertical.png");
fireImage = fireImage.getScaledCopy(50, 100);
}
@Override
public void update(GameContainer container, int delta) throws SlickException {
Input input = container.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
startY -= 1;
}
else {
startY += 1;
}
if (startY >= HEIGHT - (char_Height)) {
startY = HEIGHT - (char_Height);
}
if (startY < 0) {
startY = 0;
}
}
@Override
public void render(GameContainer container, Graphics g) throws SlickException {
background.draw();
character.draw(startX, startY);
/*for (int i = 0; i < entities.size(); i++) {
entities.get(i).render(container, g);
}*/
Input input = container.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
fireImage.draw(startX + 10, startY + 80);
}
}
}
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 16, 2019
* Time: 8:35:57 PM
*
* Project: csci205FinalProject_SP19
* Package: project
* File: MainGame
* Description:
*
* ****************************************
*/
package project;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
/**
*
* @author njb013
*/
public class MainGame extends BasicGameState {
private Image character = null;
private Image background = null;
private Image fireImage = null;
Music mainMusic;
private float startY = (float) (HEIGHT - char_Height);
private float startX = WIDTH / 6;
private float fireStartX;
private float fireStartY;
public static final int HEIGHT = 700;
public static final int WIDTH = 1500;
private static int char_Width = 100;
private static int char_Height = 100;
private static float backgroundX2 = (float) WIDTH;
private static float backgroundX = (float) 0.0;
private static float dX = (float) 1;
private int pointCounter = 0;
private String meters = "M";
private int topScore;
public MainGame(int state) {
super();
}
public int getID() {
return 1;
}
public void init(GameContainer container, StateBasedGame sbg) throws SlickException {
container.setSmoothDeltas(true);
character = new Image(
"Images/Link.png");
background = new Image("Images/city.png");
character = character.getScaledCopy(char_Width, char_Height);
background = background.getScaledCopy(WIDTH + 55, HEIGHT);
fireImage = new Image("Images/Fireball_Vertical.png");
fireImage = fireImage.getScaledCopy(50, 100);
mainMusic = new Music("Music/bucknellfight.ogg");
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
Input input = container.getInput();
backgroundX2 += dX;
backgroundX += dX;
if (input.isKeyDown(Input.KEY_SPACE)) {
startY -= 1;
}
else {
startY += 1;
}
if (startY > HEIGHT - (char_Height)) {
startY = HEIGHT - (char_Height);
}
if (startY < 0) {
startY = 0;
}
}
public void render(GameContainer container, StateBasedGame sbg, Graphics g) throws SlickException {
if (backgroundX2 == WIDTH * 2) {
backgroundX2 = WIDTH;
}
if (backgroundX == WIDTH) {
backgroundX = 0;
}
g.drawImage(background, (float) (WIDTH - backgroundX2), 0, null);
if (backgroundX2 > WIDTH) {
g.drawImage(background, (float) (WIDTH - backgroundX), 0, null);
}
if (!mainMusic.playing()) {
mainMusic.loop();
}
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
//g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
Input input = container.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
fireImage.draw(startX + 10, startY + 80);
}
character.draw(startX, startY);
}
}
......@@ -15,7 +15,6 @@
*/
package project;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
......@@ -29,8 +28,25 @@ public class MainMenu extends BasicGameState {
Image exit;
Image background;
Image logo;
private static final int HEIGHT = 600;
private static final int WIDTH = 800;
private static final int HEIGHT = MainGame.HEIGHT;
private static final int WIDTH = MainGame.WIDTH;
private final float playX = WIDTH / 2.5f;
private final float playY = 300;
private float playWidth;
private float playHeight;
private final float exitX = WIDTH / 2.5f;
private final float exitY = 415;
private float exitWidth;
private float exitHeight;
private float logoX;
private final float logoY = 75;
private float logoWidth;
private float logoHeight;
private Input input = null;
MainMenu(int state) {
}
......@@ -45,6 +61,17 @@ public class MainMenu extends BasicGameState {
play = new Image("Images/Play.png");
exit = new Image("Images/Exit.png");
logo = new Image("Images/logo.png");
playWidth = play.getWidth();
playHeight = play.getHeight();
exitWidth = exit.getWidth();
exitHeight = exit.getHeight();
logoWidth = logo.getWidth();
logoHeight = logo.getHeight();
logoX = (WIDTH / 2) - (logoWidth / 3);
background = new Image("Images/city.png");
background = background.getScaledCopy(WIDTH, HEIGHT);
logo = logo.getScaledCopy(300, 200);
......@@ -53,28 +80,27 @@ public class MainMenu extends BasicGameState {
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
background.draw();
logo.draw(250, 75);
play.draw(300, 300);
exit.draw(300, 415);
logo.draw(logoX, logoY);
play.draw(playX, playY);
exit.draw(exitX, exitY);
}
@Override
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
int posX = Mouse.getX();
int posY = Mouse.getY();
Input input = container.getInput();
//Play button
if ((posX > 300 && posX < 500) && (posY > 300 && posY < 400)) {
if (input.isKeyDown(Input.MOUSE_LEFT_BUTTON)) {
input = container.getInput();
int posX = input.getMouseX();
int posY = input.getMouseY();
if (input.isMousePressed(0)) {
if ((posX > playX && posX < (playX + playWidth)) && (posY > playY && posY < (playY + playHeight))) {
game.enterState(1);
}
}
//Exit button
if ((posX > 300 && posX < 500) && (posY > 415 && posY < 515)) {
if (input.isKeyDown(Input.MOUSE_LEFT_BUTTON)) {
else if ((posX > exitX && posX < (exitX + exitWidth)) && (posY > exitY && posY < (exitY + exitHeight))) {
System.exit(0);
}
}
}
......
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