Merge pull request #6 from cognitivegears/master

Refactored and cleaned up code.  Modernized some constructs.
This commit is contained in:
Thomas Foote 2014-04-21 07:57:57 -04:00
commit 6636ccd6e2
180 changed files with 31779 additions and 32642 deletions

View File

@ -2,68 +2,50 @@ package com.droidquest;
//This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import com.droidquest.avatars.Avatar;
import com.droidquest.avatars.LabCursor;
import com.droidquest.levels.MainMenu;
import javax.swing.*;
import com.droidquest.avatars.GameCursor;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Arrow;
import com.droidquest.decorations.Graphix;
import com.droidquest.decorations.Spark;
import com.droidquest.decorations.TextBox;
import com.droidquest.devices.ANDGate;
import com.droidquest.devices.Device;
import com.droidquest.devices.FlipFlop;
import com.droidquest.devices.NOTGate;
import com.droidquest.devices.Node;
import com.droidquest.devices.ORGate;
import com.droidquest.devices.PortDevice;
import com.droidquest.devices.XORGate;
import com.droidquest.items.Item;
import com.droidquest.items.ToolBox;
import com.droidquest.levels.Level;
import com.droidquest.levels.MainMenu;
import com.droidquest.materials.Material;
import java.util.Iterator;
import java.awt.*;
import java.awt.event.*;
import java.util.Set;
import java.util.Vector;
import java.util.Date;
import java.lang.Integer;
import java.util.Random;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;
public class DQ extends JFrame implements ActionListener
{
RoomDisplay myRoom;
public class DQ extends JFrame implements ActionListener {
private RoomDisplay myRoom;
public DQ ()
{
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");
setSize(560 + 8, 384 + 27 + 24);
addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ setVisible(false); dispose(); System.exit(0); }
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});
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)
{
addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
myRoom.requestFocus();
}
});
@ -73,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;
@ -98,15 +83,99 @@ public class DQ extends JFrame implements ActionListener
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);
try
{
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);
}
catch (SecurityException e) {}
catch (SecurityException e) {
}
}
public static void main(String[] args)
{
public static void main(String[] args) {
DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
@ -116,54 +185,229 @@ public class DQ extends JFrame implements ActionListener
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == "Save Level")
{
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);
fd.setDirectory("ROlevels");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null)
if (fd.getFile() != null) {
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
}
if (e.getActionCommand() == "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)
{
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();
}
}
if (e.getActionCommand() == "Sound")
{
if (e.getActionCommand().equals("Sound")) {
myRoom.useSounds = ((JCheckBoxMenuItem) e.getSource()).getState();
if (myRoom.useSounds==false)
{
if (!myRoom.useSounds) {
Set<String> keys = myRoom.level.sounds.keySet();
Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()) {
String soundFile = iterator.next();
for (String soundFile : keys) {
SoundClip soundClip = myRoom.level.sounds.get(soundFile);
soundClip.audioClip.stop();
}
// for (int a=0; a<myRoom.level.sounds.size(); a++)
// {
// SoundClip sc = (SoundClip) myRoom.level.sounds.elementAt(a);
// sc.audioClip.stop();
// }
}
}
if (e.getActionCommand() == "Exit")
{ setVisible(false); dispose(); System.exit(0); }
if (e.getActionCommand().equals("Exit")) {
setVisible(false);
dispose();
System.exit(0);
}
}
@ -172,8 +416,6 @@ public class DQ extends JFrame implements ActionListener
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Updating Tutorial levels to 2.0
//
//ROTUT1 : Robot Anatomy

View File

@ -1,14 +1,5 @@
package com.droidquest;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;
import com.droidquest.decorations.Arrow;
import com.droidquest.decorations.Graphix;
import com.droidquest.decorations.TextBox;
@ -16,8 +7,14 @@ import com.droidquest.items.Item;
import com.droidquest.levels.Level;
import com.droidquest.materials.Material;
public class Room implements Serializable, Cloneable
{
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;
public class Room implements Serializable, Cloneable {
public transient static Level level;
public transient Room upRoom;
public transient Room downRoom;
@ -40,14 +37,13 @@ public int[][] RoomArray = { // Array of image references
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
public transient Material[][] MaterialArray = new Material[12][20];
public Vector textBoxes = new Vector();
public Vector wires = new Vector();
public Vector graphix = new Vector();
public Vector arrows = new Vector();
public Vector<TextBox> textBoxes = new Vector<TextBox>();
public Vector<Wire> wires = new Vector<Wire>();
public Vector<Graphix> graphix = new Vector<Graphix>();
public Vector<Arrow> arrows = new Vector<Arrow>();
public boolean editable;
public Room()
{
public Room() {
upRoom = this;
downRoom = this;
rightRoom = this;
@ -55,20 +51,19 @@ public Room()
editable = false;
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
s.writeInt(level.rooms.indexOf(upRoom));
s.writeInt(level.rooms.indexOf(downRoom));
s.writeInt(level.rooms.indexOf(rightRoom));
s.writeInt(level.rooms.indexOf(leftRoom));
s.writeInt(level.items.indexOf(portalItem));
s.writeInt(wires.size());
for (int a=0; a<wires.size(); a++)
((Wire)wires.elementAt(a)).writeRef(s);
for (int a = 0; a < wires.size(); a++) {
wires.elementAt(a).writeRef(s);
}
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
upRoom = level.FindRoom(s.readInt());
downRoom = level.FindRoom(s.readInt());
rightRoom = level.FindRoom(s.readInt());
@ -76,76 +71,66 @@ public void readRef(ObjectInputStream s) throws IOException
portalItem = level.FindItem(s.readInt());
int numWires = s.readInt();
wires = new Vector();
for (int a=0; a<numWires; a++)
{
wires = new Vector<Wire>();
for (int a = 0; a < numWires; a++) {
Wire wire = new Wire();
wires.addElement(wire);
wire.readRef(s, level);
}
for (int a=0; a<graphix.size(); a++)
{
((Graphix)graphix.elementAt(a)).GenerateIcons();
for (int a = 0; a < graphix.size(); a++) {
graphix.elementAt(a).GenerateIcons();
}
GenerateArray();
}
public void GenerateArray()
{
public void GenerateArray() {
MaterialArray = new Material[12][20];
for (int y=0; y<12; y++)
for (int x=0; x<20; x++)
MaterialArray[y][x] = (Material) level.materials.elementAt(RoomArray[y][x]);
for (int y = 0; y < 12; y++) {
for (int x = 0; x < 20; x++) {
MaterialArray[y][x] = level.materials.elementAt(RoomArray[y][x]);
}
}
}
public void SetMaterial(int X, int Y, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
public void SetMaterial(int X, int Y, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
public void SetMaterial(int X, int Y, Material mat)
{
public void SetMaterial(int X, int Y, Material mat) {
int index = level.materials.indexOf(mat);
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
public void SetMaterialFill(int X1, int Y1, int X2, int Y2, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
for (int Y=Y1; Y<=Y2; Y++)
for(int X=X1; X<=X2; X++)
{
public void SetMaterialFill(int X1, int Y1, int X2, int Y2, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
for (int Y = Y1; Y <= Y2; Y++) {
for (int X = X1; X <= X2; X++) {
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
}
}
public void SetMaterialOutline(int X1, int Y1, int X2, int Y2, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
for (int Y=Y1; Y<=Y2; Y++)
{
public void SetMaterialOutline(int X1, int Y1, int X2, int Y2, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
for (int Y = Y1; Y <= Y2; Y++) {
RoomArray[Y][X1] = index;
MaterialArray[Y][X1] = mat;
RoomArray[Y][X2] = index;
MaterialArray[Y][X2] = mat;
}
for(int X=X1; X<=X2; X++)
{
for (int X = X1; X <= X2; X++) {
RoomArray[Y1][X] = index;
MaterialArray[Y1][X] = mat;
RoomArray[Y2][X] = index;
@ -154,46 +139,39 @@ public void SetMaterialOutline(int X1, int Y1, int X2, int Y2, int index)
}
}
public void SetMaterialFromRoom(int roomIndex)
{
Room r = (Room) level.rooms.elementAt(roomIndex);
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
{
public void SetMaterialFromRoom(int roomIndex) {
Room r = level.rooms.elementAt(roomIndex);
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
RoomArray[Y][X] = r.RoomArray[Y][X];
MaterialArray[Y][X] = r.MaterialArray[Y][X];
}
}
}
public void AddTextBox(String t, int X, int Y, int W)
{
public void AddTextBox(String t, int X, int Y, int W) {
TextBox newText = new TextBox(t, X, Y, W);
textBoxes.addElement(newText);
}
public void AddArrow(int X, int Y, int dir, int len, Color col)
{
public void AddArrow(int X, int Y, int dir, int len, Color col) {
Arrow newArrow = new Arrow(X, Y, dir, len, col);
arrows.addElement(newArrow);
}
public void AddGraphix(String t, int X, int Y)
{
public void AddGraphix(String t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}
public void AddGraphix(String[] t, int X, int Y)
{
public void AddGraphix(String[] t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}
public void DrawTextBoxes(Graphics g, RoomDisplay rd)
{
for (int a=0; a<textBoxes.size(); a++)
{
TextBox textBox = (TextBox) textBoxes.elementAt(a);
public void DrawTextBoxes(Graphics g, RoomDisplay rd) {
for (int a = 0; a < textBoxes.size(); a++) {
TextBox textBox = textBoxes.elementAt(a);
g.setColor(Color.white);
g.setFont(rd.smallFont);
@ -205,35 +183,31 @@ public void DrawTextBoxes(Graphics g, RoomDisplay rd)
int indexFrom = 0;
int indexTo;
do
{
do {
// Get the next word in the string
if (indexFrom >= textBox.textString.lastIndexOf(" "))
{indexTo = textBox.textString.length();}
else
{indexTo = textBox.textString.indexOf(" ",indexFrom+1);}
if (indexFrom >= textBox.textString.lastIndexOf(" ")) {
indexTo = textBox.textString.length();
}
else {
indexTo = textBox.textString.indexOf(" ", indexFrom + 1);
}
nextWord = textBox.textString.substring(indexFrom, indexTo);
if (nextWord.startsWith(" "))
{
if (nextWord.startsWith(" ")) {
nextWord = nextWord.substring(1, nextWord.length());
}
if (!nextWord.endsWith(" "))
{
if (!nextWord.endsWith(" ")) {
nextWord = nextWord + " ";
}
if (nextWord.startsWith("{BIG}"))
{
if (nextWord.startsWith("{BIG}")) {
g.setFont(rd.bigFont);
}
else if (nextWord.startsWith("{SML}"))
{
else if (nextWord.startsWith("{SML}")) {
g.setFont(rd.smallFont);
}
else if (nextWord.startsWith("{BSP}"))
{
else if (nextWord.startsWith("{BSP}")) {
FontMetrics fm = g.getFontMetrics();
advX = fm.stringWidth(" ");
cursX -= advX;
@ -242,8 +216,7 @@ public void DrawTextBoxes(Graphics g, RoomDisplay rd)
// if (nextWord fits "{rrr,ggg,bbb} "
else if (nextWord.startsWith("{")
&& nextWord.endsWith("} ")
&& nextWord.length()==14)
{
&& nextWord.length() == 14) {
// extract rrr,ggg,bbb
Integer rr = new Integer(nextWord.substring(1, 4));
Integer gg = new Integer(nextWord.substring(5, 8));
@ -252,22 +225,20 @@ public void DrawTextBoxes(Graphics g, RoomDisplay rd)
gg.intValue(),
bb.intValue()));
}
else
{
else {
FontMetrics fm = g.getFontMetrics();
if (fm.getAscent() > advY)
{advY = fm.getAscent() ;}
if (fm.getAscent() > advY) {
advY = fm.getAscent();
}
advX = fm.stringWidth(nextWord);
if (cursX+advX > textBox.width + textBox.x)
{
if (cursX + advX > textBox.width + textBox.x) {
cursX = textBox.x;
cursY += advY;
advY = fm.getAscent();
}
g.drawString(nextWord, cursX, cursY);
cursX += advX;
if (cursX+advX > textBox.width + textBox.x)
{
if (cursX + advX > textBox.width + textBox.x) {
cursX = textBox.x;
cursY += advY;
advY = fm.getAscent();
@ -279,61 +250,56 @@ public void DrawTextBoxes(Graphics g, RoomDisplay rd)
}
}
public void DrawGraphix(Graphics g, RoomDisplay rd)
{
for (int a = 0; a< graphix.size(); a++)
{
Graphix grx = (Graphix) graphix.elementAt(a);
public void DrawGraphix(Graphics g, RoomDisplay rd) {
for (int a = 0; a < graphix.size(); a++) {
Graphix grx = graphix.elementAt(a);
grx.Draw(g, rd);
}
}
public void DrawArrows(Graphics g)
{
for (int a = 0; a< arrows.size(); a++)
((Arrow) arrows.elementAt(a)).Draw(g);
public void DrawArrows(Graphics g) {
for (int a = 0; a < arrows.size(); a++) {
arrows.elementAt(a).Draw(g);
}
}
public Room getUpRoom(Item item)
{
public Room getUpRoom(Item item) {
return upRoom;
}
public Room getDownRoom(Item item)
{
public Room getDownRoom(Item item) {
return downRoom;
}
public Room getLeftRoom(Item item)
{
public Room getLeftRoom(Item item) {
return leftRoom;
}
public Room getRightRoom(Item item)
{
public Room getRightRoom(Item item) {
return rightRoom;
}
public Wire FindWire(int wireIndex)
{
if (wireIndex==-1) return null;
if (wireIndex>=wires.size()) return null;
return (Wire) wires.elementAt(wireIndex);
public Wire FindWire(int wireIndex) {
if (wireIndex == -1) {
return null;
}
if (wireIndex >= wires.size()) {
return null;
}
return wires.elementAt(wireIndex);
}
public Object clone()
{
public Object clone() {
Object newObject = null;
try
{
try {
newObject = super.clone();
}
catch (CloneNotSupportedException e) {}
catch (CloneNotSupportedException e) {
}
return newObject;
}
public void Erase()
{
public void Erase() {
upRoom = null;
downRoom = null;
rightRoom = null;
@ -341,9 +307,8 @@ public void Erase()
portalItem = null;
arrows.clear();
graphix.clear();
for (int a=0; a< wires.size(); a++)
{
Wire wire = (Wire) wires.elementAt(a);
for (int a = 0; a < wires.size(); a++) {
Wire wire = wires.elementAt(a);
wire.fromPort = null;
wire.toPort = null;
wire.inPort = null;

View File

@ -1,33 +1,5 @@
package com.droidquest;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import com.droidquest.avatars.LabCursor;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Graphix;
@ -38,47 +10,44 @@ import com.droidquest.levels.Level;
import com.droidquest.levels.MainMenu;
import com.droidquest.materials.Material;
public class RoomDisplay extends JPanel
{
public DQ dq;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class RoomDisplay extends JPanel {
public final DQ dq;
Level level;
public Timer timer;
int timerspeed=128;
private int timerspeed = 128;
public boolean useSounds = true;
AffineTransform at = new AffineTransform();
private AffineTransform at = new AffineTransform();
public Font bigFont;
public Font smallFont;
private int repeating=0; // Used for repeating keys
//public boolean isFocusTraversable()
// {
// Necessary to get the keyboard focus to work with
// the ScrenDisplay class.
// return(true);
// }
public boolean isFocusable()
{
public boolean isFocusable() {
// Necessary to get the keyboard focus to work with
// the ScrenDisplay class.
return (true);
}
public RoomDisplay()
{
public RoomDisplay(final DQ dq) {
this.dq = dq;
setSize(new Dimension(560, 384));
level = new MainMenu(this);
level.Init();
smallFont = new Font("Courier", Font.BOLD, 20);
bigFont = new Font("Courier", Font.BOLD, 45);
// setFocusable(true);
requestFocus();
// Resizing Fuctions
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e)
{
public void componentResized(ComponentEvent e) {
Dimension d = new Dimension();
getSize(d);
double w = d.width / 560.0;
@ -91,22 +60,24 @@ public class RoomDisplay extends JPanel
addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
// Event Handler for KeyReleased here
if (level.player.KeyUp(e))
if (level.player.KeyUp(e)) {
repaint();
}
if (e.getKeyCode() == e.VK_Q)
{
if (timerspeed>1)
if (e.getKeyCode() == e.VK_Q) {
if (timerspeed > 1) {
timerspeed /= 2;
}
timer.setDelay(timerspeed);
}
if (e.getKeyCode() == e.VK_W)
{
if (timerspeed<128)
if (e.getKeyCode() == e.VK_W) {
if (timerspeed < 128) {
timerspeed *= 2;
if ( (timerspeed>=128) && (level.player instanceof LabCursor) )
}
if ((timerspeed >= 128) && (level.player instanceof LabCursor)) {
timerspeed *= 2;
}
timer.setDelay(timerspeed);
}
@ -116,9 +87,9 @@ public class RoomDisplay extends JPanel
// Key Pressed Functions
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (level.player.KeyDown(e))
if (level.player.KeyDown(e)) {
repaint();
return;
}
}
});
@ -135,56 +106,35 @@ public class RoomDisplay extends JPanel
});
timer = new Timer(timerspeed, new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if (level.portal != null)
{
public void actionPerformed(ActionEvent e) {
if (level.portal != null) {
String filename = level.portal.levelName;
boolean bringStuff = level.portal.bringStuff;
boolean initLevel = level.portal.initLevel;
int x = level.player.x + level.player.getWidth()/2;
int y = level.player.y + level.player.getHeight()/2;
Graphics g = getGraphics();
level.PlaySound(level.currentViewer.room, Level.TELEPORTSOUND);
boolean tempsound = level.roomdisplay.useSounds;
level.roomdisplay.useSounds = false;
// for (int a=0; a<560; a+=2)
// {
// int c = 255*a/560;
// g.setColor(new Color(c,255-c,0));
// g.drawRect(x-a-1,y-a-1,a*2+2,a*2+2);
// g.setColor(Color.black);
// g.drawRect(x-a,y-a,a*2,a*2);
// long timeout = System.currentTimeMillis() + 1;
// do {} while (System.currentTimeMillis() < timeout);
// }
// g.setColor(Color.black);
// for (int a=0; a<560; a++)
// {
// g.drawRect(x-a,y-a,a*2,a*2);
// long timeout = System.currentTimeMillis() + 1;
// do {} while (System.currentTimeMillis() < timeout);
// }
if (bringStuff)
{
if (bringStuff) {
System.out.println("Saving carried items.");
level.WriteInventory();
}
FileInputStream f;
try
{
try {
f = new FileInputStream(filename);
try {f.close();} catch (IOException ie){}
try {
f.close();
}
catch(FileNotFoundException ie)
{
catch (IOException ie) {
}
}
catch (FileNotFoundException ie) {
// filename does not exist
RoomDisplay rd = level.roomdisplay;
String classname = "com.droidquest.levels." + filename.substring(0, filename.length() - 4);
Constructor constructor = null;
try
{
try {
Class newlevel = Class.forName(classname);
Class[] arglist = {Class.forName("com.droidquest.RoomDisplay")};
constructor = newlevel.getConstructor(arglist);
@ -195,36 +145,31 @@ public class RoomDisplay extends JPanel
}
catch (NoSuchMethodException ne) {
ne.printStackTrace();
};
try
{
}
try {
Object[] args = {rd};
level = (Level) constructor.newInstance(args);
rd.SaveLevel();
}
catch(InstantiationException ie2)
{
catch (InstantiationException ie2) {
System.out.println("Instantiation");
System.exit(0);
}
catch(IllegalAccessException ie2)
{
catch (IllegalAccessException ie2) {
System.out.println("Illegal Access");
System.exit(0);
}
catch(IllegalArgumentException ie2)
{
catch (IllegalArgumentException ie2) {
System.out.println("Illegal Argument");
System.exit(0);
}
catch(InvocationTargetException ie2)
{
catch (InvocationTargetException ie2) {
System.out.println("Invocation Target");
Throwable t = ie2.getTargetException();
ie2.printStackTrace();
System.out.println(t.getClass());
System.exit(0);
};
}
}
// {
// look for a class that matches the name "filename" without the ".lvl"
@ -233,66 +178,81 @@ public class RoomDisplay extends JPanel
System.out.println("Loading level " + filename);
LoadLevel(filename);
if (initLevel)
{
if (initLevel) {
System.out.println("Initializing Level");
level.Init();
}
if (bringStuff)
{
if (bringStuff) {
System.out.println("Loading carried items.");
level.LoadInventory();
}
x = level.player.x + level.player.getWidth()/2;
y = level.player.y + level.player.getHeight()/2;
// for (int a=560; a>0; a-=2)
// {
// int c = 255*a/560;
// g.setColor(new Color(255-c,c,0));
// g.drawRect(x-a-1,y-a-1,a*2+2,a*2+2);
// g.setColor(Color.black);
// g.drawRect(x-a,y-a,a*2,a*2);
// long timeout = System.currentTimeMillis() + 1;
// do {} while (System.currentTimeMillis() < timeout);
// }
// g.setColor(Color.black);
// for (int a=560; a>0; a--)
// {
// g.drawRect(x-a,y-a,a*2,a*2);
// long timeout = System.currentTimeMillis() + 1;
// do {} while (System.currentTimeMillis() < timeout);
// }
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++)
{
Item item = (Item) level.items.elementAt(a);
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
item.Animate();
if (item.room == level.currentViewer.room)
if (item.room == level.currentViewer.room) {
item.Decorate();
}
for (int a=0; a<level.materials.size(); a++)
((Material) level.materials.elementAt(a)).Animate();
for (int a=0; a<level.rooms.size(); a++)
{
Room room = (Room) level.rooms.elementAt(a);
for (int b=0; b<room.graphix.size(); b++)
{
Graphix graphix = (Graphix) room.graphix.elementAt(b);
}
for (int a = 0; a < level.materials.size(); a++) {
level.materials.elementAt(a).Animate();
}
for (int a = 0; a < level.rooms.size(); a++) {
Room room = level.rooms.elementAt(a);
for (int b = 0; b < room.graphix.size(); b++) {
Graphix graphix = room.graphix.elementAt(b);
graphix.Animate();
}
}
repaint();
for (int a = 0; a< level.sparks.size(); a++)
{
Spark spark = (Spark)level.sparks.elementAt(a);
for (int a = 0; a < level.sparks.size(); a++) {
Spark spark = level.sparks.elementAt(a);
spark.Age();
if (spark.age>6)
{
if (spark.age > 6) {
level.sparks.removeElement(spark);
a--;
}
@ -302,44 +262,44 @@ public class RoomDisplay extends JPanel
Image tempImage = new BufferedImage(200, 200, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = tempImage.getGraphics();
Image tempIcon;
ImageIcon tempImageIcon;
for (int a = 0; a<level.materials.size(); a++)
{
Material mat = (Material) level.materials.elementAt(a);
for (int a = 0; a < level.materials.size(); a++) {
Material mat = level.materials.elementAt(a);
tempImageIcon = mat.icon;
if (tempImageIcon != null)
if (tempImageIcon != null) {
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
}
for (int a = 0; a<level.items.size(); a++)
{
Item itm = (Item) level.items.elementAt(a);
for (int b=0; b<itm.icons.length; b++)
{
for (int a = 0; a < level.items.size(); a++) {
Item itm = level.items.elementAt(a);
for (int b = 0; b < itm.icons.length; b++) {
tempImageIcon = itm.icons[b];
if (tempImageIcon != null)
if (tempImageIcon != null) {
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
}
}
timer.start();
level.PlaySound(level.player.room, Level.STARTMUSICSOUND);
}
public void paintComponent(Graphics g)
{
public void paintComponent(Graphics g) {
super.paintComponents(g); // Paint background
Graphics2D g2 = (Graphics2D) g;
g2.setTransform(at);
// Paint Materials
if (level.currentViewer.room.MaterialArray==null)
if (level.currentViewer.room.MaterialArray == null) {
level.currentViewer.room.GenerateArray();
for (int y=0; y<12; y++)
for (int x=0;x<20;x++)
}
for (int y = 0; y < 12; y++) {
for (int x = 0; x < 20; x++) {
level.currentViewer.room.MaterialArray[y][x].Draw(g2, this, x, y);
}
}
// Paint Texts
level.currentViewer.room.DrawTextBoxes(g2, this);
@ -351,21 +311,24 @@ public class RoomDisplay extends JPanel
level.currentViewer.room.DrawArrows(g2);
// Paint Items
for (int a = 0; a < level.items.size(); a++)
if (level.currentViewer.room == ((Item) level.items.elementAt(a)).room)
((Item) level.items.elementAt(a)).Draw(g2,this);
for (int a = 0; a < level.items.size(); a++) {
if (level.currentViewer.room == level.items.elementAt(a).room) {
level.items.elementAt(a).Draw(g2, this);
}
}
// Paint Wires
for (int a = 0; a< level.currentViewer.room.wires.size(); a++)
((Wire) level.currentViewer.room.wires.elementAt(a)).Draw(g2);
for (int a = 0; a < level.currentViewer.room.wires.size(); a++) {
level.currentViewer.room.wires.elementAt(a).Draw(g2);
}
// Paint Sparks
for (int a = 0; a< level.sparks.size(); a++)
{
Spark spark = (Spark)level.sparks.elementAt(a);
if (spark.room == level.currentViewer.room)
for (int a = 0; a < level.sparks.size(); a++) {
Spark spark = level.sparks.elementAt(a);
if (spark.room == level.currentViewer.room) {
spark.Draw(g2);
}
}
// Repaint the Current Player on top of everything else
// if (level.currentViewer.room == level.player.room)
@ -376,49 +339,45 @@ public class RoomDisplay extends JPanel
}
public void Electricity()
{
if (level.electricity == false)
void Electricity() {
if (!level.electricity) {
return;
}
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.isDevice())
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.isDevice()) {
Device device = (Device) item;
for (int b=0; b<device.ports.length; b++)
{
for (int b = 0; b < device.ports.length; b++) {
Wire wire = device.ports[b].myWire;
if (wire != null)
{
if (wire.inPort != null && wire.outPort!=null)
{
if (wire != null) {
if (wire.inPort != null && wire.outPort != null) {
wire.value = wire.outPort.value;
wire.inPort.value = wire.value;
}
}
else if (device.ports[b].type == Port.TYPE_INPUT)
{
else if (device.ports[b].type == Port.TYPE_INPUT) {
device.ports[b].value = false;
if (level.gameCursor instanceof LabCursor)
if (device.room == level.gameCursor.room)
if (level.gameCursor instanceof LabCursor) {
if (device.room == level.gameCursor.room) {
if (device.ports[b].x + device.x >= level.gameCursor.x
&& device.ports[b].x + device.x <= level.gameCursor.x + level.gameCursor.getWidth()
&& device.ports[b].y + device.y >= level.gameCursor.y
&& device.ports[b].y+device.y <= level.gameCursor.y + level.gameCursor.getHeight())
if (((LabCursor)level.gameCursor).hot)
&& device.ports[b].y + device.y <= level.gameCursor.y + level.gameCursor.getHeight()) {
if (((LabCursor) level.gameCursor).hot) {
device.ports[b].value = true;
}
}
}
}
}
}
}
}
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.isDevice())
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.isDevice()) {
Device device = (Device) item;
device.Function();
}
@ -427,43 +386,40 @@ public class RoomDisplay extends JPanel
boolean nodeChanged;
int counter = 0;
do
{
do {
nodeChanged = false;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.isDevice())
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.isDevice()) {
Device device = (Device) item;
for (int b=0; b<device.ports.length; b++)
{
for (int b = 0; b < device.ports.length; b++) {
Wire wire = device.ports[b].myWire;
if (wire != null)
{
if (wire.inPort != null && wire.outPort!=null)
{
if (wire != null) {
if (wire.inPort != null && wire.outPort != null) {
wire.value = wire.outPort.value;
wire.inPort.value = wire.value;
}
}
else if (device.ports[b].type == Port.TYPE_INPUT)
{
else if (device.ports[b].type == Port.TYPE_INPUT) {
device.ports[b].value = false;
if (level.gameCursor instanceof LabCursor)
if (device.room == level.gameCursor.room)
if (level.gameCursor instanceof LabCursor) {
if (device.room == level.gameCursor.room) {
if (device.ports[b].x + device.x >= level.gameCursor.x
&& device.ports[b].x + device.x <= level.gameCursor.x + level.gameCursor.getWidth()
&& device.ports[b].y + device.y >= level.gameCursor.y
&& device.ports[b].y+device.y <= level.gameCursor.y + level.gameCursor.getHeight())
if (((LabCursor)level.gameCursor).hot)
&& device.ports[b].y + device.y <= level.gameCursor.y + level.gameCursor.getHeight()) {
if (((LabCursor) level.gameCursor).hot) {
device.ports[b].value = true;
}
}
if (device.isNode())
{
if (device.Function())
}
}
}
}
if (device.isNode()) {
if (device.Function()) {
nodeChanged = true;
}
}
}
@ -474,23 +430,21 @@ public class RoomDisplay extends JPanel
}
public void SaveLevel()
{
void SaveLevel() {
String temp = level.getClass().toString();
System.out.println("Class name is " + temp);
String[] path = temp.split("\\.");
for (int a=0; a< path.length; a++)
for (int a = 0; a < path.length; a++) {
System.out.println(a + " = " + path[a]);
}
// String filename = temp.substring(6);
String filename = path[path.length - 1];
SaveLevel(filename + ".lvl");
}
public void SaveLevel(String filename)
{
public void SaveLevel(String filename) {
System.out.println("Saving level " + filename);
try
{
try {
FileOutputStream out = new FileOutputStream(filename);
ObjectOutputStream s = new ObjectOutputStream(out);
level.writeObject(s);
@ -498,19 +452,16 @@ public class RoomDisplay extends JPanel
s.close();
out.close();
}
catch (FileNotFoundException e)
{
catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
catch (IOException e)
{
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
}
}
public void LoadLevel(String filename)
{
void LoadLevel(String filename) {
timer.stop();
level.Empty();
level = new Level(this);
@ -519,31 +470,26 @@ public class RoomDisplay extends JPanel
Material.level = level;
// Add flags for loading Object inventories or running Init()
try
{
try {
FileInputStream in = new FileInputStream(filename);
ObjectInputStream s = new ObjectInputStream(in);
level.readObject(s);
s.close();
in.close();
}
catch (FileNotFoundException e)
{
catch (FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
catch (IOException e)
{
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
if (level.remote != null)
{
if (level.electricity)
{
if (level.remote != null) {
if (level.electricity) {
level.remote.x = 28;
level.remote.y = -20;
level.remote.carriedBy = level.player;

View File

@ -5,23 +5,19 @@ import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;
public class SoundClip
{
public class SoundClip {
public AudioClip audioClip;
public String filename;
private String filename;
public SoundClip(String f)
{
public SoundClip(String f) {
filename = f;
try
{
try {
URL baseURL = new URL("file:" + System.getProperty("user.dir") + "/sounds/");
URL soundURL;
soundURL = new URL(baseURL, filename);
audioClip = Applet.newAudioClip(soundURL);
}
catch (MalformedURLException e)
{
catch (MalformedURLException e) {
System.err.println(e.getMessage());
}
}

View File

@ -1,54 +1,49 @@
package com.droidquest;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Device;
import com.droidquest.levels.Level;
public class Wire implements Serializable
{
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Wire implements Serializable {
public transient Port fromPort; // Connected First
public transient Port toPort; // Connected 2nd
public transient Port inPort; // Connected to Input
public transient Port outPort; // Connected to Output (Source of Value)
public boolean value;
public Wire() {}
public Wire() {
}
public Wire(Port f, Port t)
{
if (f.myDevice!=null)
{
if (f.myDevice.room!=null)
{
if (f.myDevice.room.wires==null)
public Wire(Port f, Port t) {
if (f.myDevice != null) {
if (f.myDevice.room != null) {
if (f.myDevice.room.wires == null) {
System.out.println("f.myDevice.room.wires is null");
}
else
}
else {
System.out.println("f.myDevice.room is null");
}
else
}
else {
System.out.println("f.myDevice is null");
}
f.myDevice.room.wires.addElement(this);
f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND);
if (f.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (f.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -57,8 +52,7 @@ public Wire(Port f, Port t)
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -69,10 +63,8 @@ public Wire(Port f, Port t)
return;
}
}
if (f.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (f.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -81,13 +73,11 @@ public Wire(Port f, Port t)
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -98,10 +88,8 @@ public Wire(Port f, Port t)
return;
}
}
if (f.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
if (f.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -111,8 +99,7 @@ public Wire(Port f, Port t)
f.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
@ -122,41 +109,49 @@ public Wire(Port f, Port t)
f.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
return;
}
}
}
protected void writeRef(ObjectOutputStream s) throws IOException
{
void writeRef(ObjectOutputStream s) throws IOException {
Level level = fromPort.myDevice.level;
int a;
s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device
a=0; while (((Device)fromPort.myDevice).ports[a] != fromPort) a++;
a = 0;
while (((Device) fromPort.myDevice).ports[a] != fromPort) {
a++;
}
s.writeInt(a); // Index of fromport (as device.ports[?]
s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device
a=0; while (((Device)toPort.myDevice).ports[a] != toPort) a++;
a = 0;
while (((Device) toPort.myDevice).ports[a] != toPort) {
a++;
}
s.writeInt(a); // Index of toPort (as device.ports[?]
s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device
a=0; while (((Device)inPort.myDevice).ports[a] != inPort) a++;
a = 0;
while (((Device) inPort.myDevice).ports[a] != inPort) {
a++;
}
s.writeInt(a); // Index of inPort (as device.ports[?]
s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device
a=0; while (((Device)outPort.myDevice).ports[a] != outPort) a++;
a = 0;
while (((Device) outPort.myDevice).ports[a] != outPort) {
a++;
}
s.writeInt(a); // Index of outPort (as device.ports[?]
}
protected void readRef(ObjectInputStream s, Level level) throws IOException
{
void readRef(ObjectInputStream s, Level level) throws IOException {
Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()];
@ -168,33 +163,27 @@ protected void readRef(ObjectInputStream s, Level level) throws IOException
outPort = tempDevice.ports[s.readInt()];
}
public void ConnectTo(Port t)
{
public void ConnectTo(Port t) {
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);
if (toPort.myDevice == toPort.myDevice.level.solderingPen)
{
if (toPort.myDevice == toPort.myDevice.level.solderingPen) {
toPort.value = false;
toPort.type = Port.TYPE_UNDEFINED;
toPort.myWire = null;
if (fromPort.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (fromPort.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
inPort = fromPort;
@ -203,23 +192,19 @@ public void ConnectTo(Port t)
return;
}
}
if (fromPort.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (fromPort.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
outPort = fromPort;
@ -228,10 +213,8 @@ public void ConnectTo(Port t)
return;
}
}
if (fromPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
if (fromPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
toPort = t;
t.myWire = this;
outPort = fromPort;
@ -239,8 +222,7 @@ public void ConnectTo(Port t)
fromPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
@ -248,37 +230,30 @@ public void ConnectTo(Port t)
fromPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
return;
}
}
}
else
{
else {
fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null;
if (toPort.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (toPort.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
inPort = toPort;
@ -287,23 +262,19 @@ public void ConnectTo(Port t)
return;
}
}
if (toPort.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
if (toPort.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
outPort = toPort;
@ -312,10 +283,8 @@ public void ConnectTo(Port t)
return;
}
}
if (toPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
if (toPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = t;
t.myWire = this;
outPort = toPort;
@ -323,8 +292,7 @@ public void ConnectTo(Port t)
toPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
@ -332,19 +300,16 @@ public void ConnectTo(Port t)
toPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
return;
}
}
}
}
public void Remove()
{
public void Remove() {
Room room = fromPort.myDevice.room;
room.level.PlaySound(room, Level.DETATCHSOUND);
@ -359,17 +324,14 @@ public void Remove()
}
public void Draw(Graphics g)
{
public void Draw(Graphics g) {
g.setColor(Color.white);
value = false;
if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value)
{
if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value) {
g.setColor(new Color(255, 128, 0));
value = true;
}
if (toPort.type == Port.TYPE_OUTPUT && toPort.value)
{
if (toPort.type == Port.TYPE_OUTPUT && toPort.value) {
g.setColor(new Color(255, 128, 0));
value = true;
}
@ -382,8 +344,7 @@ public void Draw(Graphics g)
y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y;
switch((((Device)fromPort.myDevice).rotation + fromPort.rotation)%4)
{
switch ((((Device) fromPort.myDevice).rotation + fromPort.rotation) % 4) {
case 0: // Up
x1 += 1;
y1 += 1;
@ -401,8 +362,7 @@ public void Draw(Graphics g)
y1 -= 2;
break;
}
switch((((Device)toPort.myDevice).rotation + toPort.rotation)%4)
{
switch ((((Device) toPort.myDevice).rotation + toPort.rotation) % 4) {
case 0: // Up
x2 += 1;
y2 += 1;
@ -429,10 +389,13 @@ public void Draw(Graphics g)
}
public Port otherPort(Port p)
{
if (fromPort == p) return toPort;
if (toPort == p) return fromPort;
public Port otherPort(Port p) {
if (fromPort == p) {
return toPort;
}
if (toPort == p) {
return fromPort;
}
return null;
}

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

View File

@ -1,42 +1,31 @@
package com.droidquest.avatars;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
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.*;
public class GameCursor extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class GameCursor extends Player {
private int walk = 0; // 0 or 1, used in animation
public boolean outline; // Draw outline around GameCursor?
private boolean outline; // Draw outline around GameCursor?
public GameCursor(){}
public GameCursor() {
}
public GameCursor(int X, int Y, Room r)
{
x=X; y=Y;
public GameCursor(int X, int Y, Room r) {
x = X;
y = Y;
outline = false;
room = r;
width=28; height=32;
width = 28;
height = 32;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
// Executed once during initialization
icons = new ImageIcon[8];
icons[0] = new ImageIcon(new BufferedImage(28, 32, BufferedImage.TYPE_4BYTE_ABGR));
@ -52,12 +41,10 @@ public class GameCursor extends Item
Color transparent = new Color(0, 0, 0, 0);
// 0 = up, left leg up
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -80,12 +67,10 @@ public class GameCursor extends Item
g.fillRect(16, 28, 8, 2);
// 1 = up, right leg up
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -108,12 +93,10 @@ public class GameCursor extends Item
g.fillRect(16, 26, 8, 2);
// 2 = down, left(side) leg up
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -139,12 +122,10 @@ public class GameCursor extends Item
g.fillRect(16, 28, 8, 2);
// 3 = down, right(side) leg up
try
{
try {
g = icons[3].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -170,12 +151,10 @@ public class GameCursor extends Item
g.fillRect(16, 26, 8, 2);
// 4 = left, Stand
try
{
try {
g = icons[4].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -196,12 +175,10 @@ public class GameCursor extends Item
g.fillRect(12, 28, 8, 2);
// 5 = left, walk
try
{
try {
g = icons[5].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -228,12 +205,10 @@ public class GameCursor extends Item
g.fillRect(16, 28, 8, 2);
// 6 = right, Stand
try
{
try {
g = icons[6].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -254,12 +229,10 @@ public class GameCursor extends Item
g.fillRect(8, 28, 8, 2);
// 7 = right, walk
try
{
try {
g = icons[7].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to GameCursor Image");
return;
}
@ -288,486 +261,171 @@ 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();
}
public void Draw(Graphics g, RoomDisplay rd)
{
public void Draw(Graphics g, RoomDisplay rd) {
g.drawImage(currentIcon, x, y, rd);
if (outline)
{
if (outline) {
g.setColor(Color.white);
g.drawRect(x, y, 28, 32);
}
}
public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
public boolean CanBePickedUp(Item i) {
return !i.getClass().toString().endsWith("Robot");
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_L)
{
if (carrying != null)
if (carrying.getClass().toString().endsWith("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() == e.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() == e.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() == e.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() == e.VK_SLASH)
{
if (carrying != null)
if (carrying.getClass().toString().endsWith("Chip"))
{
((GenericChip)carrying).ShowText(true);
return false;
}
if (level.helpCam == null) return false;
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
if (e.getKeyCode() == e.VK_RIGHT)
{
if (level.cheatmode)
if (e.isShiftDown())
SetRoom(room.rightRoom);
if (carriedBy==null)
MoveRight(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (level.cheatmode)
if (e.isShiftDown())
SetRoom(room.leftRoom);
if (carriedBy==null)
MoveLeft(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_UP)
{
if (level.cheatmode)
if (e.isShiftDown())
SetRoom(room.upRoom);
if (carriedBy==null)
MoveUp(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (level.cheatmode)
if (e.isShiftDown())
SetRoom(room.downRoom);
if (carriedBy==null)
MoveDown(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_SPACE)
{
{
@Override
protected boolean handleTrain() {
Item item = level.FindNearestItem(level.gameCursor);
if (item!=null)
if (item.getClass().toString().endsWith("Train"))
{
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() == e.VK_CLOSE_BRACKET)
{
if (carrying !=null)
if (carrying.isDevice())
((Device) carrying).rotate(1);
return false;
}
if (e.getKeyCode() == e.VK_OPEN_BRACKET)
{
if (carrying !=null)
if (carrying.isDevice())
((Device) carrying).rotate(-1);
return false;
}
if (e.getKeyCode() == e.VK_E)
{
boolean found=false;
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);
found=true;
}
}
if (e.getKeyCode() == e.VK_X)
{
if (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() == e.VK_F)
{
if (carrying != null)
if (carrying instanceof Device)
((Device)carrying).flip();
}
if (e.getKeyCode() == e.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() == e.VK_RIGHT)
{
repeating++;
if (repeating>5)
{
if (carriedBy==null)
MoveRight(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_LEFT)
{
repeating++;
if (repeating>5)
{
if (carriedBy==null)
MoveLeft(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_UP)
{
repeating++;
if (repeating>5)
{
if (carriedBy==null)
MoveUp(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_DOWN)
{
repeating++;
if (repeating>5)
{
if (carriedBy==null)
MoveDown(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_SPACE)
{
if (level.player == level.gameCursor)
outline = true;
}
return false;
}
public void Animate()
{
if (automove==1 && room == null)
@Override
protected void setOutline(boolean outline) {
this.outline = outline;
}
@Override
protected boolean isCheatMode() {
return level.cheatmode;
}
public void Animate() {
if (automove == 1 && room == null) {
automove = 0;
if (automove==1)
{
}
if (automove == 1) {
int dx = autoX - x;
int dy = autoY - y;
if (dx==0 && dy==0)
{
if (dx == 0 && dy == 0) {
automove = 0;
return;
}
if (dx<-28) dx =-28;
if (dx>28) dx=28;
if (dy<-32) dy=-32;
if (dy>32) dy=32;
if (dx < -28) {
dx = -28;
}
if (dx > 28) {
dx = 28;
}
if (dy < -32) {
dy = -32;
}
if (dy > 32) {
dy = 32;
}
walk = 1 - walk;
if (dx==0)
{
if (dy<0)
if (dx == 0) {
if (dy < 0) {
currentIcon = icons[0 + walk].getImage();
else
}
else {
currentIcon = icons[2 + walk].getImage();
}
else
{
if (dx<0)
}
else {
if (dx < 0) {
currentIcon = icons[4 + walk].getImage();
else
}
else {
currentIcon = icons[6 + walk].getImage();
}
if (dx>0) MoveRight(dx);
if (dx<0) MoveLeft(-dx);
if (dy>0) MoveDown(dy);
if (dy<0) MoveUp(-dy);
}
if (automove==2)
{
if (dx > 0) {
moveRight(dx);
}
if (dx < 0) {
moveLeft(-dx);
}
if (dy > 0) {
moveDown(dy);
}
if (dy < 0) {
moveUp(-dy);
}
}
if (automove == 2) {
walk = 1 - walk;
if (autoX>0)
{
if (autoX > 0) {
currentIcon = icons[6 + walk].getImage();
MoveRight(autoX);
moveRight(autoX);
}
if (autoX<0)
{
if (autoX < 0) {
currentIcon = icons[4 + walk].getImage();
MoveLeft(-autoX);
moveLeft(-autoX);
}
if (autoY>0)
{
if (autoY > 0) {
currentIcon = icons[2 + walk].getImage();
MoveDown(autoY);
moveDown(autoY);
}
if (autoY<0)
{
if (autoY < 0) {
currentIcon = icons[0 + walk].getImage();
MoveUp(-autoY);
moveUp(-autoY);
}
}
}
public GenericRobot PlayerInRobot(GenericRobot robot)
{
if (robot==null)
{
if (level.player.room.portalItem!=null)
{
if (level.player.room.portalItem.getClass().toString().endsWith("Robot"))
public GenericRobot PlayerInRobot(GenericRobot robot) {
if (robot == null) {
if (level.player.room.portalItem != null) {
if (level.player.room.portalItem instanceof GenericRobot) {
return (PlayerInRobot((GenericRobot) level.player.room.portalItem));
else return (null);
}
else
else {
return (null);
}
else
if (robot.room.portalItem != null)
{
if (robot.room.portalItem.getClass().toString().endsWith("Robot"))
}
else {
return (null);
}
}
else if (robot.room.portalItem != null) {
if (robot.room.portalItem instanceof GenericRobot) {
return (PlayerInRobot((GenericRobot) robot.room.portalItem));
else
}
else {
return null;
}
else
}
else {
return robot;
}
}
}

View File

@ -1,45 +1,100 @@
package com.droidquest.avatars;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import com.droidquest.Room;
import com.droidquest.items.Item;
public class HelpCam extends Item
{
public HelpCam(Room r)
{
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public class HelpCam extends Item implements Avatar {
public HelpCam(Room r) {
charge = 0;
x=28; y=32; width=0; height=0; room =r;
x = 28;
y = 32;
width = 0;
height = 0;
room = r;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(8, 8, BufferedImage.TYPE_4BYTE_ABGR));
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_ENTER)
{
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
level.player = level.gameCursor;
level.currentViewer = level.gameCursor;
}
return false;
}
public void Draw(Graphics g, JPanel jp)
{
public void Draw(Graphics g, JPanel jp) {
// Draws nothing
}
@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;
}
}

View File

@ -1,440 +1,155 @@
package com.droidquest.avatars;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
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;
import com.droidquest.items.ToolBox;
public class LabCursor extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class LabCursor extends Player {
public boolean hot;
public LabCursor(){}
public LabCursor(int X, int Y, Room r)
{
x=X; y=Y;
public LabCursor(int X, int Y, Room r) {
x = X;
y = Y;
hot = false;
room = r;
width=28; height=32;
width = 28;
height = 32;
GenerateIcons();
// Lab cursor has a longer key repeat rate than the game cursor
setKeyRepeatRate(10);
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
g2 = (Graphics2D) g;
g.setColor(new Color(255, 128, 0));
g.fillRect(0, 0, width, height);
if (hot)
if (hot) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_L)
{
if (carrying != null)
if (carrying.getClass().toString().endsWith("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());
public boolean CanBePickedUp(Item i) {
return !(i instanceof GenericRobot);
}
}
}
if (e.getKeyCode() == e.VK_H)
{
hot = !hot;
if (hot)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
return false;
}
if (e.getKeyCode() == e.VK_S)
{
if (level.solderingPen == null) return false;
if (carrying != null)
if (carrying.getClass().toString().endsWith("SmallChip"))
{
@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)
if (fd.getFile() != null) {
((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
}
return true;
}
}
return false;
}
if (carrying != null)
@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;
}
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() == e.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() == e.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)
if (level.currentViewer == level.player) {
level.currentViewer = level.paintbrush;
level.player = level.paintbrush;
}
if (e.getKeyCode() == e.VK_T)
{
if (level.toolbox == null) return false;
if (level.toolbox.room != room)
{
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) return false;
if (((ToolBox)level.toolbox).open) ((ToolBox)level.toolbox).Toggle();
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
else {
((ToolBox) level.toolbox).Toggle();
}
if (e.getKeyCode() == e.VK_SLASH)
{
if (carrying != null)
if (carrying.getClass().toString().endsWith("Chip"))
{
((GenericChip)carrying).ShowText(true);
return false;
}
if (level.helpCam == null) return false;
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
if (e.getKeyCode() == e.VK_RIGHT)
{
if (carriedBy==null)
MoveRight(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (carriedBy==null)
MoveLeft(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_UP)
{
if (carriedBy==null)
MoveUp(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (carriedBy==null)
MoveDown(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.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;
}
if (e.getKeyCode() == e.VK_CLOSE_BRACKET)
{
if (carrying !=null)
if (carrying.isDevice())
((Device) carrying).rotate(1);
return false;
}
if (e.getKeyCode() == e.VK_OPEN_BRACKET)
{
if (carrying !=null)
if (carrying.isDevice())
((Device) carrying).rotate(-1);
return false;
}
if (e.getKeyCode() == e.VK_E)
{
boolean found=false;
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);
found=true;
}
}
if (e.getKeyCode() == e.VK_X)
{
if (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() == e.VK_F)
{
if (carrying != null)
if (carrying instanceof Device)
((Device)carrying).flip();
}
if (e.getKeyCode() == e.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() == e.VK_RIGHT)
{
repeating++;
if (repeating>10)
{
if (carriedBy==null)
MoveRight(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_LEFT)
{
repeating++;
if (repeating>10)
{
if (carriedBy==null)
MoveLeft(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_UP)
{
repeating++;
if (repeating>10)
{
if (carriedBy==null)
MoveUp(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.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);
}
}

View File

@ -1,20 +1,17 @@
package com.droidquest.avatars;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.items.GenericRobot;
import com.droidquest.items.BlueRobot;
import com.droidquest.items.Item;
import com.droidquest.items.OrangeRobot;
import com.droidquest.items.WhiteRobot;
import com.droidquest.materials.Material;
import com.droidquest.materials.RobotBlocker;
public class PaintBrush extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
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.
@ -25,19 +22,23 @@ public class PaintBrush extends Item
// Undetectable, blocks White White
// Undetectable, blocks Blue Blue
int emptyIndex=0;
int paintIndex; // Which paintMats[] am I using?
transient Material[] paintMats;
int matIndex; // index of chosen paintMax in level.materials
private int emptyIndex = 0;
private int paintIndex; // Which paintMats[] am I using?
private transient Material[] paintMats;
private int matIndex; // index of chosen paintMax in level.materials
public PaintBrush()
{
width=28; height=32;
public PaintBrush() {
width = 28;
height = 32;
GenerateIcons();
}
public void 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));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -47,31 +48,32 @@ public class PaintBrush extends Item
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
for (int a=0; a<5; a++)
{
try
{
for (int a = 0; a < 5; a++) {
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to PaintBrush Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
switch(a)
{
case 0: g.setColor(new Color(192,0,0));
switch (a) {
case 0:
g.setColor(new Color(192, 0, 0));
break;
case 1: g.setColor(new Color(0,192,0));
case 1:
g.setColor(new Color(0, 192, 0));
break;
case 2: g.setColor(new Color(192,96,0));
case 2:
g.setColor(new Color(192, 96, 0));
break;
case 3: g.setColor(new Color(192,192,192));
case 3:
g.setColor(new Color(192, 192, 192));
break;
case 4: g.setColor(new Color(0,0,192));
case 4:
g.setColor(new Color(0, 0, 192));
break;
}
@ -90,19 +92,30 @@ public class PaintBrush extends Item
paintMats[0] = Material.FindSimiliar(new Material(Color.red, false, true));
paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false));
Item robot = null;
for (int a=0; a<level.items.size(); a++)
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("OrangeRobot"))
robot = (GenericRobot) level.items.elementAt(a);
if (robot==null)
for(Item item : level.items) {
if(item instanceof OrangeRobot) {
robot = item;
}
}
if (robot == null) {
System.out.println("Create paintbrush AFTER creating robots.");
}
paintMats[2] = Material.FindSimiliar(new RobotBlocker(robot, new Color(255, 128, 0)));
for (int a=0; a<level.items.size(); a++)
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("WhiteRobot"))
robot = (GenericRobot) level.items.elementAt(a);
for (Item item : level.items) {
if(item instanceof WhiteRobot) {
robot = item;
}
}
paintMats[3] = Material.FindSimiliar(new RobotBlocker(robot, Color.white));
for (int a=0; a<level.items.size(); a++)
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("BlueRobot"))
robot = (GenericRobot) level.items.elementAt(a);
for(Item item : level.items) {
if(item instanceof BlueRobot) {
robot = item;
}
}
paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue));
paintIndex = 0;
@ -110,168 +123,166 @@ public class PaintBrush extends Item
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_C)
{
@Override
public boolean handleHelp() {
handleGameCursor();
return super.handleHelp();
}
@Override
public boolean handleLoadSmallChip() {
return false;
}
@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)
if (level.currentViewer == level.player) {
level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor;
}
if (e.getKeyCode() == e.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() == e.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() == e.VK_SLASH)
{
if (level.helpCam == null) return false;
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
if (e.getKeyCode() == e.VK_RIGHT)
{
if (e.isShiftDown())
SetRoom(room.rightRoom);
if (carriedBy==null)
MoveRight(e.isControlDown());
repeating=0;
handleRemote();
level.roomdisplay.dq.selectCursor();
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (e.isShiftDown())
SetRoom(room.leftRoom);
if (carriedBy==null)
MoveLeft(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_UP)
{
if (e.isShiftDown())
SetRoom(room.upRoom);
if (carriedBy==null)
MoveUp(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (e.isShiftDown())
SetRoom(room.downRoom);
if (carriedBy==null)
MoveDown(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_P)
{
paintIndex++;
if (paintIndex==5) paintIndex=0;
matIndex = level.materials.indexOf(paintMats[paintIndex]);
currentIcon=icons[paintIndex].getImage();
}
if (e.getKeyCode() == e.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
protected boolean handleRepeatSpace() {
return false;
}
public void MoveUp(boolean nudge)
{
public void moveUp(boolean nudge) {
int dist = 32;
if (nudge) dist = 2;
if (nudge) {
dist = 2;
}
y = y - dist;
if (y<0)
{
if (room.getUpRoom(this) != null)
{ // change Rooms
if (y < 0) {
if (room.getUpRoom(this) != null) { // change Rooms
y = y + 384;
SetRoom(room.getUpRoom(this));
}
else // stop at top
{
y = 0;
}
}
}
public void MoveDown(boolean nudge)
{
public void moveDown(boolean nudge) {
int dist = 32;
if (nudge) dist = 2;
if (nudge) {
dist = 2;
}
y = y + dist;
if (y>383)
{
if (room.getDownRoom(this) != null)
{ // change Rooms
if (y > 383) {
if (room.getDownRoom(this) != null) { // change Rooms
y = y - 384;
SetRoom(room.getDownRoom(this));
}
else // stop at bottom
{
y = 384 - 32;
}
}
}
public void MoveLeft(boolean nudge)
{
public void moveLeft(boolean nudge) {
int dist = 28;
if (nudge) dist = 2;
if (nudge) {
dist = 2;
}
x = x - dist;
if (x<0)
{
if (room.getLeftRoom(this) != null)
{ // change Rooms
if (x < 0) {
if (room.getLeftRoom(this) != null) { // change Rooms
x = x + 560;
SetRoom(room.getLeftRoom(this));
}
else // stop at left
{
x = 0;
}
}
}
public void MoveRight(boolean nudge)
{
public void moveRight(boolean nudge) {
int dist = 28;
if (nudge) dist = 2;
if (nudge) {
dist = 2;
}
x = x + dist;
if (x>559)
{
if (room.getRightRoom(this) != null)
{ // change Rooms
if (x > 559) {
if (room.getRightRoom(this) != null) { // change Rooms
x = x - 560;
SetRoom(room.getRightRoom(this));
}
else // stop at right
{
x = 560 - 28;
}
}
}
}

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

View File

@ -1,42 +1,30 @@
package com.droidquest.avatars;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.items.Item;
public class Remote extends Item
{
public Remote()
{
// width=28; height=32;
width=4; height=20;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public class Remote extends Item implements Avatar {
public Remote() {
width = 4;
height = 20;
level.electricity = true;
GenerateIcons();
}
public void GenerateIcons()
{
// icons = new ImageIcon[2];
// icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
// icons[1]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Remote Image");
return;
}
@ -47,186 +35,130 @@ public void GenerateIcons()
g2.fillRect(2, 0, 2, 20);
g2.fillRect(0, 16, 4, 4);
currentIcon = icons[0].getImage();
// try
// {
// g = icons[0].getImage().getGraphics();
// }
// catch (NullPointerException e)
// {
// System.out.println("Could not get Graphics pointer to Remote Image[0]");
// return;
// }
// g2 = (Graphics2D) g;
// g2.setBackground(new Color(0,0,0,0));
// g2.clearRect(0,0,width,height);
// g2.setColor(Color.white);
// g2.fillRect(20,0,4,12);
// g2.fillRect(0,12,28,20);
// g2.setColor(Color.black);
// g2.fillRect(8,14,12,2);
// g2.fillRect(4,18,20,2);
// g2.fillRect(8,22,12,2);
// g2.fillRect(20,26,4,4);
// try
// {
// g = icons[1].getImage().getGraphics();
// }
// catch (NullPointerException e)
// {
// System.out.println("Could not get Graphics pointer to Remote Image[1]");
// return;
// }
// g2 = (Graphics2D) g;
// g2.setBackground(new Color(0,0,0,0));
// g2.clearRect(0,0,width,height);
// g2.setColor(new Color(255,128,0));
// g2.fillRect(20,0,4,12);
// g2.fillRect(0,12,28,20);
// g2.setColor(Color.black);
// g2.fillRect(8,14,12,2);
// g2.fillRect(4,18,20,2);
// g2.fillRect(8,22,12,2);
// g2.fillRect(20,26,4,4);
}
public void Animate()
{
if (carriedBy != null)
if (carriedBy.room != room)
public void Animate() {
if (carriedBy != null) {
if (carriedBy.room != room) {
room = carriedBy.room;
}
}
super.Animate();
// if (level.electricity)
// currentIcon = icons[1].getImage();
// else
// currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
// if (i.getClass().toString().endsWith("Robot"))
public boolean CanBePickedUp(Item i) {
return false;
// return true;
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_S)
{
if (level.solderingPen == null) return false;
public boolean KeyUp(KeyEvent e) {
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)
if (level.currentViewer == level.player) {
level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen;
}
if (e.getKeyCode() == e.VK_C)
{
else 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)
if (level.currentViewer == level.player) {
level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor;
}
if (e.getKeyCode() == e.VK_P)
{
if (level.paintbrush == null) return false;
else if (e.getKeyCode() == KeyEvent.VK_P) {
if (level.paintbrush == null) {
return false;
}
level.paintbrush.x = x;
level.paintbrush.y = y;
level.paintbrush.room = room;
room = null;
if (level.currentViewer == level.player)
if (level.currentViewer == level.player) {
level.currentViewer = level.paintbrush;
}
level.player = level.paintbrush;
}
if (e.getKeyCode() == e.VK_SLASH)
{
if (level.helpCam == null) return false;
if (level.player != level.helpCam)
{
else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
if (level.helpCam == null) {
return false;
}
if (level.player != level.helpCam) {
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
}
if (e.getKeyCode() == e.VK_RIGHT)
{
if (carriedBy==null)
MoveRight(e.isControlDown());
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
if (carriedBy == null) {
moveRight(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (carriedBy==null)
MoveLeft(e.isControlDown());
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
if (carriedBy == null) {
moveLeft(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == e.VK_UP)
{
if (carriedBy==null)
MoveUp(e.isControlDown());
else if (e.getKeyCode() == KeyEvent.VK_UP) {
if (carriedBy == null) {
moveUp(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (carriedBy==null)
MoveDown(e.isControlDown());
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (carriedBy == null) {
moveDown(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == e.VK_SPACE)
{
else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
level.electricity = !level.electricity;
}
return false;
}
public boolean KeyDown(KeyEvent e)
{
if (e.getKeyCode() == e.VK_RIGHT)
{
public boolean KeyDown(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
repeating++;
if (repeating>10)
{
MoveRight(e.isControlDown());
if (repeating > 10) {
moveRight(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_LEFT)
{
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
repeating++;
if (repeating>10)
{
MoveLeft(e.isControlDown());
if (repeating > 10) {
moveLeft(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_UP)
{
else if (e.getKeyCode() == KeyEvent.VK_UP) {
repeating++;
if (repeating>10)
{
MoveUp(e.isControlDown());
if (repeating > 10) {
moveUp(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_DOWN)
{
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
repeating++;
if (repeating>10)
{
MoveDown(e.isControlDown());
if (repeating > 10) {
moveDown(e.isControlDown());
return true;
}
return false;
@ -234,14 +166,11 @@ public boolean KeyDown(KeyEvent e)
return false;
}
public void MoveUp(boolean nudge)
{
public void moveUp(boolean nudge) {
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
if (item.UpEnterOverlap(this))
{
if (item != null) {
if (item.InternalRoom != null) {
if (item.UpEnterOverlap(this)) {
int newX = 280; // 10 * 28
int newY = 320; // 10 * 32
x = newX;
@ -249,17 +178,15 @@ public void MoveUp(boolean nudge)
SetRoom(item.InternalRoom);
}
}
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)
if (item.DownEnterOverlap(this))
{
if (item != null) {
if (item.InternalRoom != null) {
if (item.DownEnterOverlap(this)) {
int newX = 280; // 10 * 28
int newY = 0; // 0 * 32
x = newX;
@ -267,17 +194,15 @@ public void MoveDown(boolean nudge)
SetRoom(item.InternalRoom);
}
}
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)
if (item.LeftEnterOverlap(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;
@ -285,18 +210,15 @@ public void MoveLeft(boolean nudge)
SetRoom(item.InternalRoom);
}
}
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)
{
if (item.RightEnterOverlap(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;
@ -305,7 +227,66 @@ public void MoveRight(boolean nudge)
}
}
}
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;
}
}

View File

@ -1,29 +1,25 @@
package com.droidquest.avatars;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Device;
import com.droidquest.items.Item;
public class SolderingPen extends Device
{
boolean hot;
Port currentPort=null; // Port that Soldering pen is currently over
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public SolderingPen()
{
width=22; height=26;
public class SolderingPen extends Device implements Avatar {
private boolean hot;
private Port currentPort = null; // Port that Soldering pen is currently over
public SolderingPen() {
width = 22;
height = 26;
GenerateIcons();
currentIcon = icons[0].getImage();
ports = new Port[1];
@ -31,8 +27,7 @@ public SolderingPen()
}
public void GenerateIcons()
{
public void GenerateIcons() {
// Executed once during initialization
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -40,12 +35,10 @@ public void GenerateIcons()
icons[2] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to SolderingPen Image");
return;
}
@ -61,12 +54,10 @@ public void GenerateIcons()
g2.fillRect(6, 14, 6, 4);
g2.fillRect(0, 18, 12, 8);
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to SolderingPen Image");
return;
}
@ -83,12 +74,10 @@ public void GenerateIcons()
g2.setColor(new Color(255, 128, 0));
g2.fillRect(0, 18, 12, 8);
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to SolderingPen Image");
return;
}
@ -108,54 +97,55 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void CheckPort()
{
void CheckPort() {
hot = false;
currentPort = null;
// Item item = level.FindNearestItem(this);
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (!item.isDevice() || !Overlaps(item) || item==this)
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (!item.isDevice() || !Overlaps(item) || item == this) {
item = null;
if (item!=null)
{
}
if (item != null) {
Device device = (Device) item;
for (int b=0; b<device.ports.length; b++)
{
hot = true;
if (device.ports[b].x + device.x < x) hot = false;
if (device.ports[b].x + device.x > x+9) hot = false;
if (device.ports[b].y + device.y < y+18) hot = false;
if (device.ports[b].y + device.y > y+25) hot = false;
if (hot)
{
for (int b = 0; b < device.ports.length; b++) {
hot = device.ports[b].x + device.x >= x;
if (device.ports[b].x + device.x > x + 9) {
hot = false;
}
if (device.ports[b].y + device.y < y + 18) {
hot = false;
}
if (device.ports[b].y + device.y > y + 25) {
hot = false;
}
if (hot) {
currentPort = device.ports[b];
if (device.ports[b].myWire == null)
if (device.ports[b].myWire == null) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[2].getImage();
}
b = device.ports.length;
a = level.items.size();
}
else
else {
currentIcon = icons[0].getImage();
}
}
}
if (hot==false)
}
if (!hot) {
currentIcon = icons[0].getImage();
}
}
public void MoveUp(boolean nudge)
{
public void moveUp(boolean nudge) {
Room tempRoom = room;
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
if (item.UpEnterOverlap(this))
{
if (item != null) {
if (item.InternalRoom != null) {
if (item.UpEnterOverlap(this)) {
int newX = 280; // 10 * 28
int newY = 320; // 10 * 32
x = newX;
@ -163,22 +153,21 @@ public void MoveUp(boolean nudge)
SetRoom(item.InternalRoom);
}
}
super.MoveUp( nudge);
if (tempRoom != room && ports[0].myWire != null)
}
super.moveUp(nudge);
if (tempRoom != room && ports[0].myWire != null) {
ports[0].myWire.Remove();
}
// wiredPort=null;
CheckPort();
}
public void MoveDown(boolean nudge)
{
public void moveDown(boolean nudge) {
Room tempRoom = room;
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
if (item.DownEnterOverlap(this))
{
if (item != null) {
if (item.InternalRoom != null) {
if (item.DownEnterOverlap(this)) {
int newX = 280; // 10 * 28
int newY = 0; // 0 * 32
x = newX;
@ -186,22 +175,20 @@ public void MoveDown(boolean nudge)
SetRoom(item.InternalRoom);
}
}
super.MoveDown( nudge);
if (tempRoom != room && ports[0].myWire != null)
}
super.moveDown(nudge);
if (tempRoom != room && ports[0].myWire != null) {
ports[0].myWire.Remove();
// wiredPort=null;
}
CheckPort();
}
public void MoveLeft(boolean nudge)
{
public void moveLeft(boolean nudge) {
Room tempRoom = room;
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
if (item.LeftEnterOverlap(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;
@ -209,23 +196,20 @@ public void MoveLeft(boolean nudge)
SetRoom(item.InternalRoom);
}
}
super.MoveLeft( nudge);
if (tempRoom != room && ports[0].myWire != null)
}
super.moveLeft(nudge);
if (tempRoom != room && ports[0].myWire != null) {
ports[0].myWire.Remove();
// wiredPort=null;
}
CheckPort();
}
public void MoveRight(boolean nudge)
{
public void moveRight(boolean nudge) {
Room tempRoom = room;
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
{
if (item.RightEnterOverlap(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;
@ -234,29 +218,27 @@ public void MoveRight(boolean nudge)
}
}
}
super.MoveRight( nudge);
if (tempRoom != room && ports[0].myWire != null)
super.moveRight(nudge);
if (tempRoom != room && ports[0].myWire != null) {
ports[0].myWire.Remove();
// wiredPort=null;
}
CheckPort();
}
public void Animate()
{
public void Animate() {
Room tempRoom = room;
super.Animate();
if (tempRoom != room && ports[0].myWire != null)
if (tempRoom != room && ports[0].myWire != null) {
ports[0].myWire.Remove();
}
CheckPort();
}
public void Decorate()
{return;}
public void Decorate() {
}
public void WirePort()
{
if (hot)
{
void WirePort() {
if (hot) {
if (ports[0].myWire == null) // If SP is not wired
{
if (currentPort.myWire != null) // If currentPort is wired
@ -279,8 +261,9 @@ public void WirePort()
// Remove wire at currentPort
currentPort.myWire.Remove();
// Remove wire attached to Pen
if (ports[0].myWire != null)
if (ports[0].myWire != null) {
ports[0].myWire.Remove();
}
ports[0].value = false;
ports[0].type = Port.TYPE_UNDEFINED;
}
@ -300,124 +283,315 @@ public void WirePort()
}
}
public boolean Function ()
{
if (ports[0].myWire == null)
{
public boolean Function() {
if (ports[0].myWire == null) {
ports[0].value = false;
ports[0].type = Port.TYPE_UNDEFINED;
}
return false;
}
public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
public boolean CanBePickedUp(Item i) {
return !i.getClass().toString().endsWith("Robot");
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_C)
{
if (ports[0].myWire != null)
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_C && handleGameCursor()) {
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_SLASH && handleHelp()) {
return false;
}
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) {
WirePort();
}
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;
}
public boolean KeyDown(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
repeating++;
if (repeating > 10) {
moveRight(e.isControlDown());
return true;
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
repeating++;
if (repeating > 10) {
moveLeft(e.isControlDown());
return true;
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_UP) {
repeating++;
if (repeating > 10) {
moveUp(e.isControlDown());
return true;
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
repeating++;
if (repeating > 10) {
moveDown(e.isControlDown());
return true;
}
return false;
}
return false;
}
public void MouseClick(MouseEvent e) {
int button = 0;
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
button = 1;
}
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
button = 3;
}
if (button == 1) {
if (e.getClickCount() == 1) {
autoX = e.getX() - 2;
autoY = e.getY() - 20;
automove = 1;
}
else if (e.getClickCount() == 2) {
int dx = e.getX() - 2 - x;
int dy = e.getY() - 20 - y;
if (Math.abs(dx) > Math.abs(dy)) {
autoY = 0;
autoX = 28;
if (dx < 0) {
autoX = -28;
}
automove = 2;
}
else {
autoX = 0;
autoY = 32;
if (dy < 0) {
autoY = -32;
}
automove = 2;
}
}
}
if (button == 3) {
KeyEvent k = new KeyEvent(e.getComponent(), e.getID(),
e.getWhen(), 0,
KeyEvent.VK_SPACE, ' ');
KeyUp(k);
}
}
@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)
if (level.currentViewer == level.player) {
level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor;
if (level.remote != null)
if (level.remote.carriedBy != null)
{
if (level.remote != null) {
if (level.remote.carriedBy != null) {
level.remote.carriedBy = level.player;
}
}
if (e.getKeyCode() == e.VK_R)
{
if (level.remote == null) return false;
if (level.remote.carriedBy == null)
{ // Summon Remote
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
else { // Hide Remote
level.remote.carriedBy = null;
level.remote.room = null;
level.electricity = false;
level.roomdisplay.dq.setRadioSelected(false);
}
// if (ports[0].myWire != null)
// ports[0].myWire.Remove();
// 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;
return true;
}
if (e.getKeyCode() == e.VK_P)
{
if (level.paintbrush == null) return false;
if (ports[0].myWire != null)
@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)
if (level.currentViewer == level.player) {
level.currentViewer = level.paintbrush;
level.player = level.paintbrush;
}
if (e.getKeyCode() == e.VK_SLASH)
{
if (level.helpCam == null) return false;
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;
}
if (e.getKeyCode() == e.VK_RIGHT)
{
if (carriedBy==null)
MoveRight(e.isControlDown());
repeating=0;
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (carriedBy==null)
MoveLeft(e.isControlDown());
repeating=0;
@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;
}
if (e.getKeyCode() == e.VK_UP)
{
if (carriedBy==null)
MoveUp(e.isControlDown());
repeating=0;
}
}
}
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;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (carriedBy==null)
MoveDown(e.isControlDown());
repeating=0;
return true;
return false;
}
if (e.getKeyCode() == e.VK_SPACE)
{
WirePort();
}
if (e.getKeyCode() == e.VK_F)
{
if (hot)
{
@Override
public boolean handleFlipDevice() {
if (hot) {
if (ports[0].myWire != null) // If SP is wired
{
// Flip wire attached to SP
@ -428,16 +602,14 @@ public boolean KeyUp(KeyEvent e)
else if (ports[0].myWire == null) // If SP is not wired
{
// Flip wire attached to CurrentPort
if (currentPort.myWire != null)
{
if (currentPort.myWire != null) {
Port tempPort = currentPort.myWire.fromPort;
currentPort.myWire.fromPort = currentPort.myWire.toPort;
currentPort.myWire.toPort = tempPort;
}
}
}
else
{
else {
if (ports[0].myWire != null) // If SP is wired
{
// Flip wire attached to SP
@ -446,98 +618,6 @@ public boolean KeyUp(KeyEvent e)
ports[0].myWire.toPort = tempPort;
}
}
}
return false;
}
public boolean KeyDown(KeyEvent e)
{
if (e.getKeyCode() == e.VK_RIGHT)
{
repeating++;
if (repeating>10)
{
MoveRight(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_LEFT)
{
repeating++;
if (repeating>10)
{
MoveLeft(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_UP)
{
repeating++;
if (repeating>10)
{
MoveUp(e.isControlDown());
return true;
}
return false;
}
if (e.getKeyCode() == e.VK_DOWN)
{
repeating++;
if (repeating>10)
{
MoveDown(e.isControlDown());
return true;
}
return false;
}
return false;
}
public void MouseClick(MouseEvent e)
{
int button=0;
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK)
button = 1;
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
button = 3;
if (button==1)
{
if (e.getClickCount()==1)
{
autoX = e.getX() - 2;
autoY = e.getY() - 20;
automove = 1;
}
else if (e.getClickCount()==2)
{
int dx = e.getX() - 2 - x;
int dy = e.getY() - 20 - y;
if (Math.abs(dx) > Math.abs(dy))
{
autoY=0; autoX=28;
if (dx<0) autoX=-28;
automove=2;
}
else
{
autoX=0; autoY=32;
if (dy<0) autoY=-32;
automove=2;
}
}
}
if (button==3)
{
KeyEvent k = new KeyEvent(e.getComponent(), e.getID(),
e.getWhen(), 0,
KeyEvent.VK_SPACE, ' ');
KeyUp(k);
}
}
}

View File

@ -7,198 +7,181 @@ import com.droidquest.devices.PrototypeChip;
import com.droidquest.devices.SmallChip;
import com.droidquest.items.Item;
public class ChipCompiler extends Thread
{
public class ChipCompiler extends Thread {
public static int chipSpeed = 1;
public ChipCompiler(PrototypeChip pc, SmallChip sc)
{
public ChipCompiler(PrototypeChip pc, SmallChip sc) {
pc.grabbable = false;
sc.grabbable = false;
int a;
sc.Empty();
for (a=0; a<pc.InternalRoom.wires.size(); a++)
for (a = 0; a < pc.InternalRoom.wires.size(); a++) {
sc.signals.addElement(new Signal());
}
Signal dummy = new Signal();
dummy.working = false;
sc.signals.addElement(dummy);
for (a=0; a<8; a++)
{
for (a = 0; a < 8; a++) {
Wire wire = pc.portdevices[a].ports[0].myWire;
int index = pc.InternalRoom.wires.indexOf(wire);
if (index>=0)
{
Signal sig = (Signal) sc.signals.elementAt(index);
sc.portSignals[a].internalSignal= sig;
if (index >= 0) {
sc.portSignals[a].internalSignal = sc.signals.elementAt(index);
}
sc.ports[a].type = pc.ports[a].type;
sc.portSignals[a].type = pc.ports[a].type;
}
for (a=0; a<pc.level.items.size(); a++)
{
Item item = (Item) pc.level.items.elementAt(a);
if (item.room == pc.InternalRoom)
if (item.isDevice())
{
for (a = 0; a < pc.level.items.size(); a++) {
Item item = pc.level.items.elementAt(a);
if (item.room == pc.InternalRoom) {
if (item.isDevice()) {
Device device = (Device) item;
Gate gate = null;
String type = item.getClass().toString();
if (device instanceof com.droidquest.devices.ANDGate)
if (device instanceof com.droidquest.devices.ANDGate) {
gate = new Gate("AND");
if (device instanceof com.droidquest.devices.ORGate)
}
if (device instanceof com.droidquest.devices.ORGate) {
gate = new Gate("OR");
if (device instanceof com.droidquest.devices.NOTGate)
}
if (device instanceof com.droidquest.devices.NOTGate) {
gate = new Gate("NOT");
if (device instanceof com.droidquest.devices.XORGate)
}
if (device instanceof com.droidquest.devices.XORGate) {
gate = new Gate("XOR");
if (device instanceof com.droidquest.devices.FlipFlop)
{
}
if (device instanceof com.droidquest.devices.FlipFlop) {
gate = new Gate("FF");
gate.state = ((FlipFlop) device).state;
}
if (device instanceof com.droidquest.devices.Node)
if (device instanceof com.droidquest.devices.Node) {
gate = new Gate("NODE");
if (device instanceof com.droidquest.devices.SmallChip)
gate = new Gate((SmallChip)device);
if (gate != null)
{
sc.gates.addElement(gate);
for (int p=0; p<device.ports.length; p++)
{
if (device.ports[p].myWire != null)
{
int index = pc.InternalRoom.wires.indexOf(device.ports[p].myWire);
Signal sig = (Signal) sc.signals.elementAt(index);
gate.portSignals[p].externalSignal= sig;
// System.out.println("Signal "
// + index
// + " attached to "
// + gate.type
// + " Gate["
// + p
// + "]");
}
else
if (device instanceof com.droidquest.devices.SmallChip) {
gate = new Gate((SmallChip) device);
}
if (gate != null) {
sc.gates.addElement(gate);
for (int p = 0; p < device.ports.length; p++) {
if (device.ports[p].myWire != null) {
int index = pc.InternalRoom.wires.indexOf(device.ports[p].myWire);
gate.portSignals[p].externalSignal = sc.signals.elementAt(index);
}
else {
gate.portSignals[p].externalSignal = dummy;
}
}
}
}
}
}
// Remove Node Gates, and transfer Signals
for (a = 0; a < sc.gates.size(); a++) //For every Gate in the chip
{
Gate gate1 = (Gate) sc.gates.elementAt(a);
if (gate1.type == "NODE")
{
Gate gate1 = sc.gates.elementAt(a);
if (gate1.type.equals("NODE")) {
for (int ap = 1; ap < 4; ap++) // For every output Signal in the Node
{
Signal s1 = gate1.portSignals[ap].externalSignal;
if (s1!= null && s1!=dummy)
{
if (s1 != null && s1 != dummy) {
for (int b = 0; b < sc.gates.size(); b++) // For every other Gate in the Chip
{
Gate gate2 = (Gate) sc.gates.elementAt(b);
if (gate1 != gate2)
{
Gate gate2 = sc.gates.elementAt(b);
if (gate1 != gate2) {
for (int bp = 0; bp < 8; bp++) // For every Signal connection in that other gate
{
Signal s2 = gate2.portSignals[bp].externalSignal;
if (s1 == s2) // If Signal is an output Node signal
{
// System.out.println("Changing " + gate2.type
// + "[" + bp + "] = Signal "
// + sc.signals.indexOf(s2)
// + " to Signal "
// + sc.signals.indexOf(gate1.portSignals[0]));
gate2.portSignals[bp].externalSignal
= gate1.portSignals[0].externalSignal;
}
}
}
}
for (int ps=0; ps<8; ps++)
if (sc.portSignals[ps].internalSignal==s1)
for (int ps = 0; ps < 8; ps++) {
if (sc.portSignals[ps].internalSignal == s1) {
sc.portSignals[ps].internalSignal
= gate1.portSignals[0].externalSignal;
}
}
}
}
sc.gates.removeElement(gate1);
a--;
}
}
// Remove unused Signals
// System.out.println("Starting with " + sc.signals.size() + " signals");
// System.out.println("Starting with " + sc.gates.size() + " gates");
for (a=0; a<sc.signals.size(); a++)
{
for (a = 0; a < sc.signals.size(); a++) {
boolean used = false;
Signal sig1 = (Signal) sc.signals.elementAt(a);
for (int g = 0; g< sc.gates.size(); g++)
{
Gate gate = (Gate) sc.gates.elementAt(g);
for (int s = 0; s< 8; s++)
{
Signal sig1 = sc.signals.elementAt(a);
for (int g = 0; g < sc.gates.size(); g++) {
Gate gate = sc.gates.elementAt(g);
for (int s = 0; s < 8; s++) {
Signal sig2 = gate.portSignals[s].externalSignal;
if (sig2 != null)
// System.out.println(gate.type + "Gate["+s+"] connected to Signal "
// + sc.signals.indexOf(sig2));
if (sig1==sig2)
{
// System.out.println("Signal " + a + " is used by " + gate.type + "Gate ");
if (sig1 == sig2) {
used = true;
}
}
}
for (int ps = 0; ps<8; ps++)
if (sc.portSignals[ps].internalSignal==sig1)
}
for (int ps = 0; ps < 8; ps++) {
if (sc.portSignals[ps].internalSignal == sig1) {
used = true;
if (used == false)
{
// System.out.println("Removing unused Signal at " + a);
}
}
if (!used) {
sc.signals.removeElement(sig1);
a--;
}
}
// Set Signal types
for (a=0; a<8; a++)
if (sc.portSignals[a]!=null)
for (a = 0; a < 8; a++) {
if (sc.portSignals[a] != null) {
sc.portSignals[a].type = sc.ports[a].type;
}
}
// Debug report
System.out.println(sc.signals.size() + " Signals");
System.out.println(sc.gates.size() + " Gates");
for(a=0; a<sc.gates.size(); a++)
{
Gate gate1 = (Gate) sc.gates.elementAt(a);
gate1.DebugReport(1);
for (int b=0; b<8; b++)
if (gate1.portSignals[b].externalSignal!=null)
for (a = 0; a < sc.gates.size(); a++) {
Gate gate1 = sc.gates.elementAt(a);
for (int b = 0; b < 8; b++) {
if (gate1.portSignals[b].externalSignal != null) {
System.out.println(a + ": " + gate1.type
+ " gate["
+ b
+ "] = Signal "
+ sc.signals.indexOf(gate1.portSignals[b].externalSignal));
}
for (a=0; a<8; a++)
if (sc.portSignals[a].internalSignal != null)
}
}
for (a = 0; a < 8; a++) {
if (sc.portSignals[a].internalSignal != null) {
System.out.println("PortSignal "
+ a
+ " = Signal "
+ sc.signals.indexOf(sc.portSignals[a].internalSignal));
}
}
sc.speed = chipSpeed;
if (pc.label != null)
sc.label = new String(pc.label);
if (pc.description != null)
sc.description = new String(pc.description);
if (pc.label != null) {
sc.label = pc.label;
}
if (pc.description != null) {
sc.description = pc.description;
}
sc.GenerateIcons();
pc.grabbable = true;
sc.grabbable = true;

View File

@ -1,131 +1,115 @@
package com.droidquest.chipstuff;
import com.droidquest.devices.SmallChip;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;
import com.droidquest.devices.SmallChip;
public class Gate implements Serializable
{
public class Gate implements Serializable {
public transient PortSignal[] portSignals = new PortSignal[8];
public boolean state;
public String type;
public int speed;
public Vector mySignals = new Vector();
public Vector myGates = new Vector();
public Vector<Signal> mySignals = new Vector<Signal>();
public Vector<Gate> myGates = new Vector<Gate>();
public Gate(String t)
{
public Gate(String t) {
// Called whenever a non-chip gate is created.
type = t;
speed = 1;
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
public Gate(SmallChip sc)
{
public Gate(SmallChip sc) {
// Called by ChipCompiler to put a nested chip into a gate
speed = sc.speed;
type = "Chip";
Signal dummySignal;
portSignals = new PortSignal[8];
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
for (int a=0; a<sc.signals.size(); a++)
{
}
for (int a = 0; a < sc.signals.size(); a++) {
Signal newsig = new Signal();
Signal oldsig = (Signal) sc.signals.elementAt(a);
Signal oldsig = sc.signals.elementAt(a);
newsig.Set(oldsig.Get());
newsig.working = oldsig.working;
mySignals.addElement(newsig);
if (newsig.working == false)
dummySignal=newsig;
}
for (int a=0; a<sc.gates.size(); a++)
{
Gate oldgate = (Gate) sc.gates.elementAt(a);
for (int a = 0; a < sc.gates.size(); a++) {
Gate oldgate = sc.gates.elementAt(a);
Gate newgate = new Gate(oldgate);
myGates.addElement(newgate);
for (int b=0; b<8; b++)
if (oldgate.portSignals[b].externalSignal!=null)
{
for (int b = 0; b < 8; b++) {
if (oldgate.portSignals[b].externalSignal != null) {
int sigIndex = sc.signals.indexOf(oldgate.portSignals[b].externalSignal);
Signal sig = (Signal) mySignals.elementAt(sigIndex);
newgate.portSignals[b].externalSignal = sig;
newgate.portSignals[b].externalSignal = mySignals.elementAt(sigIndex);
}
}
}
for (int a=0; a<8; a++)
{
if (sc.portSignals[a].internalSignal!=null)
{
for (int a = 0; a < 8; a++) {
if (sc.portSignals[a].internalSignal != null) {
int sigIndex = sc.signals.indexOf(sc.portSignals[a].internalSignal);
Signal sig = (Signal) mySignals.elementAt(sigIndex);
portSignals[a].internalSignal = sig;
portSignals[a].internalSignal = mySignals.elementAt(sigIndex);
portSignals[a].type = sc.portSignals[a].type;
}
}
}
public Gate(Gate g)
{
public Gate(Gate g) {
// Create a new Gate based off an existing one
type = g.type;
state = g.state;
speed = g.speed;
portSignals = new PortSignal[8];
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
if (type.equalsIgnoreCase("Chip"))
{
for (int a=0; a<g.mySignals.size(); a++)
{
}
if (type.equalsIgnoreCase("Chip")) {
for (int a = 0; a < g.mySignals.size(); a++) {
Signal newsig = new Signal();
Signal oldsig = (Signal) g.mySignals.elementAt(a);
Signal oldsig = g.mySignals.elementAt(a);
newsig.Set(oldsig.Get());
newsig.working = oldsig.working;
mySignals.addElement(newsig);
}
for (int a=0; a<g.myGates.size(); a++)
{
Gate oldgate = (Gate) g.myGates.elementAt(a);
for (int a = 0; a < g.myGates.size(); a++) {
Gate oldgate = g.myGates.elementAt(a);
Gate newgate = new Gate(oldgate);
myGates.addElement(newgate);
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
int signalIndex = g.mySignals.indexOf(oldgate.portSignals[b].externalSignal);
if (signalIndex != -1)
newgate.portSignals[b].externalSignal = (Signal)mySignals.elementAt(signalIndex);
if (signalIndex != -1) {
newgate.portSignals[b].externalSignal = mySignals.elementAt(signalIndex);
}
}
for (int a=0; a<8; a++)
{
if (g.portSignals[a].internalSignal != null)
{
}
for (int a = 0; a < 8; a++) {
if (g.portSignals[a].internalSignal != null) {
int sigIndex = g.mySignals.indexOf(g.portSignals[a].internalSignal);
portSignals[a].internalSignal = (Signal) mySignals.elementAt(sigIndex);
portSignals[a].internalSignal = mySignals.elementAt(sigIndex);
portSignals[a].type = g.portSignals[a].type;
}
}
}
}
public void writeRef(ObjectOutputStream s) throws IOException
{
for (int a=0; a<8; a++)
public void writeRef(ObjectOutputStream s) throws IOException {
for (int a = 0; a < 8; a++) {
s.writeInt(mySignals.indexOf(portSignals[a].internalSignal));
for (int a=0; a<myGates.size(); a++)
{
Gate gate = (Gate) myGates.elementAt(a);
for (int b=0; b<8; b++)
{
}
for (int a = 0; a < myGates.size(); a++) {
Gate gate = myGates.elementAt(a);
for (int b = 0; b < 8; b++) {
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
@ -133,178 +117,151 @@ public void writeRef(ObjectOutputStream s) throws IOException
}
}
public void readRef(ObjectInputStream s) throws IOException
{
for (int a=0; a<8; a++)
{
public void readRef(ObjectInputStream s) throws IOException {
for (int a = 0; a < 8; a++) {
int portIndex = s.readInt();
if (portIndex>=0)
portSignals[a].internalSignal = (Signal) mySignals.elementAt(portIndex);
if (portIndex >= 0) {
portSignals[a].internalSignal = mySignals.elementAt(portIndex);
}
for (int a=0; a<myGates.size(); a++)
{
Gate gate = (Gate) myGates.elementAt(a);
}
for (int a = 0; a < myGates.size(); a++) {
Gate gate = myGates.elementAt(a);
gate.portSignals = new PortSignal[8];
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
gate.portSignals[b] = new PortSignal();
int sigIndex = s.readInt();
if (sigIndex>=0)
gate.portSignals[b].externalSignal = (Signal) mySignals.elementAt(sigIndex);
if (sigIndex >= 0) {
gate.portSignals[b].externalSignal = mySignals.elementAt(sigIndex);
}
gate.portSignals[b].type = s.readInt();
}
gate.readRef(s);
}
}
public void Function()
{
if (type.equalsIgnoreCase("AND"))
public void Function() {
if (type.equalsIgnoreCase("AND")) {
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
& portSignals[1].externalSignal.Get());
if (type.equalsIgnoreCase("OR"))
}
else if (type.equalsIgnoreCase("OR")) {
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
| portSignals[1].externalSignal.Get());
if (type.equalsIgnoreCase("NOT"))
}
else if (type.equalsIgnoreCase("NOT")) {
portSignals[1].externalSignal.Set(!portSignals[0].externalSignal.Get());
if (type.equalsIgnoreCase("XOR"))
}
else if (type.equalsIgnoreCase("XOR")) {
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
^ portSignals[1].externalSignal.Get());
if (type.equalsIgnoreCase("FF"))
{
if (portSignals[0].externalSignal.Get() ^ portSignals[1].externalSignal.Get())
}
else if (type.equalsIgnoreCase("FF")) {
if (portSignals[0].externalSignal.Get() ^ portSignals[1].externalSignal.Get()) {
state = portSignals[0].externalSignal.Get();
}
portSignals[2].externalSignal.Set(state);
portSignals[3].externalSignal.Set(!state);
}
if (type.equalsIgnoreCase("NODE"))
{
else if (type.equalsIgnoreCase("NODE")) {
portSignals[1].externalSignal.Set(portSignals[0].externalSignal.Get());
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get());
if (portSignals[3].externalSignal!=null)
if (portSignals[3].externalSignal != null) {
portSignals[3].externalSignal.Set(portSignals[0].externalSignal.Get());
}
if (type.equalsIgnoreCase("Chip"))
{
}
else if (type.equalsIgnoreCase("Chip")) {
for (int s=0; s<speed; s++)
{
for (int a=0; a<mySignals.size(); a++)
((Signal) mySignals.elementAt(a)).Flip();
for (int s = 0; s < speed; s++) {
for (int a = 0; a < mySignals.size(); a++) {
mySignals.elementAt(a).Flip();
}
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
if (portSignals[a].externalSignal != null
&& portSignals[a].internalSignal!=null)
if (portSignals[a].type==Port.TYPE_INPUT)
&& portSignals[a].internalSignal != null) {
if (portSignals[a].type == Port.TYPE_INPUT) {
portSignals[a].internalSignal.Set(portSignals[a].externalSignal.Get());
}
}
}
for (int a=0; a<myGates.size(); a++)
((Gate) myGates.elementAt(a)).Function();
for (int a = 0; a < myGates.size(); a++) {
myGates.elementAt(a).Function();
}
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
if (portSignals[a].externalSignal != null
&& portSignals[a].internalSignal!=null)
if (portSignals[a].type==Port.TYPE_OUTPUT)
&& portSignals[a].internalSignal != null) {
if (portSignals[a].type == Port.TYPE_OUTPUT) {
portSignals[a].externalSignal.Set(portSignals[a].internalSignal.Get());
}
}
}
}
}
}
public void SaveSubGate(ObjectOutputStream s) throws IOException
{
public void SaveSubGate(ObjectOutputStream s) throws IOException {
s.writeInt(mySignals.size());
for (int a=0; a<mySignals.size(); a++)
{
Signal sig = (Signal)mySignals.elementAt(a);
for (int a = 0; a < mySignals.size(); a++) {
Signal sig = mySignals.elementAt(a);
s.writeBoolean(sig.Get());
s.writeBoolean(sig.working);
}
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
s.writeInt(mySignals.indexOf(portSignals[a].internalSignal));
s.writeInt(portSignals[a].type);
}
s.writeInt(myGates.size());
for (int a=0; a<myGates.size(); a++)
{
Gate gate = (Gate) myGates.elementAt(a);
for (int a = 0; a < myGates.size(); a++) {
Gate gate = myGates.elementAt(a);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
for (int b=0; b<8; b++)
for (int b = 0; b < 8; b++) {
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
if (gate.type.equalsIgnoreCase("Chip"))
}
if (gate.type.equalsIgnoreCase("Chip")) {
gate.SaveSubGate(s);
}
}
s.writeInt(speed);
}
public void LoadSubGate(ObjectInputStream s) throws IOException, ClassNotFoundException
{
public void LoadSubGate(ObjectInputStream s) throws IOException, ClassNotFoundException {
int numSignals = s.readInt();
mySignals = new Vector();
for (int a=0; a<numSignals; a++)
{
mySignals = new Vector<Signal>();
for (int a = 0; a < numSignals; a++) {
Signal newSignal = new Signal();
newSignal.Set(s.readBoolean());
newSignal.working = s.readBoolean();
mySignals.addElement(newSignal);
}
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
int sigIndex = s.readInt();
if (sigIndex>=0)
portSignals[a].internalSignal = (Signal) mySignals.elementAt(sigIndex);
if (sigIndex >= 0) {
portSignals[a].internalSignal = mySignals.elementAt(sigIndex);
}
portSignals[a].type = s.readInt();
}
int numGates = s.readInt();
for (int a=0; a<numGates; a++)
{
for (int a = 0; a < numGates; a++) {
Gate newGate = new Gate((String) s.readObject());
newGate.state = s.readBoolean();
myGates.addElement(newGate);
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
int sigIndex = s.readInt();
if (sigIndex>=0)
newGate.portSignals[b].externalSignal = (Signal) mySignals.elementAt(sigIndex);
if (sigIndex >= 0) {
newGate.portSignals[b].externalSignal = mySignals.elementAt(sigIndex);
}
if (newGate.type.equalsIgnoreCase("Chip"))
}
if (newGate.type.equalsIgnoreCase("Chip")) {
newGate.LoadSubGate(s);
}
}
speed = s.readInt();
}
public void DebugReport(int indent)
{
// String ind = "";
// for (int a=0; a<indent; a++)
// ind += " ";
// System.out.println(ind + type + "Gate");
// System.out.println(ind + mySignals.size() + " Signals");
// System.out.println(ind + myGates.size() + " Gates");
// for(int a=0; a<myGates.size(); a++)
// {
// Gate gate1 = (Gate) myGates.elementAt(a);
// gate1.DebugReport(indent+1);
// for (int b=0; b<8; b++)
// if (gate1.myPortSignals[b]!=null)
// System.out.println(ind + a + ": " + gate1.type
// + " gate["
// + b
// + "] = Signal "
// + mySignals.indexOf(gate1.myPortSignals[b]));
// }
// for (int a=0; a<8; a++)
// if (portSignals[a] != null)
// System.out.println(ind + "PortSignal "
// + a
// + " = Signal "
// + mySignals.indexOf(portSignals[a]));
}
}

View File

@ -12,8 +12,7 @@ import com.droidquest.devices.Device;
import com.droidquest.items.Item;
import com.droidquest.levels.Level;
public class Port implements Serializable
{
public class Port implements Serializable {
// Input or Output of a Device
public int type; // 0=Input, 1=Output, 2=Undefined
@ -21,7 +20,7 @@ public class Port implements Serializable
public static final int TYPE_OUTPUT = 1;
public static final int TYPE_UNDEFINED = 2;
private int size; // Short or Long port 0=Short, 1=Long
boolean standard; // Shows Graphics?
private boolean standard; // Shows Graphics?
public int rotation; //0=Up, 1=Left, 2=Down, 3=Right;
public static final int ROT_UP = 0;
public static final int ROT_RIGHT = 1;
@ -31,15 +30,16 @@ public class Port implements Serializable
public boolean value; // True or False, what else?
public int x, y;
public int width, height; // width & height
public int wireX, wireY;
private int wireX;
private int wireY;
public transient Item myDevice;
public transient Wire myWire;
public boolean locked; // False = Reverts to Undefined with no connections
private boolean locked; // False = Reverts to Undefined with no connections
public Port() {}
public Port() {
}
public Port(int X, int Y, int Type, int Size, int rot, Device d)
{
public Port(int X, int Y, int Type, int Size, int rot, Device d) {
// There are realy only two types of Ports: Standard and Chip. A
// Standard Port is what appears on all Gates, Robot Devices, and
// the Prototype Chip. 20 images are defined for these conditions:
@ -47,61 +47,60 @@ public class Port implements Serializable
// always Off. If the type is not Standard, it's a chip port, and
// uses no graphics.
x=X; y=Y;
x = X;
y = Y;
type = Type;
size = Size;
rotation = rot;
standard = (size > 0);
myDevice = d;
if (standard)
{
width = 12; height=size;
wireX = x + 6; wireY = y + height - 6;
if (standard) {
width = 12;
height = size;
wireX = x + 6;
wireY = y + height - 6;
}
else
{
width = 2; height = 2;
wireX = x; wireY = y;
else {
width = 2;
height = 2;
wireX = x;
wireY = y;
}
if (type==TYPE_UNDEFINED)
locked=false;
else
locked=true;
locked = type != TYPE_UNDEFINED;
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
Level level = myDevice.level;
s.writeInt(level.items.indexOf(myDevice));
if (myDevice.room != null)
if (myDevice.room != null) {
s.writeInt(myDevice.room.wires.indexOf(myWire));
}
public void readRef(ObjectInputStream s, Level level) throws IOException
{
myDevice = (Item) level.FindItem(s.readInt());
if (myDevice != null)
if (myDevice.room != null)
myWire = myDevice.room.FindWire(s.readInt());
}
public void Draw(Graphics g, int rot)
{
if (value)
public void readRef(ObjectInputStream s, Level level) throws IOException {
myDevice = level.FindItem(s.readInt());
if (myDevice != null) {
if (myDevice.room != null) {
myWire = myDevice.room.FindWire(s.readInt());
}
}
}
public void Draw(Graphics g, int rot) {
if (value) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(Color.white);
}
int relRot = (rotation + rot) % 4;
if (standard)
{
switch (type)
{
if (standard) {
switch (type) {
case TYPE_INPUT:
switch(relRot)
{
switch (relRot) {
case 0: // Up
g.fillRect(x + 0, y + 4, 4, size);
g.fillRect(x - 4, y + 0, 4, 4);
@ -129,8 +128,7 @@ public class Port implements Serializable
}
break;
case TYPE_OUTPUT:
switch(relRot)
{
switch (relRot) {
case 0: // Up
g.fillRect(x + 0, y + 0, 4, size);
g.fillRect(x - 4, y + 2, 12, 2);
@ -158,8 +156,7 @@ public class Port implements Serializable
}
break;
case TYPE_UNDEFINED:
switch(relRot)
{
switch (relRot) {
case 0: // Up
g.fillRect(x - 2, y - 4, 8, 12);
g.fillRect(x, y + 8, 4, size);

View File

@ -1,12 +1,12 @@
package com.droidquest.chipstuff;
public class PortSignal
{
public class PortSignal {
public Signal externalSignal;
public Signal internalSignal;
public int type;
public PortSignal() {}
public PortSignal() {
}
}

View File

@ -2,26 +2,25 @@ package com.droidquest.chipstuff;
import java.io.Serializable;
public class Signal implements Serializable
{
public class Signal implements Serializable {
transient private int index;
private boolean[] value = new boolean[2];
public boolean working;
public Signal()
{
public Signal() {
index = 0;
working = true;
}
public void Flip()
{
public void Flip() {
index = 1 - index;
}
public boolean Get()
{
public boolean Get() {
return value[index] && working;
}
public void Set(boolean v)
{
public void Set(boolean v) {
value[1 - index] = v && working;
}
}

View File

@ -4,33 +4,31 @@ import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
public class Arrow implements Serializable
{
public class Arrow implements Serializable {
public static int DIR_UP = 0;
public static int DIR_RIGHT = 1;
public static int DIR_DOWN = 2;
public static int DIR_LEFT = 3;
public int direction;
public int length;
public int x;
private int length;
private int x;
public int y;
public Color color;
private Color color;
public Arrow() {}
public Arrow() {
}
public Arrow(int X, int Y, int dir, int len, Color c)
{
x=X; y=Y;
public Arrow(int X, int Y, int dir, int len, Color c) {
x = X;
y = Y;
direction = dir;
length = len;
color = c;
}
public void Draw(Graphics g)
{
public void Draw(Graphics g) {
g.setColor(color);
switch(direction)
{
switch (direction) {
case 0:
g.drawLine(x, y, x - 8, y + 8);
g.drawLine(x, y, x + 8, y + 8);

View File

@ -7,126 +7,128 @@ import javax.swing.ImageIcon;
import com.droidquest.RoomDisplay;
public class Graphix implements Serializable
{
public class Graphix implements Serializable {
public String[] filenames;
transient protected ImageIcon[] icons; // Array of images for this item
transient ImageIcon icon;
int animationState;
private transient ImageIcon[] icons; // Array of images for this item
private transient ImageIcon icon;
private int animationState;
public int x; // Current position
int y;
int behavior; // Overall behavior (SIT, CYCLE, BOUNCE)
int current=1; // Current behavior; 1=move forward, -1=move backward
int dx, dy; // Direction of "forward"
private int y;
private int behavior; // Overall behavior (SIT, CYCLE, BOUNCE)
private int current = 1; // Current behavior; 1=move forward, -1=move backward
private int dx;
private int dy; // Direction of "forward"
public int count;
int length; // Number of times the Graphix moves forward
public static int SIT=0;
private int length; // Number of times the Graphix moves forward
private static int SIT = 0;
public static int CYCLE = 1;
public static int BOUNCE = 2;
public Graphix() {}
public Graphix() {
}
public Graphix(int X, int Y)
{
x=X; y=Y;
public Graphix(int X, int Y) {
x = X;
y = Y;
GenerateIcons();
}
public Graphix(String file, int X, int Y)
{
public Graphix(String file, int X, int Y) {
filenames = new String[1];
filenames[0] = new String(file);
filenames[0] = file;
behavior = SIT;
x=X; y=Y;
x = X;
y = Y;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y)
{
x=X; y=Y;
public Graphix(String[] files, int X, int Y) {
x = X;
y = Y;
filenames = files;
behavior = SIT;
GenerateIcons();
}
public Graphix(String file, int X, int Y, int b, int DX, int DY, int L)
{
public Graphix(String file, int X, int Y, int b, int DX, int DY, int L) {
filenames = new String[1];
filenames[0] = new String(file);
x=X; y=Y;
filenames[0] = file;
x = X;
y = Y;
behavior = b;
dx=DX; dy=DY;
dx = DX;
dy = DY;
length = L;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y, int b, int DX, int DY, int L)
{
public Graphix(String[] files, int X, int Y, int b, int DX, int DY, int L) {
filenames = files;
x=X; y=Y;
x = X;
y = Y;
behavior = b;
dx=DX; dy=DY;
dx = DX;
dy = DY;
length = L;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
int numfiles = filenames.length;
icons = new ImageIcon[numfiles];
for (int a=0; a< numfiles; a++)
for (int a = 0; a < numfiles; a++) {
icons[a] = new ImageIcon("images/" + filenames[a]);
}
icon = icons[0];
}
public void Draw(Graphics g, RoomDisplay rd)
{
if (icon != null)
public void Draw(Graphics g, RoomDisplay rd) {
if (icon != null) {
g.drawImage(icon.getImage(), x, y, rd);
}
}
public void Animate()
{
public void Animate() {
int numfiles = filenames.length;
animationState++;
if (animationState==numfiles)
if (animationState == numfiles) {
animationState = 0;
}
icon = icons[animationState];
if (behavior==CYCLE)
{
if (count==length)
{
if (behavior == CYCLE) {
if (count == length) {
x -= dx * length;
y -= dy * length;
count = 0;
}
else
{
x+=dx; y+=dy;
else {
x += dx;
y += dy;
count++;
}
}
if (behavior==BOUNCE)
if (current==1)
{
if (count==length)
if (behavior == BOUNCE) {
if (current == 1) {
if (count == length) {
current = -1;
else
{
x+=dx; y+=dy;
}
else {
x += dx;
y += dy;
count++;
}
}
else
{
if (count==0)
else {
if (count == 0) {
current = 1;
else
{
x-=dx; y-=dy;
}
else {
x -= dx;
y -= dy;
count--;
}
}
}
}
}

View File

@ -6,38 +6,42 @@ import java.io.Serializable;
import com.droidquest.Room;
public class Spark implements Serializable
{
public class Spark implements Serializable {
public int x, y;
public int dx,dy;
private int dx;
private int dy;
public int age;
public Room room;
public Spark() {}
public Spark(int X, int Y, int Dx, int Dy, Room r)
{
x=X; y=Y;
dx = Dx; dy= Dy;
public Spark(int X, int Y, int Dx, int Dy, Room r) {
x = X;
y = Y;
dx = Dx;
dy = Dy;
room = r;
age = 0;
}
public void Age()
{
x += dx; y+= dy;
if (x<0 || x>560 || y<0 || y>384) room=null;
public void Age() {
x += dx;
y += dy;
if (x < 0 || x > 560 || y < 0 || y > 384) {
room = null;
}
age++;
}
public void Draw(Graphics g)
{
if (age<2)
public void Draw(Graphics g) {
if (age < 2) {
g.setColor(Color.white);
else if (age>=2 && age<4)
}
else if (age >= 2 && age < 4) {
g.setColor(Color.yellow);
else
}
else {
g.setColor(Color.red);
}
g.fillRect(x, y, 2, 2);
}

View File

@ -2,25 +2,26 @@ package com.droidquest.decorations;
import java.io.Serializable;
public class TextBox implements Serializable
{
public class TextBox implements Serializable {
public String textString;
public int x; // Position
public int y;
public int width; // Size
public TextBox() {}
public TextBox(String t, int X, int Y, int W)
{
textString = t;
x=X; y=Y; width=W;
public TextBox() {
}
public TextBox(String t, int X, int Y)
{
public TextBox(String t, int X, int Y, int W) {
textString = t;
x=X; y=Y;
x = X;
y = Y;
width = W;
}
public TextBox(String t, int X, int Y) {
textString = t;
x = X;
y = Y;
width = 500;
}

View File

@ -1,96 +1,90 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.ToolBox;
public class ANDGate extends Device
{
transient ImageIcon images[];
public class ANDGate extends Device {
private transient ImageIcon[] images;
public ANDGate(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=28; height=50;
public ANDGate(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 50;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (ports[0].value && ports[1].value)
if (ports[0].value && ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[3];
ports[0] = new Port(7, 47, Port.TYPE_INPUT, 12, Port.ROT_DOWN, this);
ports[1] = new Port(23, 43, Port.TYPE_INPUT, 8, Port.ROT_DOWN, this);
ports[2] = new Port(12, 2, Port.TYPE_OUTPUT, 16, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w;
int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -98,12 +92,13 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
if (v == 0) {
g.setColor(Color.white);
else
}
else {
g.setColor(new Color(255, 128, 0));
switch(r)
{
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 12, 2);
g.fillRect(8, 16, 4, 4);
@ -146,30 +141,39 @@ public void GenerateIcons()
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[2].value = ports[0].value & ports[1].value;
return false;
}
public void flip()
{
public void flip() {
Wire wire1 = ports[0].myWire;
Wire wire2 = ports[1].myWire;
if (wire1 != null)
{
if (wire1.fromPort == ports[0]) wire1.fromPort = ports[1];
if (wire1.toPort == ports[0]) wire1.toPort = ports[1];
if (wire1.inPort == ports[0]) wire1.inPort = ports[1];
if (wire1 != null) {
if (wire1.fromPort == ports[0]) {
wire1.fromPort = ports[1];
}
if (wire1.toPort == ports[0]) {
wire1.toPort = ports[1];
}
if (wire1.inPort == ports[0]) {
wire1.inPort = ports[1];
}
}
if (wire2 != null) {
if (wire2.fromPort == ports[1]) {
wire2.fromPort = ports[0];
}
if (wire2.toPort == ports[1]) {
wire2.toPort = ports[0];
}
if (wire2.inPort == ports[1]) {
wire2.inPort = ports[0];
}
if (wire2 != null)
{
if (wire2.fromPort == ports[1]) wire2.fromPort = ports[0];
if (wire2.toPort == ports[1]) wire2.toPort = ports[0];
if (wire2.inPort == ports[1]) wire2.inPort = ports[0];
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;

View File

@ -1,79 +1,76 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Dimension;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Spark;
import com.droidquest.items.GenericRobot;
import com.droidquest.levels.Level;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.items.GenericRobot;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Spark;
import com.droidquest.items.Item;
public class Antenna extends Device
{
public class Antenna extends Device {
public static int radio = 0; // One frequency that all Antennas use (robots)
public static int radio2 = 0; // Second frequency transmitted outside of robots.
private static int radio2 = 0; // Second frequency transmitted outside of robots.
private boolean oldRadio = false; // Was this radio transmitting last phase?
Color color;
transient GenericRobot robot;
private Color color;
private transient GenericRobot robot;
public Antenna(int X, int Y, Room r, Color col)
{
x=X; y=Y; color= col;
width=44; height=52;
public Antenna(int X, int Y, Room r, Color col) {
x = X;
y = Y;
color = col;
width = 44;
height = 52;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void GenerateIcons()
{
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
radio = 0;
radio2 = 0;
if (ports==null)
{
if (ports == null) {
ports = new Port[2];
ports[0] = new Port(39, 45, Port.TYPE_INPUT, 18, Port.ROT_DOWN, this);
ports[1] = new Port(11, 50, Port.TYPE_OUTPUT, 26, Port.ROT_DOWN, this);
}
else
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
else {
for (Port port : ports) {
port.myDevice = this;
}
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
}
public void Animate()
{
public void Animate() {
super.Animate();
if (robot==null)
if (ports[0].value && level.electricity)
{
if (robot == null) {
if (ports[0].value && level.electricity) {
Dimension d = GetXY();
level.sparks.addElement(new Spark(d.width + 26, d.height + 4,
level.random.nextInt(9) - 4,
@ -81,111 +78,103 @@ public void Animate()
room));
}
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
try
{
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
if (robot!=null)
{
if (robot != null) {
g.setColor(color);
g.fillRect(18, 0, 14, 6);
g.fillRect(22, 6, 6, 16);
g.fillRect(8, 22, 32, 2);
}
else
{
if (radio2>0)
else {
if (radio2 > 0) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(color);
}
g.fillRect(18, 0, 14, 6);
g.fillRect(22, 6, 6, 16);
g.fillRect(8, 22, 32, 2);
if (ports[0].value && level.electricity)
level.PlaySound(room, level.BEEPSOUND);
if (ports[0].value && level.electricity) {
level.PlaySound(room, Level.BEEPSOUND);
}
}
}
public boolean Function()
{
if (robot!=null)
{
if (radio<0)
public boolean Function() {
if (robot != null) {
if (radio < 0) {
radio = 0;
}
if (radio>0)
{
if (radio > 0) {
robot.antenna = true;
ports[1].value = true;
}
else
{
else {
robot.antenna = false;
ports[1].value = false;
}
if (oldRadio != ports[0].value)
{
if (ports[0].value == true)
{
if (oldRadio != ports[0].value) {
if (ports[0].value) {
robot.broadcasting = true;
radio++;
}
else
{
else {
robot.broadcasting = false;
radio--;
}
}
oldRadio = ports[0].value;
}
else
{
if (radio2<0)
else {
if (radio2 < 0) {
radio2 = 0;
}
if (radio2>0)
ports[1].value = true;
else
ports[1].value = false;
if (oldRadio != ports[0].value)
{
if (ports[0].value == true)
ports[1].value = radio2 > 0;
if (oldRadio != ports[0].value) {
if (ports[0].value) {
radio2++;
else
}
else {
radio2--;
}
}
oldRadio = ports[0].value;
}
return false;
}
public void SetRoom(Room r)
{
if (oldRadio)
{
if (robot!=null)
public void SetRoom(Room r) {
if (oldRadio) {
if (robot != null) {
radio--;
else
}
else {
radio2--;
}
}
super.SetRoom(r);
robot = null;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
}
public void Erase()
{
public void Erase() {
super.Erase();
robot = null;
}

View File

@ -1,124 +1,123 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Dimension;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.GenericRobot;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
public class Bumper extends Device {
private int rotation;
private Color color;
private transient GenericRobot robot;
import com.droidquest.items.GenericRobot;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
public class Bumper extends Device
{
int rotation;
Color color;
transient GenericRobot robot;
public Bumper(int X, int Y , Room r, int direction, Color col)
{
x=X; y=Y;
public Bumper(int X, int Y, Room r, int direction, Color col) {
x = X;
y = Y;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot));
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void GenerateIcons()
{
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
if (ports==null)
{
if (ports == null) {
ports = new Port[1];
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP:
width=30; height=42;
width = 30;
height = 42;
ports[0] = new Port(16, 39, Port.TYPE_OUTPUT, 26, Port.ROT_DOWN, this);
break;
case Port.ROT_RIGHT:
width=54; height=24;
width = 54;
height = 24;
ports[0] = new Port(0, 13, Port.TYPE_OUTPUT, 42, Port.ROT_LEFT, this);
break;
case Port.ROT_DOWN:
width=30; height=38;
width = 30;
height = 38;
ports[0] = new Port(13, 2, Port.TYPE_OUTPUT, 22, Port.ROT_UP, this);
break;
case Port.ROT_LEFT:
width=54; height=24;
width = 54;
height = 24;
ports[0] = new Port(52, 10, Port.TYPE_OUTPUT, 40, Port.ROT_RIGHT, this);
break;
}
}
else
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
else {
for (Port port : ports) {
port.myDevice = this;
}
}
icons = new ImageIcon[1];
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP:
width=30; height=42;
width = 30;
height = 42;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_RIGHT:
width=54; height=24;
width = 54;
height = 24;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_DOWN:
width=30; height=38;
width = 30;
height = 38;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_LEFT:
width=54; height=24;
width = 54;
height = 24;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
currentIcon = icons[0].getImage();
try
{
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(8, 0, 14, 4);
g.fillRect(4, 2, 6, 4);
@ -160,8 +159,7 @@ public void Decorate()
}
}
public boolean Function()
{
public boolean Function() {
// Check the walls on the sides of the GenericRobot and set the
// Port outputs and the bumper variables
@ -169,18 +167,18 @@ public boolean Function()
int X = d.width;
int Y = d.height;
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP: // Top Bumper
{
int bigXl = (X + 14) / 28;
int bigXr = (X + 41) / 28;
int bigY = (Y - 3) / 32;
boolean collide = false;
for (int a=bigXl; a<=bigXr; a++)
// if (a>=0 && a<19 && bigY>=0 && bigY<12)
if (robot.level.materialAt(a,bigY,robot.room).Detectable(robot))
for (int a = bigXl; a <= bigXr; a++) {
if (robot.level.materialAt(a, bigY, robot.room).Detectable(robot)) {
collide = true;
}
}
ports[0].value = collide;
robot.topBumper = collide;
}
@ -191,10 +189,11 @@ public boolean Function()
int bigYt = (Y + 5) / 32;
int bigYb = (Y + 36) / 32;
boolean collide = false;
for (int a=bigYt; a<=bigYb; a++)
// if (a>=0 && a<12 && bigX>=0 && bigX<20)
if (robot.level.materialAt(bigX,a,robot.room).Detectable(robot))
for (int a = bigYt; a <= bigYb; a++) {
if (robot.level.materialAt(bigX, a, robot.room).Detectable(robot)) {
collide = true;
}
}
ports[0].value = collide;
robot.rightBumper = collide;
}
@ -205,10 +204,11 @@ public boolean Function()
int bigXr = (X + 41) / 28;
int bigY = (Y + 44) / 32;
boolean collide = false;
for (int a=bigXl; a<=bigXr; a++)
// if (a>=0 && a<19 && bigY>=0 && bigY<12)
if (robot.level.materialAt(a,bigY,robot.room).Detectable(robot))
for (int a = bigXl; a <= bigXr; a++) {
if (robot.level.materialAt(a, bigY, robot.room).Detectable(robot)) {
collide = true;
}
}
ports[0].value = collide;
robot.bottomBumper = collide;
}
@ -219,10 +219,11 @@ public boolean Function()
int bigYt = (Y + 5) / 32;
int bigYb = (Y + 36) / 32;
boolean collide = false;
for (int a=bigYt; a<=bigYb; a++)
// if (a>=0 && a<12 && bigX>=0 && bigX<20)
if (robot.level.materialAt(bigX,a,robot.room).Detectable(robot))
for (int a = bigYt; a <= bigYb; a++) {
if (robot.level.materialAt(bigX, a, robot.room).Detectable(robot)) {
collide = true;
}
}
ports[0].value = collide;
robot.leftBumper = collide;
}
@ -232,8 +233,7 @@ public boolean Function()
return false;
}
public void Erase()
{
public void Erase() {
super.Erase();
robot = null;
}

View File

@ -1,28 +1,16 @@
package com.droidquest.devices;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ChipText extends JDialog {
private JTextArea textarea;
private JTextField textfield;
private GenericChip myChip;
public class ChipText extends JDialog
{
JTextArea textarea;
JTextField textfield;
GenericChip myChip;
public ChipText(GenericChip gc)
{
public ChipText(GenericChip gc) {
myChip = gc;
setModal(false);
Container contentPane = getContentPane();
@ -34,24 +22,24 @@ public ChipText(GenericChip gc)
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
JScrollPane scrollpane = new JScrollPane(textarea);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollpane.setPreferredSize(new Dimension(250,250));
JScrollPane scrollPane = new JScrollPane(textarea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(250, 250));
JPanel buttonpanel = new JPanel();
buttonpanel.setLayout(new FlowLayout());
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
JButton saveButton = new JButton("Save");
JButton restoreButton = new JButton("Restore");
textfield = new JTextField(3);
buttonpanel.add(saveButton);
buttonpanel.add(restoreButton);
buttonpanel.add(textfield);
buttonPanel.add(saveButton);
buttonPanel.add(restoreButton);
buttonPanel.add(textfield);
contentPane.add(buttonpanel, BorderLayout.NORTH);
contentPane.add(scrollpane, BorderLayout.CENTER);
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
saveButton.addMouseListener(new MouseAdapter() {
@ -71,13 +59,11 @@ public ChipText(GenericChip gc)
}
public void setEditable(boolean editable)
{
public void setEditable(boolean editable) {
textarea.setEditable(editable);
}
public void setText(String text, String label)
{
public void setText(String text, String label) {
textarea.setText(text);
textfield.setText(label);
}

View File

@ -9,16 +9,16 @@ import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
public class ContactSensor extends Device
{
String targetClass;
Item target;
Dimension d1 = new Dimension(); // Output pointing Right, Left
Dimension d2 = new Dimension(); // Output pointing Up, Down
public class ContactSensor extends Device {
private String targetClass;
private Item target;
private Dimension d1 = new Dimension(); // Output pointing Right, Left
private Dimension d2 = new Dimension(); // Output pointing Up, Down
public ContactSensor(int X, int Y, Room r, Item item)
{
x=X; y=Y; room = r;
public ContactSensor(int X, int Y, Room r, Item item) {
x = X;
y = Y;
room = r;
target = item;
editable = true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
@ -32,26 +32,23 @@ public ContactSensor(int X, int Y, Room r, Item item)
GenerateIcons();
}
public void GenerateIcons()
{
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[1];
ports[0] = new Port(width - 2, height / 2 - 2, Port.TYPE_OUTPUT, 24, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(d2.width, d2.height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(d1.width, d1.height, BufferedImage.TYPE_4BYTE_ABGR));
@ -59,50 +56,46 @@ public void GenerateIcons()
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[0].value = false;
if (room.portalItem == null)
{
if (room.portalItem == null) {
// Contact Sensor is not inside robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room == room)
// if (item.getClass().toString().endsWith(targetClass))
if (target.getClass().isInstance(item))
if (item.carriedBy == null)
if (Overlaps(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room) {
if (target.getClass().isInstance(item)) {
if (item.carriedBy == null) {
if (Overlaps(item)) {
ports[0].value = true;
a = level.items.size();
}
}
}
else
{
}
}
}
else {
// Contact Sensor is inside Robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room == room.portalItem.room)
if (target.getClass().isInstance(item))
if (item.carriedBy == null)
if (room.portalItem.Overlaps(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room.portalItem.room) {
if (target.getClass().isInstance(item)) {
if (item.carriedBy == null) {
if (room.portalItem.Overlaps(item)) {
ports[0].value = true;
a = level.items.size();
}
}
}
}
}
}
return false;
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
switch (rotation)
{
switch (rotation) {
case Port.ROT_UP:
g.drawImage(target.currentIcon, width / 2 - target.getWidth() / 2, 28, level);
break;
@ -118,27 +111,27 @@ public void Decorate()
}
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
else if (rotation == 3 && dir == 1)
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
else
}
else {
rotation += dir;
}
if (rotation % 2 == 0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else
{
else {
width = d1.width;
height = d1.height;
}
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP:
ports[0].x = width / 2 - 2;
ports[0].y = 2;
@ -158,8 +151,7 @@ public void rotate(int dir)
}
}
public void Erase()
{
public void Erase() {
super.Erase();
target = null;
}

View File

@ -1,21 +1,17 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.items.ToolBox;
public class Device extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Device extends Item {
// Base Class for the Logical Devices
transient Graphics g;
@ -25,49 +21,46 @@ public class Device extends Item
// Reference to the toolbox means this device can be put inside the ToolBox
transient boolean goesInToolbox;
public Device()
{
protected Device() {
// Constructor
rotation = 0;
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (int a=0; a<ports.length; a++)
ports[a].writeRef(s);
for (Port port : ports) {
port.writeRef(s);
}
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
for (int a=0; a<ports.length; a++)
ports[a].readRef(s,level);
for (Port port : ports) {
port.readRef(s, level);
}
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
goesInToolbox = false;
if (ports!=null)
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
if (ports != null) {
for (Port port : ports) {
port.myDevice = this;
}
}
icons = new ImageIcon[2];
if (rotation%2==0)
{
if (rotation % 2 == 0) {
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(height, width, BufferedImage.TYPE_4BYTE_ABGR));
}
else
{
else {
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[0] = new ImageIcon(new BufferedImage(height, width, BufferedImage.TYPE_4BYTE_ABGR));
}
}
public boolean Function()
{
public boolean Function() {
// Performs the function of the device, such as calculating the
// output based upon inputs, or handling external functions such as
// thrusting, touching walls, grabbing objects, antenna, etc...
@ -79,121 +72,110 @@ public class Device extends Item
return false;
}
public void Decorate()
{
public void Decorate() {
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
for (int a=0; a<ports.length; a++)
ports[a].Draw(g, rotation);
for (Port port : ports) {
port.Draw(g, rotation);
}
}
public boolean isDevice()
{
public boolean isDevice() {
return true;
}
public boolean isNode()
{
public boolean isNode() {
return false;
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
else if (rotation == 3 && dir == 1)
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
else
}
else {
rotation += dir;
}
int oldW = width;
int oldH = height;
int temp = width;
width = height;
height = temp;
for (int a=0; a<ports.length; a++)
{
int oldX = ports[a].x*2 + 1;
int oldY = ports[a].y*2 + 1;
temp = ports[a].width;
ports[a].width = ports[a].height;
ports[a].height = temp;
switch (dir)
{
for (Port port : ports) {
int oldX = port.x * 2 + 1;
int oldY = port.y * 2 + 1;
temp = port.width;
port.width = port.height;
port.height = temp;
switch (dir) {
case 1: // Turn Right
oldX = oldX - oldW;
oldY = oldY - oldH;
ports[a].x = (width - oldY)/2;
ports[a].y = (height + oldX)/2 ;
port.x = (width - oldY) / 2;
port.y = (height + oldX) / 2;
break;
case -1: // Turn Left
oldX = oldX - oldW;
oldY = oldY - oldH;
ports[a].x = (width + oldY)/2;
ports[a].y = (height - oldX)/2;
port.x = (width + oldY) / 2;
port.y = (height - oldX) / 2;
break;
}
}
}
public void IsDropped()
{
public void IsDropped() {
super.IsDropped();
if (goesInToolbox)
{
if (level.toolbox != null)
if (((ToolBox)level.toolbox).open)
{
if (Overlaps(level.toolbox))
{
if (goesInToolbox) {
if (level.toolbox != null) {
if (((ToolBox) level.toolbox).open) {
if (Overlaps(level.toolbox)) {
// Remove all wires and delete device
for (int a = 0; a<ports.length; a++)
if (ports[a].myWire!=null)
ports[a].myWire.Remove();
for (Port port : ports) {
if (port.myWire != null) {
port.myWire.Remove();
}
}
level.items.removeElement(this);
}
}
}
}
public boolean CanBePickedUp(Item item)
{
if (item.getClass().toString().endsWith("Robot"))
return false;
else
return super.CanBePickedUp(item);
}
public void Erase()
{
public boolean CanBePickedUp(Item item) {
return !item.getClass().toString().endsWith("Robot") && super.CanBePickedUp(item);
}
public void Erase() {
super.Erase();
g = null;
for (int a=0; a<ports.length; a++)
{
ports[a].myDevice = null;
ports[a].myWire = null;
for (Port port : ports) {
port.myDevice = null;
port.myWire = null;
}
}
public void flip()
{
return;
public void flip() {
// Just rotate twice to flip
rotate(1);
rotate(1);
}
public Object clone()
{
Device newDevice = null;
public Object clone() {
Device newDevice;
newDevice = (Device) super.clone();
newDevice.ports = null;
newDevice.GenerateIcons();

View File

@ -1,25 +1,21 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.materials.Material;
public class DirectionalSensor extends Device
{
String targetClass;
Item target;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public DirectionalSensor(int X, int Y, Room r, Item item)
{
x=X; y=Y; room = r;
public class DirectionalSensor extends Device {
private String targetClass;
private Item target;
public DirectionalSensor(int X, int Y, Room r, Item item) {
x = X;
y = Y;
room = r;
target = item;
editable = true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
@ -33,10 +29,8 @@ public DirectionalSensor(int X, int Y, Room r, Item item)
GenerateIcons();
}
public void GenerateIcons()
{
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[4];
ports[0] = new Port(width / 2 - 4, 0, Port.TYPE_OUTPUT, 24, Port.ROT_UP, this);
ports[1] = new Port(width - 5, height / 2 - 4, Port.TYPE_OUTPUT, 24, Port.ROT_RIGHT, this);
@ -49,88 +43,73 @@ public void GenerateIcons()
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[0].value = false;
ports[1].value = false;
ports[2].value = false;
ports[3].value = false;
if (room.portalItem == null)
{
if (room.portalItem == null) {
// Directional Sensor is not inside robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room == room && item.carriedBy==null)
// if (item.getClass().toString().endsWith(targetClass))
if (target.getClass().isInstance(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room && item.carriedBy == null) {
if (target.getClass().isInstance(item)) {
Dimension d = GetXY();
int X = d.width;
int Y = d.height;
if (item.y < Y)
{
if (item.y < Y) {
ports[0].value = true;
a = level.items.size();
}
if (item.x + item.getWidth() > X + width)
{
if (item.x + item.getWidth() > X + width) {
ports[1].value = true;
a = level.items.size();
}
if (item.y + item.getHeight() > Y + height)
{
if (item.y + item.getHeight() > Y + height) {
ports[2].value = true;
a = level.items.size();
}
if (item.x < X)
{
if (item.x < X) {
ports[3].value = true;
a = level.items.size();
}
}
}
}
else
{
}
else {
// Directional Sensor is inside Robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room == room.portalItem.room && item.carriedBy==null)
if (target.getClass().isInstance(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room.portalItem.room && item.carriedBy == null) {
if (target.getClass().isInstance(item)) {
Dimension d = room.portalItem.GetXY();
int X = d.width;
int Y = d.height;
if (item.y < Y)
{
if (item.y < Y) {
ports[0].value = true;
a = level.items.size();
}
if (item.x + item.getWidth() > X + room.portalItem.getWidth())
{
if (item.x + item.getWidth() > X + room.portalItem.getWidth()) {
ports[1].value = true;
a = level.items.size();
}
if (item.y + item.getHeight() > Y + room.portalItem.getHeight())
{
if (item.y + item.getHeight() > Y + room.portalItem.getHeight()) {
ports[2].value = true;
a = level.items.size();
}
if (item.x < X)
{
if (item.x < X) {
ports[3].value = true;
a = level.items.size();
}
}
}
}
}
return false;
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
g.setColor(Color.white);
g.drawRect(24, 24, target.getWidth() + 12, target.getHeight() + 12);
@ -138,13 +117,11 @@ public void Decorate()
g.drawImage(target.currentIcon, 30, 30, level);
}
public void rotate(int dir)
{
public void rotate(int dir) {
// Does not Rotate!
}
public void Erase()
{
public void Erase() {
super.Erase();
target = null;
}

View File

@ -1,96 +1,92 @@
package com.droidquest.devices;
import com.droidquest.devices.Device;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
public class FlipFlop extends Device
{
public boolean state;
public Color c1;
public Color c2;
public transient ImageIcon images[];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public FlipFlop(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=48; height=32;
public class FlipFlop extends Device {
public boolean state;
private Color c1;
private Color c2;
private transient ImageIcon[] images;
public FlipFlop(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 48;
height = 32;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (!state)
if (!state) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[4];
ports[0] = new Port(11, 29, Port.TYPE_INPUT, 6, Port.ROT_DOWN, this);
ports[1] = new Port(39, 27, Port.TYPE_INPUT, 4, Port.ROT_DOWN, this);
ports[2] = new Port(8, 2, Port.TYPE_OUTPUT, 8, Port.ROT_UP, this);
ports[3] = new Port(36, 0, Port.TYPE_OUTPUT, 10, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w; int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
int w;
int h;
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -98,18 +94,15 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
{
if (v == 0) {
c1 = new Color(255, 128, 0);
c2 = Color.white;
}
else
{
else {
c1 = Color.white;
c2 = new Color(255, 128, 0);
}
switch(r)
{
switch (r) {
case 0: // Up
g.setColor(c1);
g.fillRect(0, 10, 24, 12);
@ -134,49 +127,69 @@ public void GenerateIcons()
g.setColor(c1);
g.fillRect(10, 24, 12, 24);
break;
};
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
if (ports[0].value ^ ports[1].value)
public boolean Function() {
if (ports[0].value ^ ports[1].value) {
state = ports[0].value;
}
ports[2].value = state;
ports[3].value = !state;
return false;
}
public void flip()
{
public void flip() {
Wire wire1 = ports[0].myWire;
Wire wire2 = ports[1].myWire;
Wire wire3 = ports[2].myWire;
Wire wire4 = ports[3].myWire;
if (wire1 != null)
{
if (wire1.fromPort == ports[0]) wire1.fromPort = ports[1];
if (wire1.toPort == ports[0]) wire1.toPort = ports[1];
if (wire1.inPort == ports[0]) wire1.inPort = ports[1];
if (wire1 != null) {
if (wire1.fromPort == ports[0]) {
wire1.fromPort = ports[1];
}
if (wire2 != null)
{
if (wire2.fromPort == ports[1]) wire2.fromPort = ports[0];
if (wire2.toPort == ports[1]) wire2.toPort = ports[0];
if (wire2.inPort == ports[1]) wire2.inPort = ports[0];
if (wire1.toPort == ports[0]) {
wire1.toPort = ports[1];
}
if (wire3 != null)
{
if (wire3.fromPort == ports[2]) wire3.fromPort = ports[3];
if (wire3.toPort == ports[2]) wire3.toPort = ports[3];
if (wire3.outPort == ports[2]) wire3.outPort = ports[3];
if (wire1.inPort == ports[0]) {
wire1.inPort = ports[1];
}
}
if (wire2 != null) {
if (wire2.fromPort == ports[1]) {
wire2.fromPort = ports[0];
}
if (wire2.toPort == ports[1]) {
wire2.toPort = ports[0];
}
if (wire2.inPort == ports[1]) {
wire2.inPort = ports[0];
}
}
if (wire3 != null) {
if (wire3.fromPort == ports[2]) {
wire3.fromPort = ports[3];
}
if (wire3.toPort == ports[2]) {
wire3.toPort = ports[3];
}
if (wire3.outPort == ports[2]) {
wire3.outPort = ports[3];
}
}
if (wire4 != null) {
if (wire4.fromPort == ports[3]) {
wire4.fromPort = ports[2];
}
if (wire4.toPort == ports[3]) {
wire4.toPort = ports[2];
}
if (wire4.outPort == ports[3]) {
wire4.outPort = ports[2];
}
if (wire4 != null)
{
if (wire4.fromPort == ports[3]) wire4.fromPort = ports[2];
if (wire4.toPort == ports[3]) wire4.toPort = ports[2];
if (wire4.outPort == ports[3]) wire4.outPort = ports[2];
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;

View File

@ -1,24 +1,21 @@
package com.droidquest.devices;
public class GenericChip extends Device
{
public class GenericChip extends Device {
public String label;
public boolean inBurner;
public boolean inTester;
public String description = "Chip Pinouts";
public transient ChipText chiptext;
private transient ChipText chiptext;
public GenericChip() {}
GenericChip() {
}
public void rotate(int dir)
{
public void rotate(int dir) {
// Does not Rotate!
}
public void ShowText(boolean editable)
{
if (chiptext==null)
{
public void ShowText(boolean editable) {
if (chiptext == null) {
chiptext = new ChipText(this);
chiptext.setTitle("Pinout for Chip " + label);
}

View File

@ -1,74 +1,71 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.GenericRobot;
import com.droidquest.items.Item;
public class Grabber extends Device
{
Color color;
transient GenericRobot robot;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public Grabber(int X, int Y, Room r, Color col)
{
x=X; y=Y; color= col;
width=40; height=48;
public class Grabber extends Device {
private Color color;
private transient GenericRobot robot;
public Grabber(int X, int Y, Room r, Color col) {
x = X;
y = Y;
color = col;
width = 40;
height = 48;
grabbable = false;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void GenerateIcons()
{
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
if (ports==null)
{
if (ports == null) {
ports = new Port[2];
ports[0] = new Port(35, 41, Port.TYPE_INPUT, 16, Port.ROT_DOWN, this);
ports[1] = new Port(11, 47, Port.TYPE_OUTPUT, 26, Port.ROT_DOWN, this);
}
else
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
else {
for (Port port : ports) {
port.myDevice = this;
}
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
try
{
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -87,32 +84,23 @@ public void Decorate()
g.fillRect(0, 8, 4, 4);
}
public boolean Function()
{
if (robot.carrying != null)
ports[1].value=true;
else
ports[1].value=false;
public boolean Function() {
ports[1].value = robot.carrying != null;
if (ports[0].value == false)
{ // Input Low
if (robot.carrying != null)
if (!ports[0].value) { // Input Low
if (robot.carrying != null) {
robot.Drops();
}
else
{ // Input High
if (robot.carrying == null)
{
}
else { // Input High
if (robot.carrying == null) {
// Try and pick up something
Item item = robot.level.FindNearestItem(robot);
if (item != null)
{
if (item.CanBePickedUp(robot) && item.carriedBy==null)
{
if (item != null) {
if (item.CanBePickedUp(robot) && item.carriedBy == null) {
int CX = item.x + item.getWidth() / 2;
int CY = item.y + item.getHeight() / 2;
if (CX>=28+robot.x && CY<21+robot.y)
{
if (CX >= 28 + robot.x && CY < 21 + robot.y) {
// Move item to robot.x,robot.y
item.x = robot.x + 60 - item.getWidth() / 2;
item.y = robot.y - 9 - item.getHeight() / 2;
@ -120,8 +108,7 @@ public boolean Function()
robot.PicksUp(item);
}
if (CX>=28+robot.x && CY>=21+robot.y)
{
if (CX >= 28 + robot.x && CY >= 21 + robot.y) {
// Move item to robot.x,robot.y
item.x = robot.x + 66 - item.getWidth() / 2;
item.y = robot.y + 41 - item.getHeight() / 2;
@ -129,8 +116,7 @@ public boolean Function()
robot.PicksUp(item);
}
if (CX<28+robot.x && CY>=21+robot.y)
{
if (CX < 28 + robot.x && CY >= 21 + robot.y) {
// Move item to robot.x,robot.y
item.x = robot.x + 5 - item.getWidth() / 2;
item.y = robot.y + 52 - item.getHeight() / 2;
@ -138,8 +124,7 @@ public boolean Function()
robot.PicksUp(item);
}
if (CX<28+robot.x && CY<21+robot.y)
{
if (CX < 28 + robot.x && CY < 21 + robot.y) {
// Move item to robot.x,robot.y
item.x = robot.x - 5 - item.getWidth() / 2;
item.y = robot.y + 3 - item.getHeight() / 2;
@ -155,8 +140,7 @@ public boolean Function()
return false;
}
public void Erase()
{
public void Erase() {
super.Erase();
robot = null;
}

View File

@ -1,88 +1,86 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
public class NOTGate extends Device
{
transient ImageIcon images[];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public NOTGate(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=28; height=50;
public class NOTGate extends Device {
private transient ImageIcon[] images;
public NOTGate(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 50;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (!ports[0].value)
if (!ports[0].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[2];
ports[0] = new Port(15, 47, Port.TYPE_INPUT, 12, Port.ROT_DOWN, this);
ports[1] = new Port(12, 2, Port.TYPE_OUTPUT, 14, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w; int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
int w;
int h;
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -90,12 +88,13 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
if (v == 0) {
g.setColor(Color.white);
else
}
else {
g.setColor(new Color(255, 128, 0));
switch(r)
{
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 4, 4);
g.fillRect(16, 16, 4, 4);
@ -144,13 +143,13 @@ public void GenerateIcons()
g.fillRect(30, 24, 4, 4);
g.fillRect(32, 0, 2, 32);
break;
};
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[1].value = !ports[0].value;
return false;
}

View File

@ -11,51 +11,47 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
public class Node extends Device
{
public class Node extends Device {
public static final int TYPE_STRAIGHT = 0;
public static final int TYPE_RIGHT = 1;
public static final int TYPE_THREE = 2;
transient ImageIcon images[];
int type;
private transient ImageIcon[] images;
private int type;
public Node(int X, int Y, Room r, int t)
{
x=X; y=Y; room =r;
width=36; height=32;
public Node(int X, int Y, Room r, int t) {
x = X;
y = Y;
room = r;
width = 36;
height = 32;
type = t;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (ports[0].value)
if (ports[0].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
switch(type)
{
if (ports == null) {
switch (type) {
case TYPE_STRAIGHT:
ports = new Port[3];
ports[0] = new Port(16, 14, Port.TYPE_INPUT, 0, Port.ROT_UP, this);
@ -76,41 +72,44 @@ public void GenerateIcons()
ports[3] = new Port(19, 31, Port.TYPE_OUTPUT, 12, Port.ROT_DOWN, this);
break;
}
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w; int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
int w;
int h;
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -118,12 +117,13 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
if (v == 0) {
g.setColor(Color.white);
else
}
else {
g.setColor(new Color(255, 128, 0));
switch(r)
{
}
switch (r) {
case 0: // Up
case 2: // Down
g.fillRect(12, 12, 12, 2);
@ -138,21 +138,21 @@ public void GenerateIcons()
g.fillRect(12, 12, 2, 12);
g.fillRect(18, 12, 2, 12);
break;
};
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
boolean oldValue = ports[1].value;
for (int a=1; a<ports.length; a++)
for (int a = 1; a < ports.length; a++) {
ports[a].value = ports[0].value;
}
return (ports[0].value != oldValue);
}
public boolean isNode()
{
public boolean isNode() {
return true;
}

View File

@ -10,81 +10,81 @@ import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
public class ORGate extends Device
{
transient ImageIcon images[];
public class ORGate extends Device {
private transient ImageIcon[] images;
public ORGate(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=28; height=50;
public ORGate(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 50;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ORGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (ports[0].value || ports[1].value)
if (ports[0].value || ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[3];
ports[0] = new Port(7, 47, Port.TYPE_INPUT, 12, Port.ROT_DOWN, this);
ports[1] = new Port(23, 43, Port.TYPE_INPUT, 8, Port.ROT_DOWN, this);
ports[2] = new Port(12, 2, Port.TYPE_OUTPUT, 16, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w; int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
int w;
int h;
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -92,12 +92,13 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
if (v == 0) {
g.setColor(Color.white);
else
}
else {
g.setColor(new Color(255, 128, 0));
switch(r)
{
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 12, 2);
g.fillRect(8, 16, 4, 4);
@ -157,30 +158,39 @@ public void GenerateIcons()
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[2].value = ports[0].value | ports[1].value;
return false;
}
public void flip()
{
public void flip() {
Wire wire1 = ports[0].myWire;
Wire wire2 = ports[1].myWire;
if (wire1 != null)
{
if (wire1.fromPort == ports[0]) wire1.fromPort = ports[1];
if (wire1.toPort == ports[0]) wire1.toPort = ports[1];
if (wire1.inPort == ports[0]) wire1.inPort = ports[1];
if (wire1 != null) {
if (wire1.fromPort == ports[0]) {
wire1.fromPort = ports[1];
}
if (wire1.toPort == ports[0]) {
wire1.toPort = ports[1];
}
if (wire1.inPort == ports[0]) {
wire1.inPort = ports[1];
}
}
if (wire2 != null) {
if (wire2.fromPort == ports[1]) {
wire2.fromPort = ports[0];
}
if (wire2.toPort == ports[1]) {
wire2.toPort = ports[0];
}
if (wire2.inPort == ports[1]) {
wire2.inPort = ports[0];
}
if (wire2 != null)
{
if (wire2.fromPort == ports[1]) wire2.fromPort = ports[0];
if (wire2.toPort == ports[1]) wire2.toPort = ports[0];
if (wire2.inPort == ports[1]) wire2.inPort = ports[0];
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;

View File

@ -3,50 +3,46 @@ package com.droidquest.devices;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
public class PortDevice extends Device
{
public class PortDevice extends Device {
// This is an invisible device which has a port sticking out of it. It's
// used inside the Prototype chip as well as in various spots inside the Tutorials.
int type;
int size;
private int type;
private int size;
public boolean value = false; // Used for constants in Tutorials
public PortDevice(int X, int Y, Room r, int s, int t)
{
x=X; y=Y; room = r;
type=t; size=s;
public PortDevice(int X, int Y, Room r, int s, int t) {
x = X;
y = Y;
room = r;
type = t;
size = s;
width = 20;
height = size + 20;
grabbable = false;
GenerateIcons();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[1];
ports[0] = new Port(8, 8, type, size, Port.ROT_UP, this);
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
if (value && ports[0].type == Port.TYPE_OUTPUT)
public boolean Function() {
if (value && ports[0].type == Port.TYPE_OUTPUT) {
ports[0].value = true;
}
return false;
}

View File

@ -1,44 +1,32 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.materials.ChipTrash;
import com.droidquest.materials.Material;
public class Prototype16Chip extends GenericChip
{
transient PortDevice portdevices[];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public Prototype16Chip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=40; height=40;
public class Prototype16Chip extends GenericChip {
private transient PortDevice[] portdevices;
public Prototype16Chip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 40;
height = 40;
GenerateIcons();
// try
// {
// g = icons[0].getImage().getGraphics();
// }
// catch (NullPointerException e)
// {
// System.out.println("Could not get Graphics pointer to PrototypeChip Image");
// return;
// }
InternalRoom = new Room();
int[][] table = {
InternalRoom.RoomArray = new int[][]{
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
@ -52,13 +40,16 @@ public Prototype16Chip(int X, int Y, Room r)
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
InternalRoom.RoomArray = table;
Material mat1 = new Material(Color.blue, false, true);
level.materials.addElement(mat1);
int mat1Index = level.materials.size() - 1;
for (int rY=0; rY<12; rY++)
for (int rX=0; rX<20; rX++)
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index;
for (int rY = 0; rY < 12; rY++) {
for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
@ -88,20 +79,22 @@ public Prototype16Chip(int X, int Y, Room r)
portdevices[9].rotate(-1);
portdevices[10].rotate(-1);
portdevices[11].rotate(-1);
portdevices[12].rotate(1);portdevices[12].rotate(1);
portdevices[13].rotate(1);portdevices[13].rotate(1);
portdevices[14].rotate(1);portdevices[14].rotate(1);
portdevices[15].rotate(1);portdevices[15].rotate(1);
portdevices[12].rotate(1);
portdevices[12].rotate(1);
portdevices[13].rotate(1);
portdevices[13].rotate(1);
portdevices[14].rotate(1);
portdevices[14].rotate(1);
portdevices[15].rotate(1);
portdevices[15].rotate(1);
for (int a=0; a<16; a++)
for (int a = 0; a < 16; a++) {
level.items.addElement(portdevices[a]);
}
}
public void GenerateIcons()
{
// super.GenerateIcons();
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[16];
ports[0] = new Port(1, 8, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[1] = new Port(1, 16, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
@ -122,12 +115,10 @@ public void GenerateIcons()
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -153,8 +144,7 @@ public void GenerateIcons()
g.fillRect(15, 1, 2, 2);
g.fillRect(7, 1, 2, 2);
g.setColor(Color.black);
if (label != null)
{
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
@ -165,30 +155,27 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Decorate()
{}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<16; a++)
s.writeInt(level.items.indexOf(portdevices[a]));
public void Decorate() {
}
public void readRef(ObjectInputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (int a = 0; a < 16; a++) {
s.writeInt(level.items.indexOf(portdevices[a]));
}
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
portdevices = new PortDevice[16];
for (int a=0; a<ports.length; a++)
{
for (int a = 0; a < ports.length; a++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public void IsDropped()
{
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
@ -196,14 +183,16 @@ public void IsDropped()
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
if (bigXr>19) bigXr=19;
if (bigYb>11) bigYb=11;
if (bigXr > 19) {
bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
for (int a=bigYt; a<=bigYb; a++)
for (int b=bigXl; b<=bigXr; b++)
{
if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash)
{
for (int a = bigYt; a <= bigYb; a++) {
for (int b = bigXl; b <= bigXr; b++) {
if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash) {
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room, level.DISCHARGESOUND);
@ -211,66 +200,64 @@ public void IsDropped()
}
}
}
}
public boolean Function()
{
// Transfer values bewteen the ports and the portdevices.
public boolean Function() {
// Transfer values between the ports and the portdevices.
boolean changed = false;
for (int a = 0; a<16; a++)
{
for (int a = 0; a < 16; a++) {
Port outer = ports[a];
Port inner = portdevices[a].ports[0];
if (outer.type == Port.TYPE_INPUT)
if (outer.value != inner.value)
{
if (outer.type == Port.TYPE_INPUT) {
if (outer.value != inner.value) {
changed = true;
inner.value = outer.value;
}
if (outer.type == Port.TYPE_OUTPUT)
if (outer.value != inner.value)
{
}
if (outer.type == Port.TYPE_OUTPUT) {
if (outer.value != inner.value) {
changed = true;
outer.value = inner.value;
}
}
if (outer.myWire==null && inner.myWire==null)
{
if (outer.myWire == null && inner.myWire == null) {
outer.type = Port.TYPE_UNDEFINED;
inner.type = Port.TYPE_UNDEFINED;
}
if (outer.type == Port.TYPE_UNDEFINED)
{
if (inner.myWire != null)
{
if (inner.type == Port.TYPE_INPUT)
if (outer.type == Port.TYPE_UNDEFINED) {
if (inner.myWire != null) {
if (inner.type == Port.TYPE_INPUT) {
outer.type = Port.TYPE_OUTPUT;
else if (inner.type == Port.TYPE_OUTPUT)
}
else if (inner.type == Port.TYPE_OUTPUT) {
outer.type = Port.TYPE_INPUT;
}
}
if (inner.type == Port.TYPE_UNDEFINED)
{
if (outer.myWire != null)
{
if (outer.type == Port.TYPE_INPUT)
}
if (inner.type == Port.TYPE_UNDEFINED) {
if (outer.myWire != null) {
if (outer.type == Port.TYPE_INPUT) {
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void Erase()
{
public void Erase() {
super.Erase();
for (int a=0; a<portdevices.length; a++)
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@ -1,44 +1,33 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.levels.Level;
import com.droidquest.materials.ChipTrash;
import com.droidquest.materials.Material;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
public class Prototype32Chip extends GenericChip {
private transient PortDevice[] portdevices;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.materials.ChipTrash;
import com.droidquest.materials.Material;
public class Prototype32Chip extends GenericChip
{
transient PortDevice portdevices[];
public Prototype32Chip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=80; height=80;
public Prototype32Chip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 80;
height = 80;
GenerateIcons();
// try
// {
// g = icons[0].getImage().getGraphics();
// }
// catch (NullPointerException e)
// {
// System.out.println("Could not get Graphics pointer to PrototypeChip Image");
// return;
// }
InternalRoom = new Room();
int[][] table = {
InternalRoom.RoomArray = new int[][]{
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
@ -52,13 +41,16 @@ public Prototype32Chip(int X, int Y, Room r)
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
InternalRoom.RoomArray = table;
Material mat1 = new Material(Color.blue, false, true);
level.materials.addElement(mat1);
int mat1Index = level.materials.size() - 1;
for (int rY=0; rY<12; rY++)
for (int rX=0; rX<20; rX++)
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index;
for (int rY = 0; rY < 12; rY++) {
for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
@ -100,23 +92,20 @@ public Prototype32Chip(int X, int Y, Room r)
portdevices[30] = new PortDevice(5 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[31] = new PortDevice(3 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
portdevices[a].rotate(1);
portdevices[a + 16].rotate(-1);
portdevices[a + 24].rotate(1);
portdevices[a + 24].rotate(1);
}
for (int a=0; a<32; a++)
for (int a = 0; a < 32; a++) {
level.items.addElement(portdevices[a]);
}
}
public void GenerateIcons()
{
// super.GenerateIcons();
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[32];
ports[0] = new Port(1, 8, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[1] = new Port(1, 16, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
@ -156,12 +145,10 @@ public void GenerateIcons()
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -208,8 +195,7 @@ public void GenerateIcons()
g.fillRect(7, 1, 2, 2);
g.setColor(Color.black);
if (label != null)
{
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
@ -220,84 +206,78 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Decorate()
{}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<32; a++)
s.writeInt(level.items.indexOf(portdevices[a]));
public void Decorate() {
}
public void readRef(ObjectInputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (int a = 0; a < 32; a++) {
s.writeInt(level.items.indexOf(portdevices[a]));
}
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
portdevices = new PortDevice[32];
for (int a=0; a<ports.length; a++)
{
for (int a = 0; a < ports.length; a++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public boolean Function()
{
public boolean Function() {
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
for (int a = 0; a<32; a++)
{
for (int a = 0; a < 32; a++) {
Port outer = ports[a];
Port inner = portdevices[a].ports[0];
if (outer.type == Port.TYPE_INPUT)
if (outer.value != inner.value)
{
if (outer.type == Port.TYPE_INPUT) {
if (outer.value != inner.value) {
changed = true;
inner.value = outer.value;
}
if (outer.type == Port.TYPE_OUTPUT)
if (outer.value != inner.value)
{
}
if (outer.type == Port.TYPE_OUTPUT) {
if (outer.value != inner.value) {
changed = true;
outer.value = inner.value;
}
}
if (outer.myWire==null && inner.myWire==null)
{
if (outer.myWire == null && inner.myWire == null) {
outer.type = Port.TYPE_UNDEFINED;
inner.type = Port.TYPE_UNDEFINED;
}
if (outer.type == Port.TYPE_UNDEFINED)
{
if (inner.myWire != null)
{
if (inner.type == Port.TYPE_INPUT)
if (outer.type == Port.TYPE_UNDEFINED) {
if (inner.myWire != null) {
if (inner.type == Port.TYPE_INPUT) {
outer.type = Port.TYPE_OUTPUT;
else if (inner.type == Port.TYPE_OUTPUT)
}
else if (inner.type == Port.TYPE_OUTPUT) {
outer.type = Port.TYPE_INPUT;
}
}
if (inner.type == Port.TYPE_UNDEFINED)
{
if (outer.myWire != null)
{
if (outer.type == Port.TYPE_INPUT)
}
if (inner.type == Port.TYPE_UNDEFINED) {
if (outer.myWire != null) {
if (outer.type == Port.TYPE_INPUT) {
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void IsDropped()
{
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
@ -305,27 +285,30 @@ public void IsDropped()
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
if (bigXr>19) bigXr=19;
if (bigYb>11) bigYb=11;
if (bigXr > 19) {
bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
for (int a=bigYt; a<=bigYb; a++)
for (int b=bigXl; b<=bigXr; b++)
{
if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash)
{
for (int a = bigYt; a <= bigYb; a++) {
for (int b = bigXl; b <= bigXr; b++) {
if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash) {
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
level.PlaySound(room, Level.DISCHARGESOUND);
return;
}
}
}
}
public void Erase()
{
public void Erase() {
super.Erase();
for (int a=0; a<portdevices.length; a++)
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@ -1,44 +1,32 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.levels.Level;
import com.droidquest.materials.Material;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.materials.Material;
public class PrototypeChip extends GenericChip
{
public class PrototypeChip extends GenericChip {
public transient PortDevice portdevices[];
public PrototypeChip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=104; height=64;
public PrototypeChip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 104;
height = 64;
GenerateIcons();
// try
// {
// g = icons[0].getImage().getGraphics();
// }
// catch (NullPointerException e)
// {
// System.out.println("Could not get Graphics pointer to PrototypeChip Image");
// return;
// }
InternalRoom = new Room();
int[][] table = {
InternalRoom.RoomArray = new int[][]{
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
@ -52,13 +40,16 @@ public PrototypeChip(int X, int Y, Room r)
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}
};
InternalRoom.RoomArray = table;
Material mat1 = new Material(Color.blue, false, true);
level.materials.addElement(mat1);
int mat1Index = level.materials.size() - 1;
for (int rY=0; rY<12; rY++)
for (int rX=0; rX<20; rX++)
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index;
for (int rY = 0; rY < 12; rY++) {
for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
@ -89,15 +80,14 @@ public PrototypeChip(int X, int Y, Room r)
portdevices[6].rotate(-1);
portdevices[7].rotate(-1);
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
level.items.addElement(portdevices[a]);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
// super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[8];
ports[0] = new Port(12, 9, Port.TYPE_UNDEFINED, 16, Port.ROT_LEFT, this);
ports[1] = new Port(4, 25, Port.TYPE_UNDEFINED, 24, Port.ROT_LEFT, this);
@ -110,12 +100,10 @@ public void GenerateIcons()
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -126,8 +114,7 @@ public void GenerateIcons()
g.fillRect(24, 0, 56, 64);
g.setColor(Color.black);
g.fillRect(26, 6, 4, 4);
if (label != null)
{
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
@ -138,28 +125,25 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
try
{
public void Animate() {
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
for (int a=0; a<ports.length; a++)
ports[a].Draw(g, rotation);
for (Port port : ports) {
port.Draw(g, rotation);
}
g.setColor(Color.blue);
g.fillRect(24, 0, 56, 64);
g.setColor(Color.black);
g.fillRect(26, 6, 4, 4);
if (label != null)
{
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
@ -169,84 +153,78 @@ public void Animate()
}
}
public void Decorate()
{}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<8; a++)
s.writeInt(level.items.indexOf(portdevices[a]));
public void Decorate() {
}
public void readRef(ObjectInputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (int a = 0; a < 8; a++) {
s.writeInt(level.items.indexOf(portdevices[a]));
}
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
portdevices = new PortDevice[8];
for (int a=0; a<ports.length; a++)
{
for (int a = 0; a < ports.length; a++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public boolean Function()
{
public boolean Function() {
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
for (int a = 0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
Port outer = ports[a];
Port inner = portdevices[a].ports[0];
if (outer.type == Port.TYPE_INPUT)
if (outer.value != inner.value)
{
if (outer.type == Port.TYPE_INPUT) {
if (outer.value != inner.value) {
changed = true;
inner.value = outer.value;
}
if (outer.type == Port.TYPE_OUTPUT)
if (outer.value != inner.value)
{
}
if (outer.type == Port.TYPE_OUTPUT) {
if (outer.value != inner.value) {
changed = true;
outer.value = inner.value;
}
}
if (outer.myWire==null && inner.myWire==null)
{
if (outer.myWire == null && inner.myWire == null) {
outer.type = Port.TYPE_UNDEFINED;
inner.type = Port.TYPE_UNDEFINED;
}
if (outer.type == Port.TYPE_UNDEFINED)
{
if (inner.myWire != null)
{
if (inner.type == Port.TYPE_INPUT)
if (outer.type == Port.TYPE_UNDEFINED) {
if (inner.myWire != null) {
if (inner.type == Port.TYPE_INPUT) {
outer.type = Port.TYPE_OUTPUT;
else if (inner.type == Port.TYPE_OUTPUT)
}
else if (inner.type == Port.TYPE_OUTPUT) {
outer.type = Port.TYPE_INPUT;
}
}
if (inner.type == Port.TYPE_UNDEFINED)
{
if (outer.myWire != null)
{
if (outer.type == Port.TYPE_INPUT)
}
if (inner.type == Port.TYPE_UNDEFINED) {
if (outer.myWire != null) {
if (outer.type == Port.TYPE_INPUT) {
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void IsDropped()
{
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
@ -254,39 +232,42 @@ public void IsDropped()
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
if (bigXr>19) bigXr=19;
if (bigYb>11) bigYb=11;
if (bigXr > 19) {
bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
for (int a=bigYt; a<=bigYb; a++)
for (int b=bigXl; b<=bigXr; b++)
{
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("PrototypeBurner"))
{
a=bigYb; b=bigXr;
for (int a = bigYt; a <= bigYb; a++) {
for (int b = bigXl; b <= bigXr; b++) {
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("PrototypeBurner")) {
a = bigYb;
b = bigXr;
x = 3 * 28 + 4;
y = 5 * 32 + 12;
inBurner = true;
}
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTrash"))
{
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTrash")) {
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
level.PlaySound(room, Level.DISCHARGESOUND);
}
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTester"))
{
a=bigYb; b=bigXr;
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTester")) {
a = bigYb;
b = bigXr;
x = 10 * 28 - width / 2;
y = 5 * 32 - height / 2;
inTester = true;
}
}
}
}
public void Erase()
{
public void Erase() {
super.Erase();
for (int a=0; a<portdevices.length; a++)
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@ -10,16 +10,16 @@ import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
public class RoomSensor extends Device
{
String targetClass;
Item target;
Dimension d1 = new Dimension(); // Output pointing Right, Left
Dimension d2 = new Dimension(); // Output pointing Up, Down
public class RoomSensor extends Device {
private String targetClass;
private Item target;
private Dimension d1 = new Dimension(); // Output pointing Right, Left
private Dimension d2 = new Dimension(); // Output pointing Up, Down
public RoomSensor(int X, int Y, Room r, Item item)
{
x=X; y=Y; room = r;
public RoomSensor(int X, int Y, Room r, Item item) {
x = X;
y = Y;
room = r;
target = item;
editable = true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
@ -36,26 +36,23 @@ public RoomSensor(int X, int Y, Room r, Item item)
GenerateIcons();
}
public void GenerateIcons()
{
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[1];
ports[0] = new Port(width - 2, height / 2, Port.TYPE_OUTPUT, 24, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(d2.width, d2.height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(d1.width, d1.height, BufferedImage.TYPE_4BYTE_ABGR));
@ -63,47 +60,39 @@ public void GenerateIcons()
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[0].value = false;
if (room.portalItem == null)
{
if (room.portalItem == null) {
// Room Sensor is not inside robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room==room && item.carriedBy==null)
// if (item.getClass().toString().endsWith(targetClass))
if (target.getClass().isInstance(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room && item.carriedBy == null) {
if (target.getClass().isInstance(item)) {
ports[0].value = true;
a = level.items.size();
}
}
}
else
{
}
else {
// Room Sensor is inside Robot.
for (int a=0;a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.room == room.portalItem.room && item.carriedBy==null)
if (target.getClass().isInstance(item))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.room == room.portalItem.room && item.carriedBy == null) {
if (target.getClass().isInstance(item)) {
ports[0].value = true;
a = level.items.size();
}
}
}
}
return false;
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
g.setColor(Color.white);
switch (rotation)
{
switch (rotation) {
case Port.ROT_UP:
g.drawRect(0, 24, width, height - 24);
g.drawRect(1, 25, width - 2, height - 26);
@ -127,27 +116,27 @@ public void Decorate()
}
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
else if (rotation == 3 && dir == 1)
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
else
}
else {
rotation += dir;
}
if (rotation % 2 == 0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else
{
else {
width = d1.width;
height = d1.height;
}
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP:
ports[0].x = width / 2 - 2;
ports[0].y = 0;
@ -167,8 +156,7 @@ public void rotate(int dir)
}
}
public void Erase()
{
public void Erase() {
super.Erase();
target = null;
}

View File

@ -1,56 +1,43 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Vector;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.ChipCompiler;
import com.droidquest.chipstuff.Gate;
import com.droidquest.chipstuff.Port;
import com.droidquest.chipstuff.PortSignal;
import com.droidquest.chipstuff.Signal;
import com.droidquest.chipstuff.*;
import com.droidquest.decorations.TextBox;
import com.droidquest.levels.Level;
import com.droidquest.materials.ChipTester;
import com.droidquest.materials.ChipTrash;
import com.droidquest.materials.SmallChipBurner;
public class SmallChip extends GenericChip
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Vector;
public class SmallChip extends GenericChip {
public int speed;
public transient PortSignal[] portSignals = new PortSignal[8];
public Vector signals = new Vector();
public Vector gates = new Vector();
public Vector<Signal> signals = new Vector<Signal>();
public Vector<Gate> gates = new Vector<Gate>();
public SmallChip(int X, int Y, Room r, String l)
{
x=X; y=Y; room=r;
public SmallChip(int X, int Y, Room r, String l) {
x = X;
y = Y;
room = r;
label = l;
width=26; height=30;
width = 26;
height = 30;
speed = 1;
GenerateIcons();
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
public void GenerateIcons()
{
if (ports==null)
{
public void GenerateIcons() {
if (ports == null) {
ports = new Port[8];
ports[0] = new Port(0, 3, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[1] = new Port(0, 11, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
@ -63,21 +50,19 @@ public void GenerateIcons()
}
ChipText chiptext = new ChipText(this);
chiptext.setTitle("Pinout for Chip " + label);
if (portSignals == null)
{
if (portSignals == null) {
portSignals = new PortSignal[8];
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -100,19 +85,15 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
s.writeInt(signals.indexOf(portSignals[a].internalSignal));
s.writeInt(portSignals[a].type);
}
for (int a=0; a<gates.size(); a++)
{
Gate gate = (Gate) gates.elementAt(a);
for (int b=0; b<8; b++)
{
for (int a = 0; a < gates.size(); a++) {
Gate gate = gates.elementAt(a);
for (int b = 0; b < 8; b++) {
s.writeInt(signals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
@ -120,38 +101,35 @@ public void writeRef(ObjectOutputStream s) throws IOException
}
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
GenerateIcons();
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
int portIndex = s.readInt();
if (portIndex>=0)
portSignals[a].internalSignal = (Signal) signals.elementAt(portIndex);
if (portIndex >= 0) {
portSignals[a].internalSignal = signals.elementAt(portIndex);
}
portSignals[a].type = s.readInt();
}
for (int a=0; a<gates.size(); a++)
{
Gate gate = (Gate) gates.elementAt(a);
for (int a = 0; a < gates.size(); a++) {
Gate gate = gates.elementAt(a);
gate.portSignals = new PortSignal[8];
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
gate.portSignals[b] = new PortSignal();
int sigIndex = s.readInt();
if (sigIndex>=0)
gate.portSignals[b].externalSignal = (Signal) signals.elementAt(sigIndex);
if (sigIndex >= 0) {
gate.portSignals[b].externalSignal = signals.elementAt(sigIndex);
}
gate.portSignals[b].type = s.readInt();
}
gate.readRef(s);
}
}
public void Decorate()
{}
public void Decorate() {
}
public void IsDropped()
{
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
@ -159,33 +137,31 @@ public void IsDropped()
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
if (bigXr>19) bigXr=19;
if (bigYb>11) bigYb=11;
if (bigXr > 19) {
bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
for (int a=bigYt; a<=bigYb; a++)
for (int b=bigXl; b<=bigXr; b++)
{
if (room.MaterialArray[a][b] instanceof SmallChipBurner)
{
a=bigYb; b=bigXr;
for (int a = bigYt; a <= bigYb; a++) {
for (int b = bigXl; b <= bigXr; b++) {
if (room.MaterialArray[a][b] instanceof SmallChipBurner) {
x = 13 * 28 - width / 2;
y = 8 * 32 - height / 2;
inBurner = true;
ChipCompiler.chipSpeed = speed;
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
TextBox tb = room.textBoxes.elementAt(1);
tb.textString = speed + "x";
return;
}
if (room.MaterialArray[a][b] instanceof ChipTrash)
{
if (room.MaterialArray[a][b] instanceof ChipTrash) {
SetRoom(null); // Cheap way to remove the wires;
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
level.PlaySound(room, Level.DISCHARGESOUND);
return;
}
if (room.MaterialArray[a][b] instanceof ChipTester)
{
a=bigYb; b=bigXr;
if (room.MaterialArray[a][b] instanceof ChipTester) {
x = 10 * 28 - width / 2;
y = 5 * 32 - height / 2;
inTester = true;
@ -193,74 +169,77 @@ public void IsDropped()
}
}
}
}
public boolean Function()
{
public boolean Function() {
int a;
for (int s=0; s<speed; s++)
{
for (a=0; a<signals.size(); a++)
((Signal) signals.elementAt(a)).Flip();
for (int s = 0; s < speed; s++) {
for (a = 0; a < signals.size(); a++) {
signals.elementAt(a).Flip();
}
for (a=0; a<8; a++)
if (ports[a].type==Port.TYPE_INPUT)
if (portSignals[a].internalSignal != null)
for (a = 0; a < 8; a++) {
if (ports[a].type == Port.TYPE_INPUT) {
if (portSignals[a].internalSignal != null) {
portSignals[a].internalSignal.Set(ports[a].value);
}
}
}
for (a=0; a<gates.size(); a++)
((Gate) gates.elementAt(a)).Function();
for (a = 0; a < gates.size(); a++) {
gates.elementAt(a).Function();
}
for (a=0; a<8; a++)
if (ports[a].type==Port.TYPE_OUTPUT)
if (portSignals[a].internalSignal != null)
for (a = 0; a < 8; a++) {
if (ports[a].type == Port.TYPE_OUTPUT) {
if (portSignals[a].internalSignal != null) {
ports[a].value = portSignals[a].internalSignal.Get();
}
}
}
}
return false;
}
public void Erase()
{
public void Erase() {
super.Erase();
portSignals = null;
signals = null;
gates = null;
}
public void Empty()
{
if (signals != null)
public void Empty() {
if (signals != null) {
signals.removeAllElements();
signals = new Vector();
if (gates != null)
}
signals = new Vector<Signal>();
if (gates != null) {
gates.removeAllElements();
gates = new Vector();
if (portSignals == null)
{
}
gates = new Vector<Gate>();
if (portSignals == null) {
portSignals = new PortSignal[8];
for (int a=0; a<8; a++)
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
for (int a=0; a<8; a++)
{
}
for (int a = 0; a < 8; a++) {
portSignals[a].externalSignal = null;
portSignals[a].internalSignal = null;
portSignals[a].type = Port.TYPE_UNDEFINED;
}
}
public void LoadChip(String filename)
{
try
{
public void LoadChip(String filename) {
try {
FileInputStream in = new FileInputStream(filename);
ObjectInputStream s = new ObjectInputStream(in);
// Signals
int numSignals = s.readInt();
signals = new Vector();
for (int a=0; a<numSignals; a++)
{
signals = new Vector<Signal>();
for (int a = 0; a < numSignals; a++) {
Signal sig = new Signal();
sig.Set(s.readBoolean());
sig.working = s.readBoolean();
@ -269,29 +248,29 @@ public void LoadChip(String filename)
// Gates
int numGates = s.readInt();
gates = new Vector();
for (int a=0; a<numGates; a++)
{
gates = new Vector<Gate>();
for (int a = 0; a < numGates; a++) {
Gate gate = new Gate((String) s.readObject());
gates.addElement(gate);
gate.state = s.readBoolean();
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
int sigIndex = s.readInt();
if (sigIndex>=0)
gate.portSignals[b].externalSignal = (Signal) signals.elementAt(sigIndex);
if (sigIndex >= 0) {
gate.portSignals[b].externalSignal = signals.elementAt(sigIndex);
}
gate.portSignals[b].type = s.readInt();
}
if (gate.type.equalsIgnoreCase("Chip"))
if (gate.type.equalsIgnoreCase("Chip")) {
gate.LoadSubGate(s);
}
}
// PortSignals
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
int sigIndex = s.readInt();
if (sigIndex>=0)
portSignals[a].internalSignal = (Signal) signals.elementAt(sigIndex);
if (sigIndex >= 0) {
portSignals[a].internalSignal = signals.elementAt(sigIndex);
}
ports[a].type = s.readInt();
portSignals[a].type = ports[a].type;
}
@ -305,92 +284,65 @@ public void LoadChip(String filename)
s.close();
in.close();
}
catch (ClassNotFoundException e) {}
catch (FileNotFoundException e)
{
catch (ClassNotFoundException e) {
}
catch (FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
catch (IOException e)
{
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
// Debug report
// System.out.println(signals.size() + " Signals");
// System.out.println(gates.size() + " Gates");
// for(int a=0; a<gates.size(); a++)
// {
// Gate gate1 = (Gate) gates.elementAt(a);
// for (int b=0; b<8; b++)
// if (gate1.portSignals[b]!=null)
// System.out.println(gate1.type
// + " gate["
// + b
// + "] = Signal "
// + signals.indexOf(gate1.portSignals[b]));
// }
// for (int a=0; a<8; a++)
// if (portSignals[a] != null)
// System.out.println("PortSignal "
// + a
// + " = Signal "
// + signals.indexOf(portSignals[a]));
//
for (int a=0; a<8; a++)
if (ports[a].myWire!=null)
{
for (int a = 0; a < 8; a++) {
if (ports[a].myWire != null) {
Wire wire = ports[a].myWire;
if (wire.fromPort == ports[a])
{
if (wire.toPort.type == ports[a].type)
if (wire.fromPort == ports[a]) {
if (wire.toPort.type == ports[a].type) {
wire.Remove();
}
else if (wire.toPort == ports[a])
{
if (wire.fromPort.type == ports[a].type)
}
else if (wire.toPort == ports[a]) {
if (wire.fromPort.type == ports[a].type) {
wire.Remove();
}
}
}
}
}
public void SaveChip(String filename)
{
try
{
public void SaveChip(String filename) {
try {
FileOutputStream out = new FileOutputStream(filename);
ObjectOutputStream s = new ObjectOutputStream(out);
// Signals
s.writeInt(signals.size());
for (int a=0; a<signals.size(); a++)
{
Signal sig = (Signal)signals.elementAt(a);
for (int a = 0; a < signals.size(); a++) {
Signal sig = signals.elementAt(a);
s.writeBoolean(sig.Get());
s.writeBoolean(sig.working);
}
// Gates
s.writeInt(gates.size());
for (int a=0; a<gates.size(); a++)
{
Gate gate = (Gate) gates.elementAt(a);
for (int a = 0; a < gates.size(); a++) {
Gate gate = gates.elementAt(a);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
for (int b=0; b<8; b++)
{
for (int b = 0; b < 8; b++) {
s.writeInt(signals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
if (gate.type.equalsIgnoreCase("Chip"))
if (gate.type.equalsIgnoreCase("Chip")) {
gate.SaveSubGate(s);
}
}
// PortSignals
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
s.writeInt(signals.indexOf(portSignals[a].internalSignal));
s.writeInt(ports[a].type);
}
@ -405,12 +357,10 @@ public void SaveChip(String filename)
s.close();
out.close();
}
catch (FileNotFoundException e)
{
catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
catch (IOException e)
{
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
}

View File

@ -1,41 +1,35 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
public class StormShield extends Device
{
public StormShield(int X, int Y, Room r)
{
x=X; y=Y; room = r;
width=28; height=52;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class StormShield extends Device {
public StormShield(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 52;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[1];
ports[0] = new Port(15, 49, Port.TYPE_INPUT, 22, Port.ROT_DOWN, this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -68,25 +62,22 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Decorate()
{
try
{
public void Decorate() {
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
for (int a=0; a<ports.length; a++)
ports[a].Draw(g, rotation);
for (Port port : ports) {
port.Draw(g, rotation);
}
}
public void rotate(int dir)
{
public void rotate(int dir) {
// Does not Rotate!
}

View File

@ -1,58 +1,52 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Spark;
import com.droidquest.items.GenericRobot;
public class Thruster extends Device
{
public int rotation;
public Color color;
public transient GenericRobot robot;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public Thruster(int X, int Y, Room r, int direction, Color col)
{
x=X; y=Y;
public class Thruster extends Device {
private int rotation;
private Color color;
private transient GenericRobot robot;
public Thruster(int X, int Y, Room r, int direction, Color col) {
x = X;
y = Y;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot));
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void GenerateIcons()
{
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
if (ports==null)
{
if (ports == null) {
ports = new Port[1];
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
ports[0] = new Port(16, 35, Port.TYPE_INPUT, 20, Port.ROT_DOWN, this);
break;
@ -70,52 +64,53 @@ public class Thruster extends Device
break;
}
}
else
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
else {
for (Port port : ports) {
port.myDevice = this;
}
}
icons = new ImageIcon[1];
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
width=30; height=38;
width = 30;
height = 38;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
width=54; height=20;
width = 54;
height = 20;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
width=30; height=32;
width = 30;
height = 32;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
width=52; height=20;
width = 52;
height = 20;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
currentIcon = icons[0].getImage();
try
{
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch(rotation)
{
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(0, 0, 30, 6);
g.fillRect(4, 6, 22, 4);
@ -146,15 +141,12 @@ public class Thruster extends Device
}
}
public boolean Function()
{
public boolean Function() {
boolean thrust = ports[0].value;
if (robot==null && thrust)
{
if (robot == null && thrust) {
Dimension d = GetXY();
switch (rotation)
{
switch (rotation) {
case Port.ROT_UP:
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 0,
@ -190,10 +182,11 @@ public class Thruster extends Device
}
}
if (robot==null) return false;
if (robot == null) {
return false;
}
switch (rotation)
{
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
robot.topThruster = thrust;
break;
@ -210,8 +203,7 @@ public class Thruster extends Device
return false;
}
public void Erase()
{
public void Erase() {
super.Erase();
robot = null;
}

View File

@ -1,90 +1,88 @@
package com.droidquest.devices;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
public class XORGate extends Device
{
transient ImageIcon images[];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public XORGate(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=28; height=50;
public class XORGate extends Device {
private transient ImageIcon[] images;
public XORGate(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 50;
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to XORGate Image");
return;
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
if (ports[0].value ^ ports[1].value)
if (ports[0].value ^ ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
super.GenerateIcons();
if (ports==null)
{
if (ports == null) {
ports = new Port[3];
ports[0] = new Port(7, 47, Port.TYPE_INPUT, 12, Port.ROT_DOWN, this);
ports[1] = new Port(23, 43, Port.TYPE_INPUT, 8, Port.ROT_DOWN, this);
ports[2] = new Port(12, 2, Port.TYPE_OUTPUT, 16, Port.ROT_UP, this);
if (rotation > 0)
{
if (rotation > 0) {
int rot = rotation;
if (rotation%2==1)
{
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
for (int r=0; r<rot; r++)
for (int r = 0; r < rot; r++) {
rotate(1);
}
}
}
goesInToolbox = true;
images = new ImageIcon[8];
int w; int h;
if (rotation%2==0)
{w=width; h=height;}
else
{w=height; h=width;}
for (int v=0; v<2; v++)
for (int r=0; r<4; r++)
{
int w;
int h;
if (rotation % 2 == 0) {
w = width;
h = height;
}
else {
w = height;
h = width;
}
for (int v = 0; v < 2; v++) {
for (int r = 0; r < 4; r++) {
int a = r + v * 4;
if (r%2==0)
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
else
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
try
{
}
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
@ -92,12 +90,13 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
if (v==0)
if (v == 0) {
g.setColor(Color.white);
else
}
else {
g.setColor(new Color(255, 128, 0));
switch(r)
{
}
switch (r) {
case 0: // Up
g.fillRect(8, 18, 12, 2);
g.fillRect(8, 18, 4, 4);
@ -150,32 +149,41 @@ public void GenerateIcons()
g.fillRect(28, 8, 2, 12);
g.fillRect(32, 8, 2, 12);
break;
};
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
public boolean Function() {
ports[2].value = ports[0].value ^ ports[1].value;
return false;
}
public void flip()
{
public void flip() {
Wire wire1 = ports[0].myWire;
Wire wire2 = ports[1].myWire;
if (wire1 != null)
{
if (wire1.fromPort == ports[0]) wire1.fromPort = ports[1];
if (wire1.toPort == ports[0]) wire1.toPort = ports[1];
if (wire1.inPort == ports[0]) wire1.inPort = ports[1];
if (wire1 != null) {
if (wire1.fromPort == ports[0]) {
wire1.fromPort = ports[1];
}
if (wire1.toPort == ports[0]) {
wire1.toPort = ports[1];
}
if (wire1.inPort == ports[0]) {
wire1.inPort = ports[1];
}
}
if (wire2 != null) {
if (wire2.fromPort == ports[1]) {
wire2.fromPort = ports[0];
}
if (wire2.toPort == ports[1]) {
wire2.toPort = ports[0];
}
if (wire2.inPort == ports[1]) {
wire2.inPort = ports[0];
}
if (wire2 != null)
{
if (wire2.fromPort == ports[1]) wire2.fromPort = ports[0];
if (wire2.toPort == ports[1]) wire2.toPort = ports[0];
if (wire2.inPort == ports[1]) wire2.inPort = ports[0];
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;

View File

@ -1,20 +1,15 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class AmpireBot extends Item
{
int animationState=0; // 0-4
boolean alive=true;
int behaviorState=0;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class AmpireBot extends Item {
private int animationState = 0; // 0-4
private boolean alive = true;
private int behaviorState = 0;
// 0=Wait for Player
// 1=Patrol Init
// 2=Patrol Left
@ -23,20 +18,21 @@ int behaviorState=0;
// 5=Patrol Down
// 6=Pounce
// 7=Drain
int previousBehavior; // Used to return from Attack
Item target;
private int previousBehavior; // Used to return from Attack
private Item target;
public AmpireBot(int X, int Y, Room r)
{
x=X; y=Y; room=r;
public AmpireBot(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
grabbable = false;
width=26;height=32;
width = 26;
height = 32;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[6];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -49,12 +45,10 @@ public void GenerateIcons()
Color transparent = new Color(0, 0, 0, 0);
// 0= blue 1
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -76,12 +70,10 @@ public void GenerateIcons()
g.fillRect(2, 6, 8, 2);
// 1= blue 2
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -104,12 +96,10 @@ public void GenerateIcons()
g.fillRect(8, 6, 8, 2);
// 2= blue 3
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -134,12 +124,10 @@ public void GenerateIcons()
g.fillRect(18, 6, 8, 2);
// 3= green 1
try
{
try {
g = icons[3].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -161,12 +149,10 @@ public void GenerateIcons()
g.fillRect(2, 6, 8, 2);
// 4= orange 2
try
{
try {
g = icons[4].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -189,12 +175,10 @@ public void GenerateIcons()
g.fillRect(8, 6, 8, 2);
// 5= green 3
try
{
try {
g = icons[5].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -218,122 +202,161 @@ public void GenerateIcons()
g.setColor(Color.green);
g.fillRect(18, 6, 8, 2);
if (animationState==4) animationState=0;
if (animationState == 4) {
animationState = 0;
}
int frame = animationState;
if (animationState==3) frame=1;
if (!alive) frame +=3;
if (animationState == 3) {
frame = 1;
}
if (!alive) {
frame += 3;
}
currentIcon = icons[frame].getImage();
}
public void Animate()
{
public void Animate() {
animationState++;
if (animationState==4) animationState=0;
if (animationState == 4) {
animationState = 0;
}
int frame = animationState;
if (animationState==3) frame=1;
if (!alive) frame +=3;
if (animationState == 3) {
frame = 1;
}
if (!alive) {
frame += 3;
}
currentIcon = icons[frame].getImage();
if (alive)
{
if (behaviorState<6)
for (int a=0;a<level.items.size(); a++)
{
target = (Item) level.items.elementAt(a);
if (target.room == room)
if (target.charge>0)
{
if (alive) {
if (behaviorState < 6) {
for (int a = 0; a < level.items.size(); a++) {
target = level.items.elementAt(a);
if (target.room == room) {
if (target.charge > 0) {
previousBehavior = behaviorState;
behaviorState = 6;
a = level.items.size();
}
}
switch (behaviorState)
{
}
}
switch (behaviorState) {
case 0:
if (level.player.room == room) behaviorState=1;
if (level.player.room == room) {
behaviorState = 1;
}
break;
case 1:
if (y>=192)
if (y >= 192) {
behaviorState = 2;
else
{
MoveDown( 8);
if (x<280) MoveRight(8);
if (x>280) MoveLeft(8);
}
else {
moveDown(8);
if (x < 280) {
moveRight(8);
}
if (x > 280) {
moveLeft(8);
}
}
break;
case 2:
if (room==(Room) level.rooms.elementAt(18) && x<=280)
if (room == level.rooms.elementAt(18) && x <= 280) {
behaviorState = 3;
else
{
MoveLeft( 8);
if (y<192) MoveDown(8);
if (y>192) MoveUp(8);
}
else {
moveLeft(8);
if (y < 192) {
moveDown(8);
}
if (y > 192) {
moveUp(8);
}
}
break;
case 3:
if (room==(Room) level.rooms.elementAt(19) && y<=192)
if (room == level.rooms.elementAt(19) && y <= 192) {
behaviorState = 4;
else
{
MoveUp( 8);
if (x<280) MoveRight(8);
if (x>280) MoveLeft(8);
}
else {
moveUp(8);
if (x < 280) {
moveRight(8);
}
if (x > 280) {
moveLeft(8);
}
}
break;
case 4:
if (room==(Room) level.rooms.elementAt(15) && x>=280)
if (room == level.rooms.elementAt(15) && x >= 280) {
behaviorState = 5;
else
{
MoveRight( 8);
if (y<192) MoveDown(8);
if (y>192) MoveUp(8);
}
else {
moveRight(8);
if (y < 192) {
moveDown(8);
}
if (y > 192) {
moveUp(8);
}
}
break;
case 5:
if (room==(Room) level.rooms.elementAt(16) && y>=192)
if (room == level.rooms.elementAt(16) && y >= 192) {
behaviorState = 2;
else
{
MoveDown( 8);
if (x<280) MoveRight(8);
if (x>280) MoveLeft(8);
}
else {
moveDown(8);
if (x < 280) {
moveRight(8);
}
if (x > 280) {
moveLeft(8);
}
}
break;
case 6:
if (target.room != room)
if (target.room != room) {
behaviorState = previousBehavior;
if (Overlaps(target))
{
}
if (Overlaps(target)) {
behaviorState = 7;
break;
}
Dimension d = target.GetXY();
if (d.width<x) MoveLeft(false);
if (d.width>x) MoveRight(false);
if (d.height<y) MoveUp(false);
if (d.height>y) MoveDown(false);
if (d.width < x) {
moveLeft(false);
}
if (d.width > x) {
moveRight(false);
}
if (d.height < y) {
moveUp(false);
}
if (d.height > y) {
moveDown(false);
}
break;
case 7:
if (target.room != room)
{
if (target.room != room) {
behaviorState = previousBehavior;
break;
}
if (target.charge>0 && Overlaps(target))
{
if (target.getClass().toString().endsWith("BlackCrystal"))
if (target.charge > 0 && Overlaps(target)) {
if (target.getClass().toString().endsWith("BlackCrystal")) {
alive = false;
else
}
else {
target.charge -= 3125;
}
else
}
else {
behaviorState = 6;
if (target.charge <=0)
{
}
if (target.charge <= 0) {
target.charge = 0;
behaviorState = previousBehavior;
}
@ -342,8 +365,7 @@ public void Animate()
}
}
public void Erase()
{
public void Erase() {
super.Erase();
target = null;
}

View File

@ -1,50 +1,42 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Device;
import com.droidquest.devices.PortDevice;
import com.droidquest.devices.PrototypeChip;
import com.droidquest.devices.SmallChip;
public class AutoWire extends Item
{
int animation; // 0=Wait to Wire
// 1-8 = Wiring/Unwiring Port 1-8
Device chip;
PortDevice[] portdevices = new PortDevice[8];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public AutoWire(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=30;
public class AutoWire extends Item {
private int animation; // 0=Wait to Wire
// 1-8 = Wiring/Unwiring Port 1-8
private Device chip;
private PortDevice[] portdevices = new PortDevice[8];
public AutoWire(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 30;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// 0 = Off
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -58,12 +50,10 @@ public void GenerateIcons()
g.fillRect(8, 12, 12, 6);
// 1 = On
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -80,53 +70,52 @@ public void GenerateIcons()
}
public boolean CanBePickedUp(Item i)
{
if (animation!=0) return false;
public boolean CanBePickedUp(Item i) {
if (animation != 0) {
return false;
}
// Find the Item that has inTester set true;
chip = null;
int pdcount = 0;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("PrototypeChip"))
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item instanceof PrototypeChip) {
PrototypeChip pc = (PrototypeChip) item;
if (pc.inTester) chip = pc;
if (pc.inTester) {
chip = pc;
}
if (item.getClass().toString().endsWith("SmallChip"))
{
}
if (item instanceof SmallChip) {
SmallChip sc = (SmallChip) item;
if (sc.inTester) chip = sc;
if (sc.inTester) {
chip = sc;
}
if (item.getClass().toString().endsWith("PortDevice"))
{
if (item.room == room)
{
}
if (item instanceof PortDevice) {
if (item.room == room) {
portdevices[pdcount] = (PortDevice) item;
pdcount++;
}
}
}
if (chip==null) return false;
if (chip == null) {
return false;
}
animation = 1;
return false;
}
public void Animate()
{
if (animation==0) return;
public void Animate() {
if (animation == 0) {
return;
}
if (animation==1)
{
if (portdevices[0].ports[0].myWire==null)
{ // Wiring
if (animation == 1) {
if (portdevices[0].ports[0].myWire == null) { // Wiring
portdevices[0].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[0].ports[0].value = false;
Wire wire = new Wire(portdevices[0].ports[0], chip.ports[0]);
}
else
{ // Unwiring
else { // Unwiring
portdevices[0].ports[0].myWire.Remove();
portdevices[0].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[0].ports[0].value = false;
@ -136,21 +125,15 @@ public void Animate()
return;
}
if (animation>=2 && animation <=8)
{
if (portdevices[0].ports[0].myWire!=null)
{ // Wiring
if (portdevices[animation-1].ports[0].myWire==null)
{
if (animation >= 2 && animation <= 8) {
if (portdevices[0].ports[0].myWire != null) { // Wiring
if (portdevices[animation - 1].ports[0].myWire == null) {
portdevices[animation - 1].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[animation - 1].ports[0].value = false;
Wire wire = new Wire(portdevices[animation-1].ports[0], chip.ports[animation-1]);
}
}
else
{ // Unwiring
if (portdevices[animation-1].ports[0].myWire!=null)
{
else { // Unwiring
if (portdevices[animation - 1].ports[0].myWire != null) {
portdevices[animation - 1].ports[0].myWire.Remove();
portdevices[animation - 1].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[animation - 1].ports[0].value = false;
@ -159,16 +142,14 @@ public void Animate()
animation++;
}
if (animation==9)
{
if (animation == 9) {
currentIcon = icons[0].getImage();
animation = 0;
}
}
public void Erase()
{
public void Erase() {
super.Erase();
chip = null;
portdevices = null;

View File

@ -1,34 +1,29 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class BinaryKey extends Item
{
public BinaryKey (int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=26; height=28;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class BinaryKey extends Item {
public BinaryKey(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 26;
height = 28;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}

View File

@ -9,15 +9,12 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class BlackCrystal extends Crystal
{
public BlackCrystal(int X, int Y, Room r)
{
public class BlackCrystal extends Crystal {
public BlackCrystal(int X, int Y, Room r) {
super(X, Y, r, 10);
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
@ -25,12 +22,10 @@ public void GenerateIcons()
Color transparent = new Color(0, 0, 0, 0);
// 0 = blue
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -49,6 +44,7 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Decorate() {}
public void Decorate() {
}
}

View File

@ -1,8 +1,5 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Antenna;
@ -10,13 +7,13 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster;
public class BlueRobot extends GenericRobot
{
import java.awt.*;
public class BlueRobot extends GenericRobot {
private int scan;
private int scandir;
public BlueRobot(int X, int Y, Room r)
{
public BlueRobot(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
scan = 0;
scandir = 2;
@ -31,29 +28,28 @@ public BlueRobot(int X, int Y, Room r)
devices[7] = new Bumper(28, 134, InternalRoom, Port.ROT_LEFT, Color.white);
devices[8] = new Antenna(64, 70, InternalRoom, Color.white);
devices[9] = new Grabber(126, 44, InternalRoom, Color.white);
for (int a=0; a<10; a++)
for (int a = 0; a < 10; a++) {
level.items.addElement(devices[a]);
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g.setColor(Color.black);
g.fillRect(22, 44, 42, 4);
if (scan+scandir>36 || scan+scandir<0)
if (scan + scandir > 36 || scan + scandir < 0) {
scandir = -scandir;
}
scan = scan + scandir;
g.setColor(new Color(255, 128, 0));
g.fillRect(22 + scan, 44, 6, 4);

View File

@ -2,50 +2,40 @@ package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.ChipCompiler;
import com.droidquest.chipstuff.Gate;
import com.droidquest.chipstuff.Signal;
import com.droidquest.devices.Device;
import com.droidquest.devices.FlipFlop;
import com.droidquest.devices.PrototypeChip;
import com.droidquest.devices.SmallChip;
import com.droidquest.levels.Level;
public class Burner extends Item
{
int burning;
int animation;
public class Burner extends Item {
private int burning;
private int animation;
public Burner(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=30;
public Burner(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 30;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// 0 = Off
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -59,12 +49,10 @@ public void GenerateIcons()
g.fillRect(8, 12, 12, 6);
// 1 = On
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -81,30 +69,35 @@ public void GenerateIcons()
}
public boolean CanBePickedUp(Item i)
{
public boolean CanBePickedUp(Item i) {
// Find the SmallChip and Erase it
Item sc = null;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("SmallChip"))
if (((SmallChip)item).inBurner)
sc = (SmallChip) item;
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("SmallChip")) {
if (((SmallChip) item).inBurner) {
sc = item;
}
}
}
if (sc == null) {
return false;
}
if (sc==null) return false;
((SmallChip) sc).Empty();
// Find the PrototypeChip
Item pc = null;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("PrototypeChip"))
if (((PrototypeChip)item).inBurner)
pc = (PrototypeChip) item;
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("PrototypeChip")) {
if (((PrototypeChip) item).inBurner) {
pc = item;
}
}
}
if (pc == null) {
return false;
}
if (pc==null) return false;
// Start the ChipCompiler thread
ChipCompiler cc = new ChipCompiler((PrototypeChip) pc, (SmallChip) sc);
@ -115,17 +108,16 @@ public boolean CanBePickedUp(Item i)
return false;
}
public void Animate()
{
if (burning>0)
{
public void Animate() {
if (burning > 0) {
animation = 1 - animation;
currentIcon = icons[animation].getImage();
burning--;
}
else
else {
currentIcon = icons[0].getImage();
}
}
}

View File

@ -9,29 +9,27 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Button extends Item
{
Color color;
public class Button extends Item {
private Color color;
public Button(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r;
width=28; height=26;
public Button(int X, int Y, Room r, Color c) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
color = c;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}

View File

@ -6,36 +6,32 @@ import com.droidquest.Room;
import com.droidquest.decorations.TextBox;
import com.droidquest.materials.Material;
public class CamDisk extends Disk
{
transient SpyCam spycam=null;
public class CamDisk extends Disk {
private transient SpyCam spycam = null;
public CamDisk(int X, int Y, Room r)
{
public CamDisk(int X, int Y, Room r) {
super(X, Y, r, Color.white, 0);
}
public void IsDropped()
{
if (spycam==null)
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("SpyCam"))
public void IsDropped() {
if (spycam == null) {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("SpyCam")) {
spycam = (SpyCam) item;
}
}
}
int bigX = (x + width / 2) / 28;
int bigY = (y + height / 2) / 32;
Material mat = room.MaterialArray[bigY][bigX];
if (mat.getClass().toString().endsWith("Monitor"))
{
if (mat.getClass().toString().endsWith("Monitor")) {
level.currentViewer = spycam;
level.player = spycam;
spycam.room = room;
for (int a=5; a<60; a++)
{
Room r = (Room) level.rooms.elementAt(a);
TextBox tb = (TextBox) r.textBoxes.elementAt(0);
for (int a = 5; a < 60; a++) {
Room r = level.rooms.elementAt(a);
TextBox tb = r.textBoxes.elementAt(0);
tb.y -= 500;
}
}

View File

@ -1,133 +1,108 @@
package com.droidquest.items;
import java.util.Vector;
import com.droidquest.Wire;
import com.droidquest.chipstuff.Gate;
import com.droidquest.chipstuff.Port;
import com.droidquest.chipstuff.Signal;
import com.droidquest.devices.ANDGate;
import com.droidquest.devices.Device;
import com.droidquest.devices.FlipFlop;
import com.droidquest.devices.NOTGate;
import com.droidquest.devices.Node;
import com.droidquest.devices.ORGate;
import com.droidquest.devices.PortDevice;
import com.droidquest.devices.PrototypeChip;
import com.droidquest.devices.SmallChip;
import com.droidquest.devices.XORGate;
import com.droidquest.devices.*;
public class ChipDecompiler extends Thread
{
public ChipDecompiler(PrototypeChip pc, SmallChip sc)
{
Vector deviceList = new Vector();
import java.util.Vector;
class ChipDecompiler extends Thread {
public ChipDecompiler(PrototypeChip pc, SmallChip sc) {
Vector<Device> deviceList = new Vector<Device>();
pc.grabbable = false;
sc.grabbable = false;
// Remove all wires and devices from Prototype Chip, expect for PortDevices
for (int a=pc.InternalRoom.wires.size()-1; a>=0; a--)
{
Wire wire = (Wire)pc.InternalRoom.wires.elementAt(a);
for (int a = pc.InternalRoom.wires.size() - 1; a >= 0; a--) {
Wire wire = pc.InternalRoom.wires.elementAt(a);
wire.Remove();
}
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
pc.portdevices[a].ports[0].type = Port.TYPE_UNDEFINED;
pc.ports[a].type = Port.TYPE_UNDEFINED;
pc.ports[a].value = false;
}
for (int a=0; a<pc.level.items.size(); a++)
{
Item item = (Item) pc.level.items.elementAt(a);
for (int a = 0; a < pc.level.items.size(); a++) {
Item item = pc.level.items.elementAt(a);
if (item.room == pc.InternalRoom
&& item instanceof Device
&& !(item instanceof PortDevice))
{
&& !(item instanceof PortDevice)) {
pc.level.items.removeElement(item);
a--;
}
}
// Set the PortDevice types to match the SC PortSignal types
for (int a=0; a<8; a++)
{
if (sc.portSignals[a].type != Port.TYPE_UNDEFINED)
for (int a = 0; a < 8; a++) {
if (sc.portSignals[a].type != Port.TYPE_UNDEFINED) {
pc.portdevices[a].ports[0].type = 1 - sc.portSignals[a].type;
else
}
else {
pc.portdevices[a].ports[0].type = Port.TYPE_UNDEFINED;
}
}
// Add a corresponding Device for every Gate in the SmallChip
for (int a=0; a<sc.gates.size(); a++)
{
Gate gate = (Gate) sc.gates.elementAt(a);
if (gate.type.equalsIgnoreCase("AND"))
{
for (int a = 0; a < sc.gates.size(); a++) {
Gate gate = sc.gates.elementAt(a);
if (gate.type.equalsIgnoreCase("AND")) {
ANDGate andGate = new ANDGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(andGate);
pc.level.items.addElement(andGate);
}
if (gate.type.equalsIgnoreCase("OR"))
{
if (gate.type.equalsIgnoreCase("OR")) {
ORGate orGate = new ORGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(orGate);
pc.level.items.addElement(orGate);
}
if (gate.type.equalsIgnoreCase("NOT"))
{
if (gate.type.equalsIgnoreCase("NOT")) {
NOTGate notGate = new NOTGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(notGate);
pc.level.items.addElement(notGate);
}
if (gate.type.equalsIgnoreCase("XOR"))
{
if (gate.type.equalsIgnoreCase("XOR")) {
XORGate xorGate = new XORGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(xorGate);
pc.level.items.addElement(xorGate);
}
if (gate.type.equalsIgnoreCase("FF"))
{
if (gate.type.equalsIgnoreCase("FF")) {
FlipFlop flipflop = new FlipFlop(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(flipflop);
pc.level.items.addElement(flipflop);
flipflop.state = gate.state;
}
if (gate.type.equalsIgnoreCase("Chip"))
{
if (gate.type.equalsIgnoreCase("Chip")) {
SmallChip smallchip = new SmallChip(10 * 28, 6 * 32, pc.InternalRoom, "X");
deviceList.addElement(smallchip);
pc.level.items.addElement(smallchip);
smallchip.speed = gate.speed;
for (int b=0; b<gate.mySignals.size(); b++)
{
for (int b = 0; b < gate.mySignals.size(); b++) {
Signal newsig = new Signal();
Signal oldsig = (Signal) gate.mySignals.elementAt(b);
Signal oldsig = gate.mySignals.elementAt(b);
newsig.Set(oldsig.Get());
newsig.working = oldsig.working;
smallchip.signals.addElement(newsig);
}
for (int b=0; b<gate.myGates.size(); b++)
{
Gate oldgate = (Gate) gate.myGates.elementAt(b);
for (int b = 0; b < gate.myGates.size(); b++) {
Gate oldgate = gate.myGates.elementAt(b);
Gate newgate = new Gate(oldgate);
smallchip.gates.addElement(newgate);
for (int c=0; c<8; c++)
if (oldgate.portSignals[c].externalSignal != null)
{
for (int c = 0; c < 8; c++) {
if (oldgate.portSignals[c].externalSignal != null) {
int sigIndex = gate.mySignals.indexOf(oldgate.portSignals[c].externalSignal);
newgate.portSignals[c].externalSignal = (Signal) smallchip.signals.elementAt(sigIndex);
newgate.portSignals[c].externalSignal = smallchip.signals.elementAt(sigIndex);
}
}
for (int b=0; b<8; b++)
{
if (gate.portSignals[b].internalSignal != null)
{
}
for (int b = 0; b < 8; b++) {
if (gate.portSignals[b].internalSignal != null) {
int sigIndex = gate.mySignals.indexOf(gate.portSignals[b].internalSignal);
smallchip.portSignals[b].internalSignal = (Signal) smallchip.signals.elementAt(sigIndex);
smallchip.portSignals[b].internalSignal = smallchip.signals.elementAt(sigIndex);
}
smallchip.portSignals[b].type = gate.portSignals[b].type;
smallchip.ports[b].type = gate.portSignals[b].type;
@ -137,41 +112,44 @@ public ChipDecompiler(PrototypeChip pc, SmallChip sc)
// Wire Devices according to the way the Gates are linked to Signals
for (int a=0; a<sc.signals.size(); a++)
{
Signal sig = (Signal) sc.signals.elementAt(a);
if (sig.working)
{
for (int a = 0; a < sc.signals.size(); a++) {
Signal sig = sc.signals.elementAt(a);
if (sig.working) {
int numConnections = 0;
for (int b=0; b<8; b++)
if (sc.portSignals[b].internalSignal == sig)
for (int b = 0; b < 8; b++) {
if (sc.portSignals[b].internalSignal == sig) {
numConnections++;
for (int b=0; b<sc.gates.size(); b++)
{
Gate thisGate = (Gate) sc.gates.elementAt(b);
for (int c=0; c<8; c++)
if (thisGate.portSignals[c].externalSignal == sig)
}
}
for (int b = 0; b < sc.gates.size(); b++) {
Gate thisGate = sc.gates.elementAt(b);
for (int c = 0; c < 8; c++) {
if (thisGate.portSignals[c].externalSignal == sig) {
numConnections++;
}
}
}
if (numConnections == 2) // Simple wire from A to B
{
Port port1 = FindPort(sig, 1, pc, sc, deviceList);
Port port2 = FindPort(sig, 2, pc, sc, deviceList);
if (port1!=null && port2 != null)
{
if (port1 != null && port2 != null) {
Wire dummy = new Wire(port1, port2);
}
else
{
else {
System.out.println("Could not make connection for Signal " + a);
if (port1==null)
if (port1 == null) {
System.out.println("port1=null");
else
}
else {
System.out.println("port1 is in " + port1.myDevice.getClass());
if (port2==null)
}
if (port2 == null) {
System.out.println("port2=null");
else
}
else {
System.out.println("port2 is in " + port2.myDevice.getClass());
}
}
}
@ -184,38 +162,32 @@ public ChipDecompiler(PrototypeChip pc, SmallChip sc)
Node node = new Node(10 * 28, 6 * 32, pc.InternalRoom, Node.TYPE_STRAIGHT);
pc.level.items.addElement(node);
deviceList.addElement(node);
if (port1.type == Port.TYPE_OUTPUT)
{
if (port1.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port1, node.ports[0]);
Wire dummy2 = new Wire(port2, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
}
else if (port2.type == Port.TYPE_OUTPUT)
{
else if (port2.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port2, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
}
else if (port3.type == Port.TYPE_OUTPUT)
{
else if (port3.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port3, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
}
else if (port1.type == Port.TYPE_UNDEFINED)
{
else if (port1.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port1, node.ports[0]);
Wire dummy2 = new Wire(port2, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
}
else if (port2.type == Port.TYPE_UNDEFINED)
{
else if (port2.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port2, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
}
else if (port3.type == Port.TYPE_UNDEFINED)
{
else if (port3.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port3, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
@ -231,57 +203,49 @@ public ChipDecompiler(PrototypeChip pc, SmallChip sc)
Node node = new Node(10 * 28, 6 * 32, pc.InternalRoom, Node.TYPE_THREE);
pc.level.items.addElement(node);
deviceList.addElement(node);
if (port1.type == Port.TYPE_OUTPUT)
{
if (port1.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port1, node.ports[0]);
Wire dummy2 = new Wire(port2, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port2.type == Port.TYPE_OUTPUT)
{
else if (port2.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port2, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port3.type == Port.TYPE_OUTPUT)
{
else if (port3.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port3, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port4.type == Port.TYPE_OUTPUT)
{
else if (port4.type == Port.TYPE_OUTPUT) {
Wire dummy1 = new Wire(port4, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
Wire dummy4 = new Wire(port3, node.ports[3]);
}
else if (port1.type == Port.TYPE_UNDEFINED)
{
else if (port1.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port1, node.ports[0]);
Wire dummy2 = new Wire(port2, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port2.type == Port.TYPE_UNDEFINED)
{
else if (port2.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port2, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port3, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port3.type == Port.TYPE_UNDEFINED)
{
else if (port3.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port3, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
Wire dummy4 = new Wire(port4, node.ports[3]);
}
else if (port4.type == Port.TYPE_UNDEFINED)
{
else if (port4.type == Port.TYPE_UNDEFINED) {
Wire dummy1 = new Wire(port4, node.ports[0]);
Wire dummy2 = new Wire(port1, node.ports[1]);
Wire dummy3 = new Wire(port2, node.ports[2]);
@ -292,118 +256,119 @@ public ChipDecompiler(PrototypeChip pc, SmallChip sc)
else if (numConnections > 4) // Need many nodes
{
Port[] ports = new Port[numConnections];
for (int b=0; b<numConnections; b++)
for (int b = 0; b < numConnections; b++) {
ports[b] = FindPort(sig, b + 1, pc, sc, deviceList);
}
Node[] nodes = new Node[numConnections - 2];
for (int b=0; b<numConnections-2; b++)
{
for (int b = 0; b < numConnections - 2; b++) {
nodes[b] = new Node(10 * 28, 6 * 32, pc.InternalRoom, Node.TYPE_STRAIGHT);
pc.level.items.addElement(nodes[b]);
deviceList.addElement(nodes[b]);
}
for (int b=1; b<numConnections-2; b++)
{
for (int b = 1; b < numConnections - 2; b++) {
Wire dummy = new Wire(nodes[b - 1].ports[2], nodes[b].ports[0]);
}
int nodecounter = 0;
boolean inputfound = false;
for (int b=0; b<numConnections; b++)
{
if (ports[b].type == Port.TYPE_OUTPUT)
{
for (int b = 0; b < numConnections; b++) {
if (ports[b].type == Port.TYPE_OUTPUT) {
Wire dummy = new Wire(nodes[0].ports[0], ports[b]);
inputfound = true;
}
else if (ports[b].type == Port.TYPE_INPUT)
{
if (nodecounter<nodes.length)
{
else if (ports[b].type == Port.TYPE_INPUT) {
if (nodecounter < nodes.length) {
Wire dummy = new Wire(nodes[nodecounter].ports[1], ports[b]);
nodecounter++;
}
else
{
else {
Wire dummy = new Wire(nodes[nodecounter - 1].ports[2], ports[b]);
}
}
else
else {
System.out.println(ports[b].myDevice.getClass()
+ " port " + b + " id undefined.");
}
if (!inputfound)
for (int b=0; b<numConnections; b++)
if (ports[b].type == Port.TYPE_UNDEFINED)
{
}
if (!inputfound) {
for (int b = 0; b < numConnections; b++) {
if (ports[b].type == Port.TYPE_UNDEFINED) {
Wire dummy = new Wire(nodes[0].ports[0], ports[b]);
}
}
}
}
}
}
// Routing: Move the devices around based on what they are connected to.
for (int a=0; a<10; a++)
{
for (int b=0; b<deviceList.size(); b++)
{
Device device = (Device) deviceList.elementAt(b);
for (int a = 0; a < 10; a++) {
for (int b = 0; b < deviceList.size(); b++) {
Device device = deviceList.elementAt(b);
int numConnections = 1;
int x=device.x; int y=device.y;
for (int c=0; c<device.ports.length; c++)
if (device.ports[c].myWire != null)
{
if (device.ports[c].type == Port.TYPE_INPUT)
{
int x = device.x;
int y = device.y;
for (int c = 0; c < device.ports.length; c++) {
if (device.ports[c].myWire != null) {
if (device.ports[c].type == Port.TYPE_INPUT) {
x += device.ports[c].myWire.outPort.myDevice.x;
y += device.ports[c].myWire.outPort.myDevice.y;
}
else if (device.ports[c].type == Port.TYPE_OUTPUT)
{
else if (device.ports[c].type == Port.TYPE_OUTPUT) {
x += device.ports[c].myWire.inPort.myDevice.x;
y += device.ports[c].myWire.inPort.myDevice.y;
}
numConnections++;
}
}
device.x = x / numConnections;
device.y = y / numConnections;
if (device.x < 56) device.x = 56;
if (device.x > 504) device.x = 504;
if (device.y < 32) device.y = 32;
if (device.y > 320) device.y = 320;
if (device.x < 56) {
device.x = 56;
}
if (device.x > 504) {
device.x = 504;
}
if (device.y < 32) {
device.y = 32;
}
if (device.y > 320) {
device.y = 320;
}
}
}
// Rotate devices to point to the "next" device. AND, OR, NOT, XOR only
for (int a=0; a<deviceList.size(); a++)
{
Device device = (Device) deviceList.elementAt(a);
for (int a = 0; a < deviceList.size(); a++) {
Device device = deviceList.elementAt(a);
if (!(device instanceof SmallChip
|| device instanceof Node
|| device instanceof FlipFlop))
{
|| device instanceof FlipFlop)) {
Port port;
if (device instanceof NOTGate)
if (device instanceof NOTGate) {
port = device.ports[1];
else
}
else {
port = device.ports[2];
if (port.myWire != null)
{
}
if (port.myWire != null) {
Port otherPort = port.myWire.otherPort(port);
Device otherDevice = (Device) otherPort.myDevice;
int dx = otherDevice.x - device.x;
int dy = otherDevice.y - device.y;
if (Math.abs(dx)>Math.abs(dy))
{
if (dx<0) device.rotate(-1);
else device.rotate(1);
if (Math.abs(dx) > Math.abs(dy)) {
if (dx < 0) {
device.rotate(-1);
}
else
{
if (dy>0)
{
else {
device.rotate(1);
}
}
else {
if (dy > 0) {
device.rotate(1);
device.rotate(1);
}
@ -418,32 +383,31 @@ public ChipDecompiler(PrototypeChip pc, SmallChip sc)
}
public Port FindPort(Signal sig, int num, PrototypeChip pc, SmallChip sc, Vector deviceList)
{
Port FindPort(Signal sig, int num, PrototypeChip pc, SmallChip sc, Vector<Device> deviceList) {
// Find Nth port that this signal attaches to in given SmallChip.
int n = 0;
for (int a=0; a<8; a++)
if (sc.portSignals[a].internalSignal == sig)
{
for (int a = 0; a < 8; a++) {
if (sc.portSignals[a].internalSignal == sig) {
n++;
if (n==num) return pc.portdevices[a].ports[0];
if (n == num) {
return pc.portdevices[a].ports[0];
}
for (int a=0; a<sc.gates.size(); a++)
{
Gate thisgate = (Gate) sc.gates.elementAt(a);
for (int b=0; b<8; b++)
if (thisgate.portSignals[b].externalSignal == sig)
{
}
}
for (int a = 0; a < sc.gates.size(); a++) {
Gate thisgate = sc.gates.elementAt(a);
for (int b = 0; b < 8; b++) {
if (thisgate.portSignals[b].externalSignal == sig) {
n++;
if (n==num)
{
Device device = (Device) deviceList.elementAt(a);
if (n == num) {
Device device = deviceList.elementAt(a);
return device.ports[b];
}
}
}
}
return null;
}

View File

@ -9,22 +9,22 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Crystal extends Item
{
int color = 0; // 0 = blue; 1 = orange
public class Crystal extends Item {
private int color = 0; // 0 = blue; 1 = orange
public Crystal(int X, int Y, Room r, int ch)
{
x=X; y=Y; room=r;
public Crystal(int X, int Y, Room r, int ch) {
x = X;
y = Y;
room = r;
charge = ch;
width=28; height=24;
width = 28;
height = 24;
editable = true;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -34,12 +34,10 @@ public void GenerateIcons()
Color transparent = new Color(0, 0, 0, 0);
// 0 = blue
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -57,12 +55,10 @@ public void GenerateIcons()
g.fillRect(24, 18, 4, 2);
// 1 = orange
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -80,12 +76,10 @@ public void GenerateIcons()
g.fillRect(24, 18, 4, 2);
// 2 = white
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -103,20 +97,20 @@ public void GenerateIcons()
g.fillRect(24, 18, 4, 2);
currentIcon = icons[color].getImage();
if (charge==0)
if (charge == 0) {
currentIcon = icons[2].getImage();
}
}
public void Decorate()
{
if (charge>0)
{
public void Decorate() {
if (charge > 0) {
color = 1 - color;
currentIcon = icons[color].getImage();
}
else
else {
currentIcon = icons[2].getImage();
}
}
}

View File

@ -1,45 +1,40 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import com.droidquest.Room;
import com.droidquest.materials.Material;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.ImageIcon;
public class Disk extends Item {
private transient Room helpRoom = null;
private Color color;
private transient Room helpCamRoom = null;
import com.droidquest.Room;
import com.droidquest.decorations.TextBox;
import com.droidquest.materials.Material;
public class Disk extends Item
{
transient Room helpRoom = null;
Color color;
transient Room helpCamRoom = null;
public Disk(int X, int Y, Room r, Color col, int hr)
{
x=X; y=Y; room=r;
public Disk(int X, int Y, Room r, Color col, int hr) {
x = X;
y = Y;
room = r;
color = col;
width=28; height=24;
width = 28;
height = 24;
grabbable = true;
helpRoom = (Room) level.rooms.elementAt(hr);
helpRoom = level.rooms.elementAt(hr);
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -55,26 +50,22 @@ public void GenerateIcons()
}
public void writeRef(ObjectOutputStream s) throws IOException
{
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.rooms.indexOf(helpRoom));
}
public void readRef(ObjectInputStream s) throws IOException
{
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
helpRoom = (Room) level.FindRoom(s.readInt());
helpRoom = level.FindRoom(s.readInt());
}
public void IsDropped()
{
public void IsDropped() {
int bigX = (x + width / 2) / 28;
int bigY = (y + height / 2) / 32;
Material mat = room.MaterialArray[bigY][bigX];
if (mat.getClass().toString().endsWith("Monitor"))
{
if (mat.getClass().toString().endsWith("Monitor")) {
helpCamRoom = level.helpCam.room; // Temporary storage
level.helpCam.room = helpRoom;
level.currentViewer = level.helpCam;
@ -82,10 +73,10 @@ public void IsDropped()
}
}
public boolean CanBePickedUp(Item item)
{
if (level.helpCam.room == room)
public boolean CanBePickedUp(Item item) {
if (level.helpCam.room == room) {
level.helpCam.room = helpCamRoom;
}
level.currentViewer = level.player;
return true;
}

View File

@ -8,29 +8,27 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class ElevatorKey extends Item
{
boolean jumping=true;
public class ElevatorKey extends Item {
private boolean jumping = true;
public ElevatorKey(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=32;
public ElevatorKey(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = true;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -48,13 +46,12 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (carriedBy!=null)
public void Animate() {
if (carriedBy != null) {
jumping = false;
}
if (jumping==true)
{
if (jumping) {
x = level.random.nextInt(8 * 28) + 28;
y = level.random.nextInt(2 * 32) + (8 * 32);
}

View File

@ -5,35 +5,33 @@ import com.droidquest.decorations.Arrow;
import com.droidquest.materials.ElevatorOutPortal;
import com.droidquest.materials.Switch;
public class ElevatorSwitch extends Switch
{
int animationState=0;
public class ElevatorSwitch extends Switch {
private int animationState = 0;
// 0=open
// 1=closing
// 2=closing
// 3=switch arrow, switch outRoom
// 4=opening
// 5=opening
transient static Room room;
private transient static Room room;
public ElevatorSwitch()
{
public ElevatorSwitch() {
super(Switch.ROT_LEFT);
}
public void TouchedByItem(Item item)
{
public void TouchedByItem(Item item) {
room = item.room;
if (animationState==0)
if (animationState == 0) {
animationState = 1;
}
}
public void Animate()
{
public void Animate() {
super.Animate();
switch (animationState)
{
case 0: value =false; break;
switch (animationState) {
case 0:
value = false;
break;
case 1:
// Play sound
value = true;
@ -47,21 +45,17 @@ public void Animate()
animationState++;
break;
case 3:
if (ElevatorOutPortal.outRoom == (Room) level.rooms.elementAt(11))
{
for (int a=0; a<room.arrows.size(); a++)
{
Arrow arrow = (Arrow) room.arrows.elementAt(a);
if (ElevatorOutPortal.outRoom == level.rooms.elementAt(11)) {
for (int a = 0; a < room.arrows.size(); a++) {
Arrow arrow = room.arrows.elementAt(a);
arrow.direction = Arrow.DIR_UP;
arrow.y = 66;
}
ElevatorOutPortal.SetOutRoom(9);
}
else
{
for (int a=0; a<room.arrows.size(); a++)
{
Arrow arrow = (Arrow) room.arrows.elementAt(a);
else {
for (int a = 0; a < room.arrows.size(); a++) {
Arrow arrow = room.arrows.elementAt(a);
arrow.direction = Arrow.DIR_DOWN;
arrow.y = 94;
}

View File

@ -3,49 +3,43 @@ package com.droidquest.items;
import com.droidquest.Room;
import com.droidquest.levels.Level;
public class EndAnimation extends HiddenCamera
{
public class EndAnimation extends HiddenCamera {
int animationState=0;
transient boolean playsong = false;
private int animationState = 0;
private transient boolean playsong = false;
public EndAnimation(Room r)
{
public EndAnimation(Room r) {
super(r);
}
public void Animate()
{
if (playsong==false)
{
public void Animate() {
if (!playsong) {
level.PlaySound(room, Level.ENDMUSICSOUND);
playsong = true;
}
animationState = 1 - animationState;
for(int a=0; a<20; a++)
if (a%2==animationState)
{
for (int a = 0; a < 20; a++) {
if (a % 2 == animationState) {
room.SetMaterial(a, 0, 0);
room.SetMaterial(a, 11, 1);
}
else
{
else {
room.SetMaterial(a, 0, 1);
room.SetMaterial(a, 11, 0);
}
}
for(int a=0; a<12; a++)
if (a%2==animationState)
{
for (int a = 0; a < 12; a++) {
if (a % 2 == animationState) {
room.SetMaterial(0, a, 0);
room.SetMaterial(19, a, 1);
}
else
{
else {
room.SetMaterial(0, a, 1);
room.SetMaterial(19, a, 0);
}
}
}
}

View File

@ -4,36 +4,34 @@ import java.awt.Color;
import com.droidquest.decorations.TextBox;
public class EnergyButton extends Button
{
public class EnergyButton extends Button {
transient NotAButton nb = null;
int animationState=0;
private int animationState = 0;
public EnergyButton()
{
public EnergyButton() {
super(0, 0, null, new Color(255, 128, 0));
grabbable = false;
}
public void Animate()
{
if (animationState==0)
if (room != null)
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (Overlaps(item))
{
public void Animate() {
if (animationState == 0) {
if (room != null) {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (Overlaps(item)) {
animationState = 1;
nb.animationState = 51;
for (int b=1; b<19; b++)
for (int b = 1; b < 19; b++) {
room.downRoom.SetMaterial(b, 4, 0);
TextBox line = (TextBox) room.downRoom.textBoxes.elementAt(1);
}
TextBox line = room.downRoom.textBoxes.elementAt(1);
line.textString = " ";
}
}
}
}
}
}

View File

@ -8,29 +8,26 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class F12Form extends Item
{
transient GateKeeper gk=null;
public class F12Form extends Item {
private transient GateKeeper gk = null;
public F12Form(int X, int Y, Room r)
{
x=X; y=Y;
public F12Form(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28; height = 32;
width = 28;
height = 32;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -50,22 +47,21 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void IsDropped()
{
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("GateKeeper"))
public void IsDropped() {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("GateKeeper")) {
gk = (GateKeeper) item;
}
}
if (gk != null)
if (Overlaps(gk))
{
if (gk != null) {
if (Overlaps(gk)) {
gk.PicksUp(this);
gk.behavior = 1;
}
}
}
}

View File

@ -4,38 +4,30 @@ import java.awt.Color;
import com.droidquest.Room;
public class FFButton extends Button
{
transient GenericRobot[] robots = null;
public class FFButton extends Button {
private transient GenericRobot[] robots = null;
public FFButton(int X, int Y, Room r)
{
public FFButton(int X, int Y, Room r) {
super(X, Y, r, Color.white);
grabbable = false;
}
public void Animate()
{
if (robots==null)
{
public void Animate() {
if (robots == null) {
robots = new GenericRobot[3];
int rcount = 0;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item instanceof GenericRobot)
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item instanceof GenericRobot) {
robots[rcount] = (GenericRobot) item;
rcount++;
}
}
}
else
{
for (int a=0; a<3; a++)
if (robots[a]!=null)
if (Overlaps(robots[a]))
{
else {
for (int a = 0; a < 3; a++) {
if (robots[a] != null) {
if (Overlaps(robots[a])) {
room.SetMaterial(0, 4, 0);
room.SetMaterial(0, 5, 0);
room.SetMaterial(0, 6, 0);
@ -51,5 +43,7 @@ public void Animate()
}
}
}
}
}
}

View File

@ -11,20 +11,20 @@ import com.droidquest.Room;
import com.droidquest.devices.PrototypeChip;
import com.droidquest.levels.Level;
public class Factory extends Item
{
Item target;
public class Factory extends Item {
private Item target;
public Factory (int X, int Y, Room r, Item t)
{
x=X; y=Y; room=r;
public Factory(int X, int Y, Room r, Item t) {
x = X;
y = Y;
room = r;
target = t;
width=28; height=26;
width = 28;
height = 26;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
target.GenerateIcons();
target.Decorate();
width = Math.max(((BufferedImage) target.currentIcon).getWidth() + 8, 18);
@ -32,12 +32,10 @@ public void GenerateIcons()
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -55,13 +53,14 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
public boolean CanBePickedUp(Item i) {
Item item;
if (target instanceof PrototypeChip)
if (target instanceof PrototypeChip) {
item = new PrototypeChip(0, 0, null);
else
}
else {
item = (Item) target.clone();
}
item.GenerateIcons();
item.x = (560 - item.width) / 2;
item.y = (384 - item.height) / 2;

View File

@ -1,44 +1,38 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.devices.StormShield;
public class GateKeeper extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class GateKeeper extends Item {
int behavior = 0;
// 0= pause
// 1= Go to trash, delete F-12, delete StormShield
int goToX=2*28+14;
int goToY=8*32;
private int goToX = 2 * 28 + 14;
private int goToY = 8 * 32;
public GateKeeper(int X, int Y, Room r)
{
x=X; y=Y;
public GateKeeper(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width=52; height=38;
width = 52;
height = 38;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -68,41 +62,38 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (behavior ==1)
{
if (x != goToX && y != goToY)
{
if (x != goToX)
{
public void Animate() {
if (behavior == 1) {
if (x != goToX && y != goToY) {
if (x != goToX) {
int diff = Math.abs(goToX - x);
int dir = diff / (goToX - x);
if (diff > 2) diff = 2;
MoveRight(diff * dir);
if (diff > 2) {
diff = 2;
}
if (y != goToY)
{
moveRight(diff * dir);
}
if (y != goToY) {
int diff = Math.abs(goToY - y);
int dir = diff / (goToY - y);
if (diff > 2) diff = 2;
MoveDown(diff * dir);
if (diff > 2) {
diff = 2;
}
moveDown(diff * dir);
}
}
else
{
else {
behavior = 0;
level.items.removeElement(carrying);
carrying = null;
StormShield ss = null;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("StormShield"))
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("StormShield")) {
ss = (StormShield) item;
}
if (ss!=null)
{
}
if (ss != null) {
ss.SetRoom(null); // Removes wires
level.items.removeElement(ss);
}

View File

@ -1,27 +1,17 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Spark;
import com.droidquest.devices.Device;
import com.droidquest.levels.Level;
import com.droidquest.materials.BatteryIn;
import com.droidquest.materials.BatteryOut;
import com.droidquest.materials.Material;
import com.droidquest.materials.PeriscopeDown;
import com.droidquest.materials.PeriscopeUp;
import com.droidquest.materials.*;
public class GenericRobot extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class GenericRobot extends Item {
public Device devices[] = new Device[10];
public boolean topBumper;
public boolean bottomBumper;
@ -35,29 +25,32 @@ public boolean rightThruster;
public boolean antenna;
public boolean broadcasting;
public int grabber; // use Port.ROT_ for rotations.
Color color;
private Color color;
public boolean periscope;
public int periscopeAnimation;
transient public boolean oldTopBumper;
transient public boolean oldBottomBumper;
transient public boolean oldLeftBumper;
transient public boolean oldRightBumper;
transient ImageIcon images[];
private int periscopeAnimation;
private transient boolean oldTopBumper;
private transient boolean oldBottomBumper;
private transient boolean oldLeftBumper;
private transient boolean oldRightBumper;
private transient ImageIcon[] images;
public GenericRobot(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r;
GenericRobot(int X, int Y, Room r, Color c) {
x = X;
y = Y;
room = r;
grabber = 1;
charge = 100000;
color = c;
// orgX = 32; orgY = 24;
orgX = 14; orgY = 24;
orgX = 14;
orgY = 24;
// orgX = 14; orgY = 0;
width = 56; height = 42;
width = 56;
height = 42;
InternalRoom = new Room();
int[][] table = {
InternalRoom.RoomArray = new int[][]{
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
@ -71,7 +64,6 @@ public GenericRobot(int X, int Y, Room r, Color c)
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0}
};
InternalRoom.RoomArray = table;
Material mat1 = Material.FindSimiliar(new Material(color, false, true));
int mat1Index = level.materials.indexOf(mat1);
@ -86,9 +78,13 @@ public GenericRobot(int X, int Y, Room r, Color c)
((BatteryIn) battIn).robot = this;
((BatteryOut) battOut).robot = this;
for (int rY=0; rY<12; rY++)
for (int rX=0; rX<20; rX++)
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index;
for (int rY = 0; rY < 12; rY++) {
for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.RoomArray[2][17] = perUpIndex;
InternalRoom.RoomArray[2][16] = perDownIndex;
InternalRoom.RoomArray[3][17] = perDownIndex;
@ -116,12 +112,13 @@ public GenericRobot(int X, int Y, Room r, Color c)
Animate();
}
public void GenerateIcons()
{
public void GenerateIcons() {
// orgX = 14; orgY = 24;
// width = 56; height = 42;
orgX = 14; orgY = 24;
width = 56; height = 44;
orgX = 14;
orgY = 24;
width = 56;
height = 44;
icons = new ImageIcon[1];
// icons[0]= new ImageIcon(new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR));
icons[0] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
@ -129,17 +126,14 @@ public void GenerateIcons()
((BatteryIn) level.materials.elementAt(InternalRoom.RoomArray[9][3])).robot = this;
((BatteryOut) level.materials.elementAt(InternalRoom.RoomArray[9][2])).robot = this;
images = new ImageIcon[10];
for (int a=0; a<10; a++)
{
for (int a = 0; a < 10; a++) {
// images[a] = new ImageIcon( new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR));
images[a] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -149,8 +143,7 @@ public void GenerateIcons()
// g2.clearRect(0,0,122,92);
g2.clearRect(0, 0, 84, 84);
switch (a)
{
switch (a) {
case 0: // Robot Body
{
g.setColor(color);
@ -293,58 +286,56 @@ public void GenerateIcons()
}
}
public void Animate()
{
public void Animate() {
// Do Thrusting
if (charge>0 && level.electricity && (carriedBy == null) && thrusterPower)
{
if (topThruster)
MoveDown(8);
if (rightThruster)
MoveLeft(8);
if (bottomThruster)
MoveUp(8);
if (leftThruster)
MoveRight(8);
if (charge > 0 && level.electricity && (carriedBy == null) && thrusterPower) {
if (topThruster) {
moveDown(8);
}
if (rightThruster) {
moveLeft(8);
}
if (bottomThruster) {
moveUp(8);
}
if (leftThruster) {
moveRight(8);
}
}
if (charge>0 && level.electricity && thrusterPower)
{
if (charge > 0 && level.electricity && thrusterPower) {
Dimension d = GetXY();
int X = d.width;
int Y = d.height;
if (topThruster)
{
if (topThruster) {
level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 24, 0, -4, room));
level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 24, 0, -4, room));
charge -= 2;
}
if (rightThruster)
{
if (rightThruster) {
level.sparks.addElement(new Spark(X - orgX + 74, Y - orgY + 36 + level.random.nextInt(20), 4, 0, room));
level.sparks.addElement(new Spark(X - orgX + 74, Y - orgY + 36 + level.random.nextInt(20), 4, 0, room));
charge -= 2;
}
if (bottomThruster)
{
if (bottomThruster) {
level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 64, 0, 4, room));
level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 64, 0, 4, room));
charge -= 2;
}
if (leftThruster)
{
if (leftThruster) {
level.sparks.addElement(new Spark(X - orgX + 14, Y - orgY + 36 + level.random.nextInt(20), -4, 0, room));
level.sparks.addElement(new Spark(X - orgX + 14, Y - orgY + 36 + level.random.nextInt(20), -4, 0, room));
charge -= 2;
}
charge--;
if (charge<0) charge=0;
if (charge < 0) {
charge = 0;
}
}
// Draw Antenna sparks around Broadcasting Antenna
if (broadcasting && level.electricity)
{
if (broadcasting && level.electricity) {
Dimension d = GetXY();
level.sparks.addElement(new Spark(d.width - orgX + 34, d.height - orgY + 10,
level.random.nextInt(9) - 4,
@ -353,20 +344,21 @@ public void Animate()
}
// Make sounds
if (topBumper)
if (oldTopBumper != topBumper)
if (topBumper && !oldTopBumper) {
level.PlaySound(room, Level.BUMPSOUND);
if (bottomBumper)
if (oldBottomBumper != bottomBumper)
}
if (bottomBumper && !oldBottomBumper) {
level.PlaySound(room, Level.BUMPSOUND);
if (rightBumper)
if (oldRightBumper != rightBumper)
}
if (rightBumper && !oldRightBumper) {
level.PlaySound(room, Level.BUMPSOUND);
if (leftBumper)
if (oldLeftBumper != leftBumper)
}
if (leftBumper && !oldLeftBumper) {
level.PlaySound(room, Level.BUMPSOUND);
if (broadcasting && level.electricity)
}
if (broadcasting && level.electricity) {
level.PlaySound(room, Level.BEEPSOUND);
}
oldTopBumper = topBumper;
oldBottomBumper = bottomBumper;
oldRightBumper = rightBumper;
@ -374,16 +366,13 @@ public void Animate()
}
public void Decorate()
{
public void Decorate() {
// Paint background
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -396,40 +385,49 @@ public void Decorate()
g.drawImage(images[0].getImage(), 0, 0, level);
// Draw Bumpers
if (topBumper)
if (topBumper) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(Color.white);
}
g.fillRect(32, 24, 22, 2);
if (bottomBumper)
if (bottomBumper) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(Color.white);
}
g.fillRect(32, 66, 22, 2);
if (leftBumper)
if (leftBumper) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(Color.white);
}
g.fillRect(12, 36, 4, 20);
if (rightBumper)
if (rightBumper) {
g.setColor(new Color(255, 128, 0));
else
}
else {
g.setColor(Color.white);
}
g.fillRect(70, 36, 4, 20);
// Draw Antenna
if (antenna)
if (antenna) {
g.drawImage(images[6].getImage(), 0, 0, level);
else
}
else {
g.drawImage(images[5].getImage(), 0, 0, level);
}
// Draw Grabber
g.setColor(Color.white);
switch (grabber)
{
switch (grabber) {
case Port.ROT_UP:
g.drawImage(images[1].getImage(), 0, 0, level);
break;
@ -446,41 +444,32 @@ public void Decorate()
// Draw Periscope
// if (periscope)
if (level.currentViewer == this)
{
if (level.currentViewer == this) {
periscopeAnimation++;
if (periscopeAnimation == 32) periscopeAnimation =0;
if (periscopeAnimation <8)
if (periscopeAnimation == 32) {
periscopeAnimation = 0;
}
if (periscopeAnimation < 8) {
g.drawImage(images[7].getImage(), 0, 0, level);
}
if ((periscopeAnimation >= 8 && periscopeAnimation < 16)
|| periscopeAnimation >=24)
|| periscopeAnimation >= 24) {
g.drawImage(images[8].getImage(), 0, 0, level);
if (periscopeAnimation >=16 && periscopeAnimation <24)
}
if (periscopeAnimation >= 16 && periscopeAnimation < 24) {
g.drawImage(images[9].getImage(), 0, 0, level);
}
}
// g.setColor(Color.magenta);
// g.drawRect(orgX+leftPortal.x, orgY+leftPortal.y,
// leftPortal.width+28, leftPortal.height+32);
// g.drawRect(orgX+rightPortal.x, orgY+rightPortal.y,
// rightPortal.width+28, rightPortal.height+32);
// g.drawRect(orgX+upPortal.x, orgY+upPortal.y,
// upPortal.width+28, upPortal.height+32);
// g.drawRect(orgX+downPortal.x, orgY+downPortal.y,
// downPortal.width+28, downPortal.height+32);
}
public boolean CanBePickedUp(Item item)
{
if (item.getClass().toString().endsWith("Robot"))
return false;
else
return super.CanBePickedUp(item);
public boolean CanBePickedUp(Item item) {
return !item.getClass().toString().endsWith("Robot") && super.CanBePickedUp(item);
}
public void Erase()
{
public void Erase() {
super.Erase();
devices = null;
}

View File

@ -11,25 +11,25 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.levels.Level;
public class Ghost extends Item
{
int animationState = 0; // 0=Right, 1=Down, 2=Left, 3=Up
public class Ghost extends Item {
private int animationState = 0; // 0=Right, 1=Down, 2=Left, 3=Up
// x values are 42, 154, 266, 378
// y values are 58, 186, 314
transient boolean searched=false;
transient Item robot[];
private transient boolean searched = false;
private transient Item[] robot;
public Ghost(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width = 28; height = 32;
public Ghost(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
robot = new Item[4];
icons = new ImageIcon[4];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -37,14 +37,11 @@ public void GenerateIcons()
icons[2] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
for (int a=0; a<4; a++)
{
try
{
for (int a = 0; a < 4; a++) {
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -59,8 +56,7 @@ public void GenerateIcons()
g.fillOval(4, 8, 8, 8);
g.fillOval(16, 8, 8, 8);
g.setColor(Color.black);
switch(a)
{
switch (a) {
case 0: // Right
g.fillOval(9, 10, 4, 4);
g.fillOval(21, 10, 4, 4);
@ -82,8 +78,7 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
public void Animate() {
// Positions: There are 4x3=12 "nodes" where the ghost travels to
// and from. Every time the ghost reaches a node position, it looks
// around for any robots in the area. If it sees a robot it then
@ -91,14 +86,11 @@ public void Animate()
// penalty box and drained of energy. If no robot is found it moves
// in a random direction.
if (!searched)
{
if (!searched) {
int rcounter = 0;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item instanceof GenericRobot)
{
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item instanceof GenericRobot) {
robot[rcounter] = item;
rcounter++;
}
@ -108,82 +100,87 @@ public void Animate()
boolean flag = false;
if (((x == 42) || (x == 154) || (x == 266) || (x == 378))
&& ( (y==48) || (y==176) || (y==304)) )
&& ((y == 48) || (y == 176) || (y == 304))) {
flag = true;
}
if (flag)
{
if (flag) {
boolean decision = false;
for (int a=0; a<robot.length; a++)
{
if (robot[a] != null)
if (robot[a].room == room)
{
Dimension d = robot[a].GetXY();
if (d.width < 14*28)
{
int dx = (d.width + robot[a].width/2) - (x+width/2);
int dy = (d.height + robot[a].height/2) - (y+height/2);
if ((Math.abs(dx)<56) || (Math.abs(dy)<64))
{
for (Item aRobot : robot) {
if (aRobot != null) {
if (aRobot.room == room) {
Dimension d = aRobot.GetXY();
if (d.width < 14 * 28) {
int dx = (d.width + aRobot.width / 2) - (x + width / 2);
int dy = (d.height + aRobot.height / 2) - (y + height / 2);
if ((Math.abs(dx) < 56) || (Math.abs(dy) < 64)) {
decision = true;
if (Math.abs(dx)<56)
{
if (dy>0)
if (Math.abs(dx) < 56) {
if (dy > 0) {
animationState = 1;
else
}
else {
animationState = 3;
}
else
{
if (dx>0)
}
else {
if (dx > 0) {
animationState = 0;
else
}
else {
animationState = 2;
}
}
}
}
}
if (!decision)
{
}
}
if (!decision) {
boolean good;
int backwards = (animationState + 2) % 4;
do
{
do {
good = true;
animationState = level.random.nextInt(4);
if (animationState==0 && x==378) good=false;
if (animationState==1 && y==304) good=false;
if (animationState==2 && x== 42) good=false;
if (animationState==3 && y== 48) good=false;
if (animationState==backwards) good=false;
if (animationState == 0 && x == 378) {
good = false;
}
if (animationState == 1 && y == 304) {
good = false;
}
if (animationState == 2 && x == 42) {
good = false;
}
if (animationState == 3 && y == 48) {
good = false;
}
if (animationState == backwards) {
good = false;
}
}
while (!good);
}
}
switch (animationState)
{
switch (animationState) {
case 0: // Right
MoveRight(4);
moveRight(4);
break;
case 1: // Down
MoveDown(4);
moveDown(4);
break;
case 2: // Left
MoveLeft(4);
moveLeft(4);
break;
case 3: // Up
MoveUp(4);
moveUp(4);
break;
}
currentIcon = icons[animationState].getImage();
for (int a=0; a<4; a++)
if (robot[a] != null)
if (Overlaps(robot[a]))
{
for (int a = 0; a < 4; a++) {
if (robot[a] != null) {
if (Overlaps(robot[a])) {
robot[a].charge = 0;
level.PlaySound(room, Level.DISCHARGESOUND);
robot[a].x = 16 * 28 + 14;
@ -191,3 +188,5 @@ public void Animate()
}
}
}
}
}

View File

@ -1,37 +1,32 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Handle extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public class Handle extends Item {
// Handle used to pull sliding wall
public Handle(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=12;
public Handle(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 12;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -46,38 +41,33 @@ public class Handle extends Item
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
if (item != level.player) return false;
public boolean CanBePickedUp(Item item) {
if (item != level.player) {
return false;
}
PicksUp(item);
level.player = this;
return false;
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_RIGHT)
{
if (x<15*28)
{
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == e.VK_RIGHT) {
if (x < 15 * 28) {
room.SetMaterial(x / 28 - 12, 4, 0);
MoveRight(28);
moveRight(28);
room.SetMaterial(x / 28 - 1, 4, 8);
}
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (x>13*28)
{
if (e.getKeyCode() == e.VK_LEFT) {
if (x > 13 * 28) {
room.SetMaterial(x / 28 - 13, 4, 8);
room.SetMaterial(x / 28 - 1, 4, 0);
MoveLeft(28);
moveLeft(28);
}
}
if (e.getKeyCode() == e.VK_SPACE)
{
if (e.getKeyCode() == e.VK_SPACE) {
level.player = carrying;
Drops();
room.SetMaterial(1, 4, 8);

View File

@ -9,30 +9,28 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Hexagon extends Item
{
Color color;
public class Hexagon extends Item {
private Color color;
public Hexagon(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r;
width=28; height=28;
public Hexagon(int X, int Y, Room r, Color c) {
x = X;
y = Y;
room = r;
width = 28;
height = 28;
color = c;
editable = true;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}

View File

@ -6,17 +6,17 @@ import javax.swing.JPanel;
import com.droidquest.Room;
public class HiddenCamera extends Item
{
public HiddenCamera(Room r)
{
x=0; y=0;
public class HiddenCamera extends Item {
public HiddenCamera(Room r) {
x = 0;
y = 0;
room = r;
width=0; height=0;
width = 0;
height = 0;
grabbable = false;
}
public void Draw(Graphics g, JPanel jp)
{}
public void Draw(Graphics g, JPanel jp) {
}
}

View File

@ -1,13 +1,16 @@
package com.droidquest.items;
public class Initializer extends Item
{
public Initializer()
{
width=0; height=0; x=0; y=0; room=null;
public class Initializer extends Item {
protected Initializer() {
width = 0;
height = 0;
x = 0;
y = 0;
room = null;
}
public void Init() {}
public void Init() {
}
}

File diff suppressed because it is too large Load Diff

View File

@ -9,30 +9,29 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Key extends Item
{
public class Key extends Item {
// Generic Key, defined by it's color.
public Color color;
public Key(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r; color = c;
width=26; height=8;
public Key(int X, int Y, Room r, Color c) {
x = X;
y = Y;
room = r;
color = c;
width = 26;
height = 8;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}

View File

@ -9,26 +9,24 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Magnet extends Item
{
public Magnet(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=20;
public class Magnet extends Item {
public Magnet(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 20;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}

View File

@ -10,12 +10,10 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster;
public class MasterRobot extends GenericRobot
{
public class MasterRobot extends GenericRobot {
private int scan;
public MasterRobot(int X, int Y, Room r)
{
public MasterRobot(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
scan = 0;
Animate();
@ -29,21 +27,19 @@ public MasterRobot(int X, int Y, Room r)
devices[7] = new Bumper(28, 134, InternalRoom, Port.ROT_LEFT, Color.white);
devices[8] = new Antenna(64, 70, InternalRoom, Color.white);
devices[9] = new Grabber(126, 44, InternalRoom, Color.white);
for (int a=0; a<10; a++)
for (int a = 0; a < 10; a++) {
level.items.addElement(devices[a]);
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -51,8 +47,7 @@ public void Decorate()
g.fillRect(orgX + 16, orgY + 12, 26, 20);
g.setColor(new Color(255, 128, 0));
switch(scan)
{
switch (scan) {
case 0:
g.fillRect(orgX + 28, orgY + 18, 2, 8);
scan = 1;

View File

@ -10,38 +10,35 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.decorations.TextBox;
public class MazeControl extends Item
{
public class MazeControl extends Item {
static int mazeWidth = 4;
static int mazeHeight = 2;
int direction;
private int direction;
public static final int DIR_UP = 0;
public static final int DIR_RIGHT = 1;
public static final int DIR_DOWN = 2;
public static final int DIR_LEFT = 3;
public MazeControl(int X, int Y, Room r, int dir)
{
x=X; y=Y;
public MazeControl(int X, int Y, Room r, int dir) {
x = X;
y = Y;
room = r;
width=26; height=26;
width = 26;
height = 26;
direction = dir;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -49,8 +46,7 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
switch(direction)
{
switch (direction) {
case DIR_UP:
g.fillRect(12, 0, 2, 2);
g.fillRect(10, 2, 6, 2);
@ -95,26 +91,28 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
switch (direction)
{
public boolean CanBePickedUp(Item item) {
switch (direction) {
case DIR_UP:
if (mazeHeight==1) return false;
if (mazeHeight == 1) {
return false;
}
mazeHeight--;
break;
case DIR_DOWN:
mazeHeight++;
break;
case DIR_LEFT:
if (mazeWidth==1) return false;
if (mazeWidth == 1) {
return false;
}
mazeWidth--;
break;
case DIR_RIGHT:
mazeWidth++;
break;
}
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
TextBox tb = room.textBoxes.elementAt(1);
tb.textString = mazeWidth + "x" + mazeHeight;
tb.x = (560 - 12 * tb.textString.length()) / 2;

View File

@ -1,99 +1,92 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class MazeCreator extends Button
{
public MazeCreator(int X, int Y, Room r)
{
import java.awt.*;
public class MazeCreator extends Button {
public MazeCreator(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
}
public boolean CanBePickedUp(Item item)
{
public boolean CanBePickedUp(Item item) {
Room mazeEntrance = null;
for (int a=0; a<level.rooms.size(); a++)
{
Room r = (Room) level.rooms.elementAt(a);
if (r.downRoom != null)
if (!r.editable && r.downRoom.editable)
for (int a = 0; a < level.rooms.size(); a++) {
Room r = level.rooms.elementAt(a);
if (r.downRoom != null) {
if (!r.editable && r.downRoom.editable) {
mazeEntrance = r;
}
for (int a=0; a<level.items.size(); a++)
{
Item i = (Item) level.items.elementAt(a);
if (i.room != null)
if (i.room.editable)
i.room = room;
}
}
for (int a=0; a<level.rooms.size(); a++)
{
Room r = (Room) level.rooms.elementAt(a);
if (r.editable)
{
for (int a = 0; a < level.items.size(); a++) {
Item i = level.items.elementAt(a);
if (i.room != null) {
if (i.room.editable) {
i.room = room;
}
}
}
for (int a = 0; a < level.rooms.size(); a++) {
Room r = level.rooms.elementAt(a);
if (r.editable) {
level.rooms.removeElement(r);
a--;
}
}
if(mazeEntrance != null) {
mazeEntrance.downRoom = null;
}
for (int Y=0; Y<MazeControl.mazeHeight; Y++)
for (int X=0; X<MazeControl.mazeWidth; X++)
{
for (int Y = 0; Y < MazeControl.mazeHeight; Y++) {
for (int X = 0; X < MazeControl.mazeWidth; X++) {
Room newRoom = new Room();
newRoom.editable = true;
newRoom.GenerateArray();
level.rooms.addElement(newRoom);
if (Y==0)
{
for (int a=0; a<20; a++)
if (Y == 0) {
for (int a = 0; a < 20; a++) {
newRoom.SetMaterial(a, 0, 3);
}
else
{
Room UpRoom = (Room) level.rooms.elementAt(level.rooms.size()-1-MazeControl.mazeWidth);
}
else {
Room UpRoom = level.rooms.elementAt(level.rooms.size() - 1 - MazeControl.mazeWidth);
UpRoom.downRoom = newRoom;
newRoom.upRoom = UpRoom;
}
if (Y==MazeControl.mazeHeight-1)
{
for (int a=0; a<20; a++)
if (Y == MazeControl.mazeHeight - 1) {
for (int a = 0; a < 20; a++) {
newRoom.SetMaterial(a, 11, 3);
}
}
if (X==0)
{
for (int a=0; a<12; a++)
if (X == 0) {
for (int a = 0; a < 12; a++) {
newRoom.SetMaterial(0, a, 3);
}
else
{
Room LeftRoom = (Room) level.rooms.elementAt(level.rooms.size()-2);
}
else {
Room LeftRoom = level.rooms.elementAt(level.rooms.size() - 2);
LeftRoom.rightRoom = newRoom;
newRoom.leftRoom = LeftRoom;
}
if (X==MazeControl.mazeWidth-1)
{
for (int a=0; a<12; a++)
if (X == MazeControl.mazeWidth - 1) {
for (int a = 0; a < 12; a++) {
newRoom.SetMaterial(19, a, 3);
}
}
if (X==0 && Y==0)
{
if (X == 0 && Y == 0) {
if(mazeEntrance != null) {
mazeEntrance.downRoom = newRoom;
}
newRoom.upRoom = mazeEntrance;
newRoom.SetMaterial(1, 0, 0);
}
}
}
return false;
}

View File

@ -3,33 +3,23 @@ package com.droidquest.items;
import com.droidquest.materials.Switch;
public class MazeLock extends Switch
{
transient static Item paintbrush;
public class MazeLock extends Switch {
private transient static Item paintbrush;
public MazeLock()
{
public MazeLock() {
super(Switch.ROT_DOWN);
}
public void TouchedByItem(Item item)
{
if (paintbrush==null)
public void TouchedByItem(Item item) {
if (paintbrush == null) {
paintbrush = level.paintbrush;
}
if (!value)
{
if (!value) {
level.paintbrush = null;
value = true;
}
else
{
// for (int a=0; a<level.items.size(); a++)
// {
// Item i = (Item) level.items.elementAt(a);
// if (i instanceof PaintBrush)
// level.paintbrush = i;
// }
else {
level.paintbrush = paintbrush;
value = false;
}

View File

@ -9,30 +9,28 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class NotAButton extends Item
{
public class NotAButton extends Item {
int animationState = 0;
transient EnergyButton eb=null;
private transient EnergyButton eb = null;
public NotAButton(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=26;
public NotAButton(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -53,43 +51,42 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (eb==null)
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if(item instanceof EnergyButton)
{
public void Animate() {
if (eb == null) {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item instanceof EnergyButton) {
eb = (EnergyButton) item;
eb.nb = this;
}
}
}
if (animationState<51)
{
if (animationState < 51) {
animationState++;
int dx = level.random.nextInt(11) - 5;
int dy = level.random.nextInt(11) - 5;
if (x+dx>28 && x+dx<(19*28))
if (x + dx > 28 && x + dx < (19 * 28)) {
x += dx;
if (y+dy>32 && y+dy<(11*32))
}
if (y + dy > 32 && y + dy < (11 * 32)) {
y += dy;
if (animationState==1)
{
eb.x=x; eb.y=y;
}
if (animationState == 1) {
eb.x = x;
eb.y = y;
eb.room = room;
room = null;
}
if (animationState==2)
{
if (animationState == 2) {
room = eb.room;
eb.room = null;
}
if (animationState==50)
if (animationState == 50) {
animationState = 0;
}
}
}
}

View File

@ -10,10 +10,8 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster;
public class OrangeRobot extends GenericRobot
{
public OrangeRobot(int X, int Y, Room r)
{
public class OrangeRobot extends GenericRobot {
public OrangeRobot(int X, int Y, Room r) {
super(X, Y, r, new Color(255, 128, 0));
Animate();
devices[0] = new Thruster(176, 16, InternalRoom, Port.ROT_UP, Color.white);
@ -26,22 +24,20 @@ public OrangeRobot(int X, int Y, Room r)
devices[7] = new Bumper(28, 134, InternalRoom, Port.ROT_LEFT, Color.white);
devices[8] = new Antenna(64, 70, InternalRoom, Color.white);
devices[9] = new Grabber(126, 44, InternalRoom, Color.white);
for (int a=0; a<10; a++)
for (int a = 0; a < 10; a++) {
level.items.addElement(devices[a]);
}
}
public void Decorate()
{
public void Decorate() {
super.Decorate();
Graphics g;
int cx, cy, cc;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -49,26 +45,31 @@ public void Decorate()
g.setColor(Color.black);
g.fillRect(22, 36, 42, 20);
for (int a=0; a<20; a++)
{
for (int a = 0; a < 20; a++) {
cx = level.random.nextInt(41) + 22;
cy = level.random.nextInt(19) + 36;
cc = level.random.nextInt(7);
switch (cc)
{
case 0: g.setColor(Color.white);
switch (cc) {
case 0:
g.setColor(Color.white);
break;
case 1: g.setColor(Color.red);
case 1:
g.setColor(Color.red);
break;
case 2: g.setColor(new Color(255,128,0));
case 2:
g.setColor(new Color(255, 128, 0));
break;
case 3: g.setColor(Color.yellow);
case 3:
g.setColor(Color.yellow);
break;
case 4: g.setColor(Color.green);
case 4:
g.setColor(Color.green);
break;
case 5: g.setColor(Color.blue);
case 5:
g.setColor(Color.blue);
break;
case 6: g.setColor(Color.magenta);
case 6:
g.setColor(Color.magenta);
break;
}
g.fillRect(cx, cy, 2, 2);

View File

@ -11,26 +11,24 @@ import com.droidquest.Room;
import com.droidquest.devices.Prototype16Chip;
import com.droidquest.levels.Level;
public class PC16Button extends Item
{
public PC16Button(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=26;
public class PC16Button extends Item {
public PC16Button(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -51,8 +49,7 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
public boolean CanBePickedUp(Item i) {
Prototype16Chip newPC = new Prototype16Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);

View File

@ -11,26 +11,24 @@ import com.droidquest.Room;
import com.droidquest.devices.Prototype32Chip;
import com.droidquest.levels.Level;
public class PC32Button extends Item
{
public PC32Button(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=26;
public class PC32Button extends Item {
public PC32Button(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -51,8 +49,7 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
public boolean CanBePickedUp(Item i) {
Prototype32Chip newPC = new Prototype32Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);

View File

@ -11,26 +11,24 @@ import com.droidquest.Room;
import com.droidquest.devices.PrototypeChip;
import com.droidquest.levels.Level;
public class PCButton extends Item
{
public PCButton(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=26;
public class PCButton extends Item {
public PCButton(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -51,8 +49,7 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
public boolean CanBePickedUp(Item i) {
PrototypeChip newPC = new PrototypeChip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);

View File

@ -9,37 +9,35 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Pellet extends Item
{
transient static int pelletCount = 0;
transient boolean counted = false;
public class Pellet extends Item {
private transient static int pelletCount = 0;
private transient boolean counted = false;
public Pellet(int X, int Y, Room r)
{
x=X; y=Y; room = r;
width = 28; height = 28;
public Pellet(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 28;
pelletCount++;
}
public void GenerateIcons()
{
if (!counted)
{
public void GenerateIcons() {
if (!counted) {
int index = level.items.indexOf(this);
if (!(level.items.elementAt(index-1) instanceof Pellet))
if (!(level.items.elementAt(index - 1) instanceof Pellet)) {
pelletCount = 0;
}
counted = true;
pelletCount++;
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -52,28 +50,25 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
if (item instanceof GenericRobot)
{
public boolean CanBePickedUp(Item item) {
if (item instanceof GenericRobot) {
level.items.removeElement(this);
pelletCount--;
if (pelletCount==0)
{
if (pelletCount == 0) {
room.SetMaterial(15, 1, 0);
room.SetMaterial(15, 2, 0);
room.SetMaterial(15, 5, 0);
room.SetMaterial(15, 6, 0);
room.SetMaterial(15, 9, 0);
room.SetMaterial(15, 10, 0);
for (int a=0; a<level.items.size(); a++)
{
Item i = (Item) level.items.elementAt(a);
if (i instanceof Ghost)
for (int a = 0; a < level.items.size(); a++) {
Item i = level.items.elementAt(a);
if (i instanceof Ghost) {
level.items.removeElement(i);
}
}
}
}
return false;
}

View File

@ -10,29 +10,27 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.levels.Level;
public class Polarizer extends Item
{
transient boolean searched=false;
transient boolean found=false;
public class Polarizer extends Item {
private transient boolean searched = false;
private transient boolean found = false;
public Polarizer(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=24; height=32;
public Polarizer(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 24;
height = 32;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -53,30 +51,22 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (!searched)
{
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item instanceof StormCloud)
{
found=true;
}
public void Animate() {
if (!searched) {
for(Item item : level.items) {
searched = true;
if(item != null && item instanceof StormCloud) {
found = true;
break;
}
}
}
if (found)
{
if (room.upRoom == room)
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item instanceof StormCloud)
if (Overlaps(item))
{
if (found) {
if (room.upRoom == room) {
for(Item item : level.items) {
if (item != null && item instanceof StormCloud) {
if (Overlaps(item)) {
level.PlaySound(room, Level.DISCHARGESOUND);
level.LinkRoomsUpDown(36, 4);
room.SetMaterial(8, 0, 0);
@ -85,13 +75,16 @@ public void Animate()
room.SetMaterial(11, 0, 0);
item.room = null;
level.items.removeElement(item);
if (carriedBy != null)
if (carriedBy != null) {
carriedBy.Drops();
}
room = null;
level.items.removeElement(this);
}
}
}
}
}
}
}

View File

@ -9,23 +9,25 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class PowerSwitch extends Item
{
public class PowerSwitch extends Item {
// Controls the power in a Generic Robot
public PowerSwitch(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=32;
public PowerSwitch(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
GenerateIcons();
if (((GenericRobot)room.portalItem).thrusterPower)
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[0].getImage();
}
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -34,12 +36,10 @@ public class PowerSwitch extends Item
Color transparent = new Color(0, 0, 0, 0);
// 0 = Off
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -57,12 +57,10 @@ public class PowerSwitch extends Item
g.fillRect(20, 28, 8, 4);
// 1 = On
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -76,22 +74,26 @@ public class PowerSwitch extends Item
g.fillRect(8, 26, 12, 6);
g.fillRect(20, 28, 8, 4);
if (((GenericRobot)room.portalItem).thrusterPower)
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[0].getImage();
}
}
public boolean CanBePickedUp(Item i)
{
if (i!=level.player)
public boolean CanBePickedUp(Item i) {
if (i != level.player) {
return false;
}
((GenericRobot) room.portalItem).thrusterPower = !((GenericRobot) room.portalItem).thrusterPower;
if (((GenericRobot)room.portalItem).thrusterPower)
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[0].getImage();
}
return false;
}

View File

@ -1,16 +1,12 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Sentry extends Item
{
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Sentry extends Item {
// Base class for all Sentries.
//
// Either individual Sentries will have different Animate functions, or
@ -33,7 +29,7 @@ public class Sentry extends Item
// pairs of XY coordinates. The first two pairs define an area which
// triggers the Sentry to pounce. The third pair defines where the
// sentry will drag the player. This array can have any number of
// sextets of numbers. (The total size of the array must be divisable by
// sextets of numbers. (The total size of the array must be divisible by
// six). Each block of six numbers defines an area and target the sentry
// guards.
//
@ -44,30 +40,36 @@ public class Sentry extends Item
int animation = 0; // 0-3, 1 & 3 = icons[1]
public int behavior = 0; // 0+ for pacing, until pounce and drag. -1=pin.
public int previousBehavior;
int[] pace; // List of pacing cordinates
private int[] pace; // List of pacing coordinates
public int[] protect; // List of areas and targets
int goToX; // Current position pacing towards
int goToY; // ""
int carryToX; // Currently dragging towards
int carryToY; // ""
int pounce; // Pouncing behaviour number (pace.length/2)
int drag; // Dragging behavior number (pounce+1)
boolean smartblock; // Pins robots if they carry the player.
GenericRobot robot; // Robot to pin
private int goToX; // Current position pacing towards
private int goToY; // ""
private int carryToX; // Currently dragging towards
private int carryToY; // ""
private int pounce; // Pouncing behaviour number (pace.length/2)
private int drag; // Dragging behavior number (pounce+1)
private boolean smartblock; // Pins robots if they carry the player.
private GenericRobot robot; // Robot to pin
public Sentry(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=18; orgY = 30;
Sentry(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 18;
orgY = 30;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public Sentry(int X, int Y, Room r, int[] p1, int[] p2, boolean sb)
{
x=X; y=Y; room=r;
width=28; height=18; orgY = 30;
public Sentry(int X, int Y, Room r, int[] p1, int[] p2, boolean sb) {
x = X;
y = Y;
room = r;
width = 28;
height = 18;
orgY = 30;
pace = p1;
protect = p2;
smartblock = sb;
@ -81,8 +83,7 @@ public class Sentry extends Item
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
@ -92,12 +93,10 @@ public class Sentry extends Item
Color transparent = new Color(0, 0, 0, 0);
// 0 = Legs out
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -105,7 +104,9 @@ public class Sentry extends Item
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 24);
@ -130,12 +131,10 @@ public class Sentry extends Item
// 1 = legs mid
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -143,7 +142,9 @@ public class Sentry extends Item
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 28);
@ -166,12 +167,10 @@ public class Sentry extends Item
// 2 = legs in
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -179,7 +178,9 @@ public class Sentry extends Item
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 36);
g.fillRect(8, 12, 12, 24);
@ -198,57 +199,56 @@ public class Sentry extends Item
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
if (animation==3)
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
}
public void Animate()
{
if (carrying==null) animation++;
if (animation==4) animation=0;
if (animation==3)
public void Animate() {
if (carrying == null) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
if (behavior== -2)
{
if (behavior == -2) {
return;
}
if (smartblock)
{
if (smartblock) {
robot = PlayerInRobot(null);
if (robot != null)
{
if (robot != null) {
previousBehavior = 0;
behavior = -1; // Pin Robot
}
else if (carrying!=null && behavior!=drag)
{
else if (carrying != null && behavior != drag) {
Drops();
behavior = previousBehavior;
}
}
if (behavior==-1)
{
if (carrying==null)
{
if (behavior == -1) {
if (carrying == null) {
x = robot.x + robot.width / 2 - width / 2;
y = robot.y + robot.height / 2 - height / 2;
PicksUp(robot);
}
}
if (behavior >=0 && behavior < pounce)
if (protect.length >0 && level.player.room == room)
{
for (int p=0; p<protect.length/6; p++)
{
if (behavior >= 0 && behavior < pounce) {
if (protect.length > 0 && level.player.room == room) {
for (int p = 0; p < protect.length / 6; p++) {
int x1 = protect[p * 6];
int y1 = protect[p * 6 + 1];
int x2 = protect[p * 6 + 2];
@ -259,162 +259,165 @@ public class Sentry extends Item
if (level.player.x >= x1
&& level.player.x <= x2
&& level.player.y >= y1
&& level.player.y <= y2)
{
&& level.player.y <= y2) {
carryToX = x3;
carryToY = y3;
previousBehavior = behavior;
if (previousBehavior >= pounce)
if (previousBehavior >= pounce) {
previousBehavior = 0;
}
behavior = pounce;
}
}
}
}
if (behavior >=0 && behavior < pounce)
{
if (x == goToX && y == goToY)
{
if (behavior >= 0 && behavior < pounce) {
if (x == goToX && y == goToY) {
behavior++;
if (behavior==pounce) behavior=0;
if (behavior == pounce) {
behavior = 0;
}
goToX = pace[behavior * 2];
goToY = pace[behavior * 2 + 1];
}
else
{
if (x != goToX)
{
else {
if (x != goToX) {
int diff = Math.abs(goToX - x);
int dir = diff / (goToX - x);
if (diff > 8) diff = 8;
MoveRight(diff * dir);
if (diff > 8) {
diff = 8;
}
if (y != goToY)
{
moveRight(diff * dir);
}
if (y != goToY) {
int diff = Math.abs(goToY - y);
int dir = diff / (goToY - y);
if (diff > 8) diff = 8;
MoveDown(diff * dir);
if (diff > 8) {
diff = 8;
}
moveDown(diff * dir);
}
}
}
else if (behavior == pounce)
{
if (level.player.room != room)
else if (behavior == pounce) {
if (level.player.room != room) {
behavior = previousBehavior;
if (animation==0)
{
}
if (animation == 0) {
x = level.player.x;
y = level.player.y;
}
if (x != level.player.x)
{
if (x != level.player.x) {
int diff = Math.abs(level.player.x - x);
int dir = diff / (level.player.x - x);
if (diff > 50) diff /= 2;
MoveRight(diff * dir);
if (diff > 50) {
diff /= 2;
}
if (y != level.player.y)
{
moveRight(diff * dir);
}
if (y != level.player.y) {
int diff = Math.abs(level.player.y - y);
int dir = diff / (level.player.y - y);
if (diff > 50) diff /= 2;
MoveDown(diff * dir);
if (diff > 50) {
diff /= 2;
}
if (x == level.player.x && y == level.player.y)
{
moveDown(diff * dir);
}
if (x == level.player.x && y == level.player.y) {
PicksUp(level.player);
// if (level.player.carrying != null)
// level.player.Drops();
behavior = drag;
}
}
else if (behavior == drag)
{
if (x == carryToX && y == carryToY)
{
else if (behavior == drag) {
if (x == carryToX && y == carryToY) {
Drops();
behavior = previousBehavior;
}
else
{
if (x != carryToX)
{
else {
if (x != carryToX) {
int diff = Math.abs(carryToX - x);
int dir = diff / (carryToX - x);
if (diff > 8) diff = 8;
MoveRight(diff * dir);
if (diff > 8) {
diff = 8;
}
if (y != carryToY)
{
moveRight(diff * dir);
}
if (y != carryToY) {
int diff = Math.abs(carryToY - y);
int dir = diff / (carryToY - y);
if (diff > 8) diff = 8;
MoveDown(diff * dir);
if (diff > 8) {
diff = 8;
}
moveDown(diff * dir);
}
}
}
}
public GenericRobot PlayerInRobot(GenericRobot robot)
{
if (robot==null)
{
if (level.player.room.portalItem!=null)
{
if (level.player.room.portalItem.getClass().toString().endsWith("Robot"))
GenericRobot PlayerInRobot(GenericRobot robot) {
if (robot == null) {
if (level.player.room.portalItem != null) {
if (level.player.room.portalItem.getClass().toString().endsWith("Robot")) {
return (PlayerInRobot((GenericRobot) level.player.room.portalItem));
else return (null);
}
else
else {
return (null);
}
else
if (robot.room.portalItem != null)
{
if (robot.room.portalItem.getClass().toString().endsWith("Robot"))
}
else {
return (null);
}
}
else if (robot.room.portalItem != null) {
if (robot.room.portalItem.getClass().toString().endsWith("Robot")) {
return (PlayerInRobot((GenericRobot) robot.room.portalItem));
else
}
else {
return null;
}
else
{
if (robot.room == room)
}
else {
if (robot.room == room) {
return robot;
else
}
else {
return null;
}
}
}
public void MoveUp(int dist)
{
public void moveUp(int dist) {
int newY = y - dist;
if (newY<0)
if (newY < 0) {
newY = 0;
}
y = newY;
}
public void MoveDown(int dist)
{
public void moveDown(int dist) {
int newY = y + dist;
if (newY>383)
if (newY > 383) {
newY = 383;
}
y = newY;
}
public void MoveLeft(int dist)
{
public void moveLeft(int dist) {
int newX = x - dist;
if (newX<0)
if (newX < 0) {
newX = 0;
}
x = newX;
}
public void MoveRight(int dist)
{
public void moveRight(int dist) {
int newX = x + dist;
if (newX>579)
if (newX > 579) {
newX = 579;
}
x = newX;
}

View File

@ -2,8 +2,7 @@ package com.droidquest.items;
import com.droidquest.Room;
public class Sentry3 extends Sentry
{
public class Sentry3 extends Sentry {
// This sentry guards the Sewer Grate room. It walks up and down from
// position (2*28,2*32) to (2*28,8*32). It does not notice the player
// unless the player passes below y=11*32. Then it grabs the player if
@ -15,95 +14,129 @@ public class Sentry3 extends Sentry
// 1=Move Up
// 2=Attack
// 3=Drag
int carryToX;
boolean smart= false; // knows about the player
private int carryToX;
private boolean smart = false; // knows about the player
public Sentry3(int X, int Y, Room r)
{
public Sentry3(int X, int Y, Room r) {
super(X, Y, r);
}
public void Animate()
{
if (behavior<3) animation++;
if (animation==4) animation=0;
if (animation==3)
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
if (level.player.room!=room)
{
if (smart) behavior = previousBehavior;
if (level.player.room != room) {
if (smart) {
behavior = previousBehavior;
}
smart = false;
}
else
if (level.player.y>320)
{
else if (level.player.y > 320) {
carryToX = level.player.x;
smart = true;
}
if (behavior<2 && smart)
if (level.player.y <= 256)
{
if (behavior < 2 && smart) {
if (level.player.y <= 256) {
previousBehavior = behavior;
behavior = 2;
}
}
switch (behavior)
{
switch (behavior) {
case 0:
if (y<256) MoveDown(8);
else behavior=1;
if (x<56) MoveRight(8);
if (x>56) MoveLeft(8);
if (y < 256) {
moveDown(8);
}
else {
behavior = 1;
}
if (x < 56) {
moveRight(8);
}
if (x > 56) {
moveLeft(8);
}
break;
case 1:
if (y>64) MoveUp(8);
else behavior=0;
if (x<56) MoveRight(8);
if (x>56) MoveLeft(8);
if (y > 64) {
moveUp(8);
}
else {
behavior = 0;
}
if (x < 56) {
moveRight(8);
}
if (x > 56) {
moveLeft(8);
}
break;
case 2:
if (level.player.room != room)
{
if (level.player.room != room) {
behavior = previousBehavior;
break;
}
int dx = level.player.x - x;
int dy = level.player.y - y;
if (dx<-50) dx=-50;
if (dx>50) dx=50;
if (dy<-50) dy=-50;
if (dy>50) dy=50;
if (dx<0) MoveLeft(-dx);
if (dx>0) MoveRight(dx);
if (dy<0) MoveUp(-dy);
if (dy>0) MoveDown(dy);
if (dx==0 && dy==0)
{
if (dx < -50) {
dx = -50;
}
if (dx > 50) {
dx = 50;
}
if (dy < -50) {
dy = -50;
}
if (dy > 50) {
dy = 50;
}
if (dx < 0) {
moveLeft(-dx);
}
if (dx > 0) {
moveRight(dx);
}
if (dy < 0) {
moveUp(-dy);
}
if (dy > 0) {
moveDown(dy);
}
if (dx == 0 && dy == 0) {
PicksUp(level.player);
behavior = 3;
}
break;
case 3:
if (y>=320)
{
if (y >= 320) {
Drops();
behavior = previousBehavior;
break;
}
else
{
if (y<312)
MoveDown(8);
else if (y<320)
MoveDown(320-y);
if (x<carryToX)
MoveRight(8);
if (x>carryToX)
MoveLeft(8);
else {
if (y < 312) {
moveDown(8);
}
else if (y < 320) {
moveDown(320 - y);
}
if (x < carryToX) {
moveRight(8);
}
if (x > carryToX) {
moveLeft(8);
}
}
break;
}

View File

@ -9,8 +9,7 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class SentryT1 extends Item
{
public class SentryT1 extends Item {
// This sentry does nothing but pace back and forth in the first tutorial.
// It walks left and right, and switches directions when it hits a wall.
@ -18,20 +17,22 @@ public class SentryT1 extends Item
// 0=Move Left
// 1=Move Right
int animation = 0; // 0-3, 1 & 3 = icons[1]
int behavior = 0; // 0+ for pacing, until pounce and drag. -1=pin.
private int animation = 0; // 0-3, 1 & 3 = icons[1]
private int behavior = 0; // 0+ for pacing, until pounce and drag. -1=pin.
public SentryT1(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=18; orgY = 30;
public SentryT1(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 18;
orgY = 30;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
@ -41,12 +42,10 @@ public class SentryT1 extends Item
Color transparent = new Color(0, 0, 0, 0);
// 0 = Legs out
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -78,12 +77,10 @@ public class SentryT1 extends Item
// 1 = legs mid
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -113,12 +110,10 @@ public class SentryT1 extends Item
// 2 = legs in
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -144,34 +139,44 @@ public class SentryT1 extends Item
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
if (animation==3)
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
}
public void Animate()
{
if (behavior<3) animation++;
if (animation==4) animation=0;
if (animation==3)
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
int oldX;
switch (behavior)
{
switch (behavior) {
case 0:
oldX = x;
MoveLeft(4);
if (oldX==x) behavior=1;
moveLeft(4);
if (oldX == x) {
behavior = 1;
}
break;
case 1:
oldX = x;
MoveRight(4);
if (oldX==x) behavior=0;
moveRight(4);
if (oldX == x) {
behavior = 0;
}
break;
}
}

View File

@ -2,8 +2,7 @@ package com.droidquest.items;
import com.droidquest.Room;
public class SentryT2 extends Sentry
{
public class SentryT2 extends Sentry {
// This sentry guards a room from the toolbox being carried through it.
// It walks up and down, and pounces and drags if the cursor is
// carrying the toolbox.
@ -14,79 +13,114 @@ public class SentryT2 extends Sentry
// 2=Attack
// 3=Drag back
public SentryT2(int X, int Y, Room r)
{
public SentryT2(int X, int Y, Room r) {
super(X, Y, r);
}
public void Animate()
{
if (behavior<3) animation++;
if (animation==4) animation=0;
if (animation==3)
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
else
}
else {
currentIcon = icons[animation].getImage();
}
if (level.player.room==room)
if (level.player.x>=112)
if (level.player.carrying==level.toolbox)
{
if (level.player.room == room) {
if (level.player.x >= 112) {
if (level.player.carrying == level.toolbox) {
previousBehavior = behavior;
behavior = 2;
}
}
}
switch (behavior)
{
switch (behavior) {
case 0:
if (y<256) MoveDown(4);
else behavior=1;
if (x<56) MoveRight(4);
if (x>56) MoveLeft(4);
if (y < 256) {
moveDown(4);
}
else {
behavior = 1;
}
if (x < 56) {
moveRight(4);
}
if (x > 56) {
moveLeft(4);
}
break;
case 1:
if (y>64) MoveUp(4);
else behavior=0;
if (x<56) MoveRight(4);
if (x>56) MoveLeft(4);
if (y > 64) {
moveUp(4);
}
else {
behavior = 0;
}
if (x < 56) {
moveRight(4);
}
if (x > 56) {
moveLeft(4);
}
break;
case 2:
if (level.player.room != room)
{
if (level.player.room != room) {
behavior = previousBehavior;
break;
}
int dx = level.player.x - x;
int dy = level.player.y - y;
if (dx<-50) dx=-50;
if (dx>50) dx=50;
if (dy<-50) dy=-50;
if (dy>50) dy=50;
if (dx<0) MoveLeft(-dx);
if (dx>0) MoveRight(dx);
if (dy<0) MoveUp(-dy);
if (dy>0) MoveDown(dy);
if (dx==0 && dy==0)
{
if (dx < -50) {
dx = -50;
}
if (dx > 50) {
dx = 50;
}
if (dy < -50) {
dy = -50;
}
if (dy > 50) {
dy = 50;
}
if (dx < 0) {
moveLeft(-dx);
}
if (dx > 0) {
moveRight(dx);
}
if (dy < 0) {
moveUp(-dy);
}
if (dy > 0) {
moveDown(dy);
}
if (dx == 0 && dy == 0) {
PicksUp(level.player);
behavior = 3;
}
break;
case 3:
if (x<=56 && y>=20 && y<=30)
{
if (x <= 56 && y >= 20 && y <= 30) {
Drops();
behavior = 1;
break;
}
else
{
if (x>56)
MoveLeft(4);
if (y<20)
MoveDown(4);
if (y>30)
MoveUp(4);
else {
if (x > 56) {
moveLeft(4);
}
if (y < 20) {
moveDown(4);
}
if (y > 30) {
moveUp(4);
}
}
break;
}

View File

@ -4,54 +4,48 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class SkyGuard extends Item
{
int animationState=0;
int speed;
public class SkyGuard extends Item {
private int animationState = 0;
private int speed;
public SkyGuard (int X, int Y, Room r, int s)
{
x=X; y=Y; room=r;
public SkyGuard(int X, int Y, Room r, int s) {
x = X;
y = Y;
room = r;
speed = s;
width=28; height=32;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[5];
for (int a=0; a<5; a++)
for (int a = 0; a < 5; a++) {
icons[a] = new ImageIcon("images/skyguard" + a + ".gif");
}
currentIcon = icons[0].getImage();
}
public void Animate()
{
public void Animate() {
animationState = 1 - animationState;
if (speed>0)
{
if (speed+x < 420)
{
MoveRight(speed);
if (speed > 0) {
if (speed + x < 420) {
moveRight(speed);
currentIcon = icons[animationState].getImage();
}
else
{
else {
speed = -speed;
currentIcon = icons[2].getImage();
}
}
else if (speed<0)
{
if (speed+x > 112)
{
MoveLeft(-speed);
else if (speed < 0) {
if (speed + x > 112) {
moveLeft(-speed);
currentIcon = icons[3 + animationState].getImage();
}
else
{
else {
speed = -speed;
currentIcon = icons[2].getImage();
}

View File

@ -5,57 +5,60 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.levels.Level;
public class SkywayFlyer extends Item
{
int speed;
String[] filenames;
int animationState=0;
public class SkywayFlyer extends Item {
private int speed;
private String[] filenames;
private int animationState = 0;
public SkywayFlyer(int X, int Y, Room r, String[] f, int spd)
{
x=X; y=Y; room=r;
width=24; height=32;
public SkywayFlyer(int X, int Y, Room r, String[] f, int spd) {
x = X;
y = Y;
room = r;
width = 24;
height = 32;
orgX = 2;
filenames = f; speed=spd;
filenames = f;
speed = spd;
grabbable = false;
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[filenames.length];
for (int a=0; a<filenames.length; a++)
for (int a = 0; a < filenames.length; a++) {
icons[a] = new ImageIcon("images/" + filenames[a]);
}
currentIcon = icons[0].getImage();
}
public void MoveUp(int dist)
{
public void moveUp(int dist) {
y = y - dist;
if (y<32)
if (y < 32) {
y = 320;
}
public void MoveDown(int dist)
{
y = y + dist;
if (y>320)
y = 32;
}
public void Animate()
{
public void moveDown(int dist) {
y = y + dist;
if (y > 320) {
y = 32;
}
}
public void Animate() {
animationState++;
if (animationState == filenames.length)
if (animationState == filenames.length) {
animationState = 0;
}
currentIcon = icons[animationState].getImage();
if (speed<0)
MoveUp(-speed);
else
MoveDown(speed);
if (speed < 0) {
moveUp(-speed);
}
else {
moveDown(speed);
}
if (Overlaps(level.player))
{
if (Overlaps(level.player)) {
level.PlaySound(room, Level.DISCHARGESOUND);
level.player.x = 2 * 28;
level.player.y = 8 * 32;

View File

@ -3,53 +3,42 @@ package com.droidquest.items;
import com.droidquest.Room;
import com.droidquest.materials.Material;
public class SlipperyToken extends Token
{
boolean jumping = true;
public class SlipperyToken extends Token {
private boolean jumping = true;
public SlipperyToken(int X, int Y, Room r)
{
public SlipperyToken(int X, int Y, Room r) {
super(X, Y, r);
}
public boolean CanBePickedUp(Item item)
{
if (item == level.player && jumping)
return false;
else
return true;
public boolean CanBePickedUp(Item item) {
return !(item == level.player && jumping);
}
public void IsDropped()
{
public void IsDropped() {
int bigX = (x + width / 2) / 28;
int bigY = (y + height / 2) / 32;
Material mat = room.MaterialArray[bigY][bigX];
if (mat.getClass().toString().endsWith("VendingSlot"))
{
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("VendingHandle"))
{
if (mat.getClass().toString().endsWith("VendingSlot")) {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("VendingHandle")) {
VendingHandle vh = (VendingHandle) item;
vh.paid = true;
}
}
x=3*28; y=3*32;
room = (Room) level.rooms.elementAt(34);
x = 3 * 28;
y = 3 * 32;
room = level.rooms.elementAt(34);
jumping = true;
}
}
public void Animate()
{
if (carriedBy != null)
public void Animate() {
if (carriedBy != null) {
jumping = false;
if (jumping)
{
if (Overlaps(level.player))
{
}
if (jumping) {
if (Overlaps(level.player)) {
x = level.random.nextInt(16 * 28) + 28;
y = level.random.nextInt(8 * 32) + (2 * 32);
}

View File

@ -10,8 +10,7 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.devices.Antenna;
public class SonicLock extends Item
{
public class SonicLock extends Item {
// This works much like a regular Lock, except it locks or unlocks by watching the Radio.
//
// The program has either an array of binary values, or an array of X,Y,Materials.
@ -23,42 +22,39 @@ public class SonicLock extends Item
public static final int MODIFY = -1;
public static final int BINARY = -2;
static final int RESET = -3;
static final int LEFT = -4;
static final int RIGHT = -5;
static final int UP = -6;
static final int DOWN = -7;
int[][] program;
int doorState=0;
int radioState=1;
int animationState=1;
Room currentRoom;
private static final int RESET = -3;
private static final int LEFT = -4;
private static final int RIGHT = -5;
private static final int UP = -6;
private static final int DOWN = -7;
private int[][] program;
private int doorState = 0;
private int radioState = 1;
private int animationState = 1;
private Room currentRoom;
public SonicLock(int X, int Y, Room r, int[][] p)
{
x=X; y=Y;
public SonicLock(int X, int Y, Room r, int[][] p) {
x = X;
y = Y;
room = r;
program = p;
width=28; height=30;
width = 28;
height = 30;
grabbable = false;
currentRoom = room;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
for (int a=0; a<2; a++)
{
for (int a = 0; a < 2; a++) {
Graphics g;
try
{
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -66,8 +62,7 @@ public class SonicLock extends Item
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
switch (a)
{
switch (a) {
case 0:
g.setColor(Color.white);
break;
@ -90,46 +85,45 @@ public class SonicLock extends Item
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (doorState == program.length)
public void Animate() {
if (doorState == program.length) {
doorState = 0;
}
if (program[doorState][0]==BINARY)
{
if (program[doorState][0] == BINARY) {
animationState++;
if (animationState==program[doorState].length)
if (animationState == program[doorState].length) {
animationState = 1;
}
currentIcon = icons[program[doorState][animationState]].getImage();
}
switch (program[doorState][0])
{
case MODIFY:
{
for (int a=0; a<program[doorState].length/3; a++)
switch (program[doorState][0]) {
case MODIFY: {
for (int a = 0; a < program[doorState].length / 3; a++) {
currentRoom.SetMaterial(program[doorState][a * 3 + 1],
program[doorState][a * 3 + 2],
program[doorState][a * 3 + 3]);
}
doorState++;
radioState = 1;
}
break;
case BINARY:
{
case BINARY: {
currentRoom = room;
boolean radio = (Antenna.radio > 0);
boolean bit = (program[doorState][radioState] == 1);
if (radio == bit)
{
if (radio == bit) {
radioState++;
if (radioState == program[doorState].length)
if (radioState == program[doorState].length) {
doorState++;
}
else
}
else {
radioState = 1;
}
}
break;
case RESET:

View File

@ -1,47 +1,38 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.ChipCompiler;
import com.droidquest.decorations.TextBox;
import com.droidquest.materials.Material;
public
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
class SpeedControl extends Item
{
int direction;
public class SpeedControl extends Item {
private int direction;
public static final int DIR_UP = 0;
public static final int DIR_DOWN = 1;
public SpeedControl(int X, int Y, Room r, int dir)
{
x=X; y=Y;
public SpeedControl(int X, int Y, Room r, int dir) {
x = X;
y = Y;
room = r;
width=26; height=26;
width = 26;
height = 26;
direction = dir;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -49,8 +40,7 @@ public void GenerateIcons()
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
switch(direction)
{
switch (direction) {
case DIR_UP:
g.fillRect(12, 0, 2, 2);
g.fillRect(10, 2, 6, 2);
@ -75,19 +65,19 @@ public void GenerateIcons()
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
switch (direction)
{
public boolean CanBePickedUp(Item item) {
switch (direction) {
case DIR_UP:
ChipCompiler.chipSpeed++;
break;
case DIR_DOWN:
if (ChipCompiler.chipSpeed==1) return false;
if (ChipCompiler.chipSpeed == 1) {
return false;
}
ChipCompiler.chipSpeed--;
break;
}
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
TextBox tb = room.textBoxes.elementAt(1);
tb.textString = ChipCompiler.chipSpeed + "x";
return false;
}

View File

@ -1,56 +1,49 @@
package com.droidquest.items;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import com.droidquest.Room;
import com.droidquest.avatars.Avatar;
import com.droidquest.decorations.TextBox;
public class SpyCam extends Item
{
public SpyCam(Room r)
{
x=0; y=0;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
public class SpyCam extends Item implements Avatar {
public SpyCam(Room r) {
x = 0;
y = 0;
room = r;
width=0; height=0;
width = 0;
height = 0;
grabbable = false;
}
public void Draw(Graphics g, JPanel jp)
{}
public void Draw(Graphics g, JPanel jp) {
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_RIGHT)
{
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
SetRoom(room.rightRoom);
return true;
}
if (e.getKeyCode() == e.VK_LEFT)
{
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
SetRoom(room.leftRoom);
return true;
}
if (e.getKeyCode() == e.VK_UP)
{
if (e.getKeyCode() == KeyEvent.VK_UP) {
SetRoom(room.upRoom);
return true;
}
if (e.getKeyCode() == e.VK_DOWN)
{
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
SetRoom(room.downRoom);
return true;
}
if (e.getKeyCode() == e.VK_SPACE)
{
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
level.player = level.gameCursor;
level.currentViewer = level.player;
for (int a=5; a<60; a++)
{
Room r = (Room) level.rooms.elementAt(a);
TextBox tb = (TextBox) r.textBoxes.elementAt(0);
for (int a = 5; a < 60; a++) {
Room r = level.rooms.elementAt(a);
TextBox tb = r.textBoxes.elementAt(0);
tb.y += 500;
}
return false;
@ -58,4 +51,63 @@ public boolean KeyUp(KeyEvent e)
return false;
}
@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;
}
}

View File

@ -1,42 +1,37 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Square extends Item
{
Color color;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public Square(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r;
width=28; height=28;
public class Square extends Item {
private Color color;
public Square(int X, int Y, Room r, Color c) {
x = X;
y = Y;
room = r;
width = 28;
height = 28;
editable = true;
color = c;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
g.setColor(color);
g.fillRect(0, 0, 28, 28);
currentIcon = icons[0].getImage();

View File

@ -1,51 +1,45 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.devices.StormShield;
public class StormCloud extends Item
{
transient int animateState=0;
transient int xDirection;
transient int yDirection;
transient int moveTimer;
transient OrangeRobot orobot;
transient WhiteRobot wrobot;
transient BlueRobot brobot;
transient StormShield stormshield;
static int maxspeed = 30;
transient int anicount=0;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public StormCloud(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=32;
public class StormCloud extends Item {
private transient int animateState = 0;
private transient int xDirection;
private transient int yDirection;
private transient int moveTimer;
private transient OrangeRobot orobot;
private transient WhiteRobot wrobot;
private transient BlueRobot brobot;
private transient StormShield stormshield;
private static int maxspeed = 30;
private transient int anicount = 0;
public StormCloud(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[2] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
for (int a=0; a<3; a++)
{
try
{
for (int a = 0; a < 3; a++) {
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -78,32 +72,32 @@ public void GenerateIcons()
g.fillRect(16, 24, 4, 2);
}
currentIcon = icons[0].getImage();
do
do {
xDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (xDirection == 0);
do
do {
yDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (yDirection == 0);
moveTimer = level.random.nextInt(50) + 1;
}
public void Animate()
{
public void Animate() {
animateState++;
if (animateState==3) animateState=0;
if (animateState == 3) {
animateState = 0;
}
currentIcon = icons[animateState].getImage();
if (anicount<3)
{
if (anicount < 3) {
Graphics g;
anicount++;
try
{
try {
icons[animateState] = new ImageIcon(new BufferedImage(4 * 28, 3 * 32, BufferedImage.TYPE_4BYTE_ABGR));
g = icons[animateState].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -111,22 +105,33 @@ public void Animate()
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, 4 * 28, 3 * 32);
for (int b=0; b<50; b++)
{
switch (level.random.nextInt(7))
{
case 0: g2.setColor(Color.white); break;
case 1: g2.setColor(Color.red); break;
case 2: g2.setColor(Color.orange); break;
case 3: g2.setColor(Color.yellow); break;
case 4: g2.setColor(Color.green); break;
case 5: g2.setColor(Color.blue); break;
case 6: g2.setColor(Color.magenta); break;
for (int b = 0; b < 50; b++) {
switch (level.random.nextInt(7)) {
case 0:
g2.setColor(Color.white);
break;
case 1:
g2.setColor(Color.red);
break;
case 2:
g2.setColor(Color.orange);
break;
case 3:
g2.setColor(Color.yellow);
break;
case 4:
g2.setColor(Color.green);
break;
case 5:
g2.setColor(Color.blue);
break;
case 6:
g2.setColor(Color.magenta);
break;
}
int x1, y1, d;
int d2 = (3 * 32 / 2) * (3 * 32 / 2);
do
{
do {
x1 = level.random.nextInt(3 * 32) + 4 * 28 / 2 - 3 * 32 / 2;
y1 = level.random.nextInt(3 * 32);
int xd = (x1 - 4 * 28 / 2);
@ -139,115 +144,130 @@ public void Animate()
}
moveTimer--;
if (moveTimer==0)
{
do
if (moveTimer == 0) {
do {
xDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (xDirection == 0);
do
do {
yDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (yDirection == 0);
moveTimer = level.random.nextInt(50) + 1;
}
if (brobot==null)
{
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.getClass().toString().endsWith("BlueRobot"))
if (brobot == null) {
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.getClass().toString().endsWith("BlueRobot")) {
brobot = (BlueRobot) item;
if (item.getClass().toString().endsWith("OrangeRobot"))
}
if (item.getClass().toString().endsWith("OrangeRobot")) {
orobot = (OrangeRobot) item;
if (item.getClass().toString().endsWith("WhiteRobot"))
}
if (item.getClass().toString().endsWith("WhiteRobot")) {
wrobot = (WhiteRobot) item;
if (item.getClass().toString().endsWith("StormShield"))
}
if (item.getClass().toString().endsWith("StormShield")) {
stormshield = (StormShield) item;
}
}
}
if (xDirection>0) MoveRight(xDirection);
if (xDirection<0) MoveLeft(-xDirection);
if (yDirection>0) MoveDown(yDirection);
if (yDirection<0) MoveUp(-yDirection);
if (xDirection > 0) {
moveRight(xDirection);
}
if (xDirection < 0) {
moveLeft(-xDirection);
}
if (yDirection > 0) {
moveDown(yDirection);
}
if (yDirection < 0) {
moveUp(-yDirection);
}
if (brobot!=null)
if (Overlaps(brobot))
{
if (brobot != null) {
if (Overlaps(brobot)) {
boolean drain = true;
if (stormshield.room == brobot.InternalRoom)
if (stormshield.ports[0].value==true)
if (stormshield.room == brobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
if (drain)
}
}
if (drain) {
brobot.charge -= 5000;
if (brobot.charge<0)
}
if (brobot.charge < 0) {
brobot.charge = 0;
}
}
}
if (orobot!=null)
if (Overlaps(orobot))
{
if (orobot != null) {
if (Overlaps(orobot)) {
boolean drain = true;
if (stormshield.room == orobot.InternalRoom)
if (stormshield.ports[0].value==true)
if (stormshield.room == orobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
if (drain)
}
}
if (drain) {
orobot.charge -= 5000;
if (orobot.charge<0)
}
if (orobot.charge < 0) {
orobot.charge = 0;
}
}
}
if (wrobot!=null)
if (Overlaps(wrobot))
{
if (wrobot != null) {
if (Overlaps(wrobot)) {
boolean drain = true;
if (stormshield.room == wrobot.InternalRoom)
if (stormshield.ports[0].value==true)
if (stormshield.room == wrobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
if (drain)
}
}
if (drain) {
wrobot.charge -= 5000;
if (wrobot.charge<0)
}
if (wrobot.charge < 0) {
wrobot.charge = 0;
}
}
}
}
public void MoveRight(int dist)
{
public void moveRight(int dist) {
int newX = x + dist;
if (newX > 559 - 4*28/2)
{
if (newX > 559 - 4 * 28 / 2) {
xDirection = -(level.random.nextInt(maxspeed) + 1);
newX = x + xDirection;
}
x = newX;
}
public void MoveLeft(int dist)
{
public void moveLeft(int dist) {
int newX = x - dist;
if (newX < 0)
{
if (newX < 0) {
xDirection = level.random.nextInt(maxspeed) + 1;
newX = x + xDirection;
}
x = newX;
}
public void MoveUp(int dist)
{
public void moveUp(int dist) {
y -= dist;
if (y < 0)
{
if (y < 0) {
room = room.upRoom;
y += 384;
}
}
public void MoveDown(int dist)
{
public void moveDown(int dist) {
y += dist;
if (y > 383)
{
if (y > 383) {
room = room.downRoom;
y -= 384;
}

View File

@ -1,26 +1,26 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.materials.Material;
public class Suitcase extends Item
{
public Suitcase(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width = 24; height=18;
width = 36; height=42;
orgX = -6; orgY = -12;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Suitcase extends Item {
public Suitcase(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 24;
height = 18;
width = 36;
height = 42;
orgX = -6;
orgY = -12;
InternalRoom = new Room();
int[][] table1 = {
InternalRoom.RoomArray = new int[][]{
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
@ -34,34 +34,31 @@ public Suitcase(int X, int Y, Room r)
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
InternalRoom.RoomArray = table1;
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
Material mat1 = Material.FindSimiliar(new Material(Color.blue, false, true));
int mat1Index = level.materials.indexOf(mat1);
for (int rY=0; rY<12; rY++)
for (int rX=0; rX<20; rX++)
{
if (InternalRoom.RoomArray[rY][rX]==1)
for (int rY = 0; rY < 12; rY++) {
for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
GenerateIcons();
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}

View File

@ -1,35 +1,31 @@
package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Sweeper extends Item
{
int animationState;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Sweeper extends Item {
private int animationState;
// 1=Moving Left
// 2=Stopped and facing camera
// 3=Moving Right
// 4=Stopped and facing camera
public Sweeper(int X, int Y, Room r)
{
x=X; y=Y;
public Sweeper(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width=48; height=32;
width = 48;
height = 32;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
animationState = 1;
}
public void GenerateIcons()
{
public void GenerateIcons() {
icons = new ImageIcon[3];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@ -39,12 +35,10 @@ public void GenerateIcons()
Color transparent = new Color(0, 0, 0, 0);
// sweeper1.gif = Moving Right
try
{
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -78,12 +72,10 @@ public void GenerateIcons()
g.fillRect(32, 28, 4, 2);
// sweeper2.gif = Looking Straight
try
{
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
@ -114,12 +106,10 @@ public void GenerateIcons()
g.fillRect(30, 28, 4, 2);
// sweeper3.gif = Moving Left
try
{
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
@ -152,8 +142,7 @@ public void GenerateIcons()
g.fillRect(16, 24, 4, 2);
g.fillRect(12, 28, 4, 2);
switch (animationState)
{
switch (animationState) {
case 1:
currentIcon = icons[0].getImage();
break;
@ -167,30 +156,27 @@ public void GenerateIcons()
}
}
public void Animate()
{
for (int a = 0; a< level.items.size(); a++)
{
Item testItem = (Item) level.items.elementAt(a);
if (testItem.carriedBy == null)
if (Overlaps(testItem))
{
public void Animate() {
for (int a = 0; a < level.items.size(); a++) {
Item testItem = level.items.elementAt(a);
if (testItem.carriedBy == null) {
if (Overlaps(testItem)) {
testItem.x = 280;
testItem.y = 192;
testItem.SetRoom((Room) level.rooms.elementAt(1));
testItem.SetRoom(level.rooms.elementAt(1));
}
}
}
switch (animationState)
{
switch (animationState) {
case 1:
if (room==(Room) level.rooms.elementAt(14) && x>=120)
{
if (room == level.rooms.elementAt(14) && x >= 120) {
animationState = 2;
currentIcon = icons[1].getImage();
}
else
MoveRight(8);
else {
moveRight(8);
}
break;
case 2:
@ -199,13 +185,13 @@ public void Animate()
break;
case 3:
if (room==(Room) level.rooms.elementAt(2) && x<=504)
{
if (room == level.rooms.elementAt(2) && x <= 504) {
animationState = 4;
currentIcon = icons[2].getImage();
}
else
MoveLeft(8);
else {
moveLeft(8);
}
break;
case 4:

View File

@ -3,37 +3,32 @@ package com.droidquest.items;
import com.droidquest.Room;
import com.droidquest.materials.Switch;
public class Switch4A extends Switch
{
public class Switch4A extends Switch {
int count = 0;
int doorState=0;
private int doorState = 0;
transient Room room = null;
public Switch4A()
{
public Switch4A() {
super(Switch.ROT_UP);
GenerateIcons();
}
public void TouchedByItem(Item item)
{
if (!value)
{
public void TouchedByItem(Item item) {
if (!value) {
value = true;
count++;
room = item.room;
}
}
public void Animate()
{
public void Animate() {
super.Animate();
if (doorState==0 && count==4)
if (doorState == 0 && count == 4) {
doorState = 1;
}
switch (doorState)
{
switch (doorState) {
case 1:
room.SetMaterial(8, 3, 0);
room.SetMaterial(9, 3, 0);
@ -108,43 +103,52 @@ public void Animate()
case 4:
Room temproom = room.rightRoom; // KeyTunnel Left
temproom.SetMaterial(2, 3, 0);
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
temproom.SetMaterial(8, a + 1, 0);
temproom.SetMaterial(12, a + 1, 0);
temproom.SetMaterial(16, a + 1, 0);
}
temproom = temproom.rightRoom; // KeyTunnel Right
for (int a=0; a<8; a++)
{
for (int a = 0; a < 8; a++) {
temproom.SetMaterial(3, a + 1, 0);
temproom.SetMaterial(7, a + 1, 0);
temproom.SetMaterial(11, a + 1, 0);
}
temproom = room.leftRoom; // MineField top right
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
if (temproom.RoomArray[Y][X]==8)
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
if (temproom.RoomArray[Y][X] == 8) {
temproom.SetMaterial(X, Y, 11);
}
}
}
temproom = temproom.leftRoom; // MineField top left
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
{
if (temproom.RoomArray[Y][X]==8)
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
if (temproom.RoomArray[Y][X] == 8) {
temproom.SetMaterial(X, Y, 11);
if (temproom.RoomArray[Y][X]==16)
}
if (temproom.RoomArray[Y][X] == 16) {
temproom.SetMaterial(X, Y, 0);
}
temproom = temproom.downRoom; // MineField botom left
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
if (temproom.RoomArray[Y][X]==8)
}
}
temproom = temproom.downRoom; // MineField bottom left
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
if (temproom.RoomArray[Y][X] == 8) {
temproom.SetMaterial(X, Y, 11);
}
}
}
temproom = temproom.rightRoom; // MineField bottom right
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
if (temproom.RoomArray[Y][X]==8)
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
if (temproom.RoomArray[Y][X] == 8) {
temproom.SetMaterial(X, Y, 11);
}
}
}
temproom = room.upRoom;
temproom.SetMaterial(19, 5, 0);
temproom.SetMaterial(19, 6, 0);

View File

@ -3,29 +3,24 @@ package com.droidquest.items;
import com.droidquest.materials.Material;
import com.droidquest.materials.Switch;
public class Switch4B extends Switch
{
transient Switch4A sw = null;
public class Switch4B extends Switch {
private transient Switch4A sw = null;
public Switch4B()
{
public Switch4B() {
super(Switch.ROT_RIGHT);
}
public void TouchedByItem(Item item)
{
if (sw==null)
{
for (int a=0; a<level.materials.size(); a++)
{
Material mat = (Material) level.materials.elementAt(a);
if (mat instanceof Switch4A)
public void TouchedByItem(Item item) {
if (sw == null) {
for (int a = 0; a < level.materials.size(); a++) {
Material mat = level.materials.elementAt(a);
if (mat instanceof Switch4A) {
sw = (Switch4A) mat;
}
}
}
if (!value)
{
if (!value) {
value = true;
sw.count++;
sw.room = item.room;

Some files were not shown because too many files have changed in this diff Show More