Created
April 25, 2013 14:04
-
-
Save massimomusante/5459957 to your computer and use it in GitHub Desktop.
Bouncing hello-world Slick2d demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.musante.demo; | |
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; | |
/** | |
* Slick Hello-world demo | |
* @author maxx | |
* Apr 6, 2013 | |
* Copyright (c) Massimo Musante 2013 | |
*/ | |
public class DemoHello extends BasicGame | |
{ | |
private int x = 100; | |
private int y = 100; | |
private int dx = 1; | |
private int dy = 1; | |
public DemoHello() | |
{ | |
super("Demo Hello"); | |
} | |
/* | |
* (non-Javadoc) | |
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) | |
*/ | |
@Override | |
public void render(GameContainer gc, Graphics g) throws SlickException | |
{ | |
g.drawString("Hello There!", x, y); | |
} | |
/* | |
* (non-Javadoc) | |
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) | |
*/ | |
@Override | |
public void init(GameContainer gc) throws SlickException | |
{ | |
} | |
/* | |
* (non-Javadoc) | |
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int) | |
*/ | |
@Override | |
public void update(GameContainer gc, int delta) throws SlickException | |
{ | |
if(x>gc.getWidth()) dx = -1; | |
if(x<0) dx = 1; | |
if(y>gc.getHeight()) dy = -1; | |
if(y<0) dy = 1; | |
x = x+dx; | |
y = y+dy; | |
} | |
/** | |
* Start the demo, no parameters | |
* @param args | |
* @throws SlickException | |
*/ | |
public static void main(String[] args) throws SlickException | |
{ | |
AppGameContainer app = new AppGameContainer(new DemoHello()); | |
app.setDisplayMode(300, 200, false); | |
app.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment