public void checkStarCollision() { for (Star s : starList) { if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides if (s.checkCollision( s.getPics().get(s.getCounter()), player1)) { // if the player collides with the star we remove it then change the // velosity to the distance that the star provides sRemove.add(s); // remove star once you collide with it player1.setVelo(s.getDist()); // changes the velocity player1.setInvi(true); // sets the player invisble for a few seconds score += s.getPoints(); // points increase by the star type if (musicOn) { starSound.play(); // playthe star sound } } } else { sRemove.add(s); // remove the star if its not on the screen } } for (Star s : sRemove) { poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect starList.remove(s); } sRemove = new ArrayList<Star>(); }
public void checkEnemyCollision() { for (Enemy e : enemyList) { if (e.getOnScreen()) { // can be removed later on // goes through all the enemies and checks if they collide if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) { if (player1.getInvi() == false) { // If the player is not invisble then you get spiked. if (player1.getVelocity() > 0) { // if the player hits it from the bottom player1.setSpikeVelo(); loseCoins(); } else { player1.setVelo( 50); // if the player is on top instead the player bounces off the enemy if (musicOn) { bounce.play(); } } } eRemove.add(e); // once we hit, we remove the enemy } } else { eRemove.add(e); // if the enemy goes of the screen, we remove } } for (Enemy e : eRemove) { poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies enemyList.remove(e); } eRemove = new ArrayList<Enemy>(); }
public void checkJumperCollision() { // same as all the other collsions for (Jumper j : jumperList) { if (j.getOnScreen()) { // if (j.checkCollision(j.getImage(), player1)) { player1.setVelo(50); player1.setDown(false); if (musicOn) { bounce.play(); } } } else { jRemove.add(j); } } for (Jumper j : jRemove) { jumperList.remove(j); } jRemove = new ArrayList<Jumper>(); }
public void checkPupCollision() { // pretty much the same thing as before, however it alsoe does the powerup effects for (Powerup p : pupList) { if (p.getOnScreen()) { // can be removed later on if (p.checkCollision(player1)) { pupRemove.add(p); player1.setPower(p.getType()); player1.setVelo(50); } } else { pupRemove.add(p); } } if (player1.getPower().equals("Lucky")) { // changes everything to stars for (Coin c : coinList) { starList.add(new Star(c.getX(), c.getY(), 2)); cRemove.add(c); } for (Box b : boxList) { starList.add(new Star(b.getX(), b.getY(), 2)); bRemove.add(b); } for (Enemy e : enemyList) { starList.add(new Star(e.getX(), e.getY(), 2)); eRemove.add(e); } } else if (player1.getPower().equals("Magnet")) { // moves the coins towards the player for (Coin c : coinList) { c.moveTowards(player1); } } else { // else do nothing } for (Powerup p : pupRemove) { poofList.add(new Poof(p.getX(), p.getY(), 2)); pupList.remove(p); } pupRemove = new ArrayList<Powerup>(); }
public void checkBoxCollision() { // pretty much the same thing as all the other collisions for (Box b : boxList) { if (b.getOnScreen()) { // checks if its on the screen if (b.checkCollision(b.getImage(), player1)) { player1.setVelo(50); player1.setDown(false); b.setPcount( b.getPcount() - 1); // sets the type to one less so then you can bounce on it twice if (b.getPcount() == 0) { bRemove.add(b); // removes the box } if (musicOn) { bounce.play(); } } } else { bRemove.add(b); } } for (Box b : bRemove) { boxList.remove(b); } bRemove = new ArrayList<Box>(); }
public void checkCoinCollision() { for (Coin c : coinList) { if (c.getOnScreen()) { // check if the coin is on the screen if (c.checkCollision( c.getPics().get(c.getCounter()), player1)) { // if the player collides with the coin cRemove.add(c); // remove the coin player1.setVelo(50); // set the velocity so the player moves up player1.setDown(false); // set the down false (players moving up) coins += c.getValue(); // check the coins collected score += c.getPoints(); // get the score if (musicOn) { coinSound.play(); // play the sound } } } else { cRemove.add(c); // remove the coin } } for (Coin c : cRemove) { poofList.add(new Poof(c.getX(), c.getY(), 0)); coinList.remove(c); } cRemove = new ArrayList<Coin>(); }
public GamePanel(String name, int l) { setFocusable(true); grabFocus(); addMouseListener(this); addMouseMotionListener(this); addKeyListener(this); keys = new boolean[10000]; try { scoreFont = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf"))) .deriveFont(0, 32); } catch (IOException ioe) { System.out.println("error loading BRLNSB.tff"); } catch (FontFormatException ffe) { System.out.println("Something went wrong with the font."); } gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage(); for (int i = 1; i < 7; i++) { magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage()); } coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage(); player1 = new Player(200, 300, 100, "sheldon"); click = false; ground = true; pause = false; lvlClear = false; die = false; musicOn = true; player1.setVelo(150); player1.setInvi(true); // ------------------------------------------------------------------------------------------------------------------------------------ // Sound coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav")); clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav")); starSound = Applet.newAudioClip(getClass().getResource("star.wav")); bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav")); bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav")); bckGrndMusic.loop(); // ------------------------------------------------------------------------------------------------------------------------------------ // distance=0; score = 0; coins = 0; level = 1; prevLvl = level; backy = 0; height = backy; dieHeight = 0; dieMenuHeight = 0; pauseB = new SButton(400, 670, "pause", ""); resumeB = new SButton(100, 500, "resume", ""); menuB = new SButton(100, 620, "back", ""); muteB = new SButton(400, 600, "mute", ""); unmuteB = new SButton(400, 600, "unmute", ""); // System.out.println("characters/"+name+"/"+name+"35.png"); }