Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rpg;
- import java.awt.event.*;
- import java.util.Random;
- import org.lwjgl.*;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.*;
- import static org.lwjgl.opengl.GL11.*;
- import entities.*;
- public class RPG {
- public static final int WIDTH = 640;
- public static final int HEIGHT = 480;
- private boolean isRunning = true;
- private boolean inField = true;
- private boolean playerCanControl = true;
- static Player player;
- //static Enemy enemy;
- public RPG() {
- setUpDisplay();
- setUpOpenGL();
- setUpEntites();
- setUpTimer();
- while (isRunning) {
- render();
- input();
- logic(getDelta());
- Display.update();
- Display.sync(60);
- if (Display.isCloseRequested()) {
- isRunning = false;
- }
- }
- }
- private void input() {
- if(player.getX() % 32 == 0 && player.getY() % 32 == 0) {
- player.setDX(0);
- player.setDY(0);
- if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) player.setDX(-.5);
- else if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) player.setDX(.5);
- else if(Keyboard.isKeyDown(Keyboard.KEY_UP)) player.setDY(-.5);
- else if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) player.setDY(.5);
- }
- /*if (inField == true) {
- if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
- Keyboard.destroy();
- for (int x = 0; x < 32; x += 4) { player.setY(player.getY() - 4); }
- try {
- Keyboard.create();
- } catch (LWJGLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
- player.setY(player.getY() + 4);
- } else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
- player.setX(player.getX() + 4);
- } else if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
- player.setX(player.getX() - 4);
- }
- }*/
- }
- private long lastFrame;
- private long getTime() {
- return (Sys.getTime() * 1000 / Sys.getTimerResolution());
- }
- private int getDelta() {
- long currentTime = getTime();
- int delta = (int) (currentTime - lastFrame);
- lastFrame = getTime();
- return delta;
- }
- private void setUpDisplay() {
- try {
- Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
- Display.setTitle("RPG");
- Display.create();
- } catch (LWJGLException e) {
- e.printStackTrace();
- }
- }
- private void setUpOpenGL() {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, 640, 480, 0, 1, -1);
- glMatrixMode(GL_MODELVIEW);
- }
- private void setUpEntites() {
- player = new Player(32, 32, 32, 32);
- //enemy = new Enemy(50,50,32,32);
- }
- private void setUpTimer() {
- lastFrame = getTime();
- }
- private void render() {
- glClear(GL_COLOR_BUFFER_BIT);
- player.draw();
- //enemy.draw();
- }
- private void logic(int delta) {
- player.update(delta);
- //enemy.update(delta);
- /*if (player.intersects(enemy)) {
- changeToBattleScene(player,enemy);
- }*/
- }
- private void changeToBattleScene(Entity player, Entity enemy) {
- inField = false;
- double x = player.getX();
- double y = player.getY();
- player.setX(WIDTH - WIDTH + 50);
- player.setY(HEIGHT - 50 - player.getHeight());
- enemy.setX(WIDTH - 50 - enemy.getWidth());
- enemy.setY(HEIGHT - HEIGHT + 50);
- glRectf(100,100,100,100);
- //playerMovement = true;
- }
- private static class Player extends AbstractMovableEntity {
- public Player(float x, float y, float width, float height) {
- super(x, y, width, height);
- }
- @Override
- public void draw() {
- glRectf(x, y, x + width, y + height);
- }
- }
- private static class Enemy extends AbstractMovableEntity {
- public Enemy(float x, float y, float width, float height) {
- super(x, y, width, height);
- }
- @Override
- public void draw() {
- glRectf(x, y, x + width, y + height);
- }
- }
- public static void main(String args[]) {
- new RPG();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment