public PathXBandit(final PathXGame game, GameLevel level) { this.game = game; this.level = level; thisB = this; d = (PathXDataModel) game.getDataModel(); int r = 0; int min = 0; int max = level.getIntersections().size(); while (currentIntersection == null) { r = (int) ((min + Math.random() * (max - min))); if (r != 0 && r != 1) { Intersection tempIntersection = level.getIntersections().get(r); if (tempIntersection.open && (tempIntersection != level.getStartingLocation() || tempIntersection != level.getDestination())) { currentIntersection = tempIntersection; } } } PropertiesManager props = PropertiesManager.getPropertiesManager(); String imgPath = props.getProperty(PathX.PathXPropertyType.PATH_IMG); BufferedImage img; SpriteType sT; // LOAD THE BACKGROUNDS, WHICH ARE GUI DECOR img = game.loadImage(imgPath + props.getProperty(PathX.PathXPropertyType.IMAGE_BANDIT)); sT = new SpriteType(BANDIT_TYPE); sT.addState(BANDIT_STATE, img); img = game.loadImage(imgPath + props.getProperty(PathX.PathXPropertyType.IMAGE_BANDIT_SELECTED)); sT.addState(BANDIT_SELECTED_STATE, img); img = game.loadImage(imgPath + props.getProperty(PathX.PathXPropertyType.IMAGE_BANDIT_MINDLESS)); sT.addState(BANDIT_MINDLESS_STATE, img); Sprite = new Sprite(sT, currentIntersection.x - 20, currentIntersection.y - 20, 0, 0, BANDIT_STATE); Sprite.setActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { PathXDataModel d = (PathXDataModel) game.getDataModel(); if (game.GameScreen.flatTire && !powerUp) { game.GameScreen.flatTire = false; game.GameScreen.currentPowerUp = ""; d.updateMoney(-20); flatTire = true; timeStart = System.currentTimeMillis(); powerUp = true; return; } if (game.GameScreen.emptyGasTank && !powerUp) { game.GameScreen.emptyGasTank = false; game.GameScreen.currentPowerUp = ""; d.updateMoney(-20); emptyGasTank = true; timeStart = System.currentTimeMillis(); powerUp = true; return; } if (game.GameScreen.mindControl && !powerUp && !game.GameScreen.selected) { Sprite.setState(BANDIT_SELECTED_STATE); game.GameScreen.banditControlled = thisB; game.GameScreen.selected = true; return; } if (game.GameScreen.mindlessTerror && !powerUp && !stunned && !game.GameScreen.selected) { ((PathXDataModel) game.getDataModel()).updateMoney(-30); Sprite.setState(BANDIT_MINDLESS_STATE); mindlessTerror = true; powerUp = true; game.GameScreen.currentPowerUp = ""; mtStart = System.currentTimeMillis(); } } }); moneyHeld = (int) Math.round(level.getMoney() * .2); }
/* * RANDOMNESS FOR SHORTEST PATH */ private void mindlessTerror() { mtEnd = System.currentTimeMillis(); mtDelta = (mtEnd - mtStart) / 1000; if (mtDelta == 20) { Sprite.setState(BANDIT_STATE); mindlessTerror = false; mtStart = 0; mtEnd = 0; mtDelta = 0; powerUp = false; shortestPath = null; currentRoad = 0; return; } // CHECK COLLISION Iterator<PathXPolice> pIt = game.GameScreen.getPolice().iterator(); while (pIt.hasNext()) { PathXPolice p = pIt.next(); if (p.stunned) { continue; } if (p.mindlessTerror) { continue; } if (p.getSprite().containsPoint(Sprite.getX() + 20, Sprite.getY() + 20)) { p.stunStart = System.currentTimeMillis(); p.stunned = true; } } Iterator<PathXBandit> bIt = game.GameScreen.getBandits().iterator(); while (bIt.hasNext()) { PathXBandit b = bIt.next(); if (b == this) { continue; } if (b.stunned) { continue; } if (b.mindlessTerror) { continue; } if (b.getSprite().containsPoint(Sprite.getX() + 20, Sprite.getY() + 20)) { b.stunStart = System.currentTimeMillis(); b.stunned = true; } } Iterator<PathXZombie> zIt = game.GameScreen.getZombies().iterator(); while (zIt.hasNext()) { PathXZombie z = zIt.next(); if (z.stunned) { continue; } if (z.mindlessTerror) { continue; } if (z.getSprite().containsPoint(Sprite.getX() + 20, Sprite.getY() + 20)) { z.stunStart = System.currentTimeMillis(); z.stunned = true; } } if (atIntersection) { // IF THERE ARE NO POSSIBLE INTERSECTIONS AVAILABLE, DO NOTHING boolean open = false; for (int i = 0; i < currentIntersection.getIntersections().size(); i++) { if (currentIntersection.getIntersections().get(i).open && !currentIntersection.getIntersections().get(i).closed) { open = true; } } if (!open) { return; } // RUN WHILE WE DON'T HAVE A TARGET int min = 0; int max = currentIntersection.getRoads().size(); while (targetIntersection == null) { // GET RANDOM INTERSECTION ATTATCHED TO THE CURRENT INTERSECTION int r = (int) ((min + Math.random() * (max - min))); Intersection tempIntersection = currentIntersection.getIntersections().get(r); if ((tempIntersection == level.getStartingLocation()) || (tempIntersection == level.getDestination())) { continue; } // FIND A THE ROAD TO TRAVEL ON Iterator<Road> roadIt = currentIntersection.getRoads().iterator(); Road road = null; while (roadIt.hasNext()) { Road tempRoad = roadIt.next(); if ((tempRoad.node1 == currentIntersection) && (tempRoad.node2 == tempIntersection)) { road = tempRoad; break; } else if (((tempRoad.node1 == tempIntersection) && (tempRoad.node2 == currentIntersection)) && !tempRoad.oneWay) { road = tempRoad; break; } } if (road != null) { targetIntersection = tempIntersection; currentR = road; atIntersection = false; } if (road == null) { targetIntersection = null; return; } } } // move else { // CREATE VELOCITY float x = (targetIntersection.getX() - currentIntersection.getX()) * .0005f; float y = (targetIntersection.getY() - currentIntersection.getY()) * .0005f; // SET VELOCITY Sprite.setVx(x * currentR.getSpeedLimit() * d.gameSpeed * 2); Sprite.setVy(y * currentR.getSpeedLimit() * d.gameSpeed * 2); // GET SPRITE OF TARGET INTERSECTION Sprite tempIntersection = ((GameScreen) game.getCurrentScreen()).getIntersections().get(targetIntersection.ID - 1); // IF THE PLAYER HAS REACHED TARGET INTERSECTION if (tempIntersection.containsPoint(Sprite.getX() + 20, Sprite.getY() + 20)) { Sprite.setVx(0); Sprite.setVy(0); // SET THE X AND Y COORDS OF THE PLAYER ON TO THE SPRITE Sprite.setX(tempIntersection.getX()); Sprite.setY(tempIntersection.getY()); // PREPARE NEXT LOOP FOR CREATING A NEW TARGET INTERSECTION currentIntersection = targetIntersection; targetIntersection = null; atIntersection = true; } } }