// Sets the location for NPCs to move towards public void NPCTarget(Stage s, ArrayList<NPC> npc, Player p) { int playerx = p.getX(); int playery = p.getY(); int viewrange = 100; int npcx; int npcy; int randnext = 0; // For each npc for (NPC n : npc) { // Get X/Y npcx = n.getX(); npcy = n.getY(); randnext = rand.nextInt(10); // If npc has nowhere to go if (n.getMoveticks() == 0 || (n.getGotox() == n.getX() && n.getGotoy() == n.getY())) { // Set random amount of movements n.setMoveticks(rand.nextInt(150)); // Set a direction n.setDirection(rand.nextInt(4)); n.setGotox(0); n.setGotoy(0); } // check if the player is within view range and move if ((playery >= npcy && playery <= npcy + viewrange || playery <= npcy && playery >= npcy - viewrange) && playerx > (npcx + n.getWidth()) && playerx <= (npcx + viewrange)) { n.setGotox(p.getX() + (p.getWidth() / 2)); n.setGotoy(p.getY() + (p.getHeight() / 2)); } if ((playery >= npcy && playery <= npcy + viewrange || playery <= npcy && playery >= npcy - viewrange) && (playerx + p.getWidth()) < npcx && playerx > (npcx - viewrange)) { n.setGotox(p.getX() + (p.getWidth() / 2)); n.setGotoy(p.getY() + (p.getHeight() / 2)); } } }
public void NPCFire(NPC n, FireControl fc) throws IOException { // Is player above the npc if (n.getY() <= n.getGotoy() && ((n.getX() + n.getWidth() / 2 <= n.getGotox() + 25) && n.getX() + n.getWidth() / 2 >= n.getGotox() && n.getFirer() < n.getDistancey())) { // System.out.println("Shooting!"); fc.addShot( new Bullet( n.getX() + n.getWidth() / 2, n.getY() + n.getHeight() + 4, n.getGun().getShotwidth(), n.getGun().getShotwidth(), 0, n.getGun().getShotspeed(), n, n.getGun().getRicochet())); } if (n.getY() >= n.getGotoy() && ((n.getX() + n.getWidth() / 2 <= n.getGotox() + 25) && n.getX() + n.getWidth() / 2 >= n.getGotox() && n.getFirer() < n.getDistancey())) { // System.out.println("Shooting!"); fc.addShot( new Bullet( n.getX() + n.getWidth() / 2, n.getY() - 4, n.getGun().getShotwidth(), n.getGun().getShotwidth(), 1, n.getGun().getShotspeed(), n, n.getGun().getRicochet())); } if ((n.getY() + n.getHeight() / 2 >= n.getGotoy()) && n.getY() + n.getHeight() / 2 <= n.getGotoy() + 25 && ((n.getX() >= n.getGotox()) && n.getFirer() <= n.getDistancex())) { // System.out.println("Shooting!"); fc.addShot( new Bullet( n.getX() - 4, n.getY() + n.getHeight() / 2, n.getGun().getShotwidth(), n.getGun().getShotwidth(), 2, n.getGun().getShotwidth(), n, n.getGun().getRicochet())); } if ((n.getY() + n.getHeight() / 2 >= n.getGotoy()) && n.getY() + n.getHeight() / 2 <= n.getGotoy() + 25 && ((n.getX() < n.getGotox()) && n.getFirer() <= n.getDistancex())) { // System.out.println("Shooting!"); fc.addShot( new Bullet( n.getX() + n.getWidth() + 4, n.getY() + n.getHeight() / 2, n.getGun().getShotwidth(), n.getGun().getShotwidth(), 3, n.getGun().getShotspeed(), n, n.getGun().getRicochet())); } }
public void init() { // LEVEL SPEED levelSpeed = 8; // AudioPlayer init AudioLoader.loadFromFile("nivel3_sonido.txt"); // images loading ImagesLoader.loadFromFile("nivel3_imagenes.txt"); ImagesLoader.loadFromFile("nivel_efectosvisuales_imagenes.txt"); ImagesLoader.loadFromFile("food_imagenes.txt"); // food appearance probability if (difficulty == OptionsState.EASY) foodprobability = 0.8; if (difficulty == OptionsState.NORMAL) foodprobability = 0.88; if (difficulty == OptionsState.HARD) foodprobability = 0.94; fooddelays = new int[6]; fooddelays[0] = 100; fooddelays[1] = 600; fooddelays[2] = 100; fooddelays[3] = 500; fooddelays[4] = 100; fooddelays[5] = 400; // Events init eventIntro = true; eventClear = eventDead = eventCaught = false; txtAnimation = new TextAnimation(); camera = new Camera(); cameraPoint = new Camera(); levelStart = false; levelIntroTimer = System.nanoTime(); levelIntroDelay = 10000; foodTimer = System.nanoTime(); foodDelay = 3000; // load fonts Text.loadFont("yummyFont.png"); Text.loadFont("leishoFont.png"); player = new Player(); npc = new NPC(player); dishes = new ArrayList<>(); hud = new HUD(player); // difficulty difficulty = OptionsData.getDifficulty(); // rails init rails = new Rail[3]; // title init titleIntroA = new Title(levelName, Title.INTROANIMATIONA); titleIntroB = new Title("EMPIEZA", Title.INTROANIMATIONB); titleClear = new Title("GANASTE", Title.CLEARANIMATION); titleDead = new Title("MORISTE", Title.CAUGHTANIMATION); titleCaught = new Title("ATRAPADO", Title.CAUGHTANIMATION); titleIntroA.start(); // background creation // individual creation bgKitchen = new Background(0, 0, ImagesLoader.getImage("3_background"), Background.MOVELEFT); heartAttack = new BackgroundAnimation( ImagesLoader.getImage("heartsolo"), BackgroundAnimation.HEARTATTACK); warning = new BackgroundAnimation(ImagesLoader.getImage("warning"), BackgroundAnimation.WARNING); /* bgSky = new Background(0, 0, ImagesLoader.getImage("nivel1_clouds")); bgSoil = new Background(0, GamePanel.HEIGHT - (ImagesLoader.getHeight("nivel1_soil")), ImagesLoader.getImage("nivel1_soil")); */ numbers = new ArrayList<>(); explosions = new ArrayList<>(); powerup = new ArrayList<>(); player.init(dishes, numbers, explosions, powerup); // setting the score for the player player.setScore(PlayerData.getScore()); foodValues = new HashMap<>(); foodList = new ArrayList<>(); powerList = new ArrayList<>(); loadFoodFile("archivoComida.txt"); powerList.add("FREEZEPOWER"); powerList.add("DOUBLESCOREPOWER"); powerList.add("DOUBLESPEEDPOWER"); powerList.add("HALFSPEEDPOWER"); // set position // debugging player.setPositionInRail(playerxscreen, player.getCurrentRail()); cameraPoint.setPosition(playerxscreen, 0); // player.setVector(levelSpeed, 0); // parameters to be given: dx, dy, moveSpeed, jumpStart, fallSpeed player.setSpeed(levelSpeed, 0, 3.6, -28.8, 1.8); cameraPoint.setVector(levelSpeed, 0); npc.setPositionInRail(-npc.getWidth() / 2, npc.getCurrentRail()); // npc.setVector(levelSpeed, 0); // parameters to be given: dx, dy, moveSpeed npc.setSpeed(levelSpeed, 0, 3.6); player.setCamera(camera); npc.setCamera(camera); // results stuff init squarewidth = 5; squareheight = 1; resultsDelay = 600; ticksResults = 0; // AudioPlayer volume setting // AudioPlayer.setVolume("musicFnm", -5.0f); AudioPlayer.setVolume("increasescore", -25.0f); // AudioPlayer bg play AudioPlayer.playAndLoop(musicFnm); }