Skip to content

Instantly share code, notes, and snippets.

@rymate1234
Created November 23, 2011 20:38
Show Gist options
  • Save rymate1234/1389828 to your computer and use it in GitHub Desktop.
Save rymate1234/1389828 to your computer and use it in GitHub Desktop.
My game source
package net.rymate.gaming;
import java.util.ArrayList;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
public abstract class Entity {
int id;
Vector2f position;
float scale;
float rotation;
String name;
Image img;
float x;
float y;
public Entity(int id) {
this.id = id;
this.img = null;
position = new Vector2f(0, 0);
scale = 1;
this.name = "Anon";
rotation = 0;
}
public Vector2f getPosition() {
return position;
}
public float getScale() {
return scale;
}
public float getRotation() {
return rotation;
}
public String getName() {
return name;
}
public void setName(String n) {
this.name = n;
}
public int getId() {
return id;
}
public void setPosition(float x, float y) {
position.set(x, y);
}
public void setRotation(float rotate) {
rotation = rotate;
}
public void setScale(float scale) {
this.scale = scale;
}
public abstract void update(GameContainer gc, StateBasedGame sb, int delta);
public abstract void render(GameContainer gc, StateBasedGame sb, Graphics gr);
}
package net.rymate.gaming;
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.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
public class EntityPlane extends Entity{
public EntityPlane(int id) throws SlickException {
super(id);
this.img = new Image("data/plane.png");
//setPosition(new Vector2f(400, 300));
}
@Override
public void update(GameContainer gc, StateBasedGame sb, int delta) {
Input input = gc.getInput();
if (input.isKeyDown(Input.KEY_A)) {
img.rotate(-0.2f * delta);
}
if (input.isKeyDown(Input.KEY_D)) {
img.rotate(0.2f * delta);
}
if (input.isKeyDown(Input.KEY_W)) {
float hip = 0.4f * delta;
float rotation = img.getRotation();
x += hip * Math.sin(Math.toRadians(rotation));
y -= hip * Math.cos(Math.toRadians(rotation));
}
setPosition(x, y);
}
@Override
public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
img.draw(position.x, position.y);
}
}
package net.rymate.gaming;
import java.io.File;
import org.lwjgl.LWJGLUtil;
import org.newdawn.slick.*;
import org.newdawn.slick.geom.Vector2f;
public class Main extends BasicGame {
public static String title = "Rymate Test Shooter";
Entity land;
EntityPlane plane;
Entity bullet;
float maxX = 800;
float maxY = 600;
public Main(String title) {
super(title);
}
@Override
public void init(GameContainer gc) throws SlickException {
plane = new EntityPlane(1);
plane.setPosition(400, 300);
}
@Override
public void update(GameContainer gc, int delta) throws SlickException {
//land.update(gc, null, delta);
plane.update(gc, null, delta);
//bullet.update(gc, null, delta);
}
public void render(GameContainer gc, Graphics g) throws SlickException {
//land.render(gc, null, g);
plane.render(gc, null, g);
//bullet.render(gc, null, g);
}
public static void main(String[] args) throws SlickException {
System.setProperty("org.lwjgl.librarypath",
new File(new File(System.getProperty("user.dir"), "native"),
LWJGLUtil.getPlatformName()).getAbsolutePath());
System.setProperty("net.java.games.input.librarypath",
System.getProperty("org.lwjgl.librarypath"));
AppGameContainer app = new AppGameContainer(new Main(title));
app.setDisplayMode(800, 600, false);
app.setSmoothDeltas(true);
app.setShowFPS(true);
app.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment