// paints the player, items, and rooms public void paintComponent(Graphics g) { super.paintComponent(g); Environment Layout = new Environment(); Layout.drawRoom(mapX, mapY, g); Player PlayerSprite = new Player(); PlayerSprite.drawPlayer(x, y, g); Layout.items(x, y, g, getItem); }
// takes keyboard input to move player around, and to different rooms public void keyTyped(KeyEvent e) { c = e.getKeyChar(); repaint(); g = this.getGraphics(); Environment Layout = new Environment(); if (Layout.isWall(x, y, c, wallLayout)) { } else { if (c == 'a') { x = x - 3; } else if (c == 'w') { y = y - 3; } else if (c == 's') { y = y + 3; } else if (c == 'd') { x = x + 3; } else if (c == 'e') { getItem = !getItem; } int yDoor = Layout.isDoor(x, y, c, 'y', wallLayout); int xDoor = Layout.isDoor(x, y, c, 'x', wallLayout); if (xDoor != 0 || yDoor != 0) { mapY = mapY + yDoor; mapX = mapX + xDoor; wallLayout = Layout.walls(mapX, mapY); Layout.drawRoom(mapX, mapY, g); if (xDoor == -1) { x = 760; } else if (xDoor == 1) { x = 40; } else if (yDoor == -1) { y = 460; } else if (yDoor == 1) { y = 40; } } } }