public void render() { BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } int xOffset = player.x - (screen.width / 2); int yOffset = player.y - (screen.height / 2); level.renderTiles(screen, xOffset, yOffset); level.renderEntities(screen); level.cleanUp(); screen.renderHud(); for (int y = 0; y < screen.height; y++) { for (int x = 0; x < screen.width; x++) { int colorCode = screen.pixels[x + y * screen.width]; if (colorCode < 255) pixels[x + y * WIDTH] = colors[colorCode]; } } Graphics g = bs.getDrawGraphics(); g.drawImage(image, 0, 0, getWidth(), getHeight(), null); g.dispose(); bs.show(); }
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 void tick() { tickCount++; level.tick(); }