Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import org.lwjgl.opengl.Display;
- import static data.Screen.*;
- import static data.Clock.*;
- import static data.Player.*;
- public class Main{
- public static void main(String[] args) {
- ScreenInit();
- System.out.println("ScreenInit ready!");
- Screen();
- }
- public static void Screen(){
- new Player("test", 10, 10, 64, 64);
- while(!Display.isCloseRequested()){
- Clock.update();
- Player.handlePlayer();
- Display.update();
- Display.sync(60);
- }
- Display.destroy();
- System.exit(0);
- }
- }
- -----------------------------------------------------
- package data;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.newdawn.slick.opengl.Texture;
- import org.newdawn.slick.opengl.TextureLoader;
- import org.newdawn.slick.util.ResourceLoader;
- import static data.Main.*;
- import static org.lwjgl.opengl.GL11.*;
- import java.io.IOException;
- import java.io.InputStream;
- public class Screen {
- public static final int WIDTH = 1080, HEIGHT = 720;
- public static void ScreenInit(){
- try {
- SystemInit();
- System.out.println("SysInit ready!");
- Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
- Display.setTitle("Test");
- Display.create();
- } catch (LWJGLException e) {
- e.printStackTrace();
- Display.destroy();
- System.exit(1);
- }
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
- glMatrixMode(GL_MODELVIEW);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- public static void DrawQuadTex(Texture tex, float x, float y, float width, float height) {
- tex.bind();
- glTranslatef(x, y, 0);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(0, 0);
- glTexCoord2f(1, 0);
- glVertex2f(width, 0);
- glTexCoord2f(1, 1);
- glVertex2f(width, height);
- glTexCoord2f(0, 1);
- glVertex2f(0, height);
- glEnd();
- glLoadIdentity();
- }
- public static Texture loadTexture(String path, String fileType) {
- Texture tex = null;
- InputStream in = ResourceLoader.getResourceAsStream(path);
- try {
- tex = TextureLoader.getTexture(fileType, in);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return tex;
- }
- public static Texture QuickLoad(String name) {
- Texture tex = null;
- tex = loadTexture("resources/textures/" + name
- + ".png", "PNG");
- return tex;
- }
- }
- ----------------------------------------------------------------------
- package data;
- import org.lwjgl.Sys;
- public class Clock {
- private static boolean paused = false;
- public static long lastframe, totaltime;
- public static float d = 0, multiplier = 1;
- public static long getTime() {
- return Sys.getTime() * 1000 / Sys.getTimerResolution();
- }
- public static float getDelta() {
- long currenttime = getTime();
- int delta = (int) (currenttime - lastframe);
- lastframe = getTime();
- if(delta * 0.001f > 0.05f)
- return 0.05f;
- return delta * 0.001f;
- }
- public static float Delta() {
- if (paused)
- return 0;
- else
- return d * multiplier;
- }
- public static float Totaltime() {
- return totaltime;
- }
- public static float Multiplier() {
- return multiplier;
- }
- public static void update() {
- d = getDelta();
- totaltime += d;
- }
- public static void changemultiplier(float change) {
- if (multiplier + change < -1 && multiplier + change > 7) {
- } else {
- multiplier += change;
- }
- }
- public static void pause() {
- if (paused)
- paused = false;
- else
- paused = true;
- }
- }
- -----------------------------------------------------------------
- package data;
- import org.lwjgl.input.Keyboard;
- import static data.Screen.*;
- import static data.Clock.*;
- import java.util.ArrayList;
- import java.util.List;
- public class Player {
- private static String tex;
- private static float x;
- private static float y;
- private static float width;
- private static float height;
- private static ArrayList<Player> Players;
- public Player (String tex, float x, float y, float width, float height){
- Player.tex = tex;
- Player.x = x;
- Player.y = y;
- Player.width = width;
- Player.height = height;
- this.setPlayers(new ArrayList<Player>());
- Players.add(this);
- }
- public static int Direction = 2;
- public static boolean Moving = false;
- public static boolean start = false;
- public static void handlePlayer(){
- for(Player p: Players){
- p.Update();
- p.draw();
- }
- }
- public static void Walk(){
- if(start == false){
- start = true;
- Moving = false;
- }
- if(Direction == 0 && Moving == true ){
- System.out.println("Walking North");
- getPlayers().get(0).setY(y -= 30 * Delta());
- }
- if(Direction == 1 && Moving == true ){
- System.out.println("Walking East");
- getPlayers().get(0).setX(x += 30 * Delta());
- }
- if(Direction == 2 && Moving == true ){
- System.out.println("Walking South");
- getPlayers().get(0).setY(y += 30 * Delta());
- }
- if(Direction == 3 && Moving == true ){
- System.out.println("Walking West");
- getPlayers().get(0).setX(x -= 30 * Delta());
- }
- if(Direction == 0 && Moving == false ){
- System.out.println("Standing North");
- }
- if(Direction == 1 && Moving == false ){
- System.out.println("Standing East");
- }
- if(Direction == 2 && Moving == false ){
- System.out.println("Standing South");
- }
- if(Direction == 3 && Moving == false ){
- System.out.println("Standing West");
- }
- }
- public static void Inputs(){
- if(Keyboard.isKeyDown(Keyboard.KEY_W)){
- Direction = 0;
- Moving = true;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_D)){
- Direction = 1;
- Moving = true;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_S)){
- Direction = 2;
- Moving = true;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_A)){
- Direction = 3;
- Moving = true;
- }
- if(!Keyboard.isKeyDown(Keyboard.KEY_W) && !Keyboard.isKeyDown(Keyboard.KEY_D) && !Keyboard.isKeyDown(Keyboard.KEY_S) && !Keyboard.isKeyDown(Keyboard.KEY_A)){
- Moving = false;
- }
- }
- public static void draw(){
- DrawQuadTex(QuickLoad(tex), x, y, width, height);
- }
- public static void Update(){
- Inputs();
- Walk();
- }
- public String getTex() {
- return tex;
- }
- public void setTex(String tex) {
- Player.tex = tex;
- }
- public float getX() {
- return x;
- }
- public void setX(float x) {
- Player.x = x;
- }
- public float getY() {
- return y;
- }
- public void setY(float y) {
- Player.y = y;
- }
- public float getWidth() {
- return width;
- }
- public void setWidth(float width) {
- Player.width = width;
- }
- public float getHeight() {
- return height;
- }
- public void setHeight(float height) {
- Player.height = height;
- }
- public static ArrayList<Player> getPlayers() {
- return Players;
- }
- public void setPlayers(ArrayList<Player> players) {
- Players = players;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement