Implemented additional menu items for avatars and available controls, refactored player avatars to accommodate as well as reduce redundant code.
This commit is contained in:
83
src/com/droidquest/avatars/Avatar.java
Normal file
83
src/com/droidquest/avatars/Avatar.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
/**
|
||||
* Interface to support handling a common interface for player types.
|
||||
* Particularly, since SolderingPen needs to be a Device, this can
|
||||
* be used to provide a player avatar contract.
|
||||
*/
|
||||
public interface Avatar {
|
||||
|
||||
/**
|
||||
* Handle change to game cursor.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleGameCursor();
|
||||
|
||||
/**
|
||||
* Handle change to solder pen.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleSolderPen();
|
||||
|
||||
/**
|
||||
* Handle opening / summoning the toolbox
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleToolbox();
|
||||
|
||||
/**
|
||||
* Handle starting / stopping the remote.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleRadio();
|
||||
|
||||
/**
|
||||
* Handle rotating a Device object
|
||||
* @param direction -1 for counter clockwise, 1 for clockwise
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleRotateDevice(int direction);
|
||||
|
||||
/**
|
||||
* Handle setting the cursor to hot.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleHotCursor();
|
||||
|
||||
/**
|
||||
* Handle transforming player to the paintbrush
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handlePaintbrush();
|
||||
|
||||
/**
|
||||
* Handle loading a small chip from a saved program.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleLoadSmallChip();
|
||||
|
||||
/**
|
||||
* Handle context specific help (including chip help)
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleHelp();
|
||||
|
||||
/**
|
||||
* Handle entering an inner room (robot)
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleEnterRoom();
|
||||
|
||||
/**
|
||||
* Handle exiting an inner room (robot)
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleExitRoom();
|
||||
|
||||
/**
|
||||
* Handle flipping a device - either state or direction.
|
||||
* @return boolean whether the change was handled.
|
||||
*/
|
||||
public boolean handleFlipDevice();
|
||||
|
||||
}
|
@@ -2,20 +2,13 @@ package com.droidquest.avatars;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.RoomDisplay;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.devices.GenericChip;
|
||||
import com.droidquest.devices.SmallChip;
|
||||
import com.droidquest.items.GenericRobot;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.items.ToolBox;
|
||||
import com.droidquest.items.Train;
|
||||
import com.droidquest.items.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class GameCursor extends Item {
|
||||
public class GameCursor extends Player {
|
||||
private int walk = 0; // 0 or 1, used in animation
|
||||
private boolean outline; // Draw outline around GameCursor?
|
||||
|
||||
@@ -268,74 +261,30 @@ public class GameCursor extends Item {
|
||||
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.UpEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveUp(nudge);
|
||||
@Override
|
||||
public void moveUp(boolean nudge) {
|
||||
super.moveUp(nudge);
|
||||
walk = 1 - walk;
|
||||
currentIcon = icons[0 + walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.DownEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveDown(nudge);
|
||||
@Override
|
||||
public void moveDown(boolean nudge) {
|
||||
super.moveDown(nudge);
|
||||
walk = 1 - walk;
|
||||
currentIcon = icons[2 + walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.LeftEnterOverlap(this)) {
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveLeft(nudge);
|
||||
@Override
|
||||
public void moveLeft(boolean nudge) {
|
||||
super.moveLeft(nudge);
|
||||
walk = 1 - walk;
|
||||
currentIcon = icons[4 + walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.RightEnterOverlap(this)) {
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight(nudge);
|
||||
@Override
|
||||
public void moveRight(boolean nudge) {
|
||||
super.moveRight(nudge);
|
||||
walk = 1 - walk;
|
||||
currentIcon = icons[6 + walk].getImage();
|
||||
}
|
||||
@@ -352,303 +301,27 @@ public class GameCursor extends Item {
|
||||
return !i.getClass().toString().endsWith("Robot");
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_L) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof SmallChip) {
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null) {
|
||||
((SmallChip) carrying).Empty();
|
||||
((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_S) {
|
||||
if (level.solderingPen == null) {
|
||||
return false;
|
||||
}
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.solderingPen;
|
||||
}
|
||||
level.player = level.solderingPen;
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||
if (level.remote == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.remote.carriedBy == null) { // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else { // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
// if (carrying != null)
|
||||
// Drops();
|
||||
// level.remote.x = x;
|
||||
// level.remote.y = y;
|
||||
// level.remote.room = room;
|
||||
// room = null;
|
||||
// if (level.currentViewer == level.player)
|
||||
// level.currentViewer=level.remote;
|
||||
// level.player = level.remote;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_T) {
|
||||
if (level.toolbox == null) {
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
level.toolbox = new ToolBox(x, y + 8, room);
|
||||
level.items.addElement(level.toolbox);
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
if (level.toolbox.room != room) {
|
||||
// Summon Toolbox
|
||||
if (carrying != null) {
|
||||
return false;
|
||||
}
|
||||
if (((ToolBox) level.toolbox).open) {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x + 28;
|
||||
level.toolbox.y = y + 6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SLASH) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof GenericChip) {
|
||||
((GenericChip) carrying).ShowText(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (level.helpCam == null) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (level.cheatmode) {
|
||||
if (e.isShiftDown() && room != null) {
|
||||
SetRoom(room.rightRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (level.cheatmode) {
|
||||
if (e.isShiftDown() && room != null) {
|
||||
SetRoom(room.leftRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (level.cheatmode) {
|
||||
if (e.isShiftDown() && room != null) {
|
||||
SetRoom(room.upRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (level.cheatmode) {
|
||||
if (e.isShiftDown() && room != null) {
|
||||
SetRoom(room.downRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
{
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null) {
|
||||
if (item instanceof Train) {
|
||||
item.CanBePickedUp(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
else {
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null) {
|
||||
if (item.CanBePickedUp(level.gameCursor)) {
|
||||
PicksUp(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
outline = false;
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
|
||||
if (carrying != null) {
|
||||
if (carrying.isDevice()) {
|
||||
((Device) carrying).rotate(1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
|
||||
if (carrying != null) {
|
||||
if (carrying.isDevice()) {
|
||||
((Device) carrying).rotate(-1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_E) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (Overlaps(item))
|
||||
// if (x>=item.x && y>=item.y
|
||||
// && x+width <= item.x + item.width
|
||||
// && y+height <= item.y + item.height)
|
||||
{
|
||||
if (!item.OverWall()) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected boolean handleTrain() {
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null) {
|
||||
if (item instanceof Train) {
|
||||
item.CanBePickedUp(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_X) {
|
||||
if (room != null && room.portalItem != null) {
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth() / 2
|
||||
- width / 2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight() / 4 * 2
|
||||
- height / 2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_F) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof Device) {
|
||||
((Device) carrying).flip();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_M) {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freemem = runtime.freeMemory();
|
||||
long totalmem = runtime.totalMemory();
|
||||
System.out.println("Total Memory = " + totalmem
|
||||
+ ", (" + totalmem / 1024 + "K), ("
|
||||
+ totalmem / 1024 / 1024 + "M)");
|
||||
System.out.println("Free Memory = " + freemem
|
||||
+ ", (" + freemem / 1024 + "K), ("
|
||||
+ freemem / 1024 / 1024 + "M)");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
repeating++;
|
||||
if (repeating > 5) {
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
repeating++;
|
||||
if (repeating > 5) {
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
repeating++;
|
||||
if (repeating > 5) {
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
repeating++;
|
||||
if (repeating > 5) {
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
if (level.player == level.gameCursor) {
|
||||
outline = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@Override
|
||||
protected void setOutline(boolean outline) {
|
||||
this.outline = outline;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCheatMode() {
|
||||
return level.cheatmode;
|
||||
}
|
||||
|
||||
public void Animate() {
|
||||
@@ -692,38 +365,38 @@ public class GameCursor extends Item {
|
||||
}
|
||||
}
|
||||
if (dx > 0) {
|
||||
MoveRight(dx);
|
||||
moveRight(dx);
|
||||
}
|
||||
if (dx < 0) {
|
||||
MoveLeft(-dx);
|
||||
moveLeft(-dx);
|
||||
}
|
||||
if (dy > 0) {
|
||||
MoveDown(dy);
|
||||
moveDown(dy);
|
||||
}
|
||||
if (dy < 0) {
|
||||
MoveUp(-dy);
|
||||
moveUp(-dy);
|
||||
}
|
||||
}
|
||||
if (automove == 2) {
|
||||
walk = 1 - walk;
|
||||
if (autoX > 0) {
|
||||
currentIcon = icons[6 + walk].getImage();
|
||||
MoveRight(autoX);
|
||||
moveRight(autoX);
|
||||
}
|
||||
|
||||
if (autoX < 0) {
|
||||
currentIcon = icons[4 + walk].getImage();
|
||||
MoveLeft(-autoX);
|
||||
moveLeft(-autoX);
|
||||
}
|
||||
|
||||
if (autoY > 0) {
|
||||
currentIcon = icons[2 + walk].getImage();
|
||||
MoveDown(autoY);
|
||||
moveDown(autoY);
|
||||
}
|
||||
|
||||
if (autoY < 0) {
|
||||
currentIcon = icons[0 + walk].getImage();
|
||||
MoveUp(-autoY);
|
||||
moveUp(-autoY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class HelpCam extends Item {
|
||||
public class HelpCam extends Item implements Avatar {
|
||||
public HelpCam(Room r) {
|
||||
charge = 0;
|
||||
x = 28;
|
||||
@@ -38,4 +38,63 @@ public class HelpCam extends Item {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handleGameCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSolderPen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleToolbox() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRadio() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRotateDevice(int direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHotCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePaintbrush() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleLoadSmallChip() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHelp() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleEnterRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleExitRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFlipDevice() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.devices.GenericChip;
|
||||
import com.droidquest.devices.SmallChip;
|
||||
import com.droidquest.items.GenericRobot;
|
||||
import com.droidquest.items.Item;
|
||||
@@ -10,14 +8,12 @@ import com.droidquest.items.ToolBox;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class LabCursor extends Item {
|
||||
public class LabCursor extends Player {
|
||||
public boolean hot;
|
||||
|
||||
|
||||
|
||||
public LabCursor(int X, int Y, Room r) {
|
||||
x = X;
|
||||
y = Y;
|
||||
@@ -26,6 +22,10 @@ public class LabCursor extends Item {
|
||||
width = 28;
|
||||
height = 32;
|
||||
GenerateIcons();
|
||||
|
||||
// Lab cursor has a longer key repeat rate than the game cursor
|
||||
setKeyRepeatRate(10);
|
||||
|
||||
}
|
||||
|
||||
public void GenerateIcons() {
|
||||
@@ -63,359 +63,93 @@ public class LabCursor extends Item {
|
||||
return !(i instanceof GenericRobot);
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_L) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof SmallChip) {
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null) {
|
||||
((SmallChip) carrying).Empty();
|
||||
((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSaveSmallChip() {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof SmallChip) {
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null) {
|
||||
((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_H) {
|
||||
hot = !hot;
|
||||
if (hot) {
|
||||
currentIcon = icons[1].getImage();
|
||||
}
|
||||
else {
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handleHotCursor() {
|
||||
hot = !hot;
|
||||
if (hot) {
|
||||
currentIcon = icons[1].getImage();
|
||||
}
|
||||
else {
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
this.room.level.roomdisplay.dq.setHotCursorSelected(hot);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePaintbrush() {
|
||||
if (level.paintbrush == null) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_S) {
|
||||
if (level.solderingPen == null) {
|
||||
return false;
|
||||
}
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof SmallChip) {
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null) {
|
||||
((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.solderingPen;
|
||||
}
|
||||
level.player = level.solderingPen;
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||
if (level.remote == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.remote.carriedBy == null) { // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else { // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
// if (carrying != null)
|
||||
// Drops();
|
||||
// level.remote.x = x;
|
||||
// level.remote.y = y;
|
||||
// level.remote.room = room;
|
||||
// room = null;
|
||||
// if (level.currentViewer == level.player)
|
||||
// level.currentViewer=level.remote;
|
||||
// level.player = level.remote;
|
||||
level.paintbrush.x = (x / 28) * 28;
|
||||
level.paintbrush.y = (y / 32) * 32;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.paintbrush;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_P) {
|
||||
if (level.paintbrush == null) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.paintbrush;
|
||||
handleRemote();
|
||||
|
||||
level.roomdisplay.dq.selectPaintBrush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleToolbox() {
|
||||
if (level.toolbox == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.toolbox.room != room) {
|
||||
// Summon Toolbox
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
level.paintbrush.x = (x / 28) * 28;
|
||||
level.paintbrush.y = (y / 32) * 32;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.paintbrush;
|
||||
}
|
||||
level.player = level.paintbrush;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_T) {
|
||||
if (level.toolbox == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.toolbox.room != room) {
|
||||
// Summon Toolbox
|
||||
if (carrying != null) {
|
||||
return false;
|
||||
}
|
||||
if (((ToolBox) level.toolbox).open) {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x + 28;
|
||||
level.toolbox.y = y + 6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else {
|
||||
if (((ToolBox) level.toolbox).open) {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x + 28;
|
||||
level.toolbox.y = y + 6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof GenericChip) {
|
||||
((GenericChip) carrying).ShowText(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (level.helpCam == null) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
else {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
else {
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null) {
|
||||
if (item.CanBePickedUp(level.gameCursor)) {
|
||||
PicksUp(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
|
||||
if (carrying != null) {
|
||||
if (carrying.isDevice()) {
|
||||
((Device) carrying).rotate(1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
|
||||
if (carrying != null) {
|
||||
if (carrying.isDevice()) {
|
||||
((Device) carrying).rotate(-1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_E) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (Overlaps(item)) {
|
||||
if (!item.OverWall()) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_X) {
|
||||
if (room != null && room.portalItem != null) {
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth() / 2
|
||||
- width / 2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight() / 4 * 2
|
||||
- height / 2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
}
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_F) {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof Device) {
|
||||
((Device) carrying).flip();
|
||||
}
|
||||
}
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_M) {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freemem = runtime.freeMemory();
|
||||
long totalmem = runtime.totalMemory();
|
||||
System.out.println("Total Memory = " + totalmem
|
||||
+ ", (" + totalmem / 1024 + "K), ("
|
||||
+ totalmem / 1024 / 1024 + "M)");
|
||||
System.out.println("Free Memory = " + freemem
|
||||
+ ", (" + freemem / 1024 + "K), ("
|
||||
+ freemem / 1024 / 1024 + "M)");
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.UpEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveUp(nudge);
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.DownEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveDown(nudge);
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.LeftEnterOverlap(this)) {
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveLeft(nudge);
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.RightEnterOverlap(this)) {
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight(nudge);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -9,10 +9,9 @@ import com.droidquest.materials.RobotBlocker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class PaintBrush extends Item {
|
||||
public class PaintBrush extends Player {
|
||||
// The Paintbrush works just like the original, except it allows
|
||||
// differnt color paints for differnt materials. Pressing 'P' as the
|
||||
// Paintbrush switches the Material Settings.
|
||||
@@ -34,6 +33,11 @@ public class PaintBrush extends Item {
|
||||
GenerateIcons();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCheatMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void GenerateIcons() {
|
||||
icons = new ImageIcon[5];
|
||||
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
|
||||
@@ -119,115 +123,97 @@ public class PaintBrush extends Item {
|
||||
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_C) {
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.gameCursor;
|
||||
}
|
||||
level.player = level.gameCursor;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_S) {
|
||||
if (level.solderingPen == null) {
|
||||
return false;
|
||||
}
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.solderingPen;
|
||||
}
|
||||
level.player = level.solderingPen;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||
if (level.remote == null) {
|
||||
return false;
|
||||
}
|
||||
level.remote.x = x;
|
||||
level.remote.y = y;
|
||||
level.remote.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.remote;
|
||||
}
|
||||
level.player = level.remote;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SLASH) {
|
||||
if (level.helpCam == null) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (e.isShiftDown()) {
|
||||
SetRoom(room.rightRoom);
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (e.isShiftDown()) {
|
||||
SetRoom(room.leftRoom);
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (e.isShiftDown()) {
|
||||
SetRoom(room.upRoom);
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (e.isShiftDown()) {
|
||||
SetRoom(room.downRoom);
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_P) {
|
||||
paintIndex++;
|
||||
if (paintIndex == 5) {
|
||||
paintIndex = 0;
|
||||
}
|
||||
matIndex = level.materials.indexOf(paintMats[paintIndex]);
|
||||
currentIcon = icons[paintIndex].getImage();
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
if (!room.editable) {
|
||||
return false;
|
||||
}
|
||||
int bigX = (x + 14) / 28;
|
||||
int bigY = (y + 16) / 32;
|
||||
if (room.RoomArray[bigY][bigX] == emptyIndex) {
|
||||
room.SetMaterial(bigX, bigY, matIndex);
|
||||
}
|
||||
else {
|
||||
room.SetMaterial(bigX, bigY, emptyIndex);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean handleHelp() {
|
||||
handleGameCursor();
|
||||
return super.handleHelp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleLoadSmallChip() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge) {
|
||||
@Override
|
||||
public boolean handlePaintbrush() {
|
||||
paintIndex++;
|
||||
if (paintIndex == 5) {
|
||||
paintIndex = 0;
|
||||
}
|
||||
matIndex = level.materials.indexOf(paintMats[paintIndex]);
|
||||
currentIcon = icons[paintIndex].getImage();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleToolbox() {
|
||||
// Paintbrush doesn't handle toolbox
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePickupDrop() {
|
||||
// Paintbrush uses space for painting instead of pickup/drop
|
||||
if (!room.editable) {
|
||||
return false;
|
||||
}
|
||||
int bigX = (x + 14) / 28;
|
||||
int bigY = (y + 16) / 32;
|
||||
if (room.RoomArray[bigY][bigX] == emptyIndex) {
|
||||
room.SetMaterial(bigX, bigY, matIndex);
|
||||
}
|
||||
else {
|
||||
room.SetMaterial(bigX, bigY, emptyIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleEnterRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleExitRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFlipDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRotateDevice(int direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handleGameCursor() {
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.gameCursor;
|
||||
}
|
||||
level.player = level.gameCursor;
|
||||
|
||||
handleRemote();
|
||||
|
||||
level.roomdisplay.dq.selectCursor();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean handleRepeatSpace() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void moveUp(boolean nudge) {
|
||||
int dist = 32;
|
||||
if (nudge) {
|
||||
dist = 2;
|
||||
@@ -245,7 +231,7 @@ public class PaintBrush extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge) {
|
||||
public void moveDown(boolean nudge) {
|
||||
int dist = 32;
|
||||
if (nudge) {
|
||||
dist = 2;
|
||||
@@ -263,7 +249,7 @@ public class PaintBrush extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge) {
|
||||
public void moveLeft(boolean nudge) {
|
||||
int dist = 28;
|
||||
if (nudge) {
|
||||
dist = 2;
|
||||
@@ -281,7 +267,7 @@ public class PaintBrush extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge) {
|
||||
public void moveRight(boolean nudge) {
|
||||
int dist = 28;
|
||||
if (nudge) {
|
||||
dist = 2;
|
||||
|
562
src/com/droidquest/avatars/Player.java
Normal file
562
src/com/droidquest/avatars/Player.java
Normal file
@@ -0,0 +1,562 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.devices.GenericChip;
|
||||
import com.droidquest.devices.SmallChip;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.items.ToolBox;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* Parent class to handle common Player functions.
|
||||
*/
|
||||
public class Player extends Item implements Avatar {
|
||||
|
||||
private int keyRepeatRate = 5;
|
||||
|
||||
|
||||
protected boolean handleSaveSmallChip() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleRemote() {
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleSolderPen() {
|
||||
if (level.solderingPen == null) {
|
||||
return false;
|
||||
}
|
||||
if (carrying != null) {
|
||||
if (handleSaveSmallChip()) {
|
||||
// Actually a save small chip command,
|
||||
// skip solder pen
|
||||
return true;
|
||||
}
|
||||
Drops();
|
||||
}
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.solderingPen;
|
||||
}
|
||||
level.player = level.solderingPen;
|
||||
|
||||
handleRemote();
|
||||
|
||||
level.roomdisplay.dq.selectSolderpen();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleRadio() {
|
||||
if (level.remote == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.remote.carriedBy == null) { // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
|
||||
level.roomdisplay.dq.setRadioSelected(true);
|
||||
}
|
||||
else { // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
|
||||
level.roomdisplay.dq.setRadioSelected(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleHelp() {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof GenericChip) {
|
||||
((GenericChip) carrying).ShowText(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (level.helpCam == null) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleToolbox() {
|
||||
if (level.toolbox == null) {
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
level.toolbox = new ToolBox(x, y + 8, room);
|
||||
level.items.addElement(level.toolbox);
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
if (level.toolbox.room != room) {
|
||||
// Summon Toolbox
|
||||
if (carrying != null) {
|
||||
return false;
|
||||
}
|
||||
if (((ToolBox) level.toolbox).open) {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x + 28;
|
||||
level.toolbox.y = y + 6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else {
|
||||
((ToolBox) level.toolbox).Toggle();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean handleLoadSmallChip() {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof SmallChip) {
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null) {
|
||||
((SmallChip) carrying).Empty();
|
||||
((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleTrain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void PicksUp(Item item) {
|
||||
super.PicksUp(item);
|
||||
if (carrying instanceof SmallChip) {
|
||||
level.roomdisplay.dq.setLoadChipEnabled(true);
|
||||
}
|
||||
else {
|
||||
level.roomdisplay.dq.setLoadChipEnabled(false);
|
||||
|
||||
if (carrying.isDevice()) {
|
||||
level.roomdisplay.dq.setRotateEnabled(true);
|
||||
level.roomdisplay.dq.setFlipDeviceEnabled(true);
|
||||
}
|
||||
else {
|
||||
level.roomdisplay.dq.setRotateEnabled(false);
|
||||
level.roomdisplay.dq.setFlipDeviceEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Drops() {
|
||||
super.Drops();
|
||||
level.roomdisplay.dq.setRotateEnabled(false);
|
||||
level.roomdisplay.dq.setLoadChipEnabled(false);
|
||||
level.roomdisplay.dq.setFlipDeviceEnabled(false);
|
||||
}
|
||||
|
||||
public boolean handlePickupDrop() {
|
||||
if (handleTrain()) {
|
||||
return false;
|
||||
}
|
||||
if (carrying != null) {
|
||||
Drops();
|
||||
}
|
||||
else {
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null) {
|
||||
if (item.CanBePickedUp(level.gameCursor)) {
|
||||
PicksUp(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
setOutline(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Default implementation doesn't do anything,
|
||||
// needed by GameCursor to set outline
|
||||
protected void setOutline(boolean outline) {
|
||||
}
|
||||
|
||||
public boolean handleRotateDevice(int direction) {
|
||||
if (carrying != null) {
|
||||
if (carrying.isDevice()) {
|
||||
((Device) carrying).rotate(direction);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleEnterRoom() {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (Overlaps(item)) {
|
||||
if (!item.OverWall()) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleExitRoom() {
|
||||
if (room != null && room.portalItem != null) {
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth() / 2
|
||||
- width / 2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight() / 4 * 2
|
||||
- height / 2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleFlipDevice() {
|
||||
if (carrying != null) {
|
||||
if (carrying instanceof Device) {
|
||||
((Device) carrying).flip();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean handleMemory() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freemem = runtime.freeMemory();
|
||||
long totalmem = runtime.totalMemory();
|
||||
System.out.println("Total Memory = " + totalmem
|
||||
+ ", (" + totalmem / 1024 + "K), ("
|
||||
+ totalmem / 1024 / 1024 + "M)");
|
||||
System.out.println("Free Memory = " + freemem
|
||||
+ ", (" + freemem / 1024 + "K), ("
|
||||
+ freemem / 1024 / 1024 + "M)");
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isCheatMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleMoveDown(boolean isShiftDown, boolean isControlDown) {
|
||||
if (isCheatMode()) {
|
||||
if (isShiftDown && room != null) {
|
||||
SetRoom(room.downRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
moveDown(isControlDown);
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleMoveUp(boolean isShiftDown, boolean isControlDown) {
|
||||
if (isCheatMode()) {
|
||||
if (isShiftDown && room != null) {
|
||||
SetRoom(room.upRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
moveUp(isControlDown);
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleMoveLeft(boolean isShiftDown, boolean isControlDown) {
|
||||
if (isCheatMode()) {
|
||||
if (isShiftDown && room != null) {
|
||||
SetRoom(room.leftRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
moveLeft(isControlDown);
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleMoveRight(boolean isShiftDown, boolean isControlDown) {
|
||||
if (isCheatMode()) {
|
||||
if (isShiftDown && room != null) {
|
||||
SetRoom(room.rightRoom);
|
||||
}
|
||||
}
|
||||
if (carriedBy == null) {
|
||||
moveRight(isControlDown);
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleHotCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handlePaintbrush() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default assume that we are already a game cursor
|
||||
public boolean handleGameCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_L && handleLoadSmallChip()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_C && handleGameCursor()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_H && handleHotCursor()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_S && handleSolderPen()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_R && handleRadio()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_P && handlePaintbrush()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_T && handleToolbox()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SLASH && handleHelp()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_RIGHT && handleMoveRight(e.isShiftDown(), e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT && handleMoveLeft(e.isShiftDown(), e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP && handleMoveUp(e.isShiftDown(), e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN && handleMoveDown(e.isShiftDown(), e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SPACE && handlePickupDrop()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET && handleRotateDevice(1)) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET && handleRotateDevice(-1)) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_E && handleEnterRoom()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_X && handleExitRoom()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_F && handleFlipDevice()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_M && handleMemory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleRepeatRight(boolean isControlDown) {
|
||||
repeating++;
|
||||
if (repeating > getKeyRepeatRate()) {
|
||||
if (carriedBy == null) {
|
||||
moveRight(isControlDown);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
protected boolean handleRepeatLeft(boolean isControlDown) {
|
||||
repeating++;
|
||||
if (repeating > getKeyRepeatRate()) {
|
||||
if (carriedBy == null) {
|
||||
moveLeft(isControlDown);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleRepeatUp(boolean isControlDown) {
|
||||
repeating++;
|
||||
if (repeating > getKeyRepeatRate()) {
|
||||
if (carriedBy == null) {
|
||||
moveUp(isControlDown);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleRepeatDown(boolean isControlDown) {
|
||||
repeating++;
|
||||
if (repeating > getKeyRepeatRate()) {
|
||||
if (carriedBy == null) {
|
||||
moveDown(isControlDown);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
protected boolean handleRepeatSpace() {
|
||||
if (level.player == level.gameCursor) {
|
||||
setOutline(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (handleRepeatRight(e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (handleRepeatLeft(e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (handleRepeatUp(e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (handleRepeatDown(e.isControlDown())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
if (handleRepeatSpace()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int getKeyRepeatRate() {
|
||||
return keyRepeatRate;
|
||||
}
|
||||
|
||||
public void setKeyRepeatRate(int keyRepeatRate) {
|
||||
this.keyRepeatRate = keyRepeatRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveRight(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.RightEnterOverlap(this)) {
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.moveRight(nudge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveLeft(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.LeftEnterOverlap(this)) {
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.moveLeft(nudge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveDown(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.DownEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.moveDown(nudge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveUp(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (item.UpEnterOverlap(this)) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.moveUp(nudge);
|
||||
}
|
||||
|
||||
}
|
@@ -7,7 +7,7 @@ import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Remote extends Item {
|
||||
public class Remote extends Item implements Avatar {
|
||||
public Remote() {
|
||||
width = 4;
|
||||
height = 20;
|
||||
@@ -98,28 +98,28 @@ public class Remote extends Item {
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
moveRight(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
moveLeft(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
moveUp(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
moveDown(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
@@ -134,7 +134,7 @@ public class Remote extends Item {
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveRight(e.isControlDown());
|
||||
moveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -142,7 +142,7 @@ public class Remote extends Item {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveLeft(e.isControlDown());
|
||||
moveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -150,7 +150,7 @@ public class Remote extends Item {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveUp(e.isControlDown());
|
||||
moveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -158,7 +158,7 @@ public class Remote extends Item {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveDown(e.isControlDown());
|
||||
moveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -166,7 +166,7 @@ public class Remote extends Item {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge) {
|
||||
public void moveUp(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
@@ -179,10 +179,10 @@ public class Remote extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveUp(nudge);
|
||||
super.moveUp(nudge);
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge) {
|
||||
public void moveDown(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
@@ -195,10 +195,10 @@ public class Remote extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveDown(nudge);
|
||||
super.moveDown(nudge);
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge) {
|
||||
public void moveLeft(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
@@ -211,10 +211,10 @@ public class Remote extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveLeft(nudge);
|
||||
super.moveLeft(nudge);
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge) {
|
||||
public void moveRight(boolean nudge) {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
@@ -227,7 +227,66 @@ public class Remote extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight(nudge);
|
||||
super.moveRight(nudge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleGameCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSolderPen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleToolbox() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRadio() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRotateDevice(int direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHotCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePaintbrush() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleLoadSmallChip() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHelp() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleEnterRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleExitRoom() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFlipDevice() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class SolderingPen extends Device {
|
||||
public class SolderingPen extends Device implements Avatar {
|
||||
private boolean hot;
|
||||
private Port currentPort = null; // Port that Soldering pen is currently over
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge) {
|
||||
public void moveUp(boolean nudge) {
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
@@ -154,7 +154,7 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveUp(nudge);
|
||||
super.moveUp(nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class SolderingPen extends Device {
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge) {
|
||||
public void moveDown(boolean nudge) {
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
@@ -176,14 +176,14 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveDown(nudge);
|
||||
super.moveDown(nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge) {
|
||||
public void moveLeft(boolean nudge) {
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
@@ -197,14 +197,14 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveLeft(nudge);
|
||||
super.moveLeft(nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge) {
|
||||
public void moveRight(boolean nudge) {
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
@@ -218,7 +218,7 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight(nudge);
|
||||
super.moveRight(nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
@@ -296,89 +296,42 @@ public class SolderingPen extends Device {
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_C) {
|
||||
if (ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.gameCursor;
|
||||
}
|
||||
level.player = level.gameCursor;
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||
if (level.remote == null) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_C && handleGameCursor()) {
|
||||
return false;
|
||||
}
|
||||
if (level.remote.carriedBy == null) { // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else { // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_P) {
|
||||
if (level.paintbrush == null) {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_R && handleRadio()) {
|
||||
return false;
|
||||
}
|
||||
if (ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
level.paintbrush.x = x;
|
||||
level.paintbrush.y = y;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.paintbrush;
|
||||
}
|
||||
level.player = level.paintbrush;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
|
||||
if (level.helpCam == null) {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_P && handlePaintbrush()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SLASH && handleHelp()) {
|
||||
return false;
|
||||
}
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
if (carriedBy == null) {
|
||||
MoveRight(e.isControlDown());
|
||||
moveRight(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
if (carriedBy == null) {
|
||||
MoveLeft(e.isControlDown());
|
||||
moveLeft(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (carriedBy == null) {
|
||||
MoveUp(e.isControlDown());
|
||||
moveUp(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (carriedBy == null) {
|
||||
MoveDown(e.isControlDown());
|
||||
moveDown(e.isControlDown());
|
||||
}
|
||||
repeating = 0;
|
||||
return true;
|
||||
@@ -386,34 +339,14 @@ public class SolderingPen extends Device {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
WirePort();
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_F) {
|
||||
if (hot) {
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
else if (ports[0].myWire == null) // If SP is not wired
|
||||
{
|
||||
// Flip wire attached to CurrentPort
|
||||
if (currentPort.myWire != null) {
|
||||
Port tempPort = currentPort.myWire.fromPort;
|
||||
currentPort.myWire.fromPort = currentPort.myWire.toPort;
|
||||
currentPort.myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_F && handleFlipDevice()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_E && handleEnterRoom()) {
|
||||
return false;
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_X && handleExitRoom()) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -422,7 +355,7 @@ public class SolderingPen extends Device {
|
||||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveRight(e.isControlDown());
|
||||
moveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -430,7 +363,7 @@ public class SolderingPen extends Device {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveLeft(e.isControlDown());
|
||||
moveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -438,7 +371,7 @@ public class SolderingPen extends Device {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveUp(e.isControlDown());
|
||||
moveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -446,7 +379,7 @@ public class SolderingPen extends Device {
|
||||
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
repeating++;
|
||||
if (repeating > 10) {
|
||||
MoveDown(e.isControlDown());
|
||||
moveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -500,4 +433,191 @@ public class SolderingPen extends Device {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleGameCursor() {
|
||||
if (ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.gameCursor;
|
||||
}
|
||||
level.player = level.gameCursor;
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
|
||||
level.roomdisplay.dq.selectCursor();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSolderPen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleToolbox() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRadio() {
|
||||
if (level.remote == null) {
|
||||
return false;
|
||||
}
|
||||
if (level.remote.carriedBy == null) { // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
|
||||
level.roomdisplay.dq.setRadioSelected(true);
|
||||
}
|
||||
else { // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
|
||||
level.roomdisplay.dq.setRadioSelected(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRotateDevice(int direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHotCursor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleRemote() {
|
||||
if (level.remote != null) {
|
||||
if (level.remote.carriedBy != null) {
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePaintbrush() {
|
||||
if (level.paintbrush == null) {
|
||||
return false;
|
||||
}
|
||||
if (ports[0].myWire != null) {
|
||||
ports[0].myWire.Remove();
|
||||
}
|
||||
level.paintbrush.x = x;
|
||||
level.paintbrush.y = y;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player) {
|
||||
level.currentViewer = level.paintbrush;
|
||||
}
|
||||
level.player = level.paintbrush;
|
||||
|
||||
level.roomdisplay.dq.selectPaintBrush();
|
||||
|
||||
handleRemote();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleLoadSmallChip() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleHelp() {
|
||||
if (level.helpCam == null) {
|
||||
return false;
|
||||
}
|
||||
// First switch to game cursor
|
||||
handleGameCursor();
|
||||
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleEnterRoom() {
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null) {
|
||||
if (item.InternalRoom != null) {
|
||||
if (Overlaps(item)) {
|
||||
if (!item.OverWall()) {
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleExitRoom() {
|
||||
if (room != null && room.portalItem != null) {
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth() / 2
|
||||
- width / 2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight() / 4 * 2
|
||||
- height / 2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleFlipDevice() {
|
||||
if (hot) {
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
else if (ports[0].myWire == null) // If SP is not wired
|
||||
{
|
||||
// Flip wire attached to CurrentPort
|
||||
if (currentPort.myWire != null) {
|
||||
Port tempPort = currentPort.myWire.fromPort;
|
||||
currentPort.myWire.fromPort = currentPort.myWire.toPort;
|
||||
currentPort.myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user