Commit 976bcab4 authored by Nicholas Bindela's avatar Nicholas Bindela
Browse files

Merge Nick1

Conflicts:
	src/project/Main.java
	src/project/Obstacle.java
parents 01465038 2f57e129
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 21, 2019
* Time: 8:06:01 PM
*
* Project: csci205FinalProject_SP19
* Package: entities
* File: Entity
* Description:
*
* ****************************************
*/
package entities;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import project.Box;
/**
*
* @author njb013
*/
public abstract class Entity extends Box {
public Image image;
public Color color;
public Entity() {
init();
}
public abstract void init();
public void render(GameContainer gc, Graphics g) {
if (image != null) {
image.draw(x, y, width, height, color);
}
}
public abstract void update(GameContainer gc, int delta);
}
/* *****************************************
* CSCI205 - Software Engineering and Design
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 21, 2019
* Time: 8:27:24 PM
*
* Project: csci205FinalProject_SP19
* Package: entities
* File: Laser
* 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.Main;
/**
*
* @author njb013
*/
public class Laser extends Entity {
@Override
public void render(GameContainer gc, Graphics g) {
}
@Override
public void update(GameContainer gc, int delta) {
}
@Override
public void init() {
width = Main.WIDTH;
height = 50;
x = 0;
y = (float) (Math.random() * (Main.HEIGHT - height));
try {
image = new Image("Images/Fireball_Vertical.png");
} catch (SlickException ex) {
Logger.getLogger(Player.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 21, 2019
* Time: 8:08:07 PM
*
* Project: csci205FinalProject_SP19
* Package: entities
* File: Player
* 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.Main;
/**
*
* @author njb013
*/
public class Player extends Entity {
@Override
public void render(GameContainer gc, Graphics g) {
}
@Override
public void update(GameContainer gc, int delta) {
}
@Override
public void init() {
width = 100;
height = 100;
x = Main.WIDTH / 2;
y = (float) (Main.HEIGHT - height);
try {
image = new Image("Images/Link.png");
} catch (SlickException ex) {
Logger.getLogger(Player.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 21, 2019
* Time: 7:48:21 PM
*
* Project: csci205FinalProject_SP19
* Package: project
* File: Box
* Description:
*
* ****************************************
*/
package project;
/**
* Class for representing a box
*
* @author njb013
*/
public class Box {
public float x;
public float y;
public float width;
public float height;
public Box() {
}
/**
* Initialize a box with x, y, width, and height values
*
* @param x
* @param y
* @param width
* @param height
*/
public Box(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
/**
*
* @return x value of right side of Box
*/
public float getEndX() {
return x + width;
}
/**
*
* @return y value of the bottom of the Box
*/
public float getEndY() {
return y + height;
}
/**
*
* @return Half of the box's width
*/
public float getHalfWidth() {
return width / 2;
}
/**
*
* @return half of the box's height
*/
public float getHalfHeight() {
return height / 2;
}
/**
* Gets the center X value for the Box
*
* @return x value of the center of the Box
*/
public float getCenterX() {
return x + getHalfWidth();
}
/**
* Gets the center Y value for the Box
*
* @return y value of the center of the Box
*/
public float getCenterY() {
return y + getHalfHeight();
}
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;
return (rightB && bottomB && rightX && bottomX);
}
}
......@@ -3,8 +3,8 @@
* Spring 2019
*
* Name: Aditi Vijayvergia, Melissa Tjong, Mitch Gavars, and Nick Bindela
* Date: Apr 16, 2019
* Time: 8:35:57 PM
* Date: Apr 21, 2019
* Time: 8:35:49 PM
*
* Project: csci205FinalProject_SP19
* Package: project
......@@ -15,39 +15,51 @@
*/
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 StateBasedGame {
public class Main extends BasicGame {
private static final int HEIGHT = 600;
private static final int WIDTH = 800;
private static final int MAINMENU = 0;
private static final int GAME = 1;
private ArrayList<Entity> entities;
public Main(String name) {
super(name);
this.addState(new MainMenu(MAINMENU));
this.addState(new MainGame(GAME));
}
private Image character = null;
private Image background = null;
private Image fireImage = null;
@Override
public void initStatesList(GameContainer container) throws SlickException {
this.getState(MAINMENU).init(container, this);
this.getState(GAME).init(container, this);
this.enterState(MAINMENU);
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 title) {
super(title);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SlickException {
public static void main(String[] args) {
try {
AppGameContainer app = new AppGameContainer(new Main(
"Jetpack Joyride"));
......@@ -57,5 +69,58 @@ public class Main extends StateBasedGame {
} 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.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;
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 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, HEIGHT);
fireImage = new Image("Images/Fireball_Vertical.png");
fireImage = fireImage.getScaledCopy(50, 100);
}
public void update(GameContainer container, StateBasedGame sbg, 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;
}
}
public void render(GameContainer container, StateBasedGame sbg, Graphics g) throws SlickException {
background.draw();
character.draw(startX, startY);
Input input = container.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
fireImage.draw(startX + 10, startY + 80);
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package project;
/**
*
* @author njb013
*/
public class Obstacle {
private int obsX;
private int obsY;
private int obsWidth;
private int obsHeight;
public Obstacle() {
obsWidth = (int) (Math.random() * (200 - 100 + 1) + 100);
obsHeight = (int) (Math.random() * (200 - 100 + 1) + 100);
obsX = MainGame.WIDTH;
obsY = (int) (Math.random() * (MainGame.HEIGHT - obsHeight + 1) + obsHeight);
}
public int getObsX() {
return obsX;
}
public void setObsX(int obsX) {
this.obsX = obsX;
}
public int getObsY() {
return obsY;
}
public void setObsY(int obsY) {
this.obsY = obsY;
}
public int getObsWidth() {
return obsWidth;
}
public void setObsWidth(int obsWidth) {
this.obsWidth = obsWidth;
}
public int getObsHeight() {
return obsHeight;
}
public void setObsHeight(int obsHeight) {
this.obsHeight = obsHeight;
}
}
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