SHARE
TWEET

Untitled

a guest Jul 29th, 2013 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // An image controlled by the arrow keys
  2.  
  3. class Util {
  4.         static Map<string, PJImage> images = new Map<string, PJImage>();
  5.         static PJImage getImage(string path) {
  6.                 if (!Util.images.contains(path)) {
  7.                         Util.images[path] = PJImage.loadFromFile(path);
  8.                 }
  9.                 return Util.images[path];
  10.         }
  11. }
  12.  
  13.  
  14. class Program {
  15.         int renderCounter = 0;
  16.         SceneBase activeScene;
  17.         PJGame gameInstance;
  18.        
  19.         void init() {
  20.                 this.gameInstance = new PJGame(this.postInit, this.update, this.render, 640, 480, 60);
  21.                 this.gameInstance.start();
  22.         }
  23.        
  24.         void postInit() {
  25.                 this.activeScene = new SceneBase();
  26.         }
  27.        
  28.         void update(List<PJEvent> events, Map<string, bool> pressedKeys) {
  29.                 this.activeScene.update(events, pressedKeys);
  30.         }
  31.        
  32.         void render(PJImage screen) {
  33.                 this.activeScene.render(screen, this.renderCounter);
  34.                 this.renderCounter = this.renderCounter + 1;
  35.         }
  36. }
  37.  
  38. class SceneBase {
  39.        
  40.         SceneBase next;
  41.         PJImage img;
  42.         int x;
  43.         int y;
  44.        
  45.         SceneBase() {
  46.                 this.next = this;
  47.                 this.img = Util.getImage('images/test.png');
  48.                 this.x = 100;
  49.                 this.y = 100;
  50.         }
  51.        
  52.         void update(List<PJEvent> events, Map<string, bool> pressedKeys) {
  53.                 int v = 3;
  54.                 if (pressedKeys['left']) this.x = this.x - v;
  55.                 if (pressedKeys['right']) this.x = this.x + v;
  56.                 if (pressedKeys['up']) this.y = this.y - v;
  57.                 if (pressedKeys['down']) this.y = this.y + v;
  58.         }
  59.        
  60.         void render(PJImage screen, int renderCounter) {
  61.                 screen.blit(this.img, this.x, this.y);
  62.         }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top