Commit 0f1af33f authored by Nicholas Bindela's avatar Nicholas Bindela
Browse files

Changed to statebased game

parent 1e383f32
......@@ -2,6 +2,36 @@ annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
<<<<<<< OURS
application.title=csci205FinalProject_SP19
application.vendor=njb013
build.generated.sources.dir=${build.dir}/generated-sources
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=\
${libs.Slick2D.classpath}
javac.deprecation=false
javac.external.vm=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=
javadoc.author=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=false
javadoc.use=false
javadoc.version=false
mkdist.disabled=false
platform.active=default_platform
run.classpath=
run.test.classpath=
=======
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=csci205FinalProject_SP19
application.vendor=av015
......@@ -77,3 +107,4 @@ run.test.classpath=\
source.encoding=UTF-8
src.dir=src
test.src.dir=test
>>>>>>> THEIRS
/*
* 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;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
/**
*
* @author njb013
*/
public class Main {
public static final int DISPLAY_HEIGHT = 480;
public static final int DISPLAY_WIDTH = 640;
public static final Logger LOGGER = Logger.getLogger(Main.class.getName());
private int squareSize;
private int squareX;
private int squareY;
private int squareZ;
private Obstacle o;
private double spawnRate = 0.5;
private Image character = null;
static {
try {
LOGGER.addHandler(new FileHandler("errors.log", true));
} catch (IOException ex) {
LOGGER.log(Level.WARNING, ex.toString(), ex);
}
}
public static void main(String[] args) {
Main main = null;
try {
main = new Main();
main.create();
main.run();
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, ex.toString(), ex);
} finally {
if (main != null) {
main.destroy();
}
}
}
public Main() {
squareSize = 50;
squareX = 26;
squareY = 26;
squareZ = 0;
}
public void create() throws LWJGLException, SlickException {
//Display
Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
Display.setFullscreen(false);
Display.setTitle("Hello LWJGL World!");
Display.create();
//Keyboard
Keyboard.create();
//Mouse
Mouse.setGrabbed(false);
Mouse.create();
//OpenGL
initGL();
resizeGL();
}
public void destroy() {
//Methods already check if created before destroying.
Mouse.destroy();
Keyboard.destroy();
Display.destroy();
}
public void initGL() throws SlickException {
//2D Initialization
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
character = new Image(
"/home/accounts/student/n/njb013/csci205_FinalProject/Images/Link.png");
}
public void processKeyboard() {
//Square's Size
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
}
if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
squareY = (int) (squareY * Math.pow(Math.E, 0.05));
squareX += 1;
}
//Square's Z
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
squareX += -3;
}
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
squareX += 3;
}
}
public void processMouse() {
if (Mouse.isButtonDown(0)) {
squareY = (int) (squareY * Math.pow(Math.E, 0.05));
squareX += 1;
}
else if (squareY > (squareSize / 2)) {
squareY = (int) (squareY / Math.pow(Math.E, 0.03));
squareX += 1;
}
}
public void render() {
glClear(GL_COLOR_BUFFER_BIT);
/*glLoadIdentity();
//Draw a basic square
glTranslatef(squareX, squareY, 0.0f);
glTranslatef(-(squareSize >> 1), -(squareSize >> 1), 0.0f);
//glColor3f(1.0f, 1.0f, 0.5f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(squareSize, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(squareSize, squareSize);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, squareSize);
glEnd();*/
character.draw((float) squareX, (float) squareY, 0.1f);
}
public void createObstacle(Obstacle o) {
//glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
double x1 = o.getObsX();
double x2 = o.getObsX() + o.getObsWidth() / 2;
double y1 = o.getObsY();
double y2 = o.getObsY() - o.getObsHeight() / 2;
//Draw a basic square
glColor3f(0.0f, 0.5f, 0.3f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(x1, y1);
glTexCoord2f(1.0f, 0.0f);
glVertex2d(x1, y2);
glTexCoord2f(1.0f, 1.0f);
glVertex2d(x2, y1);
glTexCoord2f(0.0f, 1.0f);
glVertex2d(x2, y2);
glEnd();
}
public void resizeGL() {
//2D Scene
glViewport(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, DISPLAY_WIDTH, 0.0f, DISPLAY_HEIGHT);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
}
public void run() throws InterruptedException {
while (!Display.isCloseRequested() && !Keyboard.isKeyDown(
Keyboard.KEY_ESCAPE)) {
if (Display.isVisible()) {
processKeyboard();
processMouse();
update();
render();
if (o == null) {
o = new Obstacle();
}
createObstacle(o);
}
else {
if (Display.isDirty()) {
render();
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
Display.update();
Display.sync(60);
}
}
public void update() {
if (squareY >= DISPLAY_HEIGHT - (squareSize / 2)) {
squareY = DISPLAY_HEIGHT - (squareSize / 2);
}
if (squareY <= (squareSize / 2)) {
squareY = squareSize / 2;
}
if (squareX >= DISPLAY_WIDTH - (squareSize / 2)) {
squareX = DISPLAY_WIDTH - (squareSize / 2);
}
if (squareX <= squareSize / 2) {
squareX = squareSize / 2;
}
try {
o.setObsX(o.getObsX() - 1);
if (o.getObsX() + o.getObsWidth() < 0) {
o = null;
}
double squareRight = squareX;
double squareBottom = squareY - squareSize;
double oLeft = o.getObsX();
if ((squareRight == oLeft) && (squareY == o.getObsY())) {
squareX = 0;
squareY = 0;
}
} catch (NullPointerException e) {
}
}
}
/*
* 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 = Main.DISPLAY_WIDTH;
obsY = (int) (Math.random() * (Main.DISPLAY_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