mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
added sources for Slick
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
84
lib/slick-source/org/newdawn/slick/tests/AlphaMapTest.java
Normal file
84
lib/slick-source/org/newdawn/slick/tests/AlphaMapTest.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test to demonstrate world clipping as opposed to screen clipping
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class AlphaMapTest extends BasicGame {
|
||||
/** The alpha map being applied */
|
||||
private Image alphaMap;
|
||||
/** The texture to apply over the top */
|
||||
private Image textureMap;
|
||||
|
||||
/**
|
||||
* Create a new tester for the clip plane based clipping
|
||||
*/
|
||||
public AlphaMapTest() {
|
||||
super("AlphaMap Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
alphaMap = new Image("testdata/alphamap.png");
|
||||
textureMap = new Image("testdata/grass.png");
|
||||
container.getGraphics().setBackground(Color.black);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.clearAlphaMap();
|
||||
g.setDrawMode(Graphics.MODE_NORMAL);
|
||||
textureMap.draw(10,50);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(290,40,200,200);
|
||||
g.setColor(Color.white);
|
||||
// write only alpha
|
||||
g.setDrawMode(Graphics.MODE_ALPHA_MAP);
|
||||
alphaMap.draw(300,50);
|
||||
g.setDrawMode(Graphics.MODE_ALPHA_BLEND);
|
||||
textureMap.draw(300,50);
|
||||
g.setDrawMode(Graphics.MODE_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new AlphaMapTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
121
lib/slick-source/org/newdawn/slick/tests/AnimationTest.java
Normal file
121
lib/slick-source/org/newdawn/slick/tests/AnimationTest.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.Animation;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.SpriteSheet;
|
||||
|
||||
/**
|
||||
* A test for basic animation rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class AnimationTest extends BasicGame {
|
||||
/** The animation loaded */
|
||||
private Animation animation;
|
||||
/** The limited animation loaded */
|
||||
private Animation limited;
|
||||
/** The manual update animation loaded */
|
||||
private Animation manual;
|
||||
/** The animation loaded */
|
||||
private Animation pingPong;
|
||||
/** The container */
|
||||
private GameContainer container;
|
||||
/** Start limited counter */
|
||||
private int start = 5000;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public AnimationTest() {
|
||||
super("Animation Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
SpriteSheet sheet = new SpriteSheet("testdata/homeranim.png", 36, 65);
|
||||
animation = new Animation();
|
||||
for (int i=0;i<8;i++) {
|
||||
animation.addFrame(sheet.getSprite(i,0), 150);
|
||||
}
|
||||
limited = new Animation();
|
||||
for (int i=0;i<8;i++) {
|
||||
limited.addFrame(sheet.getSprite(i,0), 150);
|
||||
}
|
||||
limited.stopAt(7);
|
||||
manual = new Animation(false);
|
||||
for (int i=0;i<8;i++) {
|
||||
manual.addFrame(sheet.getSprite(i,0), 150);
|
||||
}
|
||||
pingPong = new Animation(sheet, 0,0,7,0,true,150,true);
|
||||
pingPong.setPingPong(true);
|
||||
container.getGraphics().setBackground(new Color(0.4f,0.6f,0.6f));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("Space to restart() animation", 100, 50);
|
||||
g.drawString("Til Limited animation: "+start, 100, 500);
|
||||
g.drawString("Hold 1 to move the manually animated", 100, 70);
|
||||
g.drawString("PingPong Frame:"+pingPong.getFrame(), 600, 70);
|
||||
|
||||
g.scale(-1,1);
|
||||
animation.draw(-100,100);
|
||||
animation.draw(-200,100,36*4,65*4);
|
||||
if (start < 0) {
|
||||
limited.draw(-400,100,36*4,65*4);
|
||||
}
|
||||
manual.draw(-600,100,36*4,65*4);
|
||||
pingPong.draw(-700,100,36*2,65*2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
if (container.getInput().isKeyDown(Input.KEY_1)) {
|
||||
manual.update(delta);
|
||||
}
|
||||
if (start >= 0) {
|
||||
start -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new AnimationTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
limited.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
65
lib/slick-source/org/newdawn/slick/tests/AntiAliasTest.java
Normal file
65
lib/slick-source/org/newdawn/slick/tests/AntiAliasTest.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* Test to view the effects of antialiasing on cirles
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class AntiAliasTest extends BasicGame {
|
||||
|
||||
/**
|
||||
* Create the test
|
||||
*/
|
||||
public AntiAliasTest() {
|
||||
super("AntiAlias Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.getGraphics().setBackground(Color.green);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setAntiAlias(true);
|
||||
g.setColor(Color.red);
|
||||
g.drawOval(100,100,100,100);
|
||||
g.fillOval(300,100,100,100);
|
||||
g.setAntiAlias(false);
|
||||
g.setColor(Color.red);
|
||||
g.drawOval(100,300,100,100);
|
||||
g.fillOval(300,300,100,100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new AntiAliasTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
115
lib/slick-source/org/newdawn/slick/tests/BigImageTest.java
Normal file
115
lib/slick-source/org/newdawn/slick/tests/BigImageTest.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.BigImage;
|
||||
import org.newdawn.slick.Color;
|
||||
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.SpriteSheet;
|
||||
|
||||
/**
|
||||
* A test for basic image rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class BigImageTest extends BasicGame {
|
||||
/** The original 1024x768 image loaded */
|
||||
private Image original;
|
||||
/** The image scaled */
|
||||
private Image image;
|
||||
/** The scaled image flipped on the X axis */
|
||||
private Image imageX;
|
||||
/** The scaled image flipped on the Y axis */
|
||||
private Image imageY;
|
||||
/** A sub part of the original image */
|
||||
private Image sub;
|
||||
/** The scaled version of the sub-image */
|
||||
private Image scaledSub;
|
||||
/** The x position to draw at */
|
||||
private float x;
|
||||
/** The y position to draw at */
|
||||
private float y;
|
||||
/** The angle to draw the rortating sub part at */
|
||||
private float ang = 30f;
|
||||
/** A sprite sheet made from the big image */
|
||||
private SpriteSheet bigSheet;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public BigImageTest() {
|
||||
super("Big Image Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
// force a 256 pixel limit for testing
|
||||
original = image = new BigImage("testdata/bigimage.tga", Image.FILTER_NEAREST, 512);
|
||||
sub = image.getSubImage(210,210,200,130);
|
||||
scaledSub = sub.getScaledCopy(2);
|
||||
image = image.getScaledCopy(0.3f);
|
||||
imageX = image.getFlippedCopy(true, false);
|
||||
imageY = imageX.getFlippedCopy(true, true);
|
||||
|
||||
bigSheet = new SpriteSheet(original, 16, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
original.draw(0,0,new Color(1,1,1,0.4f));
|
||||
|
||||
image.draw(x,y);
|
||||
imageX.draw(x+400,y);
|
||||
imageY.draw(x,y+300);
|
||||
scaledSub.draw(x+300,y+300);
|
||||
|
||||
bigSheet.getSprite(7, 5).draw(50,10);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(50,10,64,64);
|
||||
g.rotate(x+400, y+165, ang);
|
||||
g.drawImage(sub, x+300, y+100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new BigImageTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
ang += delta * 0.1f;
|
||||
|
||||
if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
|
||||
x -= delta * 0.1f;
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {
|
||||
x += delta * 0.1f;
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_UP)) {
|
||||
y -= delta * 0.1f;
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_DOWN)) {
|
||||
y += delta * 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.BigImage;
|
||||
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.SpriteSheet;
|
||||
|
||||
/**
|
||||
* A test for big images used as sprites sheets
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class BigSpriteSheetTest extends BasicGame {
|
||||
/** The original 1024x768 image loaded */
|
||||
private Image original;
|
||||
/** A sprite sheet made from the big image */
|
||||
private SpriteSheet bigSheet;
|
||||
/** True if we should use the old method */
|
||||
private boolean oldMethod = true;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public BigSpriteSheetTest() {
|
||||
super("Big SpriteSheet Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
original = new BigImage("testdata/bigimage.tga", Image.FILTER_NEAREST, 256);
|
||||
bigSheet = new SpriteSheet(original, 16, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
if (oldMethod) {
|
||||
for (int x=0;x<43;x++) {
|
||||
for (int y=0;y<27;y++) {
|
||||
bigSheet.getSprite(x, y).draw(10+(x*18),50+(y*18));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bigSheet.startUse();
|
||||
for (int x=0;x<43;x++) {
|
||||
for (int y=0;y<27;y++) {
|
||||
bigSheet.renderInUse(10+(x*18),50+(y*18),x,y);
|
||||
}
|
||||
}
|
||||
bigSheet.endUse();
|
||||
}
|
||||
|
||||
g.drawString("Press space to toggle rendering method",10,30);
|
||||
|
||||
container.getDefaultFont().drawString(10, 100, "TEST");
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new BigSpriteSheetTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
|
||||
oldMethod = !oldMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.CachedRender;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A simple test to show performance gains from cache operations in situtations where
|
||||
* rendering is static and heavy
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CachedRenderTest extends BasicGame {
|
||||
/** The set of operations to be cached */
|
||||
private Runnable operations;
|
||||
/** The cached version of the operations */
|
||||
private CachedRender cached;
|
||||
/** True if we're drawing the cached version */
|
||||
private boolean drawCached;
|
||||
|
||||
/**
|
||||
* Create a new simple test for cached rendering (aka display lists)
|
||||
*/
|
||||
public CachedRenderTest() {
|
||||
super("Cached Render Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(final GameContainer container) throws SlickException {
|
||||
operations = new Runnable() {
|
||||
public void run() {
|
||||
for (int i=0;i<100;i++) {
|
||||
int c = i+100;
|
||||
container.getGraphics().setColor(new Color(c,c,c,c));
|
||||
container.getGraphics().drawOval((i*5)+50,(i*3)+50,100,100);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cached = new CachedRender(operations);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
|
||||
drawCached = !drawCached;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Press space to toggle caching", 10, 130);
|
||||
if (drawCached) {
|
||||
g.drawString("Drawing from cache", 10, 100);
|
||||
cached.render();
|
||||
} else {
|
||||
g.drawString("Drawing direct", 10, 100);
|
||||
operations.run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new CachedRenderTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.CanvasGameContainer;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A test for the AWT Canvas container
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CanvasContainerTest extends BasicGame {
|
||||
/** The TGA image loaded */
|
||||
private Image tga;
|
||||
/** The TGA image loaded */
|
||||
private Image scaleMe;
|
||||
/** The TGA image loaded */
|
||||
private Image scaled;
|
||||
/** The GIF version of the image */
|
||||
private Image gif;
|
||||
/** The image we're currently displaying */
|
||||
private Image image;
|
||||
/** A sub part of the logo image */
|
||||
private Image subImage;
|
||||
/** The current rotation of our test image */
|
||||
private float rot;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public CanvasContainerTest() {
|
||||
super("Canvas Container Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = tga = new Image("testdata/logo.tga");
|
||||
scaleMe = new Image("testdata/logo.tga", true, Image.FILTER_NEAREST);
|
||||
gif = new Image("testdata/logo.gif");
|
||||
scaled = gif.getScaledCopy(120, 120);
|
||||
subImage = image.getSubImage(200,0,70,260);
|
||||
rot = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
image.draw(0,0);
|
||||
image.draw(500,0,200,100);
|
||||
scaleMe.draw(500,100,200,100);
|
||||
scaled.draw(400,500);
|
||||
Image flipped = scaled.getFlippedCopy(true, false);
|
||||
flipped.draw(520,500);
|
||||
Image flipped2 = flipped.getFlippedCopy(false, true);
|
||||
flipped2.draw(520,380);
|
||||
Image flipped3 = flipped2.getFlippedCopy(true, false);
|
||||
flipped3.draw(400,380);
|
||||
|
||||
for (int i=0;i<3;i++) {
|
||||
subImage.draw(200+(i*30),300);
|
||||
}
|
||||
|
||||
g.translate(500, 200);
|
||||
g.rotate(50, 50, rot);
|
||||
g.scale(0.3f,0.3f);
|
||||
image.draw();
|
||||
g.resetTransform();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
rot += delta * 0.1f;
|
||||
if (rot > 360) {
|
||||
rot -= 360;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
CanvasGameContainer container = new CanvasGameContainer(new CanvasContainerTest());
|
||||
|
||||
Frame frame = new Frame("Test");
|
||||
frame.setLayout(new GridLayout(1,2));
|
||||
frame.setSize(500,500);
|
||||
frame.add(container);
|
||||
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
frame.setVisible(true);
|
||||
container.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_SPACE) {
|
||||
if (image == gif) {
|
||||
image = tga;
|
||||
} else {
|
||||
image = gif;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
lib/slick-source/org/newdawn/slick/tests/CanvasSizeTest.java
Normal file
76
lib/slick-source/org/newdawn/slick/tests/CanvasSizeTest.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.CanvasGameContainer;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* Quick test to confirm canvas size is reported correctly
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CanvasSizeTest extends BasicGame {
|
||||
|
||||
/**
|
||||
* Create test
|
||||
*/
|
||||
public CanvasSizeTest() {
|
||||
super("Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
System.out.println(container.getWidth() + ", " + container.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the test
|
||||
*
|
||||
* @param args The command line arguments passed in (none honoured)
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
CanvasGameContainer container = new CanvasGameContainer(
|
||||
new CanvasSizeTest());
|
||||
container.setSize(640,480);
|
||||
Frame frame = new Frame("Test");
|
||||
frame.setLayout(new GridLayout(1,2));
|
||||
frame.add(container);
|
||||
frame.pack();
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
frame.setVisible(true);
|
||||
|
||||
container.start();
|
||||
} catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
111
lib/slick-source/org/newdawn/slick/tests/ClipTest.java
Normal file
111
lib/slick-source/org/newdawn/slick/tests/ClipTest.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test to demonstrate world clipping as opposed to screen clipping
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ClipTest extends BasicGame {
|
||||
|
||||
/** The current angle of rotation */
|
||||
private float ang = 0;
|
||||
/** True if we're showing world clipping */
|
||||
private boolean world;
|
||||
/** True if we're showing screen clipping */
|
||||
private boolean clip;
|
||||
|
||||
/**
|
||||
* Create a new tester for the clip plane based clipping
|
||||
*/
|
||||
public ClipTest() {
|
||||
super("Clip Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
ang += delta * 0.01f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("1 - No Clipping", 100, 10);
|
||||
g.drawString("2 - Screen Clipping", 100, 30);
|
||||
g.drawString("3 - World Clipping", 100, 50);
|
||||
|
||||
if (world) {
|
||||
g.drawString("WORLD CLIPPING ENABLED", 200, 80);
|
||||
}
|
||||
if (clip) {
|
||||
g.drawString("SCREEN CLIPPING ENABLED", 200, 80);
|
||||
}
|
||||
|
||||
g.rotate(400, 400, ang);
|
||||
if (world) {
|
||||
g.setWorldClip(350,302,100,196);
|
||||
}
|
||||
if (clip) {
|
||||
g.setClip(350,302,100,196);
|
||||
}
|
||||
g.setColor(Color.red);
|
||||
g.fillOval(300,300,200,200);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(390,200,20,400);
|
||||
|
||||
g.clearClip();
|
||||
g.clearWorldClip();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_1) {
|
||||
world = false;
|
||||
clip = false;
|
||||
}
|
||||
if (key == Input.KEY_2) {
|
||||
world = false;
|
||||
clip = true;
|
||||
}
|
||||
if (key == Input.KEY_3) {
|
||||
world = true;
|
||||
clip = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ClipTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test to demonstrate world clipping as opposed to screen clipping
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CopyAreaAlphaTest extends BasicGame {
|
||||
/** The texture to apply over the top */
|
||||
private Image textureMap;
|
||||
/** The copied image */
|
||||
private Image copy;
|
||||
|
||||
/**
|
||||
* Create a new tester for the clip plane based clipping
|
||||
*/
|
||||
public CopyAreaAlphaTest() {
|
||||
super("CopyArea Alpha Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
textureMap = new Image("testdata/grass.png");
|
||||
container.getGraphics().setBackground(Color.black);
|
||||
copy = new Image(100,100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.clearAlphaMap();
|
||||
g.setDrawMode(Graphics.MODE_NORMAL);
|
||||
g.setColor(Color.white);
|
||||
g.fillOval(100,100,150,150);
|
||||
textureMap.draw(10,50);
|
||||
|
||||
g.copyArea(copy, 100,100);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(300,100,200,200);
|
||||
copy.draw(350,150);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new CopyAreaAlphaTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
103
lib/slick-source/org/newdawn/slick/tests/CurveTest.java
Normal file
103
lib/slick-source/org/newdawn/slick/tests/CurveTest.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Curve;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Vector2f;
|
||||
|
||||
/**
|
||||
* A rudimentry test of loading SVG from inkscape
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CurveTest extends BasicGame {
|
||||
/** The curve being rendered */
|
||||
private Curve curve;
|
||||
/** The start point of the curve */
|
||||
private Vector2f p1 = new Vector2f(100,300);
|
||||
/** The first control point */
|
||||
private Vector2f c1 = new Vector2f(100,100);
|
||||
/** The second control point */
|
||||
private Vector2f c2 = new Vector2f(300,100);
|
||||
/** The end point of the curve */
|
||||
private Vector2f p2 = new Vector2f(300,300);
|
||||
|
||||
/** The polygon drawn next done */
|
||||
private Polygon poly;
|
||||
|
||||
/**
|
||||
* Create a new test for inkscape loading
|
||||
*/
|
||||
public CurveTest() {
|
||||
super("Curve Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.getGraphics().setBackground(Color.white);
|
||||
|
||||
curve = new Curve(p2,c2,c1,p1);
|
||||
poly = new Polygon();
|
||||
poly.addPoint(500,200);
|
||||
poly.addPoint(600,200);
|
||||
poly.addPoint(700,300);
|
||||
poly.addPoint(400,300);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a marker for a given point
|
||||
*
|
||||
* @param g The graphics context on which to draw
|
||||
* @param p The point to draw
|
||||
*/
|
||||
private void drawMarker(Graphics g, Vector2f p) {
|
||||
g.drawRect(p.x-5, p.y-5,10,10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.gray);
|
||||
drawMarker(g, p1);
|
||||
drawMarker(g, p2);
|
||||
g.setColor(Color.red);
|
||||
drawMarker(g, c1);
|
||||
drawMarker(g, c2);
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.draw(curve);
|
||||
g.fill(curve);
|
||||
|
||||
g.draw(poly);
|
||||
g.fill(poly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our simple test
|
||||
*
|
||||
* @param argv The arguments passed in
|
||||
*/
|
||||
public static void main(String argv[]) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new CurveTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.Music;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.Sound;
|
||||
import org.newdawn.slick.loading.DeferredResource;
|
||||
import org.newdawn.slick.loading.LoadingList;
|
||||
|
||||
/**
|
||||
* A test for deferred loading. Each of the resources is requested then the loading list
|
||||
* is cycled to actual perform the resource allowing the rendering to be performed in
|
||||
* between
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class DeferredLoadingTest extends BasicGame {
|
||||
/** The music that will be played on load completion */
|
||||
private Music music;
|
||||
/** The sound that will be played on load completion */
|
||||
private Sound sound;
|
||||
/** The image that will be shown on load completion */
|
||||
private Image image;
|
||||
/** The font that will be rendered on load completion */
|
||||
private Font font;
|
||||
/** The next resource to load */
|
||||
private DeferredResource nextResource;
|
||||
/** True if we've loaded all the resources and started rendereing */
|
||||
private boolean started;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public DeferredLoadingTest() {
|
||||
super("Deferred Loading Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
LoadingList.setDeferredLoading(true);
|
||||
|
||||
new Sound("testdata/cbrown01.wav");
|
||||
new Sound("testdata/engine.wav");
|
||||
sound = new Sound("testdata/restart.ogg");
|
||||
new Music("testdata/testloop.ogg");
|
||||
music = new Music("testdata/SMB-X.XM");
|
||||
|
||||
new Image("testdata/cursor.png");
|
||||
new Image("testdata/cursor.tga");
|
||||
new Image("testdata/cursor.png");
|
||||
new Image("testdata/cursor.png");
|
||||
new Image("testdata/dungeontiles.gif");
|
||||
new Image("testdata/logo.gif");
|
||||
image = new Image("testdata/logo.tga");
|
||||
new Image("testdata/logo.png");
|
||||
new Image("testdata/rocket.png");
|
||||
new Image("testdata/testpack.png");
|
||||
|
||||
font = new AngelCodeFont("testdata/demo.fnt", "testdata/demo_00.tga");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
if (nextResource != null) {
|
||||
g.drawString("Loading: "+nextResource.getDescription(), 100, 100);
|
||||
}
|
||||
|
||||
int total = LoadingList.get().getTotalResources();
|
||||
int loaded = LoadingList.get().getTotalResources() - LoadingList.get().getRemainingResources();
|
||||
|
||||
float bar = loaded / (float) total;
|
||||
g.fillRect(100,150,loaded*40,20);
|
||||
g.drawRect(100,150,total*40,20);
|
||||
|
||||
if (started) {
|
||||
image.draw(100,200);
|
||||
font.drawString(100,500,"LOADING COMPLETE");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
if (nextResource != null) {
|
||||
try {
|
||||
nextResource.load();
|
||||
// slow down loading for example purposes
|
||||
try { Thread.sleep(50); } catch (Exception e) {}
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load: "+nextResource.getDescription(), e);
|
||||
}
|
||||
|
||||
nextResource = null;
|
||||
}
|
||||
|
||||
if (LoadingList.get().getRemainingResources() > 0) {
|
||||
nextResource = LoadingList.get().getNext();
|
||||
} else {
|
||||
if (!started) {
|
||||
started = true;
|
||||
music.loop();
|
||||
sound.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new DeferredLoadingTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
}
|
||||
106
lib/slick-source/org/newdawn/slick/tests/DistanceFieldTest.java
Normal file
106
lib/slick-source/org/newdawn/slick/tests/DistanceFieldTest.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test to demonstrate distance fields generated by Hiero being applied
|
||||
* to scaled fonts
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class DistanceFieldTest extends BasicGame {
|
||||
/** The font */
|
||||
private AngelCodeFont font;
|
||||
|
||||
/**
|
||||
* Create a new tester for the clip plane based clipping
|
||||
*/
|
||||
public DistanceFieldTest() {
|
||||
super("DistanceMapTest Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
font = new AngelCodeFont("testdata/distance.fnt", "testdata/distance-dis.png");
|
||||
container.getGraphics().setBackground(Color.black);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
String text = "abc";
|
||||
font.drawString(610,100,text);
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
|
||||
font.drawString(610,150,text);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
g.translate(-50,-130);
|
||||
g.scale(10,10);
|
||||
font.drawString(0,0,text);
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
|
||||
font.drawString(0,26,text);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
g.resetTransform();
|
||||
g.setColor(Color.lightGray);
|
||||
g.drawString("Original Size on Sheet", 620, 210);
|
||||
g.drawString("10x Scale Up", 40, 575);
|
||||
|
||||
g.setColor(Color.darkGray);
|
||||
g.drawRect(40, 40, 560,530);
|
||||
g.drawRect(610, 105, 150,100);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString("512x512 Font Sheet", 620, 300);
|
||||
g.drawString("NEHE Charset", 620, 320);
|
||||
g.drawString("4096x4096 (8x) Source Image", 620, 340);
|
||||
g.drawString("ScanSize = 20", 620, 360);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new DistanceFieldTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* The double click testing
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class DoubleClickTest extends BasicGame {
|
||||
|
||||
/**
|
||||
* Create the test game
|
||||
*/
|
||||
public DoubleClickTest() {
|
||||
super("Double Click Test");
|
||||
}
|
||||
|
||||
/** The test message to display */
|
||||
private String message = "Click or Double Click";
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.drawString(message, 100, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test, not used here
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new DoubleClickTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseClicked(int, int, int, int)
|
||||
*/
|
||||
public void mouseClicked(int button, int x, int y, int clickCount) {
|
||||
if (clickCount == 1) {
|
||||
message = "Single Click: "+button+" "+x+","+y;
|
||||
}
|
||||
if (clickCount == 2) {
|
||||
message = "Double Click: "+button+" "+x+","+y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.particles.ConfigurableEmitter;
|
||||
import org.newdawn.slick.particles.ParticleIO;
|
||||
import org.newdawn.slick.particles.ParticleSystem;
|
||||
|
||||
/**
|
||||
* A test for duplicating a ConfigurableEmitter several times
|
||||
* @author Tommy
|
||||
*
|
||||
*/
|
||||
public class DuplicateEmitterTest extends BasicGame {
|
||||
|
||||
/** the game container */
|
||||
private GameContainer container;
|
||||
/** the particle system which contains an explosion emitter which we want to duplicate */
|
||||
private ParticleSystem explosionSystem;
|
||||
/** The original emitter we've duplicated */
|
||||
private ConfigurableEmitter explosionEmitter;
|
||||
|
||||
/**
|
||||
* Create a new DuplicateEmitterTest
|
||||
*/
|
||||
public DuplicateEmitterTest() {
|
||||
super("DuplicateEmitterTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* load ressources (the particle system) and create our duplicate emitters
|
||||
* and place them nicely on the screen
|
||||
* @param container The surrounding game container
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
try {
|
||||
// load the particle system containing our explosion emitter
|
||||
explosionSystem = ParticleIO.loadConfiguredSystem("testdata/endlessexplosion.xml");
|
||||
// get the emitter, it's the first (and only one) in this particle system
|
||||
explosionEmitter = (ConfigurableEmitter) explosionSystem.getEmitter(0);
|
||||
// set the original emitter in the middle of the screen at the top
|
||||
explosionEmitter.setPosition(400,100);
|
||||
// create 5 duplicate emitters
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// a single duplicate of the first emitter is created here
|
||||
ConfigurableEmitter newOne = explosionEmitter.duplicate();
|
||||
// we might get null as a result - protect against that
|
||||
if (newOne == null)
|
||||
throw new SlickException("Failed to duplicate explosionEmitter");
|
||||
// give the new emitter a new unique name
|
||||
newOne.name = newOne.name + "_" + i;
|
||||
// place it somewhere on a row below the original emitter
|
||||
newOne.setPosition((i+1)* (800/6), 400);
|
||||
// and add it to the original particle system to get the new emitter updated and rendered
|
||||
explosionSystem.addEmitter(newOne);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load particle systems", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
explosionSystem.update(delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
explosionSystem.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
if (key == Input.KEY_K) {
|
||||
explosionEmitter.wrapUp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test, not used here
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new DuplicateEmitterTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
85
lib/slick-source/org/newdawn/slick/tests/FlashTest.java
Normal file
85
lib/slick-source/org/newdawn/slick/tests/FlashTest.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A test for image flashes
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FlashTest extends BasicGame {
|
||||
/** The TGA image loaded */
|
||||
private Image image;
|
||||
/** True if the image is rendered flashed */
|
||||
private boolean flash;
|
||||
/** The container for the test */
|
||||
private GameContainer container;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public FlashTest() {
|
||||
super("Flash Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
image = new Image("testdata/logo.tga");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("Press space to toggle",10,50);
|
||||
if (flash) {
|
||||
image.draw(100,100);
|
||||
} else {
|
||||
image.drawFlash(100,100,image.getWidth(), image.getHeight(), new Color(1,0,1f,1f));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new FlashTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_SPACE) {
|
||||
flash = !flash;
|
||||
}
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test of the font rendering capabilities
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FontPerformanceTest extends BasicGame {
|
||||
/** The font we're going to use to render */
|
||||
private AngelCodeFont font;
|
||||
|
||||
/** The test text */
|
||||
private String text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin bibendum. Aliquam ac sapien a elit congue iaculis. Quisque et justo quis mi mattis euismod. Donec elementum, mi quis aliquet varius, nisi leo volutpat magna, quis ultricies eros augue at risus. Integer non magna at lorem sodales molestie. Integer diam nulla, ornare sit amet, mattis quis, euismod et, mauris. Proin eget tellus non nisl mattis laoreet. Nunc at nunc id elit pretium tempor. Duis vulputate, nibh eget rhoncus eleifend, tellus lectus sollicitudin mi, rhoncus tincidunt nisi massa vitae ipsum. Praesent tellus diam, luctus ut, eleifend nec, auctor et, orci. Praesent eu elit. Pellentesque ante orci, volutpat placerat, ornare eget, cursus sit amet, eros. Duis pede sapien, euismod a, volutpat pellentesque, convallis eu, mauris. Nunc eros. Ut eu risus et felis laoreet viverra. Curabitur a metus.";
|
||||
/** The text broken into lines */
|
||||
private ArrayList lines = new ArrayList();
|
||||
/** True if the text is visible */
|
||||
private boolean visible = true;
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public FontPerformanceTest() {
|
||||
super("Font Performance Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
font = new AngelCodeFont("testdata/perffont.fnt","testdata/perffont.png");
|
||||
|
||||
for (int j=0;j<2;j++) {
|
||||
int lineLen = 90;
|
||||
for (int i=0;i<text.length();i+=lineLen) {
|
||||
if (i+lineLen > text.length()) {
|
||||
lineLen = text.length() - i;
|
||||
}
|
||||
|
||||
lines.add(text.substring(i, i+lineLen));
|
||||
}
|
||||
lines.add("");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setFont(font);
|
||||
|
||||
if (visible) {
|
||||
for (int i=0;i<lines.size();i++) {
|
||||
font.drawString(10, 50+(i*20),(String) lines.get(i),i > 10 ? Color.red : Color.green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
visible = !visible;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new FontPerformanceTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
106
lib/slick-source/org/newdawn/slick/tests/FontTest.java
Normal file
106
lib/slick-source/org/newdawn/slick/tests/FontTest.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
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.util.Log;
|
||||
|
||||
/**
|
||||
* A test of the font rendering capabilities
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FontTest extends BasicGame {
|
||||
/** The font we're going to use to render */
|
||||
private AngelCodeFont font;
|
||||
/** The font we're going to use to render */
|
||||
private AngelCodeFont font2;
|
||||
/** The image of the font to compare against */
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public FontTest() {
|
||||
super("Font Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
font = new AngelCodeFont("testdata/demo2.fnt","testdata/demo2_00.tga");
|
||||
font2 = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
|
||||
image = new Image("testdata/demo2_00.tga", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
font.drawString(80, 5, "A Font Example", Color.red);
|
||||
font.drawString(100, 32, "We - AV - Here is a more complete line that hopefully");
|
||||
font.drawString(100, 36 + font.getHeight("We Here is a more complete line that hopefully"),
|
||||
"will show some kerning.");
|
||||
|
||||
font2.drawString(80, 85, "A Font Example", Color.red);
|
||||
font2.drawString(100, 132, "We - AV - Here is a more complete line that hopefully");
|
||||
font2.drawString(100, 136 + font2.getHeight("We - Here is a more complete line that hopefully"),
|
||||
"will show some kerning.");
|
||||
image.draw(100,400);
|
||||
|
||||
String testStr = "Testing Font";
|
||||
font2.drawString(100, 300, testStr);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(100,300+font2.getYOffset(testStr),font2.getWidth(testStr),font2.getHeight(testStr)-font2.getYOffset(testStr));
|
||||
font.drawString(500, 300, testStr);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(500,300+font.getYOffset(testStr),font.getWidth(testStr),font.getHeight(testStr)-font.getYOffset(testStr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
try {
|
||||
container.setDisplayMode(640, 480, false);
|
||||
} catch (SlickException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The container we're using */
|
||||
private static AppGameContainer container;
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
container = new AppGameContainer(new FontTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
159
lib/slick-source/org/newdawn/slick/tests/GUITest.java
Normal file
159
lib/slick-source/org/newdawn/slick/tests/GUITest.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
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.gui.AbstractComponent;
|
||||
import org.newdawn.slick.gui.ComponentListener;
|
||||
import org.newdawn.slick.gui.MouseOverArea;
|
||||
import org.newdawn.slick.gui.TextField;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* A test for the GUI components available in Slick. Very simple stuff
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GUITest extends BasicGame implements ComponentListener {
|
||||
/** The image being rendered */
|
||||
private Image image;
|
||||
/** The areas defined */
|
||||
private MouseOverArea[] areas = new MouseOverArea[4];
|
||||
/** The game container */
|
||||
private GameContainer container;
|
||||
/** The message to display */
|
||||
private String message = "Demo Menu System with stock images";
|
||||
/** The text field */
|
||||
private TextField field;
|
||||
/** The text field */
|
||||
private TextField field2;
|
||||
/** The background image */
|
||||
private Image background;
|
||||
/** The font used to render */
|
||||
private Font font;
|
||||
/** The container */
|
||||
private AppGameContainer app;
|
||||
|
||||
/**
|
||||
* Create a new test of GUI rendering
|
||||
*/
|
||||
public GUITest() {
|
||||
super("GUI Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
if (container instanceof AppGameContainer) {
|
||||
app = (AppGameContainer) container;
|
||||
app.setIcon("testdata/icon.tga");
|
||||
}
|
||||
|
||||
font = new AngelCodeFont("testdata/demo2.fnt","testdata/demo2_00.tga");
|
||||
field = new TextField(container, font, 150,20,500,35, new ComponentListener() {
|
||||
public void componentActivated(AbstractComponent source) {
|
||||
message = "Entered1: "+field.getText();
|
||||
field2.setFocus(true);
|
||||
}
|
||||
});
|
||||
field2 = new TextField(container, font, 150,70,500,35,new ComponentListener() {
|
||||
public void componentActivated(AbstractComponent source) {
|
||||
message = "Entered2: "+field2.getText();
|
||||
field.setFocus(true);
|
||||
}
|
||||
});
|
||||
field2.setBorderColor(Color.red);
|
||||
|
||||
this.container = container;
|
||||
|
||||
image = new Image("testdata/logo.tga");
|
||||
background = new Image("testdata/dungeontiles.gif");
|
||||
container.setMouseCursor("testdata/cursor.tga", 0, 0);
|
||||
|
||||
for (int i=0;i<4;i++) {
|
||||
areas[i] = new MouseOverArea(container, image, 300, 100 + (i*100), 200, 90, this);
|
||||
areas[i].setNormalColor(new Color(1,1,1,0.8f));
|
||||
areas[i].setMouseOverColor(new Color(1,1,1,0.9f));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
background.draw(0, 0, 800, 500);
|
||||
|
||||
for (int i=0;i<4;i++) {
|
||||
areas[i].render(container, g);
|
||||
}
|
||||
field.render(container, g);
|
||||
field2.render(container, g);
|
||||
|
||||
g.setFont(font);
|
||||
g.drawString(message, 200, 550);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_F2) {
|
||||
app.setDefaultMouseCursor();
|
||||
}
|
||||
if (key == Input.KEY_F1) {
|
||||
if (app != null) {
|
||||
try {
|
||||
app.setDisplayMode(640,480,false);
|
||||
} catch (SlickException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new GUITest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.gui.ComponentListener#componentActivated(org.newdawn.slick.gui.AbstractComponent)
|
||||
*/
|
||||
public void componentActivated(AbstractComponent source) {
|
||||
System.out.println("ACTIVL : "+source);
|
||||
for (int i=0;i<4;i++) {
|
||||
if (source == areas[i]) {
|
||||
message = "Option "+(i+1)+" pressed!";
|
||||
}
|
||||
}
|
||||
if (source == field2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
305
lib/slick-source/org/newdawn/slick/tests/GeomAccuracyTest.java
Normal file
305
lib/slick-source/org/newdawn/slick/tests/GeomAccuracyTest.java
Normal file
@@ -0,0 +1,305 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
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.Ellipse;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.RoundedRectangle;
|
||||
|
||||
/**
|
||||
* A simple graphics test for the context allowing vector based graphics
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GeomAccuracyTest extends BasicGame {
|
||||
/** The container holding this test */
|
||||
private GameContainer container;
|
||||
|
||||
/** The Geometry color */
|
||||
private Color geomColor;
|
||||
|
||||
/** The overlay color */
|
||||
private Color overlayColor;
|
||||
|
||||
/** Indicates overlay should be hidden */
|
||||
private boolean hideOverlay;
|
||||
|
||||
/** The current color pair id */
|
||||
private int colorIndex;
|
||||
|
||||
/** The current test taking place */
|
||||
private int curTest;
|
||||
|
||||
/** The number of tests to do */
|
||||
private static final int NUMTESTS = 3;
|
||||
|
||||
/** An image used to magnify where the mouse is */
|
||||
private Image magImage;
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public GeomAccuracyTest() {
|
||||
super("Geometry Accuracy Tests");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
geomColor = Color.magenta;
|
||||
overlayColor = Color.white;
|
||||
|
||||
magImage = new Image(21, 21);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
|
||||
String text = new String();
|
||||
|
||||
switch(curTest) {
|
||||
|
||||
case 0:
|
||||
text = "Rectangles";
|
||||
rectTest(g);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
text = "Ovals";
|
||||
ovalTest(g);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
text ="Arcs";
|
||||
arcTest(g);
|
||||
break;
|
||||
}
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Press T to toggle overlay", 200, 55);
|
||||
g.drawString("Press N to switch tests", 200, 35);
|
||||
g.drawString("Press C to cycle drawing colors", 200, 15);
|
||||
g.drawString("Current Test:", 400, 35);
|
||||
g.setColor(Color.blue);
|
||||
g.drawString(text, 485, 35);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Normal:", 10, 150);
|
||||
g.drawString("Filled:", 10, 300);
|
||||
|
||||
g.drawString("Drawn with Graphics context", 125, 400);
|
||||
g.drawString("Drawn using Shapes", 450, 400);
|
||||
|
||||
// Grab our mouse position and copy the screen to our magnified image
|
||||
g.copyArea(magImage, container.getInput().getMouseX() - 10, container.getInput().getMouseY() - 10);
|
||||
magImage.draw(351, 451, 5);
|
||||
g.drawString("Mag Area -", 250, 475);
|
||||
g.setColor(Color.darkGray);
|
||||
g.drawRect(350, 450, 106, 106);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString("NOTE:", 500, 450);
|
||||
g.drawString("lines should be flush with edges", 525, 470);
|
||||
g.drawString("corners should be symetric", 525, 490);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws arcs
|
||||
* @param g
|
||||
*/
|
||||
void arcTest(Graphics g) {
|
||||
|
||||
if(hideOverlay == false) {
|
||||
g.setColor(overlayColor);
|
||||
g.drawLine(198, 100, 198, 198);
|
||||
g.drawLine(100, 198, 198, 198);
|
||||
}
|
||||
|
||||
g.setColor(geomColor);
|
||||
g.drawArc(100, 100, 99, 99, 0, 90);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws ovals
|
||||
* @param g
|
||||
*/
|
||||
void ovalTest(Graphics g) {
|
||||
|
||||
g.setColor(geomColor);
|
||||
g.drawOval(100, 100, 99, 99);
|
||||
g.fillOval(100, 250, 99, 99);
|
||||
|
||||
//Circle circ = new Circle(400, 100, 99);
|
||||
Ellipse elip = new Ellipse(449, 149, 49, 49);
|
||||
g.draw(elip);
|
||||
elip = new Ellipse(449, 299, 49, 49);
|
||||
g.fill(elip);
|
||||
|
||||
if(hideOverlay == false) {
|
||||
g.setColor(overlayColor);
|
||||
g.drawLine(100, 149, 198, 149);
|
||||
g.drawLine(149, 100, 149, 198);
|
||||
|
||||
g.drawLine(100, 149 + 150, 198, 149 + 150);
|
||||
g.drawLine(149, 100 + 150, 149, 198 + 150);
|
||||
|
||||
g.drawLine(100 + 300, 149, 198 + 300, 149);
|
||||
g.drawLine(149 + 300, 100, 149 + 300, 198);
|
||||
|
||||
g.drawLine(100 + 300, 149 + 150, 198 + 300, 149 + 150);
|
||||
g.drawLine(149 + 300, 100 + 150, 149 + 300, 198 + 150);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws rects
|
||||
* @param g
|
||||
*/
|
||||
void rectTest(Graphics g) {
|
||||
|
||||
g.setColor(geomColor);
|
||||
|
||||
// Draw using graphics routines
|
||||
g.drawRect(100, 100, 99, 99);
|
||||
g.fillRect(100, 250, 99, 99);
|
||||
|
||||
g.drawRoundRect(250, 100, 99, 99, 10);
|
||||
g.fillRoundRect(250, 250, 99, 99, 10);
|
||||
|
||||
// Draw using shape routines
|
||||
Rectangle rect = new Rectangle(400, 100, 99, 99);
|
||||
g.draw(rect);
|
||||
rect = new Rectangle(400, 250, 99, 99);
|
||||
g.fill(rect);
|
||||
|
||||
RoundedRectangle rrect = new RoundedRectangle(550, 100, 99, 99, 10);
|
||||
g.draw(rrect);
|
||||
rrect = new RoundedRectangle(550, 250, 99, 99, 10);
|
||||
g.fill(rrect);
|
||||
|
||||
// Draw our overlays
|
||||
if(hideOverlay == false) {
|
||||
g.setColor(overlayColor);
|
||||
|
||||
// Upper row
|
||||
g.drawLine(100, 149, 198, 149);
|
||||
g.drawLine(149, 100, 149, 198);
|
||||
|
||||
g.drawLine(100 + 150, 149, 198 + 150, 149);
|
||||
g.drawLine(149 + 150, 100, 149 + 150, 198);
|
||||
|
||||
g.drawLine(100 + 300, 149, 198 + 300, 149);
|
||||
g.drawLine(149 + 300, 100, 149 + 300, 198);
|
||||
|
||||
g.drawLine(100 + 450, 149, 198 + 450, 149);
|
||||
g.drawLine(149 + 450, 100, 149 + 450, 198);
|
||||
|
||||
// Lower row
|
||||
g.drawLine(100, 149 + 150, 198, 149 + 150);
|
||||
g.drawLine(149, 100 + 150, 149, 198 + 150);
|
||||
|
||||
g.drawLine(100 + 150, 149 + 150, 198 + 150, 149 + 150);
|
||||
g.drawLine(149 + 150, 100 + 150, 149 + 150, 198 + 150);
|
||||
|
||||
g.drawLine(100 + 300, 149 + 150, 198 + 300, 149 + 150);
|
||||
g.drawLine(149 + 300, 100 + 150, 149 + 300, 198 + 150);
|
||||
|
||||
g.drawLine(100 + 450, 149 + 150, 198 + 450, 149 + 150);
|
||||
g.drawLine(149 + 450, 100 + 150, 149 + 450, 198 + 150);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if(key == Input.KEY_N) {
|
||||
curTest++;
|
||||
curTest %= NUMTESTS;
|
||||
}
|
||||
|
||||
if(key == Input.KEY_C) {
|
||||
colorIndex++;
|
||||
|
||||
colorIndex %= 4;
|
||||
setColors();
|
||||
}
|
||||
|
||||
if(key == Input.KEY_T) {
|
||||
hideOverlay = !hideOverlay;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the colors for overlay and geometry
|
||||
*
|
||||
*/
|
||||
private void setColors() {
|
||||
switch(colorIndex)
|
||||
{
|
||||
case 0:
|
||||
overlayColor = Color.white;
|
||||
geomColor = Color.magenta;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
overlayColor = Color.magenta;
|
||||
geomColor = Color.white;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
overlayColor = Color.red;
|
||||
geomColor = Color.green;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
overlayColor = Color.red;
|
||||
geomColor = Color.white;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new GeomAccuracyTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
143
lib/slick-source/org/newdawn/slick/tests/GeomTest.java
Normal file
143
lib/slick-source/org/newdawn/slick/tests/GeomTest.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Circle;
|
||||
import org.newdawn.slick.geom.Ellipse;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.RoundedRectangle;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
import org.newdawn.slick.geom.Transform;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
|
||||
/**
|
||||
* A geomertry test
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GeomTest extends BasicGame {
|
||||
/** The rectangle drawn */
|
||||
private Shape rect = new Rectangle(100,100,100,100);
|
||||
/** The rectangle drawn */
|
||||
private Shape circle = new Circle(500,200,50);
|
||||
/** The rectangle tested */
|
||||
private Shape rect1 = new Rectangle(150,120,50,100).transform(Transform.createTranslateTransform(50, 50));
|
||||
/** The rectangle tested */
|
||||
private Shape rect2 = new Rectangle(310,210,50,100).transform(
|
||||
Transform.createRotateTransform((float)Math.toRadians(45), 335, 260));
|
||||
/** The circle tested */
|
||||
private Shape circle1 = new Circle(150,90,30);
|
||||
/** The circle tested */
|
||||
private Shape circle2 = new Circle(310,110,70);
|
||||
/** The circle tested */
|
||||
private Shape circle3 = new Ellipse(510, 150, 70, 70);
|
||||
/** The circle tested */
|
||||
private Shape circle4 = new Ellipse(510, 350, 30, 30).transform(
|
||||
Transform.createTranslateTransform(-510, -350)).transform(
|
||||
Transform.createScaleTransform(2, 2)).transform(
|
||||
Transform.createTranslateTransform(510, 350));
|
||||
/** The RoundedRectangle tested */
|
||||
private Shape roundRect = new RoundedRectangle(50, 175, 100, 100, 20);
|
||||
/** The RoundedRectangle tested - less cornders */
|
||||
private Shape roundRect2 = new RoundedRectangle(50, 280, 50, 50, 20, 20, RoundedRectangle.TOP_LEFT | RoundedRectangle.BOTTOM_RIGHT);
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public GeomTest() {
|
||||
super("Geom Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Red indicates a collision, green indicates no collision", 50, 420);
|
||||
g.drawString("White are the targets", 50, 435);
|
||||
|
||||
g.pushTransform();
|
||||
g.translate(100,100);
|
||||
g.pushTransform();
|
||||
g.translate(-50,-50);
|
||||
g.scale(10, 10);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0,0,5,5);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(0,0,5,5);
|
||||
g.popTransform();
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(20,20,50,50);
|
||||
g.popTransform();
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.draw(rect);
|
||||
g.draw(circle);
|
||||
|
||||
g.setColor(rect1.intersects(rect) ? Color.red : Color.green);
|
||||
g.draw(rect1);
|
||||
g.setColor(rect2.intersects(rect) ? Color.red : Color.green);
|
||||
g.draw(rect2);
|
||||
g.setColor(roundRect.intersects(rect) ? Color.red : Color.green);
|
||||
g.draw(roundRect);
|
||||
g.setColor(circle1.intersects(rect) ? Color.red : Color.green);
|
||||
g.draw(circle1);
|
||||
g.setColor(circle2.intersects(rect) ? Color.red : Color.green);
|
||||
g.draw(circle2);
|
||||
g.setColor(circle3.intersects(circle) ? Color.red : Color.green);
|
||||
g.fill(circle3);
|
||||
g.setColor(circle4.intersects(circle) ? Color.red : Color.green);
|
||||
g.draw(circle4);
|
||||
|
||||
g.fill(roundRect2);
|
||||
g.setColor(Color.blue);
|
||||
g.draw(roundRect2);
|
||||
g.setColor(Color.blue);
|
||||
g.draw(new Circle(100,100,50));
|
||||
g.drawRect(50,50,100,100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new GeomTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
243
lib/slick-source/org/newdawn/slick/tests/GeomUtilTest.java
Normal file
243
lib/slick-source/org/newdawn/slick/tests/GeomUtilTest.java
Normal file
@@ -0,0 +1,243 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Circle;
|
||||
import org.newdawn.slick.geom.GeomUtil;
|
||||
import org.newdawn.slick.geom.GeomUtilListener;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
import org.newdawn.slick.geom.Transform;
|
||||
import org.newdawn.slick.geom.Vector2f;
|
||||
|
||||
/**
|
||||
* A test to try shape cutting
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class GeomUtilTest extends BasicGame implements GeomUtilListener {
|
||||
/** The shape we're cutting out of */
|
||||
private Shape source;
|
||||
/** The shape we're cutting */
|
||||
private Shape cut;
|
||||
/** The resulting shape */
|
||||
private Shape[] result;
|
||||
|
||||
/** The points used */
|
||||
private ArrayList points = new ArrayList();
|
||||
/** The points intersected */
|
||||
private ArrayList marks = new ArrayList();
|
||||
/** The points excluded */
|
||||
private ArrayList exclude = new ArrayList();
|
||||
|
||||
/** True if we're moving the shape around */
|
||||
private boolean dynamic;
|
||||
/** The util under test */
|
||||
private GeomUtil util = new GeomUtil();
|
||||
/** The x position of the shape */
|
||||
private int xp;
|
||||
/** The y position of the shape */
|
||||
private int yp;
|
||||
|
||||
/** The circle cutting tool */
|
||||
private Circle circle;
|
||||
/** The rectangle cutting tool */
|
||||
private Shape rect;
|
||||
/** The star cutting tool */
|
||||
private Polygon star;
|
||||
/** True if we're in union mode */
|
||||
private boolean union;
|
||||
|
||||
/**
|
||||
* Create a simple test
|
||||
*/
|
||||
public GeomUtilTest() {
|
||||
super("GeomUtilTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the cut
|
||||
*/
|
||||
public void init() {
|
||||
Polygon source = new Polygon();
|
||||
source.addPoint(100,100);
|
||||
source.addPoint(150,80);
|
||||
source.addPoint(210,120);
|
||||
source.addPoint(340,150);
|
||||
source.addPoint(150,200);
|
||||
source.addPoint(120,250);
|
||||
this.source = source;
|
||||
|
||||
circle = new Circle(0,0,50);
|
||||
rect = new Rectangle(-100,-40,200,80);
|
||||
star = new Polygon();
|
||||
|
||||
float dis = 40;
|
||||
for (int i=0;i<360;i+=30) {
|
||||
dis = dis == 40 ? 60 : 40;
|
||||
double x = (Math.cos(Math.toRadians(i)) * dis);
|
||||
double y = (Math.sin(Math.toRadians(i)) * dis);
|
||||
star.addPoint((float) x, (float) y);
|
||||
}
|
||||
|
||||
this.cut = circle;
|
||||
cut.setLocation(203,78);
|
||||
xp = (int) cut.getCenterX();
|
||||
yp = (int) cut.getCenterY();
|
||||
makeBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#init(GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
util.setListener(this);
|
||||
init();
|
||||
container.setVSync(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#update(GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
|
||||
dynamic = !dynamic;
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_ENTER)) {
|
||||
union = !union;
|
||||
makeBoolean();
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_1)) {
|
||||
cut = circle;
|
||||
circle.setCenterX(xp);
|
||||
circle.setCenterY(yp);
|
||||
makeBoolean();
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_2)) {
|
||||
cut = rect;
|
||||
rect.setCenterX(xp);
|
||||
rect.setCenterY(yp);
|
||||
makeBoolean();
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_3)) {
|
||||
cut = star;
|
||||
star.setCenterX(xp);
|
||||
star.setCenterY(yp);
|
||||
makeBoolean();
|
||||
}
|
||||
|
||||
if (dynamic) {
|
||||
xp = container.getInput().getMouseX();
|
||||
yp = container.getInput().getMouseY();
|
||||
makeBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the boolean operation
|
||||
*/
|
||||
private void makeBoolean() {
|
||||
marks.clear();
|
||||
points.clear();
|
||||
exclude.clear();
|
||||
cut.setCenterX(xp);
|
||||
cut.setCenterY(yp);
|
||||
if (union) {
|
||||
result = util.union(source, cut);
|
||||
} else {
|
||||
result = util.subtract(source, cut);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(GameContainer, Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.drawString("Space - toggle movement of cutting shape",530,10);
|
||||
g.drawString("1,2,3 - select cutting shape",530,30);
|
||||
g.drawString("Mouse wheel - rotate shape",530,50);
|
||||
g.drawString("Enter - toggle union/subtract",530,70);
|
||||
g.drawString("MODE: "+(union ? "Union" : "Cut"),530,200);
|
||||
|
||||
g.setColor(Color.green);
|
||||
g.draw(source);
|
||||
g.setColor(Color.red);
|
||||
g.draw(cut);
|
||||
|
||||
g.setColor(Color.white);
|
||||
for (int i=0;i<exclude.size();i++) {
|
||||
Vector2f pt = (Vector2f) exclude.get(i);
|
||||
g.drawOval(pt.x-3, pt.y-3, 7,7);
|
||||
}
|
||||
g.setColor(Color.yellow);
|
||||
for (int i=0;i<points.size();i++) {
|
||||
Vector2f pt = (Vector2f) points.get(i);
|
||||
g.fillOval(pt.x-1, pt.y-1, 3,3);
|
||||
}
|
||||
g.setColor(Color.white);
|
||||
for (int i=0;i<marks.size();i++) {
|
||||
Vector2f pt = (Vector2f) marks.get(i);
|
||||
g.fillOval(pt.x-1, pt.y-1, 3,3);
|
||||
}
|
||||
|
||||
g.translate(0,300);
|
||||
g.setColor(Color.white);
|
||||
if (result != null) {
|
||||
for (int i=0;i<result.length;i++) {
|
||||
g.draw(result[i]);
|
||||
}
|
||||
|
||||
g.drawString("Polys:"+result.length,10,100);
|
||||
g.drawString("X:"+xp,10,120);
|
||||
g.drawString("Y:"+yp,10,130);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new GeomUtilTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void pointExcluded(float x, float y) {
|
||||
exclude.add(new Vector2f(x,y));
|
||||
}
|
||||
|
||||
public void pointIntersected(float x, float y) {
|
||||
marks.add(new Vector2f(x,y));
|
||||
}
|
||||
|
||||
public void pointUsed(float x, float y) {
|
||||
points.add(new Vector2f(x,y));
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(int change) {
|
||||
if (dynamic) {
|
||||
if (change < 0) {
|
||||
cut = cut.transform(Transform.createRotateTransform((float) Math.toRadians(10), cut.getCenterX(), cut.getCenterY()));
|
||||
} else {
|
||||
cut = cut.transform(Transform.createRotateTransform((float) Math.toRadians(-10), cut.getCenterX(), cut.getCenterY()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
426
lib/slick-source/org/newdawn/slick/tests/GeomUtilTileTest.java
Normal file
426
lib/slick-source/org/newdawn/slick/tests/GeomUtilTileTest.java
Normal file
@@ -0,0 +1,426 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Circle;
|
||||
import org.newdawn.slick.geom.GeomUtil;
|
||||
import org.newdawn.slick.geom.GeomUtilListener;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
import org.newdawn.slick.geom.Vector2f;
|
||||
|
||||
/**
|
||||
* A test to try shape building from multiple tiles
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class GeomUtilTileTest extends BasicGame implements GeomUtilListener {
|
||||
/** The shape we're cutting out of */
|
||||
private Shape source;
|
||||
/** The shape we're cutting */
|
||||
private Shape cut;
|
||||
/** The resulting shape */
|
||||
private Shape[] result;
|
||||
|
||||
/** The util under test */
|
||||
private GeomUtil util = new GeomUtil();
|
||||
|
||||
/** The original list of shapes */
|
||||
private ArrayList original = new ArrayList();
|
||||
/** The original list of shapes */
|
||||
private ArrayList combined = new ArrayList();
|
||||
|
||||
/** The list of intersection points */
|
||||
private ArrayList intersections = new ArrayList();
|
||||
/** The list of used points */
|
||||
private ArrayList used = new ArrayList();
|
||||
|
||||
/** The quad space of shapes that need to be checked against each other */
|
||||
private ArrayList[][] quadSpace;
|
||||
/** The shapes present in each quad space - used to optimize generation */
|
||||
private Shape[][] quadSpaceShapes;
|
||||
|
||||
/**
|
||||
* Create a simple test
|
||||
*/
|
||||
public GeomUtilTileTest() {
|
||||
super("GeomUtilTileTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* So this is going to generate a quad space that holds that segments the
|
||||
* shapes into quads across the map. This makes it tunable and limits the number
|
||||
* of comparisons that need to be done for each shape
|
||||
*
|
||||
* @param shapes The shapes to be segments
|
||||
* @param minx The minimum x value of the map
|
||||
* @param miny The mimimum y value of the map
|
||||
* @param maxx The maximum x value of the map
|
||||
* @param maxy The maximum y value of the map
|
||||
* @param segments The number of segments to split the map into
|
||||
*/
|
||||
private void generateSpace(ArrayList shapes, float minx, float miny, float maxx, float maxy, int segments) {
|
||||
quadSpace = new ArrayList[segments][segments];
|
||||
quadSpaceShapes = new Shape[segments][segments];
|
||||
|
||||
float dx = (maxx - minx) / segments;
|
||||
float dy = (maxy - miny) / segments;
|
||||
|
||||
for (int x=0;x<segments;x++) {
|
||||
for (int y=0;y<segments;y++) {
|
||||
quadSpace[x][y] = new ArrayList();
|
||||
|
||||
// quad for this segment
|
||||
Polygon segmentPolygon = new Polygon();
|
||||
segmentPolygon.addPoint(minx+(dx*x), miny+(dy*y));
|
||||
segmentPolygon.addPoint(minx+(dx*x)+dx, miny+(dy*y));
|
||||
segmentPolygon.addPoint(minx+(dx*x)+dx, miny+(dy*y)+dy);
|
||||
segmentPolygon.addPoint(minx+(dx*x), miny+(dy*y)+dy);
|
||||
|
||||
for (int i=0;i<shapes.size();i++) {
|
||||
Shape shape = (Shape) shapes.get(i);
|
||||
|
||||
if (collides(shape, segmentPolygon)) {
|
||||
quadSpace[x][y].add(shape);
|
||||
}
|
||||
}
|
||||
|
||||
quadSpaceShapes[x][y] = segmentPolygon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given shape from the quad space
|
||||
*
|
||||
* @param shape The shape to remove
|
||||
*/
|
||||
private void removeFromQuadSpace(Shape shape) {
|
||||
int segments = quadSpace.length;
|
||||
|
||||
for (int x=0;x<segments;x++) {
|
||||
for (int y=0;y<segments;y++) {
|
||||
quadSpace[x][y].remove(shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a particular shape to quad space
|
||||
*
|
||||
* @param shape The shape to be added
|
||||
*/
|
||||
private void addToQuadSpace(Shape shape) {
|
||||
int segments = quadSpace.length;
|
||||
|
||||
for (int x=0;x<segments;x++) {
|
||||
for (int y=0;y<segments;y++) {
|
||||
if (collides(shape, quadSpaceShapes[x][y])) {
|
||||
quadSpace[x][y].add(shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the cut
|
||||
*/
|
||||
public void init() {
|
||||
int size = 10;
|
||||
int[][] map = new int[][] {
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 },
|
||||
{ 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 },
|
||||
{ 0, 1, 1, 0, 0, 0, 5, 1, 6, 0 },
|
||||
{ 0, 1, 2, 0, 0, 0, 4, 1, 1, 0 },
|
||||
{ 0, 1, 1, 0, 0, 0, 1, 1, 0, 0 },
|
||||
{ 0, 0, 0, 0, 3, 0, 1, 1, 0, 0 },
|
||||
{ 0, 0, 0, 1, 1, 0, 0, 0, 1, 0 },
|
||||
{ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
// size = 100;
|
||||
// map = new int[size][size];
|
||||
// for (int x=0;x<size;x++) {
|
||||
// for (int y=0;y<size;y++) {
|
||||
// if ((x+y) % 2 == 0) {
|
||||
// map[y][x] = 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
for (int x = 0; x < map[0].length; x++) {
|
||||
for (int y = 0; y < map.length; y++) {
|
||||
if (map[y][x] != 0) {
|
||||
switch (map[y][x]) {
|
||||
case 1:
|
||||
Polygon p2 = new Polygon();
|
||||
p2.addPoint(x * 32, y * 32);
|
||||
p2.addPoint((x * 32) + 32, y * 32);
|
||||
p2.addPoint((x * 32) + 32, (y * 32) + 32);
|
||||
p2.addPoint(x * 32, (y * 32) + 32);
|
||||
original.add(p2);
|
||||
break;
|
||||
case 2:
|
||||
Polygon poly = new Polygon();
|
||||
poly.addPoint(x * 32, y * 32);
|
||||
poly.addPoint((x * 32) + 32, y * 32);
|
||||
poly.addPoint(x * 32, (y * 32) + 32);
|
||||
original.add(poly);
|
||||
break;
|
||||
case 3:
|
||||
Circle ellipse = new Circle((x*32)+16,(y*32)+32,16,16);
|
||||
original.add(ellipse);
|
||||
break;
|
||||
case 4:
|
||||
Polygon p = new Polygon();
|
||||
p.addPoint((x * 32) + 32, (y * 32));
|
||||
p.addPoint((x * 32) + 32, (y * 32)+32);
|
||||
p.addPoint(x * 32, (y * 32) + 32);
|
||||
original.add(p);
|
||||
break;
|
||||
case 5:
|
||||
Polygon p3 = new Polygon();
|
||||
p3.addPoint((x * 32), (y * 32));
|
||||
p3.addPoint((x * 32) + 32, (y * 32));
|
||||
p3.addPoint((x * 32) + 32, (y * 32)+32);
|
||||
original.add(p3);
|
||||
break;
|
||||
case 6:
|
||||
Polygon p4 = new Polygon();
|
||||
p4.addPoint((x * 32), (y * 32));
|
||||
p4.addPoint((x * 32) + 32, (y * 32));
|
||||
p4.addPoint((x * 32), (y * 32)+32);
|
||||
original.add(p4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
// the quad spaced method
|
||||
generateSpace(original, 0, 0, (size+1)*32,(size+1)*32,8);
|
||||
combined = combineQuadSpace();
|
||||
|
||||
// the brute force method
|
||||
//combined = combine(original);
|
||||
|
||||
long after = System.currentTimeMillis();
|
||||
System.out.println("Combine took: "+(after-before));
|
||||
System.out.println("Combine result: "+combined.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine the shapes in the quad space
|
||||
*
|
||||
* @return The newly combined list of shapes
|
||||
*/
|
||||
private ArrayList combineQuadSpace() {
|
||||
boolean updated = true;
|
||||
while (updated) {
|
||||
updated = false;
|
||||
|
||||
for (int x=0;x<quadSpace.length;x++) {
|
||||
for (int y=0;y<quadSpace.length;y++) {
|
||||
ArrayList shapes = quadSpace[x][y];
|
||||
int before = shapes.size();
|
||||
combine(shapes);
|
||||
int after = shapes.size();
|
||||
|
||||
updated |= before != after;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// at this stage all the shapes that can be combined within their quads
|
||||
// will have gone on - we may need to combine stuff on the boundary tho
|
||||
HashSet result = new HashSet();
|
||||
|
||||
for (int x=0;x<quadSpace.length;x++) {
|
||||
for (int y=0;y<quadSpace.length;y++) {
|
||||
result.addAll(quadSpace[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine a set of shapes together
|
||||
*
|
||||
* @param shapes
|
||||
* The shapes to be combined
|
||||
* @return The list of combined shapes
|
||||
*/
|
||||
private ArrayList combine(ArrayList shapes) {
|
||||
ArrayList last = shapes;
|
||||
ArrayList current = shapes;
|
||||
boolean first = true;
|
||||
|
||||
while ((current.size() != last.size()) || (first)) {
|
||||
first = false;
|
||||
last = current;
|
||||
current = combineImpl(current);
|
||||
}
|
||||
|
||||
ArrayList pruned = new ArrayList();
|
||||
for (int i = 0; i < current.size(); i++) {
|
||||
pruned.add(((Shape) current.get(i)).prune());
|
||||
}
|
||||
return pruned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to find a simple combination that can be performed
|
||||
*
|
||||
* @param shapes
|
||||
* The shapes to be combined
|
||||
* @return The new list of shapes - this will be the same length as the
|
||||
* input if there are no new combinations
|
||||
*/
|
||||
private ArrayList combineImpl(ArrayList shapes) {
|
||||
ArrayList result = new ArrayList(shapes);
|
||||
if (quadSpace != null) {
|
||||
result = shapes;
|
||||
}
|
||||
|
||||
for (int i = 0; i < shapes.size(); i++) {
|
||||
Shape first = (Shape) shapes.get(i);
|
||||
for (int j = i + 1; j < shapes.size(); j++) {
|
||||
Shape second = (Shape) shapes.get(j);
|
||||
|
||||
if (!first.intersects(second)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Shape[] joined = util.union(first, second);
|
||||
if (joined.length == 1) {
|
||||
if (quadSpace != null) {
|
||||
removeFromQuadSpace(first);
|
||||
removeFromQuadSpace(second);
|
||||
addToQuadSpace(joined[0]);
|
||||
} else {
|
||||
result.remove(first);
|
||||
result.remove(second);
|
||||
result.add(joined[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two shapes collide
|
||||
*
|
||||
* @param shape1 The first shape
|
||||
* @param shape2 The second shape
|
||||
* @return True if the shapes collide (i.e. intersection or overlap)
|
||||
*/
|
||||
public boolean collides(Shape shape1, Shape shape2) {
|
||||
if (shape1.intersects(shape2)) {
|
||||
return true;
|
||||
}
|
||||
for (int i=0;i<shape1.getPointCount();i++) {
|
||||
float[] pt = shape1.getPoint(i);
|
||||
if (shape2.contains(pt[0], pt[1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i=0;i<shape2.getPointCount();i++) {
|
||||
float[] pt = shape2.getPoint(i);
|
||||
if (shape1.contains(pt[0], pt[1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#init(GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
util.setListener(this);
|
||||
init();
|
||||
//container.setVSync(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#update(GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(GameContainer, Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.setColor(Color.green);
|
||||
for (int i = 0; i < original.size(); i++) {
|
||||
Shape shape = (Shape) original.get(i);
|
||||
g.draw(shape);
|
||||
}
|
||||
|
||||
g.setColor(Color.white);
|
||||
if (quadSpaceShapes != null) {
|
||||
g.draw(quadSpaceShapes[0][0]);
|
||||
}
|
||||
|
||||
g.translate(0, 320);
|
||||
|
||||
for (int i = 0; i < combined.size(); i++) {
|
||||
g.setColor(Color.white);
|
||||
Shape shape = (Shape) combined.get(i);
|
||||
g.draw(shape);
|
||||
for (int j = 0; j < shape.getPointCount(); j++) {
|
||||
g.setColor(Color.yellow);
|
||||
float[] pt = shape.getPoint(j);
|
||||
g.fillOval(pt[0] - 1, pt[1] - 1, 3, 3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(
|
||||
new GeomUtilTileTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void pointExcluded(float x, float y) {
|
||||
}
|
||||
|
||||
public void pointIntersected(float x, float y) {
|
||||
intersections.add(new Vector2f(x, y));
|
||||
}
|
||||
|
||||
public void pointUsed(float x, float y) {
|
||||
used.add(new Vector2f(x, y));
|
||||
}
|
||||
}
|
||||
122
lib/slick-source/org/newdawn/slick/tests/GradientImageTest.java
Normal file
122
lib/slick-source/org/newdawn/slick/tests/GradientImageTest.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
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.fills.GradientFill;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
|
||||
/**
|
||||
* A test for applying gradients to images
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GradientImageTest extends BasicGame {
|
||||
/** The first image loaded */
|
||||
private Image image1;
|
||||
/** The second image loaded */
|
||||
private Image image2;
|
||||
/** The gradient paint we'll apply */
|
||||
private GradientFill fill;
|
||||
/** The shape we'll blend across */
|
||||
private Shape shape;
|
||||
/** The shape we'll blend across */
|
||||
private Polygon poly;
|
||||
/** The container for the test */
|
||||
private GameContainer container;
|
||||
/** The angle of rotation */
|
||||
private float ang;
|
||||
/** True if we're rotating */
|
||||
private boolean rotating = false;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public GradientImageTest() {
|
||||
super("Gradient Image Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
image1 = new Image("testdata/grass.png");
|
||||
image2 = new Image("testdata/rocks.png");
|
||||
|
||||
fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0));
|
||||
shape = new Rectangle(336,236,128,128);
|
||||
poly = new Polygon();
|
||||
poly.addPoint(320,220);
|
||||
poly.addPoint(350,200);
|
||||
poly.addPoint(450,200);
|
||||
poly.addPoint(480,220);
|
||||
poly.addPoint(420,400);
|
||||
poly.addPoint(400,390);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("R - Toggle Rotationg",10,50);
|
||||
g.drawImage(image1, 100, 236);
|
||||
g.drawImage(image2, 600, 236);
|
||||
|
||||
g.translate(0, -150);
|
||||
g.rotate(400, 300, ang);
|
||||
g.texture(shape, image2);
|
||||
g.texture(shape, image1, fill);
|
||||
g.resetTransform();
|
||||
|
||||
g.translate(0, 150);
|
||||
g.rotate(400, 300, ang);
|
||||
g.texture(poly, image2);
|
||||
g.texture(poly, image1, fill);
|
||||
g.resetTransform();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
if (rotating) {
|
||||
ang += (delta * 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new GradientImageTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_R) {
|
||||
rotating = !rotating;
|
||||
}
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
130
lib/slick-source/org/newdawn/slick/tests/GradientTest.java
Normal file
130
lib/slick-source/org/newdawn/slick/tests/GradientTest.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.fills.GradientFill;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.RoundedRectangle;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
|
||||
/**
|
||||
* A test for gradient fill on polygons
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GradientTest extends BasicGame {
|
||||
/** The container for the test */
|
||||
private GameContainer container;
|
||||
/** The paint we'll use */
|
||||
private GradientFill gradient;
|
||||
/** The paint we'll use */
|
||||
private GradientFill gradient2;
|
||||
/** The paint we'll use */
|
||||
private GradientFill gradient4;
|
||||
/** The shape to render */
|
||||
private Rectangle rect;
|
||||
/** The shape to render */
|
||||
private Rectangle center;
|
||||
/** The shape to render */
|
||||
private RoundedRectangle round;
|
||||
/** The shape to render */
|
||||
private RoundedRectangle round2;
|
||||
/** The shape to render */
|
||||
private Polygon poly;
|
||||
/** The angle of rotation */
|
||||
private float ang;
|
||||
|
||||
/**
|
||||
* Create a new gradient test
|
||||
*/
|
||||
public GradientTest() {
|
||||
super("Gradient Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
rect = new Rectangle(400,100,200,150);
|
||||
round = new RoundedRectangle(150,100,200,150,50);
|
||||
round2 = new RoundedRectangle(150,300,200,150,50);
|
||||
center = new Rectangle(350,250,100,100);
|
||||
|
||||
poly = new Polygon();
|
||||
poly.addPoint(400,350);
|
||||
poly.addPoint(550,320);
|
||||
poly.addPoint(600,380);
|
||||
poly.addPoint(620,450);
|
||||
poly.addPoint(500,450);
|
||||
|
||||
gradient = new GradientFill(0,-75,Color.red,0,75,Color.yellow,true);
|
||||
gradient2 = new GradientFill(0,-75,Color.blue,0,75,Color.white,true);
|
||||
gradient4 = new GradientFill(-50,-40,Color.green,50,40,Color.cyan,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
|
||||
g.rotate(400, 300, ang);
|
||||
g.fill(rect, gradient);
|
||||
g.fill(round, gradient);
|
||||
g.fill(poly, gradient2);
|
||||
g.fill(center, gradient4);
|
||||
|
||||
g.setAntiAlias(true);
|
||||
g.setLineWidth(10);
|
||||
g.draw(round2, gradient2);
|
||||
g.setLineWidth(2);
|
||||
g.draw(poly, gradient);
|
||||
g.setAntiAlias(false);
|
||||
|
||||
g.fill(center, gradient4);
|
||||
g.setAntiAlias(true);
|
||||
g.setColor(Color.black);
|
||||
g.draw(center);
|
||||
g.setAntiAlias(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
ang += (delta * 0.01f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new GradientTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
163
lib/slick-source/org/newdawn/slick/tests/GraphicsTest.java
Normal file
163
lib/slick-source/org/newdawn/slick/tests/GraphicsTest.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
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.Polygon;
|
||||
import org.newdawn.slick.util.FastTrig;
|
||||
|
||||
/**
|
||||
* A simple graphics test for the context allowing vector based graphics
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GraphicsTest extends BasicGame {
|
||||
/** True if we're clipping an area */
|
||||
private boolean clip;
|
||||
/** The angle of rotation */
|
||||
private float ang;
|
||||
/** The image being rendered */
|
||||
private Image image;
|
||||
/** A polygon to be rendered */
|
||||
private Polygon poly;
|
||||
/** The container holding this test */
|
||||
private GameContainer container;
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public GraphicsTest() {
|
||||
super("Graphics Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
image = new Image("testdata/logo.tga", true);
|
||||
|
||||
Image temp = new Image("testdata/palette_tool.png");
|
||||
container.setMouseCursor(temp, 0, 0);
|
||||
|
||||
container.setIcons(new String[] {"testdata/icon.tga"});
|
||||
container.setTargetFrameRate(100);
|
||||
|
||||
poly = new Polygon();
|
||||
float len = 100;
|
||||
|
||||
for (int x=0;x<360;x+=30) {
|
||||
if (len == 100) {
|
||||
len = 50;
|
||||
} else {
|
||||
len = 100;
|
||||
}
|
||||
poly.addPoint((float) FastTrig.cos(Math.toRadians(x)) * len,
|
||||
(float) FastTrig.sin(Math.toRadians(x)) * len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
|
||||
g.setAntiAlias(true);
|
||||
for (int x=0;x<360;x+=10) {
|
||||
g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)),
|
||||
(int) (100+(Math.sin(Math.toRadians(x))*100)));
|
||||
}
|
||||
g.setAntiAlias(false);
|
||||
|
||||
g.setColor(Color.yellow);
|
||||
g.drawString("The Graphics Test!", 300, 50);
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Space - Toggles clipping", 400, 80);
|
||||
g.drawString("Frame rate capped to 100", 400, 120);
|
||||
|
||||
if (clip) {
|
||||
g.setColor(Color.gray);
|
||||
g.drawRect(100,260,400,100);
|
||||
g.setClip(100,260,400,100);
|
||||
}
|
||||
|
||||
g.setColor(Color.yellow);
|
||||
g.translate(100, 120);
|
||||
g.fill(poly);
|
||||
g.setColor(Color.blue);
|
||||
g.setLineWidth(3);
|
||||
g.draw(poly);
|
||||
g.setLineWidth(1);
|
||||
g.translate(0, 230);
|
||||
g.draw(poly);
|
||||
g.resetTransform();
|
||||
|
||||
g.setColor(Color.magenta);
|
||||
g.drawRoundRect(10, 10, 100, 100, 10);
|
||||
g.fillRoundRect(10, 210, 100, 100, 10);
|
||||
|
||||
g.rotate(400, 300, ang);
|
||||
g.setColor(Color.green);
|
||||
g.drawRect(200,200,200,200);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(250,250,100,100);
|
||||
|
||||
g.drawImage(image, 300,270);
|
||||
|
||||
g.setColor(Color.red);
|
||||
g.drawOval(100,100,200,200);
|
||||
g.setColor(Color.red.darker());
|
||||
g.fillOval(300,300,150,100);
|
||||
g.setAntiAlias(true);
|
||||
g.setColor(Color.white);
|
||||
g.setLineWidth(5.0f);
|
||||
g.drawOval(300,300,150,100);
|
||||
g.setAntiAlias(true);
|
||||
g.resetTransform();
|
||||
|
||||
if (clip) {
|
||||
g.clearClip();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
ang += delta * 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
clip = !clip;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new GraphicsTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package org.newdawn.slick.tests;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.ImageBuffer;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* Quick test for endianess in image buffers
|
||||
*
|
||||
* @author thaaks
|
||||
*/
|
||||
public class ImageBufferEndianTest extends BasicGame {
|
||||
/** The buffer filled with red pixels */
|
||||
private ImageBuffer redImageBuffer;
|
||||
/** The buffer filled with blue pixels */
|
||||
private ImageBuffer blueImageBuffer;
|
||||
/** The image created from red pixels */
|
||||
private Image fromRed;
|
||||
/** The image create from blue pixels */
|
||||
private Image fromBlue;
|
||||
/** The edian message */
|
||||
private String endian;
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public ImageBufferEndianTest() {
|
||||
super("ImageBuffer Endian Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the test
|
||||
*
|
||||
* @param args The arguments passed into the test
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageBufferEndianTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Endianness is " + endian, 10, 100);
|
||||
|
||||
g.drawString("Image below should be red", 10, 200);
|
||||
g.drawImage(fromRed, 10, 220);
|
||||
g.drawString("Image below should be blue", 410, 200);
|
||||
g.drawImage(fromBlue, 410, 220);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
// detect what endian we have
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
|
||||
endian = "Big endian";
|
||||
} else if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
||||
endian = "Little endian";
|
||||
} else
|
||||
endian = "no idea";
|
||||
|
||||
redImageBuffer = new ImageBuffer(100,100);
|
||||
fillImageBufferWithColor(redImageBuffer, Color.red, 100, 100);
|
||||
|
||||
blueImageBuffer = new ImageBuffer(100,100);
|
||||
fillImageBufferWithColor(blueImageBuffer, Color.blue, 100, 100);
|
||||
|
||||
fromRed = redImageBuffer.getImage();
|
||||
fromBlue = blueImageBuffer.getImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a buffer with a given color
|
||||
*
|
||||
* @param buffer The buffer to fill
|
||||
* @param c The color to apply
|
||||
* @param width The width of the image
|
||||
* @param height The height of the image
|
||||
*/
|
||||
private void fillImageBufferWithColor(ImageBuffer buffer, Color c, int width, int height) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
buffer.setRGBA(x, y, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.ImageBuffer;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for image buffer maniupulation rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageBufferTest extends BasicGame {
|
||||
/** The image we're currently displaying */
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Create a new image buffer rendering test
|
||||
*/
|
||||
public ImageBufferTest() {
|
||||
super("Image Buffer Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
ImageBuffer buffer = new ImageBuffer(320,200);
|
||||
for (int x=0;x<320;x++) {
|
||||
for (int y=0;y<200;y++) {
|
||||
if (y == 20) {
|
||||
buffer.setRGBA(x, y, 255,255,255,255);
|
||||
} else {
|
||||
buffer.setRGBA(x, y, x,y,0,255);
|
||||
}
|
||||
}
|
||||
}
|
||||
image = buffer.getImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
image.draw(50,50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageBufferTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for basic image rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageCornerTest extends BasicGame {
|
||||
/** The test image */
|
||||
private Image image;
|
||||
/** The sub images */
|
||||
private Image[] images;
|
||||
/** The width */
|
||||
private int width;
|
||||
/** The height */
|
||||
private int height;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public ImageCornerTest() {
|
||||
super("Image Corner Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = new Image("testdata/logo.png");
|
||||
|
||||
width = image.getWidth() / 3;
|
||||
height = image.getHeight() / 3;
|
||||
|
||||
images = new Image[] {
|
||||
image.getSubImage(0, 0, width, height), image.getSubImage(width,0,width,height), image.getSubImage(width*2,0,width,height),
|
||||
image.getSubImage(0, height, width, height), image.getSubImage(width,height,width,height), image.getSubImage(width*2,height,width,height),
|
||||
image.getSubImage(0, height*2, width, height), image.getSubImage(width,height*2,width,height), image.getSubImage(width*2,height*2,width,height),
|
||||
};
|
||||
|
||||
images[0].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
|
||||
images[1].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
|
||||
images[1].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
|
||||
images[2].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
|
||||
images[3].setColor(Image.TOP_RIGHT, 0,1,1,1);
|
||||
images[3].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
|
||||
|
||||
images[4].setColor(Image.TOP_RIGHT, 0,1,1,1);
|
||||
images[4].setColor(Image.TOP_LEFT, 0,1,1,1);
|
||||
images[4].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
|
||||
images[4].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
|
||||
images[5].setColor(Image.TOP_LEFT, 0,1,1,1);
|
||||
images[5].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
|
||||
|
||||
images[6].setColor(Image.TOP_RIGHT, 0,1,1,1);
|
||||
images[7].setColor(Image.TOP_RIGHT, 0,1,1,1);
|
||||
images[7].setColor(Image.TOP_LEFT, 0,1,1,1);
|
||||
images[8].setColor(Image.TOP_LEFT, 0,1,1,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
for (int x=0;x<3;x++) {
|
||||
for (int y=0;y<3;y++) {
|
||||
images[x+(y*3)].draw(100+(x*width),100+(y*height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
boolean sharedContextTest = false;
|
||||
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageCornerTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
}
|
||||
167
lib/slick-source/org/newdawn/slick/tests/ImageGraphicsTest.java
Normal file
167
lib/slick-source/org/newdawn/slick/tests/ImageGraphicsTest.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.pbuffer.GraphicsFactory;
|
||||
|
||||
/**
|
||||
* A test for rendering to an image
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageGraphicsTest extends BasicGame {
|
||||
/** The image loaded and then rendered to */
|
||||
private Image preloaded;
|
||||
/** The image rendered to */
|
||||
private Image target;
|
||||
/** The image cut from the screen */
|
||||
private Image cut;
|
||||
/** The offscreen graphics */
|
||||
private Graphics gTarget;
|
||||
/** The offscreen graphics */
|
||||
private Graphics offscreenPreload;
|
||||
/** The image loaded */
|
||||
private Image testImage;
|
||||
/** The font loaded */
|
||||
private Font testFont;
|
||||
/** The angle of the rotation */
|
||||
private float ang;
|
||||
/** The name of the dynamic image technique in use */
|
||||
private String using = "none";
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public ImageGraphicsTest() {
|
||||
super("Image Graphics Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
testImage = new Image("testdata/logo.png");
|
||||
preloaded = new Image("testdata/logo.png");
|
||||
testFont = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
|
||||
target = new Image(400,300);
|
||||
cut = new Image(100,100);
|
||||
gTarget = target.getGraphics();
|
||||
offscreenPreload = preloaded.getGraphics();
|
||||
|
||||
offscreenPreload.drawString("Drawing over a loaded image", 5, 15);
|
||||
offscreenPreload.setLineWidth(5);
|
||||
offscreenPreload.setAntiAlias(true);
|
||||
offscreenPreload.setColor(Color.blue.brighter());
|
||||
offscreenPreload.drawOval(200, 30, 50, 50);
|
||||
offscreenPreload.setColor(Color.white);
|
||||
offscreenPreload.drawRect(190,20,70,70);
|
||||
offscreenPreload.flush();
|
||||
|
||||
if (GraphicsFactory.usingFBO()) {
|
||||
using = "FBO (Frame Buffer Objects)";
|
||||
} else if (GraphicsFactory.usingPBuffer()) {
|
||||
using = "Pbuffer (Pixel Buffers)";
|
||||
}
|
||||
|
||||
System.out.println(preloaded.getColor(50,50));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
|
||||
// RENDERING TO AN IMAGE AND THEN DRAWING IT TO THE DISPLAY
|
||||
// Draw graphics and text onto our graphics context from the Image target
|
||||
gTarget.setBackground(new Color(0,0,0,0));
|
||||
gTarget.clear();
|
||||
gTarget.rotate(200,160,ang);
|
||||
gTarget.setFont(testFont);
|
||||
gTarget.fillRect(10, 10, 50, 50);
|
||||
gTarget.drawString("HELLO WORLD",10,10);
|
||||
|
||||
gTarget.drawImage(testImage,100,150);
|
||||
gTarget.drawImage(testImage,100,50);
|
||||
gTarget.drawImage(testImage,50,75);
|
||||
|
||||
// Note we started by clearing the offscreen graphics area and then end
|
||||
// by calling flush
|
||||
gTarget.flush();
|
||||
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(250, 50, 200, 200);
|
||||
// The image has been updated using its graphics context, so now draw the image
|
||||
// to the screen a few times
|
||||
target.draw(300,100);
|
||||
target.draw(300,410,200,150);
|
||||
target.draw(505,410,100,75);
|
||||
|
||||
// Draw some text on the screen to indicate what we did and put some
|
||||
// nice boxes around the three areas
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Testing On Offscreen Buffer", 300, 80);
|
||||
g.setColor(Color.green);
|
||||
g.drawRect(300, 100, target.getWidth(), target.getHeight());
|
||||
g.drawRect(300, 410, target.getWidth()/2, target.getHeight()/2);
|
||||
g.drawRect(505, 410, target.getWidth()/4, target.getHeight()/4);
|
||||
|
||||
// SCREEN COPY EXAMPLE
|
||||
// Put some text and simple graphics on the screen to test copying
|
||||
// from the screen to a target image
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Testing Font On Back Buffer", 10, 100);
|
||||
g.drawString("Using: "+using, 10, 580);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(10,120,200,5);
|
||||
|
||||
// Copy the screen area into a destination image
|
||||
int xp = (int) (60 + (Math.sin(ang / 60) * 50));
|
||||
g.copyArea(cut,xp,50);
|
||||
|
||||
// Draw the copied image to the screen and put some nice
|
||||
// boxes around the source and the destination
|
||||
cut.draw(30,250);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(30, 250, cut.getWidth(), cut.getHeight());
|
||||
g.setColor(Color.gray);
|
||||
g.drawRect(xp, 50, cut.getWidth(), cut.getHeight());
|
||||
|
||||
// ALTERING A LOADED IMAGE EXAMPLE
|
||||
// Draw the image we loaded in the init method and then modified
|
||||
// by drawing some text and simple geometry on it
|
||||
preloaded.draw(2,400);
|
||||
g.setColor(Color.blue);
|
||||
g.drawRect(2,400,preloaded.getWidth(),preloaded.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
ang += delta * 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
GraphicsFactory.setUseFBO(false);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new ImageGraphicsTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
65
lib/slick-source/org/newdawn/slick/tests/ImageMemTest.java
Normal file
65
lib/slick-source/org/newdawn/slick/tests/ImageMemTest.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for basic image rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageMemTest extends BasicGame {
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public ImageMemTest() {
|
||||
super("Image Memory Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
try {
|
||||
Image img = new Image(2400, 2400);
|
||||
img.getGraphics();
|
||||
img.destroy();
|
||||
img = new Image(2400, 2400);
|
||||
img.getGraphics();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageMemTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
134
lib/slick-source/org/newdawn/slick/tests/ImageOutTest.java
Normal file
134
lib/slick-source/org/newdawn/slick/tests/ImageOutTest.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
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.imageout.ImageOut;
|
||||
import org.newdawn.slick.particles.ParticleIO;
|
||||
import org.newdawn.slick.particles.ParticleSystem;
|
||||
|
||||
/**
|
||||
* A test for saving images
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageOutTest extends BasicGame {
|
||||
/** The game container */
|
||||
private GameContainer container;
|
||||
/** The fire particle system */
|
||||
private ParticleSystem fire;
|
||||
/** The graphics context */
|
||||
private Graphics g;
|
||||
/** The image we're going to use to copy into */
|
||||
private Image copy;
|
||||
/** The message to display */
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public ImageOutTest() {
|
||||
super("Image Out Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
try {
|
||||
fire = ParticleIO.loadConfiguredSystem("testdata/system.xml");
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load particle systems", e);
|
||||
}
|
||||
|
||||
copy = new Image(400,300);
|
||||
String[] formats = ImageOut.getSupportedFormats();
|
||||
message = "Formats supported: ";
|
||||
for (int i=0;i<formats.length;i++) {
|
||||
message += formats[i];
|
||||
if (i < formats.length - 1) {
|
||||
message += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("T - TGA Snapshot", 10,50);
|
||||
g.drawString("J - JPG Snapshot", 10,70);
|
||||
g.drawString("P - PNG Snapshot", 10,90);
|
||||
|
||||
g.setDrawMode(Graphics.MODE_ADD);
|
||||
g.drawImage(copy, 200, 300);
|
||||
g.setDrawMode(Graphics.MODE_NORMAL);
|
||||
|
||||
g.drawString(message, 10,400);
|
||||
g.drawRect(200,0,400,300);
|
||||
g.translate(400, 250);
|
||||
fire.render();
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture and save to the specified file name
|
||||
*
|
||||
* @param fname The name of the file to write to
|
||||
* @throws SlickException Indicates a failure to capture or write
|
||||
*/
|
||||
private void writeTo(String fname) throws SlickException {
|
||||
g.copyArea(copy, 200,0);
|
||||
ImageOut.write(copy, fname);
|
||||
message = "Written "+fname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
fire.update(delta);
|
||||
|
||||
if (container.getInput().isKeyPressed(Input.KEY_P)) {
|
||||
writeTo("ImageOutTest.png");
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_J)) {
|
||||
writeTo("ImageOutTest.jpg");
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_T)) {
|
||||
writeTo("ImageOutTest.tga");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageOutTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
99
lib/slick-source/org/newdawn/slick/tests/ImageReadTest.java
Normal file
99
lib/slick-source/org/newdawn/slick/tests/ImageReadTest.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for reading image data from a teture
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageReadTest extends BasicGame {
|
||||
/** The image loaded to be read */
|
||||
private Image image;
|
||||
/** The four pixels read */
|
||||
private Color[] read = new Color[6];
|
||||
/** The main graphics context */
|
||||
private Graphics g;
|
||||
|
||||
/**
|
||||
* Create a new image reading test
|
||||
*/
|
||||
public ImageReadTest() {
|
||||
super("Image Read Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = new Image("testdata/testcard.png");
|
||||
read[0] = image.getColor(0, 0);
|
||||
read[1] = image.getColor(30, 40);
|
||||
read[2] = image.getColor(55, 70);
|
||||
read[3] = image.getColor(80, 90);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
this.g = g;
|
||||
|
||||
image.draw(100,100);
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Move mouse over test image", 200, 20);
|
||||
g.setColor(read[0]);
|
||||
g.drawString(read[0].toString(), 100,300);
|
||||
g.setColor(read[1]);
|
||||
g.drawString(read[1].toString(), 150,320);
|
||||
g.setColor(read[2]);
|
||||
g.drawString(read[2].toString(), 200,340);
|
||||
g.setColor(read[3]);
|
||||
g.drawString(read[3].toString(), 250,360);
|
||||
if (read[4] != null) {
|
||||
g.setColor(read[4]);
|
||||
g.drawString("On image: "+read[4].toString(), 100,250);
|
||||
}
|
||||
if (read[5] != null) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("On screen: "+read[5].toString(), 100,270);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
int mx = container.getInput().getMouseX();
|
||||
int my = container.getInput().getMouseY();
|
||||
|
||||
if ((mx >= 100) && (my >= 100) && (mx < 200) && (my < 200)) {
|
||||
read[4] = image.getColor(mx-100,my-100);
|
||||
} else {
|
||||
read[4] = Color.black;
|
||||
}
|
||||
|
||||
read[5] = g.getPixel(mx, my);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ImageReadTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
153
lib/slick-source/org/newdawn/slick/tests/ImageTest.java
Normal file
153
lib/slick-source/org/newdawn/slick/tests/ImageTest.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A test for basic image rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ImageTest extends BasicGame {
|
||||
/** The TGA image loaded */
|
||||
private Image tga;
|
||||
/** The TGA image loaded */
|
||||
private Image scaleMe;
|
||||
/** The TGA image loaded */
|
||||
private Image scaled;
|
||||
/** The GIF version of the image */
|
||||
private Image gif;
|
||||
/** The image we're currently displaying */
|
||||
private Image image;
|
||||
/** A sub part of the logo image */
|
||||
private Image subImage;
|
||||
/** Newer image rotation image. */
|
||||
private Image rotImage;
|
||||
/** The current rotation of our test image */
|
||||
private float rot;
|
||||
/** True if the test should just exit first time round, used for testing shared contexts */
|
||||
public static boolean exitMe = true;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public ImageTest() {
|
||||
super("Image Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = tga = new Image("testdata/logo.png");
|
||||
rotImage = new Image("testdata/logo.png");
|
||||
rotImage = rotImage.getScaledCopy(rotImage.getWidth() / 2, rotImage.getHeight() / 2);
|
||||
//rotImage.setCenterOfRotation(0,0);
|
||||
|
||||
scaleMe = new Image("testdata/logo.tga", true, Image.FILTER_NEAREST);
|
||||
gif = new Image("testdata/logo.gif");
|
||||
gif.destroy();
|
||||
gif = new Image("testdata/logo.gif");
|
||||
scaled = gif.getScaledCopy(120, 120);
|
||||
subImage = image.getSubImage(200,0,70,260);
|
||||
rot = 0;
|
||||
|
||||
if (exitMe) {
|
||||
container.exit();
|
||||
}
|
||||
|
||||
Image test = tga.getSubImage(50,50,50,50);
|
||||
System.out.println(test.getColor(50, 50));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawRect(0,0,image.getWidth(),image.getHeight());
|
||||
image.draw(0,0);
|
||||
image.draw(500,0,200,100);
|
||||
scaleMe.draw(500,100,200,100);
|
||||
scaled.draw(400,500);
|
||||
Image flipped = scaled.getFlippedCopy(true, false);
|
||||
flipped.draw(520,500);
|
||||
Image flipped2 = flipped.getFlippedCopy(false, true);
|
||||
flipped2.draw(520,380);
|
||||
Image flipped3 = flipped2.getFlippedCopy(true, false);
|
||||
flipped3.draw(400,380);
|
||||
|
||||
for (int i=0;i<3;i++) {
|
||||
subImage.draw(200+(i*30),300);
|
||||
}
|
||||
|
||||
g.translate(500, 200);
|
||||
g.rotate(50, 50, rot);
|
||||
g.scale(0.3f,0.3f);
|
||||
image.draw();
|
||||
g.resetTransform();
|
||||
|
||||
rotImage.setRotation(rot);
|
||||
rotImage.draw(100, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
rot += delta * 0.1f;
|
||||
if (rot > 360) {
|
||||
rot -= 360;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
boolean sharedContextTest = false;
|
||||
|
||||
try {
|
||||
exitMe = false;
|
||||
if (sharedContextTest) {
|
||||
GameContainer.enableSharedContext();
|
||||
exitMe = true;
|
||||
}
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new ImageTest());
|
||||
container.setForceExit(!sharedContextTest);
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
|
||||
if (sharedContextTest) {
|
||||
System.out.println("Exit first instance");
|
||||
exitMe = false;
|
||||
container = new AppGameContainer(new ImageTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
}
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_SPACE) {
|
||||
if (image == gif) {
|
||||
image = tga;
|
||||
} else {
|
||||
image = gif;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
lib/slick-source/org/newdawn/slick/tests/InkscapeTest.java
Normal file
128
lib/slick-source/org/newdawn/slick/tests/InkscapeTest.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.svg.InkscapeLoader;
|
||||
import org.newdawn.slick.svg.SimpleDiagramRenderer;
|
||||
|
||||
/**
|
||||
* A rudimentry test of loading SVG from inkscape
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class InkscapeTest extends BasicGame {
|
||||
/** The renderer doing the work */
|
||||
private SimpleDiagramRenderer[] renderer = new SimpleDiagramRenderer[5];
|
||||
/** The zoom */
|
||||
private float zoom = 1;
|
||||
/** The x location */
|
||||
private float x;
|
||||
/** The y location */
|
||||
private float y;
|
||||
|
||||
/**
|
||||
* Create a new test for inkscape loading
|
||||
*/
|
||||
public InkscapeTest() {
|
||||
super("Inkscape Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.getGraphics().setBackground(Color.white);
|
||||
|
||||
InkscapeLoader.RADIAL_TRIANGULATION_LEVEL = 2;
|
||||
|
||||
// renderer[0] = new SimpleDiagramRenderer(InkscapeLoader.load("testdata/svg/orc.svg"));
|
||||
// renderer[1] = new SimpleDiagramRenderer(InkscapeLoader.load("testdata/svg/head2.svg"));
|
||||
// renderer[2] = new SimpleDiagramRenderer(InkscapeLoader.load("testdata/svg/head3.svg"));
|
||||
renderer[3] = new SimpleDiagramRenderer(InkscapeLoader.load("testdata/svg/clonetest.svg"));
|
||||
// renderer[4] = new SimpleDiagramRenderer(InkscapeLoader.load("testdata/svg/cow.svg"));
|
||||
|
||||
container.getGraphics().setBackground(new Color(0.5f,0.7f,1.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
if (container.getInput().isKeyDown(Input.KEY_Q)) {
|
||||
zoom += (delta * 0.01f);
|
||||
if (zoom > 10) {
|
||||
zoom = 10;
|
||||
}
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_A)) {
|
||||
zoom -= (delta * 0.01f);
|
||||
if (zoom < 0.1f) {
|
||||
zoom = 0.1f;
|
||||
}
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {
|
||||
x += (delta * 0.1f);
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
|
||||
x -= (delta * 0.1f);
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_DOWN)) {
|
||||
y += (delta * 0.1f);
|
||||
}
|
||||
if (container.getInput().isKeyDown(Input.KEY_UP)) {
|
||||
y -= (delta * 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.scale(zoom,zoom);
|
||||
g.translate(x, y);
|
||||
g.scale(0.3f,0.3f);
|
||||
//renderer[0].render(g);
|
||||
g.scale(1/0.3f,1/0.3f);
|
||||
g.translate(400, 0);
|
||||
//renderer[1].render(g);
|
||||
g.translate(100, 300);
|
||||
g.scale(0.7f,0.7f);
|
||||
//renderer[2].render(g);
|
||||
g.scale(1/0.7f,1/0.7f);
|
||||
|
||||
g.scale(0.5f,0.5f);
|
||||
g.translate(-1100, -380);
|
||||
renderer[3].render(g);
|
||||
g.scale(1/0.5f,1/0.5f);
|
||||
|
||||
// g.translate(280, 100);
|
||||
// g.scale(0.5f,0.5f);
|
||||
// renderer[4].render(g);
|
||||
|
||||
g.resetTransform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our simple test
|
||||
*
|
||||
* @param argv The arguments passed in
|
||||
*/
|
||||
public static void main(String argv[]) {
|
||||
try {
|
||||
Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
|
||||
Renderer.setLineStripRenderer(Renderer.QUAD_BASED_LINE_STRIP_RENDERER);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new InkscapeTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/slick-source/org/newdawn/slick/tests/InputProviderTest.java
Normal file
102
lib/slick-source/org/newdawn/slick/tests/InputProviderTest.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.command.BasicCommand;
|
||||
import org.newdawn.slick.command.Command;
|
||||
import org.newdawn.slick.command.ControllerButtonControl;
|
||||
import org.newdawn.slick.command.ControllerDirectionControl;
|
||||
import org.newdawn.slick.command.InputProvider;
|
||||
import org.newdawn.slick.command.InputProviderListener;
|
||||
import org.newdawn.slick.command.KeyControl;
|
||||
import org.newdawn.slick.command.MouseButtonControl;
|
||||
|
||||
/**
|
||||
* A test for abstract input via InputProvider
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class InputProviderTest extends BasicGame implements InputProviderListener {
|
||||
/** The command for attack */
|
||||
private Command attack = new BasicCommand("attack");
|
||||
/** The command for jump */
|
||||
private Command jump = new BasicCommand("jump");
|
||||
/** The command for jump */
|
||||
private Command run = new BasicCommand("run");
|
||||
/** The input provider abstracting input */
|
||||
private InputProvider provider;
|
||||
/** The message to be displayed */
|
||||
private String message = "";
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public InputProviderTest() {
|
||||
super("InputProvider Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
provider = new InputProvider(container.getInput());
|
||||
provider.addListener(this);
|
||||
|
||||
provider.bindCommand(new KeyControl(Input.KEY_LEFT), run);
|
||||
provider.bindCommand(new KeyControl(Input.KEY_A), run);
|
||||
provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.LEFT), run);
|
||||
provider.bindCommand(new KeyControl(Input.KEY_UP), jump);
|
||||
provider.bindCommand(new KeyControl(Input.KEY_W), jump);
|
||||
provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.UP), jump);
|
||||
provider.bindCommand(new KeyControl(Input.KEY_SPACE), attack);
|
||||
provider.bindCommand(new MouseButtonControl(0), attack);
|
||||
provider.bindCommand(new ControllerButtonControl(0, 1), attack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("Press A, W, Left, Up, space, mouse button 1,and gamepad controls",10,50);
|
||||
g.drawString(message,100,150);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.command.InputProviderListener#controlPressed(org.newdawn.slick.command.Command)
|
||||
*/
|
||||
public void controlPressed(Command command) {
|
||||
message = "Pressed: "+command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.command.InputProviderListener#controlReleased(org.newdawn.slick.command.Command)
|
||||
*/
|
||||
public void controlReleased(Command command) {
|
||||
message = "Released: "+command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new InputProviderTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
254
lib/slick-source/org/newdawn/slick/tests/InputTest.java
Normal file
254
lib/slick-source/org/newdawn/slick/tests/InputTest.java
Normal file
@@ -0,0 +1,254 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* A test for input
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class InputTest extends BasicGame {
|
||||
/** The message to be displayed */
|
||||
private String message = "Press any key, mouse button, or drag the mouse";
|
||||
/** The lines to be drawn on the screen */
|
||||
private ArrayList lines = new ArrayList();
|
||||
/** True if the mouse button is down */
|
||||
private boolean buttonDown;
|
||||
/** The x position of our controlled stuff */
|
||||
private float x;
|
||||
/** The y position of our controlled stuff */
|
||||
private float y;
|
||||
/** The colors */
|
||||
private Color[] cols = new Color[] {Color.red, Color.green, Color.blue, Color.white, Color.magenta, Color.cyan};
|
||||
/** The current color index */
|
||||
private int index;
|
||||
/** The input syste being polled */
|
||||
private Input input;
|
||||
/** The scroll box */
|
||||
private int ypos;
|
||||
/** The container holding this test */
|
||||
private AppGameContainer app;
|
||||
|
||||
/** True if space is down */
|
||||
private boolean space;
|
||||
/** True if left shift is down */
|
||||
private boolean lshift;
|
||||
/** True if right shift is down */
|
||||
private boolean rshift;
|
||||
|
||||
/**
|
||||
* Create a new input test
|
||||
*/
|
||||
public InputTest() {
|
||||
super("Input Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
if (container instanceof AppGameContainer) {
|
||||
app = (AppGameContainer) container;
|
||||
}
|
||||
|
||||
input = container.getInput();
|
||||
x = 300;
|
||||
y = 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("left shift down: "+lshift, 100, 240);
|
||||
g.drawString("right shift down: "+rshift, 100, 260);
|
||||
g.drawString("space down: "+space, 100, 280);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString(message, 10, 50);
|
||||
g.drawString(""+container.getInput().getMouseY(), 10, 400);
|
||||
g.drawString("Use the primary gamepad to control the blob, and hit a gamepad button to change the color", 10, 90);
|
||||
|
||||
for (int i=0;i<lines.size();i++) {
|
||||
Line line = (Line) lines.get(i);
|
||||
line.draw(g);
|
||||
}
|
||||
|
||||
g.setColor(cols[index]);
|
||||
g.fillOval((int) x, (int) y, 50, 50);
|
||||
g.setColor(Color.yellow);
|
||||
g.fillRect(50,200+ypos,40,40);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
lshift = container.getInput().isKeyDown(Input.KEY_LSHIFT);
|
||||
rshift = container.getInput().isKeyDown(Input.KEY_RSHIFT);
|
||||
space = container.getInput().isKeyDown(Input.KEY_SPACE);
|
||||
|
||||
if (controllerLeft[0]) {
|
||||
x -= delta * 0.1f;
|
||||
}
|
||||
if (controllerRight[0]) {
|
||||
x += delta * 0.1f;
|
||||
}
|
||||
if (controllerUp[0]) {
|
||||
y -= delta * 0.1f;
|
||||
}
|
||||
if (controllerDown[0]) {
|
||||
y += delta * 0.1f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_F1) {
|
||||
if (app != null) {
|
||||
try {
|
||||
app.setDisplayMode(600, 600, false);
|
||||
app.reinit();
|
||||
} catch (Exception e) { Log.error(e); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
message = "You pressed key code "+key+" (character = "+c+")";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
if (button == 0) {
|
||||
buttonDown = true;
|
||||
}
|
||||
|
||||
message = "Mouse pressed "+button+" "+x+","+y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseReleased(int, int, int)
|
||||
*/
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
if (button == 0) {
|
||||
buttonDown = false;
|
||||
}
|
||||
|
||||
message = "Mouse released "+button+" "+x+","+y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseClicked(int, int, int, int)
|
||||
*/
|
||||
public void mouseClicked(int button, int x, int y, int clickCount) {
|
||||
System.out.println("CLICKED:"+x+","+y+" "+clickCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseWheelMoved(int)
|
||||
*/
|
||||
public void mouseWheelMoved(int change) {
|
||||
message = "Mouse wheel moved: "+change;
|
||||
|
||||
if (change < 0) {
|
||||
ypos -= 10;
|
||||
}
|
||||
if (change > 0) {
|
||||
ypos += 10;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseMoved(int, int, int, int)
|
||||
*/
|
||||
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
|
||||
if (buttonDown) {
|
||||
lines.add(new Line(oldx,oldy,newx,newy));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A line that has been drawn by the user
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class Line {
|
||||
/** The start x position */
|
||||
private int oldx;
|
||||
/** The start y position */
|
||||
private int oldy;
|
||||
/** The end x position */
|
||||
private int newx;
|
||||
/** The end y position */
|
||||
private int newy;
|
||||
|
||||
/**
|
||||
* Create a new line
|
||||
*
|
||||
* @param oldx The start x position
|
||||
* @param oldy The start y position
|
||||
* @param newx The end x position
|
||||
* @param newy The end y position
|
||||
*/
|
||||
public Line(int oldx, int oldy,int newx,int newy) {
|
||||
this.oldx = oldx;
|
||||
this.oldy = oldy;
|
||||
this.newx = newx;
|
||||
this.newy = newy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the line to the provided graphics context
|
||||
*
|
||||
* @param g The graphics context on which to draw the line
|
||||
*/
|
||||
public void draw(Graphics g) {
|
||||
g.drawLine(oldx, oldy, newx, newy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerButtonPressed(int, int)
|
||||
*/
|
||||
public void controllerButtonPressed(int controller, int button) {
|
||||
super.controllerButtonPressed(controller, button);
|
||||
|
||||
index ++;
|
||||
index %= cols.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed into our test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new InputTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
lib/slick-source/org/newdawn/slick/tests/IsoTiledTest.java
Normal file
59
lib/slick-source/org/newdawn/slick/tests/IsoTiledTest.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.tiled.TiledMap;
|
||||
import org.newdawn.slick.util.Bootstrap;
|
||||
|
||||
/**
|
||||
* Simple test for isometric map rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class IsoTiledTest extends BasicGame {
|
||||
/** The tilemap we're going to render */
|
||||
private TiledMap tilemap;
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public IsoTiledTest() {
|
||||
super("Isometric Tiled Map Test");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
tilemap = new TiledMap("testdata/isoexample.tmx", "testdata/");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
tilemap.render(350,150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in from the command line
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
Bootstrap.runAsApplication(new IsoTiledTest(), 800,600,false);
|
||||
}
|
||||
}
|
||||
79
lib/slick-source/org/newdawn/slick/tests/KeyRepeatTest.java
Normal file
79
lib/slick-source/org/newdawn/slick/tests/KeyRepeatTest.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for basic image rendering
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class KeyRepeatTest extends BasicGame {
|
||||
/** The number of times the key pressed event has been fired */
|
||||
private int count;
|
||||
/** The input sub system */
|
||||
private Input input;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public KeyRepeatTest() {
|
||||
super("KeyRepeatTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
input = container.getInput();
|
||||
input.enableKeyRepeat(300,100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.drawString("Key Press Count: "+count, 100,100);
|
||||
g.drawString("Press Space to Toggle Key Repeat", 100,150);
|
||||
g.drawString("Key Repeat Enabled: "+input.isKeyRepeatEnabled(), 100,200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new KeyRepeatTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
count++;
|
||||
if (key == Input.KEY_SPACE) {
|
||||
if (input.isKeyRepeatEnabled()) {
|
||||
input.disableKeyRepeat();
|
||||
} else {
|
||||
input.enableKeyRepeat(300,100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
lib/slick-source/org/newdawn/slick/tests/LameTest.java
Normal file
70
lib/slick-source/org/newdawn/slick/tests/LameTest.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
|
||||
/**
|
||||
* Lame test
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class LameTest extends BasicGame {
|
||||
/** The poly being drawn */
|
||||
private Polygon poly = new Polygon();
|
||||
/** The image being textured */
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Create the test
|
||||
*/
|
||||
public LameTest() {
|
||||
super("Lame Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
poly.addPoint(100, 100);
|
||||
poly.addPoint(120, 100);
|
||||
poly.addPoint(120, 120);
|
||||
poly.addPoint(100, 120);
|
||||
|
||||
image = new Image("testdata/rocks.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
g.texture(poly, image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new LameTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/slick-source/org/newdawn/slick/tests/LineRenderTest.java
Normal file
102
lib/slick-source/org/newdawn/slick/tests/LineRenderTest.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Path;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
|
||||
/**
|
||||
* A test for the line rendering capability
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class LineRenderTest extends BasicGame {
|
||||
/** The polygon to be rendered */
|
||||
private Polygon polygon = new Polygon();
|
||||
/** The path to be rendered */
|
||||
private Path path = new Path(100,100);
|
||||
/** The line width to render to */
|
||||
private float width = 10;
|
||||
/** True if antialiasing */
|
||||
private boolean antialias = true;
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public LineRenderTest() {
|
||||
super("LineRenderTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
polygon.addPoint(100,100);
|
||||
polygon.addPoint(200,80);
|
||||
polygon.addPoint(320,150);
|
||||
polygon.addPoint(230,210);
|
||||
polygon.addPoint(170,260);
|
||||
|
||||
path.curveTo(200,200,200,100,100,200);
|
||||
path.curveTo(400,100,400,200,200,100);
|
||||
path.curveTo(500,500,400,200,200,100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
|
||||
antialias = !antialias;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setAntiAlias(antialias);
|
||||
g.setLineWidth(50);
|
||||
g.setColor(Color.red);
|
||||
g.draw(path);
|
||||
|
||||
// g.setColor(Color.red);
|
||||
// TextureImpl.bindNone();
|
||||
// g.setLineWidth(width);
|
||||
// g.setAntiAlias(true);
|
||||
// for (int i=0;i<10;i++) {
|
||||
// g.translate(35,35);
|
||||
// g.draw(polygon);
|
||||
// }
|
||||
// g.translate(-350,-350);
|
||||
//
|
||||
// g.setColor(Color.white);
|
||||
// g.setLineWidth(1);
|
||||
// g.setAntiAlias(false);
|
||||
// g.draw(polygon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
Renderer.setLineStripRenderer(Renderer.QUAD_BASED_LINE_STRIP_RENDERER);
|
||||
Renderer.getLineStripRenderer().setLineCaps(true);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(new LineRenderTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
86
lib/slick-source/org/newdawn/slick/tests/MorphSVGTest.java
Normal file
86
lib/slick-source/org/newdawn/slick/tests/MorphSVGTest.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.svg.Diagram;
|
||||
import org.newdawn.slick.svg.InkscapeLoader;
|
||||
import org.newdawn.slick.svg.SVGMorph;
|
||||
import org.newdawn.slick.svg.SimpleDiagramRenderer;
|
||||
|
||||
/**
|
||||
* A test to try shape morphing
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class MorphSVGTest extends BasicGame {
|
||||
/** The morphing SVG */
|
||||
private SVGMorph morph;
|
||||
/** First shape of the morph */
|
||||
private Diagram base;
|
||||
/** The time index of the morph being display */
|
||||
private float time;
|
||||
/** The current x position */
|
||||
private float x = -300;
|
||||
|
||||
/**
|
||||
* Create a simple test
|
||||
*/
|
||||
public MorphSVGTest() {
|
||||
super("MorphShapeTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#init(GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
base = InkscapeLoader.load("testdata/svg/walk1.svg");
|
||||
morph = new SVGMorph(base);
|
||||
morph.addStep(InkscapeLoader.load("testdata/svg/walk2.svg"));
|
||||
morph.addStep(InkscapeLoader.load("testdata/svg/walk3.svg"));
|
||||
morph.addStep(InkscapeLoader.load("testdata/svg/walk4.svg"));
|
||||
|
||||
container.setVSync(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#update(GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
morph.updateMorphTime(delta * 0.003f);
|
||||
|
||||
x += delta * 0.2f;
|
||||
if (x > 550) {
|
||||
x = -450;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(GameContainer, Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.translate(x, 0);
|
||||
SimpleDiagramRenderer.render(g, morph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(
|
||||
new MorphSVGTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
96
lib/slick-source/org/newdawn/slick/tests/MorphShapeTest.java
Normal file
96
lib/slick-source/org/newdawn/slick/tests/MorphShapeTest.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.MorphShape;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
import org.newdawn.slick.geom.Transform;
|
||||
|
||||
/**
|
||||
* A test to try shape morphing
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class MorphShapeTest extends BasicGame {
|
||||
/** First shape of the morph */
|
||||
private Shape a;
|
||||
/** Second shape of the morph */
|
||||
private Shape b;
|
||||
/** Third shape of the morph */
|
||||
private Shape c;
|
||||
/** The morphing shape */
|
||||
private MorphShape morph;
|
||||
/** The current morph time */
|
||||
private float time;
|
||||
|
||||
/**
|
||||
* Create a simple test
|
||||
*/
|
||||
public MorphShapeTest() {
|
||||
super("MorphShapeTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#init(GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
a = new Rectangle(100,100,50,200);
|
||||
a = a.transform(Transform.createRotateTransform(0.1f,100,100));
|
||||
b = new Rectangle(200,100,50,200);
|
||||
b = b.transform(Transform.createRotateTransform(-0.6f,100,100));
|
||||
c = new Rectangle(300,100,50,200);
|
||||
c = c.transform(Transform.createRotateTransform(-0.2f,100,100));
|
||||
|
||||
morph = new MorphShape(a);
|
||||
morph.addShape(b);
|
||||
morph.addShape(c);
|
||||
|
||||
container.setVSync(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BasicGame#update(GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
time += delta * 0.001f;
|
||||
morph.setMorphTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(GameContainer, Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.setColor(Color.green);
|
||||
g.draw(a);
|
||||
g.setColor(Color.red);
|
||||
g.draw(b);
|
||||
g.setColor(Color.blue);
|
||||
g.draw(c);
|
||||
g.setColor(Color.white);
|
||||
g.draw(morph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(
|
||||
new MorphShapeTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
109
lib/slick-source/org/newdawn/slick/tests/MusicListenerTest.java
Normal file
109
lib/slick-source/org/newdawn/slick/tests/MusicListenerTest.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.Music;
|
||||
import org.newdawn.slick.MusicListener;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for music listeners which notify you when the music has eneded
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class MusicListenerTest extends BasicGame implements MusicListener {
|
||||
/** True if we should display the music ended message */
|
||||
private boolean musicEnded = false;
|
||||
/** True if we should display the music swapped message */
|
||||
private boolean musicSwapped = false;
|
||||
/** The music to be played */
|
||||
private Music music;
|
||||
/** The music to be streamed */
|
||||
private Music stream;
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public MusicListenerTest() {
|
||||
super("Music Listener Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
music = new Music("testdata/restart.ogg", false);
|
||||
stream = new Music("testdata/restart.ogg", false);
|
||||
|
||||
music.addListener(this);
|
||||
stream.addListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.MusicListener#musicEnded(org.newdawn.slick.Music)
|
||||
*/
|
||||
public void musicEnded(Music music) {
|
||||
musicEnded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.MusicListener#musicSwapped(org.newdawn.slick.Music, org.newdawn.slick.Music)
|
||||
*/
|
||||
public void musicSwapped(Music music, Music newMusic) {
|
||||
musicSwapped = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.drawString("Press M to play music", 100, 100);
|
||||
g.drawString("Press S to stream music", 100, 150);
|
||||
if (musicEnded) {
|
||||
g.drawString("Music Ended", 100, 200);
|
||||
}
|
||||
if (musicSwapped) {
|
||||
g.drawString("Music Swapped", 100, 250);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_M) {
|
||||
musicEnded = false;
|
||||
musicSwapped = false;
|
||||
music.play();
|
||||
}
|
||||
if (key == Input.KEY_S) {
|
||||
musicEnded = false;
|
||||
musicSwapped = false;
|
||||
stream.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the sound test
|
||||
*
|
||||
* @param argv The arguments provided to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new MusicListenerTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
258
lib/slick-source/org/newdawn/slick/tests/NavMeshTest.java
Normal file
258
lib/slick-source/org/newdawn/slick/tests/NavMeshTest.java
Normal file
@@ -0,0 +1,258 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.util.Bootstrap;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
import org.newdawn.slick.util.pathfinding.Mover;
|
||||
import org.newdawn.slick.util.pathfinding.PathFindingContext;
|
||||
import org.newdawn.slick.util.pathfinding.TileBasedMap;
|
||||
import org.newdawn.slick.util.pathfinding.navmesh.Link;
|
||||
import org.newdawn.slick.util.pathfinding.navmesh.NavMesh;
|
||||
import org.newdawn.slick.util.pathfinding.navmesh.NavMeshBuilder;
|
||||
import org.newdawn.slick.util.pathfinding.navmesh.NavPath;
|
||||
import org.newdawn.slick.util.pathfinding.navmesh.Space;
|
||||
|
||||
/**
|
||||
* A test to show nav-mesh generation on tile based maps.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class NavMeshTest extends BasicGame implements PathFindingContext {
|
||||
/** The mesh built for this map */
|
||||
private NavMesh navMesh;
|
||||
/** The builder used to create the nav-mesh from the tile based map */
|
||||
private NavMeshBuilder builder;
|
||||
/** True if we're showing the open spaces from the mesh */
|
||||
private boolean showSpaces = true;
|
||||
/** True if we're showing the linking points */
|
||||
private boolean showLinks = true;
|
||||
/** The path if there is one current found between the two points */
|
||||
private NavPath path;
|
||||
|
||||
/** The x coordinate of the start of the search */
|
||||
private float sx;
|
||||
/** The y coordinate of the start of the search */
|
||||
private float sy;
|
||||
/** The x coordinate of the end of the search */
|
||||
private float ex;
|
||||
/** The y coordinate of the end of the search */
|
||||
private float ey;
|
||||
/** The tile based map we're searching across - loaded from a raw file */
|
||||
private DataMap dataMap;
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public NavMeshTest() {
|
||||
super("Nav-mesh Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise resources and the map data
|
||||
*
|
||||
* @param container the container the game is running in
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.setShowFPS(false);
|
||||
|
||||
try {
|
||||
dataMap = new DataMap("testdata/map.dat");
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load map data", e);
|
||||
}
|
||||
builder = new NavMeshBuilder();
|
||||
navMesh = builder.build(dataMap);
|
||||
|
||||
System.out.println("Navmesh shapes: "+navMesh.getSpaceCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data map etc
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_1)) {
|
||||
showLinks = !showLinks;
|
||||
}
|
||||
if (container.getInput().isKeyPressed(Input.KEY_2)) {
|
||||
showSpaces = !showSpaces;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the game - in this case render the map and diagnostic data
|
||||
*
|
||||
* @param container The container we're running the game in
|
||||
* @param g The graphics context on which to render
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g)
|
||||
throws SlickException {
|
||||
g.translate(50,50);
|
||||
for (int x=0;x<50;x++) {
|
||||
for (int y=0;y<50;y++) {
|
||||
if (dataMap.blocked(this, x, y)) {
|
||||
g.setColor(Color.gray);
|
||||
g.fillRect((x*10)+1,(y*10)+1,8,8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showSpaces) {
|
||||
for (int i=0;i<navMesh.getSpaceCount();i++) {
|
||||
Space space = navMesh.getSpace(i);
|
||||
if (builder.clear(dataMap, space)) {
|
||||
g.setColor(new Color(1,1,0,0.5f));
|
||||
g.fillRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);
|
||||
}
|
||||
g.setColor(Color.yellow);
|
||||
g.drawRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);
|
||||
|
||||
if (showLinks) {
|
||||
int links = space.getLinkCount();
|
||||
for (int j=0;j<links;j++) {
|
||||
Link link = space.getLink(j);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect((link.getX()*10)-2, (link.getY()*10)-2,5,5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path != null) {
|
||||
g.setColor(Color.white);
|
||||
for (int i=0;i<path.length()-1;i++) {
|
||||
g.drawLine(path.getX(i)*10, path.getY(i)*10, path.getX(i+1)*10, path.getY(i+1)*10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.PathFindingContext#getMover()
|
||||
*/
|
||||
public Mover getMover() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.PathFindingContext#getSearchDistance()
|
||||
*/
|
||||
public int getSearchDistance() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.PathFindingContext#getSourceX()
|
||||
*/
|
||||
public int getSourceX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.PathFindingContext#getSourceY()
|
||||
*/
|
||||
public int getSourceY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.BasicGame#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
float mx = (x - 50) / 10.0f;
|
||||
float my = (y - 50) / 10.0f;
|
||||
|
||||
if (button == 0) {
|
||||
sx = mx;
|
||||
sy = my;
|
||||
} else {
|
||||
ex = mx;
|
||||
ey = my;
|
||||
}
|
||||
|
||||
path = navMesh.findPath(sx,sy,ex,ey,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple raw map implementation for testing purposes
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class DataMap implements TileBasedMap {
|
||||
/** The map data */
|
||||
private byte[] map = new byte[50*50];
|
||||
|
||||
/**
|
||||
* Create a new map loading it from a file
|
||||
*
|
||||
* @param ref The location to load the map from
|
||||
* @throws IOException Indicatese a failure to access map data
|
||||
*/
|
||||
public DataMap(String ref) throws IOException {
|
||||
ResourceLoader.getResourceAsStream(ref).read(map);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.TileBasedMap#blocked(org.newdawn.slick.util.pathfinding.PathFindingContext, int, int)
|
||||
*/
|
||||
public boolean blocked(PathFindingContext context, int tx, int ty) {
|
||||
if ((tx < 0) || (ty < 0) || (tx >= 50) || (ty >= 50)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return map[tx+(ty*50)] != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.TileBasedMap#getCost(org.newdawn.slick.util.pathfinding.PathFindingContext, int, int)
|
||||
*/
|
||||
public float getCost(PathFindingContext context, int tx, int ty) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.TileBasedMap#getHeightInTiles()
|
||||
*/
|
||||
public int getHeightInTiles() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.TileBasedMap#getWidthInTiles()
|
||||
*/
|
||||
public int getWidthInTiles() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.newdawn.slick.util.pathfinding.TileBasedMap#pathFinderVisited(int, int)
|
||||
*/
|
||||
public void pathFinderVisited(int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to out application
|
||||
*
|
||||
* @param argv The arguments passed to the application
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
Bootstrap.runAsApplication(new NavMeshTest(), 600, 600, false);
|
||||
}
|
||||
}
|
||||
110
lib/slick-source/org/newdawn/slick/tests/PackedSheetTest.java
Normal file
110
lib/slick-source/org/newdawn/slick/tests/PackedSheetTest.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.Animation;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.PackedSpriteSheet;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.SpriteSheet;
|
||||
|
||||
/**
|
||||
* A test for packed sprite sheets
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class PackedSheetTest extends BasicGame {
|
||||
/** The sheet loaded */
|
||||
private PackedSpriteSheet sheet;
|
||||
/** The container holding this game */
|
||||
private GameContainer container;
|
||||
/** The position of the rocket */
|
||||
private float r = -500;
|
||||
/** The rocket's image */
|
||||
private Image rocket;
|
||||
/** The animation for the runner */
|
||||
private Animation runner;
|
||||
/** The angle of roatation */
|
||||
private float ang;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public PackedSheetTest() {
|
||||
super("Packed Sprite Sheet Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
sheet = new PackedSpriteSheet("testdata/testpack.def", Image.FILTER_NEAREST);
|
||||
rocket = sheet.getSprite("rocket");
|
||||
|
||||
SpriteSheet anim = sheet.getSpriteSheet("runner");
|
||||
runner = new Animation();
|
||||
|
||||
for (int y=0;y<2;y++) {
|
||||
for (int x=0;x<6;x++) {
|
||||
runner.addFrame(anim.getSprite(x,y), 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
rocket.draw((int) r,100);
|
||||
runner.draw(250,250);
|
||||
g.scale(1.2f,1.2f);
|
||||
runner.draw(250,250);
|
||||
g.scale(1.2f,1.2f);
|
||||
runner.draw(250,250);
|
||||
g.resetTransform();
|
||||
|
||||
g.rotate(670, 470, ang);
|
||||
sheet.getSprite("floppy").draw(600,400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
r += delta * 0.4f;
|
||||
if (r > 900) {
|
||||
r = -500;
|
||||
}
|
||||
|
||||
ang += delta * 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new PackedSheetTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
92
lib/slick-source/org/newdawn/slick/tests/ParticleTest.java
Normal file
92
lib/slick-source/org/newdawn/slick/tests/ParticleTest.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
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.particles.ParticleSystem;
|
||||
import org.newdawn.slick.particles.effects.FireEmitter;
|
||||
|
||||
/**
|
||||
* A particle test using built in effects
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ParticleTest extends BasicGame {
|
||||
/** The particle system running everything */
|
||||
private ParticleSystem system;
|
||||
/** The particle blending mode */
|
||||
private int mode = ParticleSystem.BLEND_COMBINE;
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public ParticleTest() {
|
||||
super("Particle Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
Image image = new Image("testdata/particle.tga", true);
|
||||
system = new ParticleSystem(image);
|
||||
|
||||
system.addEmitter(new FireEmitter(400,300,45));
|
||||
system.addEmitter(new FireEmitter(200,300,60));
|
||||
system.addEmitter(new FireEmitter(600,300,30));
|
||||
|
||||
//system.setUsePoints(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
for (int i=0;i<100;i++) {
|
||||
g.translate(1,1);
|
||||
system.render();
|
||||
}
|
||||
g.resetTransform();
|
||||
g.drawString("Press space to toggle blending mode", 200, 500);
|
||||
g.drawString("Particle Count: "+(system.getParticleCount()*100), 200, 520);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
system.update(delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
mode = ParticleSystem.BLEND_ADDITIVE == mode ? ParticleSystem.BLEND_COMBINE : ParticleSystem.BLEND_ADDITIVE;
|
||||
system.setBlendingMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new ParticleTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
124
lib/slick-source/org/newdawn/slick/tests/PedigreeTest.java
Normal file
124
lib/slick-source/org/newdawn/slick/tests/PedigreeTest.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
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.particles.ConfigurableEmitter;
|
||||
import org.newdawn.slick.particles.ParticleIO;
|
||||
import org.newdawn.slick.particles.ParticleSystem;
|
||||
|
||||
/**
|
||||
* A test for loading editing particle systems
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class PedigreeTest extends BasicGame {
|
||||
/** The image we're currently displaying */
|
||||
private Image image;
|
||||
/** The game container */
|
||||
private GameContainer container;
|
||||
/** The smoke trail particle system */
|
||||
private ParticleSystem trail;
|
||||
/** The fire particle system */
|
||||
private ParticleSystem fire;
|
||||
/** The rocket x position */
|
||||
private float rx;
|
||||
/** The rocket y position */
|
||||
private float ry = 900;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public PedigreeTest() {
|
||||
super("Pedigree Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
|
||||
try {
|
||||
fire = ParticleIO.loadConfiguredSystem("testdata/system.xml");
|
||||
trail = ParticleIO.loadConfiguredSystem("testdata/smoketrail.xml");
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load particle systems", e);
|
||||
}
|
||||
image = new Image("testdata/rocket.png");
|
||||
|
||||
spawnRocket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a test rocket
|
||||
*/
|
||||
private void spawnRocket() {
|
||||
ry = 700;
|
||||
rx = (float) ((Math.random()*600) + 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
((ConfigurableEmitter) trail.getEmitter(0)).setPosition(rx+14,ry+35);
|
||||
trail.render();
|
||||
image.draw((int) rx,(int) ry);
|
||||
|
||||
g.translate(400, 300);
|
||||
fire.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
fire.update(delta);
|
||||
trail.update(delta);
|
||||
|
||||
ry -= delta * 0.25f;
|
||||
if (ry < -100) {
|
||||
spawnRocket();
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
super.mousePressed(button, x, y);
|
||||
|
||||
for (int i=0;i<fire.getEmitterCount();i++) {
|
||||
((ConfigurableEmitter) fire.getEmitter(i)).setPosition(x - 400, y - 300, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new PedigreeTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
container.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
81
lib/slick-source/org/newdawn/slick/tests/PolygonTest.java
Normal file
81
lib/slick-source/org/newdawn/slick/tests/PolygonTest.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
|
||||
/**
|
||||
* A test for polygon collision
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class PolygonTest extends BasicGame {
|
||||
/** The polygon we're going to test against */
|
||||
private Polygon poly;
|
||||
/** True if the mouse is in the polygon */
|
||||
private boolean in;
|
||||
/** The y offset */
|
||||
private float y;
|
||||
|
||||
/**
|
||||
* Create the test
|
||||
*/
|
||||
public PolygonTest() {
|
||||
super("Polygon Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
poly = new Polygon();
|
||||
poly.addPoint(300, 100);
|
||||
poly.addPoint(320, 200);
|
||||
poly.addPoint(350, 210);
|
||||
poly.addPoint(280, 250);
|
||||
poly.addPoint(300, 200);
|
||||
poly.addPoint(240, 150);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
in = poly.contains(container.getInput().getMouseX(), container.getInput().getMouseY());
|
||||
|
||||
poly.setCenterY(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
if (in) {
|
||||
g.setColor(Color.red);
|
||||
g.fill(poly);
|
||||
}
|
||||
g.setColor(Color.yellow);
|
||||
g.fillOval(poly.getCenterX()-3, poly.getCenterY()-3, 6, 6);
|
||||
g.setColor(Color.white);
|
||||
g.draw(poly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into our test
|
||||
*
|
||||
* @param argv The arguments passed on the command line
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new PolygonTest(), 640, 480, false);
|
||||
container.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
80
lib/slick-source/org/newdawn/slick/tests/PureFontTest.java
Normal file
80
lib/slick-source/org/newdawn/slick/tests/PureFontTest.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Font;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A test of the font rendering capabilities
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class PureFontTest extends BasicGame {
|
||||
/** The font we're going to use to render */
|
||||
private Font font;
|
||||
/** The image */
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public PureFontTest() {
|
||||
super("Hiero Font Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = new Image("testdata/sky.jpg");
|
||||
font = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
image.draw(0,0,800,600);
|
||||
font.drawString(100, 32, "On top of old smokey, all");
|
||||
font.drawString(100, 80, "covered with sand..");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** The container we're using */
|
||||
private static AppGameContainer container;
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
container = new AppGameContainer(new PureFontTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
lib/slick-source/org/newdawn/slick/tests/SavedStateTest.java
Normal file
120
lib/slick-source/org/newdawn/slick/tests/SavedStateTest.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SavedState;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.gui.AbstractComponent;
|
||||
import org.newdawn.slick.gui.ComponentListener;
|
||||
import org.newdawn.slick.gui.TextField;
|
||||
|
||||
/**
|
||||
* A test of the the local storage utilities
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class SavedStateTest extends BasicGame implements ComponentListener {
|
||||
/** The field taking the name */
|
||||
private TextField name;
|
||||
/** The field taking the age */
|
||||
private TextField age;
|
||||
/** The name value */
|
||||
private String nameValue = "none";
|
||||
/** The age value */
|
||||
private int ageValue = 0;
|
||||
/** The saved state */
|
||||
private SavedState state;
|
||||
/** The status message to display */
|
||||
private String message = "Enter a name and age to store";
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public SavedStateTest() {
|
||||
super("Saved State Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
state = new SavedState("testdata");
|
||||
nameValue = state.getString("name","DefaultName");
|
||||
ageValue = (int) state.getNumber("age",64);
|
||||
|
||||
name = new TextField(container,container.getDefaultFont(),100,100,300,20,this);
|
||||
age = new TextField(container,container.getDefaultFont(),100,150,201,20,this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
name.render(container, g);
|
||||
age.render(container, g);
|
||||
|
||||
container.getDefaultFont().drawString(100, 300, "Stored Name: "+nameValue);
|
||||
container.getDefaultFont().drawString(100, 350, "Stored Age: "+ageValue);
|
||||
container.getDefaultFont().drawString(200, 500, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** The container we're using */
|
||||
private static AppGameContainer container;
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
container = new AppGameContainer(new SavedStateTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.gui.ComponentListener#componentActivated(org.newdawn.slick.gui.AbstractComponent)
|
||||
*/
|
||||
public void componentActivated(AbstractComponent source) {
|
||||
if (source == name) {
|
||||
nameValue = name.getText();
|
||||
state.setString("name", nameValue);
|
||||
}
|
||||
if (source == age) {
|
||||
try {
|
||||
ageValue = Integer.parseInt(age.getText());
|
||||
state.setNumber("age", ageValue);
|
||||
} catch (NumberFormatException e) {
|
||||
// ignone
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
state.save();
|
||||
} catch (Exception e) {
|
||||
message = System.currentTimeMillis() + " : Failed to save state";
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/slick-source/org/newdawn/slick/tests/ScalableTest.java
Normal file
102
lib/slick-source/org/newdawn/slick/tests/ScalableTest.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.ScalableGame;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for a scalable game
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ScalableTest extends BasicGame {
|
||||
|
||||
/**
|
||||
* Simple test
|
||||
*/
|
||||
public ScalableTest() {
|
||||
super("Scalable Test For Widescreen");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(new Color(0.4f,0.6f,0.8f));
|
||||
g.fillRect(0,0, 1024,568);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(5,5, 1024-10,568-10);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString(container.getInput().getMouseX()+","+container.getInput().getMouseY(), 10, 400);
|
||||
g.setColor(Color.red);
|
||||
g.fillOval(container.getInput().getMouseX()-10,container.getInput().getMouseY()-10,20,20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
// normal res
|
||||
// try {
|
||||
// AppGameContainer container = new AppGameContainer(new ScalableGame(new InputTest(),600,600));
|
||||
// container.setDisplayMode(600,600,false);
|
||||
// container.start();
|
||||
// } catch (SlickException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// smaller
|
||||
// try {
|
||||
// AppGameContainer container = new AppGameContainer(new ScalableGame(new InputTest(),600,600));
|
||||
// container.setDisplayMode(300,300,false);
|
||||
// container.start();
|
||||
// } catch (SlickException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// // bigger
|
||||
// try {
|
||||
// AppGameContainer container = new AppGameContainer(new ScalableGame(new InputTest(),600,600,true));
|
||||
// container.setDisplayMode(800,800,false);
|
||||
// container.start();
|
||||
// } catch (SlickException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// maintain aspect ratio
|
||||
try {
|
||||
ScalableGame game = new ScalableGame(new ScalableTest(),1024,568,true) {
|
||||
|
||||
protected void renderOverlay(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Outside The Game", 350, 10);
|
||||
g.drawString(container.getInput().getMouseX()+","+container.getInput().getMouseY(), 400, 20);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AppGameContainer container = new AppGameContainer(game);
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
291
lib/slick-source/org/newdawn/slick/tests/ShapeTest.java
Normal file
291
lib/slick-source/org/newdawn/slick/tests/ShapeTest.java
Normal file
@@ -0,0 +1,291 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Circle;
|
||||
import org.newdawn.slick.geom.Ellipse;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.RoundedRectangle;
|
||||
import org.newdawn.slick.geom.Shape;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
|
||||
/**
|
||||
* A geomertry test
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ShapeTest extends BasicGame {
|
||||
/** rectangle to display */
|
||||
private Rectangle rect;
|
||||
/** rounded rectangle to display */
|
||||
private RoundedRectangle roundRect;
|
||||
/** ellipse to display */
|
||||
private Ellipse ellipse;
|
||||
/** circle to display */
|
||||
private Circle circle;
|
||||
/** polygon to display */
|
||||
private Polygon polygon;
|
||||
/** list for drawing the shapes*/
|
||||
private ArrayList shapes;
|
||||
/** track key presses */
|
||||
private boolean keys[];
|
||||
/** since no modifiers, use this for shifted characters */
|
||||
private char lastChar[];
|
||||
/** The polgon randomly generated */
|
||||
private Polygon randomShape = new Polygon();
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public ShapeTest() {
|
||||
super("Geom Test");
|
||||
}
|
||||
|
||||
public void createPoly(float x, float y) {
|
||||
int size = 20;
|
||||
int change = 10;
|
||||
|
||||
randomShape = new Polygon();
|
||||
// generate random polygon
|
||||
randomShape.addPoint(0 + (int)(Math.random() * change), 0 + (int)(Math.random() * change));
|
||||
randomShape.addPoint(size - (int)(Math.random() * change), 0 + (int)(Math.random() * change));
|
||||
randomShape.addPoint(size - (int)(Math.random() * change), size - (int)(Math.random() * change));
|
||||
randomShape.addPoint(0 + (int)(Math.random() * change), size - (int)(Math.random() * change));
|
||||
|
||||
// center polygon
|
||||
randomShape.setCenterX(x);
|
||||
randomShape.setCenterY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
shapes = new ArrayList();
|
||||
rect = new Rectangle(10, 10, 100, 80);
|
||||
shapes.add(rect);
|
||||
roundRect = new RoundedRectangle(150, 10, 60, 80, 20);
|
||||
shapes.add(roundRect);
|
||||
ellipse = new Ellipse(350, 40, 50, 30);
|
||||
shapes.add(ellipse);
|
||||
circle = new Circle(470, 60, 50);
|
||||
shapes.add(circle);
|
||||
polygon = new Polygon(new float[]{550, 10, 600, 40, 620, 100, 570, 130});
|
||||
shapes.add(polygon);
|
||||
|
||||
keys = new boolean[256];
|
||||
lastChar = new char[256];
|
||||
createPoly(200,200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.green);
|
||||
|
||||
for(int i=0;i<shapes.size();i++) {
|
||||
g.fill((Shape)shapes.get(i));
|
||||
}
|
||||
g.fill(randomShape);
|
||||
g.setColor(Color.black);
|
||||
g.setAntiAlias(true);
|
||||
g.draw(randomShape);
|
||||
g.setAntiAlias(false);
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.drawString("keys", 10, 300);
|
||||
g.drawString("wasd - move rectangle", 10, 315);
|
||||
g.drawString("WASD - resize rectangle", 10, 330);
|
||||
g.drawString("tgfh - move rounded rectangle", 10, 345);
|
||||
g.drawString("TGFH - resize rounded rectangle", 10, 360);
|
||||
g.drawString("ry - resize corner radius on rounded rectangle", 10, 375);
|
||||
g.drawString("ikjl - move ellipse", 10, 390);
|
||||
g.drawString("IKJL - resize ellipse", 10, 405);
|
||||
g.drawString("Arrows - move circle", 10, 420);
|
||||
g.drawString("Page Up/Page Down - resize circle", 10, 435);
|
||||
g.drawString("numpad 8546 - move polygon", 10, 450);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
|
||||
createPoly(200,200);
|
||||
if(keys[Input.KEY_ESCAPE]) {
|
||||
System.exit(0);
|
||||
}
|
||||
if(keys[Input.KEY_W]) {
|
||||
if(lastChar[Input.KEY_W] == 'w') {
|
||||
rect.setY(rect.getY() - 1);
|
||||
}
|
||||
else {
|
||||
rect.setHeight(rect.getHeight() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_S]) {
|
||||
if(lastChar[Input.KEY_S] == 's') {
|
||||
rect.setY(rect.getY() + 1);
|
||||
}
|
||||
else {
|
||||
rect.setHeight(rect.getHeight() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_A]) {
|
||||
if(lastChar[Input.KEY_A] == 'a') {
|
||||
rect.setX(rect.getX() - 1);
|
||||
}
|
||||
else {
|
||||
rect.setWidth(rect.getWidth() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_D]) {
|
||||
if(lastChar[Input.KEY_D] == 'd') {
|
||||
rect.setX(rect.getX() + 1);
|
||||
}
|
||||
else {
|
||||
rect.setWidth(rect.getWidth() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_T]) {
|
||||
if(lastChar[Input.KEY_T] == 't') {
|
||||
roundRect.setY(roundRect.getY() - 1);
|
||||
}
|
||||
else {
|
||||
roundRect.setHeight(roundRect.getHeight() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_G]) {
|
||||
if(lastChar[Input.KEY_G] == 'g') {
|
||||
roundRect.setY(roundRect.getY() + 1);
|
||||
}
|
||||
else {
|
||||
roundRect.setHeight(roundRect.getHeight() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_F]) {
|
||||
if(lastChar[Input.KEY_F] == 'f') {
|
||||
roundRect.setX(roundRect.getX() - 1);
|
||||
}
|
||||
else {
|
||||
roundRect.setWidth(roundRect.getWidth() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_H]) {
|
||||
if(lastChar[Input.KEY_H] == 'h') {
|
||||
roundRect.setX(roundRect.getX() + 1);
|
||||
}
|
||||
else {
|
||||
roundRect.setWidth(roundRect.getWidth() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_R]) {
|
||||
roundRect.setCornerRadius(roundRect.getCornerRadius() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_Y]) {
|
||||
roundRect.setCornerRadius(roundRect.getCornerRadius() + 1);
|
||||
}
|
||||
if(keys[Input.KEY_I]) {
|
||||
if(lastChar[Input.KEY_I] == 'i') {
|
||||
ellipse.setCenterY(ellipse.getCenterY() - 1);
|
||||
}
|
||||
else {
|
||||
ellipse.setRadius2(ellipse.getRadius2() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_K]) {
|
||||
if(lastChar[Input.KEY_K] == 'k') {
|
||||
ellipse.setCenterY(ellipse.getCenterY() + 1);
|
||||
}
|
||||
else {
|
||||
ellipse.setRadius2(ellipse.getRadius2() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_J]) {
|
||||
if(lastChar[Input.KEY_J] == 'j') {
|
||||
ellipse.setCenterX(ellipse.getCenterX() - 1);
|
||||
}
|
||||
else {
|
||||
ellipse.setRadius1(ellipse.getRadius1() - 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_L]) {
|
||||
if(lastChar[Input.KEY_L] == 'l') {
|
||||
ellipse.setCenterX(ellipse.getCenterX() + 1);
|
||||
}
|
||||
else {
|
||||
ellipse.setRadius1(ellipse.getRadius1() + 1);
|
||||
}
|
||||
}
|
||||
if(keys[Input.KEY_UP]) {
|
||||
circle.setCenterY(circle.getCenterY() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_DOWN]) {
|
||||
circle.setCenterY(circle.getCenterY() + 1);
|
||||
}
|
||||
if(keys[Input.KEY_LEFT]) {
|
||||
circle.setCenterX(circle.getCenterX() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_RIGHT]) {
|
||||
circle.setCenterX(circle.getCenterX() + 1);
|
||||
}
|
||||
if(keys[Input.KEY_PRIOR]) {
|
||||
circle.setRadius(circle.getRadius() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_NEXT]) {
|
||||
circle.setRadius(circle.getRadius() + 1);
|
||||
}
|
||||
if(keys[Input.KEY_NUMPAD8]) {
|
||||
polygon.setY(polygon.getY() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_NUMPAD5]) {
|
||||
polygon.setY(polygon.getY() + 1);
|
||||
}
|
||||
if(keys[Input.KEY_NUMPAD4]) {
|
||||
polygon.setX(polygon.getX() - 1);
|
||||
}
|
||||
if(keys[Input.KEY_NUMPAD6]) {
|
||||
polygon.setX(polygon.getX() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
keys[key] = true;
|
||||
lastChar[key] = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
keys[key] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
|
||||
AppGameContainer container = new AppGameContainer(new ShapeTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
244
lib/slick-source/org/newdawn/slick/tests/SlickCallableTest.java
Normal file
244
lib/slick-source/org/newdawn/slick/tests/SlickCallableTest.java
Normal file
@@ -0,0 +1,244 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.Animation;
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.SpriteSheet;
|
||||
import org.newdawn.slick.opengl.SlickCallable;
|
||||
|
||||
/**
|
||||
* A test for slick callables giving the chance to perform normal GL in mid Slick render
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class SlickCallableTest extends BasicGame {
|
||||
/** The image to be draw using normal Slick */
|
||||
private Image image;
|
||||
/** The image to be draw using normal Slick */
|
||||
private Image back;
|
||||
/** The rotation of the cog */
|
||||
private float rot;
|
||||
/** The font used to draw over */
|
||||
private AngelCodeFont font;
|
||||
/** The homer animation */
|
||||
private Animation homer;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public SlickCallableTest() {
|
||||
super("Slick Callable Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = new Image("testdata/rocket.png");
|
||||
back = new Image("testdata/sky.jpg");
|
||||
font = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
|
||||
SpriteSheet sheet = new SpriteSheet("testdata/homeranim.png", 36, 65);
|
||||
homer = new Animation(sheet, 0,0,7,0,true,150,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.scale(2,2);
|
||||
g.fillRect(0, 0, 800, 600, back, 0, 0);
|
||||
g.resetTransform();
|
||||
|
||||
g.drawImage(image,100,100);
|
||||
image.draw(100,200,80,200);
|
||||
|
||||
font.drawString(100,200,"Text Drawn before the callable");
|
||||
|
||||
SlickCallable callable = new SlickCallable() {
|
||||
protected void performGLOperations() throws SlickException {
|
||||
renderGL();
|
||||
}
|
||||
};
|
||||
callable.call();
|
||||
|
||||
homer.draw(450,250,80,200);
|
||||
font.drawString(150,300,"Text Drawn after the callable");
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the GL scene, this isn't efficient and if you know
|
||||
* OpenGL I'm assuming you can see why. If not, you probably
|
||||
* don't want to use this feature anyway
|
||||
*/
|
||||
public void renderGL() {
|
||||
FloatBuffer pos = BufferUtils.createFloatBuffer(4);
|
||||
pos.put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}).flip();
|
||||
FloatBuffer red = BufferUtils.createFloatBuffer(4);
|
||||
red.put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}).flip();
|
||||
|
||||
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
|
||||
GL11.glEnable(GL11.GL_LIGHT0);
|
||||
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
float h = (float) 600 / (float) 800;
|
||||
GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glTranslatef(0.0f, 0.0f, -40.0f);
|
||||
GL11.glRotatef(rot,0,1,1);
|
||||
|
||||
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a single gear
|
||||
*
|
||||
* @param inner_radius The inner radius of the gear
|
||||
* @param outer_radius The outer radius of the gear
|
||||
* @param width The width/depth of the gear
|
||||
* @param teeth The number of teeth
|
||||
* @param tooth_depth The depth of each tooth
|
||||
*/
|
||||
private void gear(float inner_radius, float outer_radius, float width, int teeth, float tooth_depth) {
|
||||
int i;
|
||||
float r0, r1, r2;
|
||||
float angle, da;
|
||||
float u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0f;
|
||||
r2 = outer_radius + tooth_depth / 2.0f;
|
||||
|
||||
da = 2.0f * (float) Math.PI / teeth / 4.0f;
|
||||
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
|
||||
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
/* draw front face */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
if (i < teeth) {
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da),
|
||||
width * 0.5f);
|
||||
}
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
/* draw back face */
|
||||
GL11.glNormal3f(0.0f, 0.0f, -1.0f);
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
|
||||
v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
|
||||
len = (float) Math.sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
GL11.glNormal3f(v, -u, 0.0f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
|
||||
v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
|
||||
GL11.glNormal3f(v, -u, 0.0f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
}
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
rot += delta * 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new SlickCallableTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.Music;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
|
||||
/**
|
||||
* A test for the sound system (positioning) of the library
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class SoundPositionTest extends BasicGame {
|
||||
/** the GameContainer instance for this game/testcase */
|
||||
private GameContainer myContainer;
|
||||
/** The music to be played */
|
||||
private Music music;
|
||||
|
||||
/** The IDs of the sources used for each engine noise */
|
||||
private int[] engines = new int[3];
|
||||
|
||||
/**
|
||||
* Create a new test for sounds
|
||||
*/
|
||||
public SoundPositionTest() {
|
||||
super("Music Position Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
SoundStore.get().setMaxSources(32);
|
||||
|
||||
myContainer = container;
|
||||
music = new Music("testdata/kirby.ogg", true);
|
||||
music.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("Position: "+music.getPosition(), 100,100);
|
||||
g.drawString("Space - Pause/Resume", 100,130);
|
||||
g.drawString("Right Arrow - Advance 5 seconds", 100, 145);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_SPACE) {
|
||||
if (music.playing()) {
|
||||
music.pause();
|
||||
} else {
|
||||
music.resume();
|
||||
}
|
||||
}
|
||||
if (key == Input.KEY_RIGHT) {
|
||||
music.setPosition(music.getPosition()+5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the sound test
|
||||
*
|
||||
* @param argv The arguments provided to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new SoundPositionTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
225
lib/slick-source/org/newdawn/slick/tests/SoundTest.java
Normal file
225
lib/slick-source/org/newdawn/slick/tests/SoundTest.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.Music;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.Sound;
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
import org.newdawn.slick.openal.AudioLoader;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
|
||||
/**
|
||||
* A test for the sound system of the library
|
||||
*
|
||||
* @author kevin
|
||||
* @author aaron
|
||||
*/
|
||||
public class SoundTest extends BasicGame {
|
||||
/** the GameContainer instance for this game/testcase */
|
||||
private GameContainer myContainer;
|
||||
/** The sound to be played */
|
||||
private Sound sound;
|
||||
/** The sound to be played */
|
||||
private Sound charlie;
|
||||
/** The sound to be played */
|
||||
private Sound burp;
|
||||
/** The music to be played */
|
||||
private Music music;
|
||||
/** first music that can be played */
|
||||
private Music musica;
|
||||
/** second music that can be played */
|
||||
private Music musicb;
|
||||
/** The sound to be played */
|
||||
private Audio engine;
|
||||
/** The Volume of the playing music */
|
||||
private int volume = 10;
|
||||
|
||||
/** The IDs of the sources used for each engine noise */
|
||||
private int[] engines = new int[3];
|
||||
|
||||
/**
|
||||
* Create a new test for sounds
|
||||
*/
|
||||
public SoundTest() {
|
||||
super("Sound And Music Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
SoundStore.get().setMaxSources(32);
|
||||
|
||||
myContainer = container;
|
||||
sound = new Sound("testdata/restart.ogg");
|
||||
charlie = new Sound("testdata/cbrown01.wav");
|
||||
try {
|
||||
engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
|
||||
} catch (IOException e) {
|
||||
throw new SlickException("Failed to load engine", e);
|
||||
}
|
||||
music = musica = new Music("testdata/SMB-X.XM");
|
||||
//music = musica = new Music("testdata/theme.ogg", true);
|
||||
musicb = new Music("testdata/kirby.ogg", true);
|
||||
burp = new Sound("testdata/burp.aif");
|
||||
|
||||
music.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("The OGG loop is now streaming from the file, woot.",100,60);
|
||||
g.drawString("Press space for sound effect (OGG)",100,100);
|
||||
g.drawString("Press P to pause/resume music (XM)",100,130);
|
||||
g.drawString("Press E to pause/resume engine sound (WAV)",100,190);
|
||||
g.drawString("Press enter for charlie (WAV)",100,160);
|
||||
g.drawString("Press C to change music",100,210);
|
||||
g.drawString("Press B to burp (AIF)",100,240);
|
||||
g.drawString("Press + or - to change global volume of music", 100, 270);
|
||||
g.drawString("Press Y or X to change individual volume of music", 100, 300);
|
||||
g.drawString("Press N or M to change global volume of sound fx", 100, 330);
|
||||
g.setColor(Color.blue);
|
||||
g.drawString("Global Sound Volume Level: " + container.getSoundVolume(), 150, 390);
|
||||
g.drawString("Global Music Volume Level: " + container.getMusicVolume(), 150, 420);
|
||||
g.drawString("Current Music Volume Level: " + music.getVolume(), 150, 450);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
sound.play();
|
||||
}
|
||||
if (key == Input.KEY_B) {
|
||||
burp.play();
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
sound.playAt(-1, 0, 0);
|
||||
}
|
||||
if (key == Input.KEY_L) {
|
||||
sound.playAt(1, 0, 0);
|
||||
}
|
||||
if (key == Input.KEY_RETURN) {
|
||||
charlie.play(1.0f,1.0f);
|
||||
}
|
||||
if (key == Input.KEY_P) {
|
||||
if (music.playing()) {
|
||||
music.pause();
|
||||
} else {
|
||||
music.resume();
|
||||
}
|
||||
}
|
||||
if (key == Input.KEY_C) {
|
||||
music.stop();
|
||||
if (music == musica) {
|
||||
music = musicb;
|
||||
} else {
|
||||
music = musica;
|
||||
}
|
||||
|
||||
music.loop();
|
||||
}
|
||||
for (int i=0;i<3;i++) {
|
||||
if (key == Input.KEY_1+i) {
|
||||
if (engines[i] != 0) {
|
||||
System.out.println("Stop "+i);
|
||||
SoundStore.get().stopSoundEffect(engines[i]);
|
||||
engines[i] = 0;
|
||||
} else {
|
||||
System.out.println("Start "+i);
|
||||
engines[i] = engine.playAsSoundEffect(1, 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '+') {
|
||||
volume += 1;
|
||||
setVolume();
|
||||
}
|
||||
|
||||
if (c == '-') {
|
||||
volume -= 1;
|
||||
setVolume();
|
||||
}
|
||||
|
||||
if (key == Input.KEY_Y) {
|
||||
int vol = (int) (music.getVolume() * 10);
|
||||
vol --;
|
||||
if (vol < 0) vol = 0;
|
||||
// set individual volume of music
|
||||
music.setVolume(vol/10.0f);
|
||||
}
|
||||
if (key == Input.KEY_X) {
|
||||
int vol = (int) (music.getVolume() * 10);
|
||||
vol ++;
|
||||
if (vol > 10) vol = 10;
|
||||
// set individual volume of music
|
||||
music.setVolume(vol/10.0f);
|
||||
}
|
||||
if (key == Input.KEY_N) {
|
||||
int vol = (int) (myContainer.getSoundVolume() * 10);
|
||||
vol --;
|
||||
if (vol < 0) vol = 0;
|
||||
// set global volume of sound fx
|
||||
myContainer.setSoundVolume(vol/10.0f);
|
||||
}
|
||||
if (key == Input.KEY_M) {
|
||||
int vol = (int) (myContainer.getSoundVolume() * 10);
|
||||
vol ++;
|
||||
if (vol > 10) vol = 10;
|
||||
// set global volume of sound fx
|
||||
myContainer.setSoundVolume(vol/10.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience routine to set global volume of music
|
||||
*/
|
||||
private void setVolume() {
|
||||
// Do bounds checking
|
||||
if(volume > 10) {
|
||||
volume = 10;
|
||||
} else if(volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
|
||||
myContainer.setMusicVolume(volume / 10.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the sound test
|
||||
*
|
||||
* @param argv The arguments provided to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new SoundTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
168
lib/slick-source/org/newdawn/slick/tests/SoundURLTest.java
Normal file
168
lib/slick-source/org/newdawn/slick/tests/SoundURLTest.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.Music;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.Sound;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
|
||||
/**
|
||||
* A test for the sound system of the library
|
||||
*
|
||||
* @author kevin
|
||||
* @author aaron
|
||||
*/
|
||||
public class SoundURLTest extends BasicGame {
|
||||
/** The sound to be played */
|
||||
private Sound sound;
|
||||
/** The sound to be played */
|
||||
private Sound charlie;
|
||||
/** The sound to be played */
|
||||
private Sound burp;
|
||||
/** The music to be played */
|
||||
private Music music;
|
||||
/** The music to be played */
|
||||
private Music musica;
|
||||
/** The music to be played */
|
||||
private Music musicb;
|
||||
/** The sound to be played */
|
||||
private Sound engine;
|
||||
/** The Volume of the playing music */
|
||||
private int volume = 1;
|
||||
|
||||
/**
|
||||
* Create a new test for sounds
|
||||
*/
|
||||
public SoundURLTest() {
|
||||
super("Sound URL Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
sound = new Sound(ResourceLoader.getResource("testdata/restart.ogg"));
|
||||
charlie = new Sound(ResourceLoader.getResource("testdata/cbrown01.wav"));
|
||||
engine = new Sound(ResourceLoader.getResource("testdata/engine.wav"));
|
||||
//music = musica = new Music("testdata/SMB-X.XM");
|
||||
music = musica = new Music(ResourceLoader.getResource("testdata/restart.ogg"), false);
|
||||
musicb = new Music(ResourceLoader.getResource("testdata/kirby.ogg"), false);
|
||||
burp = new Sound(ResourceLoader.getResource("testdata/burp.aif"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.drawString("The OGG loop is now streaming from the file, woot.",100,60);
|
||||
g.drawString("Press space for sound effect (OGG)",100,100);
|
||||
g.drawString("Press P to pause/resume music (XM)",100,130);
|
||||
g.drawString("Press E to pause/resume engine sound (WAV)",100,190);
|
||||
g.drawString("Press enter for charlie (WAV)",100,160);
|
||||
g.drawString("Press C to change music",100,210);
|
||||
g.drawString("Press B to burp (AIF)",100,240);
|
||||
g.drawString("Press + or - to change volume of music", 100, 270);
|
||||
g.setColor(Color.blue);
|
||||
g.drawString("Music Volume Level: " + volume / 10.0f, 150, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
sound.play();
|
||||
}
|
||||
if (key == Input.KEY_B) {
|
||||
burp.play();
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
sound.playAt(-1, 0, 0);
|
||||
}
|
||||
if (key == Input.KEY_L) {
|
||||
sound.playAt(1, 0, 0);
|
||||
}
|
||||
if (key == Input.KEY_RETURN) {
|
||||
charlie.play(1.0f,1.0f);
|
||||
}
|
||||
if (key == Input.KEY_P) {
|
||||
if (music.playing()) {
|
||||
music.pause();
|
||||
} else {
|
||||
music.resume();
|
||||
}
|
||||
}
|
||||
if (key == Input.KEY_C) {
|
||||
music.stop();
|
||||
if (music == musica) {
|
||||
music = musicb;
|
||||
} else {
|
||||
music = musica;
|
||||
}
|
||||
|
||||
music.loop();
|
||||
}
|
||||
if (key == Input.KEY_E) {
|
||||
if (engine.playing()) {
|
||||
engine.stop();
|
||||
} else {
|
||||
engine.loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '+') {
|
||||
volume += 1;
|
||||
setVolume();
|
||||
}
|
||||
|
||||
if (c == '-') {
|
||||
volume -= 1;
|
||||
setVolume();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience routine to set volume of current music
|
||||
*/
|
||||
private void setVolume() {
|
||||
// Do bounds checking
|
||||
if(volume > 10) {
|
||||
volume = 10;
|
||||
} else if(volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
|
||||
music.setVolume(volume / 10.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the sound test
|
||||
*
|
||||
* @param argv The arguments provided to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new SoundURLTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.*;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* Tests the SpriteSheetFont.
|
||||
*
|
||||
* @author Onno Scheffers
|
||||
*/
|
||||
public class SpriteSheetFontTest extends BasicGame {
|
||||
/**
|
||||
* The font we're going to use to render
|
||||
*/
|
||||
private Font font;
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public SpriteSheetFontTest() {
|
||||
super("SpriteSheetFont Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
SpriteSheet sheet = new SpriteSheet("testdata/spriteSheetFont.png", 32, 32);
|
||||
font = new SpriteSheetFont(sheet, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setBackground(Color.gray);
|
||||
font.drawString(80, 5, "A FONT EXAMPLE", Color.red);
|
||||
font.drawString(100, 50, "A MORE COMPLETE LINE");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer,int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
try {
|
||||
container.setDisplayMode(640, 480, false);
|
||||
} catch (SlickException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The container we're using
|
||||
*/
|
||||
private static AppGameContainer container;
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
container = new AppGameContainer(new SpriteSheetFontTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
48
lib/slick-source/org/newdawn/slick/tests/StateBasedTest.java
Normal file
48
lib/slick-source/org/newdawn/slick/tests/StateBasedTest.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.tests.states.TestState1;
|
||||
import org.newdawn.slick.tests.states.TestState2;
|
||||
import org.newdawn.slick.tests.states.TestState3;
|
||||
|
||||
/**
|
||||
* A test for the multi-state based functionality
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class StateBasedTest extends StateBasedGame {
|
||||
|
||||
/**
|
||||
* Create a new test
|
||||
*/
|
||||
public StateBasedTest() {
|
||||
super("State Based Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.StateBasedGame#initStatesList(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void initStatesList(GameContainer container) {
|
||||
addState(new TestState1());
|
||||
addState(new TestState2());
|
||||
addState(new TestState3());
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new StateBasedTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
274
lib/slick-source/org/newdawn/slick/tests/TestBox.java
Normal file
274
lib/slick-source/org/newdawn/slick/tests/TestBox.java
Normal file
@@ -0,0 +1,274 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.SlickCallable;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* A test box containing a bunch of tests that can be used for quickly sanity
|
||||
* checking tests.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TestBox extends BasicGame {
|
||||
/** The games that have been added */
|
||||
private ArrayList games = new ArrayList();
|
||||
/** The current game */
|
||||
private BasicGame currentGame;
|
||||
/** The index of the current game */
|
||||
private int index;
|
||||
/** The game container */
|
||||
private AppGameContainer container;
|
||||
|
||||
/**
|
||||
* Create a new box containing all the tests
|
||||
*/
|
||||
public TestBox() {
|
||||
super("Test Box");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a game to the box
|
||||
*
|
||||
* @param game The game to add to the test box
|
||||
*/
|
||||
public void addGame(Class game) {
|
||||
games.add(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the next game
|
||||
*/
|
||||
private void nextGame() {
|
||||
if (index == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
if (index >= games.size()) {
|
||||
index=0;
|
||||
}
|
||||
|
||||
startGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a particular game
|
||||
*/
|
||||
private void startGame() {
|
||||
try {
|
||||
currentGame = (BasicGame) ((Class) games.get(index)).newInstance();
|
||||
container.getGraphics().setBackground(Color.black);
|
||||
currentGame.init(container);
|
||||
currentGame.render(container, container.getGraphics());
|
||||
} catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
container.setTitle(currentGame.getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer c) throws SlickException {
|
||||
if (games.size() == 0) {
|
||||
currentGame = new BasicGame("NULL") {
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
}
|
||||
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
}
|
||||
};
|
||||
currentGame.init(c);
|
||||
index = -1;
|
||||
} else {
|
||||
index = 0;
|
||||
container = (AppGameContainer) c;
|
||||
startGame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
currentGame.update(container, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
SlickCallable.enterSafeBlock();
|
||||
currentGame.render(container, g);
|
||||
SlickCallable.leaveSafeBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerButtonPressed(int, int)
|
||||
*/
|
||||
public void controllerButtonPressed(int controller, int button) {
|
||||
currentGame.controllerButtonPressed(controller, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerButtonReleased(int, int)
|
||||
*/
|
||||
public void controllerButtonReleased(int controller, int button) {
|
||||
currentGame.controllerButtonReleased(controller, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerDownPressed(int)
|
||||
*/
|
||||
public void controllerDownPressed(int controller) {
|
||||
currentGame.controllerDownPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerDownReleased(int)
|
||||
*/
|
||||
public void controllerDownReleased(int controller) {
|
||||
currentGame.controllerDownReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerLeftPressed(int)
|
||||
*/
|
||||
public void controllerLeftPressed(int controller) {
|
||||
currentGame.controllerLeftPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerLeftReleased(int)
|
||||
*/
|
||||
public void controllerLeftReleased(int controller) {
|
||||
currentGame.controllerLeftReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerRightPressed(int)
|
||||
*/
|
||||
public void controllerRightPressed(int controller) {
|
||||
currentGame.controllerRightPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerRightReleased(int)
|
||||
*/
|
||||
public void controllerRightReleased(int controller) {
|
||||
currentGame.controllerRightReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerUpPressed(int)
|
||||
*/
|
||||
public void controllerUpPressed(int controller) {
|
||||
currentGame.controllerUpPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#controllerUpReleased(int)
|
||||
*/
|
||||
public void controllerUpReleased(int controller) {
|
||||
currentGame.controllerUpReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
currentGame.keyPressed(key, c);
|
||||
|
||||
if (key == Input.KEY_ENTER) {
|
||||
nextGame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
currentGame.keyReleased(key, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseMoved(int, int, int, int)
|
||||
*/
|
||||
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
|
||||
currentGame.mouseMoved(oldx, oldy, newx, newy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
currentGame.mousePressed(button, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseReleased(int, int, int)
|
||||
*/
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
currentGame.mouseReleased(button, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#mouseWheelMoved(int)
|
||||
*/
|
||||
public void mouseWheelMoved(int change) {
|
||||
currentGame.mouseWheelMoved(change);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
TestBox box = new TestBox();
|
||||
box.addGame(AnimationTest.class);
|
||||
box.addGame(AntiAliasTest.class);
|
||||
box.addGame(BigImageTest.class);
|
||||
box.addGame(ClipTest.class);
|
||||
box.addGame(DuplicateEmitterTest.class);
|
||||
box.addGame(FlashTest.class);
|
||||
box.addGame(FontPerformanceTest.class);
|
||||
box.addGame(FontTest.class);
|
||||
box.addGame(GeomTest.class);
|
||||
box.addGame(GradientTest.class);
|
||||
box.addGame(GraphicsTest.class);
|
||||
box.addGame(ImageBufferTest.class);
|
||||
box.addGame(ImageReadTest.class);
|
||||
box.addGame(ImageTest.class);
|
||||
box.addGame(KeyRepeatTest.class);
|
||||
box.addGame(MusicListenerTest.class);
|
||||
box.addGame(PackedSheetTest.class);
|
||||
box.addGame(PedigreeTest.class);
|
||||
box.addGame(PureFontTest.class);
|
||||
box.addGame(ShapeTest.class);
|
||||
box.addGame(SoundTest.class);
|
||||
box.addGame(SpriteSheetFontTest.class);
|
||||
box.addGame(TransparentColorTest.class);
|
||||
|
||||
AppGameContainer container = new AppGameContainer(box);
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
223
lib/slick-source/org/newdawn/slick/tests/TestUtils.java
Normal file
223
lib/slick-source/org/newdawn/slick/tests/TestUtils.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.TrueTypeFont;
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
import org.newdawn.slick.openal.AudioLoader;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
import org.newdawn.slick.opengl.TextureLoader;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* A simple utility test to use the internal slick API without
|
||||
* the slick framework.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TestUtils {
|
||||
/** The texture that's been loaded */
|
||||
private Texture texture;
|
||||
/** The ogg sound effect */
|
||||
private Audio oggEffect;
|
||||
/** The wav sound effect */
|
||||
private Audio wavEffect;
|
||||
/** The aif source effect */
|
||||
private Audio aifEffect;
|
||||
/** The ogg stream thats been loaded */
|
||||
private Audio oggStream;
|
||||
/** The mod stream thats been loaded */
|
||||
private Audio modStream;
|
||||
/** The font to draw to the screen */
|
||||
private Font font;
|
||||
|
||||
/**
|
||||
* Start the test
|
||||
*/
|
||||
public void start() {
|
||||
initGL(800,600);
|
||||
init();
|
||||
|
||||
while (true) {
|
||||
update();
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
render();
|
||||
|
||||
Display.update();
|
||||
Display.sync(100);
|
||||
|
||||
if (Display.isCloseRequested()) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the GL display
|
||||
*
|
||||
* @param width The width of the display
|
||||
* @param height The height of the display
|
||||
*/
|
||||
private void initGL(int width, int height) {
|
||||
try {
|
||||
Display.setDisplayMode(new DisplayMode(width,height));
|
||||
Display.create();
|
||||
Display.setVSyncEnabled(true);
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
GL11.glClearDepth(1);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glViewport(0,0,width,height);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, width, height, 0, 1, -1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise resources
|
||||
*/
|
||||
public void init() {
|
||||
// turn off all but errors
|
||||
Log.setVerbose(false);
|
||||
|
||||
java.awt.Font awtFont = new java.awt.Font("Times New Roman", java.awt.Font.BOLD, 16);
|
||||
font = new TrueTypeFont(awtFont, false);
|
||||
|
||||
// texture load, the second argument is a name assigned to the texture to
|
||||
// allow for caching in the texture loader. The 3rd argument indicates whether
|
||||
// the image should be flipped on loading
|
||||
try {
|
||||
texture = TextureLoader.getTexture("PNG", new FileInputStream("testdata/rocks.png"));
|
||||
|
||||
System.out.println("Texture loaded: "+texture);
|
||||
System.out.println(">> Image width: "+texture.getImageWidth());
|
||||
System.out.println(">> Image height: "+texture.getImageWidth());
|
||||
System.out.println(">> Texture width: "+texture.getTextureWidth());
|
||||
System.out.println(">> Texture height: "+texture.getTextureHeight());
|
||||
System.out.println(">> Texture ID: "+texture.getTextureID());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
// you can play oggs by loading the complete thing into
|
||||
// a sound
|
||||
oggEffect = AudioLoader.getAudio("OGG", new FileInputStream("testdata/restart.ogg"));
|
||||
|
||||
// or setting up a stream to read from. Note that the argument becomes
|
||||
// a URL here so it can be reopened when the stream is complete. Probably
|
||||
// should have reset the stream by thats not how the original stuff worked
|
||||
oggStream = AudioLoader.getStreamingAudio("OGG", new File("testdata/bongos.ogg").toURL());
|
||||
|
||||
// can load mods (XM, MOD) using ibxm which is then played through OpenAL. MODs
|
||||
// are always streamed based on the way IBXM works
|
||||
modStream = AudioLoader.getStreamingAudio("MOD", new File("testdata/SMB-X.XM").toURL());
|
||||
|
||||
// playing as music uses that reserved source to play the sound. The first
|
||||
// two arguments are pitch and gain, the boolean is whether to loop the content
|
||||
modStream.playAsMusic(1.0f, 1.0f, true);
|
||||
|
||||
// you can play aifs by loading the complete thing into
|
||||
// a sound
|
||||
aifEffect = AudioLoader.getAudio("AIF", new FileInputStream("testdata/burp.aif"));
|
||||
|
||||
// you can play wavs by loading the complete thing into
|
||||
// a sound
|
||||
wavEffect = AudioLoader.getAudio("WAV", new FileInputStream("testdata/cbrown01.wav"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Game loop update
|
||||
*/
|
||||
public void update() {
|
||||
while (Keyboard.next()) {
|
||||
if (Keyboard.getEventKeyState()) {
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_Q) {
|
||||
// play as a one off sound effect
|
||||
oggEffect.playAsSoundEffect(1.0f, 1.0f, false);
|
||||
}
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_W) {
|
||||
// replace the music thats curretly playing with
|
||||
// the ogg
|
||||
oggStream.playAsMusic(1.0f, 1.0f, true);
|
||||
}
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_E) {
|
||||
// replace the music thats curretly playing with
|
||||
// the mod
|
||||
modStream.playAsMusic(1.0f, 1.0f, true);
|
||||
}
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_R) {
|
||||
// play as a one off sound effect
|
||||
aifEffect.playAsSoundEffect(1.0f, 1.0f, false);
|
||||
}
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_T) {
|
||||
// play as a one off sound effect
|
||||
wavEffect.playAsSoundEffect(1.0f, 1.0f, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// polling is required to allow streaming to get a chance to
|
||||
// queue buffers.
|
||||
SoundStore.get().poll(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Game loop render
|
||||
*/
|
||||
public void render() {
|
||||
Color.white.bind();
|
||||
texture.bind(); // or GL11.glBind(texture.getTextureID());
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glTexCoord2f(0,0);
|
||||
GL11.glVertex2f(100,100);
|
||||
GL11.glTexCoord2f(1,0);
|
||||
GL11.glVertex2f(100+texture.getTextureWidth(),100);
|
||||
GL11.glTexCoord2f(1,1);
|
||||
GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
|
||||
GL11.glTexCoord2f(0,1);
|
||||
GL11.glVertex2f(100,100+texture.getTextureHeight());
|
||||
GL11.glEnd();
|
||||
|
||||
font.drawString(150, 300, "HELLO LWJGL WORLD", Color.yellow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to the tests
|
||||
*
|
||||
* @param argv The arguments to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
TestUtils utils = new TestUtils();
|
||||
utils.start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.geom.Polygon;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import org.newdawn.slick.geom.ShapeRenderer;
|
||||
import org.newdawn.slick.geom.TexCoordGenerator;
|
||||
import org.newdawn.slick.geom.Vector2f;
|
||||
|
||||
/**
|
||||
* Test to emulate texture paint
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TexturePaintTest extends BasicGame {
|
||||
/** The poly being drawn */
|
||||
private Polygon poly = new Polygon();
|
||||
/** The image being textured */
|
||||
private Image image;
|
||||
|
||||
/** The texture paint rectangle */
|
||||
private Rectangle texRect = new Rectangle(50,50,100,100);
|
||||
/** The texture paint */
|
||||
private TexCoordGenerator texPaint;
|
||||
|
||||
/**
|
||||
* Create the test
|
||||
*/
|
||||
public TexturePaintTest() {
|
||||
super("Texture Paint Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
poly.addPoint(120, 120);
|
||||
poly.addPoint(420, 100);
|
||||
poly.addPoint(620, 420);
|
||||
poly.addPoint(300, 320);
|
||||
|
||||
image = new Image("testdata/rocks.png");
|
||||
|
||||
texPaint = new TexCoordGenerator() {
|
||||
public Vector2f getCoordFor(float x, float y) {
|
||||
float tx = (texRect.getX() - x) / texRect.getWidth();
|
||||
float ty = (texRect.getY() - y) / texRect.getHeight();
|
||||
|
||||
return new Vector2f(tx,ty);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) throws SlickException {
|
||||
g.setColor(Color.white);
|
||||
g.texture(poly, image);
|
||||
|
||||
ShapeRenderer.texture(poly, image, texPaint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new TexturePaintTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
119
lib/slick-source/org/newdawn/slick/tests/TileMapTest.java
Normal file
119
lib/slick-source/org/newdawn/slick/tests/TileMapTest.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.tiled.TiledMap;
|
||||
|
||||
/**
|
||||
* A test of the tile map system based around the TilED (http://www.mapeditor.org) tool
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TileMapTest extends BasicGame {
|
||||
/** The tile map we're going to load and render */
|
||||
private TiledMap map;
|
||||
|
||||
/** the name of the map, read from map properties, specified by TilED */
|
||||
private String mapName;
|
||||
|
||||
/** how hard are the monsters, read from layer properties, specified by TilED */
|
||||
private String monsterDifficulty;
|
||||
|
||||
/** we try to read a property from the map which doesn't exist so we expect the default value */
|
||||
private String nonExistingMapProperty;
|
||||
|
||||
/** we try to read a property from the layer which doesn't exist so we expect the default value */
|
||||
private String nonExistingLayerProperty;
|
||||
|
||||
/** how long did we wait already until next update */
|
||||
private int updateCounter = 0;
|
||||
|
||||
/** changing some tile of the map every UPDATE_TIME milliseconds */
|
||||
private static int UPDATE_TIME = 1000;
|
||||
|
||||
/** we want to store the originalTileID before we set a new one */
|
||||
private int originalTileID = 0;
|
||||
|
||||
/**
|
||||
* Create our tile map test
|
||||
*/
|
||||
public TileMapTest() {
|
||||
super("Tile Map Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
map = new TiledMap("testdata/testmap.tmx","testdata");
|
||||
// read some properties from map and layer
|
||||
mapName = map.getMapProperty("name", "Unknown map name");
|
||||
monsterDifficulty = map.getLayerProperty(0, "monsters", "easy peasy");
|
||||
nonExistingMapProperty = map.getMapProperty("zaphod", "Undefined map property");
|
||||
nonExistingLayerProperty = map.getLayerProperty(1, "beeblebrox", "Undefined layer property");
|
||||
|
||||
// store the original tileid of layer 0 at 10, 10
|
||||
originalTileID = map.getTileId(10, 10, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
map.render(10, 10, 4,4,15,15);
|
||||
|
||||
g.scale(0.35f,0.35f);
|
||||
map.render(1400, 0);
|
||||
g.resetTransform();
|
||||
|
||||
g.drawString("map name: " + mapName, 10, 500);
|
||||
g.drawString("monster difficulty: " + monsterDifficulty, 10, 550);
|
||||
|
||||
g.drawString("non existing map property: " + nonExistingMapProperty, 10, 525);
|
||||
g.drawString("non existing layer property: " + nonExistingLayerProperty, 10, 575);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
updateCounter += delta;
|
||||
if (updateCounter > UPDATE_TIME) {
|
||||
// swap the tile every second
|
||||
updateCounter -= UPDATE_TIME;
|
||||
int currentTileID = map.getTileId(10, 10, 0);
|
||||
if (currentTileID != originalTileID)
|
||||
map.setTileId(10, 10, 0, originalTileID);
|
||||
else
|
||||
map.setTileId(10, 10, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new TileMapTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
111
lib/slick-source/org/newdawn/slick/tests/TransformTest.java
Normal file
111
lib/slick-source/org/newdawn/slick/tests/TransformTest.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for transforming the graphics context
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TransformTest extends BasicGame {
|
||||
/** The current scale applied to the graphics context */
|
||||
private float scale = 1;
|
||||
/** True if we should be scaling up */
|
||||
private boolean scaleUp;
|
||||
/** True if we should be scaling down */
|
||||
private boolean scaleDown;
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public TransformTest() {
|
||||
super("Transform Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.setTargetFrameRate(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer contiainer, Graphics g) {
|
||||
g.translate(320,240);
|
||||
g.scale(scale, scale);
|
||||
|
||||
g.setColor(Color.red);
|
||||
for (int x=0;x<10;x++) {
|
||||
for (int y=0;y<10;y++) {
|
||||
g.fillRect(-500+(x*100), -500+(y*100), 80, 80);
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(new Color(1,1,1,0.5f));
|
||||
g.fillRect(-320,-240,640,480);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(-320,-240,640,480);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
if (scaleUp) {
|
||||
scale += delta * 0.001f;
|
||||
}
|
||||
if (scaleDown) {
|
||||
scale -= delta * 0.001f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_Q) {
|
||||
scaleUp = true;
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
scaleDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
if (key == Input.KEY_Q) {
|
||||
scaleUp = false;
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
scaleDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new TransformTest());
|
||||
container.setDisplayMode(640,480,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
170
lib/slick-source/org/newdawn/slick/tests/TransformTest2.java
Normal file
170
lib/slick-source/org/newdawn/slick/tests/TransformTest2.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for transforming the graphics context
|
||||
*
|
||||
* @author Jesse Aldridge
|
||||
*/
|
||||
public class TransformTest2 extends BasicGame {
|
||||
/** The current scale applied to the graphics context */
|
||||
private float scale = 1;
|
||||
/** True if we should be scaling up */
|
||||
private boolean scaleUp;
|
||||
/** True if we should be scaling down */
|
||||
private boolean scaleDown;
|
||||
|
||||
/** The camera's position */
|
||||
private float camX = 320;
|
||||
/** The camera's position */
|
||||
private float camY = 240;
|
||||
/** True if the camera should be moving in the given direction */
|
||||
private boolean moveLeft;
|
||||
/** True if the camera should be moving in the given direction */
|
||||
private boolean moveUp;
|
||||
/** True if the camera should be moving in the given direction */
|
||||
private boolean moveRight;
|
||||
/** True if the camera should be moving in the given direction */
|
||||
private boolean moveDown;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new test of graphics context rendering
|
||||
*/
|
||||
public TransformTest2() {
|
||||
super("Transform Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.setTargetFrameRate(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer contiainer, Graphics g) {
|
||||
g.translate(320,240);
|
||||
|
||||
g.translate( -camX * scale, -camY * scale);
|
||||
|
||||
|
||||
g.scale(scale, scale);
|
||||
|
||||
g.setColor(Color.red);
|
||||
for (int x=0;x<10;x++) {
|
||||
for (int y=0;y<10;y++) {
|
||||
g.fillRect(-500+(x*100), -500+(y*100), 80, 80);
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(new Color(1,1,1,0.5f));
|
||||
g.fillRect(-320,-240,640,480);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(-320,-240,640,480);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
if (scaleUp) {
|
||||
scale += delta * 0.001f;
|
||||
}
|
||||
if (scaleDown) {
|
||||
scale -= delta * 0.001f;
|
||||
}
|
||||
|
||||
float moveSpeed = delta * 0.4f * (1/scale);
|
||||
|
||||
if( moveLeft ) {
|
||||
camX -= moveSpeed;
|
||||
}
|
||||
if( moveUp ) {
|
||||
camY -= moveSpeed;
|
||||
}
|
||||
if( moveRight) {
|
||||
camX += moveSpeed;
|
||||
}
|
||||
if( moveDown ) {
|
||||
camY += moveSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_Q) {
|
||||
scaleUp = true;
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
scaleDown = true;
|
||||
}
|
||||
|
||||
if( key == Input.KEY_LEFT) {
|
||||
moveLeft = true;
|
||||
}
|
||||
if( key == Input.KEY_UP ) {
|
||||
moveUp = true;
|
||||
}
|
||||
if( key == Input.KEY_RIGHT ) {
|
||||
moveRight = true;
|
||||
}
|
||||
if( key == Input.KEY_DOWN ) {
|
||||
moveDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
if (key == Input.KEY_Q) {
|
||||
scaleUp = false;
|
||||
}
|
||||
if (key == Input.KEY_A) {
|
||||
scaleDown = false;
|
||||
}
|
||||
|
||||
if( key == Input.KEY_LEFT) {
|
||||
moveLeft = false;
|
||||
}
|
||||
if( key == Input.KEY_UP ) {
|
||||
moveUp = false;
|
||||
}
|
||||
if( key == Input.KEY_RIGHT ) {
|
||||
moveRight = false;
|
||||
}
|
||||
if( key == Input.KEY_DOWN ) {
|
||||
moveDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new TransformTest2());
|
||||
container.setDisplayMode(640,480,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
161
lib/slick-source/org/newdawn/slick/tests/TransitionTest.java
Normal file
161
lib/slick-source/org/newdawn/slick/tests/TransitionTest.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.Color;
|
||||
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.state.BasicGameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.state.transition.BlobbyTransition;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
import org.newdawn.slick.state.transition.FadeOutTransition;
|
||||
import org.newdawn.slick.state.transition.HorizontalSplitTransition;
|
||||
import org.newdawn.slick.state.transition.RotateTransition;
|
||||
import org.newdawn.slick.state.transition.SelectTransition;
|
||||
import org.newdawn.slick.state.transition.Transition;
|
||||
import org.newdawn.slick.state.transition.VerticalSplitTransition;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
||||
/**
|
||||
* A test to view the different transitions that are currently implemented
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TransitionTest extends StateBasedGame {
|
||||
/** The transitions under test */
|
||||
private Class[][] transitions = new Class[][] {
|
||||
{null, VerticalSplitTransition.class},
|
||||
{FadeOutTransition.class, FadeInTransition.class},
|
||||
{null, RotateTransition.class},
|
||||
{null, HorizontalSplitTransition.class},
|
||||
{null, BlobbyTransition.class},
|
||||
{null, SelectTransition.class},
|
||||
};
|
||||
/** The index of the next transition to use */
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* Test the transitions implemented
|
||||
*/
|
||||
public TransitionTest() {
|
||||
super("Transition Test - Hit Space To Transition");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.StateBasedGame#initStatesList(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void initStatesList(GameContainer container) throws SlickException {
|
||||
addState(new ImageState(0, "testdata/wallpaper/paper1.png", 1));
|
||||
addState(new ImageState(1, "testdata/wallpaper/paper2.png", 2));
|
||||
addState(new ImageState(2, "testdata/bigimage.tga", 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next transition pair that we'lluse
|
||||
*
|
||||
* @return The pair of transitions used to enter and leave the next state
|
||||
*/
|
||||
public Transition[] getNextTransitionPair() {
|
||||
Transition[] pair = new Transition[2];
|
||||
|
||||
try {
|
||||
if (transitions[index][0] != null) {
|
||||
pair[0] = (Transition) transitions[index][0].newInstance();
|
||||
}
|
||||
if (transitions[index][1] != null) {
|
||||
pair[1] = (Transition) transitions[index][1].newInstance();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (index >= transitions.length) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
return pair;
|
||||
}
|
||||
|
||||
/**
|
||||
* A test state that just displayed one image full scren
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class ImageState extends BasicGameState {
|
||||
/** The id of this state */
|
||||
private int id;
|
||||
/** The next state we'll move to */
|
||||
private int next;
|
||||
/** The reference to the image to be displayed */
|
||||
private String ref;
|
||||
/** The loaded image */
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Create a new image state
|
||||
*
|
||||
* @param id The id of the this state
|
||||
* @param ref The reference to the image to display
|
||||
* @param next The next state we'll mvoe to
|
||||
*/
|
||||
public ImageState(int id, String ref, int next) {
|
||||
this.ref = ref;
|
||||
this.id = id;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#getID()
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#init(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
image = new Image(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
|
||||
image.draw(0,0,800,600);
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(-50,200,50,50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#update(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, int)
|
||||
*/
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
|
||||
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
|
||||
Transition[] pair = getNextTransitionPair();
|
||||
game.enterState(next, pair[0], pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed to the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(
|
||||
new TransitionTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A test for transparent colour specification
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TransparentColorTest extends BasicGame {
|
||||
/** The image we're currently displaying */
|
||||
private Image image;
|
||||
/** The image we're currently displaying */
|
||||
private Image timage;
|
||||
|
||||
/**
|
||||
* Create a new image rendering test
|
||||
*/
|
||||
public TransparentColorTest() {
|
||||
super("Transparent Color Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
image = new Image("testdata/transtest.png");
|
||||
timage = new Image("testdata/transtest.png",new Color(94,66,41,255));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setBackground(Color.red);
|
||||
image.draw(10,10);
|
||||
timage.draw(10,310);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv The arguments to pass into the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(new TransparentColorTest());
|
||||
container.setDisplayMode(800,600,false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.TrueTypeFont;
|
||||
|
||||
/**
|
||||
* A test of the font rendering capabilities
|
||||
*
|
||||
* @author James Chambers (Jimmy)
|
||||
* @author Kevin Glass (kevglass)
|
||||
*/
|
||||
public class TrueTypeFontPerformanceTest extends BasicGame {
|
||||
/** The java.awt font we're going to test */
|
||||
private java.awt.Font awtFont;
|
||||
/** The True Type font we're going to use to render */
|
||||
private TrueTypeFont font;
|
||||
|
||||
/** The test text */
|
||||
private String text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin bibendum. Aliquam ac sapien a elit congue iaculis. Quisque et justo quis mi mattis euismod. Donec elementum, mi quis aliquet varius, nisi leo volutpat magna, quis ultricies eros augue at risus. Integer non magna at lorem sodales molestie. Integer diam nulla, ornare sit amet, mattis quis, euismod et, mauris. Proin eget tellus non nisl mattis laoreet. Nunc at nunc id elit pretium tempor. Duis vulputate, nibh eget rhoncus eleifend, tellus lectus sollicitudin mi, rhoncus tincidunt nisi massa vitae ipsum. Praesent tellus diam, luctus ut, eleifend nec, auctor et, orci. Praesent eu elit. Pellentesque ante orci, volutpat placerat, ornare eget, cursus sit amet, eros. Duis pede sapien, euismod a, volutpat pellentesque, convallis eu, mauris. Nunc eros. Ut eu risus et felis laoreet viverra. Curabitur a metus.";
|
||||
/** The text broken into lines */
|
||||
private ArrayList lines = new ArrayList();
|
||||
/** True if the text is visible */
|
||||
private boolean visible = true;
|
||||
|
||||
/**
|
||||
* Create a new test for font rendering
|
||||
*/
|
||||
public TrueTypeFontPerformanceTest() {
|
||||
super("Font Performance Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
awtFont = new java.awt.Font("Verdana", Font.PLAIN, 16);
|
||||
font = new TrueTypeFont(awtFont, false);
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
int lineLen = 90;
|
||||
for (int i = 0; i < text.length(); i += lineLen) {
|
||||
if (i + lineLen > text.length()) {
|
||||
lineLen = text.length() - i;
|
||||
}
|
||||
|
||||
lines.add(text.substring(i, i + lineLen));
|
||||
}
|
||||
lines.add("");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,
|
||||
* org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setFont(font);
|
||||
|
||||
if (visible) {
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
font.drawString(10, 50 + (i * 20), (String) lines.get(i),
|
||||
i > 10 ? Color.red : Color.green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer,
|
||||
* int)
|
||||
*/
|
||||
public void update(GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key == Input.KEY_ESCAPE) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (key == Input.KEY_SPACE) {
|
||||
visible = !visible;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our test
|
||||
*
|
||||
* @param argv
|
||||
* The arguments passed in the test
|
||||
*/
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
AppGameContainer container = new AppGameContainer(
|
||||
new TrueTypeFontPerformanceTest());
|
||||
container.setDisplayMode(800, 600, false);
|
||||
container.start();
|
||||
} catch (SlickException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
|
||||
package org.newdawn.slick.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.newdawn.slick.AppGameContainer;
|
||||
import org.newdawn.slick.BasicGame;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.UnicodeFont;
|
||||
import org.newdawn.slick.font.effects.ColorEffect;
|
||||
import org.newdawn.slick.font.effects.ShadowEffect;
|
||||
|
||||
/**
|
||||
* A simple test of the unicode font functionality provided
|
||||
*
|
||||
* @author Nathan Sweet <misc@n4te.com>
|
||||
*/
|
||||
public class UnicodeFontTest extends BasicGame {
|
||||
/** The font we're going to display in the test */
|
||||
private UnicodeFont unicodeFont;
|
||||
|
||||
/**
|
||||
* Create the simple font test
|
||||
*/
|
||||
public UnicodeFontTest() {
|
||||
super("Font Test");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public void init(GameContainer container) throws SlickException {
|
||||
container.setShowFPS(false);
|
||||
|
||||
// unicodeFont = new UnicodeFont(Font.decode("Arial Unicode MS"), 25, false, false);
|
||||
unicodeFont = new UnicodeFont("c:/windows/fonts/arial.ttf", 48, false, false);
|
||||
// unicodeFont.setPaddingBottom(10);
|
||||
// unicodeFont.setPaddingRight(10);
|
||||
// unicodeFont.setPaddingAdvanceX(-10);
|
||||
// unicodeFont.getEffects().add(new ShadowEffect(java.awt.Color.black, 5, 5, 0.5f));
|
||||
unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white));
|
||||
|
||||
// unicodeFont = new UnicodeFont("Arial", 25, false, false);
|
||||
// unicodeFont = new UnicodeFont("Everson Mono", 44, false, false);
|
||||
|
||||
// font.addGlyphs(0, 255);
|
||||
// font.addGlyphs("~!@#$%^&*()");
|
||||
|
||||
container.getGraphics().setBackground(Color.darkGray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
|
||||
String text = "This is UnicodeFont!\nIt rockz. Kerning: T,";
|
||||
unicodeFont.drawString(10, 33, text);
|
||||
// unicodeFont.drawString(10, 33, text, Color.red, 8, 19);
|
||||
g.setColor(Color.red);
|
||||
g.drawRect(10, 33, unicodeFont.getWidth(text), unicodeFont.getLineHeight());
|
||||
g.setColor(Color.blue);
|
||||
int yOffset = unicodeFont.getYOffset(text);
|
||||
g.drawRect(10, 33 + yOffset, unicodeFont.getWidth(text), unicodeFont.getHeight(text) - yOffset);
|
||||
|
||||
// font.drawString(10, 73, "\u6880\u6881\u6882 (...) \u6883\u6884\u6885\u6886\u6887 hi?");
|
||||
|
||||
unicodeFont.addGlyphs("~!@!#!#$%___--");
|
||||
// Cypriot Syllabary glyphs (Everson Mono font): \uD802\uDC02\uD802\uDC03\uD802\uDC12 == 0x10802, 0x10803, s0x10812
|
||||
// g.drawLine(0, container.getHeight() - 512, container.getWidth(), container.getHeight() - 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update (GameContainer container, int delta) throws SlickException {
|
||||
unicodeFont.loadGlyphs(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point to our simple test
|
||||
*
|
||||
* @param args The arguments supplied to the test
|
||||
* @throws SlickException Indicates a failure loading or processing resources
|
||||
* @throws IOException Indicates a failure loading the font
|
||||
*/
|
||||
public static void main(String[] args) throws SlickException, IOException {
|
||||
Input.disableControllers();
|
||||
AppGameContainer container = new AppGameContainer(new UnicodeFontTest());
|
||||
container.setDisplayMode(512, 600, false);
|
||||
container.setTargetFrameRate(20);
|
||||
container.start();
|
||||
}
|
||||
}
|
||||
3
lib/slick-source/org/newdawn/slick/tests/package.html
Normal file
3
lib/slick-source/org/newdawn/slick/tests/package.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<BODY>
|
||||
Tests for the facilities provided by the library.
|
||||
</BODY>
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.newdawn.slick.tests.states;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.BasicGameState;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.state.transition.CrossStateTransition;
|
||||
import org.newdawn.slick.state.transition.EmptyTransition;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
import org.newdawn.slick.state.transition.FadeOutTransition;
|
||||
|
||||
/**
|
||||
* A simple test state to display a message describing the test
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TestState1 extends BasicGameState {
|
||||
/** The ID given to this state */
|
||||
public static final int ID = 1;
|
||||
/** The font to write the message with */
|
||||
private Font font;
|
||||
/** The game holding this state */
|
||||
private StateBasedGame game;
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#getID()
|
||||
*/
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#init(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
this.game = game;
|
||||
font = new AngelCodeFont("testdata/demo2.fnt","testdata/demo2_00.tga");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) {
|
||||
g.setFont(font);
|
||||
g.setColor(Color.white);
|
||||
g.drawString("State Based Game Test", 100, 100);
|
||||
g.drawString("Numbers 1-3 will switch between states.", 150, 300);
|
||||
g.setColor(Color.red);
|
||||
g.drawString("This is State 1", 200, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#update(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, int)
|
||||
*/
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
|
||||
if (key == Input.KEY_2) {
|
||||
GameState target = game.getState(TestState2.ID);
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
CrossStateTransition t = new CrossStateTransition(target) {
|
||||
public boolean isComplete() {
|
||||
return (System.currentTimeMillis() - start) > 2000;
|
||||
}
|
||||
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
}
|
||||
};
|
||||
|
||||
game.enterState(TestState2.ID, t, new EmptyTransition());
|
||||
}
|
||||
if (key == Input.KEY_3) {
|
||||
game.enterState(TestState3.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.newdawn.slick.tests.states;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
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.state.BasicGameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
import org.newdawn.slick.state.transition.FadeOutTransition;
|
||||
|
||||
/**
|
||||
* A simple test state to display an image and rotate it
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TestState2 extends BasicGameState {
|
||||
/** The ID given to this state */
|
||||
public static final int ID = 2;
|
||||
/** The font to write the message with */
|
||||
private Font font;
|
||||
/** The image to be display */
|
||||
private Image image;
|
||||
/** The angle we'll rotate by */
|
||||
private float ang;
|
||||
/** The game holding this state */
|
||||
private StateBasedGame game;
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#getID()
|
||||
*/
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#init(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
this.game = game;
|
||||
font = new AngelCodeFont("testdata/demo2.fnt","testdata/demo2_00.tga");
|
||||
image = new Image("testdata/logo.tga");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) {
|
||||
g.setFont(font);
|
||||
g.setColor(Color.green);
|
||||
g.drawString("This is State 2", 200, 50);
|
||||
|
||||
g.rotate(400,300,ang);
|
||||
g.drawImage(image,400-(image.getWidth()/2),300-(image.getHeight()/2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#update(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, int)
|
||||
*/
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) {
|
||||
ang += delta * 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
if (key == Input.KEY_1) {
|
||||
game.enterState(TestState1.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
if (key == Input.KEY_3) {
|
||||
game.enterState(TestState3.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package org.newdawn.slick.tests.states;
|
||||
|
||||
import org.newdawn.slick.AngelCodeFont;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.BasicGameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
import org.newdawn.slick.state.transition.FadeOutTransition;
|
||||
|
||||
/**
|
||||
* A simple test state to display an image and rotate it
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class TestState3 extends BasicGameState {
|
||||
/** The ID given to this state */
|
||||
public static final int ID = 3;
|
||||
/** The font to write the message with */
|
||||
private Font font;
|
||||
/** The menu options */
|
||||
private String[] options = new String[] {"Start Game","Credits","Highscores","Instructions","Exit"};
|
||||
/** The index of the selected option */
|
||||
private int selected;
|
||||
/** The game holding this state */
|
||||
private StateBasedGame game;
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#getID()
|
||||
*/
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#init(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
font = new AngelCodeFont("testdata/demo2.fnt","testdata/demo2_00.tga");
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) {
|
||||
g.setFont(font);
|
||||
g.setColor(Color.blue);
|
||||
g.drawString("This is State 3", 200, 50);
|
||||
g.setColor(Color.white);
|
||||
|
||||
for (int i=0;i<options.length;i++) {
|
||||
g.drawString(options[i], 400 - (font.getWidth(options[i])/2), 200+(i*50));
|
||||
if (selected == i) {
|
||||
g.drawRect(200,190+(i*50),400,50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#update(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, int)
|
||||
*/
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
if (key == Input.KEY_DOWN) {
|
||||
selected++;
|
||||
if (selected >= options.length) {
|
||||
selected = 0;
|
||||
}
|
||||
}
|
||||
if (key == Input.KEY_UP) {
|
||||
selected--;
|
||||
if (selected < 0) {
|
||||
selected = options.length - 1;
|
||||
}
|
||||
}
|
||||
if (key == Input.KEY_1) {
|
||||
game.enterState(TestState1.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
if (key == Input.KEY_2) {
|
||||
game.enterState(TestState2.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<BODY>
|
||||
States for the StateBasedGameTest
|
||||
</BODY>
|
||||
46
lib/slick-source/org/newdawn/slick/tests/xml/Entity.java
Normal file
46
lib/slick-source/org/newdawn/slick/tests/xml/Entity.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
/**
|
||||
* A test example of some object data that can be configured via XML
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class Entity {
|
||||
/** X position for the entity */
|
||||
private float x;
|
||||
/** Y position for the entity */
|
||||
private float y;
|
||||
/** items held */
|
||||
private Inventory invent;
|
||||
/** Entity statistics */
|
||||
private Stats stats;
|
||||
|
||||
/**
|
||||
* Called by XML parser to add a configured inventory to the entity
|
||||
*
|
||||
* @param inventory The inventory to be added
|
||||
*/
|
||||
private void add(Inventory inventory) {
|
||||
this.invent = inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by XML parser to add a configured statistics object to the entity
|
||||
*
|
||||
* @param stats The statistics to be added
|
||||
*/
|
||||
private void add(Stats stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"Entity "+x+","+y);
|
||||
invent.dump(prefix+"\t");
|
||||
stats.dump(prefix+"\t");
|
||||
}
|
||||
}
|
||||
34
lib/slick-source/org/newdawn/slick/tests/xml/GameData.java
Normal file
34
lib/slick-source/org/newdawn/slick/tests/xml/GameData.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The top level node of our test structure for XML -> object parsing
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class GameData {
|
||||
/** The list of entities added */
|
||||
private ArrayList entities = new ArrayList();
|
||||
|
||||
/**
|
||||
* Called by XML parser to add a configured entity to the GameData
|
||||
*
|
||||
* @param entity The entity to be added
|
||||
*/
|
||||
private void add(Entity entity) {
|
||||
entities.add(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"GameData");
|
||||
for (int i=0;i<entities.size();i++) {
|
||||
((Entity) entities.get(i)).dump(prefix+"\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
34
lib/slick-source/org/newdawn/slick/tests/xml/Inventory.java
Normal file
34
lib/slick-source/org/newdawn/slick/tests/xml/Inventory.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A test example of some object data that can be configured via XML
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class Inventory {
|
||||
/** The items held in the inventory */
|
||||
private ArrayList items = new ArrayList();
|
||||
|
||||
/**
|
||||
* Called by XML parser to add a configured item to the entity
|
||||
*
|
||||
* @param item The item to be added
|
||||
*/
|
||||
private void add(Item item) {
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"Inventory");
|
||||
for (int i=0;i<items.size();i++) {
|
||||
((Item) items.get(i)).dump(prefix+"\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
23
lib/slick-source/org/newdawn/slick/tests/xml/Item.java
Normal file
23
lib/slick-source/org/newdawn/slick/tests/xml/Item.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
|
||||
/**
|
||||
* A test example of some object data that can be configured via XML
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class Item {
|
||||
/** The name injected by the XML parser */
|
||||
protected String name;
|
||||
/** The condition value injected by the XML parser */
|
||||
protected int condition;
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"Item "+name+","+condition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A test example of some object data that can be configured via XML
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ItemContainer extends Item {
|
||||
/** The items held in this container */
|
||||
private ArrayList items = new ArrayList();
|
||||
|
||||
/**
|
||||
* Called by XML parser to add a configured item to the entity
|
||||
*
|
||||
* @param item The item to be added
|
||||
*/
|
||||
private void add(Item item) {
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the XML to set the name attribute. Note that set methods can
|
||||
* be used as well as direct field injection. In this case the setter *has*
|
||||
* to be used to access the protected field from the super class
|
||||
*
|
||||
* @param name The value to set
|
||||
*/
|
||||
private void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the XML to set the condition attribute. Note that set methods can
|
||||
* be used as well as direct field injection. In this case the setter *has*
|
||||
* to be used to access the protected field from the super class
|
||||
*
|
||||
* @param condition The value to set
|
||||
*/
|
||||
private void setCondition(int condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"Item Container "+name+","+condition);
|
||||
for (int i=0;i<items.size();i++) {
|
||||
((Item) items.get(i)).dump(prefix+"\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
import org.newdawn.slick.util.xml.ObjectTreeParser;
|
||||
import org.newdawn.slick.util.xml.SlickXMLException;
|
||||
|
||||
/**
|
||||
* A simple test to check that the object parser from XML works. Read the Javadoc of
|
||||
* ObjectParser to work out whats going on here
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class ObjectParserTest {
|
||||
|
||||
/**
|
||||
* Entity point to our test. Simple read some XML which should
|
||||
* generate an object tree.
|
||||
*
|
||||
* @param argv The arguments passed into the test
|
||||
* @throws SlickXMLException Indicates a failure to parse XML or generate objects
|
||||
*/
|
||||
public static void main(String[] argv) throws SlickXMLException {
|
||||
ObjectTreeParser parser = new ObjectTreeParser("org.newdawn.slick.tests.xml");
|
||||
parser.addElementMapping("Bag", ItemContainer.class);
|
||||
|
||||
GameData parsedData = (GameData) parser.parse("testdata/objxmltest.xml");
|
||||
parsedData.dump("");
|
||||
}
|
||||
}
|
||||
26
lib/slick-source/org/newdawn/slick/tests/xml/Stats.java
Normal file
26
lib/slick-source/org/newdawn/slick/tests/xml/Stats.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
/**
|
||||
* A test example of some object data that can be configured via XML
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class Stats {
|
||||
/** hit points */
|
||||
private int hp;
|
||||
/** magic points */
|
||||
private int mp;
|
||||
/** age in years */
|
||||
private float age;
|
||||
/** experience points */
|
||||
private int exp;
|
||||
|
||||
/**
|
||||
* Dump this object to sysout
|
||||
*
|
||||
* @param prefix The prefix to apply to all lines
|
||||
*/
|
||||
public void dump(String prefix) {
|
||||
System.out.println(prefix+"Stats "+hp+","+mp+","+age+","+exp);
|
||||
}
|
||||
}
|
||||
117
lib/slick-source/org/newdawn/slick/tests/xml/XMLTest.java
Normal file
117
lib/slick-source/org/newdawn/slick/tests/xml/XMLTest.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package org.newdawn.slick.tests.xml;
|
||||
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.util.xml.XMLElement;
|
||||
import org.newdawn.slick.util.xml.XMLParser;
|
||||
|
||||
/**
|
||||
* Silly test to check XML parsing functionality, note the JUnit like methods,
|
||||
* want to move it to JUnit soon but not quite there yet.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class XMLTest {
|
||||
/**
|
||||
* Fail the test
|
||||
*
|
||||
* @param message The message to describe the failure
|
||||
*/
|
||||
private static void fail(String message) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the given object is not null, if it is fail the test
|
||||
*
|
||||
* @param object1 The object to test
|
||||
*/
|
||||
private static void assertNotNull(Object object1) {
|
||||
if (object1 == null) {
|
||||
throw new RuntimeException("TEST FAILS: "+object1+" must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the two values given are equal, if not fail the test
|
||||
*
|
||||
* @param a1 The first value to compare
|
||||
* @param a2 The second value to compare
|
||||
*/
|
||||
private static void assertEquals(float a1, float a2) {
|
||||
if (a1 != a2) {
|
||||
throw new RuntimeException("TEST FAILS: "+a1+" should be "+a2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the two values given are equal, if not fail the test
|
||||
*
|
||||
* @param a1 The first value to compare
|
||||
* @param a2 The second value to compare
|
||||
*/
|
||||
private static void assertEquals(int a1, int a2) {
|
||||
if (a1 != a2) {
|
||||
throw new RuntimeException("TEST FAILS: "+a1+" should be "+a2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the two values given are equal, if not fail the test
|
||||
*
|
||||
* @param a1 The first value to compare
|
||||
* @param a2 The second value to compare
|
||||
*/
|
||||
private static void assertEquals(Object a1, Object a2) {
|
||||
if (!a1.equals(a2)) {
|
||||
throw new RuntimeException("TEST FAILS: "+a1+" should be "+a2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple test for the XML parsing API
|
||||
*
|
||||
* @param argv The arguments given to the test
|
||||
* @throws SlickException Indicates a failure
|
||||
*/
|
||||
public static void main(String[] argv) throws SlickException {
|
||||
XMLParser parser = new XMLParser();
|
||||
|
||||
XMLElement root = parser.parse("testdata/test.xml");
|
||||
|
||||
assertEquals(root.getName(), "testRoot");
|
||||
System.out.println(root);
|
||||
assertNotNull(root.getChildrenByName("simple").get(0).getContent());
|
||||
System.out.println(root.getChildrenByName("simple").get(0).getContent());
|
||||
|
||||
XMLElement parent = root.getChildrenByName("parent").get(0);
|
||||
assertEquals(parent.getChildrenByName("grandchild").size(),0);
|
||||
assertEquals(parent.getChildrenByName("child").size(),2);
|
||||
|
||||
assertEquals(parent.getChildrenByName("child").get(0).getChildren().size(),2);
|
||||
XMLElement child = parent.getChildrenByName("child").get(0).getChildren().get(0);
|
||||
|
||||
String name = child.getAttribute("name");
|
||||
String test = child.getAttribute("nothere","defaultValue");
|
||||
int age = child.getIntAttribute("age");
|
||||
|
||||
assertEquals(name, "bob");
|
||||
assertEquals(test, "defaultValue");
|
||||
assertEquals(age, 1);
|
||||
|
||||
XMLElement other = root.getChildrenByName("other").get(0);
|
||||
float x = (float) other.getDoubleAttribute("x");
|
||||
float y = (float) other.getDoubleAttribute("y", 1.0f);
|
||||
float z = (float) other.getDoubleAttribute("z", 83.0f);
|
||||
|
||||
assertEquals(x, 5.3f);
|
||||
assertEquals(y, 5.4f);
|
||||
assertEquals(z, 83.0f);
|
||||
|
||||
try {
|
||||
z = (float) other.getDoubleAttribute("z");
|
||||
fail("Attribute z as a double should fail");
|
||||
} catch (SlickException e) {
|
||||
// expect exception
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<BODY>
|
||||
Tests for the XML Parser and Object Tree Parser
|
||||
</BODY>
|
||||
Reference in New Issue
Block a user