/* ClientThread.java */ package lib; import main.Main; public class ClientThread extends Thread{ private Main client; public ClientThread(Main client) { this.client = client; } public void run() { System.out.println("hallo"); } } /********************** Main.java *********************/ package main; /* SNIP */ import lib.ClientThread; /* SNAP */ public class Main extends Game { public ClientThread cthread; @Override public void initResources() { cthread = new ClientThread(this); cthread.start(); BufferedImage backgroundTiles[] = getImages("bgtiles.jpg",8,8); int[][] mapTiles = { {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 8, 16, 24, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 9, 39, 25, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 9, 39, 25, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 10, 18, 26, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {32, 0, 0, 0,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 0, 0, 0 }, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; background = new TileBackground(backgroundTiles, mapTiles); playfield = new PlayField(background); PLAYER_GROUP = playfield.addGroup(new SpriteGroup("Player Group")); BLOCK_GROUP = playfield.addGroup(new SpriteGroup("BlockTile Group")); hero = new ExtendedSprite(getImages("man.png",3,4), 450, 300, 150); PLAYER_GROUP.add(hero); for(int n = 0; n < 20; n++) { for(int i = 0; i < 15; i++) { if(mapBlocks[n][i] != 0) { BLOCK_GROUP.add(new Sprite(getImage("blockSmall.png"), n*32, i*32)); } } } playfield.addCollisionGroup(PLAYER_GROUP, BLOCK_GROUP, new PlayerBlockCollision()); System.out.println(hero.getID()); } @Override public void render(Graphics2D arg0) { playfield.render(arg0); } @Override public void update(long arg0) { playfield.update(arg0); if (keyDown(KeyEvent.VK_LEFT)) { hero.moveLeft(arg0); }else if(keyDown(KeyEvent.VK_RIGHT)) { hero.moveRight(arg0); }else if(keyDown(KeyEvent.VK_DOWN)) { hero.moveDown(arg0); }else if(keyDown(KeyEvent.VK_UP)) { hero.moveUp(arg0); }else { hero.stopMoving(); } } public static void main(String[] args) { GameLoader game = new GameLoader(); game.setup(new Main(), new Dimension(640,480), false); game.start(); } }