Commit b8d28022 authored by Nicholas Bindela's avatar Nicholas Bindela
Browse files

End of Day Tuesday, Nicks changes

parent 3a3bf6f0
......@@ -15,10 +15,12 @@
*/
package entities;
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;
import org.newdawn.slick.SpriteSheet;
import project.Box;
/**
......@@ -29,17 +31,26 @@ public abstract class Entity extends Box {
public Image image;
public Color color;
public SpriteSheet spriteSheet;
public Animation playerAnimation;
public Entity() {
init();
}
public Image getImage() {
return image;
}
public abstract void init();
public void render(GameContainer gc, Graphics g) {
if (image != null) {
/*if (image != null) {
image.draw(x, y, width, height, color);
}
else if (spriteSheet != null) {
playerAnimation.draw(x, y, width, height);
}*/
}
public abstract void update(GameContainer gc, int delta);
......
......@@ -46,9 +46,10 @@ public class Laser extends Entity {
x = 0;
y = (float) (Math.random() * (MainGame.HEIGHT - height));
try {
image = new Image("Images/Fireball_Vertical.png");
image = new Image("Images/laser_on.png");
image = image.getScaledCopy(MainGame.WIDTH, image.getHeight());
} catch (SlickException ex) {
Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(Laser.class.getName()).log(Level.SEVERE, null, ex);
}
}
......
......@@ -17,10 +17,12 @@ package entities;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import project.MainGame;
/**
......@@ -29,6 +31,28 @@ import project.MainGame;
*/
public class Player extends Entity {
private boolean sprite = false;
private Image risingImage = null;
private Image fallingImage = null;
public Player() {
super();
}
public Player(Image i) {
super();
this.image = i;
}
public Player(SpriteSheet s, Image rise, Image fall) {
sprite = true;
this.spriteSheet = s;
risingImage = rise;
fallingImage = fall;
init();
}
@Override
public void render(GameContainer gc, Graphics g) {
......@@ -46,10 +70,51 @@ public class Player extends Entity {
x = MainGame.WIDTH / 2;
y = (float) (MainGame.HEIGHT - height);
try {
image = new Image("Images/Link.png");
if (image == null && !sprite) {
image = new Image("Images/Link.png");
}
else if (sprite) {
playerAnimation = new Animation(spriteSheet, 75);
}
} catch (SlickException ex) {
Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Image getRisingImage() {
return risingImage;
}
public void setRisingImage(Image risingImage) {
this.risingImage = risingImage;
}
public Image getFallingImage() {
return fallingImage;
}
public void setFallingImage(Image fallingImage) {
this.fallingImage = fallingImage;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Animation getAnimation() {
return playerAnimation;
}
public void setAnimation(Animation a) {
this.playerAnimation = a;
}
public boolean hasSprite() {
return sprite;
}
}
......@@ -15,12 +15,18 @@
*/
package project;
import entities.Laser;
import entities.Player;
import java.util.ArrayList;
import java.util.ListIterator;
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.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
......@@ -30,12 +36,18 @@ import org.newdawn.slick.state.StateBasedGame;
*/
public class MainGame extends BasicGameState {
private Image character = null;
private Player character = null;
private Image background = null;
private Image fireImage = null;
private SpriteSheet xeonSheet = null;
private Animation playerAnimation;
Music mainMusic;
ArrayList<Image> backgrounds = new ArrayList<Image>();
ListIterator<Image> changeBackground;
private float startY = (float) (HEIGHT - char_Height);
private float startX = WIDTH / 6;
......@@ -58,6 +70,19 @@ public class MainGame extends BasicGameState {
private int topScore;
private boolean isRising = false;
private boolean isFalling = false;
Laser laser;
public int getTopScore() {
return topScore;
}
public void setTopScore(int topScore) {
this.topScore = topScore;
}
public MainGame(int state) {
super();
}
......@@ -69,16 +94,53 @@ public class MainGame extends BasicGameState {
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);
Image city = new Image("Images/city.png");
Image game_background_1 = new Image("Images/game_background_1.png");
Image game_background_2 = new Image("Images/game_background_2.png");
Image game_background_3 = new Image("Images/game_background_3.png");
Image dancy = new Image("Images/DancyChris.png");
Image bravo = new Image("Images/Bravo.png");
city = city.getScaledCopy(WIDTH + 55, HEIGHT);
game_background_1 = game_background_1.getScaledCopy(WIDTH + 55, HEIGHT);
game_background_2 = game_background_2.getScaledCopy(WIDTH + 55, HEIGHT);
game_background_3 = game_background_3.getScaledCopy(WIDTH + 55, HEIGHT);
dancy = dancy.getScaledCopy(WIDTH + 55, HEIGHT);
bravo = bravo.getScaledCopy(WIDTH + 55, HEIGHT);
backgrounds.add(city);
backgrounds.add(game_background_1);
backgrounds.add(game_background_2);
backgrounds.add(game_background_3);
backgrounds.add(dancy);
backgrounds.add(bravo);
background = backgrounds.get(0);
changeBackground = backgrounds.listIterator();
//character = new Player(new Image("Images/Link.png"));
SpriteSheet charSprite = new SpriteSheet("Images/xeonSprite.png", 56,
64);
Image rising = new Image("Images/xeonRising.png");
Image falling = new Image("Images/xeonFalling.png");
rising = rising.getScaledCopy(56, 64);
falling = falling.getScaledCopy(56, 64);
character = new Player(charSprite, rising,
falling);
//character.setImage(character.getImage().getScaledCopy(char_Width,
// char_Height));
//xeonSheet = new SpriteSheet("Images/xeonsheet.bmp", 45, 70);
if (character.hasSprite()) {
character.getAnimation().setPingPong(false);
}
fireImage = new Image("Images/Fireball_Vertical.png");
fireImage = fireImage.getScaledCopy(50, 100);
mainMusic = new Music("Music/bucknellfight.ogg");
mainMusic = new Music("Music/SonicTheme.ogg");
laser = new Laser();
}
public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException {
......@@ -86,19 +148,35 @@ public class MainGame extends BasicGameState {
backgroundX2 += dX;
backgroundX += dX;
if (character.hasSprite()) {
character.getAnimation().update(delta);
}
if (input.isKeyDown(Input.KEY_SPACE)) {
startY -= 1;
isRising = true;
}
else {
startY += 1;
isRising = false;
isFalling = true;
}
if (startY > HEIGHT - (char_Height)) {
startY = HEIGHT - (char_Height);
isFalling = false;
}
if (startY < 0) {
startY = 0;
}
pointCounter += 1;
if ((pointCounter % 50000 == 0) && changeBackground.hasNext()) {
background = changeBackground.next();
}
else if (!changeBackground.hasNext()) {
changeBackground = backgrounds.listIterator();
}
}
......@@ -121,17 +199,30 @@ public class MainGame extends BasicGameState {
//g.setColor(Color.black);
g.drawString(Integer.toString(pointCounter / 20) + meters, 0, 0);
//g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
g.drawString(Integer.toString(getTopScore()) + meters, 0, 20);
Input input = container.getInput();
if (input.isKeyDown(Input.KEY_SPACE)) {
fireImage.draw(startX + 10, startY + 80);
if (character.hasSprite()) {
if (!isRising && !isFalling) {
character.getAnimation().draw(startX, startY);
}
else if (isRising) {
character.getRisingImage().draw(startX, startY);
}
else if (isFalling) {
character.getFallingImage().draw(startX, startY);
}
}
else {
character.getImage().draw(startX, startY);
if (input.isKeyDown(Input.KEY_SPACE)) {
character.draw(startX, startY);
fireImage.draw(startX + 10, startY + 80);
}
}
//laser.image.draw(100, 100);
//xeonSheet.draw();
}
}
......@@ -48,6 +48,8 @@ public class MainMenu extends BasicGameState {
private Input input = null;
Music menuMusic;
MainMenu(int state) {
}
......@@ -75,6 +77,8 @@ public class MainMenu extends BasicGameState {
background = new Image("Images/city.png");
background = background.getScaledCopy(WIDTH, HEIGHT);
logo = logo.getScaledCopy(300, 200);
menuMusic = new Music("Music/bucknellfight.ogg");
}
@Override
......@@ -84,6 +88,10 @@ public class MainMenu extends BasicGameState {
play.draw(playX, playY);
exit.draw(exitX, exitY);
if (!menuMusic.playing()) {
menuMusic.loop();
}
}
@Override
......
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