Refactored and cleaned up code. Modernized some constructs.

This commit is contained in:
cognitivegears
2014-04-08 22:04:44 -05:00
parent 5db7d9b43f
commit 0786afb4d9
178 changed files with 31022 additions and 32600 deletions

View File

@@ -2,178 +2,134 @@ 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.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 ()
{
// Constructor
super("DroidQuest");
setSize(560+8,384+27+24);
addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ setVisible(false); dispose(); System.exit(0); }
});
setIconImage(new ImageIcon("images/helper0.gif").getImage());
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);
}
});
Container contentPane = getContentPane();
myRoom = new RoomDisplay();
myRoom.dq=this;
setIconImage(new ImageIcon("images/helper0.gif").getImage());
addFocusListener(new FocusAdapter()
{
public void focusGained(FocusEvent e)
{
myRoom.requestFocus();
}
});
Container contentPane = getContentPane();
myRoom = new RoomDisplay();
myRoom.dq = this;
contentPane.add(myRoom);
myRoom.setLocation(0,0);
addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
myRoom.requestFocus();
}
});
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem menuItemSave;
JMenuItem menuItemMain;
JCheckBoxMenuItem menuItemSound;
JMenuItem menuItemExit;
contentPane.add(myRoom);
myRoom.setLocation(0, 0);
menuBar = new JMenuBar();
setJMenuBar(menuBar);
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem menuItemSave;
JMenuItem menuItemMain;
JCheckBoxMenuItem menuItemSound;
JMenuItem menuItemExit;
menuItemSave = new JMenuItem("Save Level",KeyEvent.VK_S);
menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M);
menuItemSound = new JCheckBoxMenuItem("Sound", true);
menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X);
fileMenu.add(menuItemSave);
fileMenu.add(menuItemMain);
fileMenu.add(menuItemSound);
fileMenu.add(menuItemExit);
menuBar = new JMenuBar();
setJMenuBar(menuBar);
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
menuItemSave.addActionListener(this);
menuItemMain.addActionListener(this);
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);
menuItemSave = new JMenuItem("Save Level", KeyEvent.VK_S);
menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M);
menuItemSound = new JCheckBoxMenuItem("Sound", true);
menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X);
fileMenu.add(menuItemSave);
fileMenu.add(menuItemMain);
fileMenu.add(menuItemSound);
fileMenu.add(menuItemExit);
try
{
System.setErr(System.out);
}
catch (SecurityException e) {}
}
menuItemSave.addActionListener(this);
menuItemMain.addActionListener(this);
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);
public static void main(String[] args)
{
DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
dq.setLocation(bounds.x + (bounds.width - 568)/2,
bounds.y + (bounds.height - 435)/2 );
dq.setVisible(true);
try {
System.setErr(System.out);
}
catch (SecurityException e) {
}
}
}
public static void main(String[] args) {
DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
dq.setLocation(bounds.x + (bounds.width - 568) / 2,
bounds.y + (bounds.height - 435) / 2);
dq.setVisible(true);
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == "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)
myRoom.SaveLevel(fd.getDirectory()+fd.getFile());
}
}
if (e.getActionCommand() == "Main Menu")
{
int n = JOptionPane.showConfirmDialog(this,"Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n==0)
{
myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom);
myRoom.level.Init();
}
}
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) {
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
}
}
if (e.getActionCommand() == "Sound")
{
myRoom.useSounds = ((JCheckBoxMenuItem)e.getSource()).getState();
if (myRoom.useSounds==false)
{
Set<String> keys = myRoom.level.sounds.keySet();
Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()) {
String soundFile = iterator.next();
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().equals("Main Menu")) {
int n = JOptionPane.showConfirmDialog(this, "Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n == 0) {
myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom);
myRoom.level.Init();
}
}
if (e.getActionCommand() == "Exit")
{ setVisible(false); dispose(); System.exit(0); }
if (e.getActionCommand().equals("Sound")) {
myRoom.useSounds = ((JCheckBoxMenuItem) e.getSource()).getState();
if (!myRoom.useSounds) {
Set<String> keys = myRoom.level.sounds.keySet();
for (String soundFile : keys) {
SoundClip soundClip = myRoom.level.sounds.get(soundFile);
soundClip.audioClip.stop();
}
}
}
}
if (e.getActionCommand().equals("Exit")) {
setVisible(false);
dispose();
System.exit(0);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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,340 +7,314 @@ import com.droidquest.items.Item;
import com.droidquest.levels.Level;
import com.droidquest.materials.Material;
public class Room implements Serializable, Cloneable
{
public transient static Level level;
public transient Room upRoom;
public transient Room downRoom;
public transient Room rightRoom;
public transient Room leftRoom;
public transient Item portalItem = null;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;
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},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{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 boolean editable;
public class Room implements Serializable, Cloneable {
public transient static Level level;
public transient Room upRoom;
public transient Room downRoom;
public transient Room rightRoom;
public transient Room leftRoom;
public transient Item portalItem = null;
public Room()
{
upRoom=this;
downRoom=this;
rightRoom=this;
leftRoom=this;
editable=false;
}
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},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{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<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 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);
}
public Room() {
upRoom = this;
downRoom = this;
rightRoom = this;
leftRoom = this;
editable = false;
}
public void readRef(ObjectInputStream s) throws IOException
{
upRoom = level.FindRoom(s.readInt());
downRoom = level.FindRoom(s.readInt());
rightRoom = level.FindRoom(s.readInt());
leftRoom = level.FindRoom(s.readInt());
portalItem = level.FindItem(s.readInt());
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++) {
wires.elementAt(a).writeRef(s);
}
}
int numWires = s.readInt();
wires = new Vector();
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();
}
GenerateArray();
}
public void readRef(ObjectInputStream s) throws IOException {
upRoom = level.FindRoom(s.readInt());
downRoom = level.FindRoom(s.readInt());
rightRoom = level.FindRoom(s.readInt());
leftRoom = level.FindRoom(s.readInt());
portalItem = level.FindItem(s.readInt());
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]);
}
int numWires = s.readInt();
wires = new Vector<Wire>();
for (int a = 0; a < numWires; a++) {
Wire wire = new Wire();
wires.addElement(wire);
wire.readRef(s, level);
}
public void SetMaterial(int X, int Y, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
for (int a = 0; a < graphix.size(); a++) {
graphix.elementAt(a).GenerateIcons();
}
public void SetMaterial(int X, int Y, Material mat)
{
int index = level.materials.indexOf(mat);
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
GenerateArray();
}
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++)
{
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
}
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] = level.materials.elementAt(RoomArray[y][x]);
}
}
}
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++)
{
RoomArray[Y][X1] = index;
MaterialArray[Y][X1] = mat;
RoomArray[Y][X2] = index;
MaterialArray[Y][X2] = mat;
}
for(int X=X1; X<=X2; X++)
{
RoomArray[Y1][X] = index;
MaterialArray[Y1][X] = mat;
RoomArray[Y2][X] = index;
MaterialArray[Y2][X] = mat;
}
}
}
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 SetMaterialFromRoom(int roomIndex)
{
Room r = (Room) 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 SetMaterial(int X, int Y, Material mat) {
int index = level.materials.indexOf(mat);
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
public void AddTextBox(String t, int X, int Y, int W)
{
TextBox newText = new TextBox(t,X,Y,W);
textBoxes.addElement(newText);
}
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 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 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;
}
public void AddGraphix(String t, int X, int Y)
{
Graphix newGraphix = new Graphix(t,X,Y);
graphix.addElement(newGraphix);
}
for (int X = X1; X <= X2; X++) {
RoomArray[Y1][X] = index;
MaterialArray[Y1][X] = mat;
RoomArray[Y2][X] = index;
MaterialArray[Y2][X] = mat;
}
}
}
public void AddGraphix(String[] t, int X, int Y)
{
Graphix newGraphix = new Graphix(t,X,Y);
graphix.addElement(newGraphix);
}
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 DrawTextBoxes(Graphics g, RoomDisplay rd)
{
for (int a=0; a<textBoxes.size(); a++)
{
TextBox textBox = (TextBox) textBoxes.elementAt(a);
g.setColor(Color.white);
g.setFont(rd.smallFont);
int cursX = textBox.x;
int cursY = textBox.y;
int advY=0;
int advX;
String nextWord;
int indexFrom=0;
int indexTo;
do
{
// Get the next word in the string
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(" "))
{
nextWord = nextWord.substring(1,nextWord.length());
}
if (!nextWord.endsWith(" "))
{
nextWord = nextWord + " ";
}
if (nextWord.startsWith("{BIG}"))
{
g.setFont(rd.bigFont);
}
else if (nextWord.startsWith("{SML}"))
{
g.setFont(rd.smallFont);
}
else if (nextWord.startsWith("{BSP}"))
{
FontMetrics fm = g.getFontMetrics();
advX = fm.stringWidth(" ");
cursX-=advX;
}
// if (nextWord fits "{rrr,ggg,bbb} "
else if (nextWord.startsWith("{")
&& nextWord.endsWith("} ")
&& nextWord.length()==14)
{
// extract rrr,ggg,bbb
Integer rr = new Integer(nextWord.substring(1,4));
Integer gg = new Integer(nextWord.substring(5,8));
Integer bb = new Integer(nextWord.substring(9,12));
g.setColor(new Color(rr.intValue(),
gg.intValue(),
bb.intValue()));
}
else
{
FontMetrics fm = g.getFontMetrics();
if (fm.getAscent() > advY)
{advY = fm.getAscent() ;}
advX = fm.stringWidth(nextWord);
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)
{
cursX=textBox.x;
cursY+=advY;
advY=fm.getAscent();
}
}
indexFrom = indexTo;
}
while (indexFrom < textBox.textString.length());
}
}
public void AddTextBox(String t, int X, int Y, int W) {
TextBox newText = new TextBox(t, X, Y, W);
textBoxes.addElement(newText);
}
public void DrawGraphix(Graphics g, RoomDisplay rd)
{
for (int a = 0; a< graphix.size(); a++)
{
Graphix grx = (Graphix) graphix.elementAt(a);
grx.Draw(g,rd);
}
}
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 DrawArrows(Graphics g)
{
for (int a = 0; a< arrows.size(); a++)
((Arrow) arrows.elementAt(a)).Draw(g);
}
public void AddGraphix(String t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}
public Room getUpRoom(Item item)
{
return upRoom;
}
public void AddGraphix(String[] t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}
public Room getDownRoom(Item item)
{
return downRoom;
}
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);
public Room getLeftRoom(Item item)
{
return leftRoom;
}
int cursX = textBox.x;
int cursY = textBox.y;
int advY = 0;
int advX;
String nextWord;
int indexFrom = 0;
int indexTo;
public Room getRightRoom(Item item)
{
return rightRoom;
}
do {
// Get the next word in the string
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(" ")) {
nextWord = nextWord.substring(1, nextWord.length());
}
if (!nextWord.endsWith(" ")) {
nextWord = nextWord + " ";
}
public Wire FindWire(int wireIndex)
{
if (wireIndex==-1) return null;
if (wireIndex>=wires.size()) return null;
return (Wire) wires.elementAt(wireIndex);
}
if (nextWord.startsWith("{BIG}")) {
g.setFont(rd.bigFont);
}
public Object clone()
{
Object newObject = null;
try
{
newObject = super.clone();
}
catch (CloneNotSupportedException e) {}
return newObject;
}
else if (nextWord.startsWith("{SML}")) {
g.setFont(rd.smallFont);
}
public void Erase()
{
upRoom = null;
downRoom = null;
rightRoom = null;
leftRoom = null;
portalItem = null;
arrows.clear();
graphix.clear();
for (int a=0; a< wires.size(); a++)
{
Wire wire = (Wire) wires.elementAt(a);
wire.fromPort = null;
wire.toPort = null;
wire.inPort = null;
wire.outPort = null;
}
wires.clear();
}
else if (nextWord.startsWith("{BSP}")) {
FontMetrics fm = g.getFontMetrics();
advX = fm.stringWidth(" ");
cursX -= advX;
}
// if (nextWord fits "{rrr,ggg,bbb} "
else if (nextWord.startsWith("{")
&& nextWord.endsWith("} ")
&& nextWord.length() == 14) {
// extract rrr,ggg,bbb
Integer rr = new Integer(nextWord.substring(1, 4));
Integer gg = new Integer(nextWord.substring(5, 8));
Integer bb = new Integer(nextWord.substring(9, 12));
g.setColor(new Color(rr.intValue(),
gg.intValue(),
bb.intValue()));
}
else {
FontMetrics fm = g.getFontMetrics();
if (fm.getAscent() > advY) {
advY = fm.getAscent();
}
advX = fm.stringWidth(nextWord);
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) {
cursX = textBox.x;
cursY += advY;
advY = fm.getAscent();
}
}
indexFrom = indexTo;
}
while (indexFrom < textBox.textString.length());
}
}
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++) {
arrows.elementAt(a).Draw(g);
}
}
public Room getUpRoom(Item item) {
return upRoom;
}
public Room getDownRoom(Item item) {
return downRoom;
}
public Room getLeftRoom(Item item) {
return leftRoom;
}
public Room getRightRoom(Item item) {
return rightRoom;
}
public Wire FindWire(int wireIndex) {
if (wireIndex == -1) {
return null;
}
if (wireIndex >= wires.size()) {
return null;
}
return wires.elementAt(wireIndex);
}
public Object clone() {
Object newObject = null;
try {
newObject = super.clone();
}
catch (CloneNotSupportedException e) {
}
return newObject;
}
public void Erase() {
upRoom = null;
downRoom = null;
rightRoom = null;
leftRoom = null;
portalItem = null;
arrows.clear();
graphix.clear();
for (int a = 0; a < wires.size(); a++) {
Wire wire = wires.elementAt(a);
wire.fromPort = null;
wire.toPort = null;
wire.inPort = null;
wire.outPort = null;
}
wires.clear();
}
}

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,525 +10,459 @@ import com.droidquest.levels.Level;
import com.droidquest.levels.MainMenu;
import com.droidquest.materials.Material;
public class RoomDisplay extends JPanel
{
public DQ dq;
Level level;
public Timer timer;
int timerspeed=128;
public boolean useSounds = true;
AffineTransform at = new AffineTransform();
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 Font bigFont;
public Font smallFont;
private int repeating=0; // Used for repeating keys
public class RoomDisplay extends JPanel {
public DQ dq;
Level level;
public Timer timer;
private int timerspeed = 128;
public boolean useSounds = true;
private AffineTransform at = new AffineTransform();
//public boolean isFocusTraversable()
// {
// Necessary to get the keyboard focus to work with
// the ScrenDisplay class.
// return(true);
// }
public Font bigFont;
public Font smallFont;
public boolean isFocusable()
{
// Necessary to get the keyboard focus to work with
// the ScrenDisplay class.
return(true);
}
public boolean isFocusable() {
// Necessary to get the keyboard focus to work with
// the ScrenDisplay class.
return (true);
}
public RoomDisplay()
{
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();
public RoomDisplay() {
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);
requestFocus();
// Resizing Fuctions
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e)
{
Dimension d = new Dimension();
getSize(d);
double w = d.width / 560.0;
double h = d.height / 384.0;
at.setToScale(w,h);
}
});
// Resizing Fuctions
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
Dimension d = new Dimension();
getSize(d);
double w = d.width / 560.0;
double h = d.height / 384.0;
at.setToScale(w, h);
}
});
// Key Released Functions
addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
// Event Handler for KeyReleased here
if (level.player.KeyUp(e))
repaint();
// Key Released Functions
addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
// Event Handler for KeyReleased here
if (level.player.KeyUp(e)) {
repaint();
}
if (e.getKeyCode() == e.VK_Q)
{
if (timerspeed>1)
timerspeed /= 2;
timer.setDelay(timerspeed);
}
if (e.getKeyCode() == e.VK_Q) {
if (timerspeed > 1) {
timerspeed /= 2;
}
timer.setDelay(timerspeed);
}
if (e.getKeyCode() == e.VK_W)
{
if (timerspeed<128)
timerspeed*=2;
if ( (timerspeed>=128) && (level.player instanceof LabCursor) )
timerspeed*=2;
timer.setDelay(timerspeed);
}
if (e.getKeyCode() == e.VK_W) {
if (timerspeed < 128) {
timerspeed *= 2;
}
if ((timerspeed >= 128) && (level.player instanceof LabCursor)) {
timerspeed *= 2;
}
timer.setDelay(timerspeed);
}
}
});
}
});
// Key Pressed Functions
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (level.player.KeyDown(e))
repaint();
return;
}
});
// Key Pressed Functions
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (level.player.KeyDown(e)) {
repaint();
}
}
});
// Mouse Functions
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int newX = (int) (e.getX() / at.getScaleX());
int newY = (int) (e.getY() / at.getScaleY());
int deltaX = newX - e.getX();
int deltaY = newY - e.getY();
e.translatePoint(deltaX,deltaY);
level.player.MouseClick(e);
}
});
// Mouse Functions
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int newX = (int) (e.getX() / at.getScaleX());
int newY = (int) (e.getY() / at.getScaleY());
int deltaX = newX - e.getX();
int deltaY = newY - e.getY();
e.translatePoint(deltaX, deltaY);
level.player.MouseClick(e);
}
});
timer = new Timer(timerspeed, new ActionListener() {
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)
{
System.out.println("Saving carried items.");
level.WriteInventory();
}
timer = new Timer(timerspeed, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (level.portal != null) {
String filename = level.portal.levelName;
boolean bringStuff = level.portal.bringStuff;
boolean initLevel = level.portal.initLevel;
FileInputStream f;
try
{
f = new FileInputStream(filename);
try {f.close();} 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
{
Class newlevel = Class.forName(classname);
Class[] arglist = {Class.forName("com.droidquest.RoomDisplay")};
constructor = newlevel.getConstructor(arglist);
constructor.setAccessible(true);
}
catch (ClassNotFoundException ce) {
ce.printStackTrace();
}
catch (NoSuchMethodException ne) {
ne.printStackTrace();
};
try
{
Object[] args = {rd};
level = (Level) constructor.newInstance(args);
rd.SaveLevel();
}
catch(InstantiationException ie2)
{
System.out.println("Instantiation");
System.exit(0);
}
catch(IllegalAccessException ie2)
{
System.out.println("Illegal Access");
System.exit(0);
}
catch(IllegalArgumentException ie2)
{
System.out.println("Illegal Argument");
System.exit(0);
}
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"
// if found, create it and save it, then load the file.
// }
level.PlaySound(level.currentViewer.room, Level.TELEPORTSOUND);
boolean tempsound = level.roomdisplay.useSounds;
level.roomdisplay.useSounds = false;
if (bringStuff) {
System.out.println("Saving carried items.");
level.WriteInventory();
}
System.out.println("Loading level " + filename);
LoadLevel(filename);
if (initLevel)
{
System.out.println("Initializing Level");
level.Init();
}
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;
FileInputStream f;
try {
f = new FileInputStream(filename);
try {
f.close();
}
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 {
Class newlevel = Class.forName(classname);
Class[] arglist = {Class.forName("com.droidquest.RoomDisplay")};
constructor = newlevel.getConstructor(arglist);
constructor.setAccessible(true);
}
catch (ClassNotFoundException ce) {
ce.printStackTrace();
}
catch (NoSuchMethodException ne) {
ne.printStackTrace();
}
try {
Object[] args = {rd};
level = (Level) constructor.newInstance(args);
rd.SaveLevel();
}
catch (InstantiationException ie2) {
System.out.println("Instantiation");
System.exit(0);
}
catch (IllegalAccessException ie2) {
System.out.println("Illegal Access");
System.exit(0);
}
catch (IllegalArgumentException ie2) {
System.out.println("Illegal Argument");
System.exit(0);
}
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"
// if found, create it and save it, then load the file.
// }
// 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);
}
Electricity();
for (int a = 0; a < level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
item.Animate();
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);
graphix.Animate();
}
}
System.out.println("Loading level " + filename);
LoadLevel(filename);
if (initLevel) {
System.out.println("Initializing Level");
level.Init();
}
if (bringStuff) {
System.out.println("Loading carried items.");
level.LoadInventory();
}
repaint();
for (int a = 0; a< level.sparks.size(); a++)
{
Spark spark = (Spark)level.sparks.elementAt(a);
spark.Age();
if (spark.age>6)
{
level.sparks.removeElement(spark);
a--;
}
}
}
});
level.roomdisplay.useSounds = tempsound;
level.PlaySound(level.currentViewer.room, Level.TRANSPORTSOUND);
}
Electricity();
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
item.Animate();
if (item.room == level.currentViewer.room) {
item.Decorate();
}
}
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();
}
}
Image tempImage= new BufferedImage(200,200,BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = tempImage.getGraphics();
Image tempIcon;
ImageIcon tempImageIcon;
repaint();
for (int a = 0; a < level.sparks.size(); a++) {
Spark spark = (Spark) level.sparks.elementAt(a);
spark.Age();
if (spark.age > 6) {
level.sparks.removeElement(spark);
a--;
}
}
}
});
for (int a = 0; a<level.materials.size(); a++)
{
Material mat = (Material) level.materials.elementAt(a);
tempImageIcon = mat.icon;
if (tempImageIcon != null)
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
Image tempImage = new BufferedImage(200, 200, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = tempImage.getGraphics();
ImageIcon tempImageIcon;
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++)
{
tempImageIcon = itm.icons[b];
if (tempImageIcon != null)
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
}
for (int a = 0; a < level.materials.size(); a++) {
Material mat = level.materials.elementAt(a);
tempImageIcon = mat.icon;
if (tempImageIcon != null) {
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
}
timer.start();
level.PlaySound(level.player.room, Level.STARTMUSICSOUND);
}
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) {
g.drawImage(tempImageIcon.getImage(), 0, 0, this);
}
}
}
public void paintComponent(Graphics g)
{
super.paintComponents(g); // Paint background
Graphics2D g2 = (Graphics2D) g;
g2.setTransform(at);
timer.start();
level.PlaySound(level.player.room, Level.STARTMUSICSOUND);
}
// Paint Materials
if (level.currentViewer.room.MaterialArray==null)
level.currentViewer.room.GenerateArray();
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);
public void paintComponent(Graphics g) {
super.paintComponents(g); // Paint background
Graphics2D g2 = (Graphics2D) g;
g2.setTransform(at);
// Paint Texts
level.currentViewer.room.DrawTextBoxes(g2, this);
// Paint Materials
if (level.currentViewer.room.MaterialArray == null) {
level.currentViewer.room.GenerateArray();
}
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 Graphix
level.currentViewer.room.DrawGraphix(g2,this);
// Paint Texts
level.currentViewer.room.DrawTextBoxes(g2, this);
// Paint Arrows
level.currentViewer.room.DrawArrows(g2);
// Paint Graphix
level.currentViewer.room.DrawGraphix(g2, this);
// 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);
// Paint Arrows
level.currentViewer.room.DrawArrows(g2);
// Paint Wires
for (int a = 0; a< level.currentViewer.room.wires.size(); a++)
((Wire) level.currentViewer.room.wires.elementAt(a)).Draw(g2);
// Paint Items
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 Sparks
for (int a = 0; a< level.sparks.size(); a++)
{
Spark spark = (Spark)level.sparks.elementAt(a);
if (spark.room == level.currentViewer.room)
spark.Draw(g2);
}
// Paint Wires
for (int a = 0; a < level.currentViewer.room.wires.size(); a++) {
level.currentViewer.room.wires.elementAt(a).Draw(g2);
}
// Repaint the Current Player on top of everything else
// if (level.currentViewer.room == level.player.room)
// level.player.Draw(g2,this);
//
// Problem with this: You can't find the Black Crystal. This could be fixed by
// putting a menu item in "Cursor always on top".
// Paint Sparks
for (int a = 0; a < level.sparks.size(); a++) {
Spark 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)
// level.player.Draw(g2,this);
//
// Problem with this: You can't find the Black Crystal. This could be fixed by
// putting a menu item in "Cursor always on top".
public void Electricity()
{
if (level.electricity == false)
return;
}
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.isDevice())
{
Device device = (Device) item;
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)
{
wire.value = wire.outPort.value;
wire.inPort.value = wire.value;
}
}
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 (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].value = true;
}
}
}
}
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())
{
Device device = (Device) item;
device.Function();
}
}
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++) {
Wire wire = device.ports[b].myWire;
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) {
device.ports[b].value = false;
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].value = true;
}
}
}
}
}
}
}
}
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item.isDevice()) {
Device device = (Device) item;
device.Function();
}
}
boolean nodeChanged;
int counter=0;
do
{
nodeChanged=false;
for (int a=0; a<level.items.size(); a++)
{
Item item = (Item) level.items.elementAt(a);
if (item.isDevice())
{
Device device = (Device) item;
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)
{
wire.value = wire.outPort.value;
wire.inPort.value = wire.value;
}
}
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 (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].value = true;
}
}
if (device.isNode())
{
if (device.Function())
nodeChanged=true;
boolean nodeChanged;
int counter = 0;
do {
nodeChanged = false;
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++) {
Wire wire = device.ports[b].myWire;
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) {
device.ports[b].value = false;
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].value = true;
}
}
}
}
}
}
if (device.isNode()) {
if (device.Function()) {
nodeChanged = true;
}
}
}
}
counter++;
}
while (nodeChanged && counter<1000);
}
}
}
counter++;
}
while (nodeChanged && counter < 1000);
}
}
public 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++)
System.out.println(a + " = " + path[a]);
// String filename = temp.substring(6);
String filename = path[path.length-1];
SaveLevel(filename+".lvl");
}
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++) {
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)
{
System.out.println("Saving level " + filename);
try
{
FileOutputStream out = new FileOutputStream(filename);
ObjectOutputStream s = new ObjectOutputStream(out);
level.writeObject(s);
s.flush();
s.close();
out.close();
}
catch (FileNotFoundException e)
{
System.out.println("File Not Found");
}
catch (IOException e)
{
System.out.println("IO Exception");
System.out.println(e.getMessage());
}
}
public void SaveLevel(String filename) {
System.out.println("Saving level " + filename);
try {
FileOutputStream out = new FileOutputStream(filename);
ObjectOutputStream s = new ObjectOutputStream(out);
level.writeObject(s);
s.flush();
s.close();
out.close();
}
catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
}
}
public void LoadLevel(String filename)
{
timer.stop();
level.Empty();
level = new Level(this);
Item.level = level;
Room.level = level;
Material.level = level;
void LoadLevel(String filename) {
timer.stop();
level.Empty();
level = new Level(this);
Item.level = level;
Room.level = level;
Material.level = level;
// Add flags for loading Object inventories or running Init()
try
{
FileInputStream in = new FileInputStream(filename);
ObjectInputStream s = new ObjectInputStream(in);
level.readObject(s);
s.close();
in.close();
}
catch (FileNotFoundException e)
{
System.out.println("File Not Found");
return;
}
catch (IOException e)
{
System.out.println("IO Exception");
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
// Add flags for loading Object inventories or running Init()
try {
FileInputStream in = new FileInputStream(filename);
ObjectInputStream s = new ObjectInputStream(in);
level.readObject(s);
s.close();
in.close();
}
catch (FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
if (level.remote != null)
{
if (level.electricity)
{
level.remote.x = 28;
level.remote.y = -20;
level.remote.carriedBy = level.player;
level.remote.room = level.player.room;
}
else // Electricity is off
{
level.remote.carriedBy = null;
level.remote.room = null;
}
}
if (level.remote != null) {
if (level.electricity) {
level.remote.x = 28;
level.remote.y = -20;
level.remote.carriedBy = level.player;
level.remote.room = level.player.room;
}
else // Electricity is off
{
level.remote.carriedBy = null;
level.remote.room = null;
}
}
timer.start();
}
timer.start();
}
}

View File

@@ -5,24 +5,20 @@ import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;
public class SoundClip
{
public AudioClip audioClip;
public String filename;
public class SoundClip {
public AudioClip audioClip;
private String filename;
public SoundClip(String f)
{
filename = f;
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)
{
System.err.println(e.getMessage());
}
}
public SoundClip(String f) {
filename = f;
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) {
System.err.println(e.getMessage());
}
}
}

View File

@@ -1,439 +1,402 @@
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
{
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;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public Wire() {}
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(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
System.out.println("f.myDevice.room is null");
}
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)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (f.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (f.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
f.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
f.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
return;
}
}
}
public Wire() {
}
protected 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++;
s.writeInt(a); // Index of fromport (as device.ports[?]
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 {
System.out.println("f.myDevice.room is null");
}
}
else {
System.out.println("f.myDevice is null");
}
s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device
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++;
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++;
s.writeInt(a); // Index of outPort (as device.ports[?]
}
f.myDevice.room.wires.addElement(this);
f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND);
protected void readRef(ObjectInputStream s, Level level) throws IOException
{
Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
toPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
inPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
outPort = tempDevice.ports[s.readInt()];
}
if (f.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (f.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (f.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
f.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
f.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
}
}
}
public void ConnectTo(Port t)
{
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);
void writeRef(ObjectOutputStream s) throws IOException {
Level level = fromPort.myDevice.level;
int a;
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)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
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)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (fromPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
toPort=t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
fromPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
fromPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
return;
}
}
}
else
{
fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null;
if (toPort.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
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)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (toPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort=t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
toPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
toPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
return;
}
}
}
s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device
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++;
}
s.writeInt(a); // Index of toPort (as device.ports[?]
public void Remove()
{
Room room = fromPort.myDevice.room;
room.level.PlaySound(room, Level.DETATCHSOUND);
fromPort.myWire = null;
toPort.myWire = null;
fromPort = null;
toPort = null;
inPort = null;
outPort = null;
room.wires.removeElement(this);
}
s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device
a = 0;
while (((Device) inPort.myDevice).ports[a] != inPort) {
a++;
}
s.writeInt(a); // Index of inPort (as device.ports[?]
public void Draw(Graphics g)
{
g.setColor(Color.white);
value = false;
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)
{
g.setColor(new Color(255,128,0));
value = true;
}
Dimension d1, d2;
int x1, y1, x2, y2;
d1 = fromPort.myDevice.GetXY();
d2 = toPort.myDevice.GetXY();
x1 = d1.width + fromPort.x;
y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y;
switch((((Device)fromPort.myDevice).rotation + fromPort.rotation)%4)
{
case 0: // Up
x1 += 1;
y1 += 1;
break;
case 1: // Right
x1 -= 2;
y1 += 1;
break;
case 2: // Down
x1 -= 2;
y1 -= 2;
break;
case 3: // Left
x1 += 1;
y1 -= 2;
break;
}
switch((((Device)toPort.myDevice).rotation + toPort.rotation)%4)
{
case 0: // Up
x2 += 1;
y2 += 1;
break;
case 1: // Right
x2 -= 2;
y2 += 1;
break;
case 2: // Down
x2 -= 2;
y2 -= 2;
break;
case 3: // Left
x2 += 1;
y2 -= 2;
break;
}
g.fillRect(Math.min(x1,x2),y1,Math.abs(x1-x2),2);
g.fillRect(x2,Math.min(y1,y2),2,Math.abs(y1-y2));
g.fillRect(x1,y1,2,2);
g.fillRect(x2,y2,2,2);
g.fillRect(x2,y1,2,2);
}
s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device
a = 0;
while (((Device) outPort.myDevice).ports[a] != outPort) {
a++;
}
s.writeInt(a); // Index of outPort (as device.ports[?]
}
public Port otherPort(Port p)
{
if (fromPort == p) return toPort;
if (toPort == p) return fromPort;
return null;
}
void readRef(ObjectInputStream s, Level level) throws IOException {
Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
toPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
inPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
outPort = tempDevice.ports[s.readInt()];
}
public void ConnectTo(Port t) {
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);
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) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
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) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (fromPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
fromPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
fromPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
}
}
}
else {
fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null;
if (toPort.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
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) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (toPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
toPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
toPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
}
}
}
}
public void Remove() {
Room room = fromPort.myDevice.room;
room.level.PlaySound(room, Level.DETATCHSOUND);
fromPort.myWire = null;
toPort.myWire = null;
fromPort = null;
toPort = null;
inPort = null;
outPort = null;
room.wires.removeElement(this);
}
public void Draw(Graphics g) {
g.setColor(Color.white);
value = false;
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) {
g.setColor(new Color(255, 128, 0));
value = true;
}
Dimension d1, d2;
int x1, y1, x2, y2;
d1 = fromPort.myDevice.GetXY();
d2 = toPort.myDevice.GetXY();
x1 = d1.width + fromPort.x;
y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y;
switch ((((Device) fromPort.myDevice).rotation + fromPort.rotation) % 4) {
case 0: // Up
x1 += 1;
y1 += 1;
break;
case 1: // Right
x1 -= 2;
y1 += 1;
break;
case 2: // Down
x1 -= 2;
y1 -= 2;
break;
case 3: // Left
x1 += 1;
y1 -= 2;
break;
}
switch ((((Device) toPort.myDevice).rotation + toPort.rotation) % 4) {
case 0: // Up
x2 += 1;
y2 += 1;
break;
case 1: // Right
x2 -= 2;
y2 += 1;
break;
case 2: // Down
x2 -= 2;
y2 -= 2;
break;
case 3: // Left
x2 += 1;
y2 -= 2;
break;
}
g.fillRect(Math.min(x1, x2), y1, Math.abs(x1 - x2), 2);
g.fillRect(x2, Math.min(y1, y2), 2, Math.abs(y1 - y2));
g.fillRect(x1, y1, 2, 2);
g.fillRect(x2, y2, 2, 2);
g.fillRect(x2, y1, 2, 2);
}
public Port otherPort(Port p) {
if (fromPort == p) {
return toPort;
}
if (toPort == p) {
return fromPort;
}
return null;
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,157 +1,146 @@
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
{
public boolean hot;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public LabCursor(){}
public class LabCursor extends Item {
public boolean hot;
public LabCursor(int X, int Y, Room r)
{
x=X; y=Y;
hot=false;
room=r;
width=28; height=32;
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
{
g = icons[0].getImage().getGraphics();
}
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
{
g = icons[1].getImage().getGraphics();
}
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)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
}
public LabCursor(int X, int Y, Room r) {
x = X;
y = Y;
hot = false;
room = r;
width = 28;
height = 32;
GenerateIcons();
}
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_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"))
{
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Save Chip", FileDialog.SAVE);
fd.setDirectory("chips");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null)
((SmallChip)carrying).SaveChip(fd.getDirectory()+fd.getFile());
return false;
}
if (carrying != null)
Drops();
level.solderingPen.x = x;
level.solderingPen.y = y;
level.solderingPen.room = room;
room = null;
if (level.currentViewer == level.player)
level.currentViewer=level.solderingPen;
level.player = level.solderingPen;
if (level.remote != null)
if (level.remote.carriedBy != null)
{
level.remote.carriedBy = level.player;
}
}
if (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;
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
g.setColor(new Color(255, 128, 0));
g.fillRect(0, 0, width, height);
if (hot) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
}
public boolean CanBePickedUp(Item i) {
return !(i instanceof GenericRobot);
}
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_L) {
if (carrying != null) {
if (carrying instanceof SmallChip) {
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
fd.setDirectory("chips");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null) {
((SmallChip) carrying).Empty();
((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
}
}
}
}
else if (e.getKeyCode() == KeyEvent.VK_H) {
hot = !hot;
if (hot) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_S) {
if (level.solderingPen == null) {
return false;
}
if (carrying != null) {
if (carrying instanceof SmallChip) {
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
fd.setDirectory("chips");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null) {
((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
}
return false;
}
}
if (carrying != null) {
Drops();
}
level.solderingPen.x = x;
level.solderingPen.y = y;
level.solderingPen.room = room;
room = null;
if (level.currentViewer == level.player) {
level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen;
if (level.remote != null) {
if (level.remote.carriedBy != null) {
level.remote.carriedBy = level.player;
}
}
}
else if (e.getKeyCode() == KeyEvent.VK_R) {
if (level.remote == null) {
return false;
}
if (level.remote.carriedBy == null) { // Summon Remote
level.remote.x = 28;
level.remote.y = -20;
level.remote.carriedBy = level.player;
level.remote.room = level.player.room;
level.electricity = true;
}
else { // Hide Remote
level.remote.carriedBy = null;
level.remote.room = null;
level.electricity = false;
}
// if (carrying != null)
// Drops();
// level.remote.x = x;
@@ -161,280 +150,272 @@ public boolean KeyUp(KeyEvent e)
// 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)
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)
{
// 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 (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)");
}
}
else if (e.getKeyCode() == KeyEvent.VK_P) {
if (level.paintbrush == null) {
return false;
}
if (carrying != null) {
Drops();
}
level.paintbrush.x = (x / 28) * 28;
level.paintbrush.y = (y / 32) * 32;
level.paintbrush.room = room;
room = null;
if (level.currentViewer == level.player) {
level.currentViewer = level.paintbrush;
}
level.player = level.paintbrush;
}
else if (e.getKeyCode() == KeyEvent.VK_T) {
if (level.toolbox == null) {
return false;
}
if (level.toolbox.room != room) {
// Summon Toolbox
if (carrying != null) {
return false;
}
if (((ToolBox) level.toolbox).open) {
((ToolBox) level.toolbox).Toggle();
}
level.toolbox.room = room;
level.toolbox.x = x + 28;
level.toolbox.y = y + 6;
PicksUp(level.toolbox);
}
else {
((ToolBox) level.toolbox).Toggle();
}
}
else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
if (carrying != null) {
if (carrying instanceof GenericChip) {
((GenericChip) carrying).ShowText(true);
return false;
}
}
if (level.helpCam == null) {
return false;
}
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
if (carriedBy == null) {
MoveRight(e.isControlDown());
}
repeating = 0;
return true;
}
else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
if (carriedBy == null) {
MoveLeft(e.isControlDown());
}
repeating = 0;
return true;
}
else if (e.getKeyCode() == KeyEvent.VK_UP) {
if (carriedBy == null) {
MoveUp(e.isControlDown());
}
repeating = 0;
return true;
}
else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (carriedBy == null) {
MoveDown(e.isControlDown());
}
repeating = 0;
return true;
}
else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
if (carrying != null) {
Drops();
}
else {
Item item = level.FindNearestItem(level.gameCursor);
if (item != null) {
if (item.CanBePickedUp(level.gameCursor)) {
PicksUp(item);
}
}
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
if (carrying != null) {
if (carrying.isDevice()) {
((Device) carrying).rotate(1);
}
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
if (carrying != null) {
if (carrying.isDevice()) {
((Device) carrying).rotate(-1);
}
}
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_E) {
Item item = level.FindNearestItem(this);
if (item != null) {
if (item.InternalRoom != null) {
if (Overlaps(item)) {
if (!item.OverWall()) {
int newX = 280; // 10 * 28
int newY = 176; // 5.5 * 32
x = newX;
y = newY;
SetRoom(item.InternalRoom);
}
}
}
}
}
else if (e.getKeyCode() == KeyEvent.VK_X) {
if (room != null && room.portalItem != null) {
Dimension d = room.portalItem.GetXY();
int newX = d.width
+ room.portalItem.getWidth() / 2
- width / 2;
int newY = d.height
+ room.portalItem.getHeight() / 4 * 2
- height / 2;
x = newX;
y = newY;
SetRoom(room.portalItem.room);
level.currentViewer = level.player;
}
} else if (e.getKeyCode() == KeyEvent.VK_F) {
if (carrying != null) {
if (carrying instanceof Device) {
((Device) carrying).flip();
}
}
} else if (e.getKeyCode() == KeyEvent.VK_M) {
Runtime runtime = Runtime.getRuntime();
long freemem = runtime.freeMemory();
long totalmem = runtime.totalMemory();
System.out.println("Total Memory = " + totalmem
+ ", (" + totalmem / 1024 + "K), ("
+ totalmem / 1024 / 1024 + "M)");
System.out.println("Free Memory = " + freemem
+ ", (" + freemem / 1024 + "K), ("
+ freemem / 1024 / 1024 + "M)");
}
return false;
}
return 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 boolean KeyDown(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveRight(e.isControlDown());
}
return true;
}
return false;
}
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveLeft(e.isControlDown());
}
return true;
}
return false;
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveUp(e.isControlDown());
}
return true;
}
return false;
}
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
repeating++;
if (repeating > 10) {
if (carriedBy == null) {
MoveDown(e.isControlDown());
}
return true;
}
return false;
}
return false;
}
public void MoveUp(boolean nudge)
{
Item item = level.FindNearestItem(this);
if (item != null)
{
if (item.InternalRoom != null)
if (item.UpEnterOverlap(this))
{
int newX = 280; // 10 * 28
int newY = 320; // 10 * 32
x = newX;
y = newY;
SetRoom(item.InternalRoom);
}
}
super.MoveUp( nudge);
}
public void 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 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 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);
}
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,277 +1,302 @@
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
{
// 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.
//
// Detectable, blocks all Red
// Undetectable, blocks all Green
// Undetectable, blocks Orange Orange
// Undetectable, blocks White White
// Undetectable, blocks Blue Blue
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
int emptyIndex=0;
int paintIndex; // Which paintMats[] am I using?
transient Material[] paintMats;
int matIndex; // index of chosen paintMax in level.materials
public class PaintBrush extends Item {
// 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.
//
// Detectable, blocks all Red
// Undetectable, blocks all Green
// Undetectable, blocks Orange Orange
// Undetectable, blocks White White
// Undetectable, blocks Blue Blue
public PaintBrush()
{
width=28; height=32;
GenerateIcons();
}
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 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));
icons[2]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[3]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[4]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
for (int a=0; a<5; a++)
{
try
{
g = icons[a].getImage().getGraphics();
}
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));
break;
case 1: g.setColor(new Color(0,192,0));
break;
case 2: g.setColor(new Color(192,96,0));
break;
case 3: g.setColor(new Color(192,192,192));
break;
case 4: g.setColor(new Color(0,0,192));
break;
}
public PaintBrush() {
width = 28;
height = 32;
GenerateIcons();
}
g2.fillRect(0,0,28,18);
g2.fillRect(4,18,20,2);
g2.fillRect(8,20,12,10);
g2.fillRect(12,30,4,2);
g.setColor(Color.black);
g2.fillRect(0,12,28,2);
g2.fillRect(12,26,4,2);
}
currentIcon=icons[0].getImage();
paintMats = new Material[5];
emptyIndex = 0;
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)
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);
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);
paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue));
paintIndex=0;
matIndex = level.materials.indexOf(paintMats[paintIndex]);
}
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));
icons[2] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[4] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
for (int a = 0; a < 5; a++) {
try {
g = icons[a].getImage().getGraphics();
}
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));
break;
case 1:
g.setColor(new Color(0, 192, 0));
break;
case 2:
g.setColor(new Color(192, 96, 0));
break;
case 3:
g.setColor(new Color(192, 192, 192));
break;
case 4:
g.setColor(new Color(0, 0, 192));
break;
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_C)
{
level.gameCursor.x = x;
level.gameCursor.y = y;
level.gameCursor.room = room;
room = null;
if (level.currentViewer == level.player)
level.currentViewer=level.gameCursor;
level.player = level.gameCursor;
}
if (e.getKeyCode() == 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;
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);
}
return false;
}
g2.fillRect(0, 0, 28, 18);
g2.fillRect(4, 18, 20, 2);
g2.fillRect(8, 20, 12, 10);
g2.fillRect(12, 30, 4, 2);
g.setColor(Color.black);
g2.fillRect(0, 12, 28, 2);
g2.fillRect(12, 26, 4, 2);
}
currentIcon = icons[0].getImage();
public void MoveUp(boolean nudge)
{
int dist = 32;
if (nudge) dist = 2;
y=y-dist;
if (y<0)
{
if (room.getUpRoom(this) != null)
{ // change Rooms
y=y+384;
SetRoom(room.getUpRoom(this));
}
else // stop at top
y=0;
}
}
paintMats = new Material[5];
emptyIndex = 0;
paintMats[0] = Material.FindSimiliar(new Material(Color.red, false, true));
paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false));
Item robot = null;
public void MoveDown(boolean nudge)
{
int dist = 32;
if (nudge) dist = 2;
y=y+dist;
if (y>383)
{
if (room.getDownRoom(this) != null)
{ // change Rooms
y=y-384;
SetRoom(room.getDownRoom(this));
}
else // stop at bottom
y=384-32;
}
}
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)));
public void MoveLeft(boolean nudge)
{
int dist = 28;
if (nudge) dist = 2;
x=x-dist;
if (x<0)
{
if (room.getLeftRoom(this) != null)
{ // change Rooms
x=x+560;
SetRoom(room.getLeftRoom(this));
}
else // stop at left
x=0;
}
}
for (Item item : level.items) {
if(item instanceof WhiteRobot) {
robot = item;
}
}
paintMats[3] = Material.FindSimiliar(new RobotBlocker(robot, Color.white));
public void MoveRight(boolean nudge)
{
int dist = 28;
if (nudge) dist = 2;
x=x+dist;
if (x>559)
{
if (room.getRightRoom(this) != null)
{ // change Rooms
x=x-560;
SetRoom(room.getRightRoom(this));
}
else // stop at right
x=560-28;
}
}
for(Item item : level.items) {
if(item instanceof BlueRobot) {
robot = item;
}
}
}
paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue));
paintIndex = 0;
matIndex = level.materials.indexOf(paintMats[paintIndex]);
}
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_C) {
level.gameCursor.x = x;
level.gameCursor.y = y;
level.gameCursor.room = room;
room = null;
if (level.currentViewer == level.player) {
level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor;
}
if (e.getKeyCode() == KeyEvent.VK_S) {
if (level.solderingPen == null) {
return false;
}
level.solderingPen.x = x;
level.solderingPen.y = y;
level.solderingPen.room = room;
room = null;
if (level.currentViewer == level.player) {
level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen;
}
if (e.getKeyCode() == KeyEvent.VK_R) {
if (level.remote == null) {
return false;
}
level.remote.x = x;
level.remote.y = y;
level.remote.room = room;
room = null;
if (level.currentViewer == level.player) {
level.currentViewer = level.remote;
}
level.player = level.remote;
}
if (e.getKeyCode() == KeyEvent.VK_SLASH) {
if (level.helpCam == null) {
return false;
}
level.player = level.helpCam;
level.currentViewer = level.helpCam;
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
if (e.isShiftDown()) {
SetRoom(room.rightRoom);
}
if (carriedBy == null) {
MoveRight(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
if (e.isShiftDown()) {
SetRoom(room.leftRoom);
}
if (carriedBy == null) {
MoveLeft(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
if (e.isShiftDown()) {
SetRoom(room.upRoom);
}
if (carriedBy == null) {
MoveUp(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (e.isShiftDown()) {
SetRoom(room.downRoom);
}
if (carriedBy == null) {
MoveDown(e.isControlDown());
}
repeating = 0;
return true;
}
if (e.getKeyCode() == KeyEvent.VK_P) {
paintIndex++;
if (paintIndex == 5) {
paintIndex = 0;
}
matIndex = level.materials.indexOf(paintMats[paintIndex]);
currentIcon = icons[paintIndex].getImage();
}
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
if (!room.editable) {
return false;
}
int bigX = (x + 14) / 28;
int bigY = (y + 16) / 32;
if (room.RoomArray[bigY][bigX] == emptyIndex) {
room.SetMaterial(bigX, bigY, matIndex);
}
else {
room.SetMaterial(bigX, bigY, emptyIndex);
}
}
return false;
}
public void MoveUp(boolean nudge) {
int dist = 32;
if (nudge) {
dist = 2;
}
y = y - dist;
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) {
int dist = 32;
if (nudge) {
dist = 2;
}
y = y + dist;
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) {
int dist = 28;
if (nudge) {
dist = 2;
}
x = x - dist;
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) {
int dist = 28;
if (nudge) {
dist = 2;
}
x = x + dist;
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

@@ -1,311 +1,233 @@
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;
level.electricity = true;
GenerateIcons();
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
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 class Remote extends Item {
public Remote() {
width = 4;
height = 20;
level.electricity = true;
GenerateIcons();
}
icons = new ImageIcon[1];
icons[0]= 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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to Remote Image");
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(2,0,2,20);
g2.fillRect(0,16,4,4);
currentIcon = icons[0].getImage();
Graphics g;
Graphics2D g2;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Remote Image");
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(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) {
room = carriedBy.room;
}
}
super.Animate();
}
}
public boolean CanBePickedUp(Item i) {
return false;
}
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 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) {
level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen;
}
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) {
level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor;
}
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) {
level.currentViewer = level.paintbrush;
}
level.player = level.paintbrush;
}
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;
}
}
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) {
level.electricity = !level.electricity;
}
return false;
}
public boolean CanBePickedUp(Item i)
{
// if (i.getClass().toString().endsWith("Robot"))
return false;
// return true;
}
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 boolean KeyUp(KeyEvent e)
{
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_C)
{
level.gameCursor.x = x;
level.gameCursor.y = y;
level.gameCursor.room = room;
room = null;
if (level.currentViewer == level.player)
level.currentViewer=level.gameCursor;
level.player = level.gameCursor;
}
if (e.getKeyCode() == e.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)
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)
{
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)
{
level.electricity = ! level.electricity;
}
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 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 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 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 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 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);
}
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);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -7,201 +7,184 @@ import com.droidquest.devices.PrototypeChip;
import com.droidquest.devices.SmallChip;
import com.droidquest.items.Item;
public class ChipCompiler extends Thread
{
public static int chipSpeed=1;
public class ChipCompiler extends Thread {
public static int chipSpeed = 1;
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++)
sc.signals.addElement(new Signal());
Signal dummy = new Signal();
dummy.working = false;
sc.signals.addElement(dummy);
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;
}
sc.ports[a].type = pc.ports[a].type;
sc.portSignals[a].type = pc.ports[a].type;
}
public ChipCompiler(PrototypeChip pc, SmallChip sc) {
pc.grabbable = false;
sc.grabbable = false;
int a;
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())
{
Device device = (Device) item;
Gate gate=null;
String type = item.getClass().toString();
if (device instanceof com.droidquest.devices.ANDGate)
gate = new Gate("AND");
if (device instanceof com.droidquest.devices.ORGate)
gate = new Gate("OR");
if (device instanceof com.droidquest.devices.NOTGate)
gate = new Gate("NOT");
if (device instanceof com.droidquest.devices.XORGate)
gate = new Gate("XOR");
if (device instanceof com.droidquest.devices.FlipFlop)
{
gate = new Gate("FF");
gate.state = ((FlipFlop)device).state;
}
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
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")
{
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)
{
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)
{
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)
sc.portSignals[ps].internalSignal
= gate1.portSignals[0].externalSignal;
}
}
sc.gates.removeElement(gate1);
a--;
}
}
sc.Empty();
// 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++)
{
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 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 ");
used = true;
}
}
}
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);
sc.signals.removeElement(sig1);
a--;
}
}
// Set Signal types
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)
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)
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);
sc.GenerateIcons();
pc.grabbable = true;
sc.grabbable = true;
}
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++) {
Wire wire = pc.portdevices[a].ports[0].myWire;
int index = pc.InternalRoom.wires.indexOf(wire);
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 = pc.level.items.elementAt(a);
if (item.room == pc.InternalRoom) {
if (item.isDevice()) {
Device device = (Device) item;
Gate gate = null;
if (device instanceof com.droidquest.devices.ANDGate) {
gate = new Gate("AND");
}
if (device instanceof com.droidquest.devices.ORGate) {
gate = new Gate("OR");
}
if (device instanceof com.droidquest.devices.NOTGate) {
gate = new Gate("NOT");
}
if (device instanceof com.droidquest.devices.XORGate) {
gate = new Gate("XOR");
}
if (device instanceof com.droidquest.devices.FlipFlop) {
gate = new Gate("FF");
gate.state = ((FlipFlop) device).state;
}
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);
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 = 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) {
for (int b = 0; b < sc.gates.size(); b++) // For every other Gate in the Chip
{
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
{
gate2.portSignals[bp].externalSignal
= gate1.portSignals[0].externalSignal;
}
}
}
}
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
for (a = 0; a < sc.signals.size(); a++) {
boolean used = false;
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)
{
if (sig1 == sig2) {
used = true;
}
}
}
}
for (int ps = 0; ps < 8; ps++) {
if (sc.portSignals[ps].internalSignal == sig1) {
used = true;
}
}
if (!used) {
sc.signals.removeElement(sig1);
a--;
}
}
// Set Signal types
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 = 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) {
System.out.println("PortSignal "
+ a
+ " = Signal "
+ sc.signals.indexOf(sc.portSignals[a].internalSignal));
}
}
sc.speed = chipSpeed;
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,310 +1,267 @@
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 transient PortSignal[] portSignals = new PortSignal[8];
public boolean state;
public String type;
public int speed;
public class Gate implements Serializable
{
public transient PortSignal[] portSignals = new PortSignal[8];
public boolean state;
public String type;
public int speed;
public Vector<Signal> mySignals = new Vector<Signal>();
public Vector<Gate> myGates = new Vector<Gate>();
public Vector mySignals = new Vector();
public Vector myGates = new Vector();
public Gate(String t)
{
// Called whenever a non-chip gate is created.
type = t;
speed = 1;
for (int a=0; a<8; a++)
portSignals[a] = new PortSignal();
public Gate(String t) {
// Called whenever a non-chip gate is created.
type = t;
speed = 1;
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
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++)
portSignals[a] = new PortSignal();
for (int a=0; a<sc.signals.size(); a++)
{
Signal newsig = new Signal();
Signal oldsig = (Signal) 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);
Gate newgate = new Gate(oldgate);
myGates.addElement(newgate);
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;
}
}
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].type = sc.portSignals[a].type;
}
}
public Gate(SmallChip sc) {
// Called by ChipCompiler to put a nested chip into a gate
speed = sc.speed;
type = "Chip";
}
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++)
portSignals[a] = new PortSignal();
if (type.equalsIgnoreCase("Chip"))
{
for (int a=0; a<g.mySignals.size(); a++)
{
Signal newsig = new Signal();
Signal oldsig = (Signal) 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);
Gate newgate = new Gate(oldgate);
myGates.addElement(newgate);
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);
}
}
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].type = g.portSignals[a].type;
}
}
}
}
portSignals = new PortSignal[8];
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
for (int a = 0; a < sc.signals.size(); a++) {
Signal newsig = new Signal();
Signal oldsig = sc.signals.elementAt(a);
newsig.Set(oldsig.Get());
newsig.working = oldsig.working;
mySignals.addElement(newsig);
}
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++)
{
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
gate.writeRef(s);
}
}
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) {
int sigIndex = sc.signals.indexOf(oldgate.portSignals[b].externalSignal);
newgate.portSignals[b].externalSignal = mySignals.elementAt(sigIndex);
}
}
}
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);
}
for (int a=0; a<myGates.size(); a++)
{
Gate gate = (Gate) myGates.elementAt(a);
gate.portSignals = new PortSignal[8];
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);
gate.portSignals[b].type = s.readInt();
}
gate.readRef(s);
}
}
for (int a = 0; a < 8; a++) {
if (sc.portSignals[a].internalSignal != null) {
int sigIndex = sc.signals.indexOf(sc.portSignals[a].internalSignal);
portSignals[a].internalSignal = mySignals.elementAt(sigIndex);
portSignals[a].type = sc.portSignals[a].type;
}
}
public void Function()
{
if (type.equalsIgnoreCase("AND"))
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
& portSignals[1].externalSignal.Get());
if (type.equalsIgnoreCase("OR"))
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
| portSignals[1].externalSignal.Get());
if (type.equalsIgnoreCase("NOT"))
portSignals[1].externalSignal.Set(!portSignals[0].externalSignal.Get());
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())
state = portSignals[0].externalSignal.Get();
portSignals[2].externalSignal.Set(state);
portSignals[3].externalSignal.Set(!state);
}
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)
portSignals[3].externalSignal.Set(portSignals[0].externalSignal.Get());
}
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 a=0; a<8; a++)
if (portSignals[a].externalSignal!=null
&& 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<8; a++)
if (portSignals[a].externalSignal!=null
&& 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
{
s.writeInt(mySignals.size());
for (int a=0; a<mySignals.size(); a++)
{
Signal sig = (Signal)mySignals.elementAt(a);
s.writeBoolean(sig.Get());
s.writeBoolean(sig.working);
}
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);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
for (int b=0; b<8; b++)
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
if (gate.type.equalsIgnoreCase("Chip"))
gate.SaveSubGate(s);
}
s.writeInt(speed);
}
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++) {
portSignals[a] = new PortSignal();
}
if (type.equalsIgnoreCase("Chip")) {
for (int a = 0; a < g.mySignals.size(); a++) {
Signal newsig = new Signal();
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 = g.myGates.elementAt(a);
Gate newgate = new Gate(oldgate);
myGates.addElement(newgate);
for (int b = 0; b < 8; b++) {
int signalIndex = g.mySignals.indexOf(oldgate.portSignals[b].externalSignal);
if (signalIndex != -1) {
newgate.portSignals[b].externalSignal = mySignals.elementAt(signalIndex);
}
}
}
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 = mySignals.elementAt(sigIndex);
portSignals[a].type = g.portSignals[a].type;
}
}
}
}
public void LoadSubGate(ObjectInputStream s) throws IOException, ClassNotFoundException
{
int numSignals = s.readInt();
mySignals = new Vector();
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++)
{
int sigIndex = s.readInt();
if (sigIndex>=0)
portSignals[a].internalSignal = (Signal) mySignals.elementAt(sigIndex);
portSignals[a].type = s.readInt();
}
int numGates = s.readInt();
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++)
{
int sigIndex = s.readInt();
if (sigIndex>=0)
newGate.portSignals[b].externalSignal = (Signal) mySignals.elementAt(sigIndex);
}
if (newGate.type.equalsIgnoreCase("Chip"))
newGate.LoadSubGate(s);
}
speed = s.readInt();
}
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 = myGates.elementAt(a);
for (int b = 0; b < 8; b++) {
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
gate.writeRef(s);
}
}
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]));
}
public void readRef(ObjectInputStream s) throws IOException {
for (int a = 0; a < 8; a++) {
int portIndex = s.readInt();
if (portIndex >= 0) {
portSignals[a].internalSignal = mySignals.elementAt(portIndex);
}
}
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++) {
gate.portSignals[b] = new PortSignal();
int sigIndex = s.readInt();
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")) {
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
& portSignals[1].externalSignal.Get());
}
else if (type.equalsIgnoreCase("OR")) {
portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()
| portSignals[1].externalSignal.Get());
}
else if (type.equalsIgnoreCase("NOT")) {
portSignals[1].externalSignal.Set(!portSignals[0].externalSignal.Get());
}
else if (type.equalsIgnoreCase("XOR")) {
portSignals[2].externalSignal.Set(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);
}
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) {
portSignals[3].externalSignal.Set(portSignals[0].externalSignal.Get());
}
}
else if (type.equalsIgnoreCase("Chip")) {
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++) {
if (portSignals[a].externalSignal != null
&& 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++) {
myGates.elementAt(a).Function();
}
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].externalSignal.Set(portSignals[a].internalSignal.Get());
}
}
}
}
}
}
public void SaveSubGate(ObjectOutputStream s) throws IOException {
s.writeInt(mySignals.size());
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++) {
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 = myGates.elementAt(a);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
for (int b = 0; b < 8; b++) {
s.writeInt(mySignals.indexOf(gate.portSignals[b].externalSignal));
}
if (gate.type.equalsIgnoreCase("Chip")) {
gate.SaveSubGate(s);
}
}
s.writeInt(speed);
}
public void LoadSubGate(ObjectInputStream s) throws IOException, ClassNotFoundException {
int numSignals = s.readInt();
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++) {
int sigIndex = s.readInt();
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++) {
Gate newGate = new Gate((String) s.readObject());
newGate.state = s.readBoolean();
myGates.addElement(newGate);
for (int b = 0; b < 8; b++) {
int sigIndex = s.readInt();
if (sigIndex >= 0) {
newGate.portSignals[b].externalSignal = mySignals.elementAt(sigIndex);
}
}
if (newGate.type.equalsIgnoreCase("Chip")) {
newGate.LoadSubGate(s);
}
}
speed = s.readInt();
}
}

View File

@@ -12,183 +12,180 @@ import com.droidquest.devices.Device;
import com.droidquest.items.Item;
import com.droidquest.levels.Level;
public class Port implements Serializable
{
// Input or Output of a Device
public class Port implements Serializable {
// Input or Output of a Device
public int type; // 0=Input, 1=Output, 2=Undefined
public static final int TYPE_INPUT = 0;
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?
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;
public static final int ROT_DOWN = 2;
public static final int ROT_LEFT = 3;
public int type; // 0=Input, 1=Output, 2=Undefined
public static final int TYPE_INPUT = 0;
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
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;
public static final int ROT_DOWN = 2;
public static final int ROT_LEFT = 3;
public boolean value; // True or False, what else?
public int x,y;
public int width, height; // width & height
public int wireX, wireY;
public transient Item myDevice;
public transient Wire myWire;
public boolean locked; // False = Reverts to Undefined with no connections
public boolean value; // True or False, what else?
public int x, y;
public int width, height; // width & height
private int wireX;
private int wireY;
public transient Item myDevice;
public transient Wire myWire;
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)
{
// 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:
// (Input/Output/Undefined) * (U/D/L/R) * (On/Off). Undefined is
// always Off. If the type is not Standard, it's a chip port, and
// uses no graphics.
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;
}
else
{
width = 2; height = 2;
wireX = x; wireY = y;
}
if (type==TYPE_UNDEFINED)
locked=false;
else
locked=true;
}
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:
// (Input/Output/Undefined) * (U/D/L/R) * (On/Off). Undefined is
// always Off. If the type is not Standard, it's a chip port, and
// uses no graphics.
public void writeRef(ObjectOutputStream s) throws IOException
{
Level level = myDevice.level;
s.writeInt(level.items.indexOf(myDevice));
if (myDevice.room != null)
s.writeInt(myDevice.room.wires.indexOf(myWire));
}
x = X;
y = Y;
type = Type;
size = Size;
rotation = rot;
standard = (size > 0);
myDevice = d;
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());
}
if (standard) {
width = 12;
height = size;
wireX = x + 6;
wireY = y + height - 6;
}
else {
width = 2;
height = 2;
wireX = x;
wireY = y;
}
public void Draw(Graphics g, int rot)
{
if (value)
g.setColor(new Color(255,128,0));
else
g.setColor(Color.white);
int relRot = (rotation + rot)%4;
if (standard)
{
switch (type)
{
case TYPE_INPUT:
switch(relRot)
{
case 0: // Up
g.fillRect(x+0,y+4,4,size);
g.fillRect(x-4,y+0,4,4);
g.fillRect(x+4,y+0,4,4);
g.fillRect(x+0,y-2,4,2);
break;
case 1: // Right
g.fillRect(x-size-3,y+0,size,4);
g.fillRect(x-3,y-4,4,4);
g.fillRect(x-3,y+4,4,4);
g.fillRect(x+1,y+0,2,4);
break;
case 2: // Down
g.fillRect(x-3,y-size-3,4,size);
g.fillRect(x-7,y-3,4,4);
g.fillRect(x+1,y-3,4,4);
g.fillRect(x-3,y+1,4,2);
break;
case 3: // Left
g.fillRect(x+4,y-3,size,4);
g.fillRect(x+0,y-7,4,4);
g.fillRect(x+0,y+1,4,4);
g.fillRect(x-2,y-3,2,4);
break;
}
break;
case TYPE_OUTPUT:
switch(relRot)
{
case 0: // Up
g.fillRect(x+0,y+0,4,size);
g.fillRect(x-4,y+2,12,2);
g.fillRect(x-8,y+4,4,2);
g.fillRect(x+8,y+4,4,2);
break;
case 1: // Right
g.fillRect(x-size+1,y+0,size,4);
g.fillRect(x-3,y-4,2,12);
g.fillRect(x-5,y-8,2,4);
g.fillRect(x-5,y+8,2,4);
break;
case 2: // Down
g.fillRect(x-3,y-size,4,size);
g.fillRect(x-7,y-3,12,2);
g.fillRect(x-11,y-5,4,2);
g.fillRect(x+5,y-5,4,2);
break;
case 3: // Left
g.fillRect(x,y-3,size,4);
g.fillRect(x+2,y-7,2,12);
g.fillRect(x+4,y+5,2,4);
g.fillRect(x+4,y-11,2,4);
break;
}
break;
case TYPE_UNDEFINED:
switch(relRot)
{
case 0: // Up
g.fillRect(x-2,y-4,8,12);
g.fillRect(x,y+8,4,size);
g.setColor(Color.black);
g.fillRect(x,y,4,4);
break;
case 1: // Right
g.fillRect(x-7,y-2,12,8);
g.fillRect(x-7-size,y,size,4);
g.setColor(Color.black);
g.fillRect(x-3,y,4,4);
break;
case 2: // Down
g.fillRect(x-5,y-7,8,12);
g.fillRect(x-3,y-7-size,4,size);
g.setColor(Color.black);
g.fillRect(x-3,y-3,4,4);
break;
case 3: // Left
g.fillRect(x-4,y-5,12,8);
g.fillRect(x+8,y-3,size,4);
g.setColor(Color.black);
g.fillRect(x,y-3,4,4);
break;
}
break;
}
}
}
locked = type != TYPE_UNDEFINED;
}
public void writeRef(ObjectOutputStream s) throws IOException {
Level level = myDevice.level;
s.writeInt(level.items.indexOf(myDevice));
if (myDevice.room != null) {
s.writeInt(myDevice.room.wires.indexOf(myWire));
}
}
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 {
g.setColor(Color.white);
}
int relRot = (rotation + rot) % 4;
if (standard) {
switch (type) {
case TYPE_INPUT:
switch (relRot) {
case 0: // Up
g.fillRect(x + 0, y + 4, 4, size);
g.fillRect(x - 4, y + 0, 4, 4);
g.fillRect(x + 4, y + 0, 4, 4);
g.fillRect(x + 0, y - 2, 4, 2);
break;
case 1: // Right
g.fillRect(x - size - 3, y + 0, size, 4);
g.fillRect(x - 3, y - 4, 4, 4);
g.fillRect(x - 3, y + 4, 4, 4);
g.fillRect(x + 1, y + 0, 2, 4);
break;
case 2: // Down
g.fillRect(x - 3, y - size - 3, 4, size);
g.fillRect(x - 7, y - 3, 4, 4);
g.fillRect(x + 1, y - 3, 4, 4);
g.fillRect(x - 3, y + 1, 4, 2);
break;
case 3: // Left
g.fillRect(x + 4, y - 3, size, 4);
g.fillRect(x + 0, y - 7, 4, 4);
g.fillRect(x + 0, y + 1, 4, 4);
g.fillRect(x - 2, y - 3, 2, 4);
break;
}
break;
case TYPE_OUTPUT:
switch (relRot) {
case 0: // Up
g.fillRect(x + 0, y + 0, 4, size);
g.fillRect(x - 4, y + 2, 12, 2);
g.fillRect(x - 8, y + 4, 4, 2);
g.fillRect(x + 8, y + 4, 4, 2);
break;
case 1: // Right
g.fillRect(x - size + 1, y + 0, size, 4);
g.fillRect(x - 3, y - 4, 2, 12);
g.fillRect(x - 5, y - 8, 2, 4);
g.fillRect(x - 5, y + 8, 2, 4);
break;
case 2: // Down
g.fillRect(x - 3, y - size, 4, size);
g.fillRect(x - 7, y - 3, 12, 2);
g.fillRect(x - 11, y - 5, 4, 2);
g.fillRect(x + 5, y - 5, 4, 2);
break;
case 3: // Left
g.fillRect(x, y - 3, size, 4);
g.fillRect(x + 2, y - 7, 2, 12);
g.fillRect(x + 4, y + 5, 2, 4);
g.fillRect(x + 4, y - 11, 2, 4);
break;
}
break;
case TYPE_UNDEFINED:
switch (relRot) {
case 0: // Up
g.fillRect(x - 2, y - 4, 8, 12);
g.fillRect(x, y + 8, 4, size);
g.setColor(Color.black);
g.fillRect(x, y, 4, 4);
break;
case 1: // Right
g.fillRect(x - 7, y - 2, 12, 8);
g.fillRect(x - 7 - size, y, size, 4);
g.setColor(Color.black);
g.fillRect(x - 3, y, 4, 4);
break;
case 2: // Down
g.fillRect(x - 5, y - 7, 8, 12);
g.fillRect(x - 3, y - 7 - size, 4, size);
g.setColor(Color.black);
g.fillRect(x - 3, y - 3, 4, 4);
break;
case 3: // Left
g.fillRect(x - 4, y - 5, 12, 8);
g.fillRect(x + 8, y - 3, size, 4);
g.setColor(Color.black);
g.fillRect(x, y - 3, 4, 4);
break;
}
break;
}
}
}
}
}

View File

@@ -1,12 +1,12 @@
package com.droidquest.chipstuff;
public class PortSignal
{
public Signal externalSignal;
public Signal internalSignal;
public int type;
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
{
transient private int index;
private boolean[] value = new boolean[2];
public boolean working;
public Signal()
{
index=0;
working=true;
}
public void Flip()
{
index = 1-index;
}
public boolean Get()
{
return value[index] && working;
}
public void Set(boolean v)
{
value[1-index] = v && working;
}
public class Signal implements Serializable {
transient private int index;
private boolean[] value = new boolean[2];
public boolean working;
public Signal() {
index = 0;
working = true;
}
public void Flip() {
index = 1 - index;
}
public boolean Get() {
return value[index] && working;
}
public void Set(boolean v) {
value[1 - index] = v && working;
}
}

View File

@@ -4,54 +4,52 @@ import java.awt.Color;
import java.awt.Graphics;
import java.io.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;
public int y;
public Color color;
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;
private int length;
private int x;
public int y;
private Color color;
public Arrow() {}
public Arrow() {
}
public Arrow(int X, int Y, int dir, int len, Color c)
{
x=X; y=Y;
direction = dir;
length = len;
color = c;
}
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)
{
g.setColor(color);
switch(direction)
{
case 0:
g.drawLine(x,y,x-8,y+8);
g.drawLine(x,y,x+8,y+8);
g.drawLine(x,y,x,y+length);
break;
case 1:
g.drawLine(x,y,x-8,y-8);
g.drawLine(x,y,x-8,y+8);
g.drawLine(x,y,x-length,y);
break;
case 2:
g.drawLine(x,y,x-8,y-8);
g.drawLine(x,y,x+8,y-8);
g.drawLine(x,y,x,y-length);
break;
case 3:
g.drawLine(x,y,x+8,y-8);
g.drawLine(x,y,x+8,y+8);
g.drawLine(x,y,x+length,y);
break;
}
}
public void Draw(Graphics g) {
g.setColor(color);
switch (direction) {
case 0:
g.drawLine(x, y, x - 8, y + 8);
g.drawLine(x, y, x + 8, y + 8);
g.drawLine(x, y, x, y + length);
break;
case 1:
g.drawLine(x, y, x - 8, y - 8);
g.drawLine(x, y, x - 8, y + 8);
g.drawLine(x, y, x - length, y);
break;
case 2:
g.drawLine(x, y, x - 8, y - 8);
g.drawLine(x, y, x + 8, y - 8);
g.drawLine(x, y, x, y - length);
break;
case 3:
g.drawLine(x, y, x + 8, y - 8);
g.drawLine(x, y, x + 8, y + 8);
g.drawLine(x, y, x + length, y);
break;
}
}
}

View File

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

View File

@@ -6,39 +6,43 @@ import java.io.Serializable;
import com.droidquest.Room;
public class Spark implements Serializable
{
public int x,y;
public int dx,dy;
public int age;
public Room room;
public class Spark implements Serializable {
public int x, y;
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;
room = r;
age=0;
}
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;
age++;
}
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)
g.setColor(Color.white);
else if (age>=2 && age<4)
g.setColor(Color.yellow);
else
g.setColor(Color.red);
g.fillRect(x,y,2,2);
}
public void Draw(Graphics g) {
if (age < 2) {
g.setColor(Color.white);
}
else if (age >= 2 && age < 4) {
g.setColor(Color.yellow);
}
else {
g.setColor(Color.red);
}
g.fillRect(x, y, 2, 2);
}
}

View File

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

View File

@@ -1,181 +1,185 @@
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;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
}
public void Decorate()
{
super.Decorate();
if (ports[0].value && ports[1].value)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
super.GenerateIcons();
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
g.setColor(Color.white);
else
g.setColor(new Color(255,128,0));
switch(r)
{
case 0: // Up
g.fillRect(8,16,12,2);
g.fillRect(8,16,4,4);
g.fillRect(16,16,4,4);
g.fillRect(4,18,4,6);
g.fillRect(20,18,4,6);
g.fillRect(0,22,4,12);
g.fillRect(24,22,4,12);
g.fillRect(0,32,24,2);
break;
case 1: // Right
g.fillRect(16,0,2,28);
g.fillRect(16,0,12,4);
g.fillRect(16,24,12,4);
g.fillRect(26,4,6,4);
g.fillRect(26,20,6,4);
g.fillRect(30,8,4,4);
g.fillRect(30,16,4,4);
g.fillRect(32,12,2,4);
break;
case 2: // Down
g.fillRect(0,16,28,2);
g.fillRect(0,16,4,12);
g.fillRect(24,16,4,12);
g.fillRect(4,26,4,6);
g.fillRect(20,26,4,6);
g.fillRect(8,30,4,4);
g.fillRect(16,30,4,4);
g.fillRect(12,32,4,2);
break;
case 3: // Left
g.fillRect(32,0,2,28);
g.fillRect(22,0,12,4);
g.fillRect(22,24,12,4);
g.fillRect(18,4,6,4);
g.fillRect(18,20,6,4);
g.fillRect(16,8,4,4);
g.fillRect(16,16,4,4);
g.fillRect(16,12,2,4);
break;
}
}
currentIcon = icons[rotation%2].getImage();
}
public void Decorate() {
super.Decorate();
if (ports[0].value && ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public boolean Function()
{
ports[2].value = ports[0].value & ports[1].value;
return false;
}
public void GenerateIcons() {
super.GenerateIcons();
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
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 (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;
}
if (v == 0) {
g.setColor(Color.white);
}
else {
g.setColor(new Color(255, 128, 0));
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 12, 2);
g.fillRect(8, 16, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(4, 18, 4, 6);
g.fillRect(20, 18, 4, 6);
g.fillRect(0, 22, 4, 12);
g.fillRect(24, 22, 4, 12);
g.fillRect(0, 32, 24, 2);
break;
case 1: // Right
g.fillRect(16, 0, 2, 28);
g.fillRect(16, 0, 12, 4);
g.fillRect(16, 24, 12, 4);
g.fillRect(26, 4, 6, 4);
g.fillRect(26, 20, 6, 4);
g.fillRect(30, 8, 4, 4);
g.fillRect(30, 16, 4, 4);
g.fillRect(32, 12, 2, 4);
break;
case 2: // Down
g.fillRect(0, 16, 28, 2);
g.fillRect(0, 16, 4, 12);
g.fillRect(24, 16, 4, 12);
g.fillRect(4, 26, 4, 6);
g.fillRect(20, 26, 4, 6);
g.fillRect(8, 30, 4, 4);
g.fillRect(16, 30, 4, 4);
g.fillRect(12, 32, 4, 2);
break;
case 3: // Left
g.fillRect(32, 0, 2, 28);
g.fillRect(22, 0, 12, 4);
g.fillRect(22, 24, 12, 4);
g.fillRect(18, 4, 6, 4);
g.fillRect(18, 20, 6, 4);
g.fillRect(16, 8, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(16, 12, 2, 4);
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function() {
ports[2].value = ports[0].value & ports[1].value;
return false;
}
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 (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,193 +1,182 @@
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;
public class Antenna extends Device {
public static int radio = 0; // One frequency that all Antennas use (robots)
private static int radio2 = 0; // Second frequency transmitted outside of robots.
private boolean oldRadio = false; // Was this radio transmitting last phase?
private Color color;
private transient GenericRobot robot;
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 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")) {
robot = (GenericRobot) room.portalItem;
}
}
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
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 boolean oldRadio = false; // Was this radio transmitting last phase?
Color color;
transient GenericRobot robot;
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
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"))
robot = (GenericRobot) room.portalItem;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
radio = 0;
radio2 = 0;
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 (Port port : ports) {
port.myDevice = this;
}
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
}
public void GenerateIcons()
{
robot = (GenericRobot) room.portalItem;
radio=0;
radio2=0;
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;
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
}
public void Animate() {
super.Animate();
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,
level.random.nextInt(9) - 4,
room));
}
}
}
public void Animate()
{
super.Animate();
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,
level.random.nextInt(9)-4,
room));
}
}
public void Decorate() {
super.Decorate();
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
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) {
g.setColor(new Color(255, 128, 0));
}
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);
}
}
}
public void Decorate()
{
super.Decorate();
try
{
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
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)
g.setColor(new Color(255,128,0));
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);
}
}
public boolean Function() {
if (robot != null) {
if (radio < 0) {
radio = 0;
}
public boolean Function()
{
if (robot!=null)
{
if (radio<0)
radio=0;
if (radio>0)
{
robot.antenna = true;
ports[1].value = true;
}
else
{
robot.antenna = false;
ports[1].value = false;
}
if (oldRadio != ports[0].value)
{
if (ports[0].value == true)
{
robot.broadcasting = true;
radio++;
}
else
{
robot.broadcasting = false;
radio--;
}
}
oldRadio = ports[0].value;
}
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)
radio2++;
else
radio2--;
}
oldRadio = ports[0].value;
}
return false;
}
if (radio > 0) {
robot.antenna = true;
ports[1].value = true;
}
else {
robot.antenna = false;
ports[1].value = false;
}
if (oldRadio != ports[0].value) {
if (ports[0].value) {
robot.broadcasting = true;
radio++;
}
else {
robot.broadcasting = false;
radio--;
}
}
oldRadio = ports[0].value;
}
else {
if (radio2 < 0) {
radio2 = 0;
}
public void SetRoom(Room r)
{
if (oldRadio)
{
if (robot!=null)
radio--;
else
radio2--;
}
super.SetRoom(r);
robot=null;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
robot = (GenericRobot) room.portalItem;
}
ports[1].value = radio2 > 0;
if (oldRadio != ports[0].value) {
if (ports[0].value) {
radio2++;
}
else {
radio2--;
}
}
oldRadio = ports[0].value;
}
return false;
}
public void Erase()
{
super.Erase();
robot = null;
}
public void SetRoom(Room r) {
if (oldRadio) {
if (robot != null) {
radio--;
}
else {
radio2--;
}
}
super.SetRoom(r);
robot = null;
if (room.portalItem != null) {
if (room.portalItem.getClass().toString().endsWith("Robot")) {
robot = (GenericRobot) room.portalItem;
}
}
}
public void Erase() {
super.Erase();
robot = null;
}
}

View File

@@ -1,241 +1,241 @@
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 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")) {
robot = (GenericRobot) room.portalItem;
}
}
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public class Bumper extends Device
{
int rotation;
Color color;
transient GenericRobot robot;
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot));
}
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"))
robot = (GenericRobot) room.portalItem;
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
s.writeInt(level.items.indexOf(robot));
}
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
if (ports == null) {
ports = new Port[1];
switch (rotation) {
case Port.ROT_UP:
width = 30;
height = 42;
ports[0] = new Port(16, 39, Port.TYPE_OUTPUT, 26, Port.ROT_DOWN, this);
break;
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
case Port.ROT_RIGHT:
width = 54;
height = 24;
ports[0] = new Port(0, 13, Port.TYPE_OUTPUT, 42, Port.ROT_LEFT, this);
break;
public void GenerateIcons()
{
robot = (GenericRobot) room.portalItem;
if (ports==null)
{
ports = new Port[1];
switch(rotation)
{
case Port.ROT_UP:
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;
ports[0] = new Port(0,13,Port.TYPE_OUTPUT,42,Port.ROT_LEFT,this);
break;
case Port.ROT_DOWN:
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;
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;
icons = new ImageIcon[1];
switch(rotation)
{
case Port.ROT_UP:
width=30; height=42;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_DOWN:
width = 30;
height = 38;
ports[0] = new Port(13, 2, Port.TYPE_OUTPUT, 22, Port.ROT_UP, this);
break;
case Port.ROT_RIGHT:
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;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_LEFT:
width=54; height=24;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
case Port.ROT_LEFT:
width = 54;
height = 24;
ports[0] = new Port(52, 10, Port.TYPE_OUTPUT, 40, Port.ROT_RIGHT, this);
break;
}
}
else {
for (Port port : ports) {
port.myDevice = this;
}
}
public void Decorate()
{
super.Decorate();
currentIcon = icons[0].getImage();
try
{
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch(rotation)
{
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(8,0,14,4);
g.fillRect(4,2,6,4);
g.fillRect(20,2,6,4);
g.fillRect(0,4,6,4);
g.fillRect(24,4,6,4);
g.fillRect(12,6,6,10);
break;
icons = new ImageIcon[1];
switch (rotation) {
case Port.ROT_UP:
width = 30;
height = 42;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
g.fillRect(44,6,10,12);
g.fillRect(40,2,10,6);
g.fillRect(40,16,10,6);
g.fillRect(36,0,10,4);
g.fillRect(36,20,10,4);
g.fillRect(32,0,14,2);
g.fillRect(32,22,14,2);
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
g.fillRect(8,34,14,4);
g.fillRect(4,32,6,4);
g.fillRect(20,32,6,4);
g.fillRect(0,30,6,4);
g.fillRect(24,30,6,4);
g.fillRect(12,22,6,10);
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
g.fillRect(0,6,10,12);
g.fillRect(4,2,10,6);
g.fillRect(4,16,10,6);
g.fillRect(8,0,10,4);
g.fillRect(8,20,10,4);
g.fillRect(8,0,14,2);
g.fillRect(8,22,14,2);
g.fillRect(12,10,14,4);
break;
}
}
case Port.ROT_RIGHT:
width = 54;
height = 24;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
public boolean Function()
{
// Check the walls on the sides of the GenericRobot and set the
// Port outputs and the bumper variables
case Port.ROT_DOWN:
width = 30;
height = 38;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
Dimension d = robot.GetXY();
int X = d.width;
int Y = d.height;
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))
collide = true;
ports[0].value=collide;
robot.topBumper = collide;
}
break;
case Port.ROT_RIGHT: // Right Bumper
{
int bigX = (X+60)/28;
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))
collide = true;
ports[0].value=collide;
robot.rightBumper = collide;
}
break;
case Port.ROT_DOWN: // Bottom Bumper
{
int bigXl = (X+14) / 28;
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))
collide = true;
ports[0].value=collide;
robot.bottomBumper = collide;
}
break;
case Port.ROT_LEFT: // Left Bumper
{
int bigX = (X-3) / 28;
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))
collide = true;
ports[0].value=collide;
robot.leftBumper = collide;
}
break;
}
return false;
}
case Port.ROT_LEFT:
width = 54;
height = 24;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
public void Erase()
{
super.Erase();
robot = null;
}
public void Decorate() {
super.Decorate();
currentIcon = icons[0].getImage();
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(8, 0, 14, 4);
g.fillRect(4, 2, 6, 4);
g.fillRect(20, 2, 6, 4);
g.fillRect(0, 4, 6, 4);
g.fillRect(24, 4, 6, 4);
g.fillRect(12, 6, 6, 10);
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
g.fillRect(44, 6, 10, 12);
g.fillRect(40, 2, 10, 6);
g.fillRect(40, 16, 10, 6);
g.fillRect(36, 0, 10, 4);
g.fillRect(36, 20, 10, 4);
g.fillRect(32, 0, 14, 2);
g.fillRect(32, 22, 14, 2);
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
g.fillRect(8, 34, 14, 4);
g.fillRect(4, 32, 6, 4);
g.fillRect(20, 32, 6, 4);
g.fillRect(0, 30, 6, 4);
g.fillRect(24, 30, 6, 4);
g.fillRect(12, 22, 6, 10);
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
g.fillRect(0, 6, 10, 12);
g.fillRect(4, 2, 10, 6);
g.fillRect(4, 16, 10, 6);
g.fillRect(8, 0, 10, 4);
g.fillRect(8, 20, 10, 4);
g.fillRect(8, 0, 14, 2);
g.fillRect(8, 22, 14, 2);
g.fillRect(12, 10, 14, 4);
break;
}
}
public boolean Function() {
// Check the walls on the sides of the GenericRobot and set the
// Port outputs and the bumper variables
Dimension d = robot.GetXY();
int X = d.width;
int Y = d.height;
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 (robot.level.materialAt(a, bigY, robot.room).Detectable(robot)) {
collide = true;
}
}
ports[0].value = collide;
robot.topBumper = collide;
}
break;
case Port.ROT_RIGHT: // Right Bumper
{
int bigX = (X + 60) / 28;
int bigYt = (Y + 5) / 32;
int bigYb = (Y + 36) / 32;
boolean collide = false;
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;
}
break;
case Port.ROT_DOWN: // Bottom Bumper
{
int bigXl = (X + 14) / 28;
int bigXr = (X + 41) / 28;
int bigY = (Y + 44) / 32;
boolean collide = false;
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;
}
break;
case Port.ROT_LEFT: // Left Bumper
{
int bigX = (X - 3) / 28;
int bigYt = (Y + 5) / 32;
int bigYb = (Y + 36) / 32;
boolean collide = false;
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;
}
break;
}
return false;
}
public void Erase() {
super.Erase();
robot = null;
}
}

View File

@@ -1,86 +1,72 @@
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) {
myChip = gc;
setModal(false);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setSize(new Dimension(250, 300));
public ChipText(GenericChip gc)
{
myChip=gc;
setModal(false);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setSize(new Dimension(250,300));
textarea = new JTextArea("This is a test.");
textarea.setFont(new Font("Serif", Font.PLAIN, 16));
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
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());
JButton saveButton = new JButton("Save");
JButton restoreButton = new JButton("Restore");
textfield = new JTextField(3);
buttonpanel.add(saveButton);
buttonpanel.add(restoreButton);
buttonpanel.add(textfield);
contentPane.add(buttonpanel, BorderLayout.NORTH);
contentPane.add(scrollpane, BorderLayout.CENTER);
pack();
saveButton.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
myChip.description = textarea.getText();
myChip.label = textfield.getText();
myChip.GenerateIcons();
}
});
restoreButton.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
textarea.setText(myChip.description);
textfield.setText(myChip.label);
}
});
}
textarea = new JTextArea("This is a test.");
textarea.setFont(new Font("Serif", Font.PLAIN, 16));
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
public void setEditable(boolean editable)
{
textarea.setEditable(editable);
}
JScrollPane scrollPane = new JScrollPane(textarea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(250, 250));
public void setText(String text, String label)
{
textarea.setText(text);
textfield.setText(label);
}
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);
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
saveButton.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
myChip.description = textarea.getText();
myChip.label = textfield.getText();
myChip.GenerateIcons();
}
});
restoreButton.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
textarea.setText(myChip.description);
textfield.setText(myChip.label);
}
});
}
public void setEditable(boolean editable) {
textarea.setEditable(editable);
}
public void setText(String text, String label) {
textarea.setText(text);
textfield.setText(label);
}
}

View File

@@ -9,159 +9,151 @@ 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;
target = item;
editable=true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
rotation = 1; // Right
d1.width = 28 + target.getWidth();
d1.height = Math.max(target.getHeight(),12);
d2.width = Math.max(target.getWidth(),12);
d2.height = 28 + target.getHeight();
width = d1.width;
height = d1.height;
GenerateIcons();
}
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 "
rotation = 1; // Right
d1.width = 28 + target.getWidth();
d1.height = Math.max(target.getHeight(), 12);
d2.width = Math.max(target.getWidth(), 12);
d2.height = 28 + target.getHeight();
width = d1.width;
height = d1.height;
GenerateIcons();
}
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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));
target.GenerateIcons();
currentIcon = icons[rotation%2].getImage();
}
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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));
target.GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
ports[0].value=false;
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))
{
ports[0].value=true;
a=level.items.size();
}
}
}
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))
{
ports[0].value=true;
a=level.items.size();
}
}
}
return false;
}
public boolean Function() {
ports[0].value = false;
if (room.portalItem == null) {
// Contact Sensor is not inside robot.
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 {
// Contact Sensor is inside Robot.
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()
{
super.Decorate();
switch (rotation)
{
case Port.ROT_UP:
g.drawImage(target.currentIcon, width/2-target.getWidth()/2, 28, level);
break;
case Port.ROT_RIGHT:
g.drawImage(target.currentIcon, 0, height/2-target.getHeight()/2, level);
break;
case Port.ROT_DOWN:
g.drawImage(target.currentIcon, width/2-target.getWidth()/2, 0, level);
break;
case Port.ROT_LEFT:
g.drawImage(target.currentIcon, 28, height/2-target.getHeight()/2, level);
break;
}
}
public void Decorate() {
super.Decorate();
switch (rotation) {
case Port.ROT_UP:
g.drawImage(target.currentIcon, width / 2 - target.getWidth() / 2, 28, level);
break;
case Port.ROT_RIGHT:
g.drawImage(target.currentIcon, 0, height / 2 - target.getHeight() / 2, level);
break;
case Port.ROT_DOWN:
g.drawImage(target.currentIcon, width / 2 - target.getWidth() / 2, 0, level);
break;
case Port.ROT_LEFT:
g.drawImage(target.currentIcon, 28, height / 2 - target.getHeight() / 2, level);
break;
}
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
rotation = 3;
else if (rotation == 3 && dir == 1)
rotation =0;
else
rotation += dir;
if (rotation%2==0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else
{
width = d1.width;
height = d1.height;
}
switch(rotation)
{
case Port.ROT_UP:
ports[0].x = width/2-2;
ports[0].y = 2;
break;
case Port.ROT_RIGHT:
ports[0].x = width-2;
ports[0].y = height/2-2;
break;
case Port.ROT_DOWN:
ports[0].x = width/2+1;
ports[0].y = height-2;
break;
case Port.ROT_LEFT:
ports[0].x = 2;
ports[0].y = height/2+1;
break;
}
}
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
}
else {
rotation += dir;
}
public void Erase()
{
super.Erase();
target = null;
}
if (rotation % 2 == 0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else {
width = d1.width;
height = d1.height;
}
switch (rotation) {
case Port.ROT_UP:
ports[0].x = width / 2 - 2;
ports[0].y = 2;
break;
case Port.ROT_RIGHT:
ports[0].x = width - 2;
ports[0].y = height / 2 - 2;
break;
case Port.ROT_DOWN:
ports[0].x = width / 2 + 1;
ports[0].y = height - 2;
break;
case Port.ROT_LEFT:
ports[0].x = 2;
ports[0].y = height / 2 + 1;
break;
}
}
public void Erase() {
super.Erase();
target = null;
}
}

View File

@@ -1,204 +1,183 @@
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
{
// Base Class for the Logical Devices
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
transient Graphics g;
transient static Color transparent = new Color(0,0,0,0);
public Port[] ports;
public int rotation; // 0=Up, 1=Right, 2=Down, 3=Left
// Reference to the toolbox means this device can be put inside the ToolBox
transient boolean goesInToolbox;
public class Device extends Item {
// Base Class for the Logical Devices
public Device()
{
// Constructor
rotation =0;
}
transient Graphics g;
transient static Color transparent = new Color(0, 0, 0, 0);
public Port[] ports;
public int rotation; // 0=Up, 1=Right, 2=Down, 3=Left
// Reference to the toolbox means this device can be put inside the ToolBox
transient boolean goesInToolbox;
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<ports.length; a++)
ports[a].writeRef(s);
}
protected Device() {
// Constructor
rotation = 0;
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
for (int a=0; a<ports.length; a++)
ports[a].readRef(s,level);
GenerateIcons();
}
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
for (Port port : ports) {
port.writeRef(s);
}
}
public void GenerateIcons()
{
goesInToolbox=false;
if (ports!=null)
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
icons = new ImageIcon[2];
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
{
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 void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
for (Port port : ports) {
port.readRef(s, level);
}
GenerateIcons();
}
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...
//
//
// Return False unless the device is a Node-like device and output
// has changed.
//
return false;
}
public void GenerateIcons() {
goesInToolbox = false;
if (ports != null) {
for (Port port : ports) {
port.myDevice = this;
}
}
public void Decorate()
{
currentIcon = icons[rotation%2].getImage();
try
{
g = currentIcon.getGraphics();
}
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);
}
public boolean isDevice()
{
return true;
}
icons = new ImageIcon[2];
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 {
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 isNode()
{
return false;
}
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...
//
//
// Return False unless the device is a Node-like device and output
// has changed.
//
return false;
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
rotation = 3;
else if (rotation == 3 && dir == 1)
rotation =0;
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)
{
case 1: // Turn Right
oldX = oldX - oldW;
oldY = oldY - oldH;
ports[a].x = (width - oldY)/2;
ports[a].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;
break;
}
}
}
public void Decorate() {
currentIcon = icons[rotation % 2].getImage();
try {
g = currentIcon.getGraphics();
}
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 (Port port : ports) {
port.Draw(g, rotation);
}
}
public void IsDropped()
{
super.IsDropped();
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();
level.items.removeElement(this);
}
}
}
}
public boolean isDevice() {
return true;
}
public boolean CanBePickedUp(Item item)
{
if (item.getClass().toString().endsWith("Robot"))
return false;
else
return super.CanBePickedUp(item);
}
public boolean isNode() {
return false;
}
public void Erase()
{
super.Erase();
g = null;
for (int a=0; a<ports.length; a++)
{
ports[a].myDevice = null;
ports[a].myWire = null;
}
}
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
}
else {
rotation += dir;
}
public void flip()
{
return;
}
int oldW = width;
int oldH = height;
int temp = width;
width = height;
height = temp;
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;
port.x = (width - oldY) / 2;
port.y = (height + oldX) / 2;
break;
case -1: // Turn Left
oldX = oldX - oldW;
oldY = oldY - oldH;
port.x = (width + oldY) / 2;
port.y = (height - oldX) / 2;
break;
}
}
}
public Object clone()
{
Device newDevice = null;
newDevice = (Device) super.clone();
newDevice.ports = null;
newDevice.GenerateIcons();
return newDevice;
}
public void IsDropped() {
super.IsDropped();
if (goesInToolbox) {
if (level.toolbox != null) {
if (((ToolBox) level.toolbox).open) {
if (Overlaps(level.toolbox)) {
// Remove all wires and delete device
for (Port port : ports) {
if (port.myWire != null) {
port.myWire.Remove();
}
}
level.items.removeElement(this);
}
}
}
}
}
}
public boolean CanBePickedUp(Item item) {
return !item.getClass().toString().endsWith("Robot") && super.CanBePickedUp(item);
}
public void Erase() {
super.Erase();
g = null;
for (Port port : ports) {
port.myDevice = null;
port.myWire = null;
}
}
public void flip() {
}
public Object clone() {
Device newDevice;
newDevice = (Device) super.clone();
newDevice.ports = null;
newDevice.GenerateIcons();
return newDevice;
}
}

View File

@@ -1,153 +1,130 @@
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;
target = item;
editable=true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
width = 64 + target.getWidth();
height = 64 + target.getHeight();
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);
ports[2] = new Port(width/2-1,height-4,Port.TYPE_OUTPUT,24,Port.ROT_DOWN,this);
ports[3] = new Port(0,height/2-1,Port.TYPE_OUTPUT,24,Port.ROT_LEFT,this);
GenerateIcons();
}
public class DirectionalSensor extends Device {
private String targetClass;
private Item target;
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);
ports[2] = new Port(width/2-1,height-4,Port.TYPE_OUTPUT,24,Port.ROT_DOWN,this);
ports[3] = new Port(0,height/2-1,Port.TYPE_OUTPUT,24,Port.ROT_LEFT,this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
target.GenerateIcons();
currentIcon = icons[rotation%2].getImage();
}
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 "
width = 64 + target.getWidth();
height = 64 + target.getHeight();
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);
ports[2] = new Port(width / 2 - 1, height - 4, Port.TYPE_OUTPUT, 24, Port.ROT_DOWN, this);
ports[3] = new Port(0, height / 2 - 1, Port.TYPE_OUTPUT, 24, Port.ROT_LEFT, this);
GenerateIcons();
}
public boolean Function()
{
ports[0].value=false;
ports[1].value=false;
ports[2].value=false;
ports[3].value=false;
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))
{
Dimension d = GetXY();
int X = d.width;
int Y = d.height;
if (item.y < Y)
{
ports[0].value=true;
a=level.items.size();
}
if (item.x + item.getWidth() > X + width)
{
ports[1].value=true;
a=level.items.size();
}
if (item.y + item.getHeight() > Y + height)
{
ports[2].value=true;
a=level.items.size();
}
if (item.x < X)
{
ports[3].value=true;
a=level.items.size();
}
}
}
}
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))
{
Dimension d = room.portalItem.GetXY();
int X = d.width;
int Y = d.height;
if (item.y < Y)
{
ports[0].value=true;
a=level.items.size();
}
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())
{
ports[2].value=true;
a=level.items.size();
}
if (item.x < X)
{
ports[3].value=true;
a=level.items.size();
}
}
}
}
return false;
}
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);
ports[2] = new Port(width / 2 - 1, height - 4, Port.TYPE_OUTPUT, 24, Port.ROT_DOWN, this);
ports[3] = new Port(0, height / 2 - 1, Port.TYPE_OUTPUT, 24, Port.ROT_LEFT, this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
target.GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
}
public void Decorate()
{
super.Decorate();
g.setColor(Color.white);
g.drawRect(24,24,target.getWidth()+12, target.getHeight()+12);
g.drawRect(25,25,target.getWidth()+10, target.getHeight()+10);
g.drawImage(target.currentIcon, 30, 30, level);
}
public boolean Function() {
ports[0].value = false;
ports[1].value = false;
ports[2].value = false;
ports[3].value = false;
if (room.portalItem == null) {
// Directional Sensor is not inside robot.
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) {
ports[0].value = true;
a = level.items.size();
}
if (item.x + item.getWidth() > X + width) {
ports[1].value = true;
a = level.items.size();
}
if (item.y + item.getHeight() > Y + height) {
ports[2].value = true;
a = level.items.size();
}
if (item.x < X) {
ports[3].value = true;
a = level.items.size();
}
}
}
}
}
else {
// Directional Sensor is inside Robot.
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) {
ports[0].value = true;
a = level.items.size();
}
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()) {
ports[2].value = true;
a = level.items.size();
}
if (item.x < X) {
ports[3].value = true;
a = level.items.size();
}
}
}
}
}
return false;
}
public void rotate(int dir)
{
// Does not Rotate!
}
public void Decorate() {
super.Decorate();
g.setColor(Color.white);
g.drawRect(24, 24, target.getWidth() + 12, target.getHeight() + 12);
g.drawRect(25, 25, target.getWidth() + 10, target.getHeight() + 10);
g.drawImage(target.currentIcon, 30, 30, level);
}
public void Erase()
{
super.Erase();
target = null;
}
public void rotate(int dir) {
// Does not Rotate!
}
public void Erase() {
super.Erase();
target = null;
}
}

View File

@@ -1,188 +1,201 @@
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;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public class FlipFlop extends Device {
public boolean state;
private Color c1;
private Color c2;
private transient ImageIcon[] images;
public void Decorate()
{
super.Decorate();
if (!state)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
}
public void GenerateIcons()
{
super.GenerateIcons();
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
{
c1 = new Color(255,128,0);
c2 = Color.white;
}
else
{
c1 = Color.white;
c2 = new Color(255,128,0);
}
switch(r)
{
case 0: // Up
g.setColor(c1);
g.fillRect(0,10,24,12);
g.setColor(c2);
g.fillRect(24,10,24,12);
break;
case 1: // Right
g.setColor(c1);
g.fillRect(10,0,12,24);
g.setColor(c2);
g.fillRect(10,24,12,24);
break;
case 2: // Down
g.setColor(c2);
g.fillRect(0,10,24,12);
g.setColor(c1);
g.fillRect(24,10,24,12);
break;
case 3: // Left
g.setColor(c2);
g.fillRect(10,0,12,24);
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)
state = ports[0].value;
ports[2].value = state;
ports[3].value = !state;
return false;
}
public void Decorate() {
super.Decorate();
if (!state) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
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 (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];
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;
ports[2].myWire = wire4;
ports[3].myWire = wire3;
state = !state;
}
public void GenerateIcons() {
super.GenerateIcons();
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
if (v == 0) {
c1 = new Color(255, 128, 0);
c2 = Color.white;
}
else {
c1 = Color.white;
c2 = new Color(255, 128, 0);
}
switch (r) {
case 0: // Up
g.setColor(c1);
g.fillRect(0, 10, 24, 12);
g.setColor(c2);
g.fillRect(24, 10, 24, 12);
break;
case 1: // Right
g.setColor(c1);
g.fillRect(10, 0, 12, 24);
g.setColor(c2);
g.fillRect(10, 24, 12, 24);
break;
case 2: // Down
g.setColor(c2);
g.fillRect(0, 10, 24, 12);
g.setColor(c1);
g.fillRect(24, 10, 24, 12);
break;
case 3: // Left
g.setColor(c2);
g.fillRect(10, 0, 12, 24);
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) {
state = ports[0].value;
}
ports[2].value = state;
ports[3].value = !state;
return false;
}
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 (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];
}
}
ports[0].myWire = wire2;
ports[1].myWire = wire1;
ports[2].myWire = wire4;
ports[3].myWire = wire3;
state = !state;
}
}

View File

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

View File

@@ -1,164 +1,148 @@
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;
grabbable = false;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
robot = (GenericRobot) room.portalItem;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public class Grabber extends Device {
private Color color;
private transient GenericRobot robot;
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
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")) {
robot = (GenericRobot) room.portalItem;
}
}
GenerateIcons();
currentIcon = icons[0].getImage();
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot)); // Index of fromport device
}
public void GenerateIcons()
{
robot = (GenericRobot) room.portalItem;
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;
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void Decorate()
{
super.Decorate();
try
{
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
g.fillRect(24,4,4,10);
g.fillRect(16,4,12,2);
g.fillRect(16,8,12,2);
g.fillRect(16,2,4,10);
g.fillRect(12,0,4,4);
g.fillRect(12,10,4,4);
g.fillRect(4,0,12,2);
g.fillRect(4,12,12,2);
g.fillRect(4,0,4,4);
g.fillRect(4,10,4,4);
g.fillRect(0,2,4,4);
g.fillRect(0,8,4,4);
}
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
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 (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 boolean Function()
{
if (robot.carrying != null)
ports[1].value=true;
else
ports[1].value=false;
if (ports[0].value == false)
{ // Input Low
if (robot.carrying != null)
robot.Drops();
}
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)
{
int CX = item.x+item.getWidth()/2;
int CY = item.y+item.getHeight()/2;
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;
robot.grabber = Port.ROT_UP;
robot.PicksUp(item);
}
public void Decorate() {
super.Decorate();
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
g.fillRect(24, 4, 4, 10);
g.fillRect(16, 4, 12, 2);
g.fillRect(16, 8, 12, 2);
g.fillRect(16, 2, 4, 10);
g.fillRect(12, 0, 4, 4);
g.fillRect(12, 10, 4, 4);
g.fillRect(4, 0, 12, 2);
g.fillRect(4, 12, 12, 2);
g.fillRect(4, 0, 4, 4);
g.fillRect(4, 10, 4, 4);
g.fillRect(0, 2, 4, 4);
g.fillRect(0, 8, 4, 4);
}
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;
robot.grabber = Port.ROT_RIGHT;
robot.PicksUp(item);
}
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;
robot.grabber = Port.ROT_DOWN;
robot.PicksUp(item);
}
public boolean Function() {
ports[1].value = robot.carrying != null;
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;
robot.grabber = Port.ROT_LEFT;
robot.PicksUp(item);
}
}
}
}
}
return false;
}
if (!ports[0].value) { // Input Low
if (robot.carrying != null) {
robot.Drops();
}
}
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) {
int CX = item.x + item.getWidth() / 2;
int CY = item.y + item.getHeight() / 2;
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;
robot.grabber = Port.ROT_UP;
robot.PicksUp(item);
}
public void Erase()
{
super.Erase();
robot = null;
}
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;
robot.grabber = Port.ROT_RIGHT;
robot.PicksUp(item);
}
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;
robot.grabber = Port.ROT_DOWN;
robot.PicksUp(item);
}
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;
robot.grabber = Port.ROT_LEFT;
robot.PicksUp(item);
}
}
}
}
}
return false;
}
public void Erase() {
super.Erase();
robot = null;
}
}

View File

@@ -1,158 +1,157 @@
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;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public class NOTGate extends Device {
private transient ImageIcon[] images;
public void Decorate()
{
super.Decorate();
if (!ports[0].value)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
}
}
public void Decorate() {
super.Decorate();
if (!ports[0].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons() {
super.GenerateIcons();
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
if (v == 0) {
g.setColor(Color.white);
}
else {
g.setColor(new Color(255, 128, 0));
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(12, 20, 4, 4);
g.fillRect(8, 22, 4, 4);
g.fillRect(16, 22, 4, 4);
g.fillRect(4, 26, 4, 4);
g.fillRect(20, 26, 4, 4);
g.fillRect(0, 30, 4, 4);
g.fillRect(24, 30, 4, 4);
g.fillRect(0, 32, 32, 2);
break;
case 1: // Right
g.fillRect(30, 8, 4, 4);
g.fillRect(30, 16, 4, 4);
g.fillRect(26, 12, 4, 4);
g.fillRect(24, 8, 4, 4);
g.fillRect(24, 16, 4, 4);
g.fillRect(20, 4, 4, 4);
g.fillRect(20, 20, 4, 4);
g.fillRect(16, 0, 4, 4);
g.fillRect(16, 24, 4, 4);
g.fillRect(16, 0, 2, 32);
break;
case 2: // Down
g.fillRect(8, 30, 4, 4);
g.fillRect(16, 30, 4, 4);
g.fillRect(12, 26, 4, 4);
g.fillRect(8, 24, 4, 4);
g.fillRect(16, 24, 4, 4);
g.fillRect(4, 20, 4, 4);
g.fillRect(20, 20, 4, 4);
g.fillRect(0, 16, 4, 4);
g.fillRect(24, 16, 4, 4);
g.fillRect(0, 16, 32, 2);
break;
case 3: // Left
g.fillRect(16, 8, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(20, 12, 4, 4);
g.fillRect(22, 8, 4, 4);
g.fillRect(22, 16, 4, 4);
g.fillRect(26, 4, 4, 4);
g.fillRect(26, 20, 4, 4);
g.fillRect(30, 0, 4, 4);
g.fillRect(30, 24, 4, 4);
g.fillRect(32, 0, 2, 32);
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function() {
ports[1].value = !ports[0].value;
return false;
}
public void GenerateIcons()
{
super.GenerateIcons();
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
g.setColor(Color.white);
else
g.setColor(new Color(255,128,0));
switch(r)
{
case 0: // Up
g.fillRect(8,16,4,4);
g.fillRect(16,16,4,4);
g.fillRect(12,20,4,4);
g.fillRect(8,22,4,4);
g.fillRect(16,22,4,4);
g.fillRect(4,26,4,4);
g.fillRect(20,26,4,4);
g.fillRect(0,30,4,4);
g.fillRect(24,30,4,4);
g.fillRect(0,32,32,2);
break;
case 1: // Right
g.fillRect(30,8,4,4);
g.fillRect(30,16,4,4);
g.fillRect(26,12,4,4);
g.fillRect(24,8,4,4);
g.fillRect(24,16,4,4);
g.fillRect(20,4,4,4);
g.fillRect(20,20,4,4);
g.fillRect(16,0,4,4);
g.fillRect(16,24,4,4);
g.fillRect(16,0,2,32);
break;
case 2: // Down
g.fillRect(8,30,4,4);
g.fillRect(16,30,4,4);
g.fillRect(12,26,4,4);
g.fillRect(8,24,4,4);
g.fillRect(16,24,4,4);
g.fillRect(4,20,4,4);
g.fillRect(20,20,4,4);
g.fillRect(0,16,4,4);
g.fillRect(24,16,4,4);
g.fillRect(0,16,32,2);
break;
case 3: // Left
g.fillRect(16,8,4,4);
g.fillRect(16,16,4,4);
g.fillRect(20,12,4,4);
g.fillRect(22,8,4,4);
g.fillRect(22,16,4,4);
g.fillRect(26,4,4,4);
g.fillRect(26,20,4,4);
g.fillRect(30,0,4,4);
g.fillRect(30,24,4,4);
g.fillRect(32,0,2,32);
break;
};
}
currentIcon = icons[rotation%2].getImage();
}
public boolean Function()
{
ports[1].value = !ports[0].value;
return false;
}
}

View File

@@ -11,149 +11,149 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
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;
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;
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;
type=t;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to ANDGate Image");
return;
}
}
public Node(int X, int Y, Room r, int t) {
x = X;
y = Y;
room = r;
width = 36;
height = 32;
type = t;
public void Decorate()
{
super.Decorate();
if (ports[0].value)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ANDGate Image");
}
public void GenerateIcons()
{
super.GenerateIcons();
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);
ports[1] = new Port(16,0,Port.TYPE_OUTPUT,12,Port.ROT_UP,this);
ports[2] = new Port(19,31,Port.TYPE_OUTPUT,12,Port.ROT_DOWN,this);
break;
case TYPE_RIGHT:
ports = new Port[3];
ports[0] = new Port(16,14,Port.TYPE_INPUT,0,Port.ROT_UP,this);
ports[1] = new Port(16,0,Port.TYPE_OUTPUT,12,Port.ROT_UP,this);
ports[2] = new Port(35,14,Port.TYPE_OUTPUT,12,Port.ROT_RIGHT,this);
break;
case TYPE_THREE:
ports = new Port[4];
ports[0] = new Port(16,14,Port.TYPE_INPUT,0,Port.ROT_UP,this);
ports[1] = new Port(16,0,Port.TYPE_OUTPUT,12,Port.ROT_UP,this);
ports[2] = new Port(35,14,Port.TYPE_OUTPUT,12,Port.ROT_RIGHT,this);
ports[3] = new Port(19,31,Port.TYPE_OUTPUT,12,Port.ROT_DOWN,this);
break;
}
if (rotation > 0)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
g.setColor(Color.white);
else
g.setColor(new Color(255,128,0));
switch(r)
{
case 0: // Up
case 2: // Down
g.fillRect(12,12,12,2);
g.fillRect(12,18,12,2);
g.fillRect(12,12,4,8);
g.fillRect(20,12,4,8);
break;
case 1: // Right
case 3: // Left
g.fillRect(12,12,8,4);
g.fillRect(12,20,8,4);
g.fillRect(12,12,2,12);
g.fillRect(18,12,2,12);
break;
};
}
currentIcon = icons[rotation%2].getImage();
}
public boolean Function()
{
boolean oldValue = ports[1].value;
for (int a=1; a<ports.length; a++)
ports[a].value = ports[0].value;
return (ports[0].value != oldValue);
}
}
public boolean isNode()
{
return true;
}
public void Decorate() {
super.Decorate();
if (ports[0].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons() {
super.GenerateIcons();
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);
ports[1] = new Port(16, 0, Port.TYPE_OUTPUT, 12, Port.ROT_UP, this);
ports[2] = new Port(19, 31, Port.TYPE_OUTPUT, 12, Port.ROT_DOWN, this);
break;
case TYPE_RIGHT:
ports = new Port[3];
ports[0] = new Port(16, 14, Port.TYPE_INPUT, 0, Port.ROT_UP, this);
ports[1] = new Port(16, 0, Port.TYPE_OUTPUT, 12, Port.ROT_UP, this);
ports[2] = new Port(35, 14, Port.TYPE_OUTPUT, 12, Port.ROT_RIGHT, this);
break;
case TYPE_THREE:
ports = new Port[4];
ports[0] = new Port(16, 14, Port.TYPE_INPUT, 0, Port.ROT_UP, this);
ports[1] = new Port(16, 0, Port.TYPE_OUTPUT, 12, Port.ROT_UP, this);
ports[2] = new Port(35, 14, Port.TYPE_OUTPUT, 12, Port.ROT_RIGHT, this);
ports[3] = new Port(19, 31, Port.TYPE_OUTPUT, 12, Port.ROT_DOWN, this);
break;
}
if (rotation > 0) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
if (v == 0) {
g.setColor(Color.white);
}
else {
g.setColor(new Color(255, 128, 0));
}
switch (r) {
case 0: // Up
case 2: // Down
g.fillRect(12, 12, 12, 2);
g.fillRect(12, 18, 12, 2);
g.fillRect(12, 12, 4, 8);
g.fillRect(20, 12, 4, 8);
break;
case 1: // Right
case 3: // Left
g.fillRect(12, 12, 8, 4);
g.fillRect(12, 20, 8, 4);
g.fillRect(12, 12, 2, 12);
g.fillRect(18, 12, 2, 12);
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function() {
boolean oldValue = ports[1].value;
for (int a = 1; a < ports.length; a++) {
ports[a].value = ports[0].value;
}
return (ports[0].value != oldValue);
}
public boolean isNode() {
return true;
}
}

View File

@@ -10,180 +10,190 @@ 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;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to ORGate Image");
return;
}
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to ORGate Image");
}
public void Decorate()
{
super.Decorate();
if (ports[0].value || ports[1].value)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public void GenerateIcons()
{
super.GenerateIcons();
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
g.setColor(Color.white);
else
g.setColor(new Color(255,128,0));
switch(r)
{
case 0: // Up
g.fillRect(8,16,12,2);
g.fillRect(8,16,4,4);
g.fillRect(16,16,4,4);
g.fillRect(4,18,4,6);
g.fillRect(20,18,4,6);
g.fillRect(0,22,4,12);
g.fillRect(24,22,4,12);
g.fillRect(0,32,8,2);
g.fillRect(8,30,4,2);
g.fillRect(12,28,4,2);
g.fillRect(16,30,4,2);
g.fillRect(20,32,8,2);
break;
case 1: // Right
g.fillRect(16,0,12,4);
g.fillRect(16,24,12,4);
g.fillRect(26,4,6,4);
g.fillRect(26,20,6,4);
g.fillRect(30,8,4,4);
g.fillRect(30,16,4,4);
g.fillRect(32,12,2,4);
g.fillRect(16,0,2,8);
g.fillRect(16,20,2,8);
g.fillRect(18,8,2,4);
g.fillRect(20,12,2,4);
g.fillRect(18,16,2,4);
break;
case 2: // Down
g.fillRect(0,16,4,12);
g.fillRect(24,16,4,12);
g.fillRect(4,26,4,6);
g.fillRect(20,26,4,6);
g.fillRect(8,30,4,4);
g.fillRect(16,30,4,4);
g.fillRect(12,32,4,2);
g.fillRect(0,16,8,2);
g.fillRect(20,16,8,2);
g.fillRect(8,18,4,2);
g.fillRect(12,20,4,2);
g.fillRect(16,18,4,2);
break;
case 3: // Left
g.fillRect(22,0,12,4);
g.fillRect(22,24,12,4);
g.fillRect(18,4,6,4);
g.fillRect(18,20,6,4);
g.fillRect(16,8,4,4);
g.fillRect(16,16,4,4);
g.fillRect(16,12,2,4);
g.fillRect(32,0,2,8);
g.fillRect(32,20,2,8);
g.fillRect(30,8,2,4);
g.fillRect(28,12,2,4);
g.fillRect(30,16,2,4);
break;
}
}
currentIcon = icons[rotation%2].getImage();
}
public void Decorate() {
super.Decorate();
if (ports[0].value || ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
public boolean Function()
{
ports[2].value = ports[0].value | ports[1].value;
return false;
}
public void GenerateIcons() {
super.GenerateIcons();
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
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 (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;
}
if (v == 0) {
g.setColor(Color.white);
}
else {
g.setColor(new Color(255, 128, 0));
}
switch (r) {
case 0: // Up
g.fillRect(8, 16, 12, 2);
g.fillRect(8, 16, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(4, 18, 4, 6);
g.fillRect(20, 18, 4, 6);
g.fillRect(0, 22, 4, 12);
g.fillRect(24, 22, 4, 12);
g.fillRect(0, 32, 8, 2);
g.fillRect(8, 30, 4, 2);
g.fillRect(12, 28, 4, 2);
g.fillRect(16, 30, 4, 2);
g.fillRect(20, 32, 8, 2);
break;
case 1: // Right
g.fillRect(16, 0, 12, 4);
g.fillRect(16, 24, 12, 4);
g.fillRect(26, 4, 6, 4);
g.fillRect(26, 20, 6, 4);
g.fillRect(30, 8, 4, 4);
g.fillRect(30, 16, 4, 4);
g.fillRect(32, 12, 2, 4);
g.fillRect(16, 0, 2, 8);
g.fillRect(16, 20, 2, 8);
g.fillRect(18, 8, 2, 4);
g.fillRect(20, 12, 2, 4);
g.fillRect(18, 16, 2, 4);
break;
case 2: // Down
g.fillRect(0, 16, 4, 12);
g.fillRect(24, 16, 4, 12);
g.fillRect(4, 26, 4, 6);
g.fillRect(20, 26, 4, 6);
g.fillRect(8, 30, 4, 4);
g.fillRect(16, 30, 4, 4);
g.fillRect(12, 32, 4, 2);
g.fillRect(0, 16, 8, 2);
g.fillRect(20, 16, 8, 2);
g.fillRect(8, 18, 4, 2);
g.fillRect(12, 20, 4, 2);
g.fillRect(16, 18, 4, 2);
break;
case 3: // Left
g.fillRect(22, 0, 12, 4);
g.fillRect(22, 24, 12, 4);
g.fillRect(18, 4, 6, 4);
g.fillRect(18, 20, 6, 4);
g.fillRect(16, 8, 4, 4);
g.fillRect(16, 16, 4, 4);
g.fillRect(16, 12, 2, 4);
g.fillRect(32, 0, 2, 8);
g.fillRect(32, 20, 2, 8);
g.fillRect(30, 8, 2, 4);
g.fillRect(28, 12, 2, 4);
g.fillRect(30, 16, 2, 4);
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function() {
ports[2].value = ports[0].value | ports[1].value;
return false;
}
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 (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,51 +3,47 @@ package com.droidquest.devices;
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
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.
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 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;
width = 20;
height = size+20;
grabbable=false;
GenerateIcons();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
}
}
public void GenerateIcons()
{
super.GenerateIcons();
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 void GenerateIcons() {
super.GenerateIcons();
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)
ports[0].value = true;
return false;
}
public boolean Function() {
if (value && ports[0].type == Port.TYPE_OUTPUT) {
ports[0].value = true;
}
return false;
}
}
}

View File

@@ -1,276 +1,263 @@
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;
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 = {
{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},
{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},
{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},
{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},
{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},
{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;
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
public Prototype16Chip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 40;
height = 40;
portdevices = new PortDevice[16];
portdevices[0] = new PortDevice(16,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(4*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(7*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(12*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(15*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[8] = new PortDevice(500,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[9] = new PortDevice(500,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[10] = new PortDevice(500,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[11] = new PortDevice(500,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[12] = new PortDevice(15*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[13] = new PortDevice(12*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[14] = new PortDevice(7*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[15] = new PortDevice(4*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[0].rotate(1);
portdevices[1].rotate(1);
portdevices[2].rotate(1);
portdevices[3].rotate(1);
portdevices[8].rotate(-1);
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);
GenerateIcons();
for (int a=0; a<16; a++)
level.items.addElement(portdevices[a]);
}
InternalRoom = new Room();
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},
{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},
{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},
{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},
{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},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
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;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
public void GenerateIcons()
{
// super.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);
ports[2] = new Port( 1,24,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[3] = new Port( 1,32,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[4] = new Port( 8,38,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[5] = new Port(16,38,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[6] = new Port(24,38,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[7] = new Port(32,38,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[8] = new Port(38,31,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[9] = new Port(38,23,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[10] = new Port(38,15,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[11] = new Port(38, 7,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[12] = new Port(31, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[13] = new Port(23, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[14] = new Port(15, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[15] = new Port( 7, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(3,3,34,34);
g.fillRect(1,7,2,2);
g.fillRect(1,15,2,2);
g.fillRect(1,23,2,2);
g.fillRect(1,31,2,2);
g.fillRect(7,37,2,2);
g.fillRect(15,37,2,2);
g.fillRect(23,37,2,2);
g.fillRect(31,37,2,2);
g.fillRect(37,31,2,2);
g.fillRect(37,23,2,2);
g.fillRect(37,15,2,2);
g.fillRect(37,7,2,2);
g.fillRect(31,1,2,2);
g.fillRect(23,1,2,2);
g.fillRect(15,1,2,2);
g.fillRect(7,1,2,2);
g.setColor(Color.black);
if (label != null)
{
g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52-X/2, 32);
}
currentIcon = icons[0].getImage();
}
portdevices = new PortDevice[16];
portdevices[0] = new PortDevice(16, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(4 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(7 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(12 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(15 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[8] = new PortDevice(500, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[9] = new PortDevice(500, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[10] = new PortDevice(500, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[11] = new PortDevice(500, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[12] = new PortDevice(15 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[13] = new PortDevice(12 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[14] = new PortDevice(7 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[15] = new PortDevice(4 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[0].rotate(1);
portdevices[1].rotate(1);
portdevices[2].rotate(1);
portdevices[3].rotate(1);
portdevices[8].rotate(-1);
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);
public void Decorate()
{}
for (int a = 0; a < 16; a++) {
level.items.addElement(portdevices[a]);
}
}
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 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);
ports[2] = new Port(1, 24, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[3] = new Port(1, 32, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[4] = new Port(8, 38, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[5] = new Port(16, 38, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[6] = new Port(24, 38, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[7] = new Port(32, 38, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[8] = new Port(38, 31, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[9] = new Port(38, 23, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[10] = new Port(38, 15, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[11] = new Port(38, 7, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[12] = new Port(31, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[13] = new Port(23, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[14] = new Port(15, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[15] = new Port(7, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try {
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(3, 3, 34, 34);
g.fillRect(1, 7, 2, 2);
g.fillRect(1, 15, 2, 2);
g.fillRect(1, 23, 2, 2);
g.fillRect(1, 31, 2, 2);
g.fillRect(7, 37, 2, 2);
g.fillRect(15, 37, 2, 2);
g.fillRect(23, 37, 2, 2);
g.fillRect(31, 37, 2, 2);
g.fillRect(37, 31, 2, 2);
g.fillRect(37, 23, 2, 2);
g.fillRect(37, 15, 2, 2);
g.fillRect(37, 7, 2, 2);
g.fillRect(31, 1, 2, 2);
g.fillRect(23, 1, 2, 2);
g.fillRect(15, 1, 2, 2);
g.fillRect(7, 1, 2, 2);
g.setColor(Color.black);
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52 - X / 2, 32);
}
currentIcon = icons[0].getImage();
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
portdevices = new PortDevice[16];
for (int a=0; a<ports.length; a++)
{
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public void Decorate() {
}
public void IsDropped()
{
inBurner=false;
inTester=false;
int bigXl = (x)/28;
int bigXr = (x+width-1)/28;
int bigYt = (y)/32;
int bigYb = (y+height-1)/32;
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)
{
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
return;
}
}
}
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 boolean Function()
{
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
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)
{
changed=true;
inner.value = outer.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)
{
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)
outer.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)
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
inner.type = Port.TYPE_INPUT;
}
}
}
return changed;
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
portdevices = new PortDevice[16];
for (int a = 0; a < ports.length; a++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public void Erase()
{
super.Erase();
for (int a=0; a<portdevices.length; a++)
portdevices[a]=null;
}
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
int bigXr = (x + width - 1) / 28;
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
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) {
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room, level.DISCHARGESOUND);
return;
}
}
}
}
public boolean Function() {
// Transfer values between the ports and the portdevices.
boolean changed = false;
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) {
changed = true;
inner.value = outer.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) {
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) {
outer.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) {
inner.type = Port.TYPE_OUTPUT;
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void Erase() {
super.Erase();
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@@ -1,331 +1,314 @@
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 Prototype32Chip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 80;
height = 80;
public class Prototype32Chip extends GenericChip
{
transient PortDevice portdevices[];
GenerateIcons();
public Prototype32Chip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=80; height=80;
InternalRoom = new Room();
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},
{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},
{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},
{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},
{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},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
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;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
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 = {
{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},
{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},
{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},
{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},
{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},
{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;
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
portdevices = new PortDevice[32];
portdevices[0] = new PortDevice(16, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16, 3 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16, 5 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(16, 6 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(16, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(16, 8 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(16, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices = new PortDevice[32];
portdevices[0] = new PortDevice(16,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16,3*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16,5*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(16,6*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(16,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(16,8*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(16,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[8] = new PortDevice(3 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[9] = new PortDevice(5 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[10] = new PortDevice(7 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[11] = new PortDevice(9 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[12] = new PortDevice(11 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[13] = new PortDevice(13 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[14] = new PortDevice(15 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[15] = new PortDevice(17 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[8] = new PortDevice(3*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[9] = new PortDevice(5*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[10] = new PortDevice(7*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[11] = new PortDevice(9*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[12] = new PortDevice(11*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[13] = new PortDevice(13*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[14] = new PortDevice(15*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[15] = new PortDevice(17*28,320,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[16] = new PortDevice(500, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[17] = new PortDevice(500, 8 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[18] = new PortDevice(500, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[19] = new PortDevice(500, 6 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[20] = new PortDevice(500, 5 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[21] = new PortDevice(500, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[22] = new PortDevice(500, 3 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[23] = new PortDevice(500, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[16] = new PortDevice(500,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[17] = new PortDevice(500,8*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[18] = new PortDevice(500,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[19] = new PortDevice(500,6*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[20] = new PortDevice(500,5*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[21] = new PortDevice(500,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[22] = new PortDevice(500,3*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[23] = new PortDevice(500,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[24] = new PortDevice(17 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[25] = new PortDevice(15 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[26] = new PortDevice(13 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[27] = new PortDevice(11 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[28] = new PortDevice(9 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[29] = new PortDevice(7 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[30] = new PortDevice(5 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[31] = new PortDevice(3 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[24] = new PortDevice(17*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[25] = new PortDevice(15*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[26] = new PortDevice(13*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[27] = new PortDevice(11*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[28] = new PortDevice(9*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[29] = new PortDevice(7*28,12,InternalRoom,28,Port.TYPE_UNDEFINED);
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++) {
portdevices[a].rotate(1);
portdevices[a + 16].rotate(-1);
portdevices[a + 24].rotate(1);
portdevices[a + 24].rotate(1);
}
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++) {
level.items.addElement(portdevices[a]);
}
}
for (int a=0; a<32; a++)
level.items.addElement(portdevices[a]);
}
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);
ports[2] = new Port(1, 24, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[3] = new Port(1, 32, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[4] = new Port(1, 40, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[5] = new Port(1, 48, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[6] = new Port(1, 56, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[7] = new Port(1, 64, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
public void GenerateIcons()
{
// super.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);
ports[2] = new Port( 1,24,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[3] = new Port( 1,32,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[4] = new Port( 1,40,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[5] = new Port( 1,48,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[6] = new Port( 1,56,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[7] = new Port( 1,64,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this);
ports[8] = new Port(8, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[9] = new Port(16, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[10] = new Port(24, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[11] = new Port(32, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[12] = new Port(40, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[13] = new Port(48, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[14] = new Port(56, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[15] = new Port(64, 76, Port.TYPE_UNDEFINED, 0, Port.ROT_DOWN, this);
ports[8] = new Port( 8,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[9] = new Port(16,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[10] = new Port(24,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[11] = new Port(32,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[12] = new Port(40,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[13] = new Port(48,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[14] = new Port(56,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[15] = new Port(64,76,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN,this);
ports[16] = new Port(76,63,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[17] = new Port(76,55,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[18] = new Port(76,47,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[19] = new Port(76,39,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[20] = new Port(76,31,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[21] = new Port(76,23,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[22] = new Port(76,15,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[23] = new Port(76, 7,Port.TYPE_UNDEFINED,0,Port.ROT_RIGHT,this);
ports[24] = new Port(63, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[25] = new Port(55, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[26] = new Port(47, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[27] = new Port(39, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[28] = new Port(31, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[29] = new Port(23, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[30] = new Port(15, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
ports[31] = new Port( 7, 1,Port.TYPE_UNDEFINED,0,Port.ROT_UP,this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(3,3,72,72);
g.fillRect(1,7,2,2);
g.fillRect(1,15,2,2);
g.fillRect(1,23,2,2);
g.fillRect(1,31,2,2);
g.fillRect(1,39,2,2);
g.fillRect(1,47,2,2);
g.fillRect(1,55,2,2);
g.fillRect(1,63,2,2);
g.fillRect(7,75,2,2);
g.fillRect(15,75,2,2);
g.fillRect(23,75,2,2);
g.fillRect(31,75,2,2);
g.fillRect(39,75,2,2);
g.fillRect(47,75,2,2);
g.fillRect(55,75,2,2);
g.fillRect(63,75,2,2);
g.fillRect(75,63,2,2);
g.fillRect(75,55,2,2);
g.fillRect(75,47,2,2);
g.fillRect(75,39,2,2);
g.fillRect(75,31,2,2);
g.fillRect(75,23,2,2);
g.fillRect(75,15,2,2);
g.fillRect(75,7,2,2);
ports[16] = new Port(76, 63, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[17] = new Port(76, 55, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[18] = new Port(76, 47, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[19] = new Port(76, 39, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[20] = new Port(76, 31, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[21] = new Port(76, 23, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[22] = new Port(76, 15, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[23] = new Port(76, 7, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
g.fillRect(63,1,2,2);
g.fillRect(55,1,2,2);
g.fillRect(47,1,2,2);
g.fillRect(39,1,2,2);
g.fillRect(31,1,2,2);
g.fillRect(23,1,2,2);
g.fillRect(15,1,2,2);
g.fillRect(7,1,2,2);
ports[24] = new Port(63, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[25] = new Port(55, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[26] = new Port(47, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[27] = new Port(39, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[28] = new Port(31, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[29] = new Port(23, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[30] = new Port(15, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
ports[31] = new Port(7, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try {
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(3, 3, 72, 72);
g.setColor(Color.black);
if (label != null)
{
g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52-X/2, 32);
}
currentIcon = icons[0].getImage();
}
g.fillRect(1, 7, 2, 2);
g.fillRect(1, 15, 2, 2);
g.fillRect(1, 23, 2, 2);
g.fillRect(1, 31, 2, 2);
g.fillRect(1, 39, 2, 2);
g.fillRect(1, 47, 2, 2);
g.fillRect(1, 55, 2, 2);
g.fillRect(1, 63, 2, 2);
public void Decorate()
{}
g.fillRect(7, 75, 2, 2);
g.fillRect(15, 75, 2, 2);
g.fillRect(23, 75, 2, 2);
g.fillRect(31, 75, 2, 2);
g.fillRect(39, 75, 2, 2);
g.fillRect(47, 75, 2, 2);
g.fillRect(55, 75, 2, 2);
g.fillRect(63, 75, 2, 2);
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<32; a++)
s.writeInt(level.items.indexOf(portdevices[a]));
}
g.fillRect(75, 63, 2, 2);
g.fillRect(75, 55, 2, 2);
g.fillRect(75, 47, 2, 2);
g.fillRect(75, 39, 2, 2);
g.fillRect(75, 31, 2, 2);
g.fillRect(75, 23, 2, 2);
g.fillRect(75, 15, 2, 2);
g.fillRect(75, 7, 2, 2);
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
portdevices = new PortDevice[32];
for (int a=0; a<ports.length; a++)
{
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
g.fillRect(63, 1, 2, 2);
g.fillRect(55, 1, 2, 2);
g.fillRect(47, 1, 2, 2);
g.fillRect(39, 1, 2, 2);
g.fillRect(31, 1, 2, 2);
g.fillRect(23, 1, 2, 2);
g.fillRect(15, 1, 2, 2);
g.fillRect(7, 1, 2, 2);
public boolean Function()
{
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
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)
{
changed=true;
inner.value = outer.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)
{
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)
outer.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)
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
inner.type = Port.TYPE_INPUT;
}
}
}
return changed;
}
g.setColor(Color.black);
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52 - X / 2, 32);
}
currentIcon = icons[0].getImage();
}
public void IsDropped()
{
inBurner=false;
inTester=false;
int bigXl = (x)/28;
int bigXr = (x+width-1)/28;
int bigYt = (y)/32;
int bigYb = (y+height-1)/32;
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)
{
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
return;
}
}
}
public void Decorate() {
}
public void Erase()
{
super.Erase();
for (int a=0; a<portdevices.length; a++)
portdevices[a]=null;
}
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++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public boolean Function() {
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
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) {
changed = true;
inner.value = outer.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) {
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) {
outer.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) {
inner.type = Port.TYPE_OUTPUT;
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
int bigXr = (x + width - 1) / 28;
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
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) {
SetRoom(null);
level.items.removeElement(this);
level.PlaySound(room, Level.DISCHARGESOUND);
return;
}
}
}
}
public void Erase() {
super.Erase();
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@@ -1,292 +1,273 @@
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;
public class PrototypeChip extends GenericChip {
public transient PortDevice portdevices[];
import com.droidquest.Room;
import com.droidquest.chipstuff.Port;
import com.droidquest.items.Item;
import com.droidquest.materials.Material;
public PrototypeChip(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 104;
height = 64;
public class PrototypeChip extends GenericChip
{
public transient PortDevice portdevices[];
GenerateIcons();
public PrototypeChip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=104; height=64;
InternalRoom = new Room();
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},
{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},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{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},
{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},
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}
};
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;
}
}
}
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
InternalRoom.upRoom = null;
InternalRoom.downRoom = null;
InternalRoom.leftRoom = null;
InternalRoom.rightRoom = null;
leftPortal = new Rectangle(8, 12, 8, 10);
rightPortal = new Rectangle(64, 12, 8, 10);
upPortal = new Rectangle(36, -6, 8, 10);
downPortal = new Rectangle(36, 38, 8, 10);
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 = {
{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},
{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},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{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},
{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},
{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;
InternalRoom.GenerateArray();
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
InternalRoom.upRoom = null;
InternalRoom.downRoom = null;
InternalRoom.leftRoom = null;
InternalRoom.rightRoom = null;
leftPortal = new Rectangle (8,12,8,10);
rightPortal = new Rectangle (64,12,8,10);
upPortal = new Rectangle (36,-6,8,10);
downPortal = new Rectangle (36,38,8,10);
portdevices = new PortDevice[8];
portdevices[0] = new PortDevice(16, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(500, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(500, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(500, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(500, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[0].rotate(1);
portdevices[1].rotate(1);
portdevices[2].rotate(1);
portdevices[3].rotate(1);
portdevices[4].rotate(-1);
portdevices[5].rotate(-1);
portdevices[6].rotate(-1);
portdevices[7].rotate(-1);
portdevices = new PortDevice[8];
portdevices[0] = new PortDevice(16,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[1] = new PortDevice(16,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[3] = new PortDevice(16,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(500,9*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[5] = new PortDevice(500,7*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(500,4*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[7] = new PortDevice(500,2*32,InternalRoom,28,Port.TYPE_UNDEFINED);
portdevices[0].rotate(1);
portdevices[1].rotate(1);
portdevices[2].rotate(1);
portdevices[3].rotate(1);
portdevices[4].rotate(-1);
portdevices[5].rotate(-1);
portdevices[6].rotate(-1);
portdevices[7].rotate(-1);
for (int a = 0; a < 8; a++) {
level.items.addElement(portdevices[a]);
}
}
for (int a=0; a<8; a++)
level.items.addElement(portdevices[a]);
}
public void GenerateIcons()
{
public void GenerateIcons() {
// super.GenerateIcons();
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);
ports[2] = new Port(4,41,Port.TYPE_UNDEFINED,24,Port.ROT_LEFT,this);
ports[3] = new Port(12,57,Port.TYPE_UNDEFINED,16,Port.ROT_LEFT,this);
ports[4] = new Port(91,54,Port.TYPE_UNDEFINED,16,Port.ROT_RIGHT,this);
ports[5] = new Port(99,38,Port.TYPE_UNDEFINED,24,Port.ROT_RIGHT,this);
ports[6] = new Port(99,22,Port.TYPE_UNDEFINED,24,Port.ROT_RIGHT,this);
ports[7] = new Port(91,6,Port.TYPE_UNDEFINED,16,Port.ROT_RIGHT,this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(24,0,56,64);
g.setColor(Color.black);
g.fillRect(26,6,4,4);
if (label != null)
{
g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52-X/2, 32);
}
currentIcon = icons[0].getImage();
}
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);
ports[2] = new Port(4, 41, Port.TYPE_UNDEFINED, 24, Port.ROT_LEFT, this);
ports[3] = new Port(12, 57, Port.TYPE_UNDEFINED, 16, Port.ROT_LEFT, this);
ports[4] = new Port(91, 54, Port.TYPE_UNDEFINED, 16, Port.ROT_RIGHT, this);
ports[5] = new Port(99, 38, Port.TYPE_UNDEFINED, 24, Port.ROT_RIGHT, this);
ports[6] = new Port(99, 22, Port.TYPE_UNDEFINED, 24, Port.ROT_RIGHT, this);
ports[7] = new Port(91, 6, Port.TYPE_UNDEFINED, 16, Port.ROT_RIGHT, this);
}
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try {
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(24, 0, 56, 64);
g.setColor(Color.black);
g.fillRect(26, 6, 4, 4);
if (label != null) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52 - X / 2, 32);
}
currentIcon = icons[0].getImage();
}
public void Animate()
{
try
{
g = currentIcon.getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(24,0,56,64);
g.setColor(Color.black);
g.fillRect(26,6,4,4);
if (label != null)
{
g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52-X/2, 32);
}
}
public void Animate() {
try {
g = currentIcon.getGraphics();
}
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 (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) {
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label);
g.drawString(label, 52 - X / 2, 32);
}
}
public void Decorate()
{}
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 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++)
{
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
portdevices = new PortDevice[8];
for (int a = 0; a < ports.length; a++) {
Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item;
}
GenerateIcons();
}
public boolean Function()
{
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
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)
{
changed=true;
inner.value = outer.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)
{
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)
outer.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)
inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT)
inner.type = Port.TYPE_INPUT;
}
}
}
return changed;
}
public boolean Function() {
// Transfer values bewteen the ports and the portdevices.
boolean changed = false;
for (int a = 0; a < 8; a++) {
Port outer = ports[a];
Port inner = portdevices[a].ports[0];
public void IsDropped()
{
inBurner=false;
inTester=false;
int bigXl = (x)/28;
int bigXr = (x+width-1)/28;
int bigYt = (y)/32;
int bigYb = (y+height-1)/32;
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;
x = 3*28+4;
y = 5*32+12;
inBurner=true;
}
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTrash"))
{
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
}
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;
}
}
}
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) {
changed = true;
outer.value = inner.value;
}
}
public void Erase()
{
super.Erase();
for (int a=0; a<portdevices.length; a++)
portdevices[a]=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) {
outer.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) {
inner.type = Port.TYPE_OUTPUT;
}
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT;
}
}
}
}
return changed;
}
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
int bigXr = (x + width - 1) / 28;
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
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;
x = 3 * 28 + 4;
y = 5 * 32 + 12;
inBurner = true;
}
if (level.materials.elementAt(room.RoomArray[a][b]).getClass().toString().endsWith("ChipTrash")) {
level.items.removeElement(this);
level.PlaySound(room, Level.DISCHARGESOUND);
}
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() {
super.Erase();
for (int a = 0; a < portdevices.length; a++) {
portdevices[a] = null;
}
}
}

View File

@@ -10,167 +10,155 @@ 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;
target = item;
editable=true;
targetClass = target.getClass().toString().substring(6); // Removes "class "
rotation = 1; // Right
d1.width = 32 + target.getWidth();
d1.height = Math.max(target.getHeight()+8,18);
d2.width = Math.max(target.getWidth()+8,18);
d2.height = 32 + target.getHeight();
width = d1.width;
height = d1.height;
ports = new Port[1];
ports[0] = new Port(width-2,height/2,Port.TYPE_OUTPUT,24,Port.ROT_UP,this);
icons = new ImageIcon[2];
GenerateIcons();
}
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 "
rotation = 1; // Right
d1.width = 32 + target.getWidth();
d1.height = Math.max(target.getHeight() + 8, 18);
d2.width = Math.max(target.getWidth() + 8, 18);
d2.height = 32 + target.getHeight();
width = d1.width;
height = d1.height;
ports = new Port[1];
ports[0] = new Port(width - 2, height / 2, Port.TYPE_OUTPUT, 24, Port.ROT_UP, this);
icons = new ImageIcon[2];
GenerateIcons();
}
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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));
target.GenerateIcons();
currentIcon = icons[rotation%2].getImage();
}
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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));
target.GenerateIcons();
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function()
{
ports[0].value=false;
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))
{
ports[0].value=true;
a=level.items.size();
}
}
}
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))
{
ports[0].value=true;
a=level.items.size();
}
}
}
return false;
}
public boolean Function() {
ports[0].value = false;
if (room.portalItem == null) {
// Room Sensor is not inside robot.
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 {
// Room Sensor is inside Robot.
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()
{
super.Decorate();
g.setColor(Color.white);
switch (rotation)
{
case Port.ROT_UP:
g.drawRect(0,24,width,height-24);
g.drawRect(1,25,width-2,height-26);
g.drawImage(target.currentIcon, width/2-target.getWidth()/2, 28, level);
break;
case Port.ROT_RIGHT:
g.drawRect(0,0,width-24,height);
g.drawRect(1,1,width-26,height-2);
g.drawImage(target.currentIcon, 4, 4, level);
break;
case Port.ROT_DOWN:
g.drawRect(0,0,width,height-24);
g.drawRect(1,1,width-2,height-26);
g.drawImage(target.currentIcon, 4, 4, level);
break;
case Port.ROT_LEFT:
g.drawRect(24,0,width-24,height);
g.drawRect(25,1,width-26,height-2);
g.drawImage(target.currentIcon, 28, height/2-target.getHeight()/2, level);
break;
}
}
public void Decorate() {
super.Decorate();
g.setColor(Color.white);
switch (rotation) {
case Port.ROT_UP:
g.drawRect(0, 24, width, height - 24);
g.drawRect(1, 25, width - 2, height - 26);
g.drawImage(target.currentIcon, width / 2 - target.getWidth() / 2, 28, level);
break;
case Port.ROT_RIGHT:
g.drawRect(0, 0, width - 24, height);
g.drawRect(1, 1, width - 26, height - 2);
g.drawImage(target.currentIcon, 4, 4, level);
break;
case Port.ROT_DOWN:
g.drawRect(0, 0, width, height - 24);
g.drawRect(1, 1, width - 2, height - 26);
g.drawImage(target.currentIcon, 4, 4, level);
break;
case Port.ROT_LEFT:
g.drawRect(24, 0, width - 24, height);
g.drawRect(25, 1, width - 26, height - 2);
g.drawImage(target.currentIcon, 28, height / 2 - target.getHeight() / 2, level);
break;
}
}
public void rotate(int dir)
{
if (rotation ==0 && dir == -1)
rotation = 3;
else if (rotation == 3 && dir == 1)
rotation =0;
else
rotation += dir;
if (rotation%2==0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else
{
width = d1.width;
height = d1.height;
}
switch(rotation)
{
case Port.ROT_UP:
ports[0].x = width/2-2;
ports[0].y = 0;
break;
case Port.ROT_RIGHT:
ports[0].x = width-2;
ports[0].y = height/2-2;
break;
case Port.ROT_DOWN:
ports[0].x = width/2+1;
ports[0].y = height;
break;
case Port.ROT_LEFT:
ports[0].x = 0;
ports[0].y = height/2+1;
break;
}
}
public void rotate(int dir) {
if (rotation == 0 && dir == -1) {
rotation = 3;
}
else if (rotation == 3 && dir == 1) {
rotation = 0;
}
else {
rotation += dir;
}
public void Erase()
{
super.Erase();
target = null;
}
if (rotation % 2 == 0) // if rotation == Up or Down
{
width = d2.width;
height = d2.height;
}
else {
width = d1.width;
height = d1.height;
}
switch (rotation) {
case Port.ROT_UP:
ports[0].x = width / 2 - 2;
ports[0].y = 0;
break;
case Port.ROT_RIGHT:
ports[0].x = width - 2;
ports[0].y = height / 2 - 2;
break;
case Port.ROT_DOWN:
ports[0].x = width / 2 + 1;
ports[0].y = height;
break;
case Port.ROT_LEFT:
ports[0].x = 0;
ports[0].y = height / 2 + 1;
break;
}
}
public void Erase() {
super.Erase();
target = null;
}
}

View File

@@ -1,420 +1,370 @@
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
{
public int speed;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Vector;
public transient PortSignal[] portSignals = new PortSignal[8];
public Vector signals = new Vector();
public Vector gates = new Vector();
public class SmallChip extends GenericChip {
public int speed;
public SmallChip(int X, int Y, Room r, String l)
{
x=X; y=Y; room=r;
label = l;
width=26; height=30;
speed=1;
GenerateIcons();
for (int a=0; a<8; a++)
portSignals[a] = new PortSignal();
}
public transient PortSignal[] portSignals = new PortSignal[8];
public Vector<Signal> signals = new Vector<Signal>();
public Vector<Gate> gates = new Vector<Gate>();
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);
ports[2] = new Port(0,19,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[3] = new Port(0,27,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[4] = new Port(25,26,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[5] = new Port(25,18,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[6] = new Port(25,10,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[7] = new Port(25,2,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
}
ChipText chiptext = new ChipText(this);
chiptext.setTitle("Pinout for Chip " + label);
if (portSignals == null)
{
portSignals = new PortSignal[8];
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
{
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(4,0,18,30);
g.fillRect(0,2,26,2);
g.fillRect(0,10,26,2);
g.fillRect(0,18,26,2);
g.fillRect(0,26,26,2);
g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
label = String.valueOf(label.charAt(0));
int X = fm.stringWidth(label);
g.drawString(label, 13-X/2, 22);
currentIcon = icons[0].getImage();
}
public SmallChip(int X, int Y, Room r, String l) {
x = X;
y = Y;
room = r;
label = l;
width = 26;
height = 30;
speed = 1;
GenerateIcons();
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
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++)
{
s.writeInt(signals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
gate.writeRef(s);
}
}
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);
ports[2] = new Port(0, 19, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[3] = new Port(0, 27, Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this);
ports[4] = new Port(25, 26, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[5] = new Port(25, 18, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[6] = new Port(25, 10, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
ports[7] = new Port(25, 2, Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this);
}
ChipText chiptext = new ChipText(this);
chiptext.setTitle("Pinout for Chip " + label);
if (portSignals == null) {
portSignals = new PortSignal[8];
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 {
g = icons[0].getImage().getGraphics();
}
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);
g.setColor(Color.blue);
g.fillRect(4, 0, 18, 30);
g.fillRect(0, 2, 26, 2);
g.fillRect(0, 10, 26, 2);
g.fillRect(0, 18, 26, 2);
g.fillRect(0, 26, 26, 2);
g.setColor(Color.black);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
label = String.valueOf(label.charAt(0));
int X = fm.stringWidth(label);
g.drawString(label, 13 - X / 2, 22);
currentIcon = icons[0].getImage();
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
GenerateIcons();
for (int a=0; a<8; a++)
{
int portIndex = s.readInt();
if (portIndex>=0)
portSignals[a].internalSignal = (Signal) signals.elementAt(portIndex);
portSignals[a].type = s.readInt();
}
for (int a=0; a<gates.size(); a++)
{
Gate gate = (Gate) gates.elementAt(a);
gate.portSignals = new PortSignal[8];
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);
gate.portSignals[b].type = s.readInt();
}
gate.readRef(s);
}
}
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
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 = gates.elementAt(a);
for (int b = 0; b < 8; b++) {
s.writeInt(signals.indexOf(gate.portSignals[b].externalSignal));
s.writeInt(gate.portSignals[b].type);
}
gate.writeRef(s);
}
}
public void Decorate()
{}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
GenerateIcons();
for (int a = 0; a < 8; a++) {
int portIndex = s.readInt();
if (portIndex >= 0) {
portSignals[a].internalSignal = signals.elementAt(portIndex);
}
portSignals[a].type = s.readInt();
}
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++) {
gate.portSignals[b] = new PortSignal();
int sigIndex = s.readInt();
if (sigIndex >= 0) {
gate.portSignals[b].externalSignal = signals.elementAt(sigIndex);
}
gate.portSignals[b].type = s.readInt();
}
gate.readRef(s);
}
}
public void IsDropped()
{
inBurner = false;
inTester = false;
int bigXl = (x)/28;
int bigXr = (x+width-1)/28;
int bigYt = (y)/32;
int bigYb = (y+height-1)/32;
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;
x = 13*28 - width/2;
y = 8*32 - height/2;
inBurner=true;
ChipCompiler.chipSpeed = speed;
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
tb.textString= speed + "x";
return;
}
if (room.MaterialArray[a][b] instanceof ChipTrash)
{
SetRoom(null); // Cheap way to remove the wires;
level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND);
return;
}
if (room.MaterialArray[a][b] instanceof ChipTester)
{
a=bigYb; b=bigXr;
x = 10*28-width/2;
y = 5*32-height/2;
inTester=true;
return;
}
}
}
public void Decorate() {
}
public boolean Function()
{
int a;
for (int s=0; s<speed; s++)
{
for (a=0; a<signals.size(); a++)
((Signal) signals.elementAt(a)).Flip();
public void IsDropped() {
inBurner = false;
inTester = false;
int bigXl = (x) / 28;
int bigXr = (x + width - 1) / 28;
int bigYt = (y) / 32;
int bigYb = (y + height - 1) / 32;
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();
if (bigXr > 19) {
bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
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;
}
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 = room.textBoxes.elementAt(1);
tb.textString = speed + "x";
return;
}
if (room.MaterialArray[a][b] instanceof ChipTrash) {
SetRoom(null); // Cheap way to remove the wires;
level.items.removeElement(this);
level.PlaySound(room, Level.DISCHARGESOUND);
return;
}
if (room.MaterialArray[a][b] instanceof ChipTester) {
x = 10 * 28 - width / 2;
y = 5 * 32 - height / 2;
inTester = true;
return;
}
}
}
}
public void Erase()
{
super.Erase();
portSignals = null;
signals = null;
gates = null;
}
public boolean Function() {
int a;
public void Empty()
{
if (signals != null)
signals.removeAllElements();
signals = new Vector();
if (gates != null)
gates.removeAllElements();
gates = new Vector();
if (portSignals == null)
{
portSignals = new PortSignal[8];
for (int a=0; a<8; a++)
portSignals[a] = new PortSignal();
}
for (int a=0; a<8; a++)
{
portSignals[a].externalSignal = null;
portSignals[a].internalSignal = null;
portSignals[a].type = Port.TYPE_UNDEFINED;
}
}
for (int s = 0; s < speed; s++) {
for (a = 0; a < signals.size(); a++) {
signals.elementAt(a).Flip();
}
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++)
{
Signal sig = new Signal();
sig.Set(s.readBoolean());
sig.working = s.readBoolean();
signals.addElement(sig);
}
// Gates
int numGates = s.readInt();
gates = new Vector();
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++)
{
int sigIndex = s.readInt();
if (sigIndex>=0)
gate.portSignals[b].externalSignal = (Signal) signals.elementAt(sigIndex);
gate.portSignals[b].type = s.readInt();
}
if (gate.type.equalsIgnoreCase("Chip"))
gate.LoadSubGate(s);
}
// PortSignals
for (int a=0; a<8; a++)
{
int sigIndex = s.readInt();
if (sigIndex>=0)
portSignals[a].internalSignal = (Signal) signals.elementAt(sigIndex);
ports[a].type = s.readInt();
portSignals[a].type = ports[a].type;
}
// Description
description = (String) s.readObject();
// Speed
speed = s.readInt();
s.close();
in.close();
}
catch (ClassNotFoundException e) {}
catch (FileNotFoundException e)
{
System.out.println("File Not Found");
return;
}
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)
{
Wire wire = ports[a].myWire;
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)
wire.Remove();
}
}
}
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);
}
}
}
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);
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);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
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"))
gate.SaveSubGate(s);
}
// PortSignals
for (int a=0; a<8; a++)
{
s.writeInt(signals.indexOf(portSignals[a].internalSignal));
s.writeInt(ports[a].type);
}
// Description
s.writeObject(description);
// Speed
s.writeInt(speed);
s.flush();
s.close();
out.close();
}
catch (FileNotFoundException e)
{
System.out.println("File Not Found");
}
catch (IOException e)
{
System.out.println("IO Exception");
System.out.println(e.getMessage());
}
}
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) {
ports[a].value = portSignals[a].internalSignal.Get();
}
}
}
}
return false;
}
public void Erase() {
super.Erase();
portSignals = null;
signals = null;
gates = null;
}
public void Empty() {
if (signals != null) {
signals.removeAllElements();
}
signals = new Vector<Signal>();
if (gates != null) {
gates.removeAllElements();
}
gates = new Vector<Gate>();
if (portSignals == null) {
portSignals = new PortSignal[8];
for (int a = 0; a < 8; a++) {
portSignals[a] = new PortSignal();
}
}
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 {
FileInputStream in = new FileInputStream(filename);
ObjectInputStream s = new ObjectInputStream(in);
// Signals
int numSignals = s.readInt();
signals = new Vector<Signal>();
for (int a = 0; a < numSignals; a++) {
Signal sig = new Signal();
sig.Set(s.readBoolean());
sig.working = s.readBoolean();
signals.addElement(sig);
}
// Gates
int numGates = s.readInt();
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++) {
int sigIndex = s.readInt();
if (sigIndex >= 0) {
gate.portSignals[b].externalSignal = signals.elementAt(sigIndex);
}
gate.portSignals[b].type = s.readInt();
}
if (gate.type.equalsIgnoreCase("Chip")) {
gate.LoadSubGate(s);
}
}
// PortSignals
for (int a = 0; a < 8; a++) {
int sigIndex = s.readInt();
if (sigIndex >= 0) {
portSignals[a].internalSignal = signals.elementAt(sigIndex);
}
ports[a].type = s.readInt();
portSignals[a].type = ports[a].type;
}
// Description
description = (String) s.readObject();
// Speed
speed = s.readInt();
s.close();
in.close();
}
catch (ClassNotFoundException e) {
}
catch (FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
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) {
wire.Remove();
}
}
else if (wire.toPort == ports[a]) {
if (wire.fromPort.type == ports[a].type) {
wire.Remove();
}
}
}
}
}
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 = 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 = gates.elementAt(a);
s.writeObject(gate.type);
s.writeBoolean(gate.state);
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")) {
gate.SaveSubGate(s);
}
}
// PortSignals
for (int a = 0; a < 8; a++) {
s.writeInt(signals.indexOf(portSignals[a].internalSignal));
s.writeInt(ports[a].type);
}
// Description
s.writeObject(description);
// Speed
s.writeInt(speed);
s.flush();
s.close();
out.close();
}
catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
catch (IOException e) {
System.out.println("IO Exception");
System.out.println(e.getMessage());
}
}
}

View File

@@ -1,93 +1,84 @@
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;
GenerateIcons();
}
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public void GenerateIcons()
{
super.GenerateIcons();
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(16,0,4,2);
g.fillRect(4,2,4,2);
g.fillRect(12,4,4,2);
g.fillRect(20,4,4,2);
g.fillRect(4,8,4,2);
g.fillRect(12,8,4,2);
g.fillRect(24,8,4,2);
g.fillRect(0,10,4,2);
g.fillRect(8,10,4,2);
g.fillRect(16,10,4,2);
g.fillRect(24,12,4,2);
g.fillRect(8,14,4,2);
g.fillRect(16,14,4,2);
g.fillRect(0,18,4,2);
g.fillRect(12,18,4,2);
g.fillRect(24,18,4,2);
g.fillRect(16,20,4,2);
g.fillRect(4,22,4,2);
g.fillRect(20,22,4,2);
g.fillRect(8,24,4,2);
g.fillRect(16,24,4,2);
currentIcon = icons[0].getImage();
}
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 Decorate()
{
try
{
g = currentIcon.getGraphics();
}
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);
}
public void GenerateIcons() {
super.GenerateIcons();
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(16, 0, 4, 2);
g.fillRect(4, 2, 4, 2);
g.fillRect(12, 4, 4, 2);
g.fillRect(20, 4, 4, 2);
g.fillRect(4, 8, 4, 2);
g.fillRect(12, 8, 4, 2);
g.fillRect(24, 8, 4, 2);
g.fillRect(0, 10, 4, 2);
g.fillRect(8, 10, 4, 2);
g.fillRect(16, 10, 4, 2);
g.fillRect(24, 12, 4, 2);
g.fillRect(8, 14, 4, 2);
g.fillRect(16, 14, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(24, 18, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(4, 22, 4, 2);
g.fillRect(20, 22, 4, 2);
g.fillRect(8, 24, 4, 2);
g.fillRect(16, 24, 4, 2);
currentIcon = icons[0].getImage();
}
public void rotate(int dir)
{
// Does not Rotate!
}
public void Decorate() {
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to Device Image");
return;
}
for (Port port : ports) {
port.Draw(g, rotation);
}
}
public void rotate(int dir) {
// Does not Rotate!
}
}

View File

@@ -1,219 +1,211 @@
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;
room = r;
if (room.portalItem!=null)
if (room.portalItem.getClass().toString().endsWith("Robot"))
robot = (GenericRobot) room.portalItem;
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public class Thruster extends Device {
private int rotation;
private Color color;
private transient GenericRobot robot;
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
s.writeInt(level.items.indexOf(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")) {
robot = (GenericRobot) room.portalItem;
}
}
rotation = direction;
color = col;
grabbable = false;
GenerateIcons();
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.items.indexOf(robot));
}
public void GenerateIcons()
{
robot = (GenericRobot) room.portalItem;
if (ports==null)
{
ports = new Port[1];
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;
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
robot = (GenericRobot) level.FindItem(s.readInt());
}
case Port.ROT_RIGHT: // Thrusts Right, moves Left
ports[0] = new Port(4,11,Port.TYPE_INPUT,28,Port.ROT_LEFT,this);
break;
public void GenerateIcons() {
robot = (GenericRobot) room.portalItem;
if (ports == null) {
ports = new Port[1];
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;
case Port.ROT_DOWN: // Thrusts Down, moves Up
ports[0] = new Port(13,2,Port.TYPE_INPUT,12,Port.ROT_UP,this);
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
ports[0] = new Port(4, 11, Port.TYPE_INPUT, 28, Port.ROT_LEFT, this);
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
ports[0] = new Port(47,8,Port.TYPE_INPUT,26,Port.ROT_RIGHT,this);
break;
}
}
else
for (int a=0; a<ports.length; a++)
ports[a].myDevice = this;
case Port.ROT_DOWN: // Thrusts Down, moves Up
ports[0] = new Port(13, 2, Port.TYPE_INPUT, 12, Port.ROT_UP, this);
break;
icons = new ImageIcon[1];
switch(rotation)
{
case Port.ROT_UP: // Thrusts Up, moves Down
width=30; height=38;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
ports[0] = new Port(47, 8, Port.TYPE_INPUT, 26, Port.ROT_RIGHT, this);
break;
}
}
else {
for (Port port : ports) {
port.myDevice = this;
}
}
case Port.ROT_RIGHT: // Thrusts Right, moves Left
width=54; height=20;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
icons = new ImageIcon[1];
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
width = 30;
height = 38;
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;
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;
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;
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
case Port.ROT_DOWN: // Thrusts Down, moves Up
width = 30;
height = 32;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
public void Decorate()
{
super.Decorate();
currentIcon = icons[0].getImage();
try
{
g = currentIcon.getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch(rotation)
{
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(0,0,30,6);
g.fillRect(4,6,22,4);
g.fillRect(8,10,14,4);
g.fillRect(12,14,6,2);
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
width = 52;
height = 20;
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
break;
}
currentIcon = icons[0].getImage();
}
case Port.ROT_RIGHT: // Thrusts Right, moves Left
g.fillRect(44,0,10,20);
g.fillRect(40,2,4,16);
g.fillRect(36,4,4,12);
g.fillRect(32,6,4,8);
break;
public void Decorate() {
super.Decorate();
currentIcon = icons[0].getImage();
try {
g = currentIcon.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
g.fillRect(0, 0, 30, 6);
g.fillRect(4, 6, 22, 4);
g.fillRect(8, 10, 14, 4);
g.fillRect(12, 14, 6, 2);
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
g.fillRect(0,26,30,6);
g.fillRect(4,22,22,4);
g.fillRect(8,18,14,4);
g.fillRect(12,16,6,2);
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
g.fillRect(44, 0, 10, 20);
g.fillRect(40, 2, 4, 16);
g.fillRect(36, 4, 4, 12);
g.fillRect(32, 6, 4, 8);
break;
case Port.ROT_LEFT: // Thrusts Left, moves Right
g.fillRect(0,0,10,20);
g.fillRect(10,2,4,16);
g.fillRect(14,4,4,12);
g.fillRect(18,6,4,8);
break;
}
}
case Port.ROT_DOWN: // Thrusts Down, moves Up
g.fillRect(0, 26, 30, 6);
g.fillRect(4, 22, 22, 4);
g.fillRect(8, 18, 14, 4);
g.fillRect(12, 16, 6, 2);
break;
public boolean Function()
{
boolean thrust = ports[0].value;
case Port.ROT_LEFT: // Thrusts Left, moves Right
g.fillRect(0, 0, 10, 20);
g.fillRect(10, 2, 4, 16);
g.fillRect(14, 4, 4, 12);
g.fillRect(18, 6, 4, 8);
break;
}
}
if (robot==null && thrust)
{
Dimension d = GetXY();
switch (rotation)
{
case Port.ROT_UP:
level.sparks.addElement(new Spark(d.width+level.random.nextInt(30),
d.height+0,
0, -4, room));
level.sparks.addElement(new Spark(d.width+level.random.nextInt(30),
d.height+0,
0, -4, room));
break;
case Port.ROT_RIGHT:
level.sparks.addElement(new Spark(d.width+54,
d.height+level.random.nextInt(20),
4, 0, room));
level.sparks.addElement(new Spark(d.width+54,
d.height+level.random.nextInt(20),
4, 0, room));
break;
case Port.ROT_DOWN:
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 26,
0, 4, room));
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 26,
0, 4, room));
break;
case Port.ROT_LEFT:
level.sparks.addElement(new Spark(d.width + 44,
d.height + level.random.nextInt(20),
-4, 0, room));
level.sparks.addElement(new Spark(d.width + 44,
d.height + level.random.nextInt(20),
-4, 0, room));
break;
}
}
public boolean Function() {
boolean thrust = ports[0].value;
if (robot==null) return false;
if (robot == null && thrust) {
Dimension d = GetXY();
switch (rotation) {
case Port.ROT_UP:
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 0,
0, -4, room));
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 0,
0, -4, room));
break;
case Port.ROT_RIGHT:
level.sparks.addElement(new Spark(d.width + 54,
d.height + level.random.nextInt(20),
4, 0, room));
level.sparks.addElement(new Spark(d.width + 54,
d.height + level.random.nextInt(20),
4, 0, room));
break;
case Port.ROT_DOWN:
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 26,
0, 4, room));
level.sparks.addElement(new Spark(d.width + level.random.nextInt(30),
d.height + 26,
0, 4, room));
break;
case Port.ROT_LEFT:
level.sparks.addElement(new Spark(d.width + 44,
d.height + level.random.nextInt(20),
-4, 0, room));
level.sparks.addElement(new Spark(d.width + 44,
d.height + level.random.nextInt(20),
-4, 0, room));
break;
}
}
switch (rotation)
{
case Port.ROT_UP: // Thrusts Up, moves Down
robot.topThruster = thrust;
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
robot.rightThruster = thrust;
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
robot.bottomThruster = thrust;
break;
case Port.ROT_LEFT: // Thrusts Left, Moves Right
robot.leftThruster = thrust;
break;
}
return false;
}
if (robot == null) {
return false;
}
public void Erase()
{
super.Erase();
robot = null;
}
switch (rotation) {
case Port.ROT_UP: // Thrusts Up, moves Down
robot.topThruster = thrust;
break;
case Port.ROT_RIGHT: // Thrusts Right, moves Left
robot.rightThruster = thrust;
break;
case Port.ROT_DOWN: // Thrusts Down, moves Up
robot.bottomThruster = thrust;
break;
case Port.ROT_LEFT: // Thrusts Left, Moves Right
robot.leftThruster = thrust;
break;
}
return false;
}
public void Erase() {
super.Erase();
robot = null;
}
}

View File

@@ -1,184 +1,192 @@
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;
GenerateIcons();
currentIcon = icons[rotation%2].getImage();
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to XORGate Image");
return;
}
}
public class XORGate extends Device {
private transient ImageIcon[] images;
public void Decorate()
{
super.Decorate();
if (ports[0].value ^ ports[1].value)
g.drawImage(images[4+rotation].getImage(), 0, 0, level);
else
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to XORGate Image");
}
public void GenerateIcons()
{
super.GenerateIcons();
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)
{
int rot = rotation;
if (rotation%2==1)
{
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v*4;
if (r%2==0)
images[a] = new ImageIcon( new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR));
else
images[a] = new ImageIcon( new BufferedImage(h,w,BufferedImage.TYPE_4BYTE_ABGR));
try
{
g = images[a].getImage().getGraphics();
}
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);
if (v==0)
g.setColor(Color.white);
else
g.setColor(new Color(255,128,0));
switch(r)
{
case 0: // Up
g.fillRect(8,18,12,2);
g.fillRect(8,18,4,4);
g.fillRect(16,18,4,4);
g.fillRect(4,20,4,6);
g.fillRect(20,20,4,6);
g.fillRect(0,24,4,10);
g.fillRect(24,24,4,10);
g.fillRect(4,30,4,2);
g.fillRect(20,30,4,2);
g.fillRect(8,32,12,2);
g.fillRect(8,28,12,2);
break;
case 1: // Right
g.fillRect(16,0,10,4);
g.fillRect(16,24,10,4);
g.fillRect(24,4,6,4);
g.fillRect(24,20,6,4);
g.fillRect(28,8,4,4);
g.fillRect(28,16,4,4);
g.fillRect(30,12,2,4);
g.fillRect(18,4,2,4);
g.fillRect(18,20,2,4);
g.fillRect(16,8,2,12);
g.fillRect(20,8,2,12);
break;
case 2: // Down
g.fillRect(0,16,4,10);
g.fillRect(24,16,4,10);
g.fillRect(4,24,4,6);
g.fillRect(20,24,4,6);
g.fillRect(8,28,4,4);
g.fillRect(16,28,4,4);
g.fillRect(12,30,4,2);
g.fillRect(4,18,4,2);
g.fillRect(20,18,4,2);
g.fillRect(8,16,12,2);
g.fillRect(8,20,12,2);
break;
case 3: // Left
g.fillRect(24,0,10,4);
g.fillRect(24,24,10,4);
g.fillRect(20,4,6,4);
g.fillRect(20,20,6,4);
g.fillRect(18,8,4,4);
g.fillRect(18,16,4,4);
g.fillRect(18,12,2,4);
g.fillRect(30,4,2,4);
g.fillRect(30,20,2,4);
g.fillRect(28,8,2,12);
g.fillRect(32,8,2,12);
break;
};
}
currentIcon = icons[rotation%2].getImage();
}
}
public boolean Function()
{
ports[2].value = ports[0].value ^ ports[1].value;
return false;
}
public void Decorate() {
super.Decorate();
if (ports[0].value ^ ports[1].value) {
g.drawImage(images[4 + rotation].getImage(), 0, 0, level);
}
else {
g.drawImage(images[rotation].getImage(), 0, 0, level);
}
}
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 (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;
}
public void GenerateIcons() {
super.GenerateIcons();
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) {
int rot = rotation;
if (rotation % 2 == 1) {
int temp = width;
width = height;
height = temp;
}
rotation = 0;
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 a = r + v * 4;
if (r % 2 == 0) {
images[a] = new ImageIcon(new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR));
}
else {
images[a] = new ImageIcon(new BufferedImage(h, w, BufferedImage.TYPE_4BYTE_ABGR));
}
try {
g = images[a].getImage().getGraphics();
}
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);
if (v == 0) {
g.setColor(Color.white);
}
else {
g.setColor(new Color(255, 128, 0));
}
switch (r) {
case 0: // Up
g.fillRect(8, 18, 12, 2);
g.fillRect(8, 18, 4, 4);
g.fillRect(16, 18, 4, 4);
g.fillRect(4, 20, 4, 6);
g.fillRect(20, 20, 4, 6);
g.fillRect(0, 24, 4, 10);
g.fillRect(24, 24, 4, 10);
g.fillRect(4, 30, 4, 2);
g.fillRect(20, 30, 4, 2);
g.fillRect(8, 32, 12, 2);
g.fillRect(8, 28, 12, 2);
break;
case 1: // Right
g.fillRect(16, 0, 10, 4);
g.fillRect(16, 24, 10, 4);
g.fillRect(24, 4, 6, 4);
g.fillRect(24, 20, 6, 4);
g.fillRect(28, 8, 4, 4);
g.fillRect(28, 16, 4, 4);
g.fillRect(30, 12, 2, 4);
g.fillRect(18, 4, 2, 4);
g.fillRect(18, 20, 2, 4);
g.fillRect(16, 8, 2, 12);
g.fillRect(20, 8, 2, 12);
break;
case 2: // Down
g.fillRect(0, 16, 4, 10);
g.fillRect(24, 16, 4, 10);
g.fillRect(4, 24, 4, 6);
g.fillRect(20, 24, 4, 6);
g.fillRect(8, 28, 4, 4);
g.fillRect(16, 28, 4, 4);
g.fillRect(12, 30, 4, 2);
g.fillRect(4, 18, 4, 2);
g.fillRect(20, 18, 4, 2);
g.fillRect(8, 16, 12, 2);
g.fillRect(8, 20, 12, 2);
break;
case 3: // Left
g.fillRect(24, 0, 10, 4);
g.fillRect(24, 24, 10, 4);
g.fillRect(20, 4, 6, 4);
g.fillRect(20, 20, 6, 4);
g.fillRect(18, 8, 4, 4);
g.fillRect(18, 16, 4, 4);
g.fillRect(18, 12, 2, 4);
g.fillRect(30, 4, 2, 4);
g.fillRect(30, 20, 2, 4);
g.fillRect(28, 8, 2, 12);
g.fillRect(32, 8, 2, 12);
break;
}
}
}
currentIcon = icons[rotation % 2].getImage();
}
public boolean Function() {
ports[2].value = ports[0].value ^ ports[1].value;
return false;
}
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 (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,21 +1,16 @@
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;
// 0=Wait for Player
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
// 3=Patrol Up
@@ -23,329 +18,356 @@ 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;
grabbable = false;
width=26;height=32;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public AmpireBot(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
grabbable = false;
width = 26;
height = 32;
GenerateIcons();
currentIcon = icons[0].getImage();
}
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));
icons[2]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[3]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[4]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[5]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// 0= blue 1
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(2,6,8,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,16,6,6);
g.fillRect(6,18,14,2);
g.setColor(Color.blue);
g.fillRect(2,6,8,2);
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));
icons[2] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[4] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[5] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
// 1= blue 2
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(2,6,8,2);
g.fillRect(8,28,10,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,14,6,6);
g.fillRect(6,16,14,2);
g.setColor(Color.blue);
g.fillRect(8,6,8,2);
// 0= blue 1
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(2, 6, 8, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 16, 6, 6);
g.fillRect(6, 18, 14, 2);
g.setColor(Color.blue);
g.fillRect(2, 6, 8, 2);
// 2= blue 3
try
{
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(12,24,2,4);
g.fillRect(0,28,6,2);
g.fillRect(20,28,6,2);
g.fillRect(8,30,10,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,12,6,6);
g.fillRect(6,14,14,2);
g.setColor(Color.blue);
g.fillRect(18,6,8,2);
// 1= blue 2
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(2, 6, 8, 2);
g.fillRect(8, 28, 10, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 14, 6, 6);
g.fillRect(6, 16, 14, 2);
g.setColor(Color.blue);
g.fillRect(8, 6, 8, 2);
// 3= green 1
try
{
g = icons[3].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.green);
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(2,6,8,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,16,6,6);
g.fillRect(6,18,14,2);
g.setColor(Color.green);
g.fillRect(2,6,8,2);
// 2= blue 3
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(12, 24, 2, 4);
g.fillRect(0, 28, 6, 2);
g.fillRect(20, 28, 6, 2);
g.fillRect(8, 30, 10, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 12, 6, 6);
g.fillRect(6, 14, 14, 2);
g.setColor(Color.blue);
g.fillRect(18, 6, 8, 2);
// 4= orange 2
try
{
g = icons[4].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(new Color(255,128,0));
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(2,6,8,2);
g.fillRect(8,28,10,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,14,6,6);
g.fillRect(6,16,14,2);
g.setColor(new Color(255,128,0));
g.fillRect(8,6,8,2);
// 3= green 1
try {
g = icons[3].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.green);
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(2, 6, 8, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 16, 6, 6);
g.fillRect(6, 18, 14, 2);
g.setColor(Color.green);
g.fillRect(2, 6, 8, 2);
// 5= green 3
try
{
g = icons[5].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.green);
g.fillRect(8,0,8,2);
g.fillRect(0,2,26,10);
g.fillRect(4,12,18,12);
g.fillRect(0,16,26,6);
g.fillRect(12,24,2,8);
g.fillRect(12,24,2,4);
g.fillRect(0,28,6,2);
g.fillRect(20,28,6,2);
g.fillRect(8,30,10,2);
g.setColor(Color.black);
g.fillRect(2,4,22,6);
g.fillRect(10,12,6,6);
g.fillRect(6,14,14,2);
g.setColor(Color.green);
g.fillRect(18,6,8,2);
if (animationState==4) animationState=0;
int frame = animationState;
if (animationState==3) frame=1;
if (!alive) frame +=3;
currentIcon = icons[frame].getImage();
}
// 4= orange 2
try {
g = icons[4].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(new Color(255, 128, 0));
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(2, 6, 8, 2);
g.fillRect(8, 28, 10, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 14, 6, 6);
g.fillRect(6, 16, 14, 2);
g.setColor(new Color(255, 128, 0));
g.fillRect(8, 6, 8, 2);
public void Animate()
{
animationState++;
if (animationState==4) animationState=0;
int frame = animationState;
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)
{
previousBehavior=behaviorState;
behaviorState=6;
a=level.items.size();
}
}
switch (behaviorState)
{
case 0:
if (level.player.room == room) behaviorState=1;
break;
case 1:
if (y>=192)
behaviorState = 2;
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)
behaviorState = 3;
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)
behaviorState = 4;
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)
behaviorState = 5;
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)
behaviorState = 2;
else
{
MoveDown( 8);
if (x<280) MoveRight(8);
if (x>280) MoveLeft(8);
}
break;
case 6:
if (target.room != room)
behaviorState = previousBehavior;
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);
break;
case 7:
if (target.room != room)
{
behaviorState = previousBehavior;
break;
}
if (target.charge>0 && Overlaps(target))
{
if (target.getClass().toString().endsWith("BlackCrystal"))
alive = false;
else
target.charge-=3125;
}
else
behaviorState = 6;
if (target.charge <=0)
{
target.charge=0;
behaviorState=previousBehavior;
}
break;
}
}
}
// 5= green 3
try {
g = icons[5].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.green);
g.fillRect(8, 0, 8, 2);
g.fillRect(0, 2, 26, 10);
g.fillRect(4, 12, 18, 12);
g.fillRect(0, 16, 26, 6);
g.fillRect(12, 24, 2, 8);
g.fillRect(12, 24, 2, 4);
g.fillRect(0, 28, 6, 2);
g.fillRect(20, 28, 6, 2);
g.fillRect(8, 30, 10, 2);
g.setColor(Color.black);
g.fillRect(2, 4, 22, 6);
g.fillRect(10, 12, 6, 6);
g.fillRect(6, 14, 14, 2);
g.setColor(Color.green);
g.fillRect(18, 6, 8, 2);
public void Erase()
{
super.Erase();
target = null;
}
if (animationState == 4) {
animationState = 0;
}
int frame = animationState;
if (animationState == 3) {
frame = 1;
}
if (!alive) {
frame += 3;
}
currentIcon = icons[frame].getImage();
}
public void Animate() {
animationState++;
if (animationState == 4) {
animationState = 0;
}
int frame = animationState;
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 = level.items.elementAt(a);
if (target.room == room) {
if (target.charge > 0) {
previousBehavior = behaviorState;
behaviorState = 6;
a = level.items.size();
}
}
}
}
switch (behaviorState) {
case 0:
if (level.player.room == room) {
behaviorState = 1;
}
break;
case 1:
if (y >= 192) {
behaviorState = 2;
}
else {
MoveDown(8);
if (x < 280) {
MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
}
break;
case 2:
if (room == level.rooms.elementAt(18) && x <= 280) {
behaviorState = 3;
}
else {
MoveLeft(8);
if (y < 192) {
MoveDown(8);
}
if (y > 192) {
MoveUp(8);
}
}
break;
case 3:
if (room == level.rooms.elementAt(19) && y <= 192) {
behaviorState = 4;
}
else {
MoveUp(8);
if (x < 280) {
MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
}
break;
case 4:
if (room == level.rooms.elementAt(15) && x >= 280) {
behaviorState = 5;
}
else {
MoveRight(8);
if (y < 192) {
MoveDown(8);
}
if (y > 192) {
MoveUp(8);
}
}
break;
case 5:
if (room == level.rooms.elementAt(16) && y >= 192) {
behaviorState = 2;
}
else {
MoveDown(8);
if (x < 280) {
MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
}
break;
case 6:
if (target.room != room) {
behaviorState = previousBehavior;
}
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);
}
break;
case 7:
if (target.room != room) {
behaviorState = previousBehavior;
break;
}
if (target.charge > 0 && Overlaps(target)) {
if (target.getClass().toString().endsWith("BlackCrystal")) {
alive = false;
}
else {
target.charge -= 3125;
}
}
else {
behaviorState = 6;
}
if (target.charge <= 0) {
target.charge = 0;
behaviorState = previousBehavior;
}
break;
}
}
}
public void Erase() {
super.Erase();
target = null;
}
}

View File

@@ -1,177 +1,158 @@
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;
GenerateIcons();
}
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 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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0,0,28,30);
g.setColor(Color.black);
g.fillRect(8,8,12,14);
g.fillRect(4,10,20,10);
g.setColor(Color.white);
g.fillRect(12,10,4,10);
g.fillRect(8,12,12,6);
public AutoWire(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 30;
GenerateIcons();
}
// 1 = On
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(new Color(255,128,0));
g.fillRect(0,0,28,30);
g.setColor(Color.black);
g.fillRect(8,8,12,14);
g.fillRect(4,10,20,10);
g.setColor(new Color(255,128,0));
g.fillRect(12,10,4,10);
g.fillRect(8,12,12,6);
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;
currentIcon = icons[0].getImage();
}
// 0 = Off
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, 28, 30);
g.setColor(Color.black);
g.fillRect(8, 8, 12, 14);
g.fillRect(4, 10, 20, 10);
g.setColor(Color.white);
g.fillRect(12, 10, 4, 10);
g.fillRect(8, 12, 12, 6);
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"))
{
PrototypeChip pc = (PrototypeChip) item;
if (pc.inTester) chip = pc;
}
if (item.getClass().toString().endsWith("SmallChip"))
{
SmallChip sc = (SmallChip) item;
if (sc.inTester) chip = sc;
}
if (item.getClass().toString().endsWith("PortDevice"))
{
if (item.room == room)
{
portdevices[pdcount] = (PortDevice) item;
pdcount++;
}
}
}
if (chip==null) return false;
animation=1;
return false;
}
// 1 = On
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(new Color(255, 128, 0));
g.fillRect(0, 0, 28, 30);
g.setColor(Color.black);
g.fillRect(8, 8, 12, 14);
g.fillRect(4, 10, 20, 10);
g.setColor(new Color(255, 128, 0));
g.fillRect(12, 10, 4, 10);
g.fillRect(8, 12, 12, 6);
public void Animate()
{
if (animation==0) return;
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
portdevices[0].ports[0].myWire.Remove();
portdevices[0].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[0].ports[0].value = false;
}
animation++;
currentIcon = icons[1].getImage();
return;
}
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)
{
portdevices[animation-1].ports[0].myWire.Remove();
portdevices[animation-1].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[animation-1].ports[0].value = false;
}
}
animation++;
}
currentIcon = icons[0].getImage();
if (animation==9)
{
currentIcon = icons[0].getImage();
animation=0;
}
}
}
public void Erase()
{
super.Erase();
chip=null;
portdevices = null;
}
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 = level.items.elementAt(a);
if (item instanceof PrototypeChip) {
PrototypeChip pc = (PrototypeChip) item;
if (pc.inTester) {
chip = pc;
}
}
if (item instanceof SmallChip) {
SmallChip sc = (SmallChip) item;
if (sc.inTester) {
chip = sc;
}
}
if (item instanceof PortDevice) {
if (item.room == room) {
portdevices[pdcount] = (PortDevice) item;
pdcount++;
}
}
}
if (chip == null) {
return false;
}
animation = 1;
return false;
}
public void Animate() {
if (animation == 0) {
return;
}
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;
}
else { // Unwiring
portdevices[0].ports[0].myWire.Remove();
portdevices[0].ports[0].type = Port.TYPE_UNDEFINED;
portdevices[0].ports[0].value = false;
}
animation++;
currentIcon = icons[1].getImage();
return;
}
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;
}
}
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;
}
}
animation++;
}
if (animation == 9) {
currentIcon = icons[0].getImage();
animation = 0;
}
}
public void Erase() {
super.Erase();
chip = null;
portdevices = null;
}
}

View File

@@ -1,58 +1,53 @@
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;
GenerateIcons();
}
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(new Color(255,128,0));
g.fillRect(4,0,4,8);
g.fillRect(4,10,4,2);
g.fillRect(0,12,4,4);
g.fillRect(8,12,4,4);
g.fillRect(4,16,4,2);
g.fillRect(4,20,4,8);
g.fillRect(16,0,4,2);
g.fillRect(12,2,4,4);
g.fillRect(20,2,4,4);
g.fillRect(16,6,4,2);
g.fillRect(16,10,4,8);
g.fillRect(16,20,4,2);
g.fillRect(12,22,4,4);
g.fillRect(20,22,4,4);
g.fillRect(16,26,4,2);
currentIcon = icons[0].getImage();
}
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() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(new Color(255, 128, 0));
g.fillRect(4, 0, 4, 8);
g.fillRect(4, 10, 4, 2);
g.fillRect(0, 12, 4, 4);
g.fillRect(8, 12, 4, 4);
g.fillRect(4, 16, 4, 2);
g.fillRect(4, 20, 4, 8);
g.fillRect(16, 0, 4, 2);
g.fillRect(12, 2, 4, 4);
g.fillRect(20, 2, 4, 4);
g.fillRect(16, 6, 4, 2);
g.fillRect(16, 10, 4, 8);
g.fillRect(16, 20, 4, 2);
g.fillRect(12, 22, 4, 4);
g.fillRect(20, 22, 4, 4);
g.fillRect(16, 26, 4, 2);
currentIcon = icons[0].getImage();
}
}

View File

@@ -9,46 +9,42 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class BlackCrystal extends Crystal
{
public BlackCrystal(int X, int Y, Room r)
{
super(X,Y,r,10);
}
public class BlackCrystal extends Crystal {
public BlackCrystal(int X, int Y, Room r) {
super(X, Y, r, 10);
}
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);
// 0 = blue
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.black);
g.fillRect(12,0,4,24);
g.fillRect(8,4,12,16);
g.fillRect(4,6,20,12);
g.fillRect(0,10,28,4);
g.fillRect(0,4,4,2);
g.fillRect(0,18,4,2);
g.fillRect(24,4,4,2);
g.fillRect(24,18,4,2);
currentIcon = icons[0].getImage();
}
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);
public void Decorate() {}
// 0 = blue
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.black);
g.fillRect(12, 0, 4, 24);
g.fillRect(8, 4, 12, 16);
g.fillRect(4, 6, 20, 12);
g.fillRect(0, 10, 28, 4);
g.fillRect(0, 4, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(24, 4, 4, 2);
g.fillRect(24, 18, 4, 2);
currentIcon = icons[0].getImage();
}
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,53 +7,52 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster;
public class BlueRobot extends GenericRobot
{
private int scan;
private int scandir;
import java.awt.*;
public BlueRobot(int X, int Y, Room r)
{
super(X,Y,r,Color.blue);
scan=0;
scandir=2;
Animate();
devices[0] = new Thruster(176,16,InternalRoom,Port.ROT_UP,Color.white);
devices[1] = new Thruster(476,128,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[2] = new Thruster(356,336,InternalRoom,Port.ROT_DOWN,Color.white);
devices[3] = new Thruster(32,236,InternalRoom,Port.ROT_LEFT,Color.white);
devices[4] = new Bumper(396,16,InternalRoom,Port.ROT_UP,Color.white);
devices[5] = new Bumper(480,256,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[6] = new Bumper(128,330,InternalRoom,Port.ROT_DOWN,Color.white);
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++)
level.items.addElement(devices[a]);
public class BlueRobot extends GenericRobot {
private int scan;
private int scandir;
}
public BlueRobot(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
scan = 0;
scandir = 2;
Animate();
devices[0] = new Thruster(176, 16, InternalRoom, Port.ROT_UP, Color.white);
devices[1] = new Thruster(476, 128, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[2] = new Thruster(356, 336, InternalRoom, Port.ROT_DOWN, Color.white);
devices[3] = new Thruster(32, 236, InternalRoom, Port.ROT_LEFT, Color.white);
devices[4] = new Bumper(396, 16, InternalRoom, Port.ROT_UP, Color.white);
devices[5] = new Bumper(480, 256, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[6] = new Bumper(128, 330, InternalRoom, Port.ROT_DOWN, Color.white);
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++) {
level.items.addElement(devices[a]);
}
public void Decorate()
{
super.Decorate();
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
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)
scandir=-scandir;
scan=scan+scandir;
g.setColor(new Color(255,128,0));
g.fillRect(22+scan,44,6,4);
}
}
public void Decorate() {
super.Decorate();
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
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) {
scandir = -scandir;
}
scan = scan + scandir;
g.setColor(new Color(255, 128, 0));
g.fillRect(22 + scan, 44, 6, 4);
}
}

View File

@@ -2,130 +2,122 @@ 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;
GenerateIcons();
}
public Burner(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 30;
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0,0,28,30);
g.setColor(Color.black);
g.fillRect(8,8,12,14);
g.fillRect(4,10,20,10);
g.setColor(Color.white);
g.fillRect(12,10,4,10);
g.fillRect(8,12,12,6);
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;
// 1 = On
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(new Color(255,128,0));
g.fillRect(0,0,28,30);
g.setColor(Color.black);
g.fillRect(8,8,12,14);
g.fillRect(4,10,20,10);
g.setColor(new Color(255,128,0));
g.fillRect(12,10,4,10);
g.fillRect(8,12,12,6);
// 0 = Off
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, 28, 30);
g.setColor(Color.black);
g.fillRect(8, 8, 12, 14);
g.fillRect(4, 10, 20, 10);
g.setColor(Color.white);
g.fillRect(12, 10, 4, 10);
g.fillRect(8, 12, 12, 6);
currentIcon = icons[0].getImage();
}
// 1 = On
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(new Color(255, 128, 0));
g.fillRect(0, 0, 28, 30);
g.setColor(Color.black);
g.fillRect(8, 8, 12, 14);
g.fillRect(4, 10, 20, 10);
g.setColor(new Color(255, 128, 0));
g.fillRect(12, 10, 4, 10);
g.fillRect(8, 12, 12, 6);
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;
}
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;
}
if (pc==null) return false;
// Start the ChipCompiler thread
ChipCompiler cc = new ChipCompiler( (PrototypeChip) pc, (SmallChip) sc);
level.PlaySound(room,Level.BURNSOUND);
burning = 10;
return false;
}
currentIcon = icons[0].getImage();
public void Animate()
{
if (burning>0)
{
animation = 1- animation;
currentIcon = icons[animation].getImage();
burning--;
}
else
currentIcon = icons[0].getImage();
}
}
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 = level.items.elementAt(a);
if (item.getClass().toString().endsWith("SmallChip")) {
if (((SmallChip) item).inBurner) {
sc = item;
}
}
}
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 = level.items.elementAt(a);
if (item.getClass().toString().endsWith("PrototypeChip")) {
if (((PrototypeChip) item).inBurner) {
pc = item;
}
}
}
if (pc == null) {
return false;
}
// Start the ChipCompiler thread
ChipCompiler cc = new ChipCompiler((PrototypeChip) pc, (SmallChip) sc);
level.PlaySound(room, Level.BURNSOUND);
burning = 10;
return false;
}
public void Animate() {
if (burning > 0) {
animation = 1 - animation;
currentIcon = icons[animation].getImage();
burning--;
}
else {
currentIcon = icons[0].getImage();
}
}
}

View File

@@ -9,47 +9,45 @@ 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;
color=c;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(color);
g.fillRect(8,0,12,26);
g.fillRect(4,2,20,22);
g.fillRect(0,4,28,18);
g.setColor(Color.black);
g.fillRect(8,6,12,14);
g.fillRect(4,8,20,10);
g.setColor(color);
g.fillRect(12,8,4,10);
g.fillRect(8,10,12,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(color);
g.fillRect(8, 0, 12, 26);
g.fillRect(4, 2, 20, 22);
g.fillRect(0, 4, 28, 18);
g.setColor(Color.black);
g.fillRect(8, 6, 12, 14);
g.fillRect(4, 8, 20, 10);
g.setColor(color);
g.fillRect(12, 8, 4, 10);
g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage();
}
}

View File

@@ -6,39 +6,35 @@ 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)
{
super(X,Y,r,Color.white,0);
}
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"))
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"))
{
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);
tb.y -= 500;
}
}
}
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")) {
level.currentViewer = spycam;
level.player = spycam;
spycam.room = room;
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,450 +1,414 @@
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();
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);
wire.Remove();
}
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);
if (item.room == pc.InternalRoom
&& item instanceof Device
&& !(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)
pc.portdevices[a].ports[0].type = 1-sc.portSignals[a].type;
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"))
{
ANDGate andGate = new ANDGate(10*28,6*32,pc.InternalRoom);
deviceList.addElement(andGate);
pc.level.items.addElement(andGate);
}
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"))
{
NOTGate notGate = new NOTGate(10*28,6*32,pc.InternalRoom);
deviceList.addElement(notGate);
pc.level.items.addElement(notGate);
}
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"))
{
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"))
{
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++)
{
Signal newsig = new Signal();
Signal oldsig = (Signal) 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);
Gate newgate = new Gate(oldgate);
smallchip.gates.addElement(newgate);
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);
}
}
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].type = gate.portSignals[b].type;
smallchip.ports[b].type = gate.portSignals[b].type;
}
}
}
// 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)
{
int numConnections = 0;
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)
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)
{
Wire dummy = new Wire(port1, port2);
}
else
{
System.out.println("Could not make connection for Signal " + a);
if (port1==null)
System.out.println("port1=null");
else
System.out.println("port1 is in " + port1.myDevice.getClass());
if (port2==null)
System.out.println("port2=null");
else
System.out.println("port2 is in " + port2.myDevice.getClass());
}
}
else if (numConnections==3) // Need a regular Node
{
Port port1 = FindPort(sig, 1, pc, sc, deviceList);
Port port2 = FindPort(sig, 2, pc, sc, deviceList);
Port port3 = FindPort(sig, 3, pc, sc, deviceList);
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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 (numConnections==4) // Need a 3 output Node
{
Port port1 = FindPort(sig, 1, pc, sc, deviceList);
Port port2 = FindPort(sig, 2, pc, sc, deviceList);
Port port3 = FindPort(sig, 3, pc, sc, deviceList);
Port port4 = FindPort(sig, 4, pc, sc, deviceList);
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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 (numConnections>4) // Need many nodes
{
Port[] ports = new Port[numConnections];
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++)
{
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++)
{
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)
{
Wire dummy = new Wire(nodes[0].ports[0],ports[b]);
inputfound=true;
}
else if (ports[b].type == Port.TYPE_INPUT)
{
if (nodecounter<nodes.length)
{
Wire dummy = new Wire(nodes[nodecounter].ports[1],ports[b]);
nodecounter++;
}
else
{
Wire dummy = new Wire(nodes[nodecounter-1].ports[2], ports[b]);
}
}
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)
{
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);
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)
{
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)
{
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;
}
}
// 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);
if (!(device instanceof SmallChip
|| device instanceof Node
|| device instanceof FlipFlop))
{
Port port;
if (device instanceof NOTGate)
port = device.ports[1];
else
port = device.ports[2];
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);
}
else
{
if (dy>0)
{
device.rotate(1);
device.rotate(1);
}
}
}
}
}
pc.grabbable = true;
sc.grabbable = true;
}
import java.util.Vector;
public Port FindPort(Signal sig, int num, PrototypeChip pc, SmallChip sc, Vector 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)
{
n++;
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)
{
n++;
if (n==num)
{
Device device = (Device) deviceList.elementAt(a);
return device.ports[b];
}
}
}
return null;
}
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 = pc.InternalRoom.wires.elementAt(a);
wire.Remove();
}
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 = pc.level.items.elementAt(a);
if (item.room == pc.InternalRoom
&& item instanceof Device
&& !(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) {
pc.portdevices[a].ports[0].type = 1 - sc.portSignals[a].type;
}
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 = 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")) {
ORGate orGate = new ORGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(orGate);
pc.level.items.addElement(orGate);
}
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")) {
XORGate xorGate = new XORGate(10 * 28, 6 * 32, pc.InternalRoom);
deviceList.addElement(xorGate);
pc.level.items.addElement(xorGate);
}
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")) {
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++) {
Signal newsig = new Signal();
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.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) {
int sigIndex = gate.mySignals.indexOf(oldgate.portSignals[c].externalSignal);
newgate.portSignals[c].externalSignal = (Signal) smallchip.signals.elementAt(sigIndex);
}
}
}
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].type = gate.portSignals[b].type;
smallchip.ports[b].type = gate.portSignals[b].type;
}
}
}
// Wire Devices according to the way the Gates are linked to Signals
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) {
numConnections++;
}
}
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) {
Wire dummy = new Wire(port1, port2);
}
else {
System.out.println("Could not make connection for Signal " + a);
if (port1 == null) {
System.out.println("port1=null");
}
else {
System.out.println("port1 is in " + port1.myDevice.getClass());
}
if (port2 == null) {
System.out.println("port2=null");
}
else {
System.out.println("port2 is in " + port2.myDevice.getClass());
}
}
}
else if (numConnections == 3) // Need a regular Node
{
Port port1 = FindPort(sig, 1, pc, sc, deviceList);
Port port2 = FindPort(sig, 2, pc, sc, deviceList);
Port port3 = FindPort(sig, 3, pc, sc, deviceList);
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) {
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) {
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) {
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) {
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) {
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) {
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 (numConnections == 4) // Need a 3 output Node
{
Port port1 = FindPort(sig, 1, pc, sc, deviceList);
Port port2 = FindPort(sig, 2, pc, sc, deviceList);
Port port3 = FindPort(sig, 3, pc, sc, deviceList);
Port port4 = FindPort(sig, 4, pc, sc, deviceList);
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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 (numConnections > 4) // Need many nodes
{
Port[] ports = new Port[numConnections];
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++) {
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++) {
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) {
Wire dummy = new Wire(nodes[0].ports[0], ports[b]);
inputfound = true;
}
else if (ports[b].type == Port.TYPE_INPUT) {
if (nodecounter < nodes.length) {
Wire dummy = new Wire(nodes[nodecounter].ports[1], ports[b]);
nodecounter++;
}
else {
Wire dummy = new Wire(nodes[nodecounter - 1].ports[2], ports[b]);
}
}
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) {
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 = 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) {
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) {
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;
}
}
}
// Rotate devices to point to the "next" device. AND, OR, NOT, XOR only
for (int a = 0; a < deviceList.size(); a++) {
Device device = deviceList.elementAt(a);
if (!(device instanceof SmallChip
|| device instanceof Node
|| device instanceof FlipFlop)) {
Port port;
if (device instanceof NOTGate) {
port = device.ports[1];
}
else {
port = device.ports[2];
}
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);
}
}
else {
if (dy > 0) {
device.rotate(1);
device.rotate(1);
}
}
}
}
}
pc.grabbable = true;
sc.grabbable = true;
}
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) {
n++;
if (n == num) {
return pc.portdevices[a].ports[0];
}
}
}
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 = deviceList.elementAt(a);
return device.ports[b];
}
}
}
}
return null;
}
}

View File

@@ -9,114 +9,108 @@ 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;
charge=ch;
width=28; height=24;
editable=true;
GenerateIcons();
currentIcon = icons[0].getImage();
}
public Crystal(int X, int Y, Room r, int ch) {
x = X;
y = Y;
room = r;
charge = ch;
width = 28;
height = 24;
editable = true;
GenerateIcons();
currentIcon = icons[0].getImage();
}
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;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// 0 = blue
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(12,0,4,24);
g.fillRect(8,4,12,16);
g.fillRect(4,6,20,12);
g.fillRect(0,10,28,4);
g.fillRect(0,4,4,2);
g.fillRect(0,18,4,2);
g.fillRect(24,4,4,2);
g.fillRect(24,18,4,2);
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;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
// 1 = orange
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(new Color(255,128,0));
g.fillRect(12,0,4,24);
g.fillRect(8,4,12,16);
g.fillRect(4,6,20,12);
g.fillRect(0,10,28,4);
g.fillRect(0,4,4,2);
g.fillRect(0,18,4,2);
g.fillRect(24,4,4,2);
g.fillRect(24,18,4,2);
// 2 = white
try
{
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(12,0,4,24);
g.fillRect(8,4,12,16);
g.fillRect(4,6,20,12);
g.fillRect(0,10,28,4);
g.fillRect(0,4,4,2);
g.fillRect(0,18,4,2);
g.fillRect(24,4,4,2);
g.fillRect(24,18,4,2);
currentIcon = icons[color].getImage();
if (charge==0)
currentIcon = icons[2].getImage();
}
// 0 = blue
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(12, 0, 4, 24);
g.fillRect(8, 4, 12, 16);
g.fillRect(4, 6, 20, 12);
g.fillRect(0, 10, 28, 4);
g.fillRect(0, 4, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(24, 4, 4, 2);
g.fillRect(24, 18, 4, 2);
public void Decorate()
{
if (charge>0)
{
color = 1-color;
currentIcon = icons[color].getImage();
}
else
currentIcon = icons[2].getImage();
}
// 1 = orange
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(new Color(255, 128, 0));
g.fillRect(12, 0, 4, 24);
g.fillRect(8, 4, 12, 16);
g.fillRect(4, 6, 20, 12);
g.fillRect(0, 10, 28, 4);
g.fillRect(0, 4, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(24, 4, 4, 2);
g.fillRect(24, 18, 4, 2);
// 2 = white
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(12, 0, 4, 24);
g.fillRect(8, 4, 12, 16);
g.fillRect(4, 6, 20, 12);
g.fillRect(0, 10, 28, 4);
g.fillRect(0, 4, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(24, 4, 4, 2);
g.fillRect(24, 18, 4, 2);
currentIcon = icons[color].getImage();
if (charge == 0) {
currentIcon = icons[2].getImage();
}
}
public void Decorate() {
if (charge > 0) {
color = 1 - color;
currentIcon = icons[color].getImage();
}
else {
currentIcon = icons[2].getImage();
}
}
}

View File

@@ -1,94 +1,85 @@
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 Disk(int X, int Y, Room r, Color col, int hr) {
x = X;
y = Y;
room = r;
color = col;
width = 28;
height = 24;
grabbable = true;
helpRoom = level.rooms.elementAt(hr);
GenerateIcons();
}
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;
color = col;
width=28; height=24;
grabbable=true;
helpRoom = (Room) level.rooms.elementAt(hr);
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
g.fillRect(0,0,width,height);
g.setColor(Color.black);
g.fillRect(24,4,4,2);
g.fillRect(12,8,4,8);
g.fillRect(8,10,12,4);
g.fillRect(20,14,4,2);
g.fillRect(12,18,4,4);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
g.fillRect(24, 4, 4, 2);
g.fillRect(12, 8, 4, 8);
g.fillRect(8, 10, 12, 4);
g.fillRect(20, 14, 4, 2);
g.fillRect(12, 18, 4, 4);
currentIcon = icons[0].getImage();
}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
s.writeInt(level.rooms.indexOf(helpRoom));
}
public void writeRef(ObjectOutputStream s) throws IOException {
super.writeRef(s);
s.writeInt(level.rooms.indexOf(helpRoom));
}
public void readRef(ObjectInputStream s) throws IOException
{
super.readRef(s);
helpRoom = (Room) level.FindRoom(s.readInt());
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s);
helpRoom = level.FindRoom(s.readInt());
}
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"))
{
helpCamRoom = level.helpCam.room; // Temporary storage
level.helpCam.room = helpRoom;
level.currentViewer=level.helpCam;
level.player=level.helpCam;
}
}
public void IsDropped() {
public boolean CanBePickedUp(Item item)
{
if (level.helpCam.room == room)
level.helpCam.room = helpCamRoom;
level.currentViewer = level.player;
return true;
}
int bigX = (x + width / 2) / 28;
int bigY = (y + height / 2) / 32;
Material mat = room.MaterialArray[bigY][bigX];
if (mat.getClass().toString().endsWith("Monitor")) {
helpCamRoom = level.helpCam.room; // Temporary storage
level.helpCam.room = helpRoom;
level.currentViewer = level.helpCam;
level.player = level.helpCam;
}
}
public boolean CanBePickedUp(Item item) {
if (level.helpCam.room == room) {
level.helpCam.room = helpCamRoom;
}
level.currentViewer = level.player;
return true;
}
}

View File

@@ -8,56 +8,53 @@ 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;
grabbable=true;
GenerateIcons();
}
public ElevatorKey(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = true;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0,0,28,32);
g.setColor(Color.black);
g.fillRect(4,4,4,2);
g.fillRect(12,4,4,2);
g.fillRect(4,8,4,2);
g.fillRect(20,8,4,2);
g.fillRect(20,26,4,2);
g.fillRect(4,14,12,4);
g.fillRect(4,22,12,4);
g.fillRect(20,12,4,12);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, 28, 32);
g.setColor(Color.black);
g.fillRect(4, 4, 4, 2);
g.fillRect(12, 4, 4, 2);
g.fillRect(4, 8, 4, 2);
g.fillRect(20, 8, 4, 2);
g.fillRect(20, 26, 4, 2);
g.fillRect(4, 14, 12, 4);
g.fillRect(4, 22, 12, 4);
g.fillRect(20, 12, 4, 12);
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (carriedBy!=null)
jumping=false;
if (jumping==true)
{
x=level.random.nextInt(8*28)+28;
y=level.random.nextInt(2*32)+(8*32);
}
}
public void Animate() {
if (carriedBy != null) {
jumping = false;
}
if (jumping) {
x = level.random.nextInt(8 * 28) + 28;
y = level.random.nextInt(2 * 32) + (8 * 32);
}
}
}

View File

@@ -5,82 +5,76 @@ import com.droidquest.decorations.Arrow;
import com.droidquest.materials.ElevatorOutPortal;
import com.droidquest.materials.Switch;
public class ElevatorSwitch extends Switch
{
int animationState=0;
// 0=open
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()
{
super(Switch.ROT_LEFT);
}
public ElevatorSwitch() {
super(Switch.ROT_LEFT);
}
public void TouchedByItem(Item item)
{
room = item.room;
if (animationState==0)
animationState = 1;
}
public void TouchedByItem(Item item) {
room = item.room;
if (animationState == 0) {
animationState = 1;
}
}
public void Animate()
{
super.Animate();
switch (animationState)
{
case 0: value =false; break;
case 1:
// Play sound
value=true;
room.SetMaterial(0,7,4);
room.SetMaterial(0,10,4);
animationState++;
break;
case 2:
room.SetMaterial(0,8,4);
room.SetMaterial(0,9,4);
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);
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);
arrow.direction = Arrow.DIR_DOWN;
arrow.y = 94;
}
ElevatorOutPortal.SetOutRoom(11);
}
animationState++;
break;
case 4:
room.SetMaterial(0,8,12);
room.SetMaterial(0,9,12);
animationState++;
break;
case 5:
room.SetMaterial(0,7,12);
room.SetMaterial(0,10,12);
animationState=0;
break;
}
}
public void Animate() {
super.Animate();
switch (animationState) {
case 0:
value = false;
break;
case 1:
// Play sound
value = true;
room.SetMaterial(0, 7, 4);
room.SetMaterial(0, 10, 4);
animationState++;
break;
case 2:
room.SetMaterial(0, 8, 4);
room.SetMaterial(0, 9, 4);
animationState++;
break;
case 3:
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 = room.arrows.elementAt(a);
arrow.direction = Arrow.DIR_DOWN;
arrow.y = 94;
}
ElevatorOutPortal.SetOutRoom(11);
}
animationState++;
break;
case 4:
room.SetMaterial(0, 8, 12);
room.SetMaterial(0, 9, 12);
animationState++;
break;
case 5:
room.SetMaterial(0, 7, 12);
room.SetMaterial(0, 10, 12);
animationState = 0;
break;
}
}
}

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;
public EndAnimation(Room r)
{
super(r);
}
private int animationState = 0;
private transient boolean playsong = false;
public void Animate()
{
if (playsong==false)
{
level.PlaySound(room, Level.ENDMUSICSOUND);
playsong=true;
}
animationState = 1-animationState;
for(int a=0; a<20; a++)
if (a%2==animationState)
{
room.SetMaterial(a,0,0);
room.SetMaterial(a,11,1);
}
else
{
room.SetMaterial(a,0,1);
room.SetMaterial(a,11,0);
}
for(int a=0; a<12; a++)
if (a%2==animationState)
{
room.SetMaterial(0,a,0);
room.SetMaterial(19,a,1);
}
else
{
room.SetMaterial(0,a,1);
room.SetMaterial(19,a,0);
}
}
public EndAnimation(Room r) {
super(r);
}
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) {
room.SetMaterial(a, 0, 0);
room.SetMaterial(a, 11, 1);
}
else {
room.SetMaterial(a, 0, 1);
room.SetMaterial(a, 11, 0);
}
}
for (int a = 0; a < 12; a++) {
if (a % 2 == animationState) {
room.SetMaterial(0, a, 0);
room.SetMaterial(19, a, 1);
}
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
{
transient NotAButton nb=null;
int animationState=0;
public class EnergyButton extends Button {
transient NotAButton nb = null;
private int animationState = 0;
public EnergyButton()
{
super(0,0,null,new Color(255,128,0));
grabbable=false;
}
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))
{
animationState=1;
nb.animationState=51;
for (int b=1; b<19; b++)
room.downRoom.SetMaterial(b,4,0);
TextBox line = (TextBox) room.downRoom.textBoxes.elementAt(1);
line.textString = " ";
}
}
}
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++) {
room.downRoom.SetMaterial(b, 4, 0);
}
TextBox line = room.downRoom.textBoxes.elementAt(1);
line.textString = " ";
}
}
}
}
}
}

View File

@@ -8,64 +8,60 @@ 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;
room = r;
width = 28; height = 32;
GenerateIcons();
}
public F12Form(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0,0,28,32);
g.setColor(Color.black);
g.fillRect(8,2,4,10);
g.fillRect(12,2,8,2);
g.fillRect(12,6,4,2);
g.fillRect(12,14,4,4);
g.fillRect(4,20,4,10);
g.fillRect(12,20,8,2);
g.fillRect(20,22,4,2);
g.fillRect(16,24,4,2);
g.fillRect(12,26,4,4);
g.fillRect(16,28,8,2);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, 28, 32);
g.setColor(Color.black);
g.fillRect(8, 2, 4, 10);
g.fillRect(12, 2, 8, 2);
g.fillRect(12, 6, 4, 2);
g.fillRect(12, 14, 4, 4);
g.fillRect(4, 20, 4, 10);
g.fillRect(12, 20, 8, 2);
g.fillRect(20, 22, 4, 2);
g.fillRect(16, 24, 4, 2);
g.fillRect(12, 26, 4, 4);
g.fillRect(16, 28, 8, 2);
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"))
gk = (GateKeeper) item;
}
if (gk != null)
if (Overlaps(gk))
{
gk.PicksUp(this);
gk.behavior=1;
}
}
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)) {
gk.PicksUp(this);
gk.behavior = 1;
}
}
}
}

View File

@@ -4,52 +4,46 @@ 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)
{
super(X, Y, r, Color.white);
grabbable = false;
}
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)
{
robots[rcount] = (GenericRobot) item;
rcount++;
}
}
}
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);
room.SetMaterial(19,4,0);
room.SetMaterial(19,5,0);
room.SetMaterial(19,6,0);
room = room.leftRoom;
room.SetMaterial(19,4,0);
room.SetMaterial(19,5,0);
room.SetMaterial(19,6,0);
room = null;
level.items.remove(this);
}
}
}
public FFButton(int X, int Y, Room r) {
super(X, Y, r, Color.white);
grabbable = false;
}
public void Animate() {
if (robots == null) {
robots = new GenericRobot[3];
int rcount = 0;
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])) {
room.SetMaterial(0, 4, 0);
room.SetMaterial(0, 5, 0);
room.SetMaterial(0, 6, 0);
room.SetMaterial(19, 4, 0);
room.SetMaterial(19, 5, 0);
room.SetMaterial(19, 6, 0);
room = room.leftRoom;
room.SetMaterial(19, 4, 0);
room.SetMaterial(19, 5, 0);
room.SetMaterial(19, 6, 0);
room = null;
level.items.remove(this);
}
}
}
}
}
}

View File

@@ -11,64 +11,63 @@ 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;
target = t;
width=28; height=26;
GenerateIcons();
}
public Factory(int X, int Y, Room r, Item t) {
x = X;
y = Y;
room = r;
target = t;
width = 28;
height = 26;
GenerateIcons();
}
public void GenerateIcons()
{
target.GenerateIcons();
target.Decorate();
width = Math.max(((BufferedImage)target.currentIcon).getWidth()+8,18);
height = Math.max(((BufferedImage)target.currentIcon).getHeight()+8, 18);
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.drawRect(0,0,width, height);
g.drawRect(1,1,width-2, height-2);
g.drawImage(target.currentIcon,
width/2-target.width/2 - target.orgX,
height/2-target.height/2 - target.orgY,
level);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
target.GenerateIcons();
target.Decorate();
width = Math.max(((BufferedImage) target.currentIcon).getWidth() + 8, 18);
height = Math.max(((BufferedImage) target.currentIcon).getHeight() + 8, 18);
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.drawRect(0, 0, width, height);
g.drawRect(1, 1, width - 2, height - 2);
g.drawImage(target.currentIcon,
width / 2 - target.width / 2 - target.orgX,
height / 2 - target.height / 2 - target.orgY,
level);
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
Item item;
if (target instanceof PrototypeChip)
item = new PrototypeChip(0,0,null);
else
item = (Item) target.clone();
item.GenerateIcons();
item.x = (560 - item.width)/2;
item.y = (384 - item.height)/2;
item.room = room;
level.items.addElement(item);
level.PlaySound(room,Level.CHARGESOUND);
return false;
}
public boolean CanBePickedUp(Item i) {
Item item;
if (target instanceof PrototypeChip) {
item = new PrototypeChip(0, 0, null);
}
else {
item = (Item) target.clone();
}
item.GenerateIcons();
item.x = (560 - item.width) / 2;
item.y = (384 - item.height) / 2;
item.room = room;
level.items.addElement(item);
level.PlaySound(room, Level.CHARGESOUND);
return false;
}
}

View File

@@ -1,113 +1,104 @@
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
{
int behavior=0;
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;
room =r;
width=52; height=38;
grabbable=false;
GenerateIcons();
}
public GateKeeper(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 52;
height = 38;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(4,0,12,14);
g.fillRect(0,2,20,10);
g.fillRect(20,4,8,6);
g.fillRect(24,8,24,20);
g.fillRect(48,12,4,16);
g.fillRect(32,6,12,32);
g.fillRect(28,34,20,2);
g.fillRect(24,36,28,2);
g.setColor(Color.black);
g.fillRect(8,2,4,10);
g.fillRect(4,4,12,6);
g.fillRect(0,6,4,2);
g.fillRect(20,6,4,2);
g.fillRect(28,18,4,2);
g.fillRect(32,16,4,2);
g.fillRect(36,18,4,2);
g.fillRect(40,16,4,2);
g.fillRect(44,18,4,2);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(4, 0, 12, 14);
g.fillRect(0, 2, 20, 10);
g.fillRect(20, 4, 8, 6);
g.fillRect(24, 8, 24, 20);
g.fillRect(48, 12, 4, 16);
g.fillRect(32, 6, 12, 32);
g.fillRect(28, 34, 20, 2);
g.fillRect(24, 36, 28, 2);
g.setColor(Color.black);
g.fillRect(8, 2, 4, 10);
g.fillRect(4, 4, 12, 6);
g.fillRect(0, 6, 4, 2);
g.fillRect(20, 6, 4, 2);
g.fillRect(28, 18, 4, 2);
g.fillRect(32, 16, 4, 2);
g.fillRect(36, 18, 4, 2);
g.fillRect(40, 16, 4, 2);
g.fillRect(44, 18, 4, 2);
currentIcon = icons[0].getImage();
}
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 (y != goToY)
{
int diff = Math.abs(goToY - y);
int dir = diff / (goToY - y);
if (diff > 2) diff = 2;
MoveDown(diff * dir);
}
}
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"))
ss = (StormShield) item;
}
if (ss!=null)
{
ss.SetRoom(null); // Removes wires
level.items.removeElement(ss);
}
room.SetMaterial(7,7,21);
}
}
}
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 (y != goToY) {
int diff = Math.abs(goToY - y);
int dir = diff / (goToY - y);
if (diff > 2) {
diff = 2;
}
MoveDown(diff * dir);
}
}
else {
behavior = 0;
level.items.removeElement(carrying);
carrying = null;
StormShield ss = null;
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) {
ss.SetRoom(null); // Removes wires
level.items.removeElement(ss);
}
room.SetMaterial(7, 7, 21);
}
}
}
}

View File

@@ -1,464 +1,466 @@
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
{
public Device devices[] = new Device[10];
public boolean topBumper;
public boolean bottomBumper;
public boolean leftBumper;
public boolean rightBumper;
public boolean thrusterPower;
public boolean topThruster;
public boolean bottomThruster;
public boolean leftThruster;
public boolean rightThruster;
public boolean antenna;
public boolean broadcasting;
public int grabber; // use Port.ROT_ for rotations.
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[];
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public GenericRobot(int X, int Y, Room r, Color c)
{
x=X; y=Y; room=r;
grabber = 1;
charge=100000;
color = c;
public class GenericRobot extends Item {
public Device devices[] = new Device[10];
public boolean topBumper;
public boolean bottomBumper;
public boolean leftBumper;
public boolean rightBumper;
public boolean thrusterPower;
public boolean topThruster;
public boolean bottomThruster;
public boolean leftThruster;
public boolean rightThruster;
public boolean antenna;
public boolean broadcasting;
public int grabber; // use Port.ROT_ for rotations.
private Color color;
public boolean periscope;
private int periscopeAnimation;
private transient boolean oldTopBumper;
private transient boolean oldBottomBumper;
private transient boolean oldLeftBumper;
private transient boolean oldRightBumper;
private transient ImageIcon[] images;
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 = {
{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},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,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,0,0},
{0,0,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,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{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);
Material perUp = Material.FindSimiliar(new PeriscopeUp());
int perUpIndex = level.materials.indexOf(perUp);
Material perDown = Material.FindSimiliar(new PeriscopeDown());
int perDownIndex = level.materials.indexOf(perDown);
Material battIn = Material.FindSimiliar(new BatteryIn());
int battInIndex = level.materials.indexOf(battIn);
Material battOut = Material.FindSimiliar(new BatteryOut());
int battOutIndex = level.materials.indexOf(battOut);
((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;
InternalRoom.RoomArray[2][17] = perUpIndex;
InternalRoom.RoomArray[2][16] = perDownIndex;
InternalRoom.RoomArray[3][17] = perDownIndex;
InternalRoom.RoomArray[9][2] = battOutIndex;
InternalRoom.RoomArray[9][3] = battInIndex;
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
InternalRoom.upRoom = null;
InternalRoom.downRoom = null;
InternalRoom.leftRoom = null;
InternalRoom.rightRoom = null;
InternalRoom = new Room();
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},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
{1, 1, 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, 0, 0},
{0, 0, 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, 1, 1},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{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}
};
Material mat1 = Material.FindSimiliar(new Material(color, false, true));
int mat1Index = level.materials.indexOf(mat1);
Material perUp = Material.FindSimiliar(new PeriscopeUp());
int perUpIndex = level.materials.indexOf(perUp);
Material perDown = Material.FindSimiliar(new PeriscopeDown());
int perDownIndex = level.materials.indexOf(perDown);
Material battIn = Material.FindSimiliar(new BatteryIn());
int battInIndex = level.materials.indexOf(battIn);
Material battOut = Material.FindSimiliar(new BatteryOut());
int battOutIndex = level.materials.indexOf(battOut);
((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;
}
}
}
InternalRoom.RoomArray[2][17] = perUpIndex;
InternalRoom.RoomArray[2][16] = perDownIndex;
InternalRoom.RoomArray[3][17] = perDownIndex;
InternalRoom.RoomArray[9][2] = battOutIndex;
InternalRoom.RoomArray[9][3] = battInIndex;
InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom);
InternalRoom.upRoom = null;
InternalRoom.downRoom = null;
InternalRoom.leftRoom = null;
InternalRoom.rightRoom = null;
// leftPortal = new Rectangle (-14,0,8,10);
// rightPortal = new Rectangle (36,0,8,10);
// upPortal = new Rectangle (12,-18,12,8);
// downPortal = new Rectangle (10,24,12,8);
//
leftPortal = new Rectangle (-28,0,8,14);
rightPortal = new Rectangle (50,0,8,14);
upPortal = new Rectangle (10,-30,12,18);
downPortal = new Rectangle (10,24,12,18);
level.items.addElement(new PowerSwitch(17*28-4,9*32-4,InternalRoom));
leftPortal = new Rectangle(-28, 0, 8, 14);
rightPortal = new Rectangle(50, 0, 8, 14);
upPortal = new Rectangle(10, -30, 12, 18);
downPortal = new Rectangle(10, 24, 12, 18);
GenerateIcons();
Animate();
}
level.items.addElement(new PowerSwitch(17 * 28 - 4, 9 * 32 - 4, InternalRoom));
public void GenerateIcons()
{
GenerateIcons();
Animate();
}
public void GenerateIcons() {
// orgX = 14; orgY = 24;
// width = 56; height = 42;
orgX = 14; orgY = 24;
width = 56; height = 44;
icons = new ImageIcon[1];
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));
currentIcon = icons[0].getImage();
((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++)
{
icons[0] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage();
((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++) {
// 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
{
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
images[a] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = images[a].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
// g2.clearRect(0,0,122,92);
g2.clearRect(0,0,84,84);
switch (a)
{
case 0: // Robot Body
{
g.setColor(color);
int X=orgX+18;
int Y=orgY+6;
g.fillRect(X, Y, 22,32);
g.fillRect(X-4, Y+2, 30,28);
g.fillRect(X-8, Y+4, 38,24);
g.fillRect(X-12, Y+6, 46,20);
}
break;
g2.clearRect(0, 0, 84, 84);
case 1: // Grabber Up
g.setColor(Color.white);
{
int X=orgX+40;
int Y=orgY-16;
g.fillRect(X+0,Y+20,20,4);
g.fillRect(X+16,Y+16,4,8);
g.fillRect(X+12,Y+10,4,8);
g.fillRect(X+20,Y+10,4,8);
g.fillRect(X+12,Y+12,12,2);
g.fillRect(X+8,Y+2,4,10);
g.fillRect(X+24,Y+2,4,10);
g.fillRect(X+12,Y+0,4,4);
g.fillRect(X+20,Y+0,4,4);
break;
}
case 2: // Grabber Right
g.setColor(Color.white);
{
int X=orgX+46;
int Y=orgY+34;
g.fillRect(X+0,Y+0,4,10);
g.fillRect(X+0,Y+4,12,2);
g.fillRect(X+0,Y+8,12,2);
g.fillRect(X+8,Y+2,4,10);
g.fillRect(X+12,Y+0,4,4);
g.fillRect(X+12,Y+10,4,4);
g.fillRect(X+12,Y+0,12,2);
g.fillRect(X+12,Y+12,12,2);
g.fillRect(X+16,Y+0,4,4);
g.fillRect(X+16,Y+10,4,4);
g.fillRect(X+20,Y+2,4,4);
g.fillRect(X+20,Y+8,4,4);
}
break;
case 3: // Grabber Down
g.setColor(Color.white);
{
int X=orgX-10;
int Y=orgY+32;
g.fillRect(X+8,Y+0,12,4);
g.fillRect(X+8,Y+0,4,10);
g.fillRect(X+4,Y+8,4,8);
g.fillRect(X+12,Y+8,4,8);
g.fillRect(X+4,Y+12,12,2);
g.fillRect(X+0,Y+14,4,10);
g.fillRect(X+16,Y+14,4,10);
g.fillRect(X+4,Y+22,4,4);
g.fillRect(X+12,Y+22,4,4);
}
break;
case 4: // Grabber Left
g.setColor(Color.white);
{
int X=orgX-16;
int Y=orgY-6;
g.fillRect(X+24,Y+4,4,10);
g.fillRect(X+16,Y+4,12,2);
g.fillRect(X+16,Y+8,12,2);
g.fillRect(X+16,Y+2,4,10);
g.fillRect(X+12,Y+0,4,4);
g.fillRect(X+12,Y+10,4,4);
g.fillRect(X+4,Y+0,12,2);
g.fillRect(X+4,Y+12,12,2);
g.fillRect(X+4,Y+0,4,4);
g.fillRect(X+4,Y+10,4,4);
g.fillRect(X+0,Y+2,4,4);
g.fillRect(X+0,Y+8,4,4);
break;
}
switch (a) {
case 0: // Robot Body
{
g.setColor(color);
int X = orgX + 18;
int Y = orgY + 6;
g.fillRect(X, Y, 22, 32);
g.fillRect(X - 4, Y + 2, 30, 28);
g.fillRect(X - 8, Y + 4, 38, 24);
g.fillRect(X - 12, Y + 6, 46, 20);
}
break;
case 5: // Antenna Off
{
int X=orgX+14;
int Y=orgY-18;
g.setColor(Color.white);
g.fillRect(X,Y,12,6);
g.fillRect(X+4,Y+6,4,16);
}
break;
case 6: // Antenna On
{
int X=orgX+14;
int Y=orgY-18;
g.setColor(new Color(255,128,0));
g.fillRect(X,Y,12,6);
g.fillRect(X+4,Y+6,4,16);
}
break;
case 1: // Grabber Up
g.setColor(Color.white);
{
int X = orgX + 40;
int Y = orgY - 16;
g.fillRect(X + 0, Y + 20, 20, 4);
g.fillRect(X + 16, Y + 16, 4, 8);
g.fillRect(X + 12, Y + 10, 4, 8);
g.fillRect(X + 20, Y + 10, 4, 8);
g.fillRect(X + 12, Y + 12, 12, 2);
g.fillRect(X + 8, Y + 2, 4, 10);
g.fillRect(X + 24, Y + 2, 4, 10);
g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X + 20, Y + 0, 4, 4);
break;
}
case 2: // Grabber Right
g.setColor(Color.white);
{
int X = orgX + 46;
int Y = orgY + 34;
g.fillRect(X + 0, Y + 0, 4, 10);
g.fillRect(X + 0, Y + 4, 12, 2);
g.fillRect(X + 0, Y + 8, 12, 2);
g.fillRect(X + 8, Y + 2, 4, 10);
g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X + 12, Y + 10, 4, 4);
g.fillRect(X + 12, Y + 0, 12, 2);
g.fillRect(X + 12, Y + 12, 12, 2);
g.fillRect(X + 16, Y + 0, 4, 4);
g.fillRect(X + 16, Y + 10, 4, 4);
g.fillRect(X + 20, Y + 2, 4, 4);
g.fillRect(X + 20, Y + 8, 4, 4);
}
break;
case 3: // Grabber Down
g.setColor(Color.white);
{
int X = orgX - 10;
int Y = orgY + 32;
g.fillRect(X + 8, Y + 0, 12, 4);
g.fillRect(X + 8, Y + 0, 4, 10);
g.fillRect(X + 4, Y + 8, 4, 8);
g.fillRect(X + 12, Y + 8, 4, 8);
g.fillRect(X + 4, Y + 12, 12, 2);
g.fillRect(X + 0, Y + 14, 4, 10);
g.fillRect(X + 16, Y + 14, 4, 10);
g.fillRect(X + 4, Y + 22, 4, 4);
g.fillRect(X + 12, Y + 22, 4, 4);
}
break;
case 4: // Grabber Left
g.setColor(Color.white);
{
int X = orgX - 16;
int Y = orgY - 6;
g.fillRect(X + 24, Y + 4, 4, 10);
g.fillRect(X + 16, Y + 4, 12, 2);
g.fillRect(X + 16, Y + 8, 12, 2);
g.fillRect(X + 16, Y + 2, 4, 10);
g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X + 12, Y + 10, 4, 4);
g.fillRect(X + 4, Y + 0, 12, 2);
g.fillRect(X + 4, Y + 12, 12, 2);
g.fillRect(X + 4, Y + 0, 4, 4);
g.fillRect(X + 4, Y + 10, 4, 4);
g.fillRect(X + 0, Y + 2, 4, 4);
g.fillRect(X + 0, Y + 8, 4, 4);
break;
}
case 7: // Periscope Left
{
int X = orgX+40;
int Y = orgY+5;
g.fillRect(X-10,Y-24,6,14);
g.fillRect(X-6,Y-22,12,10);
g.fillRect(X+6,Y-20,4,6);
g.fillRect(X+2,Y-12,4,18);
}
break;
case 8: // Periscope Straight
{
int X = orgX+40;
int Y = orgY+5;
g.fillRect(X-2,Y-24,12,2);
g.fillRect(X-2,Y-14,12,2);
g.fillRect(X-6,Y-22,4,2);
g.fillRect(X-6,Y-16,4,2);
g.fillRect(X+10,Y-22,4,2);
g.fillRect(X+10,Y-16,4,2);
g.fillRect(X-10,Y-20,4,4);
g.fillRect(X+2,Y-20,4,4);
g.fillRect(X+14,Y-20,4,4);
g.fillRect(X+2,Y-12,4,18);
}
break;
case 9: // Periscope Right
{
int X = orgX+40;
int Y = orgY+5;
g.fillRect(X+14,Y-24,6,14);
g.fillRect(X+2,Y-22,12,10);
g.fillRect(X-2,Y-20,4,6);
g.fillRect(X+2,Y-12,4,18);
}
break;
}
}
}
case 5: // Antenna Off
{
int X = orgX + 14;
int Y = orgY - 18;
g.setColor(Color.white);
g.fillRect(X, Y, 12, 6);
g.fillRect(X + 4, Y + 6, 4, 16);
}
break;
case 6: // Antenna On
{
int X = orgX + 14;
int Y = orgY - 18;
g.setColor(new Color(255, 128, 0));
g.fillRect(X, Y, 12, 6);
g.fillRect(X + 4, Y + 6, 4, 16);
}
break;
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 && thrusterPower)
{
Dimension d = GetXY();
int X = d.width;
int Y = d.height;
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)
{
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)
{
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)
{
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;
}
case 7: // Periscope Left
{
int X = orgX + 40;
int Y = orgY + 5;
g.fillRect(X - 10, Y - 24, 6, 14);
g.fillRect(X - 6, Y - 22, 12, 10);
g.fillRect(X + 6, Y - 20, 4, 6);
g.fillRect(X + 2, Y - 12, 4, 18);
}
break;
case 8: // Periscope Straight
{
int X = orgX + 40;
int Y = orgY + 5;
g.fillRect(X - 2, Y - 24, 12, 2);
g.fillRect(X - 2, Y - 14, 12, 2);
g.fillRect(X - 6, Y - 22, 4, 2);
g.fillRect(X - 6, Y - 16, 4, 2);
g.fillRect(X + 10, Y - 22, 4, 2);
g.fillRect(X + 10, Y - 16, 4, 2);
g.fillRect(X - 10, Y - 20, 4, 4);
g.fillRect(X + 2, Y - 20, 4, 4);
g.fillRect(X + 14, Y - 20, 4, 4);
g.fillRect(X + 2, Y - 12, 4, 18);
}
break;
case 9: // Periscope Right
{
int X = orgX + 40;
int Y = orgY + 5;
g.fillRect(X + 14, Y - 24, 6, 14);
g.fillRect(X + 2, Y - 22, 12, 10);
g.fillRect(X - 2, Y - 20, 4, 6);
g.fillRect(X + 2, Y - 12, 4, 18);
}
break;
}
}
}
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 && thrusterPower) {
Dimension d = GetXY();
int X = d.width;
int Y = d.height;
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) {
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) {
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) {
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;
}
}
// Draw Antenna sparks around Broadcasting Antenna
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,
level.random.nextInt(9)-4,
room));
}
// Make sounds
if (topBumper)
if (oldTopBumper != topBumper)
level.PlaySound(room, Level.BUMPSOUND);
if (bottomBumper)
if (oldBottomBumper != bottomBumper)
level.PlaySound(room, Level.BUMPSOUND);
if (rightBumper)
if (oldRightBumper != rightBumper)
level.PlaySound(room, Level.BUMPSOUND);
if (leftBumper)
if (oldLeftBumper != leftBumper)
level.PlaySound(room, Level.BUMPSOUND);
if (broadcasting && level.electricity)
level.PlaySound(room, Level.BEEPSOUND);
oldTopBumper = topBumper;
oldBottomBumper = bottomBumper;
oldRightBumper = rightBumper;
oldLeftBumper = leftBumper;
}
// Draw Antenna sparks around Broadcasting Antenna
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,
level.random.nextInt(9) - 4,
room));
}
public void Decorate()
{
// Paint background
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,123,92);
// Paint Robot Body
g.drawImage(images[0].getImage(), 0, 0, level);
// Make sounds
if (topBumper && !oldTopBumper) {
level.PlaySound(room, Level.BUMPSOUND);
}
if (bottomBumper && !oldBottomBumper) {
level.PlaySound(room, Level.BUMPSOUND);
}
if (rightBumper && !oldRightBumper) {
level.PlaySound(room, Level.BUMPSOUND);
}
if (leftBumper && !oldLeftBumper) {
level.PlaySound(room, Level.BUMPSOUND);
}
if (broadcasting && level.electricity) {
level.PlaySound(room, Level.BEEPSOUND);
}
oldTopBumper = topBumper;
oldBottomBumper = bottomBumper;
oldRightBumper = rightBumper;
oldLeftBumper = leftBumper;
// Draw Bumpers
if (topBumper)
g.setColor(new Color(255,128,0));
else
g.setColor(Color.white);
g.fillRect(32,24,22,2);
if (bottomBumper)
g.setColor(new Color(255,128,0));
else
g.setColor(Color.white);
g.fillRect(32,66,22,2);
if (leftBumper)
g.setColor(new Color(255,128,0));
else
g.setColor(Color.white);
g.fillRect(12,36,4,20);
}
if (rightBumper)
g.setColor(new Color(255,128,0));
else
g.setColor(Color.white);
g.fillRect(70,36,4,20);
// Draw Antenna
if (antenna)
g.drawImage(images[6].getImage(), 0, 0, level);
else
g.drawImage(images[5].getImage(), 0, 0, level);
// Draw Grabber
g.setColor(Color.white);
switch (grabber)
{
case Port.ROT_UP:
g.drawImage(images[1].getImage(), 0, 0, level);
break;
case Port.ROT_RIGHT:
g.drawImage(images[2].getImage(), 0, 0, level);
break;
case Port.ROT_DOWN:
g.drawImage(images[3].getImage(), 0, 0, level);
break;
case Port.ROT_LEFT:
g.drawImage(images[4].getImage(), 0, 0, level);
break;
}
public void Decorate() {
// Paint background
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, 123, 92);
// Draw Periscope
// Paint Robot Body
g.drawImage(images[0].getImage(), 0, 0, level);
// Draw Bumpers
if (topBumper) {
g.setColor(new Color(255, 128, 0));
}
else {
g.setColor(Color.white);
}
g.fillRect(32, 24, 22, 2);
if (bottomBumper) {
g.setColor(new Color(255, 128, 0));
}
else {
g.setColor(Color.white);
}
g.fillRect(32, 66, 22, 2);
if (leftBumper) {
g.setColor(new Color(255, 128, 0));
}
else {
g.setColor(Color.white);
}
g.fillRect(12, 36, 4, 20);
if (rightBumper) {
g.setColor(new Color(255, 128, 0));
}
else {
g.setColor(Color.white);
}
g.fillRect(70, 36, 4, 20);
// Draw Antenna
if (antenna) {
g.drawImage(images[6].getImage(), 0, 0, level);
}
else {
g.drawImage(images[5].getImage(), 0, 0, level);
}
// Draw Grabber
g.setColor(Color.white);
switch (grabber) {
case Port.ROT_UP:
g.drawImage(images[1].getImage(), 0, 0, level);
break;
case Port.ROT_RIGHT:
g.drawImage(images[2].getImage(), 0, 0, level);
break;
case Port.ROT_DOWN:
g.drawImage(images[3].getImage(), 0, 0, level);
break;
case Port.ROT_LEFT:
g.drawImage(images[4].getImage(), 0, 0, level);
break;
}
// Draw Periscope
// if (periscope)
if (level.currentViewer == this)
{
periscopeAnimation ++;
if (periscopeAnimation == 32) periscopeAnimation =0;
if (periscopeAnimation <8)
g.drawImage(images[7].getImage(), 0, 0, level);
if ((periscopeAnimation >=8 && periscopeAnimation <16)
|| periscopeAnimation >=24)
g.drawImage(images[8].getImage(), 0, 0, level);
if (periscopeAnimation >=16 && periscopeAnimation <24)
g.drawImage(images[9].getImage(), 0, 0, level);
}
if (level.currentViewer == this) {
periscopeAnimation++;
if (periscopeAnimation == 32) {
periscopeAnimation = 0;
}
if (periscopeAnimation < 8) {
g.drawImage(images[7].getImage(), 0, 0, level);
}
if ((periscopeAnimation >= 8 && periscopeAnimation < 16)
|| periscopeAnimation >= 24) {
g.drawImage(images[8].getImage(), 0, 0, level);
}
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);
@@ -468,22 +470,17 @@ public void Decorate()
// 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 void Erase()
{
super.Erase();
devices = null;
}
public boolean CanBePickedUp(Item item) {
return !item.getClass().toString().endsWith("Robot") && super.CanBePickedUp(item);
}
public void Erase() {
super.Erase();
devices = null;
}
}

View File

@@ -11,183 +11,182 @@ 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;
grabbable = false;
GenerateIcons();
}
public Ghost(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
robot = new Item[4];
icons = new ImageIcon[4];
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));
icons[3]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
for (int a=0; a<4; a++)
{
try
{
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.red);
g.fillArc(0,0,28,32,0,180);
g.fillRect(0,16,28,16);
g.setColor(Color.white);
g.fillOval(4,8,8,8);
g.fillOval(16,8,8,8);
g.setColor(Color.black);
switch(a)
{
case 0: // Right
g.fillOval(9,10,4,4);
g.fillOval(21,10,4,4);
break;
case 1: // Down
g.fillOval(7,12,4,4);
g.fillOval(19,12,4,4);
break;
case 2: // Left
g.fillOval(4,10,4,4);
g.fillOval(16,10,4,4);
break;
case 3: // Up
g.fillOval(7,8,4,4);
g.fillOval(19,8,4,4);
break;
}
}
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
robot = new Item[4];
icons = new ImageIcon[4];
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));
icons[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
for (int a = 0; a < 4; a++) {
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.red);
g.fillArc(0, 0, 28, 32, 0, 180);
g.fillRect(0, 16, 28, 16);
g.setColor(Color.white);
g.fillOval(4, 8, 8, 8);
g.fillOval(16, 8, 8, 8);
g.setColor(Color.black);
switch (a) {
case 0: // Right
g.fillOval(9, 10, 4, 4);
g.fillOval(21, 10, 4, 4);
break;
case 1: // Down
g.fillOval(7, 12, 4, 4);
g.fillOval(19, 12, 4, 4);
break;
case 2: // Left
g.fillOval(4, 10, 4, 4);
g.fillOval(16, 10, 4, 4);
break;
case 3: // Up
g.fillOval(7, 8, 4, 4);
g.fillOval(19, 8, 4, 4);
break;
}
}
currentIcon = icons[0].getImage();
}
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
// heads in that direction. Robots that are hit are put in the
// penalty box and drained of energy. If no robot is found it moves
// in a random direction.
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
// heads in that direction. Robots that are hit are put in the
// penalty box and drained of energy. If no robot is found it moves
// in a random direction.
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)
{
robot[rcounter] = item;
rcounter++;
}
}
searched=true;
}
boolean flag = false;
if ( ((x==42) || (x==154) || (x==266) || (x==378))
&& ( (y==48) || (y==176) || (y==304)) )
flag=true;
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))
{
decision=true;
if (Math.abs(dx)<56)
{
if (dy>0)
animationState=1;
else
animationState=3;
}
else
{
if (dx>0)
animationState=0;
else
animationState=2;
}
}
}
}
}
if (!decision)
{
boolean good;
int backwards = (animationState+2)%4;
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;
}
while (!good);
}
}
switch (animationState)
{
case 0: // Right
MoveRight(4);
break;
case 1: // Down
MoveDown(4);
break;
case 2: // Left
MoveLeft(4);
break;
case 3: // Up
MoveUp(4);
break;
}
currentIcon = icons[animationState].getImage();
if (!searched) {
int rcounter = 0;
for (int a = 0; a < level.items.size(); a++) {
Item item = level.items.elementAt(a);
if (item instanceof GenericRobot) {
robot[rcounter] = item;
rcounter++;
}
}
searched = true;
}
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;
robot[a].y = 32;
}
}
boolean flag = false;
if (((x == 42) || (x == 154) || (x == 266) || (x == 378))
&& ((y == 48) || (y == 176) || (y == 304))) {
flag = true;
}
if (flag) {
boolean decision = false;
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) {
animationState = 1;
}
else {
animationState = 3;
}
}
else {
if (dx > 0) {
animationState = 0;
}
else {
animationState = 2;
}
}
}
}
}
}
}
if (!decision) {
boolean good;
int backwards = (animationState + 2) % 4;
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;
}
}
while (!good);
}
}
switch (animationState) {
case 0: // Right
MoveRight(4);
break;
case 1: // Down
MoveDown(4);
break;
case 2: // Left
MoveLeft(4);
break;
case 3: // Up
MoveUp(4);
break;
}
currentIcon = icons[animationState].getImage();
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;
robot[a].y = 32;
}
}
}
}
}

View File

@@ -1,93 +1,83 @@
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
{
// Handle used to pull sliding wall
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public Handle(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=12;
GenerateIcons();
}
public class Handle extends Item {
// Handle used to pull sliding wall
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(0,4,16,4);
g.fillRect(16,2,12,8);
g.fillRect(20,0,4,12);
currentIcon = icons[0].getImage();
}
public Handle(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 12;
GenerateIcons();
}
public boolean CanBePickedUp(Item item)
{
if (item != level.player) return false;
PicksUp(item);
level.player = this;
return false;
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(0, 4, 16, 4);
g.fillRect(16, 2, 12, 8);
g.fillRect(20, 0, 4, 12);
currentIcon = icons[0].getImage();
}
public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_RIGHT)
{
if (x<15*28)
{
room.SetMaterial(x/28-12, 4, 0);
MoveRight(28);
room.SetMaterial(x/28-1, 4, 8);
}
}
public boolean CanBePickedUp(Item item) {
if (item != level.player) {
return false;
}
PicksUp(item);
level.player = this;
return false;
}
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);
}
}
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == e.VK_RIGHT) {
if (x < 15 * 28) {
room.SetMaterial(x / 28 - 12, 4, 0);
MoveRight(28);
room.SetMaterial(x / 28 - 1, 4, 8);
}
}
if (e.getKeyCode() == e.VK_SPACE)
{
level.player=carrying;
Drops();
room.SetMaterial(1, 4, 8);
room.SetMaterial(2, 4, 8);
room.SetMaterial(13, 4, 0);
room.SetMaterial(14, 4, 0);
x=13*28;
}
return false;
}
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);
}
}
}
if (e.getKeyCode() == e.VK_SPACE) {
level.player = carrying;
Drops();
room.SetMaterial(1, 4, 8);
room.SetMaterial(2, 4, 8);
room.SetMaterial(13, 4, 0);
room.SetMaterial(14, 4, 0);
x = 13 * 28;
}
return false;
}
}

View File

@@ -9,42 +9,40 @@ 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;
color = c;
editable=true;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(color);
int[] xp = { 7, 21, 27, 21, 7, 0};
int[] yp = { 0, 0, 14, 27, 27, 14};
g.fillPolygon(xp,yp,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(color);
int[] xp = {7, 21, 27, 21, 7, 0};
int[] yp = {0, 0, 14, 27, 27, 14};
g.fillPolygon(xp, yp, 6);
currentIcon = icons[0].getImage();
}
}

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;
room = r;
width=0; height=0;
grabbable=false;
}
public class HiddenCamera extends Item {
public HiddenCamera(Room r) {
x = 0;
y = 0;
room = r;
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,43 +9,42 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class Key extends Item
{
// Generic Key, defined by it's color.
public class Key extends Item {
// Generic Key, defined by it's color.
public Color 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;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(color);
g.fillRect(0,0,6,8);
g.fillRect(0,2,26,2);
g.fillRect(0,4,22,2);
g.fillRect(16,6,2,2);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(color);
g.fillRect(0, 0, 6, 8);
g.fillRect(0, 2, 26, 2);
g.fillRect(0, 4, 22, 2);
g.fillRect(16, 6, 2, 2);
currentIcon = icons[0].getImage();
}
}
}

View File

@@ -9,44 +9,42 @@ 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;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(0,4,8,12);
g.fillRect(4,2,8,6);
g.fillRect(4,12,8,6);
g.fillRect(8,0,20,6);
g.fillRect(8,14,20,6);
g.setColor(Color.black);
g.fillRect(20,0,4,6);
g.fillRect(20,14,4,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(0, 4, 8, 12);
g.fillRect(4, 2, 8, 6);
g.fillRect(4, 12, 8, 6);
g.fillRect(8, 0, 20, 6);
g.fillRect(8, 14, 20, 6);
g.setColor(Color.black);
g.fillRect(20, 0, 4, 6);
g.fillRect(20, 14, 4, 6);
currentIcon = icons[0].getImage();
}
}

View File

@@ -10,66 +10,61 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster;
public class MasterRobot extends GenericRobot
{
private int scan;
public class MasterRobot extends GenericRobot {
private int scan;
public MasterRobot(int X, int Y, Room r)
{
super(X,Y,r,Color.blue);
scan=0;
Animate();
devices[0] = new Thruster(176,16,InternalRoom,Port.ROT_UP,Color.white);
devices[1] = new Thruster(476,128,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[2] = new Thruster(356,336,InternalRoom,Port.ROT_DOWN,Color.white);
devices[3] = new Thruster(32,236,InternalRoom,Port.ROT_LEFT,Color.white);
devices[4] = new Bumper(396,16,InternalRoom,Port.ROT_UP,Color.white);
devices[5] = new Bumper(480,256,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[6] = new Bumper(128,330,InternalRoom,Port.ROT_DOWN,Color.white);
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++)
level.items.addElement(devices[a]);
public MasterRobot(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
scan = 0;
Animate();
devices[0] = new Thruster(176, 16, InternalRoom, Port.ROT_UP, Color.white);
devices[1] = new Thruster(476, 128, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[2] = new Thruster(356, 336, InternalRoom, Port.ROT_DOWN, Color.white);
devices[3] = new Thruster(32, 236, InternalRoom, Port.ROT_LEFT, Color.white);
devices[4] = new Bumper(396, 16, InternalRoom, Port.ROT_UP, Color.white);
devices[5] = new Bumper(480, 256, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[6] = new Bumper(128, 330, InternalRoom, Port.ROT_DOWN, Color.white);
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++) {
level.items.addElement(devices[a]);
}
}
}
public void Decorate()
{
super.Decorate();
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g.setColor(Color.black);
g.fillRect(orgX+16,orgY+12,26,20);
g.setColor(new Color(255,128,0));
switch(scan)
{
case 0:
g.fillRect(orgX+28,orgY+18,2,8);
scan=1;
break;
case 1:
g.fillRect(orgX+24,orgY+16,10,12);
g.setColor(Color.black);
g.fillRect(orgX+26,orgY+18,6,8);
scan=2;
break;
case 2:
g.fillRect(orgX+20,orgY+14,18,16);
g.setColor(Color.black);
g.fillRect(orgX+22,orgY+16,14,12);
scan=0;
break;
}
}
public void Decorate() {
super.Decorate();
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g.setColor(Color.black);
g.fillRect(orgX + 16, orgY + 12, 26, 20);
g.setColor(new Color(255, 128, 0));
switch (scan) {
case 0:
g.fillRect(orgX + 28, orgY + 18, 2, 8);
scan = 1;
break;
case 1:
g.fillRect(orgX + 24, orgY + 16, 10, 12);
g.setColor(Color.black);
g.fillRect(orgX + 26, orgY + 18, 6, 8);
scan = 2;
break;
case 2:
g.fillRect(orgX + 20, orgY + 14, 18, 16);
g.setColor(Color.black);
g.fillRect(orgX + 22, orgY + 16, 14, 12);
scan = 0;
break;
}
}
}

View File

@@ -10,116 +10,114 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.decorations.TextBox;
public class MazeControl extends Item
{
static int mazeWidth=4;
static int mazeHeight=2;
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 class MazeControl extends Item {
static int mazeWidth = 4;
static int mazeHeight = 2;
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;
room = r;
width=26; height=26;
direction = dir;
GenerateIcons();
}
public MazeControl(int X, int Y, Room r, int dir) {
x = X;
y = Y;
room = r;
width = 26;
height = 26;
direction = dir;
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
switch(direction)
{
case DIR_UP:
g.fillRect(12,0,2,2);
g.fillRect(10,2,6,2);
g.fillRect(8,4,10,2);
g.fillRect(6,6,14,2);
g.fillRect(4,8,18,2);
g.fillRect(2,10,22,2);
g.fillRect(0,12,26,2);
g.fillRect(10,14,6,12);
break;
case DIR_RIGHT:
g.fillRect(24,12,2,2);
g.fillRect(22,10,2,6);
g.fillRect(20,8,2,10);
g.fillRect(18,6,2,14);
g.fillRect(16,4,2,18);
g.fillRect(14,2,2,22);
g.fillRect(12,0,2,26);
g.fillRect(0,10,12,6);
break;
case DIR_DOWN:
g.fillRect(12,24,2,2);
g.fillRect(10,22,6,2);
g.fillRect(8,20,10,2);
g.fillRect(6,18,14,2);
g.fillRect(4,16,18,2);
g.fillRect(2,14,22,2);
g.fillRect(0,12,26,2);
g.fillRect(10,0,6,12);
break;
case DIR_LEFT:
g.fillRect(0,12,2,2);
g.fillRect(2,10,2,6);
g.fillRect(4,8,2,10);
g.fillRect(6,6,2,14);
g.fillRect(8,4,2,18);
g.fillRect(10,2,2,22);
g.fillRect(12,0,2,26);
g.fillRect(14,10,12,6);
break;
}
currentIcon = icons[0].getImage();
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
switch (direction) {
case DIR_UP:
g.fillRect(12, 0, 2, 2);
g.fillRect(10, 2, 6, 2);
g.fillRect(8, 4, 10, 2);
g.fillRect(6, 6, 14, 2);
g.fillRect(4, 8, 18, 2);
g.fillRect(2, 10, 22, 2);
g.fillRect(0, 12, 26, 2);
g.fillRect(10, 14, 6, 12);
break;
case DIR_RIGHT:
g.fillRect(24, 12, 2, 2);
g.fillRect(22, 10, 2, 6);
g.fillRect(20, 8, 2, 10);
g.fillRect(18, 6, 2, 14);
g.fillRect(16, 4, 2, 18);
g.fillRect(14, 2, 2, 22);
g.fillRect(12, 0, 2, 26);
g.fillRect(0, 10, 12, 6);
break;
case DIR_DOWN:
g.fillRect(12, 24, 2, 2);
g.fillRect(10, 22, 6, 2);
g.fillRect(8, 20, 10, 2);
g.fillRect(6, 18, 14, 2);
g.fillRect(4, 16, 18, 2);
g.fillRect(2, 14, 22, 2);
g.fillRect(0, 12, 26, 2);
g.fillRect(10, 0, 6, 12);
break;
case DIR_LEFT:
g.fillRect(0, 12, 2, 2);
g.fillRect(2, 10, 2, 6);
g.fillRect(4, 8, 2, 10);
g.fillRect(6, 6, 2, 14);
g.fillRect(8, 4, 2, 18);
g.fillRect(10, 2, 2, 22);
g.fillRect(12, 0, 2, 26);
g.fillRect(14, 10, 12, 6);
break;
}
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
switch (direction)
{
case DIR_UP:
if (mazeHeight==1) return false;
mazeHeight--;
break;
case DIR_DOWN:
mazeHeight++;
break;
case DIR_LEFT:
if (mazeWidth==1) return false;
mazeWidth--;
break;
case DIR_RIGHT:
mazeWidth++;
break;
}
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
tb.textString = mazeWidth + "x" + mazeHeight;
tb.x = (560 - 12*tb.textString.length())/2;
return false;
}
public boolean CanBePickedUp(Item item) {
switch (direction) {
case DIR_UP:
if (mazeHeight == 1) {
return false;
}
mazeHeight--;
break;
case DIR_DOWN:
mazeHeight++;
break;
case DIR_LEFT:
if (mazeWidth == 1) {
return false;
}
mazeWidth--;
break;
case DIR_RIGHT:
mazeWidth++;
break;
}
TextBox tb = room.textBoxes.elementAt(1);
tb.textString = mazeWidth + "x" + mazeHeight;
tb.x = (560 - 12 * tb.textString.length()) / 2;
return false;
}
}

View File

@@ -1,100 +1,93 @@
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)
{
super(X,Y,r,Color.blue);
}
import java.awt.*;
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)
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)
{
level.rooms.removeElement(r);
a--;
}
}
mazeEntrance.downRoom = null;
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++)
newRoom.SetMaterial(a,0,3);
}
else
{
Room UpRoom = (Room) 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++)
newRoom.SetMaterial(a,11,3);
}
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);
LeftRoom.rightRoom = newRoom;
newRoom.leftRoom = LeftRoom;
}
if (X==MazeControl.mazeWidth-1)
{
for (int a=0; a<12; a++)
newRoom.SetMaterial(19,a,3);
}
if (X==0 && Y==0)
{
mazeEntrance.downRoom = newRoom;
newRoom.upRoom = mazeEntrance;
newRoom.SetMaterial(1,0,0);
}
}
return false;
}
public class MazeCreator extends Button {
public MazeCreator(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
}
public boolean CanBePickedUp(Item item) {
Room mazeEntrance = null;
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 = 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++) {
Room newRoom = new Room();
newRoom.editable = true;
newRoom.GenerateArray();
level.rooms.addElement(newRoom);
if (Y == 0) {
for (int a = 0; a < 20; a++) {
newRoom.SetMaterial(a, 0, 3);
}
}
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++) {
newRoom.SetMaterial(a, 11, 3);
}
}
if (X == 0) {
for (int a = 0; a < 12; a++) {
newRoom.SetMaterial(0, a, 3);
}
}
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++) {
newRoom.SetMaterial(19, a, 3);
}
}
if (X == 0 && Y == 0) {
if(mazeEntrance != null) {
mazeEntrance.downRoom = newRoom;
}
newRoom.upRoom = mazeEntrance;
newRoom.SetMaterial(1, 0, 0);
}
}
}
return false;
}
}

View File

@@ -3,36 +3,26 @@ 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()
{
super(Switch.ROT_DOWN);
}
public MazeLock() {
super(Switch.ROT_DOWN);
}
public void TouchedByItem(Item item)
{
if (paintbrush==null)
paintbrush = level.paintbrush;
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;
// }
level.paintbrush = paintbrush;
value = false;
}
}
public void TouchedByItem(Item item) {
if (paintbrush == null) {
paintbrush = level.paintbrush;
}
if (!value) {
level.paintbrush = null;
value = true;
}
else {
level.paintbrush = paintbrush;
value = false;
}
}
}

View File

@@ -9,87 +9,84 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class NotAButton extends Item
{
int animationState=0;
transient EnergyButton eb=null;
public class NotAButton extends Item {
int animationState = 0;
private transient EnergyButton eb = null;
public NotAButton(int X, int Y, Room r)
{
x=X; y=Y; room=r;
width=28; height=26;
grabbable = false;
GenerateIcons();
}
public NotAButton(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 26;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(8,0,12,26);
g.fillRect(4,2,20,22);
g.fillRect(0,4,28,18);
g.setColor(Color.black);
g.fillRect(8,6,12,14);
g.fillRect(4,8,20,10);
g.setColor(Color.white);
g.fillRect(12,10,4,6);
g.fillRect(8,10,12,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(8, 0, 12, 26);
g.fillRect(4, 2, 20, 22);
g.fillRect(0, 4, 28, 18);
g.setColor(Color.black);
g.fillRect(8, 6, 12, 14);
g.fillRect(4, 8, 20, 10);
g.setColor(Color.white);
g.fillRect(12, 10, 4, 6);
g.fillRect(8, 10, 12, 6);
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)
{
eb = (EnergyButton) item;
eb.nb = this;
}
}
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))
x+=dx;
if (y+dy>32 && y+dy<(11*32))
y+=dy;
if (animationState==1)
{
eb.x=x; eb.y=y;
eb.room = room;
room = null;
}
if (animationState==2)
{
room = eb.room;
eb.room = null;
}
if (animationState==50)
animationState=0;
}
}
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) {
animationState++;
int dx = level.random.nextInt(11) - 5;
int dy = level.random.nextInt(11) - 5;
if (x + dx > 28 && x + dx < (19 * 28)) {
x += dx;
}
if (y + dy > 32 && y + dy < (11 * 32)) {
y += dy;
}
if (animationState == 1) {
eb.x = x;
eb.y = y;
eb.room = room;
room = null;
}
if (animationState == 2) {
room = eb.room;
eb.room = null;
}
if (animationState == 50) {
animationState = 0;
}
}
}
}

View File

@@ -10,69 +10,70 @@ 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)
{
super(X,Y,r,new Color(255,128,0));
Animate();
devices[0] = new Thruster(176,16,InternalRoom,Port.ROT_UP,Color.white);
devices[1] = new Thruster(476,128,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[2] = new Thruster(356,336,InternalRoom,Port.ROT_DOWN,Color.white);
devices[3] = new Thruster(32,236,InternalRoom,Port.ROT_LEFT,Color.white);
devices[4] = new Bumper(396,16,InternalRoom,Port.ROT_UP,Color.white);
devices[5] = new Bumper(480,256,InternalRoom,Port.ROT_RIGHT,Color.white);
devices[6] = new Bumper(128,330,InternalRoom,Port.ROT_DOWN,Color.white);
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++)
level.items.addElement(devices[a]);
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);
devices[1] = new Thruster(476, 128, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[2] = new Thruster(356, 336, InternalRoom, Port.ROT_DOWN, Color.white);
devices[3] = new Thruster(32, 236, InternalRoom, Port.ROT_LEFT, Color.white);
devices[4] = new Bumper(396, 16, InternalRoom, Port.ROT_UP, Color.white);
devices[5] = new Bumper(480, 256, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[6] = new Bumper(128, 330, InternalRoom, Port.ROT_DOWN, Color.white);
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++) {
level.items.addElement(devices[a]);
}
}
}
public void Decorate()
{
super.Decorate();
Graphics g;
int cx, cy, cc;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g.setColor(Color.black);
g.fillRect(22,36,42,20);
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);
break;
case 1: g.setColor(Color.red);
break;
case 2: g.setColor(new Color(255,128,0));
break;
case 3: g.setColor(Color.yellow);
break;
case 4: g.setColor(Color.green);
break;
case 5: g.setColor(Color.blue);
break;
case 6: g.setColor(Color.magenta);
break;
}
g.fillRect(cx,cy,2,2);
}
}
public void Decorate() {
super.Decorate();
Graphics g;
int cx, cy, cc;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g.setColor(Color.black);
g.fillRect(22, 36, 42, 20);
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);
break;
case 1:
g.setColor(Color.red);
break;
case 2:
g.setColor(new Color(255, 128, 0));
break;
case 3:
g.setColor(Color.yellow);
break;
case 4:
g.setColor(Color.green);
break;
case 5:
g.setColor(Color.blue);
break;
case 6:
g.setColor(Color.magenta);
break;
}
g.fillRect(cx, cy, 2, 2);
}
}
}

View File

@@ -11,52 +11,49 @@ 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;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,12,26);
g.fillRect(4,2,20,22);
g.fillRect(0,4,28,18);
g.setColor(Color.black);
g.fillRect(8,6,12,14);
g.fillRect(4,8,20,10);
g.setColor(Color.blue);
g.fillRect(12,8,4,10);
g.fillRect(8,10,12,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 12, 26);
g.fillRect(4, 2, 20, 22);
g.fillRect(0, 4, 28, 18);
g.setColor(Color.black);
g.fillRect(8, 6, 12, 14);
g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue);
g.fillRect(12, 8, 4, 10);
g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
Prototype16Chip newPC = new Prototype16Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND);
return false;
}
public boolean CanBePickedUp(Item i) {
Prototype16Chip newPC = new Prototype16Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);
return false;
}
}

View File

@@ -11,53 +11,50 @@ 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;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,12,26);
g.fillRect(4,2,20,22);
g.fillRect(0,4,28,18);
g.setColor(Color.black);
g.fillRect(8,6,12,14);
g.fillRect(4,8,20,10);
g.setColor(Color.blue);
g.fillRect(12,8,4,10);
g.fillRect(8,10,12,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 12, 26);
g.fillRect(4, 2, 20, 22);
g.fillRect(0, 4, 28, 18);
g.setColor(Color.black);
g.fillRect(8, 6, 12, 14);
g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue);
g.fillRect(12, 8, 4, 10);
g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
Prototype32Chip newPC = new Prototype32Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND);
return false;
}
public boolean CanBePickedUp(Item i) {
Prototype32Chip newPC = new Prototype32Chip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);
return false;
}
}

View File

@@ -11,52 +11,49 @@ 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;
GenerateIcons();
}
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()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(8,0,12,26);
g.fillRect(4,2,20,22);
g.fillRect(0,4,28,18);
g.setColor(Color.black);
g.fillRect(8,6,12,14);
g.fillRect(4,8,20,10);
g.setColor(Color.blue);
g.fillRect(12,8,4,10);
g.fillRect(8,10,12,6);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(8, 0, 12, 26);
g.fillRect(4, 2, 20, 22);
g.fillRect(0, 4, 28, 18);
g.setColor(Color.black);
g.fillRect(8, 6, 12, 14);
g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue);
g.fillRect(12, 8, 4, 10);
g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item i)
{
PrototypeChip newPC = new PrototypeChip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND);
return false;
}
public boolean CanBePickedUp(Item i) {
PrototypeChip newPC = new PrototypeChip(228, 160, room);
level.items.addElement(newPC);
level.PlaySound(room, Level.CHARGESOUND);
return false;
}
}

View File

@@ -9,72 +9,67 @@ 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;
pelletCount ++;
}
public Pellet(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 28;
pelletCount++;
}
public void GenerateIcons()
{
if (!counted)
{
int index = level.items.indexOf(this);
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillOval(0,0,width,height);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
if (!counted) {
int index = level.items.indexOf(this);
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillOval(0, 0, width, height);
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
if (item instanceof GenericRobot)
{
level.items.removeElement(this);
pelletCount--;
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)
level.items.removeElement(i);
}
}
}
return false;
}
public boolean CanBePickedUp(Item item) {
if (item instanceof GenericRobot) {
level.items.removeElement(this);
pelletCount--;
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 = level.items.elementAt(a);
if (i instanceof Ghost) {
level.items.removeElement(i);
}
}
}
}
return false;
}
}

View File

@@ -10,88 +10,81 @@ 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;
GenerateIcons();
}
public Polarizer(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 24;
height = 32;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.yellow);
g.fillRect(10,0,4,6);
g.fillRect(9,1,6,4);
g.fillRect(11,6,2,22);
g.fillRect(10,8,4,18);
g.fillRect(8,10,8,2);
g.fillRect(6,14,12,2);
g.fillRect(4,18,16,2);
g.fillRect(2,22,20,2);
g.fillRect(0,28,24,4);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.yellow);
g.fillRect(10, 0, 4, 6);
g.fillRect(9, 1, 6, 4);
g.fillRect(11, 6, 2, 22);
g.fillRect(10, 8, 4, 18);
g.fillRect(8, 10, 8, 2);
g.fillRect(6, 14, 12, 2);
g.fillRect(4, 18, 16, 2);
g.fillRect(2, 22, 20, 2);
g.fillRect(0, 28, 24, 4);
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;
}
searched=true;
}
}
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))
{
level.PlaySound(room, Level.DISCHARGESOUND);
level.LinkRoomsUpDown(36,4);
room.SetMaterial(8,0,0);
room.SetMaterial(9,0,0);
room.SetMaterial(10,0,0);
room.SetMaterial(11,0,0);
item.room = null;
level.items.removeElement(item);
if (carriedBy != null)
carriedBy.Drops();
room = null;
level.items.removeElement(this);
}
}
}
}
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(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);
room.SetMaterial(9, 0, 0);
room.SetMaterial(10, 0, 0);
room.SetMaterial(11, 0, 0);
item.room = null;
level.items.removeElement(item);
if (carriedBy != null) {
carriedBy.Drops();
}
room = null;
level.items.removeElement(this);
}
}
}
}
}
}
}

View File

@@ -9,91 +9,93 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
public class PowerSwitch extends Item
{
// Controls the power in a Generic Robot
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;
GenerateIcons();
if (((GenericRobot)room.portalItem).thrusterPower)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
}
public PowerSwitch(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
GenerateIcons();
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
}
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(8,0,20,4);
g.fillRect(8,0,12,8);
g.fillRect(0,10,4,4);
g.fillRect(4,14,4,4);
g.fillRect(8,18,4,4);
g.fillRect(12,22,4,4);
g.fillRect(8,26,12,6);
g.fillRect(20,28,8,4);
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);
// 1 = On
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(new Color(255,128,0));
g.fillRect(8,0,20,4);
g.fillRect(8,0,12,8);
g.fillRect(12,8,4,18);
g.fillRect(8,26,12,6);
g.fillRect(20,28,8,4);
// 0 = Off
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(8, 0, 20, 4);
g.fillRect(8, 0, 12, 8);
g.fillRect(0, 10, 4, 4);
g.fillRect(4, 14, 4, 4);
g.fillRect(8, 18, 4, 4);
g.fillRect(12, 22, 4, 4);
g.fillRect(8, 26, 12, 6);
g.fillRect(20, 28, 8, 4);
if (((GenericRobot)room.portalItem).thrusterPower)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
}
// 1 = On
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(new Color(255, 128, 0));
g.fillRect(8, 0, 20, 4);
g.fillRect(8, 0, 12, 8);
g.fillRect(12, 8, 4, 18);
g.fillRect(8, 26, 12, 6);
g.fillRect(20, 28, 8, 4);
public boolean CanBePickedUp(Item i)
{
if (i!=level.player)
return false;
((GenericRobot)room.portalItem).thrusterPower = !((GenericRobot)room.portalItem).thrusterPower;
if (((GenericRobot)room.portalItem).thrusterPower)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
return false;
}
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
}
}
public boolean CanBePickedUp(Item i) {
if (i != level.player) {
return false;
}
((GenericRobot) room.portalItem).thrusterPower = !((GenericRobot) room.portalItem).thrusterPower;
if (((GenericRobot) room.portalItem).thrusterPower) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
return false;
}
}

View File

@@ -1,422 +1,425 @@
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
{
// Base class for all Sentries.
//
// Either individual Sentries will have different Animate functions, or
// they will be instances of this class and behave in a manner according
// to two arrays of numbers.
//
// int pace[] = {x1,y1} , {x2,y2}, ...
//
// int protect[] = {x1,y1, x2,y2, x3,y3}, ...
//
//
// The pace array is a list of XY pairs that define the path that the
// Sentry will follow. By default the Sentry paces by going to the first
// point, then the second, then third, and so on until the end of the
// list is reached at which point it goes back to the beginning. Most
// Sentries will probably have two points it paces back and forth
// between.
//
// The protect array consists of sets of 6 numbers, each set is three
// 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
// six). Each block of six numbers defines an area and target the sentry
// guards.
//
// The smartblock variable tells the Sentry to pin a robot down if the
// player is inside it.
//
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
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
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
public class Sentry extends Item {
// Base class for all Sentries.
//
// Either individual Sentries will have different Animate functions, or
// they will be instances of this class and behave in a manner according
// to two arrays of numbers.
//
// int pace[] = {x1,y1} , {x2,y2}, ...
//
// int protect[] = {x1,y1, x2,y2, x3,y3}, ...
//
//
// The pace array is a list of XY pairs that define the path that the
// Sentry will follow. By default the Sentry paces by going to the first
// point, then the second, then third, and so on until the end of the
// list is reached at which point it goes back to the beginning. Most
// Sentries will probably have two points it paces back and forth
// between.
//
// The protect array consists of sets of 6 numbers, each set is three
// 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 divisible by
// six). Each block of six numbers defines an area and target the sentry
// guards.
//
// The smartblock variable tells the Sentry to pin a robot down if the
// player is inside it.
//
public 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();
}
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;
private int[] pace; // List of pacing coordinates
public int[] protect; // List of areas and targets
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, int[] p1, int[] p2, boolean sb)
{
x=X; y=Y; room=r;
width=28; height=18; orgY = 30;
pace = p1;
protect = p2;
smartblock = sb;
pounce = pace.length /2;
drag = pounce+1;
grabbable = false;
behavior = 0;
goToX = pace[0];
goToY = pace[1];
GenerateIcons();
currentIcon = icons[0].getImage();
}
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 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));
icons[2]= new ImageIcon(new BufferedImage(width,height+orgY,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
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;
pounce = pace.length / 2;
drag = pounce + 1;
grabbable = false;
behavior = 0;
goToX = pace[0];
goToY = pace[1];
GenerateIcons();
currentIcon = icons[0].getImage();
}
// 0 = Legs out
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,6);
g.fillRect(8,12,12,24);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(4,36,8,4);
g.fillRect(4,36,4,6);
g.fillRect(0,40,4,8);
g.fillRect(16,36,8,4);
g.fillRect(20,36,4,6);
g.fillRect(24,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
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));
icons[2] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
// 1 = legs mid
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,6);
g.fillRect(8,12,12,28);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(4,40,8,2);
g.fillRect(16,40,8,2);
g.fillRect(4,40,4,8);
g.fillRect(20,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
// 0 = Legs out
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 24);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(4, 36, 8, 4);
g.fillRect(4, 36, 4, 6);
g.fillRect(0, 40, 4, 8);
g.fillRect(16, 36, 8, 4);
g.fillRect(20, 36, 4, 6);
g.fillRect(24, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
// 2 = legs in
try
{
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
if (smartblock) g.setColor(Color.blue);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,36);
g.fillRect(8,12,12,24);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(8,40,4,8);
g.fillRect(16,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
// 1 = legs mid
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 28);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(4, 40, 8, 2);
g.fillRect(16, 40, 8, 2);
g.fillRect(4, 40, 4, 8);
g.fillRect(20, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
if (animation==3)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
}
// 2 = legs in
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
if (smartblock) {
g.setColor(Color.blue);
}
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 36);
g.fillRect(8, 12, 12, 24);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(8, 40, 4, 8);
g.fillRect(16, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
public void Animate()
{
if (carrying==null) animation++;
if (animation==4) animation=0;
if (animation==3)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
if (behavior== -2)
{
return;
}
if (smartblock)
{
robot = PlayerInRobot(null);
if (robot != null)
{
previousBehavior = 0;
behavior=-1; // Pin Robot
}
else if (carrying!=null && behavior!=drag)
{
Drops();
behavior = previousBehavior;
}
}
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++)
{
int x1= protect[p*6];
int y1= protect[p*6+1];
int x2= protect[p*6+2];
int y2= protect[p*6+3];
int x3= protect[p*6+4];
int y3= protect[p*6+5];
if (level.player.x >= x1
&& level.player.x <= x2
&& level.player.y >= y1
&& level.player.y <= y2)
{
carryToX = x3;
carryToY = y3;
previousBehavior = behavior;
if (previousBehavior >= pounce)
previousBehavior = 0;
behavior=pounce;
}
}
}
if (behavior >=0 && behavior < pounce)
{
if (x == goToX && y == goToY)
{
behavior++;
if (behavior==pounce) behavior=0;
goToX = pace[behavior*2];
goToY = pace[behavior*2+1];
}
else
{
if (x != goToX)
{
int diff = Math.abs(goToX - x);
int dir = diff / (goToX - x);
if (diff > 8) diff = 8;
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);
}
}
}
else if (behavior == pounce)
{
if (level.player.room != room)
behavior = previousBehavior;
if (animation==0)
{
x=level.player.x;
y=level.player.y;
}
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 (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 (x == level.player.x && y == level.player.y)
{
PicksUp(level.player);
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
}
public void Animate() {
if (carrying == null) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
if (behavior == -2) {
return;
}
if (smartblock) {
robot = PlayerInRobot(null);
if (robot != null) {
previousBehavior = 0;
behavior = -1; // Pin Robot
}
else if (carrying != null && behavior != drag) {
Drops();
behavior = previousBehavior;
}
}
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++) {
int x1 = protect[p * 6];
int y1 = protect[p * 6 + 1];
int x2 = protect[p * 6 + 2];
int y2 = protect[p * 6 + 3];
int x3 = protect[p * 6 + 4];
int y3 = protect[p * 6 + 5];
if (level.player.x >= x1
&& level.player.x <= x2
&& level.player.y >= y1
&& level.player.y <= y2) {
carryToX = x3;
carryToY = y3;
previousBehavior = behavior;
if (previousBehavior >= pounce) {
previousBehavior = 0;
}
behavior = pounce;
}
}
}
}
if (behavior >= 0 && behavior < pounce) {
if (x == goToX && y == goToY) {
behavior++;
if (behavior == pounce) {
behavior = 0;
}
goToX = pace[behavior * 2];
goToY = pace[behavior * 2 + 1];
}
else {
if (x != goToX) {
int diff = Math.abs(goToX - x);
int dir = diff / (goToX - x);
if (diff > 8) {
diff = 8;
}
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);
}
}
}
else if (behavior == pounce) {
if (level.player.room != room) {
behavior = previousBehavior;
}
if (animation == 0) {
x = level.player.x;
y = level.player.y;
}
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 (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 (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)
{
Drops();
behavior=previousBehavior;
}
else
{
if (x != carryToX)
{
int diff = Math.abs(carryToX - x);
int dir = diff / (carryToX - x);
if (diff > 8) diff = 8;
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);
}
}
}
}
behavior = drag;
}
}
else if (behavior == drag) {
if (x == carryToX && y == carryToY) {
Drops();
behavior = previousBehavior;
}
else {
if (x != carryToX) {
int diff = Math.abs(carryToX - x);
int dir = diff / (carryToX - x);
if (diff > 8) {
diff = 8;
}
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);
}
}
}
}
public 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
return (null);
}
else
if (robot.room.portalItem != null)
{
if (robot.room.portalItem.getClass().toString().endsWith("Robot"))
return (PlayerInRobot ((GenericRobot) robot.room.portalItem));
else
return null;
}
else
{
if (robot.room == room)
return robot;
else
return null;
}
}
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 {
return (null);
}
}
else if (robot.room.portalItem != null) {
if (robot.room.portalItem.getClass().toString().endsWith("Robot")) {
return (PlayerInRobot((GenericRobot) robot.room.portalItem));
}
else {
return null;
}
}
else {
if (robot.room == room) {
return robot;
}
else {
return null;
}
}
}
public void MoveUp(int dist)
{
int newY = y-dist;
if (newY<0)
newY=0;
y=newY;
}
public void MoveUp(int dist) {
int newY = y - dist;
if (newY < 0) {
newY = 0;
}
y = newY;
}
public void MoveDown(int dist)
{
int newY = y+dist;
if (newY>383)
newY=383;
y=newY;
}
public void MoveDown(int dist) {
int newY = y + dist;
if (newY > 383) {
newY = 383;
}
y = newY;
}
public void MoveLeft(int dist)
{
int newX = x-dist;
if (newX<0)
newX=0;
x=newX;
}
public void MoveLeft(int dist) {
int newX = x - dist;
if (newX < 0) {
newX = 0;
}
x = newX;
}
public void MoveRight(int dist)
{
int newX = x+dist;
if (newX>579)
newX=579;
x=newX;
}
public void MoveRight(int dist) {
int newX = x + dist;
if (newX > 579) {
newX = 579;
}
x = newX;
}
}
}

View File

@@ -2,112 +2,145 @@ package com.droidquest.items;
import com.droidquest.Room;
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
// it goes above y=8*32. The Sentry drags the player down to y=11*32. If
// the player ever leaves the room, the Sentry forgets about the player.
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
// it goes above y=8*32. The Sentry drags the player down to y=11*32. If
// the player ever leaves the room, the Sentry forgets about the player.
// Behavior values:
// 0=Move Down
// 1=Move Up
// 2=Attack
// 3=Drag
int carryToX;
boolean smart= false; // knows about the player
// Behavior values:
// 0=Move Down
// 1=Move Up
// 2=Attack
// 3=Drag
private int carryToX;
private boolean smart = false; // knows about the player
public Sentry3(int X, int Y, Room r)
{
super(X,Y,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)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
if (level.player.room!=room)
{
if (smart) behavior = previousBehavior;
smart=false;
}
else
if (level.player.y>320)
{
carryToX = level.player.x;
smart=true;
}
if (behavior<2 && smart)
if (level.player.y <= 256)
{
previousBehavior = behavior;
behavior=2;
}
switch (behavior)
{
case 0:
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);
break;
case 2:
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)
{
PicksUp(level.player);
behavior=3;
}
break;
case 3:
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);
}
break;
}
}
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
}
if (level.player.room != room) {
if (smart) {
behavior = previousBehavior;
}
smart = false;
}
else if (level.player.y > 320) {
carryToX = level.player.x;
smart = true;
}
if (behavior < 2 && smart) {
if (level.player.y <= 256) {
previousBehavior = behavior;
behavior = 2;
}
}
switch (behavior) {
case 0:
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);
}
break;
case 2:
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) {
PicksUp(level.player);
behavior = 3;
}
break;
case 3:
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);
}
}
break;
}
}
}

View File

@@ -9,171 +9,176 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
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.
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.
// Behavior values:
// 0=Move Left
// 1=Move Right
// Behavior values:
// 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;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
}
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()
{
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));
icons[2]= new ImageIcon(new BufferedImage(width,height+orgY,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
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));
icons[2] = new ImageIcon(new BufferedImage(width, height + orgY, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
// 0 = Legs out
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,6);
g.fillRect(8,12,12,24);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(4,36,8,4);
g.fillRect(4,36,4,6);
g.fillRect(0,40,4,8);
g.fillRect(16,36,8,4);
g.fillRect(20,36,4,6);
g.fillRect(24,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
// 1 = legs mid
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,6);
g.fillRect(8,12,12,28);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(4,40,8,2);
g.fillRect(16,40,8,2);
g.fillRect(4,40,4,8);
g.fillRect(20,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
// 0 = Legs out
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 24);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(4, 36, 8, 4);
g.fillRect(4, 36, 4, 6);
g.fillRect(0, 40, 4, 8);
g.fillRect(16, 36, 8, 4);
g.fillRect(20, 36, 4, 6);
g.fillRect(24, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
// 2 = legs in
try
{
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height+orgY);
g.setColor(Color.white);
g.fillRect(8,0,12,6);
g.fillRect(12,6,4,36);
g.fillRect(8,12,12,24);
g.fillRect(4,16,20,18);
g.fillRect(0,20,28,10);
g.fillRect(8,40,4,8);
g.fillRect(16,40,4,8);
g.setColor(Color.black);
g.fillRect(4,22,4,6);
g.fillRect(20,22,4,6);
g.fillRect(8,20,4,2);
g.fillRect(16,20,4,2);
g.fillRect(8,28,4,2);
g.fillRect(16,28,4,2);
g.fillRect(12,18,4,2);
g.fillRect(12,30,4,2);
g.fillRect(12,22,4,6);
// 1 = legs mid
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 6);
g.fillRect(8, 12, 12, 28);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(4, 40, 8, 2);
g.fillRect(16, 40, 8, 2);
g.fillRect(4, 40, 4, 8);
g.fillRect(20, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
if (animation==3)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
}
// 2 = legs in
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height + orgY);
g.setColor(Color.white);
g.fillRect(8, 0, 12, 6);
g.fillRect(12, 6, 4, 36);
g.fillRect(8, 12, 12, 24);
g.fillRect(4, 16, 20, 18);
g.fillRect(0, 20, 28, 10);
g.fillRect(8, 40, 4, 8);
g.fillRect(16, 40, 4, 8);
g.setColor(Color.black);
g.fillRect(4, 22, 4, 6);
g.fillRect(20, 22, 4, 6);
g.fillRect(8, 20, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(8, 28, 4, 2);
g.fillRect(16, 28, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(12, 30, 4, 2);
g.fillRect(12, 22, 4, 6);
public void Animate()
{
if (behavior<3) animation++;
if (animation==4) animation=0;
if (animation==3)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
int oldX;
switch (behavior)
{
case 0:
oldX=x;
MoveLeft(4);
if (oldX==x) behavior=1;
break;
case 1:
oldX=x;
MoveRight(4);
if (oldX==x) behavior=0;
break;
}
}
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
}
}
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
int oldX;
switch (behavior) {
case 0:
oldX = x;
MoveLeft(4);
if (oldX == x) {
behavior = 1;
}
break;
case 1:
oldX = x;
MoveRight(4);
if (oldX == x) {
behavior = 0;
}
break;
}
}
}

View File

@@ -2,94 +2,128 @@ package com.droidquest.items;
import com.droidquest.Room;
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.
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.
// Behavior values:
// 0=Walk down
// 1=Walk up
// 2=Attack
// 3=Drag back
// Behavior values:
// 0=Walk down
// 1=Walk up
// 2=Attack
// 3=Drag back
public SentryT2(int X, int Y, Room r)
{
super(X,Y,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)
currentIcon = icons[1].getImage();
else
currentIcon = icons[animation].getImage();
if (level.player.room==room)
if (level.player.x>=112)
if (level.player.carrying==level.toolbox)
{
previousBehavior = behavior;
behavior=2;
}
switch (behavior)
{
case 0:
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);
break;
case 2:
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)
{
PicksUp(level.player);
behavior=3;
}
break;
case 3:
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);
}
break;
}
}
public void Animate() {
if (behavior < 3) {
animation++;
}
if (animation == 4) {
animation = 0;
}
if (animation == 3) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[animation].getImage();
}
}
if (level.player.room == room) {
if (level.player.x >= 112) {
if (level.player.carrying == level.toolbox) {
previousBehavior = behavior;
behavior = 2;
}
}
}
switch (behavior) {
case 0:
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);
}
break;
case 2:
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) {
PicksUp(level.player);
behavior = 3;
}
break;
case 3:
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);
}
}
break;
}
}
}

View File

@@ -4,59 +4,53 @@ 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;
speed=s;
width=28; height=32;
grabbable = false;
GenerateIcons();
}
public SkyGuard(int X, int Y, Room r, int s) {
x = X;
y = Y;
room = r;
speed = s;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void GenerateIcons()
{
icons = new ImageIcon[5];
for (int a=0; a<5; a++)
icons[a] = new ImageIcon("images/skyguard"+a+".gif");
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[5];
for (int a = 0; a < 5; a++) {
icons[a] = new ImageIcon("images/skyguard" + a + ".gif");
}
currentIcon = icons[0].getImage();
}
public void Animate()
{
animationState = 1-animationState;
if (speed>0)
{
if (speed+x < 420)
{
MoveRight(speed);
currentIcon = icons[animationState].getImage();
}
else
{
speed=-speed;
currentIcon = icons[2].getImage();
}
}
else if (speed<0)
{
if (speed+x > 112)
{
MoveLeft(-speed);
currentIcon = icons[3+animationState].getImage();
}
else
{
speed=-speed;
currentIcon = icons[2].getImage();
}
}
}
public void Animate() {
animationState = 1 - animationState;
if (speed > 0) {
if (speed + x < 420) {
MoveRight(speed);
currentIcon = icons[animationState].getImage();
}
else {
speed = -speed;
currentIcon = icons[2].getImage();
}
}
else if (speed < 0) {
if (speed + x > 112) {
MoveLeft(-speed);
currentIcon = icons[3 + animationState].getImage();
}
else {
speed = -speed;
currentIcon = icons[2].getImage();
}
}
}
}

View File

@@ -5,62 +5,65 @@ 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;
orgX = 2;
filenames = f; speed=spd;
grabbable = false;
}
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;
grabbable = false;
}
public void GenerateIcons()
{
icons = new ImageIcon[filenames.length];
for (int a=0; a<filenames.length; a++)
icons[a] = new ImageIcon("images/"+filenames[a]);
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[filenames.length];
for (int a = 0; a < filenames.length; a++) {
icons[a] = new ImageIcon("images/" + filenames[a]);
}
currentIcon = icons[0].getImage();
}
public void MoveUp(int dist)
{
y = y - dist;
if (y<32)
y = 320;
}
public void MoveUp(int dist) {
y = y - dist;
if (y < 32) {
y = 320;
}
}
public void MoveDown(int dist)
{
y = y + dist;
if (y>320)
y = 32;
}
public void MoveDown(int dist) {
y = y + dist;
if (y > 320) {
y = 32;
}
}
public void Animate()
{
animationState++;
if (animationState == filenames.length)
animationState=0;
currentIcon = icons[animationState].getImage();
if (speed<0)
MoveUp(-speed);
else
MoveDown(speed);
if (Overlaps(level.player))
{
level.PlaySound(room, Level.DISCHARGESOUND);
level.player.x = 2*28;
level.player.y = 8*32;
level.player.SetRoom(room.downRoom);
}
}
public void Animate() {
animationState++;
if (animationState == filenames.length) {
animationState = 0;
}
currentIcon = icons[animationState].getImage();
if (speed < 0) {
MoveUp(-speed);
}
else {
MoveDown(speed);
}
if (Overlaps(level.player)) {
level.PlaySound(room, Level.DISCHARGESOUND);
level.player.x = 2 * 28;
level.player.y = 8 * 32;
level.player.SetRoom(room.downRoom);
}
}
}

View File

@@ -3,57 +3,46 @@ 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)
{
super(X,Y,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()
{
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"))
{
VendingHandle vh = (VendingHandle) item;
vh.paid = true;
}
}
x=3*28; y=3*32;
room = (Room) level.rooms.elementAt(34);
jumping = true;
}
}
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 = level.items.elementAt(a);
if (item.getClass().toString().endsWith("VendingHandle")) {
VendingHandle vh = (VendingHandle) item;
vh.paid = true;
}
}
x = 3 * 28;
y = 3 * 32;
room = level.rooms.elementAt(34);
jumping = true;
}
}
public void Animate()
{
if (carriedBy != null)
jumping = false;
if (jumping)
{
if (Overlaps(level.player))
{
x = level.random.nextInt(16*28)+28;
y = level.random.nextInt(8*32)+(2*32);
}
}
}
public void Animate() {
if (carriedBy != null) {
jumping = false;
}
if (jumping) {
if (Overlaps(level.player)) {
x = level.random.nextInt(16 * 28) + 28;
y = level.random.nextInt(8 * 32) + (2 * 32);
}
}
}
}

View File

@@ -10,149 +10,143 @@ import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.devices.Antenna;
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.
//
// Binary arrays start with a -1.
// Room Changes use other single codes.
//
//
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.
//
// Binary arrays start with a -1.
// Room Changes use other single codes.
//
//
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;
public static final int MODIFY = -1;
public static final int BINARY = -2;
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;
room = r;
program = p;
width=28; height=30;
grabbable = false;
currentRoom = room;
GenerateIcons();
}
public SonicLock(int X, int Y, Room r, int[][] p) {
x = X;
y = Y;
room = r;
program = p;
width = 28;
height = 30;
grabbable = false;
currentRoom = room;
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++)
{
Graphics g;
try
{
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
switch (a)
{
case 0:
g.setColor(Color.white);
break;
case 1:
g.setColor(new Color(255,128,0));
break;
}
g.fillRect(0,14,28,2);
g.fillRect(4,12,4,6);
g.fillRect(8,10,4,2);
g.fillRect(8,18,4,2);
g.fillRect(12,8,4,2);
g.fillRect(12,20,4,2);
g.fillRect(12,0,4,6);
g.fillRect(12,24,4,6);
g.fillRect(16,2,4,26);
g.fillRect(20,6,4,18);
g.fillRect(24,12,4,6);
}
currentIcon = icons[0].getImage();
}
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++) {
Graphics g;
try {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
switch (a) {
case 0:
g.setColor(Color.white);
break;
case 1:
g.setColor(new Color(255, 128, 0));
break;
}
g.fillRect(0, 14, 28, 2);
g.fillRect(4, 12, 4, 6);
g.fillRect(8, 10, 4, 2);
g.fillRect(8, 18, 4, 2);
g.fillRect(12, 8, 4, 2);
g.fillRect(12, 20, 4, 2);
g.fillRect(12, 0, 4, 6);
g.fillRect(12, 24, 4, 6);
g.fillRect(16, 2, 4, 26);
g.fillRect(20, 6, 4, 18);
g.fillRect(24, 12, 4, 6);
}
currentIcon = icons[0].getImage();
}
public void Animate()
{
if (doorState == program.length)
doorState = 0;
if (program[doorState][0]==BINARY)
{
animationState++;
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++)
currentRoom.SetMaterial(program[doorState][a*3+1],
program[doorState][a*3+2],
program[doorState][a*3+3]);
doorState++;
radioState=1;
}
break;
case BINARY:
{
currentRoom = room;
boolean radio = (Antenna.radio>0);
boolean bit = (program[doorState][radioState]==1);
if (radio == bit)
{
radioState++;
if (radioState == program[doorState].length)
doorState++;
}
else
radioState =1;
}
break;
case RESET:
currentRoom = room;
break;
case LEFT:
currentRoom = currentRoom.leftRoom;
break;
case RIGHT:
currentRoom = currentRoom.rightRoom;
break;
case UP:
currentRoom = currentRoom.upRoom;
break;
case DOWN:
currentRoom = currentRoom.downRoom;
break;
}
}
public void Animate() {
if (doorState == program.length) {
doorState = 0;
}
}
if (program[doorState][0] == BINARY) {
animationState++;
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++) {
currentRoom.SetMaterial(program[doorState][a * 3 + 1],
program[doorState][a * 3 + 2],
program[doorState][a * 3 + 3]);
}
doorState++;
radioState = 1;
}
break;
case BINARY: {
currentRoom = room;
boolean radio = (Antenna.radio > 0);
boolean bit = (program[doorState][radioState] == 1);
if (radio == bit) {
radioState++;
if (radioState == program[doorState].length) {
doorState++;
}
}
else {
radioState = 1;
}
}
break;
case RESET:
currentRoom = room;
break;
case LEFT:
currentRoom = currentRoom.leftRoom;
break;
case RIGHT:
currentRoom = currentRoom.rightRoom;
break;
case UP:
currentRoom = currentRoom.upRoom;
break;
case DOWN:
currentRoom = currentRoom.downRoom;
break;
}
}
}

View File

@@ -1,96 +1,86 @@
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 static final int DIR_UP = 0;
public static final int DIR_DOWN = 1;
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;
room = r;
width=26; height=26;
direction = dir;
GenerateIcons();
}
public SpeedControl(int X, int Y, Room r, int dir) {
x = X;
y = Y;
room = r;
width = 26;
height = 26;
direction = dir;
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
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
switch(direction)
{
case DIR_UP:
g.fillRect(12,0,2,2);
g.fillRect(10,2,6,2);
g.fillRect(8,4,10,2);
g.fillRect(6,6,14,2);
g.fillRect(4,8,18,2);
g.fillRect(2,10,22,2);
g.fillRect(0,12,26,2);
g.fillRect(10,14,6,12);
break;
case DIR_DOWN:
g.fillRect(12,24,2,2);
g.fillRect(10,22,6,2);
g.fillRect(8,20,10,2);
g.fillRect(6,18,14,2);
g.fillRect(4,16,18,2);
g.fillRect(2,14,22,2);
g.fillRect(0,12,26,2);
g.fillRect(10,0,6,12);
break;
}
currentIcon = icons[0].getImage();
}
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 {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
switch (direction) {
case DIR_UP:
g.fillRect(12, 0, 2, 2);
g.fillRect(10, 2, 6, 2);
g.fillRect(8, 4, 10, 2);
g.fillRect(6, 6, 14, 2);
g.fillRect(4, 8, 18, 2);
g.fillRect(2, 10, 22, 2);
g.fillRect(0, 12, 26, 2);
g.fillRect(10, 14, 6, 12);
break;
case DIR_DOWN:
g.fillRect(12, 24, 2, 2);
g.fillRect(10, 22, 6, 2);
g.fillRect(8, 20, 10, 2);
g.fillRect(6, 18, 14, 2);
g.fillRect(4, 16, 18, 2);
g.fillRect(2, 14, 22, 2);
g.fillRect(0, 12, 26, 2);
g.fillRect(10, 0, 6, 12);
break;
}
currentIcon = icons[0].getImage();
}
public boolean CanBePickedUp(Item item)
{
switch (direction)
{
case DIR_UP:
ChipCompiler.chipSpeed++;
break;
case DIR_DOWN:
if (ChipCompiler.chipSpeed==1) return false;
ChipCompiler.chipSpeed--;
break;
}
TextBox tb = (TextBox) room.textBoxes.elementAt(1);
tb.textString = ChipCompiler.chipSpeed + "x";
return false;
}
public boolean CanBePickedUp(Item item) {
switch (direction) {
case DIR_UP:
ChipCompiler.chipSpeed++;
break;
case DIR_DOWN:
if (ChipCompiler.chipSpeed == 1) {
return false;
}
ChipCompiler.chipSpeed--;
break;
}
TextBox tb = room.textBoxes.elementAt(1);
tb.textString = ChipCompiler.chipSpeed + "x";
return false;
}
}

View File

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

View File

@@ -1,45 +1,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;
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;
editable=true;
color = c;
GenerateIcons();
}
public class Square extends Item {
private Color color;
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
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();
}
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() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g.setColor(color);
g.fillRect(0, 0, 28, 28);
currentIcon = icons[0].getImage();
}
}

View File

@@ -1,256 +1,276 @@
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;
grabbable=false;
GenerateIcons();
}
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 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
{
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,4*28,3*32);
g.setColor(Color.white);
g.fillRect(16,0,4,2);
g.fillRect(4,2,4,2);
g.fillRect(12,4,4,2);
g.fillRect(20,4,4,2);
g.fillRect(4,8,4,2);
g.fillRect(12,8,4,2);
g.fillRect(24,8,4,2);
g.fillRect(0,10,4,2);
g.fillRect(8,10,4,2);
g.fillRect(16,10,4,2);
g.fillRect(24,12,4,2);
g.fillRect(8,14,4,2);
g.fillRect(16,14,4,2);
g.fillRect(0,18,4,2);
g.fillRect(12,18,4,2);
g.fillRect(24,18,4,2);
g.fillRect(16,20,4,2);
g.fillRect(4,22,4,2);
g.fillRect(20,22,4,2);
g.fillRect(8,24,4,2);
g.fillRect(16,24,4,2);
}
currentIcon = icons[0].getImage();
do
xDirection = level.random.nextInt(maxspeed*2 + 1)-maxspeed;
while (xDirection == 0);
do
yDirection = level.random.nextInt(maxspeed*2 + 1)-maxspeed;
while (yDirection == 0);
moveTimer = level.random.nextInt(50)+1;
}
public StormCloud(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 32;
grabbable = false;
GenerateIcons();
}
public void Animate()
{
animateState++;
if (animateState==3) animateState=0;
currentIcon = icons[animateState].getImage();
if (anicount<3)
{
Graphics g;
anicount++;
try
{
icons[animateState]= new ImageIcon(new BufferedImage(4*28,3*32,BufferedImage.TYPE_4BYTE_ABGR));
g = icons[animateState].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
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;
}
int x1, y1, d;
int d2 = (3*32/2) * (3*32/2);
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) ;
int yd= (y1 - 3*32/2);
d = xd*xd + yd*yd;
}
while (d>d2);
g2.fillRect(x1,y1,2,2);
}
}
moveTimer--;
if (moveTimer==0)
{
do
xDirection = level.random.nextInt(maxspeed*2 + 1)-maxspeed;
while (xDirection == 0);
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"))
brobot = (BlueRobot) item;
if (item.getClass().toString().endsWith("OrangeRobot"))
orobot = (OrangeRobot) item;
if (item.getClass().toString().endsWith("WhiteRobot"))
wrobot = (WhiteRobot) item;
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 (brobot!=null)
if (Overlaps(brobot))
{
boolean drain = true;
if (stormshield.room == brobot.InternalRoom)
if (stormshield.ports[0].value==true)
drain=false;
if (drain)
brobot.charge -= 5000;
if (brobot.charge<0)
brobot.charge = 0;
}
if (orobot!=null)
if (Overlaps(orobot))
{
boolean drain = true;
if (stormshield.room == orobot.InternalRoom)
if (stormshield.ports[0].value==true)
drain=false;
if (drain)
orobot.charge -= 5000;
if (orobot.charge<0)
orobot.charge = 0;
}
if (wrobot!=null)
if (Overlaps(wrobot))
{
boolean drain = true;
if (stormshield.room == wrobot.InternalRoom)
if (stormshield.ports[0].value==true)
drain=false;
if (drain)
wrobot.charge -= 5000;
if (wrobot.charge<0)
wrobot.charge = 0;
}
}
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 {
g = icons[a].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, 4 * 28, 3 * 32);
public void MoveRight(int dist)
{
int newX = x + dist;
if (newX > 559 - 4*28/2)
{
xDirection = -(level.random.nextInt(maxspeed)+1);
newX = x + xDirection;
}
x=newX;
}
g.setColor(Color.white);
g.fillRect(16, 0, 4, 2);
g.fillRect(4, 2, 4, 2);
g.fillRect(12, 4, 4, 2);
g.fillRect(20, 4, 4, 2);
g.fillRect(4, 8, 4, 2);
g.fillRect(12, 8, 4, 2);
g.fillRect(24, 8, 4, 2);
g.fillRect(0, 10, 4, 2);
g.fillRect(8, 10, 4, 2);
g.fillRect(16, 10, 4, 2);
g.fillRect(24, 12, 4, 2);
g.fillRect(8, 14, 4, 2);
g.fillRect(16, 14, 4, 2);
g.fillRect(0, 18, 4, 2);
g.fillRect(12, 18, 4, 2);
g.fillRect(24, 18, 4, 2);
g.fillRect(16, 20, 4, 2);
g.fillRect(4, 22, 4, 2);
g.fillRect(20, 22, 4, 2);
g.fillRect(8, 24, 4, 2);
g.fillRect(16, 24, 4, 2);
}
currentIcon = icons[0].getImage();
do {
xDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (xDirection == 0);
do {
yDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (yDirection == 0);
moveTimer = level.random.nextInt(50) + 1;
}
public void MoveLeft(int dist)
{
int newX = x - dist;
if (newX < 0)
{
xDirection = level.random.nextInt(maxspeed)+1;
newX = x + xDirection;
}
x=newX;
}
public void Animate() {
animateState++;
if (animateState == 3) {
animateState = 0;
}
currentIcon = icons[animateState].getImage();
public void MoveUp(int dist)
{
y -= dist;
if (y < 0)
{
room = room.upRoom;
y += 384;
}
}
if (anicount < 3) {
Graphics g;
anicount++;
try {
icons[animateState] = new ImageIcon(new BufferedImage(4 * 28, 3 * 32, BufferedImage.TYPE_4BYTE_ABGR));
g = icons[animateState].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
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;
}
int x1, y1, d;
int d2 = (3 * 32 / 2) * (3 * 32 / 2);
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);
int yd = (y1 - 3 * 32 / 2);
d = xd * xd + yd * yd;
}
while (d > d2);
g2.fillRect(x1, y1, 2, 2);
}
}
public void MoveDown(int dist)
{
y += dist;
if (y > 383)
{
room = room.downRoom;
y -= 384;
}
}
moveTimer--;
if (moveTimer == 0) {
do {
xDirection = level.random.nextInt(maxspeed * 2 + 1) - maxspeed;
}
while (xDirection == 0);
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 = level.items.elementAt(a);
if (item.getClass().toString().endsWith("BlueRobot")) {
brobot = (BlueRobot) item;
}
if (item.getClass().toString().endsWith("OrangeRobot")) {
orobot = (OrangeRobot) item;
}
if (item.getClass().toString().endsWith("WhiteRobot")) {
wrobot = (WhiteRobot) item;
}
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 (brobot != null) {
if (Overlaps(brobot)) {
boolean drain = true;
if (stormshield.room == brobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
}
}
if (drain) {
brobot.charge -= 5000;
}
if (brobot.charge < 0) {
brobot.charge = 0;
}
}
}
if (orobot != null) {
if (Overlaps(orobot)) {
boolean drain = true;
if (stormshield.room == orobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
}
}
if (drain) {
orobot.charge -= 5000;
}
if (orobot.charge < 0) {
orobot.charge = 0;
}
}
}
if (wrobot != null) {
if (Overlaps(wrobot)) {
boolean drain = true;
if (stormshield.room == wrobot.InternalRoom) {
if (stormshield.ports[0].value) {
drain = false;
}
}
if (drain) {
wrobot.charge -= 5000;
}
if (wrobot.charge < 0) {
wrobot.charge = 0;
}
}
}
}
public void MoveRight(int dist) {
int newX = x + dist;
if (newX > 559 - 4 * 28 / 2) {
xDirection = -(level.random.nextInt(maxspeed) + 1);
newX = x + xDirection;
}
x = newX;
}
public void MoveLeft(int dist) {
int newX = x - dist;
if (newX < 0) {
xDirection = level.random.nextInt(maxspeed) + 1;
newX = x + xDirection;
}
x = newX;
}
public void MoveUp(int dist) {
y -= dist;
if (y < 0) {
room = room.upRoom;
y += 384;
}
}
public void MoveDown(int dist) {
y += dist;
if (y > 383) {
room = room.downRoom;
y -= 384;
}
}
}

View File

@@ -1,80 +1,77 @@
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;
InternalRoom = new Room();
int[][] table1 = {
{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},
{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},
{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},
{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},
{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},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
InternalRoom.RoomArray = table1;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
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)
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
GenerateIcons();
}
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;
public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0);
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.blue);
g.fillRect(0,4,24,14);
g.fillRect(7,0,10,2);
g.fillRect(7,0,2,4);
g.fillRect(15,0,2,4);
currentIcon = icons[0].getImage();
}
InternalRoom = new Room();
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},
{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},
{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},
{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},
{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},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
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) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
GenerateIcons();
}
public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g;
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.blue);
g.fillRect(0, 4, 24, 14);
g.fillRect(7, 0, 10, 2);
g.fillRect(7, 0, 2, 4);
g.fillRect(15, 0, 2, 4);
currentIcon = icons[0].getImage();
}
}

View File

@@ -1,218 +1,204 @@
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;
room=r;
width=48; height=32;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
animationState=1;
}
public Sweeper(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 48;
height = 32;
grabbable = false;
GenerateIcons();
currentIcon = icons[0].getImage();
animationState = 1;
}
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;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// sweeper1.gif = Moving Right
try
{
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(12,0,12,2);
g.fillRect(8,2,20,10);
g.fillRect(8,12,24,2);
g.fillRect(4,14,28,8);
g.fillRect(4,22,36,6);
g.fillRect(0,28,40,4);
g.fillRect(28,4,8,2);
g.fillRect(36,2,4,6);
g.fillRect(32,14,12,2);
g.fillRect(40,12,8,2);
g.fillRect(40,16,8,2);
g.setColor(Color.black);
g.fillRect(12,8,4,4);
g.fillRect(20,8,4,4);
g.fillRect(8,16,4,2);
g.fillRect(8,20,4,2);
g.fillRect(8,26,4,2);
g.fillRect(16,18,4,2);
g.fillRect(16,22,4,2);
g.fillRect(20,26,4,2);
g.fillRect(24,16,4,2);
g.fillRect(24,20,4,2);
g.fillRect(28,24,4,2);
g.fillRect(32,28,4,2);
// sweeper2.gif = Looking Straight
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(18,0,12,2);
g.fillRect(14,2,20,10);
g.fillRect(10,12,28,20);
g.fillRect(6,28,36,4);
g.setColor(Color.black);
g.fillRect(22,2,4,6);
g.fillRect(18,4,12,2);
g.fillRect(18,8,4,4);
g.fillRect(26,8,4,4);
g.fillRect(14,12,4,6);
g.fillRect(30,12,4,6);
g.fillRect(14,20,4,2);
g.fillRect(14,24,4,2);
g.fillRect(14,28,4,2);
g.fillRect(22,16,4,2);
g.fillRect(22,20,4,2);
g.fillRect(22,24,4,2);
g.fillRect(22,28,4,2);
g.fillRect(30,20,4,2);
g.fillRect(30,24,4,2);
g.fillRect(30,28,4,2);
// sweeper3.gif = Moving Left
try
{
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0,0,width,height);
g.setColor(Color.white);
g.fillRect(24,0,12,2);
g.fillRect(20,2,20,10);
g.fillRect(16,12,24,2);
g.fillRect(16,14,28,8);
g.fillRect(12,22,36,6);
g.fillRect(8,28,40,4);
g.fillRect(12,4,8,2);
g.fillRect(8,2,4,6);
g.fillRect(4,14,12,2);
g.fillRect(0,12,8,2);
g.fillRect(0,16,8,2);
g.setColor(Color.black);
g.fillRect(24,8,4,4);
g.fillRect(32,8,4,4);
g.fillRect(36,16,4,2);
g.fillRect(36,20,4,2);
g.fillRect(36,26,4,2);
g.fillRect(28,18,4,2);
g.fillRect(28,22,4,2);
g.fillRect(24,26,4,2);
g.fillRect(20,16,4,2);
g.fillRect(20,20,4,2);
g.fillRect(16,24,4,2);
g.fillRect(12,28,4,2);
switch (animationState)
{
case 1:
currentIcon = icons[0].getImage();
break;
case 3:
currentIcon = icons[2].getImage();
break;
case 2:
case 4:
currentIcon = icons[1].getImage();
break;
}
}
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;
Graphics2D g2;
Color transparent = new Color(0, 0, 0, 0);
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))
{
testItem.x = 280;
testItem.y = 192;
testItem.SetRoom((Room) level.rooms.elementAt(1));
}
}
switch (animationState)
{
case 1:
if (room==(Room) level.rooms.elementAt(14) && x>=120)
{
animationState = 2;
currentIcon = icons[1].getImage();
}
else
MoveRight(8);
break;
// sweeper1.gif = Moving Right
try {
g = icons[0].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(12, 0, 12, 2);
g.fillRect(8, 2, 20, 10);
g.fillRect(8, 12, 24, 2);
g.fillRect(4, 14, 28, 8);
g.fillRect(4, 22, 36, 6);
g.fillRect(0, 28, 40, 4);
g.fillRect(28, 4, 8, 2);
g.fillRect(36, 2, 4, 6);
g.fillRect(32, 14, 12, 2);
g.fillRect(40, 12, 8, 2);
g.fillRect(40, 16, 8, 2);
g.setColor(Color.black);
g.fillRect(12, 8, 4, 4);
g.fillRect(20, 8, 4, 4);
g.fillRect(8, 16, 4, 2);
g.fillRect(8, 20, 4, 2);
g.fillRect(8, 26, 4, 2);
g.fillRect(16, 18, 4, 2);
g.fillRect(16, 22, 4, 2);
g.fillRect(20, 26, 4, 2);
g.fillRect(24, 16, 4, 2);
g.fillRect(24, 20, 4, 2);
g.fillRect(28, 24, 4, 2);
g.fillRect(32, 28, 4, 2);
case 2:
animationState = 3;
currentIcon = icons[2].getImage();
break;
// sweeper2.gif = Looking Straight
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(18, 0, 12, 2);
g.fillRect(14, 2, 20, 10);
g.fillRect(10, 12, 28, 20);
g.fillRect(6, 28, 36, 4);
g.setColor(Color.black);
g.fillRect(22, 2, 4, 6);
g.fillRect(18, 4, 12, 2);
g.fillRect(18, 8, 4, 4);
g.fillRect(26, 8, 4, 4);
g.fillRect(14, 12, 4, 6);
g.fillRect(30, 12, 4, 6);
g.fillRect(14, 20, 4, 2);
g.fillRect(14, 24, 4, 2);
g.fillRect(14, 28, 4, 2);
g.fillRect(22, 16, 4, 2);
g.fillRect(22, 20, 4, 2);
g.fillRect(22, 24, 4, 2);
g.fillRect(22, 28, 4, 2);
g.fillRect(30, 20, 4, 2);
g.fillRect(30, 24, 4, 2);
g.fillRect(30, 28, 4, 2);
case 3:
if (room==(Room) level.rooms.elementAt(2) && x<=504)
{
animationState = 4;
currentIcon = icons[2].getImage();
}
else
MoveLeft(8);
break;
// sweeper3.gif = Moving Left
try {
g = icons[2].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
g2 = (Graphics2D) g;
g2.setBackground(transparent);
g2.clearRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(24, 0, 12, 2);
g.fillRect(20, 2, 20, 10);
g.fillRect(16, 12, 24, 2);
g.fillRect(16, 14, 28, 8);
g.fillRect(12, 22, 36, 6);
g.fillRect(8, 28, 40, 4);
g.fillRect(12, 4, 8, 2);
g.fillRect(8, 2, 4, 6);
g.fillRect(4, 14, 12, 2);
g.fillRect(0, 12, 8, 2);
g.fillRect(0, 16, 8, 2);
g.setColor(Color.black);
g.fillRect(24, 8, 4, 4);
g.fillRect(32, 8, 4, 4);
g.fillRect(36, 16, 4, 2);
g.fillRect(36, 20, 4, 2);
g.fillRect(36, 26, 4, 2);
g.fillRect(28, 18, 4, 2);
g.fillRect(28, 22, 4, 2);
g.fillRect(24, 26, 4, 2);
g.fillRect(20, 16, 4, 2);
g.fillRect(20, 20, 4, 2);
g.fillRect(16, 24, 4, 2);
g.fillRect(12, 28, 4, 2);
case 4:
animationState = 1;
currentIcon = icons[0].getImage();
}
}
switch (animationState) {
case 1:
currentIcon = icons[0].getImage();
break;
case 3:
currentIcon = icons[2].getImage();
break;
case 2:
case 4:
currentIcon = icons[1].getImage();
break;
}
}
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(level.rooms.elementAt(1));
}
}
}
switch (animationState) {
case 1:
if (room == level.rooms.elementAt(14) && x >= 120) {
animationState = 2;
currentIcon = icons[1].getImage();
}
else {
MoveRight(8);
}
break;
case 2:
animationState = 3;
currentIcon = icons[2].getImage();
break;
case 3:
if (room == level.rooms.elementAt(2) && x <= 504) {
animationState = 4;
currentIcon = icons[2].getImage();
}
else {
MoveLeft(8);
}
break;
case 4:
animationState = 1;
currentIcon = icons[0].getImage();
}
}
}

View File

@@ -3,162 +3,166 @@ package com.droidquest.items;
import com.droidquest.Room;
import com.droidquest.materials.Switch;
public class Switch4A extends Switch
{
int count = 0;
int doorState=0;
transient Room room= null;
public class Switch4A extends Switch {
int count = 0;
private int doorState = 0;
transient Room room = null;
public Switch4A()
{
super(Switch.ROT_UP);
GenerateIcons();
}
public Switch4A() {
super(Switch.ROT_UP);
GenerateIcons();
}
public void TouchedByItem(Item item)
{
if (!value)
{
value=true;
count++;
room = item.room;
}
}
public void TouchedByItem(Item item) {
if (!value) {
value = true;
count++;
room = item.room;
}
}
public void Animate()
{
super.Animate();
if (doorState==0 && count==4)
doorState=1;
switch (doorState)
{
case 1:
room.SetMaterial(8,3,0);
room.SetMaterial(9,3,0);
room.SetMaterial(10,3,0);
room.SetMaterial(11,3,0);
room.SetMaterial(8,8,0);
room.SetMaterial(9,8,0);
room.SetMaterial(10,8,0);
room.SetMaterial(11,8,0);
room.SetMaterial(12,4,0);
room.SetMaterial(12,5,0);
room.SetMaterial(12,6,0);
room.SetMaterial(12,7,0);
room.SetMaterial(13,4,4);
room.SetMaterial(13,7,4);
room.SetMaterial(7,4,0);
room.SetMaterial(7,5,0);
room.SetMaterial(7,6,0);
room.SetMaterial(7,7,0);
room.SetMaterial(6,4,4);
room.SetMaterial(6,7,4);
doorState++;
break;
case 2:
room.SetMaterial(8,2,0);
room.SetMaterial(9,2,0);
room.SetMaterial(10,2,0);
room.SetMaterial(11,2,0);
room.SetMaterial(12,2,0);
room.SetMaterial(7,9,0);
room.SetMaterial(8,9,0);
room.SetMaterial(9,9,0);
room.SetMaterial(10,9,0);
room.SetMaterial(11,9,0);
room.SetMaterial(13,4,0);
room.SetMaterial(13,5,0);
room.SetMaterial(13,6,0);
room.SetMaterial(13,7,0);
room.SetMaterial(14,4,4);
room.SetMaterial(14,7,4);
room.SetMaterial(6,4,0);
room.SetMaterial(6,5,0);
room.SetMaterial(6,6,0);
room.SetMaterial(6,7,0);
room.SetMaterial(5,4,4);
room.SetMaterial(5,7,4);
doorState++;
break;
case 3:
room.SetMaterial(8,1,0);
room.SetMaterial(9,1,0);
room.SetMaterial(10,1,0);
room.SetMaterial(11,1,0);
room.SetMaterial(8,10,0);
room.SetMaterial(9,10,0);
room.SetMaterial(10,10,0);
room.SetMaterial(11,10,0);
room.SetMaterial(14,4,0);
room.SetMaterial(14,5,0);
room.SetMaterial(14,6,0);
room.SetMaterial(14,7,0);
room.SetMaterial(15,4,4);
room.SetMaterial(15,7,4);
room.SetMaterial(5,4,0);
room.SetMaterial(5,5,0);
room.SetMaterial(5,6,0);
room.SetMaterial(5,7,0);
room.SetMaterial(4,4,4);
room.SetMaterial(4,7,4);
doorState++;
break;
case 4:
Room temproom = room.rightRoom; // KeyTunnel Left
temproom.SetMaterial(2,3,0);
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++)
{
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)
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)
temproom.SetMaterial(X,Y,11);
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.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)
temproom.SetMaterial(X,Y,11);
temproom = room.upRoom;
temproom.SetMaterial(19,5,0);
temproom.SetMaterial(19,6,0);
temproom.SetMaterial(19,7,0);
temproom = temproom.rightRoom;
temproom = temproom.upRoom;
temproom = temproom.leftRoom;
temproom = temproom.leftRoom;
temproom.SetMaterial(19,5,0);
temproom.SetMaterial(19,6,0);
doorState++;
break;
}
}
public void Animate() {
super.Animate();
if (doorState == 0 && count == 4) {
doorState = 1;
}
switch (doorState) {
case 1:
room.SetMaterial(8, 3, 0);
room.SetMaterial(9, 3, 0);
room.SetMaterial(10, 3, 0);
room.SetMaterial(11, 3, 0);
room.SetMaterial(8, 8, 0);
room.SetMaterial(9, 8, 0);
room.SetMaterial(10, 8, 0);
room.SetMaterial(11, 8, 0);
room.SetMaterial(12, 4, 0);
room.SetMaterial(12, 5, 0);
room.SetMaterial(12, 6, 0);
room.SetMaterial(12, 7, 0);
room.SetMaterial(13, 4, 4);
room.SetMaterial(13, 7, 4);
room.SetMaterial(7, 4, 0);
room.SetMaterial(7, 5, 0);
room.SetMaterial(7, 6, 0);
room.SetMaterial(7, 7, 0);
room.SetMaterial(6, 4, 4);
room.SetMaterial(6, 7, 4);
doorState++;
break;
case 2:
room.SetMaterial(8, 2, 0);
room.SetMaterial(9, 2, 0);
room.SetMaterial(10, 2, 0);
room.SetMaterial(11, 2, 0);
room.SetMaterial(12, 2, 0);
room.SetMaterial(7, 9, 0);
room.SetMaterial(8, 9, 0);
room.SetMaterial(9, 9, 0);
room.SetMaterial(10, 9, 0);
room.SetMaterial(11, 9, 0);
room.SetMaterial(13, 4, 0);
room.SetMaterial(13, 5, 0);
room.SetMaterial(13, 6, 0);
room.SetMaterial(13, 7, 0);
room.SetMaterial(14, 4, 4);
room.SetMaterial(14, 7, 4);
room.SetMaterial(6, 4, 0);
room.SetMaterial(6, 5, 0);
room.SetMaterial(6, 6, 0);
room.SetMaterial(6, 7, 0);
room.SetMaterial(5, 4, 4);
room.SetMaterial(5, 7, 4);
doorState++;
break;
case 3:
room.SetMaterial(8, 1, 0);
room.SetMaterial(9, 1, 0);
room.SetMaterial(10, 1, 0);
room.SetMaterial(11, 1, 0);
room.SetMaterial(8, 10, 0);
room.SetMaterial(9, 10, 0);
room.SetMaterial(10, 10, 0);
room.SetMaterial(11, 10, 0);
room.SetMaterial(14, 4, 0);
room.SetMaterial(14, 5, 0);
room.SetMaterial(14, 6, 0);
room.SetMaterial(14, 7, 0);
room.SetMaterial(15, 4, 4);
room.SetMaterial(15, 7, 4);
room.SetMaterial(5, 4, 0);
room.SetMaterial(5, 5, 0);
room.SetMaterial(5, 6, 0);
room.SetMaterial(5, 7, 0);
room.SetMaterial(4, 4, 4);
room.SetMaterial(4, 7, 4);
doorState++;
break;
case 4:
Room temproom = room.rightRoom; // KeyTunnel Left
temproom.SetMaterial(2, 3, 0);
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++) {
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) {
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) {
temproom.SetMaterial(X, Y, 11);
}
if (temproom.RoomArray[Y][X] == 16) {
temproom.SetMaterial(X, Y, 0);
}
}
}
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) {
temproom.SetMaterial(X, Y, 11);
}
}
}
temproom = room.upRoom;
temproom.SetMaterial(19, 5, 0);
temproom.SetMaterial(19, 6, 0);
temproom.SetMaterial(19, 7, 0);
temproom = temproom.rightRoom;
temproom = temproom.upRoom;
temproom = temproom.leftRoom;
temproom = temproom.leftRoom;
temproom.SetMaterial(19, 5, 0);
temproom.SetMaterial(19, 6, 0);
doorState++;
break;
}
}
}

View File

@@ -3,32 +3,27 @@ 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()
{
super(Switch.ROT_RIGHT);
}
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)
sw = (Switch4A) mat;
}
}
if (!value)
{
value=true;
sw.count++;
sw.room = item.room;
}
}
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) {
value = true;
sw.count++;
sw.room = item.room;
}
}
}

View File

@@ -3,32 +3,27 @@ package com.droidquest.items;
import com.droidquest.materials.Material;
import com.droidquest.materials.Switch;
public class Switch4C extends Switch
{
transient Switch4A sw = null;
public class Switch4C extends Switch {
private transient Switch4A sw = null;
public Switch4C()
{
super(Switch.ROT_DOWN);
}
public Switch4C() {
super(Switch.ROT_DOWN);
}
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)
sw = (Switch4A) mat;
}
}
if (!value)
{
value=true;
sw.count++;
sw.room = item.room;
}
}
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) {
value = true;
sw.count++;
sw.room = item.room;
}
}
}

View File

@@ -3,33 +3,28 @@ package com.droidquest.items;
import com.droidquest.materials.Material;
import com.droidquest.materials.Switch;
public class Switch4D extends Switch
{
transient Switch4A sw = null;
public class Switch4D extends Switch {
private transient Switch4A sw = null;
public Switch4D()
{
super(Switch.ROT_LEFT);
}
public Switch4D() {
super(Switch.ROT_LEFT);
}
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)
sw = (Switch4A) mat;
}
}
if (!value)
{
value=true;
sw.count++;
sw.room = item.room;
}
}
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) {
value = true;
sw.count++;
sw.room = item.room;
}
}
}

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