Initial version of pathfinding

This commit is contained in:
cognitivegears
2014-04-21 21:44:36 -05:00
parent a660adb81c
commit a8e68af6db
7 changed files with 524 additions and 127 deletions

View File

@@ -3,6 +3,7 @@ package com.droidquest.avatars;
import com.droidquest.Room;
import com.droidquest.RoomDisplay;
import com.droidquest.items.*;
import com.droidquest.pathfinder.Node;
import javax.swing.*;
import java.awt.*;
@@ -324,81 +325,51 @@ public class GameCursor extends Player {
return level.cheatmode;
}
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();
}
@Override
protected void animateCharacter(int dx, int dy) {
walk = 1 - walk;
if (dx == 0) {
if (dy < 0) {
currentIcon = icons[0 + 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);
}
}
else {
if (dx < 0) {
currentIcon = icons[4 + walk].getImage();
}
else {
currentIcon = icons[6 + walk].getImage();
}
}
}
@Override
protected void autoMoveFull() {
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) {

View File

@@ -93,8 +93,8 @@ public class PaintBrush extends Player {
paintMats[1] = Material.FindSimiliar(new Material(Color.green, false, false));
Item robot = null;
for(Item item : level.items) {
if(item instanceof OrangeRobot) {
for (Item item : level.items) {
if (item instanceof OrangeRobot) {
robot = item;
}
}
@@ -104,14 +104,14 @@ public class PaintBrush extends Player {
paintMats[2] = Material.FindSimiliar(new RobotBlocker(robot, new Color(255, 128, 0)));
for (Item item : level.items) {
if(item instanceof WhiteRobot) {
if (item instanceof WhiteRobot) {
robot = item;
}
}
paintMats[3] = Material.FindSimiliar(new RobotBlocker(robot, Color.white));
for(Item item : level.items) {
if(item instanceof BlueRobot) {
for (Item item : level.items) {
if (item instanceof BlueRobot) {
robot = item;
}
}
@@ -210,9 +210,10 @@ public class PaintBrush extends Player {
@Override
protected boolean handleRepeatSpace() {
return false;
return false;
}
@Override
public void moveUp(boolean nudge) {
int dist = 32;
if (nudge) {
@@ -231,6 +232,7 @@ public class PaintBrush extends Player {
}
}
@Override
public void moveDown(boolean nudge) {
int dist = 32;
if (nudge) {
@@ -249,6 +251,20 @@ public class PaintBrush extends Player {
}
}
// @Override
// protected void findPath(int startX, int startY, int endX, int endY) {
// // The paintbrush can go anywhere
//// autoPath = new ArrayList<Node>();
//// autoPath.add(new Node(endX * 28, endY * 32));
// autoX = endX * 28;
// autoY = endY * 28;
// autoX -= autoX % 2; // Even numbered pixel only!
// autoY -= autoY % 2;
// automove = 1;
//
// }
@Override
public void moveLeft(boolean nudge) {
int dist = 28;
if (nudge) {
@@ -267,6 +283,7 @@ public class PaintBrush extends Player {
}
}
@Override
public void moveRight(boolean nudge) {
int dist = 28;
if (nudge) {

View File

@@ -225,6 +225,7 @@ public class SolderingPen extends Device implements Avatar {
CheckPort();
}
@Override
public void Animate() {
Room tempRoom = room;
super.Animate();
@@ -297,16 +298,16 @@ public class SolderingPen extends Device implements Avatar {
public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_C && handleGameCursor()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_R && handleRadio()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_P && handlePaintbrush()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_SLASH && handleHelp()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
if (carriedBy == null) {
@@ -340,13 +341,13 @@ public class SolderingPen extends Device implements Avatar {
WirePort();
}
else if (e.getKeyCode() == KeyEvent.VK_F && handleFlipDevice()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_E && handleEnterRoom()) {
return false;
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_X && handleExitRoom()) {
return false;
return false;
}
return false;
}
@@ -592,32 +593,32 @@ public class SolderingPen extends Device implements Avatar {
@Override
public boolean handleFlipDevice() {
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;
}
}
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 true;
}
}