private void renderSprite(Graphics g, Sprite s) { // ONLY RENDER THE VISIBLE ONES if (!s.getState().equals(PathXSpriteState.INVISIBLE.toString())) { SpriteType bgST = s.getSpriteType(); Image img = bgST.getStateImage(s.getState()); g.drawImage(img, (int) s.getX(), (int) s.getY(), bgST.getWidth(), bgST.getHeight(), null); } }
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); }