public void init() { int index = 0; for (int r = 0; r < COLOR_SHADES; r++) { for (int g = 0; g < COLOR_SHADES; g++) { for (int b = 0; b < COLOR_SHADES; b++) { int rr = (r * 255 / 5); int gg = (g * 255 / 5); int bb = (b * 255 / 5); colors[index++] = rr << 16 | gg << 8 | bb; } } } screen = new Screen(WIDTH, HEIGHT, new SpriteSheet("/sprite_sheet.png")); input = new InputHandler(this); windowHandler = new WindowHandler(this); mouseHandler = new MouseHandler(this); level = new Level("/levels/Level1.png"); player = new PlayerMP( this, level, UUID.randomUUID(), JOptionPane.showInputDialog(this, "Please enter a username"), 20, 100, input, null, -1); Packet00Login loginPacket = new Packet00Login(player); if (socketServer != null) { // TODO move this to the game loop and replace with mob generator Tonberry tonberry = new Tonberry(this, level, UUID.randomUUID(), 80, 300); socketServer.addMob(tonberry); level.addEntity(tonberry); // TODO remove this later LootTypes lt = LootTypes.get("MANA_POTION"); Loot mp = lt.get(this, level, 100, 200); level.addEntity(mp); socketServer.addConnection((PlayerMP) player, loginPacket); } loginPacket.writeData(socketClient); level.addEntity(player); }
public synchronized void start() { running = true; new Thread(this).start(); if (JOptionPane.showConfirmDialog(this, "Do you want to run the server") == 0) { socketServer = new GameServer(this); socketServer.start(); } socketClient = new GameClient(this, "localhost"); socketClient.start(); }