Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /**
  2. * Created by Andre on 16.01.2017.
  3. */
  4.  
  5. import org.newdawn.slick.*;
  6.  
  7. public class Game extends BasicGame
  8. {
  9. private Animation a;
  10.  
  11. public Game() throws SlickException {
  12. super("HTL-RUN");
  13. }
  14.  
  15. public static void main(String[] args) throws SlickException {
  16. AppGameContainer container = new AppGameContainer(new
  17. Game());
  18. //Fenster mit 1024 x 786 im Fenstermodus (false)
  19. container.setDisplayMode(1024, 768, false);
  20. container.start();
  21. }
  22.  
  23. public Animation getAnimation ( Image i , int spritesX, int spritesY , int spriteWidth , int spriteHeight, int frames, int duration )
  24. {
  25. Animation a = new Animation(false);
  26.  
  27. int c = 0;
  28. for( int y = 0 ; y < spritesY; y++)
  29. {
  30. for( int x = 0 ; x < spritesX; x++)
  31. {
  32. if( c < frames ) a.addFrame( i.getSubImage(x*spriteWidth, y*spriteHeight, spriteWidth, spriteHeight), duration);
  33. c++;
  34. }
  35. }
  36.  
  37. return a;
  38. }
  39.  
  40. public void init(GameContainer gc) throws SlickException {
  41. Image i = new Image("res/dude_animation_sheet.png");
  42. a = getAnimation ( i, 5 , 4 , 130, 150, 27, 100 );
  43. }
  44.  
  45. public void render(GameContainer gc, Graphics g) throws SlickException {
  46. a.draw(410, 330);
  47. }
  48.  
  49. public void update(GameContainer gc, int delta) throws SlickException {
  50. a.update(delta);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement