Thomas Allen avatar Thomas Allen committed 18f4c54

Initial commit

Comments (0)

Files changed (19)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="lib" path="C:/Users/Thomas/Dropbox/Game Development/Java Development/Libraries/LWJGL - 2.8.4/jar/lwjgl.jar">
+		<attributes>
+			<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="C:/Users/Thomas/Dropbox/Game Development/Java Development/Libraries/LWJGL - 2.8.4/native/windows"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="C:/Users/Thomas/Dropbox/Game Development/Java Development/Libraries/LWJGL - 2.8.4/jar/lwjgl_util.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Thomas/Dropbox/Game Development/Java Development/Libraries/Slick 2D/slick-util.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>LWJGL TestBed</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
Add a comment to this file

src/assets/graphics/alien.gif

Added
New image
Add a comment to this file

src/assets/graphics/alien.png

Added
New image
Add a comment to this file

src/assets/graphics/alien2.gif

Added
New image
Add a comment to this file

src/assets/graphics/alien3.gif

Added
New image
Add a comment to this file

src/assets/graphics/gotyou.gif

Added
New image
Add a comment to this file

src/assets/graphics/grass.png

Added
New image
Add a comment to this file

src/assets/graphics/pressanykey.gif

Added
New image
Add a comment to this file

src/assets/graphics/ship.gif

Added
New image
Add a comment to this file

src/assets/graphics/shot.gif

Added
New image
Add a comment to this file

src/assets/graphics/youwin.gif

Added
New image

src/com/xardov/lwjgl/testbed/Main.java

+package com.xardov.lwjgl.testbed;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.DisplayMode;
+import org.lwjgl.opengl.GL11;
+
+public class Main
+{
+	private final int WIDTH = 640, HEIGHT = 480;
+	private final int FPS = 60;
+	
+	public boolean paused = false;
+	
+	Sprite sprite = new Sprite(WIDTH / 2, HEIGHT / 2);
+	
+	public void init()
+	{
+		try 
+		{
+			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
+			Display.create();
+		} catch (LWJGLException e) 
+		{
+			e.printStackTrace();
+			System.exit(0);
+		}
+		
+		GL11.glMatrixMode(GL11.GL_PROJECTION);
+		GL11.glLoadIdentity();
+		GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
+		GL11.glMatrixMode(GL11.GL_MODELVIEW);
+		
+		try 
+		{
+			sprite.loadImage("assets/graphics/alien.png", 0, 0);
+		} catch (Exception e) 
+		{
+			e.printStackTrace();
+			System.exit(0);
+		}
+		
+		while(!Display.isCloseRequested())
+		{
+			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+			
+			render();
+			
+			Display.update();
+		}
+		
+		Display.destroy();
+	}
+	
+	public void render()
+	{
+		sprite.render();
+	}
+	
+	public static void main(String[] args) 
+	{
+		Main main = new Main();
+		main.init();
+	}
+
+}

src/com/xardov/lwjgl/testbed/Sprite.java

+package com.xardov.lwjgl.testbed;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.lwjgl.opengl.GL11;
+import org.newdawn.slick.opengl.Texture;
+import org.newdawn.slick.opengl.TextureLoader;
+import org.newdawn.slick.util.ResourceLoader;
+
+public class Sprite 
+{
+	Texture bodyTexture;
+	
+	public float x, y; 
+	private int width, height;
+	
+	public Sprite(int x, int y)
+	{
+		this.x = x;
+		this.y = y;
+	}
+	
+	public void loadImage(String filePath, int width, int height) throws IOException
+	{		
+		bodyTexture = TextureLoader.getTexture("PNG", Main.class.getClassLoader().
+														getResourceAsStream(filePath));
+		
+		this.width = width;
+		this.height = height;
+	}
+	
+	public void render()
+	{
+		GL11.glPushMatrix();
+		
+		bodyTexture.bind();
+		
+		GL11.glBegin(GL11.GL_QUADS);
+		{
+			GL11.glColor3f(1.0f, 1.0f, 1.0f);
+			
+			GL11.glTexCoord2f(0, 0);
+			GL11.glVertex2f(x, y);
+			
+			GL11.glTexCoord2f(1, 0);
+			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), y);
+			
+			GL11.glTexCoord2f(0, 1);
+			GL11.glVertex2f(x, y - bodyTexture.getTextureHeight());
+			
+			GL11.glTexCoord2f(1, 1);
+			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), 
+							y - bodyTexture.getTextureHeight());
+		}
+		GL11.glEnd();
+		
+		drawHitbox(0, 0, x + bodyTexture.getWidth(), y - bodyTexture.getHeight());
+		
+		GL11.glPopMatrix();
+	}
+	
+	private void drawHitbox(float x1, float y1, float x2, float y2)
+	{
+		GL11.glBegin(GL11.GL_LINES);
+		{
+			GL11.glColor3f(1.0f, 0.0f, 0.0f);
+			
+			GL11.glVertex2f(x1, y1);
+			GL11.glVertex2f(x2, y2);
+		}
+		GL11.glEnd();
+	}
+}

src/com/xardov/terrain/gen/Main.java

+package com.xardov.terrain.gen;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.DisplayMode;
+import org.lwjgl.opengl.GL11;
+
+public class Main
+{
+	private final int WIDTH = 640, HEIGHT = 480;
+	private final int FPS = 60;
+	
+	public boolean paused = false;
+	
+	public Map map = new Map();
+	
+	public void init()
+	{
+		try 
+		{
+			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
+			Display.create();
+		} catch (LWJGLException e) 
+		{
+			e.printStackTrace();
+			System.exit(0);
+		}
+		
+		GL11.glMatrixMode(GL11.GL_PROJECTION);
+		GL11.glLoadIdentity();
+		GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
+		GL11.glMatrixMode(GL11.GL_MODELVIEW);
+		
+		map.init();
+		
+		while(!Display.isCloseRequested())
+		{
+			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+			
+			render();
+			
+			Display.update();
+		}
+		
+		Display.destroy();
+	}
+	
+	public void render()
+	{
+		map.render();
+	}
+	
+	public static void main(String[] args) 
+	{
+		Main main = new Main();
+		main.init();
+	}
+
+}

src/com/xardov/terrain/gen/Map.java

+package com.xardov.terrain.gen;
+
+public class Map 
+{
+	public static final int WIDTH = 40, HEIGHT = 30;
+	public static final int TILE_WIDTH = 16;
+	
+	public Tile terrain[][] = new Tile[WIDTH][HEIGHT];
+	
+	public Map()
+	{
+	}
+	
+	public void init()
+	{
+		genTerrain();
+	}
+	
+	public void genTerrain()
+	{
+		for(int i = 0; i < WIDTH; i++)
+			for(int k = 0; k < HEIGHT; k++)
+			{
+				terrain[i][k] = new Tile(i * TILE_WIDTH, k * TILE_WIDTH);
+			}
+	}
+	
+	public void render()
+	{
+		for(int i = 0; i < WIDTH; i++)
+			for(int k = 0; k < HEIGHT; k++)
+			{
+				terrain[i][k].render();
+			}
+	}
+}

src/com/xardov/terrain/gen/Sprite.java

+package com.xardov.terrain.gen;
+
+import java.io.IOException;
+
+import org.lwjgl.opengl.GL11;
+import org.newdawn.slick.opengl.Texture;
+import org.newdawn.slick.opengl.TextureLoader;
+
+public class Sprite 
+{
+	Texture bodyTexture;
+	
+	public float x, y; 
+	private int width, height;
+	
+	public Sprite(int x, int y)
+	{
+		this.x = x;
+		this.y = y;
+	}
+	
+	public void loadImage(String filePath, int width, int height) throws IOException
+	{		
+		bodyTexture = TextureLoader.getTexture("PNG", Main.class.getClassLoader().
+														getResourceAsStream(filePath));
+		
+		this.width = width;
+		this.height = height;
+	}
+	
+	public void render()
+	{
+		GL11.glPushMatrix();
+		
+		bodyTexture.bind();
+		
+		GL11.glBegin(GL11.GL_QUADS);
+		{
+			GL11.glColor3f(1.0f, 1.0f, 1.0f);
+			
+			GL11.glTexCoord2f(0, 0);
+			GL11.glVertex2f(x, y);
+			
+			GL11.glTexCoord2f(1, 0);
+			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), y);
+			
+			GL11.glTexCoord2f(0, 1);
+			GL11.glVertex2f(x, y - bodyTexture.getTextureHeight());
+			
+			GL11.glTexCoord2f(1, 1);
+			GL11.glVertex2f(x + bodyTexture.getTextureWidth(), 
+							y - bodyTexture.getTextureHeight());
+		}
+		GL11.glEnd();
+		
+		//drawHitbox(0, 0, x + bodyTexture.getWidth(), y - bodyTexture.getHeight());
+		
+		GL11.glPopMatrix();
+	}
+	
+	private void drawHitbox(float x1, float y1, float x2, float y2)
+	{
+		GL11.glBegin(GL11.GL_LINES);
+		{
+			GL11.glColor3f(1.0f, 0.0f, 0.0f);
+			
+			GL11.glVertex2f(x1, y1);
+			GL11.glVertex2f(x2, y2);
+		}
+		GL11.glEnd();
+	}
+}

src/com/xardov/terrain/gen/Tile.java

+package com.xardov.terrain.gen;
+
+public class Tile extends Sprite
+{
+	public Tile(int x, int y)
+	{
+		super(x, y);
+		
+		try 
+		{
+			loadImage("assets/graphics/grass.png", 16, 16);
+		} catch (Exception e) 
+		{
+			e.printStackTrace();
+			System.exit(0);
+		}
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.