Initial Version
This commit is contained in:
773
src/com/droidquest/avatars/GameCursor.java
Normal file
773
src/com/droidquest/avatars/GameCursor.java
Normal file
@@ -0,0 +1,773 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.RoomDisplay;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.devices.GenericChip;
|
||||
import com.droidquest.devices.SmallChip;
|
||||
import com.droidquest.items.GenericRobot;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.items.ToolBox;
|
||||
|
||||
public class GameCursor extends Item
|
||||
{
|
||||
private int walk = 0; // 0 or 1, used in animation
|
||||
public boolean outline; // Draw outline around GameCursor?
|
||||
|
||||
public GameCursor(){}
|
||||
|
||||
public GameCursor(int X, int Y, Room r)
|
||||
{
|
||||
x=X; y=Y;
|
||||
outline=false;
|
||||
room=r;
|
||||
width=28; height=32;
|
||||
GenerateIcons();
|
||||
}
|
||||
|
||||
public void GenerateIcons()
|
||||
{
|
||||
// Executed once during initialization
|
||||
icons = new ImageIcon[8];
|
||||
icons[0]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[1]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[2]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[3]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[4]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[5]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[6]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[7]= new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
Graphics g;
|
||||
Graphics2D g2;
|
||||
Color transparent = new Color(0,0,0,0);
|
||||
|
||||
// 0 = up, left leg up
|
||||
try
|
||||
{
|
||||
g = icons[0].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,20,4);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(4,10,20,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(0,12,4,8);
|
||||
g.fillRect(24,12,4,6);
|
||||
g.fillRect(4,22,8,8);
|
||||
g.fillRect(16,20,8,12);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,26,8,2);
|
||||
g.fillRect(16,28,8,2);
|
||||
|
||||
// 1 = up, right leg up
|
||||
try
|
||||
{
|
||||
g = icons[1].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,20,4);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(4,10,20,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(0,12,4,6);
|
||||
g.fillRect(24,12,4,8);
|
||||
g.fillRect(4,20,8,12);
|
||||
g.fillRect(16,22,8,8);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,28,8,2);
|
||||
g.fillRect(16,26,8,2);
|
||||
|
||||
// 2 = down, left(side) leg up
|
||||
try
|
||||
{
|
||||
g = icons[2].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,20,4);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(4,10,20,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(0,12,4,8);
|
||||
g.fillRect(24,12,4,6);
|
||||
g.fillRect(4,22,8,8);
|
||||
g.fillRect(16,20,8,12);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(8,2,4,2);
|
||||
g.fillRect(16,2,4,2);
|
||||
g.fillRect(12,4,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,26,8,2);
|
||||
g.fillRect(16,28,8,2);
|
||||
|
||||
// 3 = down, right(side) leg up
|
||||
try
|
||||
{
|
||||
g = icons[3].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,20,4);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(4,10,20,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(0,12,4,6);
|
||||
g.fillRect(24,12,4,8);
|
||||
g.fillRect(4,20,8,12);
|
||||
g.fillRect(16,22,8,8);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(8,2,4,2);
|
||||
g.fillRect(16,2,4,2);
|
||||
g.fillRect(12,4,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,28,8,2);
|
||||
g.fillRect(16,26,8,2);
|
||||
|
||||
// 4 = left, Stand
|
||||
try
|
||||
{
|
||||
g = icons[4].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(20,2,4,4);
|
||||
g.fillRect(4,4,4,2);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(12,10,8,18);
|
||||
g.fillRect(8,12,4,12);
|
||||
g.fillRect(8,30,12,2);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(12,2,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(12,28,8,2);
|
||||
|
||||
// 5 = left, walk
|
||||
try
|
||||
{
|
||||
g = icons[5].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(20,2,4,4);
|
||||
g.fillRect(4,4,4,2);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(4,12,20,4);
|
||||
g.fillRect(0,14,4,4);
|
||||
g.fillRect(24,14,4,6);
|
||||
g.fillRect(4,24,8,8);
|
||||
g.fillRect(16,22,8,10);
|
||||
g.fillRect(0,30,4,2);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(12,2,4,2);
|
||||
g.fillRect(16,14,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,28,8,2);
|
||||
g.fillRect(16,28,8,2);
|
||||
|
||||
// 6 = right, Stand
|
||||
try
|
||||
{
|
||||
g = icons[6].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,4,4);
|
||||
g.fillRect(20,4,4,2);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(8,10,8,18);
|
||||
g.fillRect(16,12,4,12);
|
||||
g.fillRect(8,30,12,2);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(12,2,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(8,28,8,2);
|
||||
|
||||
// 7 = right, walk
|
||||
try
|
||||
{
|
||||
g = icons[7].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to GameCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,28,32);
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(8,0,12,8);
|
||||
g.fillRect(4,2,4,4);
|
||||
g.fillRect(20,4,4,2);
|
||||
g.fillRect(12,8,4,2);
|
||||
g.fillRect(8,10,12,14);
|
||||
g.fillRect(4,12,20,4);
|
||||
g.fillRect(0,14,4,6);
|
||||
g.fillRect(24,14,4,4);
|
||||
g.fillRect(4,22,8,10);
|
||||
g.fillRect(16,24,8,8);
|
||||
g.fillRect(24,30,4,2);
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(12,2,4,2);
|
||||
g.fillRect(8,14,4,2);
|
||||
g.fillRect(8,18,12,2);
|
||||
g.fillRect(4,28,8,2);
|
||||
g.fillRect(16,28,8,2);
|
||||
currentIcon = icons[6].getImage();
|
||||
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.UpEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveUp( nudge);
|
||||
walk = 1-walk;
|
||||
currentIcon = icons[0+walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.DownEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveDown( nudge);
|
||||
walk = 1-walk;
|
||||
currentIcon = icons[2+walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.LeftEnterOverlap(this))
|
||||
{
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveLeft( nudge);
|
||||
walk = 1-walk;
|
||||
currentIcon = icons[4+walk].getImage();
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
{
|
||||
if (item.RightEnterOverlap(this))
|
||||
{
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight( nudge);
|
||||
walk = 1-walk;
|
||||
currentIcon = icons[6+walk].getImage();
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, RoomDisplay rd)
|
||||
{
|
||||
g.drawImage(currentIcon, x, y, rd);
|
||||
if (outline)
|
||||
{
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(x,y,28,32);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CanBePickedUp(Item i)
|
||||
{
|
||||
if (i.getClass().toString().endsWith("Robot"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_L)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying.getClass().toString().endsWith("SmallChip"))
|
||||
{
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Load Chip", FileDialog.LOAD);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null)
|
||||
{
|
||||
((SmallChip)carrying).Empty();
|
||||
((SmallChip)carrying).LoadChip(fd.getDirectory()+fd.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_S)
|
||||
{
|
||||
if (level.solderingPen == null) return false;
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.solderingPen;
|
||||
level.player = level.solderingPen;
|
||||
if (level.remote != null)
|
||||
if (level.remote.carriedBy != null)
|
||||
{
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_R)
|
||||
{
|
||||
if (level.remote == null) return false;
|
||||
if (level.remote.carriedBy == null)
|
||||
{ // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else
|
||||
{ // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
// if (carrying != null)
|
||||
// Drops();
|
||||
// level.remote.x = x;
|
||||
// level.remote.y = y;
|
||||
// level.remote.room = room;
|
||||
// room = null;
|
||||
// if (level.currentViewer == level.player)
|
||||
// level.currentViewer=level.remote;
|
||||
// level.player = level.remote;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_T)
|
||||
{
|
||||
if (level.toolbox == null)
|
||||
{
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
level.toolbox = new ToolBox(x,y+8,room);
|
||||
level.items.addElement(level.toolbox);
|
||||
((ToolBox)level.toolbox).Toggle();
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
if (level.toolbox.room != room)
|
||||
{
|
||||
// Summon Toolbox
|
||||
if (carrying != null) return false;
|
||||
if (((ToolBox)level.toolbox).open) ((ToolBox)level.toolbox).Toggle();
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x+28;
|
||||
level.toolbox.y = y+6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else
|
||||
((ToolBox)level.toolbox).Toggle();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SLASH)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying.getClass().toString().endsWith("Chip"))
|
||||
{
|
||||
((GenericChip)carrying).ShowText(true);
|
||||
return false;
|
||||
}
|
||||
if (level.helpCam == null) return false;
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
if (level.cheatmode)
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.rightRoom);
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
if (level.cheatmode)
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.leftRoom);
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
if (level.cheatmode)
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.upRoom);
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
if (level.cheatmode)
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.downRoom);
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
{
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item!=null)
|
||||
if (item.getClass().toString().endsWith("Train"))
|
||||
{
|
||||
item.CanBePickedUp(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
else
|
||||
{
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null)
|
||||
if (item.CanBePickedUp(level.gameCursor))
|
||||
PicksUp(item);
|
||||
}
|
||||
outline = false;
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_CLOSE_BRACKET)
|
||||
{
|
||||
if (carrying !=null)
|
||||
if (carrying.isDevice())
|
||||
((Device) carrying).rotate(1);
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_OPEN_BRACKET)
|
||||
{
|
||||
if (carrying !=null)
|
||||
if (carrying.isDevice())
|
||||
((Device) carrying).rotate(-1);
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_E)
|
||||
{
|
||||
boolean found=false;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item!=null)
|
||||
if (item.InternalRoom!=null)
|
||||
if (Overlaps(item))
|
||||
// if (x>=item.x && y>=item.y
|
||||
// && x+width <= item.x + item.width
|
||||
// && y+height <= item.y + item.height)
|
||||
if (!item.OverWall())
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_X)
|
||||
{
|
||||
if (room.portalItem!=null)
|
||||
{
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth()/2
|
||||
- width/2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight()/4*2
|
||||
- height/2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_F)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying instanceof Device)
|
||||
((Device)carrying).flip();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_M)
|
||||
{
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freemem = runtime.freeMemory();
|
||||
long totalmem = runtime.totalMemory();
|
||||
System.out.println("Total Memory = "+ totalmem
|
||||
+ ", (" + totalmem/1024 + "K), ("
|
||||
+ totalmem/1024/1024 + "M)");
|
||||
System.out.println("Free Memory = "+ freemem
|
||||
+ ", (" + freemem/1024 + "K), ("
|
||||
+ freemem/1024/1024 + "M)");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>5)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>5)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>5)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>5)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
if (level.player == level.gameCursor)
|
||||
outline = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
if (automove==1 && room == null)
|
||||
automove=0;
|
||||
if (automove==1)
|
||||
{
|
||||
int dx = autoX - x;
|
||||
int dy = autoY - y;
|
||||
if (dx==0 && dy==0)
|
||||
{
|
||||
automove=0;
|
||||
return;
|
||||
}
|
||||
if (dx<-28) dx =-28;
|
||||
if (dx>28) dx=28;
|
||||
if (dy<-32) dy=-32;
|
||||
if (dy>32) dy=32;
|
||||
walk = 1-walk;
|
||||
if (dx==0)
|
||||
{
|
||||
if (dy<0)
|
||||
currentIcon = icons[0+walk].getImage();
|
||||
else
|
||||
currentIcon = icons[2+walk].getImage();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dx<0)
|
||||
currentIcon = icons[4+walk].getImage();
|
||||
else
|
||||
currentIcon = icons[6+walk].getImage();
|
||||
}
|
||||
if (dx>0) MoveRight(dx);
|
||||
if (dx<0) MoveLeft(-dx);
|
||||
if (dy>0) MoveDown(dy);
|
||||
if (dy<0) MoveUp(-dy);
|
||||
}
|
||||
if (automove==2)
|
||||
{
|
||||
walk = 1-walk;
|
||||
if (autoX>0)
|
||||
{
|
||||
currentIcon = icons[6+walk].getImage();
|
||||
MoveRight(autoX);
|
||||
}
|
||||
|
||||
if (autoX<0)
|
||||
{
|
||||
currentIcon = icons[4+walk].getImage();
|
||||
MoveLeft(-autoX);
|
||||
}
|
||||
|
||||
if (autoY>0)
|
||||
{
|
||||
currentIcon = icons[2+walk].getImage();
|
||||
MoveDown(autoY);
|
||||
}
|
||||
|
||||
if (autoY<0)
|
||||
{
|
||||
currentIcon = icons[0+walk].getImage();
|
||||
MoveUp(-autoY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GenericRobot PlayerInRobot(GenericRobot robot)
|
||||
{
|
||||
if (robot==null)
|
||||
{
|
||||
if (level.player.room.portalItem!=null)
|
||||
{
|
||||
if (level.player.room.portalItem.getClass().toString().endsWith("Robot"))
|
||||
return (PlayerInRobot ((GenericRobot) level.player.room.portalItem));
|
||||
else return (null);
|
||||
}
|
||||
else
|
||||
return (null);
|
||||
}
|
||||
else
|
||||
if (robot.room.portalItem != null)
|
||||
{
|
||||
if (robot.room.portalItem.getClass().toString().endsWith("Robot"))
|
||||
return (PlayerInRobot ((GenericRobot) robot.room.portalItem));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return robot;
|
||||
}
|
||||
|
||||
}
|
45
src/com/droidquest/avatars/HelpCam.java
Normal file
45
src/com/droidquest/avatars/HelpCam.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.items.Item;
|
||||
|
||||
public class HelpCam extends Item
|
||||
{
|
||||
public HelpCam(Room r)
|
||||
{
|
||||
charge=0;
|
||||
x=28; y=32; width=0; height=0; room =r;
|
||||
GenerateIcons();
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
public void GenerateIcons()
|
||||
{
|
||||
icons = new ImageIcon[1];
|
||||
icons[0] = new ImageIcon(new BufferedImage(8,8,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_ENTER)
|
||||
{
|
||||
level.player = level.gameCursor;
|
||||
level.currentViewer = level.gameCursor;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, JPanel jp)
|
||||
{
|
||||
// Draws nothing
|
||||
}
|
||||
|
||||
|
||||
}
|
440
src/com/droidquest/avatars/LabCursor.java
Normal file
440
src/com/droidquest/avatars/LabCursor.java
Normal file
@@ -0,0 +1,440 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.devices.GenericChip;
|
||||
import com.droidquest.devices.SmallChip;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.items.ToolBox;
|
||||
|
||||
public class LabCursor extends Item
|
||||
{
|
||||
public boolean hot;
|
||||
|
||||
public LabCursor(){}
|
||||
|
||||
public LabCursor(int X, int Y, Room r)
|
||||
{
|
||||
x=X; y=Y;
|
||||
hot=false;
|
||||
room=r;
|
||||
width=28; height=32;
|
||||
GenerateIcons();
|
||||
}
|
||||
|
||||
public void GenerateIcons()
|
||||
{
|
||||
icons = new ImageIcon[2];
|
||||
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[1]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
Graphics g;
|
||||
try
|
||||
{
|
||||
g = icons[0].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to LabCursor Image");
|
||||
return;
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0,0,width,height);
|
||||
try
|
||||
{
|
||||
g = icons[1].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to LabCursor Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g.setColor(new Color(255,128,0));
|
||||
g.fillRect(0,0,width,height);
|
||||
if (hot)
|
||||
currentIcon = icons[1].getImage();
|
||||
else
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
public boolean CanBePickedUp(Item i)
|
||||
{
|
||||
if (i.getClass().toString().endsWith("Robot"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_L)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying.getClass().toString().endsWith("SmallChip"))
|
||||
{
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Load Chip", FileDialog.LOAD);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null)
|
||||
{
|
||||
((SmallChip)carrying).Empty();
|
||||
((SmallChip)carrying).LoadChip(fd.getDirectory()+fd.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_H)
|
||||
{
|
||||
hot = !hot;
|
||||
if (hot)
|
||||
currentIcon = icons[1].getImage();
|
||||
else
|
||||
currentIcon = icons[0].getImage();
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_S)
|
||||
{
|
||||
if (level.solderingPen == null) return false;
|
||||
if (carrying != null)
|
||||
if (carrying.getClass().toString().endsWith("SmallChip"))
|
||||
{
|
||||
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Save Chip", FileDialog.SAVE);
|
||||
fd.setDirectory("chips");
|
||||
fd.show();
|
||||
System.out.println("Dialog returned with "
|
||||
+ fd.getDirectory()
|
||||
+ fd.getFile());
|
||||
if (fd.getFile() != null)
|
||||
((SmallChip)carrying).SaveChip(fd.getDirectory()+fd.getFile());
|
||||
return false;
|
||||
}
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.solderingPen;
|
||||
level.player = level.solderingPen;
|
||||
if (level.remote != null)
|
||||
if (level.remote.carriedBy != null)
|
||||
{
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_R)
|
||||
{
|
||||
if (level.remote == null) return false;
|
||||
if (level.remote.carriedBy == null)
|
||||
{ // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else
|
||||
{ // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
// if (carrying != null)
|
||||
// Drops();
|
||||
// level.remote.x = x;
|
||||
// level.remote.y = y;
|
||||
// level.remote.room = room;
|
||||
// room = null;
|
||||
// if (level.currentViewer == level.player)
|
||||
// level.currentViewer=level.remote;
|
||||
// level.player = level.remote;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_P)
|
||||
{
|
||||
if (level.paintbrush == null) return false;
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
level.paintbrush.x = (x/28)*28;
|
||||
level.paintbrush.y = (y/32)*32;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.paintbrush;
|
||||
level.player = level.paintbrush;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_T)
|
||||
{
|
||||
if (level.toolbox == null) return false;
|
||||
if (level.toolbox.room != room)
|
||||
{
|
||||
// Summon Toolbox
|
||||
if (carrying != null) return false;
|
||||
if (((ToolBox)level.toolbox).open) ((ToolBox)level.toolbox).Toggle();
|
||||
level.toolbox.room = room;
|
||||
level.toolbox.x = x+28;
|
||||
level.toolbox.y = y+6;
|
||||
PicksUp(level.toolbox);
|
||||
}
|
||||
else
|
||||
((ToolBox)level.toolbox).Toggle();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SLASH)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying.getClass().toString().endsWith("Chip"))
|
||||
{
|
||||
((GenericChip)carrying).ShowText(true);
|
||||
return false;
|
||||
}
|
||||
if (level.helpCam == null) return false;
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
if (carrying != null)
|
||||
Drops();
|
||||
else
|
||||
{
|
||||
Item item = level.FindNearestItem(level.gameCursor);
|
||||
if (item != null)
|
||||
if (item.CanBePickedUp(level.gameCursor))
|
||||
PicksUp(item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_CLOSE_BRACKET)
|
||||
{
|
||||
if (carrying !=null)
|
||||
if (carrying.isDevice())
|
||||
((Device) carrying).rotate(1);
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_OPEN_BRACKET)
|
||||
{
|
||||
if (carrying !=null)
|
||||
if (carrying.isDevice())
|
||||
((Device) carrying).rotate(-1);
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_E)
|
||||
{
|
||||
boolean found=false;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item!=null)
|
||||
if (item.InternalRoom!=null)
|
||||
if (Overlaps(item))
|
||||
if (!item.OverWall())
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_X)
|
||||
{
|
||||
if (room.portalItem!=null)
|
||||
{
|
||||
Dimension d = room.portalItem.GetXY();
|
||||
int newX = d.width
|
||||
+ room.portalItem.getWidth()/2
|
||||
- width/2;
|
||||
int newY = d.height
|
||||
+ room.portalItem.getHeight()/4*2
|
||||
- height/2;
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(room.portalItem.room);
|
||||
level.currentViewer = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_F)
|
||||
{
|
||||
if (carrying != null)
|
||||
if (carrying instanceof Device)
|
||||
((Device)carrying).flip();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_M)
|
||||
{
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freemem = runtime.freeMemory();
|
||||
long totalmem = runtime.totalMemory();
|
||||
System.out.println("Total Memory = "+ totalmem
|
||||
+ ", (" + totalmem/1024 + "K), ("
|
||||
+ totalmem/1024/1024 + "M)");
|
||||
System.out.println("Free Memory = "+ freemem
|
||||
+ ", (" + freemem/1024 + "K), ("
|
||||
+ freemem/1024/1024 + "M)");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.UpEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveUp( nudge);
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.DownEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveDown( nudge);
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.LeftEnterOverlap(this))
|
||||
{
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveLeft( nudge);
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
{
|
||||
if (item.RightEnterOverlap(this))
|
||||
{
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight( nudge);
|
||||
}
|
||||
|
||||
}
|
277
src/com/droidquest/avatars/PaintBrush.java
Normal file
277
src/com/droidquest/avatars/PaintBrush.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.droidquest.items.GenericRobot;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.materials.Material;
|
||||
import com.droidquest.materials.RobotBlocker;
|
||||
|
||||
public class PaintBrush extends Item
|
||||
{
|
||||
// The Paintbrush works just like the original, except it allows
|
||||
// differnt color paints for differnt materials. Pressing 'P' as the
|
||||
// Paintbrush switches the Material Settings.
|
||||
//
|
||||
// Detectable, blocks all Red
|
||||
// Undetectable, blocks all Green
|
||||
// Undetectable, blocks Orange Orange
|
||||
// Undetectable, blocks White White
|
||||
// Undetectable, blocks Blue Blue
|
||||
|
||||
int emptyIndex=0;
|
||||
int paintIndex; // Which paintMats[] am I using?
|
||||
transient Material[] paintMats;
|
||||
int matIndex; // index of chosen paintMax in level.materials
|
||||
|
||||
public PaintBrush()
|
||||
{
|
||||
width=28; height=32;
|
||||
GenerateIcons();
|
||||
}
|
||||
|
||||
public void GenerateIcons()
|
||||
{
|
||||
icons = new ImageIcon[5];
|
||||
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[1]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[2]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[3]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[4]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
Graphics g;
|
||||
Graphics2D g2;
|
||||
Color transparent = new Color(0,0,0,0);
|
||||
for (int a=0; a<5; a++)
|
||||
{
|
||||
try
|
||||
{
|
||||
g = icons[a].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to PaintBrush Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(transparent);
|
||||
g2.clearRect(0,0,width,height);
|
||||
switch(a)
|
||||
{
|
||||
case 0: g.setColor(new Color(192,0,0));
|
||||
break;
|
||||
case 1: g.setColor(new Color(0,192,0));
|
||||
break;
|
||||
case 2: g.setColor(new Color(192,96,0));
|
||||
break;
|
||||
case 3: g.setColor(new Color(192,192,192));
|
||||
break;
|
||||
case 4: g.setColor(new Color(0,0,192));
|
||||
break;
|
||||
}
|
||||
|
||||
g2.fillRect(0,0,28,18);
|
||||
g2.fillRect(4,18,20,2);
|
||||
g2.fillRect(8,20,12,10);
|
||||
g2.fillRect(12,30,4,2);
|
||||
g.setColor(Color.black);
|
||||
g2.fillRect(0,12,28,2);
|
||||
g2.fillRect(12,26,4,2);
|
||||
}
|
||||
currentIcon=icons[0].getImage();
|
||||
|
||||
paintMats = new Material[5];
|
||||
emptyIndex = 0;
|
||||
paintMats[0] = Material.FindSimiliar(new Material(Color.red, false, true));
|
||||
paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false));
|
||||
Item robot=null;
|
||||
for (int a=0; a<level.items.size(); a++)
|
||||
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("OrangeRobot"))
|
||||
robot = (GenericRobot) level.items.elementAt(a);
|
||||
if (robot==null)
|
||||
System.out.println("Create paintbrush AFTER creating robots.");
|
||||
paintMats[2] = Material.FindSimiliar(new RobotBlocker(robot, new Color(255,128,0)));
|
||||
for (int a=0; a<level.items.size(); a++)
|
||||
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("WhiteRobot"))
|
||||
robot = (GenericRobot) level.items.elementAt(a);
|
||||
paintMats[3] = Material.FindSimiliar(new RobotBlocker(robot, Color.white));
|
||||
for (int a=0; a<level.items.size(); a++)
|
||||
if (((Item)level.items.elementAt(a)).getClass().toString().endsWith("BlueRobot"))
|
||||
robot = (GenericRobot) level.items.elementAt(a);
|
||||
paintMats[4] = Material.FindSimiliar(new RobotBlocker(robot, Color.blue));
|
||||
|
||||
paintIndex=0;
|
||||
matIndex = level.materials.indexOf(paintMats[paintIndex]);
|
||||
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_C)
|
||||
{
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.gameCursor;
|
||||
level.player = level.gameCursor;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_S)
|
||||
{
|
||||
if (level.solderingPen == null) return false;
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.solderingPen;
|
||||
level.player = level.solderingPen;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_R)
|
||||
{
|
||||
if (level.remote == null) return false;
|
||||
level.remote.x = x;
|
||||
level.remote.y = y;
|
||||
level.remote.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.remote;
|
||||
level.player = level.remote;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SLASH)
|
||||
{
|
||||
if (level.helpCam == null) return false;
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.rightRoom);
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.leftRoom);
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.upRoom);
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
if (e.isShiftDown())
|
||||
SetRoom(room.downRoom);
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_P)
|
||||
{
|
||||
paintIndex++;
|
||||
if (paintIndex==5) paintIndex=0;
|
||||
matIndex = level.materials.indexOf(paintMats[paintIndex]);
|
||||
currentIcon=icons[paintIndex].getImage();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
if (!room.editable) return false;
|
||||
int bigX=(x+14)/28;
|
||||
int bigY=(y+16)/32;
|
||||
if (room.RoomArray[bigY][bigX]==emptyIndex)
|
||||
room.SetMaterial(bigX,bigY,matIndex);
|
||||
else
|
||||
room.SetMaterial(bigX,bigY,emptyIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge)
|
||||
{
|
||||
int dist = 32;
|
||||
if (nudge) dist = 2;
|
||||
y=y-dist;
|
||||
if (y<0)
|
||||
{
|
||||
if (room.getUpRoom(this) != null)
|
||||
{ // change Rooms
|
||||
y=y+384;
|
||||
SetRoom(room.getUpRoom(this));
|
||||
}
|
||||
else // stop at top
|
||||
y=0;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge)
|
||||
{
|
||||
int dist = 32;
|
||||
if (nudge) dist = 2;
|
||||
y=y+dist;
|
||||
if (y>383)
|
||||
{
|
||||
if (room.getDownRoom(this) != null)
|
||||
{ // change Rooms
|
||||
y=y-384;
|
||||
SetRoom(room.getDownRoom(this));
|
||||
}
|
||||
else // stop at bottom
|
||||
y=384-32;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge)
|
||||
{
|
||||
int dist = 28;
|
||||
if (nudge) dist = 2;
|
||||
x=x-dist;
|
||||
if (x<0)
|
||||
{
|
||||
if (room.getLeftRoom(this) != null)
|
||||
{ // change Rooms
|
||||
x=x+560;
|
||||
SetRoom(room.getLeftRoom(this));
|
||||
}
|
||||
else // stop at left
|
||||
x=0;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge)
|
||||
{
|
||||
int dist = 28;
|
||||
if (nudge) dist = 2;
|
||||
x=x+dist;
|
||||
if (x>559)
|
||||
{
|
||||
if (room.getRightRoom(this) != null)
|
||||
{ // change Rooms
|
||||
x=x-560;
|
||||
SetRoom(room.getRightRoom(this));
|
||||
}
|
||||
else // stop at right
|
||||
x=560-28;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
311
src/com/droidquest/avatars/Remote.java
Normal file
311
src/com/droidquest/avatars/Remote.java
Normal file
@@ -0,0 +1,311 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.droidquest.items.Item;
|
||||
|
||||
public class Remote extends Item
|
||||
{
|
||||
public Remote()
|
||||
{
|
||||
// width=28; height=32;
|
||||
width=4; height=20;
|
||||
level.electricity = true;
|
||||
GenerateIcons();
|
||||
}
|
||||
|
||||
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[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
|
||||
Graphics g;
|
||||
Graphics2D g2;
|
||||
try
|
||||
{
|
||||
g = icons[0].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to Remote Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(new Color(0,0,0,0));
|
||||
g2.clearRect(0,0,width,height);
|
||||
g2.setColor(new Color(255,128,0));
|
||||
g2.fillRect(2,0,2,20);
|
||||
g2.fillRect(0,16,4,4);
|
||||
currentIcon = icons[0].getImage();
|
||||
|
||||
// try
|
||||
// {
|
||||
// g = icons[0].getImage().getGraphics();
|
||||
// }
|
||||
// catch (NullPointerException e)
|
||||
// {
|
||||
// System.out.println("Could not get Graphics pointer to Remote Image[0]");
|
||||
// return;
|
||||
// }
|
||||
// g2 = (Graphics2D) g;
|
||||
// g2.setBackground(new Color(0,0,0,0));
|
||||
// g2.clearRect(0,0,width,height);
|
||||
// g2.setColor(Color.white);
|
||||
// g2.fillRect(20,0,4,12);
|
||||
// g2.fillRect(0,12,28,20);
|
||||
// g2.setColor(Color.black);
|
||||
// g2.fillRect(8,14,12,2);
|
||||
// g2.fillRect(4,18,20,2);
|
||||
// g2.fillRect(8,22,12,2);
|
||||
// g2.fillRect(20,26,4,4);
|
||||
|
||||
// try
|
||||
// {
|
||||
// g = icons[1].getImage().getGraphics();
|
||||
// }
|
||||
// catch (NullPointerException e)
|
||||
// {
|
||||
// System.out.println("Could not get Graphics pointer to Remote Image[1]");
|
||||
// return;
|
||||
// }
|
||||
// g2 = (Graphics2D) g;
|
||||
// g2.setBackground(new Color(0,0,0,0));
|
||||
// g2.clearRect(0,0,width,height);
|
||||
// g2.setColor(new Color(255,128,0));
|
||||
// g2.fillRect(20,0,4,12);
|
||||
// g2.fillRect(0,12,28,20);
|
||||
// g2.setColor(Color.black);
|
||||
// g2.fillRect(8,14,12,2);
|
||||
// g2.fillRect(4,18,20,2);
|
||||
// g2.fillRect(8,22,12,2);
|
||||
// g2.fillRect(20,26,4,4);
|
||||
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
if (carriedBy != null)
|
||||
if (carriedBy.room != room)
|
||||
room = carriedBy.room;
|
||||
super.Animate();
|
||||
// if (level.electricity)
|
||||
// currentIcon = icons[1].getImage();
|
||||
// else
|
||||
// currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
public boolean CanBePickedUp(Item i)
|
||||
{
|
||||
// if (i.getClass().toString().endsWith("Robot"))
|
||||
return false;
|
||||
// return true;
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_S)
|
||||
{
|
||||
if (level.solderingPen == null) return false;
|
||||
level.solderingPen.x = x;
|
||||
level.solderingPen.y = y;
|
||||
level.solderingPen.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.solderingPen;
|
||||
level.player = level.solderingPen;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_C)
|
||||
{
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.gameCursor;
|
||||
level.player = level.gameCursor;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_P)
|
||||
{
|
||||
if (level.paintbrush == null) return false;
|
||||
level.paintbrush.x = x;
|
||||
level.paintbrush.y = y;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.paintbrush;
|
||||
level.player = level.paintbrush;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SLASH)
|
||||
{
|
||||
if (level.helpCam == null) return false;
|
||||
if (level.player != level.helpCam)
|
||||
{
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
level.electricity = ! level.electricity;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.UpEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveUp( nudge);
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.DownEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveDown( nudge);
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.LeftEnterOverlap(this))
|
||||
{
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveLeft( nudge);
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge)
|
||||
{
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
{
|
||||
if (item.RightEnterOverlap(this))
|
||||
{
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight( nudge);
|
||||
}
|
||||
|
||||
}
|
543
src/com/droidquest/avatars/SolderingPen.java
Normal file
543
src/com/droidquest/avatars/SolderingPen.java
Normal file
@@ -0,0 +1,543 @@
|
||||
package com.droidquest.avatars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.droidquest.Room;
|
||||
import com.droidquest.Wire;
|
||||
import com.droidquest.chipstuff.Port;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.items.Item;
|
||||
|
||||
public class SolderingPen extends Device
|
||||
{
|
||||
boolean hot;
|
||||
Port currentPort=null; // Port that Soldering pen is currently over
|
||||
|
||||
public SolderingPen()
|
||||
{
|
||||
width=22; height=26;
|
||||
GenerateIcons();
|
||||
currentIcon = icons[0].getImage();
|
||||
ports = new Port[1];
|
||||
ports[0] = new Port(2,20,Port.TYPE_UNDEFINED,0,Port.ROT_DOWN, this);
|
||||
|
||||
}
|
||||
|
||||
public void GenerateIcons()
|
||||
{
|
||||
// Executed once during initialization
|
||||
icons = new ImageIcon[3];
|
||||
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[1]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
icons[2]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
|
||||
Graphics g;
|
||||
Graphics2D g2;
|
||||
try
|
||||
{
|
||||
g = icons[0].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to SolderingPen Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(new Color(0,0,0,0));
|
||||
g2.clearRect(0,0,width,height);
|
||||
g2.setColor(Color.blue);
|
||||
g2.fillRect(18,0,6,4);
|
||||
g2.fillRect(10,2,2,4);
|
||||
g2.fillRect(10,4,10,2);
|
||||
g2.fillRect(16,6,10,4);
|
||||
g2.fillRect(10,10,6,4);
|
||||
g2.fillRect(6,14,6,4);
|
||||
g2.fillRect(0,18,12,8);
|
||||
|
||||
try
|
||||
{
|
||||
g = icons[1].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to SolderingPen Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(new Color(0,0,0,0));
|
||||
g2.clearRect(0,0,width,height);
|
||||
g2.setColor(Color.blue);
|
||||
g2.fillRect(18,0,6,4);
|
||||
g2.fillRect(10,2,2,4);
|
||||
g2.fillRect(10,4,10,2);
|
||||
g2.fillRect(16,6,10,4);
|
||||
g2.fillRect(10,10,6,4);
|
||||
g2.fillRect(6,14,6,4);
|
||||
g2.setColor(new Color(255,128,0));
|
||||
g2.fillRect(0,18,12,8);
|
||||
|
||||
try
|
||||
{
|
||||
g = icons[2].getImage().getGraphics();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.out.println("Could not get Graphics pointer to SolderingPen Image");
|
||||
return;
|
||||
}
|
||||
g2 = (Graphics2D) g;
|
||||
g2.setBackground(new Color(0,0,0,0));
|
||||
g2.clearRect(0,0,width,height);
|
||||
g2.setColor(Color.blue);
|
||||
g2.fillRect(18,0,6,4);
|
||||
g2.fillRect(10,2,2,4);
|
||||
g2.fillRect(10,4,10,2);
|
||||
g2.fillRect(16,6,10,4);
|
||||
g2.fillRect(10,10,6,4);
|
||||
g2.fillRect(6,14,6,4);
|
||||
g2.setColor(Color.green);
|
||||
g2.fillRect(0,18,12,8);
|
||||
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
public void CheckPort()
|
||||
{
|
||||
hot=false;
|
||||
currentPort=null;
|
||||
// Item item = level.FindNearestItem(this);
|
||||
for (int a=0; a<level.items.size(); a++)
|
||||
{
|
||||
Item item = (Item) level.items.elementAt(a);
|
||||
if (!item.isDevice() || !Overlaps(item) || item==this)
|
||||
item=null;
|
||||
if (item!=null)
|
||||
{
|
||||
Device device = (Device) item;
|
||||
for (int b=0; b<device.ports.length; b++)
|
||||
{
|
||||
hot = true;
|
||||
if (device.ports[b].x + device.x < x) hot = false;
|
||||
if (device.ports[b].x + device.x > x+9) hot = false;
|
||||
if (device.ports[b].y + device.y < y+18) hot = false;
|
||||
if (device.ports[b].y + device.y > y+25) hot = false;
|
||||
if (hot)
|
||||
{
|
||||
currentPort = device.ports[b];
|
||||
if (device.ports[b].myWire == null)
|
||||
currentIcon = icons[1].getImage();
|
||||
else
|
||||
currentIcon = icons[2].getImage();
|
||||
b = device.ports.length;
|
||||
a = level.items.size();
|
||||
}
|
||||
else
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hot==false)
|
||||
currentIcon = icons[0].getImage();
|
||||
}
|
||||
|
||||
public void MoveUp(boolean nudge)
|
||||
{
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.UpEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 320; // 10 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveUp( nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
// wiredPort=null;
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveDown(boolean nudge)
|
||||
{
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.DownEnterOverlap(this))
|
||||
{
|
||||
int newX = 280; // 10 * 28
|
||||
int newY = 0; // 0 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveDown( nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
// wiredPort=null;
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveLeft(boolean nudge)
|
||||
{
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
if (item.LeftEnterOverlap(this))
|
||||
{
|
||||
int newX = 532; // 19 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
super.MoveLeft( nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
// wiredPort=null;
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void MoveRight(boolean nudge)
|
||||
{
|
||||
Room tempRoom = room;
|
||||
Item item = level.FindNearestItem(this);
|
||||
if (item != null)
|
||||
{
|
||||
if (item.InternalRoom != null)
|
||||
{
|
||||
if (item.RightEnterOverlap(this))
|
||||
{
|
||||
int newX = 0; // 0 * 28
|
||||
int newY = 176; // 5.5 * 32
|
||||
x = newX;
|
||||
y = newY;
|
||||
SetRoom(item.InternalRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.MoveRight( nudge);
|
||||
if (tempRoom != room && ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
// wiredPort=null;
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
Room tempRoom = room;
|
||||
super.Animate();
|
||||
if (tempRoom != room && ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
CheckPort();
|
||||
}
|
||||
|
||||
public void Decorate()
|
||||
{return;}
|
||||
|
||||
public void WirePort()
|
||||
{
|
||||
if (hot)
|
||||
{
|
||||
if (ports[0].myWire == null) // If SP is not wired
|
||||
{
|
||||
if (currentPort.myWire != null) // If currentPort is wired
|
||||
{
|
||||
// Remove Wire from currentPort
|
||||
currentPort.myWire.Remove();
|
||||
ports[0].value = false;
|
||||
ports[0].type = Port.TYPE_UNDEFINED;
|
||||
}
|
||||
else // If currentPort not wired
|
||||
{
|
||||
// Create Wire from CurrentPort to Soldering Pen
|
||||
Wire tempWire = new Wire(currentPort, ports[0]);
|
||||
}
|
||||
}
|
||||
else // if SP is wired
|
||||
{
|
||||
if (currentPort.myWire != null) // If currentPort is wired
|
||||
{
|
||||
// Remove wire at currentPort
|
||||
currentPort.myWire.Remove();
|
||||
// Remove wire attached to Pen
|
||||
if (ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
ports[0].value = false;
|
||||
ports[0].type = Port.TYPE_UNDEFINED;
|
||||
}
|
||||
else // If currentPort not wired
|
||||
{
|
||||
// Attach Wire to currentPort
|
||||
ports[0].myWire.ConnectTo(currentPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ports[0].myWire != null) // If not hot and SP wired
|
||||
{
|
||||
// Remove Wire to Pen
|
||||
ports[0].myWire.Remove();
|
||||
ports[0].value = false;
|
||||
ports[0].type = Port.TYPE_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean Function ()
|
||||
{
|
||||
if (ports[0].myWire == null)
|
||||
{
|
||||
ports[0].value = false;
|
||||
ports[0].type = Port.TYPE_UNDEFINED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CanBePickedUp(Item i)
|
||||
{
|
||||
if (i.getClass().toString().endsWith("Robot"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean KeyUp(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_C)
|
||||
{
|
||||
if (ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
level.gameCursor.x = x;
|
||||
level.gameCursor.y = y;
|
||||
level.gameCursor.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.gameCursor;
|
||||
level.player = level.gameCursor;
|
||||
if (level.remote != null)
|
||||
if (level.remote.carriedBy != null)
|
||||
{
|
||||
level.remote.carriedBy = level.player;
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_R)
|
||||
{
|
||||
if (level.remote == null) return false;
|
||||
if (level.remote.carriedBy == null)
|
||||
{ // Summon Remote
|
||||
level.remote.x = 28;
|
||||
level.remote.y = -20;
|
||||
level.remote.carriedBy = level.player;
|
||||
level.remote.room = level.player.room;
|
||||
level.electricity = true;
|
||||
}
|
||||
else
|
||||
{ // Hide Remote
|
||||
level.remote.carriedBy = null;
|
||||
level.remote.room = null;
|
||||
level.electricity = false;
|
||||
}
|
||||
// if (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)
|
||||
{
|
||||
if (level.paintbrush == null) return false;
|
||||
if (ports[0].myWire != null)
|
||||
ports[0].myWire.Remove();
|
||||
level.paintbrush.x = x;
|
||||
level.paintbrush.y = y;
|
||||
level.paintbrush.room = room;
|
||||
room = null;
|
||||
if (level.currentViewer == level.player)
|
||||
level.currentViewer=level.paintbrush;
|
||||
level.player = level.paintbrush;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SLASH)
|
||||
{
|
||||
if (level.helpCam == null) return false;
|
||||
level.player = level.helpCam;
|
||||
level.currentViewer = level.helpCam;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveRight(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveLeft(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveUp(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
if (carriedBy==null)
|
||||
MoveDown(e.isControlDown());
|
||||
repeating=0;
|
||||
return true;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_SPACE)
|
||||
{
|
||||
WirePort();
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_F)
|
||||
{
|
||||
if (hot)
|
||||
{
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
else if (ports[0].myWire == null) // If SP is not wired
|
||||
{
|
||||
// Flip wire attached to CurrentPort
|
||||
if (currentPort.myWire != null)
|
||||
{
|
||||
Port tempPort = currentPort.myWire.fromPort;
|
||||
currentPort.myWire.fromPort = currentPort.myWire.toPort;
|
||||
currentPort.myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ports[0].myWire != null) // If SP is wired
|
||||
{
|
||||
// Flip wire attached to SP
|
||||
Port tempPort = ports[0].myWire.fromPort;
|
||||
ports[0].myWire.fromPort = ports[0].myWire.toPort;
|
||||
ports[0].myWire.toPort = tempPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean KeyDown(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == e.VK_RIGHT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveRight(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_LEFT)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveLeft(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_UP)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveUp(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (e.getKeyCode() == e.VK_DOWN)
|
||||
{
|
||||
repeating++;
|
||||
if (repeating>10)
|
||||
{
|
||||
MoveDown(e.isControlDown());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MouseClick(MouseEvent e)
|
||||
{
|
||||
int button=0;
|
||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK)
|
||||
button = 1;
|
||||
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
|
||||
button = 3;
|
||||
|
||||
if (button==1)
|
||||
{
|
||||
if (e.getClickCount()==1)
|
||||
{
|
||||
autoX = e.getX() - 2;
|
||||
autoY = e.getY() - 20;
|
||||
automove = 1;
|
||||
}
|
||||
else if (e.getClickCount()==2)
|
||||
{
|
||||
int dx = e.getX() - 2 - x;
|
||||
int dy = e.getY() - 20 - y;
|
||||
if (Math.abs(dx) > Math.abs(dy))
|
||||
{
|
||||
autoY=0; autoX=28;
|
||||
if (dx<0) autoX=-28;
|
||||
automove=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
autoX=0; autoY=32;
|
||||
if (dy<0) autoY=-32;
|
||||
automove=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (button==3)
|
||||
{
|
||||
KeyEvent k = new KeyEvent(e.getComponent(), e.getID(),
|
||||
e.getWhen(), 0,
|
||||
KeyEvent.VK_SPACE, ' ');
|
||||
KeyUp(k);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user