Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - // An image controlled by the arrow keys
 - class Util {
 - static Map<string, PJImage> images = new Map<string, PJImage>();
 - static PJImage getImage(string path) {
 - if (!Util.images.contains(path)) {
 - Util.images[path] = PJImage.loadFromFile(path);
 - }
 - return Util.images[path];
 - }
 - }
 - class Program {
 - int renderCounter = 0;
 - SceneBase activeScene;
 - PJGame gameInstance;
 - void init() {
 - this.gameInstance = new PJGame(this.postInit, this.update, this.render, 640, 480, 60);
 - this.gameInstance.start();
 - }
 - void postInit() {
 - this.activeScene = new SceneBase();
 - }
 - void update(List<PJEvent> events, Map<string, bool> pressedKeys) {
 - this.activeScene.update(events, pressedKeys);
 - }
 - void render(PJImage screen) {
 - this.activeScene.render(screen, this.renderCounter);
 - this.renderCounter = this.renderCounter + 1;
 - }
 - }
 - class SceneBase {
 - SceneBase next;
 - PJImage img;
 - int x;
 - int y;
 - SceneBase() {
 - this.next = this;
 - this.img = Util.getImage('images/test.png');
 - this.x = 100;
 - this.y = 100;
 - }
 - void update(List<PJEvent> events, Map<string, bool> pressedKeys) {
 - int v = 3;
 - if (pressedKeys['left']) this.x = this.x - v;
 - if (pressedKeys['right']) this.x = this.x + v;
 - if (pressedKeys['up']) this.y = this.y - v;
 - if (pressedKeys['down']) this.y = this.y + v;
 - }
 - void render(PJImage screen, int renderCounter) {
 - screen.blit(this.img, this.x, this.y);
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment