Browse Source

Implemented additional menu items for avatars and available controls, refactored player avatars to accommodate as well as reduce redundant code.

tags/2.7
cognitivegears 5 years ago
parent
commit
a660adb81c
34 changed files with 1813 additions and 1098 deletions
  1. 290
    4
      src/com/droidquest/DQ.java
  2. 44
    4
      src/com/droidquest/RoomDisplay.java
  3. 83
    0
      src/com/droidquest/avatars/Avatar.java
  4. 37
    364
      src/com/droidquest/avatars/GameCursor.java
  5. 60
    1
      src/com/droidquest/avatars/HelpCam.java
  6. 70
    336
      src/com/droidquest/avatars/LabCursor.java
  7. 93
    107
      src/com/droidquest/avatars/PaintBrush.java
  8. 562
    0
      src/com/droidquest/avatars/Player.java
  9. 76
    17
      src/com/droidquest/avatars/Remote.java
  10. 217
    97
      src/com/droidquest/avatars/SolderingPen.java
  11. 3
    0
      src/com/droidquest/devices/Device.java
  12. 19
    19
      src/com/droidquest/items/AmpireBot.java
  13. 2
    2
      src/com/droidquest/items/ChipDecompiler.java
  14. 2
    2
      src/com/droidquest/items/GateKeeper.java
  15. 5
    13
      src/com/droidquest/items/GenericRobot.java
  16. 4
    4
      src/com/droidquest/items/Ghost.java
  17. 2
    2
      src/com/droidquest/items/Handle.java
  18. 24
    24
      src/com/droidquest/items/Item.java
  19. 10
    10
      src/com/droidquest/items/Sentry.java
  20. 14
    14
      src/com/droidquest/items/Sentry3.java
  21. 2
    2
      src/com/droidquest/items/SentryT1.java
  22. 13
    13
      src/com/droidquest/items/SentryT2.java
  23. 2
    2
      src/com/droidquest/items/SkyGuard.java
  24. 4
    4
      src/com/droidquest/items/SkywayFlyer.java
  25. 66
    6
      src/com/droidquest/items/SpyCam.java
  26. 8
    8
      src/com/droidquest/items/StormCloud.java
  27. 2
    2
      src/com/droidquest/items/Sweeper.java
  28. 62
    2
      src/com/droidquest/items/Train.java
  29. 30
    30
      src/com/droidquest/items/TrashCollector.java
  30. 1
    1
      src/com/droidquest/items/Turbine.java
  31. 3
    3
      src/com/droidquest/items/VendingHandle.java
  32. 3
    3
      src/com/droidquest/items/WallHandle.java
  33. 0
    1
      src/com/droidquest/materials/AntiPlayer.java
  34. 0
    1
      src/com/droidquest/materials/ElevatorDoor.java

+ 290
- 4
src/com/droidquest/DQ.java View File

@@ -2,6 +2,8 @@ package com.droidquest;

//This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote.

import com.droidquest.avatars.Avatar;
import com.droidquest.avatars.LabCursor;
import com.droidquest.levels.MainMenu;

import javax.swing.*;
@@ -12,6 +14,19 @@ import java.util.Set;
public class DQ extends JFrame implements ActionListener {
private RoomDisplay myRoom;

private JCheckBoxMenuItem menuToggleHot = null;
private JMenuItem menuItemCursor = null;
private JMenuItem menuItemSolderpen = null;
private JMenuItem menuItemPaintbrush = null;
private JCheckBoxMenuItem menuItemRadio = null;
private JMenuItem menuItemToolbox = null;

private JMenuItem menuRotateRight = null;
private JMenuItem menuRotateLeft = null;
private JMenuItem menuLoadChip = null;

private JMenuItem menuFlipDevice = null;

private DQ() {
// Constructor
super("DroidQuest");
@@ -27,8 +42,7 @@ public class DQ extends JFrame implements ActionListener {
setIconImage(new ImageIcon("images/helper0.gif").getImage());

Container contentPane = getContentPane();
myRoom = new RoomDisplay();
myRoom.dq = this;
myRoom = new RoomDisplay(this);

addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
@@ -41,6 +55,9 @@ public class DQ extends JFrame implements ActionListener {

JMenuBar menuBar;
JMenu fileMenu;
JMenu avatarMenu;
JMenu controlMenu;
JMenu helpMenu;
JMenuItem menuItemSave;
JMenuItem menuItemMain;
JCheckBoxMenuItem menuItemSound;
@@ -66,6 +83,91 @@ public class DQ extends JFrame implements ActionListener {
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);

avatarMenu = new JMenu("Avatar");
avatarMenu.setMnemonic(KeyEvent.VK_A);
menuBar.add(avatarMenu);


menuItemCursor = new JRadioButtonMenuItem("Cursor");
avatarMenu.add(menuItemCursor);
menuItemCursor.addActionListener(this);

menuItemSolderpen = new JRadioButtonMenuItem("Solderpen");
avatarMenu.add(menuItemSolderpen);
menuItemSolderpen.setEnabled(false);
menuItemSolderpen.addActionListener(this);

menuItemPaintbrush = new JRadioButtonMenuItem("Paintbrush");
avatarMenu.add(menuItemPaintbrush);
menuItemPaintbrush.setEnabled(false);
menuItemPaintbrush.addActionListener(this);

ButtonGroup menuItemAvatarButtonGroup = new ButtonGroup();
menuItemAvatarButtonGroup.add(menuItemCursor);
menuItemAvatarButtonGroup.add(menuItemSolderpen);
menuItemAvatarButtonGroup.add(menuItemPaintbrush);
menuItemCursor.setSelected(true);

controlMenu = new JMenu("Controls");
controlMenu.setMnemonic(KeyEvent.VK_C);
menuBar.add(controlMenu);


menuItemToolbox = new JMenuItem("Toolbox");
controlMenu.add(menuItemToolbox);
menuItemToolbox.addActionListener(this);

menuItemRadio = new JCheckBoxMenuItem("Radio");
controlMenu.add(menuItemRadio);
menuItemRadio.setSelected(false);
menuItemRadio.setEnabled(false);
menuItemRadio.addActionListener(this);

menuRotateRight = new JMenuItem("Rotate Part Clockwise");
controlMenu.add(menuRotateRight);
menuRotateRight.setEnabled(false);
menuRotateRight.addActionListener(this);

menuRotateLeft = new JMenuItem("Rotate Part Counter-clockwise");
controlMenu.add(menuRotateLeft);
menuRotateLeft.setEnabled(false);
menuRotateLeft.addActionListener(this);

menuToggleHot = new JCheckBoxMenuItem("Hot Cursor", false);
menuToggleHot.setEnabled(false);
controlMenu.add(menuToggleHot);
menuToggleHot.addActionListener(this);


menuLoadChip = new JMenuItem("Load Chip");
controlMenu.add(menuLoadChip);
menuLoadChip.setEnabled(false);
menuLoadChip.addActionListener(this);


JMenuItem menuEnterRobot = new JMenuItem("Enter Robot");
controlMenu.add(menuEnterRobot);
menuEnterRobot.addActionListener(this);

JMenuItem menuExitRobot = new JMenuItem("Exit Robot");
controlMenu.add(menuExitRobot);
menuExitRobot.addActionListener(this);

menuFlipDevice = new JMenuItem("Flip Device/Wire");
controlMenu.add(menuFlipDevice);
menuFlipDevice.setEnabled(false);
menuFlipDevice.addActionListener(this);

menuBar.add(Box.createHorizontalGlue());

helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
menuBar.add(helpMenu);

JMenuItem helpInfo = new JMenuItem("Help");
helpMenu.add(helpInfo);
helpInfo.addActionListener(this);

try {
System.setErr(System.out);
}
@@ -83,6 +185,98 @@ public class DQ extends JFrame implements ActionListener {

}

public void setHotCursorSelected(boolean selected) {
if (null != this.menuToggleHot) {
this.menuToggleHot.setSelected(selected);
}
}

public void setHotCursorEnabled(boolean enabled) {
if (null != this.menuToggleHot) {
this.menuToggleHot.setEnabled(enabled);
}
}

public void setRotateEnabled(boolean enabled) {
if (null != this.menuRotateRight && null != this.menuRotateLeft) {
this.menuRotateRight.setEnabled(enabled);
this.menuRotateLeft.setEnabled(enabled);
}
}

public void setLoadChipEnabled(boolean enabled) {
if (null != this.menuLoadChip) {
this.menuLoadChip.setEnabled(enabled);
}
}

public void setFlipDeviceEnabled(boolean enabled) {
if(null != this.menuFlipDevice) {
this.menuFlipDevice.setEnabled(enabled);
}
}

public void setToolboxEnabled(boolean enabled) {
if (null != this.menuItemToolbox) {
this.menuItemToolbox.setEnabled(enabled);
}
}


public void selectCursor() {
if (null != this.menuItemCursor) {
this.menuItemCursor.setSelected(true);
if (null != myRoom && null != myRoom.level && myRoom.level.gameCursor instanceof LabCursor) {
setHotCursorEnabled(true);
}
setToolboxEnabled(true);
}
}

public void setSolderPenEnabled(boolean enabled) {
if (null != this.menuItemSolderpen) {
this.menuItemSolderpen.setEnabled(enabled);
}
}

public void selectSolderpen() {
if (null != this.menuItemSolderpen) {
this.menuItemSolderpen.setSelected(true);
this.setHotCursorEnabled(false);
setToolboxEnabled(false);
setFlipDeviceEnabled(true);
}
}

public void setPaintbrushEnabled(boolean enabled) {
if (null != this.menuItemPaintbrush) {
this.menuItemPaintbrush.setEnabled(enabled);
setFlipDeviceEnabled(false);
}
}

public void selectPaintBrush() {
if (null != this.menuItemPaintbrush) {
this.menuItemPaintbrush.setSelected(true);
this.setHotCursorEnabled(false);
this.setToolboxEnabled(false);
}
}


public void setRadioEnabled(boolean enabled) {
if (null != this.menuItemRadio) {
this.menuItemRadio.setEnabled(enabled);
}
}

public void setRadioSelected(boolean selected) {
if (null != this.menuItemRadio) {
this.menuItemRadio.setSelected(selected);
}
}


public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Save Level")) {
FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
@@ -95,14 +289,106 @@ public class DQ extends JFrame implements ActionListener {
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
}
}

if (e.getActionCommand().equals("Main Menu")) {
else if (e.getActionCommand().equals("Cursor")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleGameCursor();
}
}
else if (e.getActionCommand().equals("Solderpen")) {
// Handle Solderpen
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleSolderPen();
}
}
else if (e.getActionCommand().equals("Paintbrush")) {
// Handle Paintbrush
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handlePaintbrush();
}
}
else if (e.getActionCommand().equals("Toolbox")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleToolbox();
}
}
else if (e.getActionCommand().equals("Radio")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRadio();
}
}
else if (e.getActionCommand().equals("Rotate Part Clockwise")) {
// Rotate a part clockwise
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRotateDevice(1);
}
}
else if (e.getActionCommand().equals("Rotate Part Counter-clockwise")) {
// Rotate counter clockwise
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRotateDevice(-1);
}
}
else if (e.getActionCommand().equals("Hot Cursor")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleHotCursor();
}
}
else if (e.getActionCommand().equals("Load Chip")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleLoadSmallChip();
}
}
else if (e.getActionCommand().equals("Help")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleHelp();
}
}
else if (e.getActionCommand().equals("Enter Robot")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleEnterRoom();
}
}
else if (e.getActionCommand().equals("Exit Robot")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleExitRoom();
}
}
else if (e.getActionCommand().equals("Flip Device/Wire")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleFlipDevice();
}
}
else if (e.getActionCommand().equals("Main Menu")) {
int n = JOptionPane.showConfirmDialog(this, "Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n == 0) {
myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom);
myRoom.level.Init();
setHotCursorEnabled(false);
setHotCursorSelected(false);
setRotateEnabled(false);
setLoadChipEnabled(false);
setPaintbrushEnabled(false);
setFlipDeviceEnabled(false);
setToolboxEnabled(false);
setSolderPenEnabled(false);
setRadioSelected(false);
setRadioEnabled(false);
selectCursor();
}
}


+ 44
- 4
src/com/droidquest/RoomDisplay.java View File

@@ -20,7 +20,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RoomDisplay extends JPanel {
public DQ dq;
public final DQ dq;
Level level;
public Timer timer;
private int timerspeed = 128;
@@ -36,7 +36,8 @@ public class RoomDisplay extends JPanel {
return (true);
}

public RoomDisplay() {
public RoomDisplay(final DQ dq) {
this.dq = dq;
setSize(new Dimension(560, 384));
level = new MainMenu(this);
level.Init();
@@ -188,6 +189,45 @@ public class RoomDisplay extends JPanel {

level.roomdisplay.useSounds = tempsound;
level.PlaySound(level.currentViewer.room, Level.TRANSPORTSOUND);


// Handle menu item initialization
if (level.gameCursor instanceof LabCursor) {
dq.setHotCursorSelected(false);
dq.setHotCursorEnabled(true);
}
else {
dq.setHotCursorSelected(false);
dq.setHotCursorEnabled(false);
}

if(null == level.solderingPen) {
dq.setSolderPenEnabled(false);
}
else {
dq.setSolderPenEnabled(true);
}

if(null == level.paintbrush) {
dq.setPaintbrushEnabled(false);
}
else {
dq.setPaintbrushEnabled(true);
}

if(null == level.remote) {
dq.setRadioEnabled(false);
dq.setRadioSelected(false);
}
else {
dq.setRadioEnabled(true);
dq.setRadioSelected(true);
}

// Always start with cursor
dq.selectCursor();


}
Electricity();
for (int a = 0; a < level.items.size(); a++) {
@@ -210,7 +250,7 @@ public class RoomDisplay extends JPanel {

repaint();
for (int a = 0; a < level.sparks.size(); a++) {
Spark spark = (Spark) level.sparks.elementAt(a);
Spark spark = level.sparks.elementAt(a);
spark.Age();
if (spark.age > 6) {
level.sparks.removeElement(spark);
@@ -284,7 +324,7 @@ public class RoomDisplay extends JPanel {

// Paint Sparks
for (int a = 0; a < level.sparks.size(); a++) {
Spark spark = (Spark) level.sparks.elementAt(a);
Spark spark = level.sparks.elementAt(a);
if (spark.room == level.currentViewer.room) {
spark.Draw(g2);
}

+ 83
- 0
src/com/droidquest/avatars/Avatar.java View 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();

}

+ 37
- 364
src/com/droidquest/avatars/GameCursor.java View File

@@ -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);
}
}
}
}
}
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();
}
@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_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);
}
}
}

+ 60
- 1
src/com/droidquest/avatars/HelpCam.java View File

@@ -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;
}
}

+ 70
- 336
src/com/droidquest/avatars/LabCursor.java View File

@@ -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());
}
}
}
}
else if (e.getKeyCode() == KeyEvent.VK_H) {
hot = !hot;
if (hot) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
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;
}
}
}
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;
}
else if (e.getKeyCode() == KeyEvent.VK_P) {
if (level.paintbrush == null) {
return false;
}
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 {
((ToolBox) level.toolbox).Toggle();
}
}
else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
if (carrying != null) {
if (carrying instanceof GenericChip) {
((GenericChip) carrying).ShowText(true);
return false;

@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;
}
if (level.helpCam == null) {
return false;
}
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
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;
return false;
}


@Override
public boolean handleHotCursor() {
hot = !hot;
if (hot) {
currentIcon = icons[1].getImage();
}
else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
if (carrying != null) {
if (carrying.isDevice()) {
((Device) carrying).rotate(1);
}
}
return false;
else {
currentIcon = icons[0].getImage();
}
else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
if (carrying != null) {
if (carrying.isDevice()) {
((Device) carrying).rotate(-1);
}
}

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_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);
}
}
}
}
if (carrying != null) {
Drops();
}
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)");
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;
handleRemote();

return false;
level.roomdisplay.dq.selectPaintBrush();

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;
}
@Override
public boolean handleToolbox() {
if (level.toolbox == null) {
return false;
}
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveLeft(e.isControlDown());
}
return true;
if (level.toolbox.room != room) {
// Summon Toolbox
if (carrying != null) {
return false;
}
return false;
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveUp(e.isControlDown());
}
return true;
if (((ToolBox) level.toolbox).open) {
((ToolBox) level.toolbox).Toggle();
}
return false;
level.toolbox.room = room;
level.toolbox.x = x + 28;
level.toolbox.y = y + 6;
PicksUp(level.toolbox);
}
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveDown(e.isControlDown());
}
return true;
}
return false;
else {
((ToolBox) level.toolbox).Toggle();
}
return false;
return true;
}

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);
}



}

+ 93
- 107
src/com/droidquest/avatars/PaintBrush.java View File

@@ -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;
@Override
public boolean handleHelp() {
handleGameCursor();
return super.handleHelp();
}

@Override
public boolean handleLoadSmallChip() {
return false;
}

@Override
public boolean handlePaintbrush() {
paintIndex++;
if (paintIndex == 5) {
paintIndex = 0;
}
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (e.isShiftDown()) {
SetRoom(room.downRoom);
}
if (carriedBy == null) {
MoveDown(e.isControlDown());
}
repeating = 0;
return true;
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;
}
if (e.getKeyCode() == KeyEvent.VK_P) {
paintIndex++;
if (paintIndex == 5) {
paintIndex = 0;
}
matIndex = level.materials.indexOf(paintMats[paintIndex]);
currentIcon = icons[paintIndex].getImage();
int bigX = (x + 14) / 28;
int bigY = (y + 16) / 32;
if (room.RoomArray[bigY][bigX] == emptyIndex) {
room.SetMaterial(bigX, bigY, matIndex);
}
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);
}
else {
room.SetMaterial(bigX, bigY, emptyIndex);
}
return true;
}

@Override
public boolean handleEnterRoom() {
return false;
}

public void MoveUp(boolean nudge) {
@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
- 0
src/com/droidquest/avatars/Player.java View 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;
}