Created
April 25, 2013 14:23
-
-
Save massimomusante/5460086 to your computer and use it in GitHub Desktop.
More code fragments for Slick2d blog post
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
... | |
private int x = 100; | |
private int y = 100; | |
private int dx = 1; | |
private int dy = 1; | |
private Image img = null; | |
... |
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
... | |
public void init(GameContainer gc) throws SlickException | |
{ | |
img = new Image("res/ball.png"); | |
} | |
... |
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
... | |
public void render(GameContainer gc, Graphics g) throws SlickException | |
{ | |
img.draw(x, y); | |
} | |
... |
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
... | |
public void update(GameContainer gc, int delta) throws SlickException | |
{ | |
if(x>gc.getWidth()-img.getWidth()) dx = -1; | |
if(x<0) dx = 1; | |
if(y>gc.getHeight()-img.getHeight()) dy = -1; | |
if(y<0) dy = 1; | |
x = x+dx; | |
y = y+dy; | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment