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,74 +2,42 @@ package com.droidquest;
//This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote. //This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote.
import java.io.*; import com.droidquest.levels.MainMenu;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import com.droidquest.avatars.GameCursor; import java.awt.event.*;
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.util.Set; 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 public class DQ extends JFrame implements ActionListener {
{ private RoomDisplay myRoom;
RoomDisplay myRoom;
public DQ () private DQ() {
{
// Constructor // Constructor
super("DroidQuest"); super("DroidQuest");
setSize(560+8,384+27+24); setSize(560 + 8, 384 + 27 + 24);
addWindowListener( new WindowAdapter() addWindowListener(new WindowAdapter() {
{ public void windowClosing(WindowEvent e) {
public void windowClosing(WindowEvent e) setVisible(false);
{ setVisible(false); dispose(); System.exit(0); } dispose();
System.exit(0);
}
}); });
setIconImage(new ImageIcon("images/helper0.gif").getImage()); setIconImage(new ImageIcon("images/helper0.gif").getImage());
Container contentPane = getContentPane(); Container contentPane = getContentPane();
myRoom = new RoomDisplay(); myRoom = new RoomDisplay();
myRoom.dq=this; myRoom.dq = this;
addFocusListener(new FocusAdapter() addFocusListener(new FocusAdapter() {
{ public void focusGained(FocusEvent e) {
public void focusGained(FocusEvent e)
{
myRoom.requestFocus(); myRoom.requestFocus();
} }
}); });
contentPane.add(myRoom); contentPane.add(myRoom);
myRoom.setLocation(0,0); myRoom.setLocation(0, 0);
JMenuBar menuBar; JMenuBar menuBar;
JMenu fileMenu; JMenu fileMenu;
@@ -84,7 +52,7 @@ public class DQ extends JFrame implements ActionListener
fileMenu.setMnemonic(KeyEvent.VK_F); fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu); menuBar.add(fileMenu);
menuItemSave = new JMenuItem("Save Level",KeyEvent.VK_S); menuItemSave = new JMenuItem("Save Level", KeyEvent.VK_S);
menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M); menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M);
menuItemSound = new JCheckBoxMenuItem("Sound", true); menuItemSound = new JCheckBoxMenuItem("Sound", true);
menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X); menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X);
@@ -98,72 +66,62 @@ public class DQ extends JFrame implements ActionListener
menuItemSound.addActionListener(this); menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this); menuItemExit.addActionListener(this);
try try {
{
System.setErr(System.out); System.setErr(System.out);
} }
catch (SecurityException e) {} catch (SecurityException e) {
}
} }
public static void main(String[] args) public static void main(String[] args) {
{
DQ dq = new DQ(); DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration(); GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds(); Rectangle bounds = gc.getBounds();
dq.setLocation(bounds.x + (bounds.width - 568)/2, dq.setLocation(bounds.x + (bounds.width - 568) / 2,
bounds.y + (bounds.height - 435)/2 ); bounds.y + (bounds.height - 435) / 2);
dq.setVisible(true); dq.setVisible(true);
} }
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e) {
{ if (e.getActionCommand().equals("Save Level")) {
if (e.getActionCommand() == "Save Level") FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
{
FileDialog fd = new FileDialog(this,"Save Level", FileDialog.SAVE);
fd.setDirectory("ROlevels"); fd.setDirectory("ROlevels");
fd.show(); fd.show();
System.out.println("Dialog returned with " System.out.println("Dialog returned with "
+ fd.getDirectory() + fd.getDirectory()
+ fd.getFile()); + fd.getFile());
if (fd.getFile() != null) if (fd.getFile() != null) {
myRoom.SaveLevel(fd.getDirectory()+fd.getFile()); myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
}
} }
if (e.getActionCommand() == "Main Menu") if (e.getActionCommand().equals("Main Menu")) {
{ int n = JOptionPane.showConfirmDialog(this, "Do you want to quit this level?",
int n = JOptionPane.showConfirmDialog(this,"Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION); "return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n==0) if (n == 0) {
{
myRoom.level.Empty(); myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom); myRoom.level = new MainMenu(myRoom);
myRoom.level.Init(); myRoom.level.Init();
} }
} }
if (e.getActionCommand() == "Sound") if (e.getActionCommand().equals("Sound")) {
{ myRoom.useSounds = ((JCheckBoxMenuItem) e.getSource()).getState();
myRoom.useSounds = ((JCheckBoxMenuItem)e.getSource()).getState(); if (!myRoom.useSounds) {
if (myRoom.useSounds==false)
{
Set<String> keys = myRoom.level.sounds.keySet(); Set<String> keys = myRoom.level.sounds.keySet();
Iterator<String> iterator = keys.iterator(); for (String soundFile : keys) {
while (iterator.hasNext()) {
String soundFile = iterator.next();
SoundClip soundClip = myRoom.level.sounds.get(soundFile); SoundClip soundClip = myRoom.level.sounds.get(soundFile);
soundClip.audioClip.stop(); soundClip.audioClip.stop();
} }
// for (int a=0; a<myRoom.level.sounds.size(); a++)
// {
// SoundClip sc = (SoundClip) myRoom.level.sounds.elementAt(a);
// sc.audioClip.stop();
// }
} }
} }
if (e.getActionCommand() == "Exit") if (e.getActionCommand().equals("Exit")) {
{ setVisible(false); dispose(); System.exit(0); } setVisible(false);
dispose();
System.exit(0);
}
} }
@@ -172,8 +130,6 @@ public class DQ extends JFrame implements ActionListener
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Updating Tutorial levels to 2.0 //Updating Tutorial levels to 2.0
// //
//ROTUT1 : Robot Anatomy //ROTUT1 : Robot Anatomy

View File

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

View File

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

View File

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

View File

@@ -1,66 +1,60 @@
package com.droidquest; 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.chipstuff.Port;
import com.droidquest.devices.Device; import com.droidquest.devices.Device;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
public class Wire implements Serializable import java.awt.*;
{ import java.io.IOException;
public transient Port fromPort; // Connected First import java.io.ObjectInputStream;
public transient Port toPort; // Connected 2nd import java.io.ObjectOutputStream;
public transient Port inPort; // Connected to Input import java.io.Serializable;
public transient Port outPort; // Connected to Output (Source of Value)
public boolean value;
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) public Wire() {
{ }
if (f.myDevice!=null)
{ public Wire(Port f, Port t) {
if (f.myDevice.room!=null) if (f.myDevice != null) {
{ if (f.myDevice.room != null) {
if (f.myDevice.room.wires==null) if (f.myDevice.room.wires == null) {
System.out.println("f.myDevice.room.wires is null"); System.out.println("f.myDevice.room.wires is null");
} }
else }
else {
System.out.println("f.myDevice.room is null"); System.out.println("f.myDevice.room is null");
} }
else }
else {
System.out.println("f.myDevice is null"); System.out.println("f.myDevice is null");
}
f.myDevice.room.wires.addElement(this); f.myDevice.room.wires.addElement(this);
f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND); f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND);
if (f.type == Port.TYPE_INPUT) if (f.type == Port.TYPE_INPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT)
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
outPort = toPort; outPort = toPort;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
@@ -69,27 +63,23 @@ public Wire(Port f, Port t)
return; return;
} }
} }
if (f.type == Port.TYPE_OUTPUT) if (f.type == Port.TYPE_OUTPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT)
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
inPort = toPort; inPort = toPort;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
@@ -98,12 +88,10 @@ public Wire(Port f, Port t)
return; return;
} }
} }
if (f.type == Port.TYPE_UNDEFINED) if (f.type == Port.TYPE_UNDEFINED) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT)
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
@@ -111,10 +99,9 @@ public Wire(Port f, Port t)
f.type = Port.TYPE_OUTPUT; f.type = Port.TYPE_OUTPUT;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
@@ -122,41 +109,49 @@ public Wire(Port f, Port t)
f.type = Port.TYPE_INPUT; f.type = Port.TYPE_INPUT;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{
fromPort = f; fromPort = f;
toPort=t; toPort = t;
f.myWire = this; f.myWire = this;
t.myWire = this; t.myWire = this;
return;
} }
} }
} }
protected void writeRef(ObjectOutputStream s) throws IOException void writeRef(ObjectOutputStream s) throws IOException {
{
Level level = fromPort.myDevice.level; Level level = fromPort.myDevice.level;
int a; int a;
s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device
a=0; while (((Device)fromPort.myDevice).ports[a] != fromPort) a++; a = 0;
while (((Device) fromPort.myDevice).ports[a] != fromPort) {
a++;
}
s.writeInt(a); // Index of fromport (as device.ports[?] s.writeInt(a); // Index of fromport (as device.ports[?]
s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device
a=0; while (((Device)toPort.myDevice).ports[a] != toPort) a++; a = 0;
while (((Device) toPort.myDevice).ports[a] != toPort) {
a++;
}
s.writeInt(a); // Index of toPort (as device.ports[?] s.writeInt(a); // Index of toPort (as device.ports[?]
s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device
a=0; while (((Device)inPort.myDevice).ports[a] != inPort) a++; a = 0;
while (((Device) inPort.myDevice).ports[a] != inPort) {
a++;
}
s.writeInt(a); // Index of inPort (as device.ports[?] s.writeInt(a); // Index of inPort (as device.ports[?]
s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device
a=0; while (((Device)outPort.myDevice).ports[a] != outPort) a++; a = 0;
while (((Device) outPort.myDevice).ports[a] != outPort) {
a++;
}
s.writeInt(a); // Index of outPort (as device.ports[?] s.writeInt(a); // Index of outPort (as device.ports[?]
} }
protected void readRef(ObjectInputStream s, Level level) throws IOException void readRef(ObjectInputStream s, Level level) throws IOException {
{
Device tempDevice; Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt()); tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()]; fromPort = tempDevice.ports[s.readInt()];
@@ -168,34 +163,28 @@ protected void readRef(ObjectInputStream s, Level level) throws IOException
outPort = tempDevice.ports[s.readInt()]; outPort = tempDevice.ports[s.readInt()];
} }
public void ConnectTo(Port t) public void ConnectTo(Port t) {
{
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND); fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);
if (toPort.myDevice == toPort.myDevice.level.solderingPen) if (toPort.myDevice == toPort.myDevice.level.solderingPen) {
{
toPort.value = false; toPort.value = false;
toPort.type = Port.TYPE_UNDEFINED; toPort.type = Port.TYPE_UNDEFINED;
toPort.myWire = null; toPort.myWire = null;
if (fromPort.type == Port.TYPE_INPUT) if (fromPort.type == Port.TYPE_INPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT)
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{ toPort = t;
toPort=t;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
outPort = toPort; outPort = toPort;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ toPort = t;
toPort=t;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
outPort = toPort; outPort = toPort;
@@ -203,24 +192,20 @@ public void ConnectTo(Port t)
return; return;
} }
} }
if (fromPort.type == Port.TYPE_OUTPUT) if (fromPort.type == Port.TYPE_OUTPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) toPort = t;
{
toPort=t;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
inPort = toPort; inPort = toPort;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ toPort = t;
toPort=t;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
inPort = toPort; inPort = toPort;
@@ -228,58 +213,48 @@ public void ConnectTo(Port t)
return; return;
} }
} }
if (fromPort.type == Port.TYPE_UNDEFINED) if (fromPort.type == Port.TYPE_UNDEFINED) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) toPort = t;
{
toPort=t;
t.myWire = this; t.myWire = this;
outPort = fromPort; outPort = fromPort;
inPort = toPort; inPort = toPort;
fromPort.type = Port.TYPE_OUTPUT; fromPort.type = Port.TYPE_OUTPUT;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{ toPort = t;
toPort=t;
t.myWire = this; t.myWire = this;
inPort = fromPort; inPort = fromPort;
outPort = toPort; outPort = toPort;
fromPort.type = Port.TYPE_INPUT; fromPort.type = Port.TYPE_INPUT;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ toPort = t;
toPort=t;
t.myWire = this; t.myWire = this;
return;
} }
} }
} }
else else {
{
fromPort.value = false; fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED; fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null; fromPort.myWire = null;
if (toPort.type == Port.TYPE_INPUT) if (toPort.type == Port.TYPE_INPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT)
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{ fromPort = t;
fromPort=t;
t.myWire = this; t.myWire = this;
inPort = toPort; inPort = toPort;
outPort = fromPort; outPort = fromPort;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ fromPort = t;
fromPort=t;
t.myWire = this; t.myWire = this;
inPort = toPort; inPort = toPort;
outPort = fromPort; outPort = fromPort;
@@ -287,24 +262,20 @@ public void ConnectTo(Port t)
return; return;
} }
} }
if (toPort.type == Port.TYPE_OUTPUT) if (toPort.type == Port.TYPE_OUTPUT) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) fromPort = t;
{
fromPort=t;
t.myWire = this; t.myWire = this;
outPort = toPort; outPort = toPort;
inPort = fromPort; inPort = fromPort;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{
Remove(); Remove();
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ fromPort = t;
fromPort=t;
t.myWire = this; t.myWire = this;
outPort = toPort; outPort = toPort;
inPort = fromPort; inPort = fromPort;
@@ -312,39 +283,33 @@ public void ConnectTo(Port t)
return; return;
} }
} }
if (toPort.type == Port.TYPE_UNDEFINED) if (toPort.type == Port.TYPE_UNDEFINED) {
{ if (t.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) fromPort = t;
{
fromPort=t;
t.myWire = this; t.myWire = this;
outPort = toPort; outPort = toPort;
inPort = fromPort; inPort = fromPort;
toPort.type = Port.TYPE_OUTPUT; toPort.type = Port.TYPE_OUTPUT;
return; return;
} }
if (t.type == Port.TYPE_OUTPUT) if (t.type == Port.TYPE_OUTPUT) {
{ fromPort = t;
fromPort=t;
t.myWire = this; t.myWire = this;
inPort = toPort; inPort = toPort;
outPort = fromPort; outPort = fromPort;
toPort.type = Port.TYPE_INPUT; toPort.type = Port.TYPE_INPUT;
return; return;
} }
if (t.type == Port.TYPE_UNDEFINED) if (t.type == Port.TYPE_UNDEFINED) {
{ fromPort = t;
fromPort=t;
t.myWire = this; t.myWire = this;
return;
} }
} }
} }
} }
public void Remove() public void Remove() {
{
Room room = fromPort.myDevice.room; Room room = fromPort.myDevice.room;
room.level.PlaySound(room, Level.DETATCHSOUND); room.level.PlaySound(room, Level.DETATCHSOUND);
@@ -359,18 +324,15 @@ public void Remove()
} }
public void Draw(Graphics g) public void Draw(Graphics g) {
{
g.setColor(Color.white); g.setColor(Color.white);
value = false; value = false;
if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value) if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value) {
{ g.setColor(new Color(255, 128, 0));
g.setColor(new Color(255,128,0));
value = true; value = true;
} }
if (toPort.type == Port.TYPE_OUTPUT && toPort.value) if (toPort.type == Port.TYPE_OUTPUT && toPort.value) {
{ g.setColor(new Color(255, 128, 0));
g.setColor(new Color(255,128,0));
value = true; value = true;
} }
@@ -382,8 +344,7 @@ public void Draw(Graphics g)
y1 = d1.height + fromPort.y; y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x; x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y; y2 = d2.height + toPort.y;
switch((((Device)fromPort.myDevice).rotation + fromPort.rotation)%4) switch ((((Device) fromPort.myDevice).rotation + fromPort.rotation) % 4) {
{
case 0: // Up case 0: // Up
x1 += 1; x1 += 1;
y1 += 1; y1 += 1;
@@ -401,8 +362,7 @@ public void Draw(Graphics g)
y1 -= 2; y1 -= 2;
break; break;
} }
switch((((Device)toPort.myDevice).rotation + toPort.rotation)%4) switch ((((Device) toPort.myDevice).rotation + toPort.rotation) % 4) {
{
case 0: // Up case 0: // Up
x2 += 1; x2 += 1;
y2 += 1; y2 += 1;
@@ -421,18 +381,21 @@ public void Draw(Graphics g)
break; break;
} }
g.fillRect(Math.min(x1,x2),y1,Math.abs(x1-x2),2); 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(x2, Math.min(y1, y2), 2, Math.abs(y1 - y2));
g.fillRect(x1,y1,2,2); g.fillRect(x1, y1, 2, 2);
g.fillRect(x2,y2,2,2); g.fillRect(x2, y2, 2, 2);
g.fillRect(x2,y1,2,2); g.fillRect(x2, y1, 2, 2);
} }
public Port otherPort(Port p) public Port otherPort(Port p) {
{ if (fromPort == p) {
if (fromPort == p) return toPort; return toPort;
if (toPort == p) return fromPort; }
if (toPort == p) {
return fromPort;
}
return null; return null;
} }

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,153 +1,142 @@
package com.droidquest.avatars; 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.Room;
import com.droidquest.devices.Device; import com.droidquest.devices.Device;
import com.droidquest.devices.GenericChip; import com.droidquest.devices.GenericChip;
import com.droidquest.devices.SmallChip; import com.droidquest.devices.SmallChip;
import com.droidquest.items.GenericRobot;
import com.droidquest.items.Item; import com.droidquest.items.Item;
import com.droidquest.items.ToolBox; import com.droidquest.items.ToolBox;
public class LabCursor extends Item import javax.swing.*;
{ import java.awt.*;
public boolean hot; 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; public LabCursor(int X, int Y, Room r) {
hot=false; x = X;
room=r; y = Y;
width=28; height=32; hot = false;
room = r;
width = 28;
height = 32;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[2]; icons = new ImageIcon[2];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); 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[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to LabCursor Image"); System.out.println("Could not get Graphics pointer to LabCursor Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g;
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0,0,width,height); g.fillRect(0, 0, width, height);
try try {
{
g = icons[1].getImage().getGraphics(); g = icons[1].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to LabCursor Image"); System.out.println("Could not get Graphics pointer to LabCursor Image");
return; return;
} }
g2 = (Graphics2D) g; g.setColor(new Color(255, 128, 0));
g.setColor(new Color(255,128,0)); g.fillRect(0, 0, width, height);
g.fillRect(0,0,width,height); if (hot) {
if (hot)
currentIcon = icons[1].getImage(); currentIcon = icons[1].getImage();
else }
else {
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
} }
public boolean KeyUp(KeyEvent e) public boolean CanBePickedUp(Item i) {
{ return !(i instanceof GenericRobot);
if (e.getKeyCode() == e.VK_L) }
{
if (carrying != null) public boolean KeyUp(KeyEvent e) {
if (carrying.getClass().toString().endsWith("SmallChip")) if (e.getKeyCode() == KeyEvent.VK_L) {
{ if (carrying != null) {
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Load Chip", FileDialog.LOAD); if (carrying instanceof SmallChip) {
FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
fd.setDirectory("chips"); fd.setDirectory("chips");
fd.show(); fd.show();
System.out.println("Dialog returned with " System.out.println("Dialog returned with "
+ fd.getDirectory() + fd.getDirectory()
+ fd.getFile()); + fd.getFile());
if (fd.getFile() != null) if (fd.getFile() != null) {
{ ((SmallChip) carrying).Empty();
((SmallChip)carrying).Empty(); ((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
((SmallChip)carrying).LoadChip(fd.getDirectory()+fd.getFile());
} }
} }
} }
if (e.getKeyCode() == e.VK_H) }
{ else if (e.getKeyCode() == KeyEvent.VK_H) {
hot = !hot; hot = !hot;
if (hot) if (hot) {
currentIcon = icons[1].getImage(); currentIcon = icons[1].getImage();
else }
else {
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
}
return false; return false;
} }
if (e.getKeyCode() == e.VK_S) else if (e.getKeyCode() == KeyEvent.VK_S) {
{ if (level.solderingPen == null) {
if (level.solderingPen == null) return false; return false;
if (carrying != null) }
if (carrying.getClass().toString().endsWith("SmallChip")) if (carrying != null) {
{ if (carrying instanceof SmallChip) {
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Save Chip", FileDialog.SAVE); FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
fd.setDirectory("chips"); fd.setDirectory("chips");
fd.show(); fd.show();
System.out.println("Dialog returned with " System.out.println("Dialog returned with "
+ fd.getDirectory() + fd.getDirectory()
+ fd.getFile()); + fd.getFile());
if (fd.getFile() != null) if (fd.getFile() != null) {
((SmallChip)carrying).SaveChip(fd.getDirectory()+fd.getFile()); ((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
}
return false; return false;
} }
if (carrying != null) }
if (carrying != null) {
Drops(); Drops();
}
level.solderingPen.x = x; level.solderingPen.x = x;
level.solderingPen.y = y; level.solderingPen.y = y;
level.solderingPen.room = room; level.solderingPen.room = room;
room = null; room = null;
if (level.currentViewer == level.player) if (level.currentViewer == level.player) {
level.currentViewer=level.solderingPen; level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen; level.player = level.solderingPen;
if (level.remote != null) if (level.remote != null) {
if (level.remote.carriedBy != null) if (level.remote.carriedBy != null) {
{
level.remote.carriedBy = level.player; level.remote.carriedBy = level.player;
} }
} }
if (e.getKeyCode() == e.VK_R) }
{ else if (e.getKeyCode() == KeyEvent.VK_R) {
if (level.remote == null) return false; if (level.remote == null) {
if (level.remote.carriedBy == null) return false;
{ // Summon Remote }
if (level.remote.carriedBy == null) { // Summon Remote
level.remote.x = 28; level.remote.x = 28;
level.remote.y = -20; level.remote.y = -20;
level.remote.carriedBy = level.player; level.remote.carriedBy = level.player;
level.remote.room = level.player.room; level.remote.room = level.player.room;
level.electricity = true; level.electricity = true;
} }
else else { // Hide Remote
{ // Hide Remote
level.remote.carriedBy = null; level.remote.carriedBy = null;
level.remote.room = null; level.remote.room = null;
level.electricity = false; level.electricity = false;
@@ -162,200 +151,202 @@ public boolean KeyUp(KeyEvent e)
// level.currentViewer=level.remote; // level.currentViewer=level.remote;
// level.player = level.remote; // level.player = level.remote;
} }
if (e.getKeyCode() == e.VK_P) else if (e.getKeyCode() == KeyEvent.VK_P) {
{ if (level.paintbrush == null) {
if (level.paintbrush == null) return false; return false;
if (carrying != null) }
Drops(); if (carrying != null) {
level.paintbrush.x = (x/28)*28; Drops();
level.paintbrush.y = (y/32)*32; }
level.paintbrush.room = room; level.paintbrush.x = (x / 28) * 28;
room = null; level.paintbrush.y = (y / 32) * 32;
if (level.currentViewer == level.player) level.paintbrush.room = room;
level.currentViewer=level.paintbrush; room = null;
level.player = level.paintbrush; if (level.currentViewer == level.player) {
} level.currentViewer = level.paintbrush;
if (e.getKeyCode() == e.VK_T) }
{ level.player = level.paintbrush;
if (level.toolbox == null) return false; }
if (level.toolbox.room != room) else if (e.getKeyCode() == KeyEvent.VK_T) {
{ if (level.toolbox == null) {
// Summon Toolbox return false;
if (carrying != null) return false; }
if (((ToolBox)level.toolbox).open) ((ToolBox)level.toolbox).Toggle(); if (level.toolbox.room != room) {
level.toolbox.room = room; // Summon Toolbox
level.toolbox.x = x+28; if (carrying != null) {
level.toolbox.y = y+6; return false;
PicksUp(level.toolbox); }
} if (((ToolBox) level.toolbox).open) {
else ((ToolBox) level.toolbox).Toggle();
((ToolBox)level.toolbox).Toggle(); }
} level.toolbox.room = room;
if (e.getKeyCode() == e.VK_SLASH) level.toolbox.x = x + 28;
{ level.toolbox.y = y + 6;
if (carrying != null) PicksUp(level.toolbox);
if (carrying.getClass().toString().endsWith("Chip")) }
{ else {
((GenericChip)carrying).ShowText(true); ((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; return false;
} }
if (level.helpCam == null) return false;
level.player = level.helpCam; level.player = level.helpCam;
level.currentViewer = level.helpCam; level.currentViewer = level.helpCam;
} }
if (e.getKeyCode() == e.VK_RIGHT) else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveRight(e.isControlDown()); MoveRight(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_LEFT) else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveLeft(e.isControlDown()); MoveLeft(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_UP) else if (e.getKeyCode() == KeyEvent.VK_UP) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveUp(e.isControlDown()); MoveUp(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_DOWN) else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveDown(e.isControlDown()); MoveDown(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_SPACE) else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
{ if (carrying != null) {
if (carrying != null)
Drops(); Drops();
else }
{ else {
Item item = level.FindNearestItem(level.gameCursor); Item item = level.FindNearestItem(level.gameCursor);
if (item != null) if (item != null) {
if (item.CanBePickedUp(level.gameCursor)) if (item.CanBePickedUp(level.gameCursor)) {
PicksUp(item); PicksUp(item);
} }
}
}
return false; return false;
} }
if (e.getKeyCode() == e.VK_CLOSE_BRACKET) else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
{ if (carrying != null) {
if (carrying !=null) if (carrying.isDevice()) {
if (carrying.isDevice())
((Device) carrying).rotate(1); ((Device) carrying).rotate(1);
}
}
return false; return false;
} }
if (e.getKeyCode() == e.VK_OPEN_BRACKET) else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
{ if (carrying != null) {
if (carrying !=null) if (carrying.isDevice()) {
if (carrying.isDevice())
((Device) carrying).rotate(-1); ((Device) carrying).rotate(-1);
}
}
return false; return false;
} }
if (e.getKeyCode() == e.VK_E) else if (e.getKeyCode() == KeyEvent.VK_E) {
{
boolean found=false;
Item item = level.FindNearestItem(this); Item item = level.FindNearestItem(this);
if (item!=null) if (item != null) {
if (item.InternalRoom!=null) if (item.InternalRoom != null) {
if (Overlaps(item)) if (Overlaps(item)) {
if (!item.OverWall()) if (!item.OverWall()) {
{
int newX = 280; // 10 * 28 int newX = 280; // 10 * 28
int newY = 176; // 5.5 * 32 int newY = 176; // 5.5 * 32
x = newX; x = newX;
y = newY; y = newY;
SetRoom(item.InternalRoom); SetRoom(item.InternalRoom);
found=true;
} }
} }
if (e.getKeyCode() == e.VK_X) }
{ }
if (room.portalItem!=null) }
{ else if (e.getKeyCode() == KeyEvent.VK_X) {
if (room != null && room.portalItem != null) {
Dimension d = room.portalItem.GetXY(); Dimension d = room.portalItem.GetXY();
int newX = d.width int newX = d.width
+ room.portalItem.getWidth()/2 + room.portalItem.getWidth() / 2
- width/2; - width / 2;
int newY = d.height int newY = d.height
+ room.portalItem.getHeight()/4*2 + room.portalItem.getHeight() / 4 * 2
- height/2; - height / 2;
x = newX; x = newX;
y = newY; y = newY;
SetRoom(room.portalItem.room); SetRoom(room.portalItem.room);
level.currentViewer = level.player; level.currentViewer = level.player;
} }
} else if (e.getKeyCode() == KeyEvent.VK_F) {
if (carrying != null) {
if (carrying instanceof Device) {
((Device) carrying).flip();
} }
if (e.getKeyCode() == e.VK_F)
{
if (carrying != null)
if (carrying instanceof Device)
((Device)carrying).flip();
} }
if (e.getKeyCode() == e.VK_M) } else if (e.getKeyCode() == KeyEvent.VK_M) {
{
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
long freemem = runtime.freeMemory(); long freemem = runtime.freeMemory();
long totalmem = runtime.totalMemory(); long totalmem = runtime.totalMemory();
System.out.println("Total Memory = "+ totalmem System.out.println("Total Memory = " + totalmem
+ ", (" + totalmem/1024 + "K), (" + ", (" + totalmem / 1024 + "K), ("
+ totalmem/1024/1024 + "M)"); + totalmem / 1024 / 1024 + "M)");
System.out.println("Free Memory = "+ freemem System.out.println("Free Memory = " + freemem
+ ", (" + freemem/1024 + "K), (" + ", (" + freemem / 1024 + "K), ("
+ freemem/1024/1024 + "M)"); + freemem / 1024 / 1024 + "M)");
} }
return false; return false;
} }
public boolean KeyDown(KeyEvent e) public boolean KeyDown(KeyEvent e) {
{ if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
if (e.getKeyCode() == e.VK_RIGHT)
{
repeating++; repeating++;
if (repeating>10) if (repeating > 10) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveRight(e.isControlDown()); MoveRight(e.isControlDown());
}
return true; return true;
} }
return false; return false;
} }
if (e.getKeyCode() == e.VK_LEFT) if (e.getKeyCode() == KeyEvent.VK_LEFT) {
{
repeating++; repeating++;
if (repeating>10) if (repeating > 10) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveLeft(e.isControlDown()); MoveLeft(e.isControlDown());
}
return true; return true;
} }
return false; return false;
} }
if (e.getKeyCode() == e.VK_UP) if (e.getKeyCode() == KeyEvent.VK_UP) {
{
repeating++; repeating++;
if (repeating>10) if (repeating > 10) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveUp(e.isControlDown()); MoveUp(e.isControlDown());
}
return true; return true;
} }
return false; return false;
} }
if (e.getKeyCode() == e.VK_DOWN) if (e.getKeyCode() == KeyEvent.VK_DOWN) {
{
repeating++; repeating++;
if (repeating>10) if (repeating > 10) {
{ if (carriedBy == null) {
if (carriedBy==null)
MoveDown(e.isControlDown()); MoveDown(e.isControlDown());
}
return true; return true;
} }
return false; return false;
@@ -363,14 +354,11 @@ public boolean KeyDown(KeyEvent e)
return false; return false;
} }
public void MoveUp(boolean nudge) public void MoveUp(boolean nudge) {
{
Item item = level.FindNearestItem(this); Item item = level.FindNearestItem(this);
if (item != null) if (item != null) {
{ if (item.InternalRoom != null) {
if (item.InternalRoom != null) if (item.UpEnterOverlap(this)) {
if (item.UpEnterOverlap(this))
{
int newX = 280; // 10 * 28 int newX = 280; // 10 * 28
int newY = 320; // 10 * 32 int newY = 320; // 10 * 32
x = newX; x = newX;
@@ -378,17 +366,15 @@ public void MoveUp(boolean nudge)
SetRoom(item.InternalRoom); SetRoom(item.InternalRoom);
} }
} }
super.MoveUp( nudge); }
super.MoveUp(nudge);
} }
public void MoveDown(boolean nudge) public void MoveDown(boolean nudge) {
{
Item item = level.FindNearestItem(this); Item item = level.FindNearestItem(this);
if (item != null) if (item != null) {
{ if (item.InternalRoom != null) {
if (item.InternalRoom != null) if (item.DownEnterOverlap(this)) {
if (item.DownEnterOverlap(this))
{
int newX = 280; // 10 * 28 int newX = 280; // 10 * 28
int newY = 0; // 0 * 32 int newY = 0; // 0 * 32
x = newX; x = newX;
@@ -396,17 +382,15 @@ public void MoveDown(boolean nudge)
SetRoom(item.InternalRoom); SetRoom(item.InternalRoom);
} }
} }
super.MoveDown( nudge); }
super.MoveDown(nudge);
} }
public void MoveLeft(boolean nudge) public void MoveLeft(boolean nudge) {
{
Item item = level.FindNearestItem(this); Item item = level.FindNearestItem(this);
if (item != null) if (item != null) {
{ if (item.InternalRoom != null) {
if (item.InternalRoom != null) if (item.LeftEnterOverlap(this)) {
if (item.LeftEnterOverlap(this))
{
int newX = 532; // 19 * 28 int newX = 532; // 19 * 28
int newY = 176; // 5.5 * 32 int newY = 176; // 5.5 * 32
x = newX; x = newX;
@@ -414,18 +398,15 @@ public void MoveLeft(boolean nudge)
SetRoom(item.InternalRoom); SetRoom(item.InternalRoom);
} }
} }
super.MoveLeft( nudge); }
super.MoveLeft(nudge);
} }
public void MoveRight(boolean nudge) public void MoveRight(boolean nudge) {
{
Item item = level.FindNearestItem(this); Item item = level.FindNearestItem(this);
if (item != null) if (item != null) {
{ if (item.InternalRoom != null) {
if (item.InternalRoom != null) if (item.RightEnterOverlap(this)) {
{
if (item.RightEnterOverlap(this))
{
int newX = 0; // 0 * 28 int newX = 0; // 0 * 28
int newY = 176; // 5.5 * 32 int newY = 176; // 5.5 * 32
x = newX; x = newX;
@@ -434,7 +415,7 @@ public void MoveRight(boolean nudge)
} }
} }
} }
super.MoveRight( nudge); super.MoveRight(nudge);
} }
} }

View File

@@ -1,20 +1,18 @@
package com.droidquest.avatars; package com.droidquest.avatars;
import java.awt.Color; import com.droidquest.items.BlueRobot;
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.Item; import com.droidquest.items.Item;
import com.droidquest.items.OrangeRobot;
import com.droidquest.items.WhiteRobot;
import com.droidquest.materials.Material; import com.droidquest.materials.Material;
import com.droidquest.materials.RobotBlocker; import com.droidquest.materials.RobotBlocker;
public class PaintBrush extends Item import javax.swing.*;
{ import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
public class PaintBrush extends Item {
// The Paintbrush works just like the original, except it allows // The Paintbrush works just like the original, except it allows
// differnt color paints for differnt materials. Pressing 'P' as the // differnt color paints for differnt materials. Pressing 'P' as the
// Paintbrush switches the Material Settings. // Paintbrush switches the Material Settings.
@@ -25,253 +23,280 @@ public class PaintBrush extends Item
// Undetectable, blocks White White // Undetectable, blocks White White
// Undetectable, blocks Blue Blue // Undetectable, blocks Blue Blue
int emptyIndex=0; private int emptyIndex = 0;
int paintIndex; // Which paintMats[] am I using? private int paintIndex; // Which paintMats[] am I using?
transient Material[] paintMats; private transient Material[] paintMats;
int matIndex; // index of chosen paintMax in level.materials private int matIndex; // index of chosen paintMax in level.materials
public PaintBrush() public PaintBrush() {
{ width = 28;
width=28; height=32; height = 32;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[5]; icons = new ImageIcon[5];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); 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[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[2]= 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[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[4]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[4] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
Graphics2D g2; Graphics2D g2;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
for (int a=0; a<5; a++) for (int a = 0; a < 5; a++) {
{ try {
try
{
g = icons[a].getImage().getGraphics(); g = icons[a].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to PaintBrush Image"); System.out.println("Could not get Graphics pointer to PaintBrush Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
switch(a) switch (a) {
{ case 0:
case 0: g.setColor(new Color(192,0,0)); g.setColor(new Color(192, 0, 0));
break; break;
case 1: g.setColor(new Color(0,192,0)); case 1:
g.setColor(new Color(0, 192, 0));
break; break;
case 2: g.setColor(new Color(192,96,0)); case 2:
g.setColor(new Color(192, 96, 0));
break; break;
case 3: g.setColor(new Color(192,192,192)); case 3:
g.setColor(new Color(192, 192, 192));
break; break;
case 4: g.setColor(new Color(0,0,192)); case 4:
g.setColor(new Color(0, 0, 192));
break; break;
} }
g2.fillRect(0,0,28,18); g2.fillRect(0, 0, 28, 18);
g2.fillRect(4,18,20,2); g2.fillRect(4, 18, 20, 2);
g2.fillRect(8,20,12,10); g2.fillRect(8, 20, 12, 10);
g2.fillRect(12,30,4,2); g2.fillRect(12, 30, 4, 2);
g.setColor(Color.black); g.setColor(Color.black);
g2.fillRect(0,12,28,2); g2.fillRect(0, 12, 28, 2);
g2.fillRect(12,26,4,2); g2.fillRect(12, 26, 4, 2);
} }
currentIcon=icons[0].getImage(); currentIcon = icons[0].getImage();
paintMats = new Material[5]; paintMats = new Material[5];
emptyIndex = 0; emptyIndex = 0;
paintMats[0] = Material.FindSimiliar(new Material(Color.red, false, true)); paintMats[0] = Material.FindSimiliar(new Material(Color.red, false, true));
paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false)); paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false));
Item robot=null; Item robot = null;
for (int a=0; a<level.items.size(); a++)
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("OrangeRobot")) for(Item item : level.items) {
robot = (GenericRobot) level.items.elementAt(a); if(item instanceof OrangeRobot) {
if (robot==null) robot = item;
}
}
if (robot == null) {
System.out.println("Create paintbrush AFTER creating robots."); 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++) paintMats[2] = Material.FindSimiliar(new RobotBlocker(robot, new Color(255, 128, 0)));
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("WhiteRobot"))
robot = (GenericRobot) level.items.elementAt(a); for (Item item : level.items) {
if(item instanceof WhiteRobot) {
robot = item;
}
}
paintMats[3] = Material.FindSimiliar(new RobotBlocker(robot, Color.white)); 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")) for(Item item : level.items) {
robot = (GenericRobot) level.items.elementAt(a); if(item instanceof BlueRobot) {
robot = item;
}
}
paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue)); paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue));
paintIndex=0; paintIndex = 0;
matIndex = level.materials.indexOf(paintMats[paintIndex]); matIndex = level.materials.indexOf(paintMats[paintIndex]);
} }
public boolean KeyUp(KeyEvent e) public boolean KeyUp(KeyEvent e) {
{ if (e.getKeyCode() == KeyEvent.VK_C) {
if (e.getKeyCode() == e.VK_C)
{
level.gameCursor.x = x; level.gameCursor.x = x;
level.gameCursor.y = y; level.gameCursor.y = y;
level.gameCursor.room = room; level.gameCursor.room = room;
room = null; room = null;
if (level.currentViewer == level.player) if (level.currentViewer == level.player) {
level.currentViewer=level.gameCursor; level.currentViewer = level.gameCursor;
}
level.player = level.gameCursor; level.player = level.gameCursor;
} }
if (e.getKeyCode() == e.VK_S) if (e.getKeyCode() == KeyEvent.VK_S) {
{ if (level.solderingPen == null) {
if (level.solderingPen == null) return false; return false;
}
level.solderingPen.x = x; level.solderingPen.x = x;
level.solderingPen.y = y; level.solderingPen.y = y;
level.solderingPen.room = room; level.solderingPen.room = room;
room = null; room = null;
if (level.currentViewer == level.player) if (level.currentViewer == level.player) {
level.currentViewer=level.solderingPen; level.currentViewer = level.solderingPen;
}
level.player = level.solderingPen; level.player = level.solderingPen;
} }
if (e.getKeyCode() == e.VK_R) if (e.getKeyCode() == KeyEvent.VK_R) {
{ if (level.remote == null) {
if (level.remote == null) return false; return false;
}
level.remote.x = x; level.remote.x = x;
level.remote.y = y; level.remote.y = y;
level.remote.room = room; level.remote.room = room;
room = null; room = null;
if (level.currentViewer == level.player) if (level.currentViewer == level.player) {
level.currentViewer=level.remote; level.currentViewer = level.remote;
}
level.player = level.remote; level.player = level.remote;
} }
if (e.getKeyCode() == e.VK_SLASH) if (e.getKeyCode() == KeyEvent.VK_SLASH) {
{ if (level.helpCam == null) {
if (level.helpCam == null) return false; return false;
}
level.player = level.helpCam; level.player = level.helpCam;
level.currentViewer = level.helpCam; level.currentViewer = level.helpCam;
} }
if (e.getKeyCode() == e.VK_RIGHT) if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
{ if (e.isShiftDown()) {
if (e.isShiftDown())
SetRoom(room.rightRoom); SetRoom(room.rightRoom);
if (carriedBy==null) }
if (carriedBy == null) {
MoveRight(e.isControlDown()); MoveRight(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_LEFT) if (e.getKeyCode() == KeyEvent.VK_LEFT) {
{ if (e.isShiftDown()) {
if (e.isShiftDown())
SetRoom(room.leftRoom); SetRoom(room.leftRoom);
if (carriedBy==null) }
if (carriedBy == null) {
MoveLeft(e.isControlDown()); MoveLeft(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_UP) if (e.getKeyCode() == KeyEvent.VK_UP) {
{ if (e.isShiftDown()) {
if (e.isShiftDown())
SetRoom(room.upRoom); SetRoom(room.upRoom);
if (carriedBy==null) }
if (carriedBy == null) {
MoveUp(e.isControlDown()); MoveUp(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_DOWN) if (e.getKeyCode() == KeyEvent.VK_DOWN) {
{ if (e.isShiftDown()) {
if (e.isShiftDown())
SetRoom(room.downRoom); SetRoom(room.downRoom);
if (carriedBy==null) }
if (carriedBy == null) {
MoveDown(e.isControlDown()); MoveDown(e.isControlDown());
repeating=0; }
repeating = 0;
return true; return true;
} }
if (e.getKeyCode() == e.VK_P) if (e.getKeyCode() == KeyEvent.VK_P) {
{
paintIndex++; paintIndex++;
if (paintIndex==5) paintIndex=0; if (paintIndex == 5) {
matIndex = level.materials.indexOf(paintMats[paintIndex]); paintIndex = 0;
currentIcon=icons[paintIndex].getImage(); }
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);
} }
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; return false;
} }
public void MoveUp(boolean nudge) public void MoveUp(boolean nudge) {
{
int dist = 32; int dist = 32;
if (nudge) dist = 2; if (nudge) {
y=y-dist; dist = 2;
if (y<0) }
{ y = y - dist;
if (room.getUpRoom(this) != null) if (y < 0) {
{ // change Rooms if (room.getUpRoom(this) != null) { // change Rooms
y=y+384; y = y + 384;
SetRoom(room.getUpRoom(this)); SetRoom(room.getUpRoom(this));
} }
else // stop at top else // stop at top
y=0; {
y = 0;
}
} }
} }
public void MoveDown(boolean nudge) public void MoveDown(boolean nudge) {
{
int dist = 32; int dist = 32;
if (nudge) dist = 2; if (nudge) {
y=y+dist; dist = 2;
if (y>383) }
{ y = y + dist;
if (room.getDownRoom(this) != null) if (y > 383) {
{ // change Rooms if (room.getDownRoom(this) != null) { // change Rooms
y=y-384; y = y - 384;
SetRoom(room.getDownRoom(this)); SetRoom(room.getDownRoom(this));
} }
else // stop at bottom else // stop at bottom
y=384-32; {
y = 384 - 32;
}
} }
} }
public void MoveLeft(boolean nudge) public void MoveLeft(boolean nudge) {
{
int dist = 28; int dist = 28;
if (nudge) dist = 2; if (nudge) {
x=x-dist; dist = 2;
if (x<0) }
{ x = x - dist;
if (room.getLeftRoom(this) != null) if (x < 0) {
{ // change Rooms if (room.getLeftRoom(this) != null) { // change Rooms
x=x+560; x = x + 560;
SetRoom(room.getLeftRoom(this)); SetRoom(room.getLeftRoom(this));
} }
else // stop at left else // stop at left
x=0; {
x = 0;
}
} }
} }
public void MoveRight(boolean nudge) public void MoveRight(boolean nudge) {
{
int dist = 28; int dist = 28;
if (nudge) dist = 2; if (nudge) {
x=x+dist; dist = 2;
if (x>559) }
{ x = x + dist;
if (room.getRightRoom(this) != null) if (x > 559) {
{ // change Rooms if (room.getRightRoom(this) != null) { // change Rooms
x=x-560; x = x - 560;
SetRoom(room.getRightRoom(this)); SetRoom(room.getRightRoom(this));
} }
else // stop at right else // stop at right
x=560-28; {
x = 560 - 28;
}
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,331 +1,314 @@
package com.droidquest.devices; package com.droidquest.devices;
import java.awt.Color; import com.droidquest.Room;
import java.awt.Font; import com.droidquest.chipstuff.Port;
import java.awt.FontMetrics; import com.droidquest.items.Item;
import java.awt.Graphics2D; 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.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import javax.swing.ImageIcon; public class Prototype32Chip extends GenericChip {
private transient PortDevice[] portdevices;
import com.droidquest.Room; public Prototype32Chip(int X, int Y, Room r) {
import com.droidquest.chipstuff.Port; x = X;
import com.droidquest.items.Item; y = Y;
import com.droidquest.materials.ChipTrash; room = r;
import com.droidquest.materials.Material; width = 80;
height = 80;
public class Prototype32Chip extends GenericChip
{
transient PortDevice portdevices[];
public Prototype32Chip(int X, int Y, Room r)
{
x=X; y=Y; room =r;
width=80; height=80;
GenerateIcons(); 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(); InternalRoom = new Room();
int[][] table = { InternalRoom.RoomArray = new int[][]{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {1, 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,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} {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); Material mat1 = new Material(Color.blue, false, true);
level.materials.addElement(mat1); level.materials.addElement(mat1);
int mat1Index = level.materials.size()-1; int mat1Index = level.materials.size() - 1;
for (int rY=0; rY<12; rY++) for (int rY = 0; rY < 12; rY++) {
for (int rX=0; rX<20; rX++) for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index; if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.GenerateArray(); InternalRoom.GenerateArray();
InternalRoom.portalItem = this; InternalRoom.portalItem = this;
level.rooms.addElement(InternalRoom); level.rooms.addElement(InternalRoom);
portdevices = new PortDevice[32]; portdevices = new PortDevice[32];
portdevices[0] = new PortDevice(16,2*32,InternalRoom,28,Port.TYPE_UNDEFINED); 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[1] = new PortDevice(16, 3 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[2] = new PortDevice(16,4*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[3] = new PortDevice(16, 5 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[4] = new PortDevice(16,6*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[5] = new PortDevice(16, 7 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[6] = new PortDevice(16,8*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[7] = new PortDevice(16, 9 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[8] = new PortDevice(3*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[9] = new PortDevice(5 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[10] = new PortDevice(7*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[11] = new PortDevice(9 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[12] = new PortDevice(11*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[13] = new PortDevice(13 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[14] = new PortDevice(15*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[15] = new PortDevice(17 * 28, 320, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[16] = new PortDevice(500,9*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[17] = new PortDevice(500, 8 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[18] = new PortDevice(500,7*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[19] = new PortDevice(500, 6 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[20] = new PortDevice(500,5*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[21] = new PortDevice(500, 4 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[22] = new PortDevice(500,3*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[23] = new PortDevice(500, 2 * 32, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[24] = new PortDevice(17*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[25] = new PortDevice(15 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[26] = new PortDevice(13*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[27] = new PortDevice(11 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[28] = new PortDevice(9*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[29] = new PortDevice(7 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
portdevices[30] = new PortDevice(5*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[31] = new PortDevice(3 * 28, 12, InternalRoom, 28, Port.TYPE_UNDEFINED);
for (int a=0; a<8; a++) for (int a = 0; a < 8; a++) {
{
portdevices[a].rotate(1); portdevices[a].rotate(1);
portdevices[a+16].rotate(-1); portdevices[a + 16].rotate(-1);
portdevices[a+24].rotate(1); portdevices[a + 24].rotate(1);
portdevices[a+24].rotate(1); portdevices[a + 24].rotate(1);
} }
for (int a=0; a<32; a++) for (int a = 0; a < 32; a++) {
level.items.addElement(portdevices[a]); level.items.addElement(portdevices[a]);
} }
}
public void GenerateIcons() public void GenerateIcons() {
{ if (ports == null) {
// super.GenerateIcons();
if (ports==null)
{
ports = new Port[32]; ports = new Port[32];
ports[0] = new Port( 1, 8,Port.TYPE_UNDEFINED,0,Port.ROT_LEFT,this); 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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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[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); ports[31] = new Port(7, 1, Port.TYPE_UNDEFINED, 0, Port.ROT_UP, this);
} }
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(3,3,72,72); g.fillRect(3, 3, 72, 72);
g.fillRect(1,7,2,2); g.fillRect(1, 7, 2, 2);
g.fillRect(1,15,2,2); g.fillRect(1, 15, 2, 2);
g.fillRect(1,23,2,2); g.fillRect(1, 23, 2, 2);
g.fillRect(1,31,2,2); g.fillRect(1, 31, 2, 2);
g.fillRect(1,39,2,2); g.fillRect(1, 39, 2, 2);
g.fillRect(1,47,2,2); g.fillRect(1, 47, 2, 2);
g.fillRect(1,55,2,2); g.fillRect(1, 55, 2, 2);
g.fillRect(1,63,2,2); g.fillRect(1, 63, 2, 2);
g.fillRect(7,75,2,2); g.fillRect(7, 75, 2, 2);
g.fillRect(15,75,2,2); g.fillRect(15, 75, 2, 2);
g.fillRect(23,75,2,2); g.fillRect(23, 75, 2, 2);
g.fillRect(31,75,2,2); g.fillRect(31, 75, 2, 2);
g.fillRect(39,75,2,2); g.fillRect(39, 75, 2, 2);
g.fillRect(47,75,2,2); g.fillRect(47, 75, 2, 2);
g.fillRect(55,75,2,2); g.fillRect(55, 75, 2, 2);
g.fillRect(63,75,2,2); g.fillRect(63, 75, 2, 2);
g.fillRect(75,63,2,2); g.fillRect(75, 63, 2, 2);
g.fillRect(75,55,2,2); g.fillRect(75, 55, 2, 2);
g.fillRect(75,47,2,2); g.fillRect(75, 47, 2, 2);
g.fillRect(75,39,2,2); g.fillRect(75, 39, 2, 2);
g.fillRect(75,31,2,2); g.fillRect(75, 31, 2, 2);
g.fillRect(75,23,2,2); g.fillRect(75, 23, 2, 2);
g.fillRect(75,15,2,2); g.fillRect(75, 15, 2, 2);
g.fillRect(75,7,2,2); g.fillRect(75, 7, 2, 2);
g.fillRect(63,1,2,2); g.fillRect(63, 1, 2, 2);
g.fillRect(55,1,2,2); g.fillRect(55, 1, 2, 2);
g.fillRect(47,1,2,2); g.fillRect(47, 1, 2, 2);
g.fillRect(39,1,2,2); g.fillRect(39, 1, 2, 2);
g.fillRect(31,1,2,2); g.fillRect(31, 1, 2, 2);
g.fillRect(23,1,2,2); g.fillRect(23, 1, 2, 2);
g.fillRect(15,1,2,2); g.fillRect(15, 1, 2, 2);
g.fillRect(7,1,2,2); g.fillRect(7, 1, 2, 2);
g.setColor(Color.black); g.setColor(Color.black);
if (label != null) if (label != null) {
{
g.setColor(Color.black); g.setColor(Color.black);
Font font = new Font("Courier",Font.BOLD, 20); Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font); g.setFont(font);
FontMetrics fm = g.getFontMetrics(); FontMetrics fm = g.getFontMetrics();
int X = fm.stringWidth(label); int X = fm.stringWidth(label);
g.drawString(label, 52-X/2, 32); g.drawString(label, 52 - X / 2, 32);
} }
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public void Decorate() public void Decorate() {
{}
public void writeRef(ObjectOutputStream s) throws IOException
{
super.writeRef(s);
for (int a=0; a<32; a++)
s.writeInt(level.items.indexOf(portdevices[a]));
} }
public void readRef(ObjectInputStream s) throws IOException public void writeRef(ObjectOutputStream s) throws IOException {
{ super.writeRef(s);
for (int a = 0; a < 32; a++) {
s.writeInt(level.items.indexOf(portdevices[a]));
}
}
public void readRef(ObjectInputStream s) throws IOException {
super.readRef(s); super.readRef(s);
portdevices = new PortDevice[32]; portdevices = new PortDevice[32];
for (int a=0; a<ports.length; a++) for (int a = 0; a < ports.length; a++) {
{
Item item = level.FindItem(s.readInt()); Item item = level.FindItem(s.readInt());
portdevices[a] = (PortDevice) item; portdevices[a] = (PortDevice) item;
} }
GenerateIcons(); GenerateIcons();
} }
public boolean Function() public boolean Function() {
{
// Transfer values bewteen the ports and the portdevices. // Transfer values bewteen the ports and the portdevices.
boolean changed = false; boolean changed = false;
for (int a = 0; a<32; a++) for (int a = 0; a < 32; a++) {
{
Port outer = ports[a]; Port outer = ports[a];
Port inner = portdevices[a].ports[0]; Port inner = portdevices[a].ports[0];
if (outer.type == Port.TYPE_INPUT) if (outer.type == Port.TYPE_INPUT) {
if (outer.value != inner.value) if (outer.value != inner.value) {
{ changed = true;
changed=true;
inner.value = outer.value; inner.value = outer.value;
} }
if (outer.type == Port.TYPE_OUTPUT) }
if (outer.value != inner.value) if (outer.type == Port.TYPE_OUTPUT) {
{ if (outer.value != inner.value) {
changed=true; changed = true;
outer.value = inner.value; outer.value = inner.value;
} }
}
if (outer.myWire==null && inner.myWire==null) if (outer.myWire == null && inner.myWire == null) {
{
outer.type = Port.TYPE_UNDEFINED; outer.type = Port.TYPE_UNDEFINED;
inner.type = Port.TYPE_UNDEFINED; inner.type = Port.TYPE_UNDEFINED;
} }
if (outer.type == Port.TYPE_UNDEFINED) if (outer.type == Port.TYPE_UNDEFINED) {
{ if (inner.myWire != null) {
if (inner.myWire != null) if (inner.type == Port.TYPE_INPUT) {
{
if (inner.type == Port.TYPE_INPUT)
outer.type = Port.TYPE_OUTPUT; outer.type = Port.TYPE_OUTPUT;
else if (inner.type == Port.TYPE_OUTPUT) }
else if (inner.type == Port.TYPE_OUTPUT) {
outer.type = Port.TYPE_INPUT; outer.type = Port.TYPE_INPUT;
} }
} }
if (inner.type == Port.TYPE_UNDEFINED) }
{ if (inner.type == Port.TYPE_UNDEFINED) {
if (outer.myWire != null) if (outer.myWire != null) {
{ if (outer.type == Port.TYPE_INPUT) {
if (outer.type == Port.TYPE_INPUT)
inner.type = Port.TYPE_OUTPUT; inner.type = Port.TYPE_OUTPUT;
else if (outer.type == Port.TYPE_OUTPUT) }
else if (outer.type == Port.TYPE_OUTPUT) {
inner.type = Port.TYPE_INPUT; inner.type = Port.TYPE_INPUT;
} }
} }
}
} }
return changed; return changed;
} }
public void IsDropped() public void IsDropped() {
{ inBurner = false;
inBurner=false; inTester = false;
inTester=false; int bigXl = (x) / 28;
int bigXl = (x)/28; int bigXr = (x + width - 1) / 28;
int bigXr = (x+width-1)/28; int bigYt = (y) / 32;
int bigYt = (y)/32; int bigYb = (y + height - 1) / 32;
int bigYb = (y+height-1)/32;
if (bigXr>19) bigXr=19; if (bigXr > 19) {
if (bigYb>11) bigYb=11; bigXr = 19;
}
if (bigYb > 11) {
bigYb = 11;
}
for (int a=bigYt; a<=bigYb; a++) for (int a = bigYt; a <= bigYb; a++) {
for (int b=bigXl; b<=bigXr; b++) for (int b = bigXl; b <= bigXr; b++) {
{ if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash) {
if (level.materials.elementAt(room.RoomArray[a][b]) instanceof ChipTrash)
{
SetRoom(null); SetRoom(null);
level.items.removeElement(this); level.items.removeElement(this);
level.PlaySound(room,level.DISCHARGESOUND); level.PlaySound(room, Level.DISCHARGESOUND);
return; return;
} }
} }
} }
}
public void Erase() public void Erase() {
{
super.Erase(); super.Erase();
for (int a=0; a<portdevices.length; a++) for (int a = 0; a < portdevices.length; a++) {
portdevices[a]=null; portdevices[a] = null;
}
} }
} }

View File

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

View File

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

View File

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

View File

@@ -1,92 +1,83 @@
package com.droidquest.devices; 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.Room;
import com.droidquest.chipstuff.Port; import com.droidquest.chipstuff.Port;
public class StormShield extends Device import javax.swing.*;
{ import java.awt.*;
public StormShield(int X, int Y, Room r) import java.awt.image.BufferedImage;
{
x=X; y=Y; room = r; public class StormShield extends Device {
width=28; height=52; public StormShield(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 28;
height = 52;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
super.GenerateIcons(); super.GenerateIcons();
if (ports==null) if (ports == null) {
{
ports = new Port[1]; ports = new Port[1];
ports[0] = new Port(15,49,Port.TYPE_INPUT, 22, Port.ROT_DOWN, this); ports[0] = new Port(15, 49, Port.TYPE_INPUT, 22, Port.ROT_DOWN, this);
} }
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(16,0,4,2); g.fillRect(16, 0, 4, 2);
g.fillRect(4,2,4,2); g.fillRect(4, 2, 4, 2);
g.fillRect(12,4,4,2); g.fillRect(12, 4, 4, 2);
g.fillRect(20,4,4,2); g.fillRect(20, 4, 4, 2);
g.fillRect(4,8,4,2); g.fillRect(4, 8, 4, 2);
g.fillRect(12,8,4,2); g.fillRect(12, 8, 4, 2);
g.fillRect(24,8,4,2); g.fillRect(24, 8, 4, 2);
g.fillRect(0,10,4,2); g.fillRect(0, 10, 4, 2);
g.fillRect(8,10,4,2); g.fillRect(8, 10, 4, 2);
g.fillRect(16,10,4,2); g.fillRect(16, 10, 4, 2);
g.fillRect(24,12,4,2); g.fillRect(24, 12, 4, 2);
g.fillRect(8,14,4,2); g.fillRect(8, 14, 4, 2);
g.fillRect(16,14,4,2); g.fillRect(16, 14, 4, 2);
g.fillRect(0,18,4,2); g.fillRect(0, 18, 4, 2);
g.fillRect(12,18,4,2); g.fillRect(12, 18, 4, 2);
g.fillRect(24,18,4,2); g.fillRect(24, 18, 4, 2);
g.fillRect(16,20,4,2); g.fillRect(16, 20, 4, 2);
g.fillRect(4,22,4,2); g.fillRect(4, 22, 4, 2);
g.fillRect(20,22,4,2); g.fillRect(20, 22, 4, 2);
g.fillRect(8,24,4,2); g.fillRect(8, 24, 4, 2);
g.fillRect(16,24,4,2); g.fillRect(16, 24, 4, 2);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public void Decorate() public void Decorate() {
{ try {
try
{
g = currentIcon.getGraphics(); g = currentIcon.getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to Device Image"); System.out.println("Could not get Graphics pointer to Device Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g;
for (int a=0; a<ports.length; a++) for (Port port : ports) {
ports[a].Draw(g, rotation); port.Draw(g, rotation);
}
} }
public void rotate(int dir) public void rotate(int dir) {
{
// Does not Rotate! // Does not Rotate!
} }

View File

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

View File

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

View File

@@ -1,21 +1,16 @@
package com.droidquest.items; 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; import com.droidquest.Room;
public class AmpireBot extends Item import javax.swing.*;
{ import java.awt.*;
int animationState=0; // 0-4 import java.awt.image.BufferedImage;
boolean alive=true;
int behaviorState=0; public class AmpireBot extends Item {
// 0=Wait for Player private int animationState = 0; // 0-4
private boolean alive = true;
private int behaviorState = 0;
// 0=Wait for Player
// 1=Patrol Init // 1=Patrol Init
// 2=Patrol Left // 2=Patrol Left
// 3=Patrol Up // 3=Patrol Up
@@ -23,327 +18,354 @@ int behaviorState=0;
// 5=Patrol Down // 5=Patrol Down
// 6=Pounce // 6=Pounce
// 7=Drain // 7=Drain
int previousBehavior; // Used to return from Attack private int previousBehavior; // Used to return from Attack
Item target; private Item target;
public AmpireBot(int X, int Y, Room r) public AmpireBot(int X, int Y, Room r) {
{ x = X;
x=X; y=Y; room=r; y = Y;
room = r;
grabbable = false; grabbable = false;
width=26;height=32; width = 26;
height = 32;
GenerateIcons(); GenerateIcons();
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[6]; icons = new ImageIcon[6];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); 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[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[2]= 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[3] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[4]= 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)); icons[5] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
Graphics2D g2; Graphics2D g2;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
// 0= blue 1 // 0= blue 1
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,16,6,6); g.fillRect(10, 16, 6, 6);
g.fillRect(6,18,14,2); g.fillRect(6, 18, 14, 2);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
// 1= blue 2 // 1= blue 2
try try {
{
g = icons[1].getImage().getGraphics(); g = icons[1].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
g.fillRect(8,28,10,2); g.fillRect(8, 28, 10, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,14,6,6); g.fillRect(10, 14, 6, 6);
g.fillRect(6,16,14,2); g.fillRect(6, 16, 14, 2);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,6,8,2); g.fillRect(8, 6, 8, 2);
// 2= blue 3 // 2= blue 3
try try {
{
g = icons[2].getImage().getGraphics(); g = icons[2].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(12,24,2,4); g.fillRect(12, 24, 2, 4);
g.fillRect(0,28,6,2); g.fillRect(0, 28, 6, 2);
g.fillRect(20,28,6,2); g.fillRect(20, 28, 6, 2);
g.fillRect(8,30,10,2); g.fillRect(8, 30, 10, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,12,6,6); g.fillRect(10, 12, 6, 6);
g.fillRect(6,14,14,2); g.fillRect(6, 14, 14, 2);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(18,6,8,2); g.fillRect(18, 6, 8, 2);
// 3= green 1 // 3= green 1
try try {
{
g = icons[3].getImage().getGraphics(); g = icons[3].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.green); g.setColor(Color.green);
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,16,6,6); g.fillRect(10, 16, 6, 6);
g.fillRect(6,18,14,2); g.fillRect(6, 18, 14, 2);
g.setColor(Color.green); g.setColor(Color.green);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
// 4= orange 2 // 4= orange 2
try try {
{
g = icons[4].getImage().getGraphics(); g = icons[4].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(2,6,8,2); g.fillRect(2, 6, 8, 2);
g.fillRect(8,28,10,2); g.fillRect(8, 28, 10, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,14,6,6); g.fillRect(10, 14, 6, 6);
g.fillRect(6,16,14,2); g.fillRect(6, 16, 14, 2);
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(8,6,8,2); g.fillRect(8, 6, 8, 2);
// 5= green 3 // 5= green 3
try try {
{
g = icons[5].getImage().getGraphics(); g = icons[5].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.green); g.setColor(Color.green);
g.fillRect(8,0,8,2); g.fillRect(8, 0, 8, 2);
g.fillRect(0,2,26,10); g.fillRect(0, 2, 26, 10);
g.fillRect(4,12,18,12); g.fillRect(4, 12, 18, 12);
g.fillRect(0,16,26,6); g.fillRect(0, 16, 26, 6);
g.fillRect(12,24,2,8); g.fillRect(12, 24, 2, 8);
g.fillRect(12,24,2,4); g.fillRect(12, 24, 2, 4);
g.fillRect(0,28,6,2); g.fillRect(0, 28, 6, 2);
g.fillRect(20,28,6,2); g.fillRect(20, 28, 6, 2);
g.fillRect(8,30,10,2); g.fillRect(8, 30, 10, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(2,4,22,6); g.fillRect(2, 4, 22, 6);
g.fillRect(10,12,6,6); g.fillRect(10, 12, 6, 6);
g.fillRect(6,14,14,2); g.fillRect(6, 14, 14, 2);
g.setColor(Color.green); g.setColor(Color.green);
g.fillRect(18,6,8,2); g.fillRect(18, 6, 8, 2);
if (animationState==4) animationState=0; if (animationState == 4) {
animationState = 0;
}
int frame = animationState; int frame = animationState;
if (animationState==3) frame=1; if (animationState == 3) {
if (!alive) frame +=3; frame = 1;
}
if (!alive) {
frame += 3;
}
currentIcon = icons[frame].getImage(); currentIcon = icons[frame].getImage();
} }
public void Animate() public void Animate() {
{
animationState++; animationState++;
if (animationState==4) animationState=0; if (animationState == 4) {
animationState = 0;
}
int frame = animationState; int frame = animationState;
if (animationState==3) frame=1; if (animationState == 3) {
if (!alive) frame +=3; frame = 1;
}
if (!alive) {
frame += 3;
}
currentIcon = icons[frame].getImage(); currentIcon = icons[frame].getImage();
if (alive) if (alive) {
{ if (behaviorState < 6) {
if (behaviorState<6) for (int a = 0; a < level.items.size(); a++) {
for (int a=0;a<level.items.size(); a++) target = level.items.elementAt(a);
{ if (target.room == room) {
target = (Item) level.items.elementAt(a); if (target.charge > 0) {
if (target.room == room) previousBehavior = behaviorState;
if (target.charge>0) behaviorState = 6;
{ a = level.items.size();
previousBehavior=behaviorState;
behaviorState=6;
a=level.items.size();
} }
} }
switch (behaviorState) }
{ }
switch (behaviorState) {
case 0: case 0:
if (level.player.room == room) behaviorState=1; if (level.player.room == room) {
behaviorState = 1;
}
break; break;
case 1: case 1:
if (y>=192) if (y >= 192) {
behaviorState = 2; behaviorState = 2;
else }
{ else {
MoveDown( 8); MoveDown(8);
if (x<280) MoveRight(8); if (x < 280) {
if (x>280) MoveLeft(8); MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
} }
break; break;
case 2: case 2:
if (room==(Room) level.rooms.elementAt(18) && x<=280) if (room == level.rooms.elementAt(18) && x <= 280) {
behaviorState = 3; behaviorState = 3;
else }
{ else {
MoveLeft( 8); MoveLeft(8);
if (y<192) MoveDown(8); if (y < 192) {
if (y>192) MoveUp(8); MoveDown(8);
}
if (y > 192) {
MoveUp(8);
}
} }
break; break;
case 3: case 3:
if (room==(Room) level.rooms.elementAt(19) && y<=192) if (room == level.rooms.elementAt(19) && y <= 192) {
behaviorState = 4; behaviorState = 4;
else }
{ else {
MoveUp( 8); MoveUp(8);
if (x<280) MoveRight(8); if (x < 280) {
if (x>280) MoveLeft(8); MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
} }
break; break;
case 4: case 4:
if (room==(Room) level.rooms.elementAt(15) && x>=280) if (room == level.rooms.elementAt(15) && x >= 280) {
behaviorState = 5; behaviorState = 5;
else }
{ else {
MoveRight( 8); MoveRight(8);
if (y<192) MoveDown(8); if (y < 192) {
if (y>192) MoveUp(8); MoveDown(8);
}
if (y > 192) {
MoveUp(8);
}
} }
break; break;
case 5: case 5:
if (room==(Room) level.rooms.elementAt(16) && y>=192) if (room == level.rooms.elementAt(16) && y >= 192) {
behaviorState = 2; behaviorState = 2;
else }
{ else {
MoveDown( 8); MoveDown(8);
if (x<280) MoveRight(8); if (x < 280) {
if (x>280) MoveLeft(8); MoveRight(8);
}
if (x > 280) {
MoveLeft(8);
}
} }
break; break;
case 6: case 6:
if (target.room != room) if (target.room != room) {
behaviorState = previousBehavior; behaviorState = previousBehavior;
if (Overlaps(target)) }
{ if (Overlaps(target)) {
behaviorState=7; behaviorState = 7;
break; break;
} }
Dimension d = target.GetXY(); Dimension d = target.GetXY();
if (d.width<x) MoveLeft(false); if (d.width < x) {
if (d.width>x) MoveRight(false); MoveLeft(false);
if (d.height<y) MoveUp(false); }
if (d.height>y) MoveDown(false); if (d.width > x) {
MoveRight(false);
}
if (d.height < y) {
MoveUp(false);
}
if (d.height > y) {
MoveDown(false);
}
break; break;
case 7: case 7:
if (target.room != room) if (target.room != room) {
{
behaviorState = previousBehavior; behaviorState = previousBehavior;
break; break;
} }
if (target.charge>0 && Overlaps(target)) if (target.charge > 0 && Overlaps(target)) {
{ if (target.getClass().toString().endsWith("BlackCrystal")) {
if (target.getClass().toString().endsWith("BlackCrystal"))
alive = false; alive = false;
else
target.charge-=3125;
} }
else else {
target.charge -= 3125;
}
}
else {
behaviorState = 6; behaviorState = 6;
if (target.charge <=0) }
{ if (target.charge <= 0) {
target.charge=0; target.charge = 0;
behaviorState=previousBehavior; behaviorState = previousBehavior;
} }
break; break;
} }
} }
} }
public void Erase() public void Erase() {
{
super.Erase(); super.Erase();
target = null; target = null;
} }

View File

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

View File

@@ -1,57 +1,52 @@
package com.droidquest.items; 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.Room;
public class BinaryKey extends Item import javax.swing.*;
{ import java.awt.*;
public BinaryKey (int X, int Y, Room r) import java.awt.image.BufferedImage;
{
x=X; y=Y; room=r; public class BinaryKey extends Item {
width=26; height=28; public BinaryKey(int X, int Y, Room r) {
x = X;
y = Y;
room = r;
width = 26;
height = 28;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(4,0,4,8); g.fillRect(4, 0, 4, 8);
g.fillRect(4,10,4,2); g.fillRect(4, 10, 4, 2);
g.fillRect(0,12,4,4); g.fillRect(0, 12, 4, 4);
g.fillRect(8,12,4,4); g.fillRect(8, 12, 4, 4);
g.fillRect(4,16,4,2); g.fillRect(4, 16, 4, 2);
g.fillRect(4,20,4,8); g.fillRect(4, 20, 4, 8);
g.fillRect(16,0,4,2); g.fillRect(16, 0, 4, 2);
g.fillRect(12,2,4,4); g.fillRect(12, 2, 4, 4);
g.fillRect(20,2,4,4); g.fillRect(20, 2, 4, 4);
g.fillRect(16,6,4,2); g.fillRect(16, 6, 4, 2);
g.fillRect(16,10,4,8); g.fillRect(16, 10, 4, 8);
g.fillRect(16,20,4,2); g.fillRect(16, 20, 4, 2);
g.fillRect(12,22,4,4); g.fillRect(12, 22, 4, 4);
g.fillRect(20,22,4,4); g.fillRect(20, 22, 4, 4);
g.fillRect(16,26,4,2); g.fillRect(16, 26, 4, 2);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }

View File

@@ -9,46 +9,42 @@ import javax.swing.ImageIcon;
import com.droidquest.Room; import com.droidquest.Room;
public class BlackCrystal extends Crystal public class BlackCrystal extends Crystal {
{ public BlackCrystal(int X, int Y, Room r) {
public BlackCrystal(int X, int Y, Room r) super(X, Y, r, 10);
{
super(X,Y,r,10);
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
Graphics2D g2; Graphics2D g2;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
// 0 = blue // 0 = blue
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g2 = (Graphics2D) g; g2 = (Graphics2D) g;
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(12,0,4,24); g.fillRect(12, 0, 4, 24);
g.fillRect(8,4,12,16); g.fillRect(8, 4, 12, 16);
g.fillRect(4,6,20,12); g.fillRect(4, 6, 20, 12);
g.fillRect(0,10,28,4); g.fillRect(0, 10, 28, 4);
g.fillRect(0,4,4,2); g.fillRect(0, 4, 4, 2);
g.fillRect(0,18,4,2); g.fillRect(0, 18, 4, 2);
g.fillRect(24,4,4,2); g.fillRect(24, 4, 4, 2);
g.fillRect(24,18,4,2); g.fillRect(24, 18, 4, 2);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public void Decorate() {} public void Decorate() {
}
} }

View File

@@ -1,8 +1,5 @@
package com.droidquest.items; package com.droidquest.items;
import java.awt.Color;
import java.awt.Graphics;
import com.droidquest.Room; import com.droidquest.Room;
import com.droidquest.chipstuff.Port; import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Antenna; import com.droidquest.devices.Antenna;
@@ -10,53 +7,52 @@ import com.droidquest.devices.Bumper;
import com.droidquest.devices.Grabber; import com.droidquest.devices.Grabber;
import com.droidquest.devices.Thruster; import com.droidquest.devices.Thruster;
public class BlueRobot extends GenericRobot import java.awt.*;
{
private int scan;
private int scandir;
public BlueRobot(int X, int Y, Room r) public class BlueRobot extends GenericRobot {
{ private int scan;
super(X,Y,r,Color.blue); private int scandir;
scan=0;
scandir=2; public BlueRobot(int X, int Y, Room r) {
super(X, Y, r, Color.blue);
scan = 0;
scandir = 2;
Animate(); Animate();
devices[0] = new Thruster(176,16,InternalRoom,Port.ROT_UP,Color.white); 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[1] = new Thruster(476, 128, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[2] = new Thruster(356,336,InternalRoom,Port.ROT_DOWN,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[3] = new Thruster(32, 236, InternalRoom, Port.ROT_LEFT, Color.white);
devices[4] = new Bumper(396,16,InternalRoom,Port.ROT_UP,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[5] = new Bumper(480, 256, InternalRoom, Port.ROT_RIGHT, Color.white);
devices[6] = new Bumper(128,330,InternalRoom,Port.ROT_DOWN,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[7] = new Bumper(28, 134, InternalRoom, Port.ROT_LEFT, Color.white);
devices[8] = new Antenna(64,70,InternalRoom,Color.white); devices[8] = new Antenna(64, 70, InternalRoom, Color.white);
devices[9] = new Grabber(126,44,InternalRoom,Color.white); devices[9] = new Grabber(126, 44, InternalRoom, Color.white);
for (int a=0; a<10; a++) for (int a = 0; a < 10; a++) {
level.items.addElement(devices[a]); level.items.addElement(devices[a]);
}
} }
public void Decorate() public void Decorate() {
{
super.Decorate(); super.Decorate();
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image"); System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return; return;
} }
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(22,44,42,4); g.fillRect(22, 44, 42, 4);
if (scan+scandir>36 || scan+scandir<0) if (scan + scandir > 36 || scan + scandir < 0) {
scandir=-scandir; scandir = -scandir;
scan=scan+scandir; }
g.setColor(new Color(255,128,0)); scan = scan + scandir;
g.fillRect(22+scan,44,6,4); 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.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import com.droidquest.Room; import com.droidquest.Room;
import com.droidquest.Wire;
import com.droidquest.chipstuff.ChipCompiler; 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.PrototypeChip;
import com.droidquest.devices.SmallChip; import com.droidquest.devices.SmallChip;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
public class Burner extends Item public class Burner extends Item {
{ private int burning;
int burning; private int animation;
int animation;
public Burner(int X, int Y, Room r) public Burner(int X, int Y, Room r) {
{ x = X;
x=X; y=Y; room=r; y = Y;
width=28; height=30; room = r;
width = 28;
height = 30;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[2]; icons = new ImageIcon[2];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); 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[1] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
Graphics2D g2;
Color transparent = new Color(0,0,0,0);
// 0 = Off // 0 = Off
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0,0,28,30); g.fillRect(0, 0, 28, 30);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,8,12,14); g.fillRect(8, 8, 12, 14);
g.fillRect(4,10,20,10); g.fillRect(4, 10, 20, 10);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(12,10,4,10); g.fillRect(12, 10, 4, 10);
g.fillRect(8,12,12,6); g.fillRect(8, 12, 12, 6);
// 1 = On // 1 = On
try try {
{
g = icons[1].getImage().getGraphics(); g = icons[1].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(0,0,28,30); g.fillRect(0, 0, 28, 30);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,8,12,14); g.fillRect(8, 8, 12, 14);
g.fillRect(4,10,20,10); g.fillRect(4, 10, 20, 10);
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(12,10,4,10); g.fillRect(12, 10, 4, 10);
g.fillRect(8,12,12,6); g.fillRect(8, 12, 12, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public boolean CanBePickedUp(Item i) public boolean CanBePickedUp(Item i) {
{
// Find the SmallChip and Erase it // Find the SmallChip and Erase it
Item sc=null; Item sc = null;
for (int a=0; a<level.items.size(); a++) for (int a = 0; a < level.items.size(); a++) {
{ Item item = level.items.elementAt(a);
Item item = (Item) level.items.elementAt(a); if (item.getClass().toString().endsWith("SmallChip")) {
if (item.getClass().toString().endsWith("SmallChip")) if (((SmallChip) item).inBurner) {
if (((SmallChip)item).inBurner) sc = item;
sc = (SmallChip) item;
} }
if (sc==null) return false; }
((SmallChip)sc).Empty(); }
if (sc == null) {
return false;
}
((SmallChip) sc).Empty();
// Find the PrototypeChip // Find the PrototypeChip
Item pc=null; Item pc = null;
for (int a=0; a<level.items.size(); a++) for (int a = 0; a < level.items.size(); a++) {
{ Item item = level.items.elementAt(a);
Item item = (Item) level.items.elementAt(a); if (item.getClass().toString().endsWith("PrototypeChip")) {
if (item.getClass().toString().endsWith("PrototypeChip")) if (((PrototypeChip) item).inBurner) {
if (((PrototypeChip)item).inBurner) pc = item;
pc = (PrototypeChip) item; }
}
}
if (pc == null) {
return false;
} }
if (pc==null) return false;
// Start the ChipCompiler thread // Start the ChipCompiler thread
ChipCompiler cc = new ChipCompiler( (PrototypeChip) pc, (SmallChip) sc); ChipCompiler cc = new ChipCompiler((PrototypeChip) pc, (SmallChip) sc);
level.PlaySound(room,Level.BURNSOUND); level.PlaySound(room, Level.BURNSOUND);
burning = 10; burning = 10;
return false; return false;
} }
public void Animate() public void Animate() {
{ if (burning > 0) {
if (burning>0) animation = 1 - animation;
{
animation = 1- animation;
currentIcon = icons[animation].getImage(); currentIcon = icons[animation].getImage();
burning--; burning--;
} }
else else {
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
}
} }

View File

@@ -9,46 +9,44 @@ import javax.swing.ImageIcon;
import com.droidquest.Room; import com.droidquest.Room;
public class Button extends Item public class Button extends Item {
{ private Color color;
Color color;
public Button(int X, int Y, Room r, Color c) public Button(int X, int Y, Room r, Color c) {
{ x = X;
x=X; y=Y; room=r; y = Y;
width=28; height=26; room = r;
color=c; width = 28;
height = 26;
color = c;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(color); g.setColor(color);
g.fillRect(8,0,12,26); g.fillRect(8, 0, 12, 26);
g.fillRect(4,2,20,22); g.fillRect(4, 2, 20, 22);
g.fillRect(0,4,28,18); g.fillRect(0, 4, 28, 18);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,6,12,14); g.fillRect(8, 6, 12, 14);
g.fillRect(4,8,20,10); g.fillRect(4, 8, 20, 10);
g.setColor(color); g.setColor(color);
g.fillRect(12,8,4,10); g.fillRect(12, 8, 4, 10);
g.fillRect(8,10,12,6); g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,112 +1,103 @@
package com.droidquest.items; 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.Room;
import com.droidquest.devices.StormShield; import com.droidquest.devices.StormShield;
public class GateKeeper extends Item import javax.swing.*;
{ import java.awt.*;
int behavior=0; import java.awt.image.BufferedImage;
public class GateKeeper extends Item {
int behavior = 0;
// 0= pause // 0= pause
// 1= Go to trash, delete F-12, delete StormShield // 1= Go to trash, delete F-12, delete StormShield
int goToX=2*28+14; private int goToX = 2 * 28 + 14;
int goToY=8*32; private int goToY = 8 * 32;
public GateKeeper(int X, int Y, Room r) public GateKeeper(int X, int Y, Room r) {
{ x = X;
x=X; y=Y; y = Y;
room =r; room = r;
width=52; height=38; width = 52;
grabbable=false; height = 38;
grabbable = false;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(4,0,12,14); g.fillRect(4, 0, 12, 14);
g.fillRect(0,2,20,10); g.fillRect(0, 2, 20, 10);
g.fillRect(20,4,8,6); g.fillRect(20, 4, 8, 6);
g.fillRect(24,8,24,20); g.fillRect(24, 8, 24, 20);
g.fillRect(48,12,4,16); g.fillRect(48, 12, 4, 16);
g.fillRect(32,6,12,32); g.fillRect(32, 6, 12, 32);
g.fillRect(28,34,20,2); g.fillRect(28, 34, 20, 2);
g.fillRect(24,36,28,2); g.fillRect(24, 36, 28, 2);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,2,4,10); g.fillRect(8, 2, 4, 10);
g.fillRect(4,4,12,6); g.fillRect(4, 4, 12, 6);
g.fillRect(0,6,4,2); g.fillRect(0, 6, 4, 2);
g.fillRect(20,6,4,2); g.fillRect(20, 6, 4, 2);
g.fillRect(28,18,4,2); g.fillRect(28, 18, 4, 2);
g.fillRect(32,16,4,2); g.fillRect(32, 16, 4, 2);
g.fillRect(36,18,4,2); g.fillRect(36, 18, 4, 2);
g.fillRect(40,16,4,2); g.fillRect(40, 16, 4, 2);
g.fillRect(44,18,4,2); g.fillRect(44, 18, 4, 2);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public void Animate() public void Animate() {
{ if (behavior == 1) {
if (behavior ==1) if (x != goToX && y != goToY) {
{ if (x != goToX) {
if (x != goToX && y != goToY)
{
if (x != goToX)
{
int diff = Math.abs(goToX - x); int diff = Math.abs(goToX - x);
int dir = diff / (goToX - x); int dir = diff / (goToX - x);
if (diff > 2) diff = 2; if (diff > 2) {
diff = 2;
}
MoveRight(diff * dir); MoveRight(diff * dir);
} }
if (y != goToY) if (y != goToY) {
{
int diff = Math.abs(goToY - y); int diff = Math.abs(goToY - y);
int dir = diff / (goToY - y); int dir = diff / (goToY - y);
if (diff > 2) diff = 2; if (diff > 2) {
diff = 2;
}
MoveDown(diff * dir); MoveDown(diff * dir);
} }
} }
else else {
{ behavior = 0;
behavior=0;
level.items.removeElement(carrying); level.items.removeElement(carrying);
carrying = null; carrying = null;
StormShield ss=null; StormShield ss = null;
for (int a=0; a<level.items.size(); a++) for (int a = 0; a < level.items.size(); a++) {
{ Item item = level.items.elementAt(a);
Item item = (Item) level.items.elementAt(a); if (item.getClass().toString().endsWith("StormShield")) {
if (item.getClass().toString().endsWith("StormShield"))
ss = (StormShield) item; ss = (StormShield) item;
} }
if (ss!=null) }
{ if (ss != null) {
ss.SetRoom(null); // Removes wires ss.SetRoom(null); // Removes wires
level.items.removeElement(ss); level.items.removeElement(ss);
} }
room.SetMaterial(7,7,21); room.SetMaterial(7, 7, 21);
} }
} }
} }

View File

@@ -1,77 +1,69 @@
package com.droidquest.items; 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.Room;
import com.droidquest.chipstuff.Port; import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Spark; import com.droidquest.decorations.Spark;
import com.droidquest.devices.Device; import com.droidquest.devices.Device;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
import com.droidquest.materials.BatteryIn; import com.droidquest.materials.*;
import com.droidquest.materials.BatteryOut;
import com.droidquest.materials.Material;
import com.droidquest.materials.PeriscopeDown;
import com.droidquest.materials.PeriscopeUp;
public class GenericRobot extends Item import javax.swing.*;
{ import java.awt.*;
public Device devices[] = new Device[10]; import java.awt.image.BufferedImage;
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[];
public GenericRobot(int X, int Y, Room r, Color c) public class GenericRobot extends Item {
{ public Device devices[] = new Device[10];
x=X; y=Y; room=r; 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; grabber = 1;
charge=100000; charge = 100000;
color = c; color = c;
// orgX = 32; orgY = 24; // orgX = 32; orgY = 24;
orgX = 14; orgY = 24; orgX = 14;
orgY = 24;
// orgX = 14; orgY = 0; // orgX = 14; orgY = 0;
width = 56; height = 42; width = 56;
height = 42;
InternalRoom = new Room(); InternalRoom = new Room();
int[][] table = { InternalRoom.RoomArray = new int[][]{
{0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0}, {0, 0, 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, 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}, {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},
{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},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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},
{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, 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, 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} {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)); Material mat1 = Material.FindSimiliar(new Material(color, false, true));
int mat1Index = level.materials.indexOf(mat1); int mat1Index = level.materials.indexOf(mat1);
@@ -83,12 +75,16 @@ public GenericRobot(int X, int Y, Room r, Color c)
int battInIndex = level.materials.indexOf(battIn); int battInIndex = level.materials.indexOf(battIn);
Material battOut = Material.FindSimiliar(new BatteryOut()); Material battOut = Material.FindSimiliar(new BatteryOut());
int battOutIndex = level.materials.indexOf(battOut); int battOutIndex = level.materials.indexOf(battOut);
((BatteryIn)battIn).robot = this; ((BatteryIn) battIn).robot = this;
((BatteryOut)battOut).robot = this; ((BatteryOut) battOut).robot = this;
for (int rY=0; rY<12; rY++) for (int rY = 0; rY < 12; rY++) {
for (int rX=0; rX<20; rX++) for (int rX = 0; rX < 20; rX++) {
if (InternalRoom.RoomArray[rY][rX]==1) InternalRoom.RoomArray[rY][rX] = mat1Index; if (InternalRoom.RoomArray[rY][rX] == 1) {
InternalRoom.RoomArray[rY][rX] = mat1Index;
}
}
}
InternalRoom.RoomArray[2][17] = perUpIndex; InternalRoom.RoomArray[2][17] = perUpIndex;
InternalRoom.RoomArray[2][16] = perDownIndex; InternalRoom.RoomArray[2][16] = perDownIndex;
InternalRoom.RoomArray[3][17] = perDownIndex; InternalRoom.RoomArray[3][17] = perDownIndex;
@@ -105,268 +101,264 @@ public GenericRobot(int X, int Y, Room r, Color c)
// upPortal = new Rectangle (12,-18,12,8); // upPortal = new Rectangle (12,-18,12,8);
// downPortal = new Rectangle (10,24,12,8); // downPortal = new Rectangle (10,24,12,8);
// //
leftPortal = new Rectangle (-28,0,8,14); leftPortal = new Rectangle(-28, 0, 8, 14);
rightPortal = new Rectangle (50,0,8,14); rightPortal = new Rectangle(50, 0, 8, 14);
upPortal = new Rectangle (10,-30,12,18); upPortal = new Rectangle(10, -30, 12, 18);
downPortal = new Rectangle (10,24,12,18); downPortal = new Rectangle(10, 24, 12, 18);
level.items.addElement(new PowerSwitch(17*28-4,9*32-4,InternalRoom)); level.items.addElement(new PowerSwitch(17 * 28 - 4, 9 * 32 - 4, InternalRoom));
GenerateIcons(); GenerateIcons();
Animate(); Animate();
} }
public void GenerateIcons() public void GenerateIcons() {
{
// orgX = 14; orgY = 24; // orgX = 14; orgY = 24;
// width = 56; height = 42; // width = 56; height = 42;
orgX = 14; orgY = 24; orgX = 14;
width = 56; height = 44; orgY = 24;
width = 56;
height = 44;
icons = new ImageIcon[1]; icons = new ImageIcon[1];
// icons[0]= new ImageIcon(new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR)); // icons[0]= new ImageIcon(new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR));
icons[0]= new ImageIcon(new BufferedImage(84,84,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
((BatteryIn)level.materials.elementAt(InternalRoom.RoomArray[9][3])).robot = this; ((BatteryIn) level.materials.elementAt(InternalRoom.RoomArray[9][3])).robot = this;
((BatteryOut)level.materials.elementAt(InternalRoom.RoomArray[9][2])).robot = this; ((BatteryOut) level.materials.elementAt(InternalRoom.RoomArray[9][2])).robot = this;
images = new ImageIcon[10]; images = new ImageIcon[10];
for (int a=0; a<10; a++) for (int a = 0; a < 10; a++) {
{
// images[a] = new ImageIcon( new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR)); // images[a] = new ImageIcon( new BufferedImage(122,92,BufferedImage.TYPE_4BYTE_ABGR));
images[a] = new ImageIcon( new BufferedImage(84,84,BufferedImage.TYPE_4BYTE_ABGR)); images[a] = new ImageIcon(new BufferedImage(84, 84, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = images[a].getImage().getGraphics(); g = images[a].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image"); System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
// g2.clearRect(0,0,122,92); // g2.clearRect(0,0,122,92);
g2.clearRect(0,0,84,84); g2.clearRect(0, 0, 84, 84);
switch (a) switch (a) {
{
case 0: // Robot Body case 0: // Robot Body
{ {
g.setColor(color); g.setColor(color);
int X=orgX+18; int X = orgX + 18;
int Y=orgY+6; int Y = orgY + 6;
g.fillRect(X, Y, 22,32); g.fillRect(X, Y, 22, 32);
g.fillRect(X-4, Y+2, 30,28); g.fillRect(X - 4, Y + 2, 30, 28);
g.fillRect(X-8, Y+4, 38,24); g.fillRect(X - 8, Y + 4, 38, 24);
g.fillRect(X-12, Y+6, 46,20); g.fillRect(X - 12, Y + 6, 46, 20);
} }
break; break;
case 1: // Grabber Up case 1: // Grabber Up
g.setColor(Color.white); g.setColor(Color.white);
{ {
int X=orgX+40; int X = orgX + 40;
int Y=orgY-16; int Y = orgY - 16;
g.fillRect(X+0,Y+20,20,4); g.fillRect(X + 0, Y + 20, 20, 4);
g.fillRect(X+16,Y+16,4,8); g.fillRect(X + 16, Y + 16, 4, 8);
g.fillRect(X+12,Y+10,4,8); g.fillRect(X + 12, Y + 10, 4, 8);
g.fillRect(X+20,Y+10,4,8); g.fillRect(X + 20, Y + 10, 4, 8);
g.fillRect(X+12,Y+12,12,2); g.fillRect(X + 12, Y + 12, 12, 2);
g.fillRect(X+8,Y+2,4,10); g.fillRect(X + 8, Y + 2, 4, 10);
g.fillRect(X+24,Y+2,4,10); g.fillRect(X + 24, Y + 2, 4, 10);
g.fillRect(X+12,Y+0,4,4); g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X+20,Y+0,4,4); g.fillRect(X + 20, Y + 0, 4, 4);
break; break;
} }
case 2: // Grabber Right case 2: // Grabber Right
g.setColor(Color.white); g.setColor(Color.white);
{ {
int X=orgX+46; int X = orgX + 46;
int Y=orgY+34; int Y = orgY + 34;
g.fillRect(X+0,Y+0,4,10); g.fillRect(X + 0, Y + 0, 4, 10);
g.fillRect(X+0,Y+4,12,2); g.fillRect(X + 0, Y + 4, 12, 2);
g.fillRect(X+0,Y+8,12,2); g.fillRect(X + 0, Y + 8, 12, 2);
g.fillRect(X+8,Y+2,4,10); g.fillRect(X + 8, Y + 2, 4, 10);
g.fillRect(X+12,Y+0,4,4); g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X+12,Y+10,4,4); g.fillRect(X + 12, Y + 10, 4, 4);
g.fillRect(X+12,Y+0,12,2); g.fillRect(X + 12, Y + 0, 12, 2);
g.fillRect(X+12,Y+12,12,2); g.fillRect(X + 12, Y + 12, 12, 2);
g.fillRect(X+16,Y+0,4,4); g.fillRect(X + 16, Y + 0, 4, 4);
g.fillRect(X+16,Y+10,4,4); g.fillRect(X + 16, Y + 10, 4, 4);
g.fillRect(X+20,Y+2,4,4); g.fillRect(X + 20, Y + 2, 4, 4);
g.fillRect(X+20,Y+8,4,4); g.fillRect(X + 20, Y + 8, 4, 4);
} }
break; break;
case 3: // Grabber Down case 3: // Grabber Down
g.setColor(Color.white); g.setColor(Color.white);
{ {
int X=orgX-10; int X = orgX - 10;
int Y=orgY+32; int Y = orgY + 32;
g.fillRect(X+8,Y+0,12,4); g.fillRect(X + 8, Y + 0, 12, 4);
g.fillRect(X+8,Y+0,4,10); g.fillRect(X + 8, Y + 0, 4, 10);
g.fillRect(X+4,Y+8,4,8); g.fillRect(X + 4, Y + 8, 4, 8);
g.fillRect(X+12,Y+8,4,8); g.fillRect(X + 12, Y + 8, 4, 8);
g.fillRect(X+4,Y+12,12,2); g.fillRect(X + 4, Y + 12, 12, 2);
g.fillRect(X+0,Y+14,4,10); g.fillRect(X + 0, Y + 14, 4, 10);
g.fillRect(X+16,Y+14,4,10); g.fillRect(X + 16, Y + 14, 4, 10);
g.fillRect(X+4,Y+22,4,4); g.fillRect(X + 4, Y + 22, 4, 4);
g.fillRect(X+12,Y+22,4,4); g.fillRect(X + 12, Y + 22, 4, 4);
} }
break; break;
case 4: // Grabber Left case 4: // Grabber Left
g.setColor(Color.white); g.setColor(Color.white);
{ {
int X=orgX-16; int X = orgX - 16;
int Y=orgY-6; int Y = orgY - 6;
g.fillRect(X+24,Y+4,4,10); g.fillRect(X + 24, Y + 4, 4, 10);
g.fillRect(X+16,Y+4,12,2); g.fillRect(X + 16, Y + 4, 12, 2);
g.fillRect(X+16,Y+8,12,2); g.fillRect(X + 16, Y + 8, 12, 2);
g.fillRect(X+16,Y+2,4,10); g.fillRect(X + 16, Y + 2, 4, 10);
g.fillRect(X+12,Y+0,4,4); g.fillRect(X + 12, Y + 0, 4, 4);
g.fillRect(X+12,Y+10,4,4); g.fillRect(X + 12, Y + 10, 4, 4);
g.fillRect(X+4,Y+0,12,2); g.fillRect(X + 4, Y + 0, 12, 2);
g.fillRect(X+4,Y+12,12,2); g.fillRect(X + 4, Y + 12, 12, 2);
g.fillRect(X+4,Y+0,4,4); g.fillRect(X + 4, Y + 0, 4, 4);
g.fillRect(X+4,Y+10,4,4); g.fillRect(X + 4, Y + 10, 4, 4);
g.fillRect(X+0,Y+2,4,4); g.fillRect(X + 0, Y + 2, 4, 4);
g.fillRect(X+0,Y+8,4,4); g.fillRect(X + 0, Y + 8, 4, 4);
break; break;
} }
case 5: // Antenna Off case 5: // Antenna Off
{ {
int X=orgX+14; int X = orgX + 14;
int Y=orgY-18; int Y = orgY - 18;
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(X,Y,12,6); g.fillRect(X, Y, 12, 6);
g.fillRect(X+4,Y+6,4,16); g.fillRect(X + 4, Y + 6, 4, 16);
} }
break; break;
case 6: // Antenna On case 6: // Antenna On
{ {
int X=orgX+14; int X = orgX + 14;
int Y=orgY-18; int Y = orgY - 18;
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
g.fillRect(X,Y,12,6); g.fillRect(X, Y, 12, 6);
g.fillRect(X+4,Y+6,4,16); g.fillRect(X + 4, Y + 6, 4, 16);
} }
break; break;
case 7: // Periscope Left case 7: // Periscope Left
{ {
int X = orgX+40; int X = orgX + 40;
int Y = orgY+5; int Y = orgY + 5;
g.fillRect(X-10,Y-24,6,14); g.fillRect(X - 10, Y - 24, 6, 14);
g.fillRect(X-6,Y-22,12,10); g.fillRect(X - 6, Y - 22, 12, 10);
g.fillRect(X+6,Y-20,4,6); g.fillRect(X + 6, Y - 20, 4, 6);
g.fillRect(X+2,Y-12,4,18); g.fillRect(X + 2, Y - 12, 4, 18);
} }
break; break;
case 8: // Periscope Straight case 8: // Periscope Straight
{ {
int X = orgX+40; int X = orgX + 40;
int Y = orgY+5; int Y = orgY + 5;
g.fillRect(X-2,Y-24,12,2); g.fillRect(X - 2, Y - 24, 12, 2);
g.fillRect(X-2,Y-14,12,2); g.fillRect(X - 2, Y - 14, 12, 2);
g.fillRect(X-6,Y-22,4,2); g.fillRect(X - 6, Y - 22, 4, 2);
g.fillRect(X-6,Y-16,4,2); g.fillRect(X - 6, Y - 16, 4, 2);
g.fillRect(X+10,Y-22,4,2); g.fillRect(X + 10, Y - 22, 4, 2);
g.fillRect(X+10,Y-16,4,2); g.fillRect(X + 10, Y - 16, 4, 2);
g.fillRect(X-10,Y-20,4,4); g.fillRect(X - 10, Y - 20, 4, 4);
g.fillRect(X+2,Y-20,4,4); g.fillRect(X + 2, Y - 20, 4, 4);
g.fillRect(X+14,Y-20,4,4); g.fillRect(X + 14, Y - 20, 4, 4);
g.fillRect(X+2,Y-12,4,18); g.fillRect(X + 2, Y - 12, 4, 18);
} }
break; break;
case 9: // Periscope Right case 9: // Periscope Right
{ {
int X = orgX+40; int X = orgX + 40;
int Y = orgY+5; int Y = orgY + 5;
g.fillRect(X+14,Y-24,6,14); g.fillRect(X + 14, Y - 24, 6, 14);
g.fillRect(X+2,Y-22,12,10); g.fillRect(X + 2, Y - 22, 12, 10);
g.fillRect(X-2,Y-20,4,6); g.fillRect(X - 2, Y - 20, 4, 6);
g.fillRect(X+2,Y-12,4,18); g.fillRect(X + 2, Y - 12, 4, 18);
} }
break; break;
} }
} }
} }
public void Animate() public void Animate() {
{
// Do Thrusting // Do Thrusting
if (charge>0 && level.electricity && (carriedBy == null) && thrusterPower) if (charge > 0 && level.electricity && (carriedBy == null) && thrusterPower) {
{ if (topThruster) {
if (topThruster)
MoveDown(8); MoveDown(8);
if (rightThruster) }
if (rightThruster) {
MoveLeft(8); MoveLeft(8);
if (bottomThruster) }
if (bottomThruster) {
MoveUp(8); MoveUp(8);
if (leftThruster) }
if (leftThruster) {
MoveRight(8); MoveRight(8);
} }
}
if (charge>0 && level.electricity && thrusterPower) if (charge > 0 && level.electricity && thrusterPower) {
{
Dimension d = GetXY(); Dimension d = GetXY();
int X = d.width; int X = d.width;
int Y = d.height; int Y = d.height;
if (topThruster) if (topThruster) {
{ level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 24, 0, -4, room));
level.sparks.addElement(new Spark(X-orgX+32+level.random.nextInt(24),Y-orgY+24,0,-4,room)); 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;
charge-=2;
} }
if (rightThruster) if (rightThruster) {
{ level.sparks.addElement(new Spark(X - orgX + 74, Y - orgY + 36 + level.random.nextInt(20), 4, 0, room));
level.sparks.addElement(new Spark(X-orgX+74,Y-orgY+36+level.random.nextInt(20),4,0,room)); 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;
charge-=2;
} }
if (bottomThruster) if (bottomThruster) {
{ level.sparks.addElement(new Spark(X - orgX + 32 + level.random.nextInt(24), Y - orgY + 64, 0, 4, room));
level.sparks.addElement(new Spark(X-orgX+32+level.random.nextInt(24),Y-orgY+64,0,4,room)); 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;
charge-=2;
} }
if (leftThruster) if (leftThruster) {
{ level.sparks.addElement(new Spark(X - orgX + 14, Y - orgY + 36 + level.random.nextInt(20), -4, 0, room));
level.sparks.addElement(new Spark(X-orgX+14,Y-orgY+36+level.random.nextInt(20),-4,0,room)); 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-=2;
} }
charge--; charge--;
if (charge<0) charge=0; if (charge < 0) {
charge = 0;
}
} }
// Draw Antenna sparks around Broadcasting Antenna // Draw Antenna sparks around Broadcasting Antenna
if (broadcasting && level.electricity) if (broadcasting && level.electricity) {
{
Dimension d = GetXY(); Dimension d = GetXY();
level.sparks.addElement(new Spark(d.width-orgX+34,d.height-orgY+10, level.sparks.addElement(new Spark(d.width - orgX + 34, d.height - orgY + 10,
level.random.nextInt(9)-4, level.random.nextInt(9) - 4,
level.random.nextInt(9)-4, level.random.nextInt(9) - 4,
room)); room));
} }
// Make sounds // Make sounds
if (topBumper) if (topBumper && !oldTopBumper) {
if (oldTopBumper != topBumper)
level.PlaySound(room, Level.BUMPSOUND); level.PlaySound(room, Level.BUMPSOUND);
if (bottomBumper) }
if (oldBottomBumper != bottomBumper) if (bottomBumper && !oldBottomBumper) {
level.PlaySound(room, Level.BUMPSOUND); level.PlaySound(room, Level.BUMPSOUND);
if (rightBumper) }
if (oldRightBumper != rightBumper) if (rightBumper && !oldRightBumper) {
level.PlaySound(room, Level.BUMPSOUND); level.PlaySound(room, Level.BUMPSOUND);
if (leftBumper) }
if (oldLeftBumper != leftBumper) if (leftBumper && !oldLeftBumper) {
level.PlaySound(room, Level.BUMPSOUND); level.PlaySound(room, Level.BUMPSOUND);
if (broadcasting && level.electricity) }
if (broadcasting && level.electricity) {
level.PlaySound(room, Level.BEEPSOUND); level.PlaySound(room, Level.BEEPSOUND);
}
oldTopBumper = topBumper; oldTopBumper = topBumper;
oldBottomBumper = bottomBumper; oldBottomBumper = bottomBumper;
oldRightBumper = rightBumper; oldRightBumper = rightBumper;
@@ -374,62 +366,68 @@ public void Animate()
} }
public void Decorate() public void Decorate() {
{
// Paint background // Paint background
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + "Image"); System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,123,92); g2.clearRect(0, 0, 123, 92);
// Paint Robot Body // Paint Robot Body
g.drawImage(images[0].getImage(), 0, 0, level); g.drawImage(images[0].getImage(), 0, 0, level);
// Draw Bumpers // Draw Bumpers
if (topBumper) if (topBumper) {
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
else }
else {
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(32,24,22,2); }
g.fillRect(32, 24, 22, 2);
if (bottomBumper) if (bottomBumper) {
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
else }
else {
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(32,66,22,2); }
g.fillRect(32, 66, 22, 2);
if (leftBumper) if (leftBumper) {
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
else }
else {
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(12,36,4,20); }
g.fillRect(12, 36, 4, 20);
if (rightBumper) if (rightBumper) {
g.setColor(new Color(255,128,0)); g.setColor(new Color(255, 128, 0));
else }
else {
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(70,36,4,20); }
g.fillRect(70, 36, 4, 20);
// Draw Antenna // Draw Antenna
if (antenna) if (antenna) {
g.drawImage(images[6].getImage(), 0, 0, level); g.drawImage(images[6].getImage(), 0, 0, level);
else }
else {
g.drawImage(images[5].getImage(), 0, 0, level); g.drawImage(images[5].getImage(), 0, 0, level);
}
// Draw Grabber // Draw Grabber
g.setColor(Color.white); g.setColor(Color.white);
switch (grabber) switch (grabber) {
{
case Port.ROT_UP: case Port.ROT_UP:
g.drawImage(images[1].getImage(), 0, 0, level); g.drawImage(images[1].getImage(), 0, 0, level);
break; break;
@@ -446,18 +444,22 @@ public void Decorate()
// Draw Periscope // Draw Periscope
// if (periscope) // if (periscope)
if (level.currentViewer == this) if (level.currentViewer == this) {
{ periscopeAnimation++;
periscopeAnimation ++; if (periscopeAnimation == 32) {
if (periscopeAnimation == 32) periscopeAnimation =0; periscopeAnimation = 0;
if (periscopeAnimation <8) }
if (periscopeAnimation < 8) {
g.drawImage(images[7].getImage(), 0, 0, level); g.drawImage(images[7].getImage(), 0, 0, level);
if ((periscopeAnimation >=8 && periscopeAnimation <16) }
|| periscopeAnimation >=24) if ((periscopeAnimation >= 8 && periscopeAnimation < 16)
|| periscopeAnimation >= 24) {
g.drawImage(images[8].getImage(), 0, 0, level); g.drawImage(images[8].getImage(), 0, 0, level);
if (periscopeAnimation >=16 && periscopeAnimation <24) }
if (periscopeAnimation >= 16 && periscopeAnimation < 24) {
g.drawImage(images[9].getImage(), 0, 0, level); g.drawImage(images[9].getImage(), 0, 0, level);
} }
}
// g.setColor(Color.magenta); // g.setColor(Color.magenta);
// g.drawRect(orgX+leftPortal.x, orgY+leftPortal.y, // g.drawRect(orgX+leftPortal.x, orgY+leftPortal.y,
@@ -471,16 +473,11 @@ public void Decorate()
} }
public boolean CanBePickedUp(Item item) public boolean CanBePickedUp(Item item) {
{ return !item.getClass().toString().endsWith("Robot") && super.CanBePickedUp(item);
if (item.getClass().toString().endsWith("Robot"))
return false;
else
return super.CanBePickedUp(item);
} }
public void Erase() public void Erase() {
{
super.Erase(); super.Erase();
devices = null; devices = null;
} }

View File

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

View File

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

View File

@@ -9,41 +9,39 @@ import javax.swing.ImageIcon;
import com.droidquest.Room; import com.droidquest.Room;
public class Hexagon extends Item public class Hexagon extends Item {
{ private Color color;
Color color;
public Hexagon(int X, int Y, Room r, Color c) public Hexagon(int X, int Y, Room r, Color c) {
{ x = X;
x=X; y=Y; room=r; y = Y;
width=28; height=28; room = r;
width = 28;
height = 28;
color = c; color = c;
editable=true; editable = true;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(color); g.setColor(color);
int[] xp = { 7, 21, 27, 21, 7, 0}; int[] xp = {7, 21, 27, 21, 7, 0};
int[] yp = { 0, 0, 14, 27, 27, 14}; int[] yp = {0, 0, 14, 27, 27, 14};
g.fillPolygon(xp,yp,6); g.fillPolygon(xp, yp, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }

View File

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

View File

@@ -9,42 +9,40 @@ import javax.swing.ImageIcon;
import com.droidquest.Room; import com.droidquest.Room;
public class Magnet extends Item public class Magnet extends Item {
{ public Magnet(int X, int Y, Room r) {
public Magnet(int X, int Y, Room r) x = X;
{ y = Y;
x=X; y=Y; room=r; room = r;
width=28; height=20; width = 28;
height = 20;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0,4,8,12); g.fillRect(0, 4, 8, 12);
g.fillRect(4,2,8,6); g.fillRect(4, 2, 8, 6);
g.fillRect(4,12,8,6); g.fillRect(4, 12, 8, 6);
g.fillRect(8,0,20,6); g.fillRect(8, 0, 20, 6);
g.fillRect(8,14,20,6); g.fillRect(8, 14, 20, 6);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(20,0,4,6); g.fillRect(20, 0, 4, 6);
g.fillRect(20,14,4,6); g.fillRect(20, 14, 4, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -11,51 +11,48 @@ import com.droidquest.Room;
import com.droidquest.devices.Prototype16Chip; import com.droidquest.devices.Prototype16Chip;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
public class PC16Button extends Item public class PC16Button extends Item {
{ public PC16Button(int X, int Y, Room r) {
public PC16Button(int X, int Y, Room r) x = X;
{ y = Y;
x=X; y=Y; room=r; room = r;
width=28; height=26; width = 28;
height = 26;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,12,26); g.fillRect(8, 0, 12, 26);
g.fillRect(4,2,20,22); g.fillRect(4, 2, 20, 22);
g.fillRect(0,4,28,18); g.fillRect(0, 4, 28, 18);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,6,12,14); g.fillRect(8, 6, 12, 14);
g.fillRect(4,8,20,10); g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(12,8,4,10); g.fillRect(12, 8, 4, 10);
g.fillRect(8,10,12,6); g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public boolean CanBePickedUp(Item i) public boolean CanBePickedUp(Item i) {
{
Prototype16Chip newPC = new Prototype16Chip(228, 160, room); Prototype16Chip newPC = new Prototype16Chip(228, 160, room);
level.items.addElement(newPC); level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND); level.PlaySound(room, Level.CHARGESOUND);
return false; return false;
} }

View File

@@ -11,51 +11,48 @@ import com.droidquest.Room;
import com.droidquest.devices.Prototype32Chip; import com.droidquest.devices.Prototype32Chip;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
public class PC32Button extends Item public class PC32Button extends Item {
{ public PC32Button(int X, int Y, Room r) {
public PC32Button(int X, int Y, Room r) x = X;
{ y = Y;
x=X; y=Y; room=r; room = r;
width=28; height=26; width = 28;
height = 26;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,12,26); g.fillRect(8, 0, 12, 26);
g.fillRect(4,2,20,22); g.fillRect(4, 2, 20, 22);
g.fillRect(0,4,28,18); g.fillRect(0, 4, 28, 18);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,6,12,14); g.fillRect(8, 6, 12, 14);
g.fillRect(4,8,20,10); g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(12,8,4,10); g.fillRect(12, 8, 4, 10);
g.fillRect(8,10,12,6); g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public boolean CanBePickedUp(Item i) public boolean CanBePickedUp(Item i) {
{
Prototype32Chip newPC = new Prototype32Chip(228, 160, room); Prototype32Chip newPC = new Prototype32Chip(228, 160, room);
level.items.addElement(newPC); level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND); level.PlaySound(room, Level.CHARGESOUND);
return false; return false;
} }

View File

@@ -11,51 +11,48 @@ import com.droidquest.Room;
import com.droidquest.devices.PrototypeChip; import com.droidquest.devices.PrototypeChip;
import com.droidquest.levels.Level; import com.droidquest.levels.Level;
public class PCButton extends Item public class PCButton extends Item {
{ public PCButton(int X, int Y, Room r) {
public PCButton(int X, int Y, Room r) x = X;
{ y = Y;
x=X; y=Y; room=r; room = r;
width=28; height=26; width = 28;
height = 26;
GenerateIcons(); GenerateIcons();
} }
public void GenerateIcons() public void GenerateIcons() {
{
icons = new ImageIcon[1]; icons = new ImageIcon[1];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
Graphics g; Graphics g;
try try {
{
g = icons[0].getImage().getGraphics(); g = icons[0].getImage().getGraphics();
} }
catch (NullPointerException e) catch (NullPointerException e) {
{
System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return; return;
} }
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Color transparent = new Color(0,0,0,0); Color transparent = new Color(0, 0, 0, 0);
g2.setBackground(transparent); g2.setBackground(transparent);
g2.clearRect(0,0,width,height); g2.clearRect(0, 0, width, height);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(8,0,12,26); g.fillRect(8, 0, 12, 26);
g.fillRect(4,2,20,22); g.fillRect(4, 2, 20, 22);
g.fillRect(0,4,28,18); g.fillRect(0, 4, 28, 18);
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(8,6,12,14); g.fillRect(8, 6, 12, 14);
g.fillRect(4,8,20,10); g.fillRect(4, 8, 20, 10);
g.setColor(Color.blue); g.setColor(Color.blue);
g.fillRect(12,8,4,10); g.fillRect(12, 8, 4, 10);
g.fillRect(8,10,12,6); g.fillRect(8, 10, 12, 6);
currentIcon = icons[0].getImage(); currentIcon = icons[0].getImage();
} }
public boolean CanBePickedUp(Item i) public boolean CanBePickedUp(Item i) {
{
PrototypeChip newPC = new PrototypeChip(228, 160, room); PrototypeChip newPC = new PrototypeChip(228, 160, room);
level.items.addElement(newPC); level.items.addElement(newPC);
level.PlaySound(room,Level.CHARGESOUND); level.PlaySound(room, Level.CHARGESOUND);
return false; return false;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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