private void movement() { int x = getX(), y = getY(), dir = getRotation(); if (Greenfoot.isKeyDown("left") && x > 10) { setLocation(x - 7, y); setRotation(Math.max(dir - 2, 247)); starsDir(); } else if (Greenfoot.isKeyDown("right") && x < 794) { setLocation(x + 7, y); setRotation(Math.min(dir + 2, 293)); starsDir(); } else { setRotation((int) Math.round(-(dir - 270) / 1.8) + dir); starsDir(); } x = getX(); if (Greenfoot.isKeyDown("up") && y > 70) { setLocation(x, y - 7); } else if (Greenfoot.isKeyDown("down") && y < 660) { setLocation(x, y + 7); } }
public void Mover() { if (Greenfoot.isKeyDown("right")) { move(1); } if (Greenfoot.isKeyDown("left")) { move(-1); } }
public void moveAndTurn() { move(3); if (Greenfoot.isKeyDown("a")) { turn(-5); } if (Greenfoot.isKeyDown("d")) { turn(5); } }
/** Do the action for this key. */ public void act() { if (!isDown && Greenfoot.isKeyDown(key)) { setImage("white-key-down.png"); isDown = true; play(); } if (isDown && !Greenfoot.isKeyDown(key)) { setImage("white-key.png"); isDown = false; } }
private void equipment() { if (Greenfoot.isKeyDown("q") && amIntv > 20) { ammoChange(playerAmmunition.get(nextIndex(playerAmmunition, playerAmmo, -1))); amIntv = 0; } else if (Greenfoot.isKeyDown("e") && amIntv > 20) { ammoChange(playerAmmunition.get(nextIndex(playerAmmunition, playerAmmo, 1))); amIntv = 0; } amIntv++; }
protected void animateMario() { SWorld sWorld = (SWorld) getWorld(); mLeft = sWorld.minionL; if (mLeft == true && Greenfoot.isKeyDown("left")) { if (getImage() == imageL && imageDelayCount >= imageTime) { setImage(imageML); imageDelayCount = 0; } if (getImage() == imageML && imageDelayCount >= imageTime) { setImage(imageL); imageDelayCount = 0; } if (getImage() == imageR) { setImage(imageL); imageDelayCount = 0; } if (getImage() == imageMR) { setImage(imageL); imageDelayCount = 0; } } if (mLeft == true && Greenfoot.isKeyDown("left") == false) { setImage(imageL); } if (mLeft == false && Greenfoot.isKeyDown("right")) { if (getImage() == imageR && imageDelayCount >= imageTime) { setImage(imageMR); imageDelayCount = 0; } if (getImage() == imageMR && imageDelayCount >= imageTime) { setImage(imageR); imageDelayCount = 0; } if (getImage() == imageL) { setImage(imageR); imageDelayCount = 0; } if (getImage() == imageML) { setImage(imageR); imageDelayCount = 0; } } if (mLeft == false && Greenfoot.isKeyDown("right") == false) { setImage(imageR); } }
@Override public void act() { if (Greenfoot.isKeyDown("enter")) { Greenfoot.setWorld(new SkyscraperWorld()); return; } }
public void act() // sean { if (!played) { burningSteppes.playLoop(); played = !played; } // makeSmokeFireball(); counterDelay++; if (Greenfoot.isKeyDown("h") && delay > 10) { clickSound.play(); Menu menu = new Menu(getThisWorld()); Greenfoot.setWorld(menu); delay = 0; } if (getObjects(Ninja.class).size() != 0 && counterDelay >= 10) { healthCounter.setValue(ninja.getNINJAHP()); shurikenCounter.setValue(ninja.getSHURIKENNUMBER()); powerCounter.setValue(ninja.getPOWERBAR()); checkDoor(); counterDelay -= 10; /**/ // TEMPORAY FUNCTIONS FOR HAYDEN TO CHANGE LEVELS TO MAKE THEM /**/ /**/ // TEMPORAY FUNCTIONS FOR HAYDEN TO CHANGE LEVELS TO MAKE THEM /**/ } delay++; fireballDelay++; }
public void checkTPress() // this method whether T key is being pressed o not and move the object // according do following. { if (alive) // check if the ship alive { DeepSpace myDeepSpace = (DeepSpace) getWorld(); // get referance to the DeepSpace class FuelTank myFuelTank = myDeepSpace .myFuelTank(); // use myFuelTank method that return reference of FuelTank class. So // you can call method of Fueltank class. if (Greenfoot.isKeyDown("t") && !myFuelTank .empty()) // if "t" key is being pressed by user and if i have enough fuel, do // following. { move(3); // move forward direction of object setImage("rocket.png"); // set the image rocket that seems like burning fuel. myFuelTank .burn(); // call the Fueltank class method in order to decrese level of fuel on screen } else setImage("rocket_noThrust.png"); // if no key is being press than set the regular picture. } }
public void act() { Mover(); darPosicao(); if (Greenfoot.isKeyDown("space")) { Atirar(); } }
/** las esferas giraran dependiendo de la tecla que se presione */ public void mueve() { BlurWorld mundo = (BlurWorld) getWorld(); vel = mundo.dameVel() + 1; if (Greenfoot.isKeyDown("left")) { int rotationalSpeed = -vel; setLocation((ROWS / 2), (COLS / 2) + 220); turn(rotationalSpeed + 90); move(radius); turn(-90); } if (Greenfoot.isKeyDown("right")) { int rotationalSpeed = vel; setLocation((ROWS / 2), (COLS / 2) + 220); turn(rotationalSpeed + 90); move(radius); turn(-90); } }
public void Atirar() { if (TempodeTiro > 0) { TempodeTiro = TempodeTiro - 1; } else if (Greenfoot.isKeyDown("space")) { shot.play(); Bala bala = new Bala(); getWorld().addObject(bala, getX(), getY()); bala.SetXY(getX(), getY()); TempodeTiro = 2; } }
private void animatePlayer(boolean moveDir) { if (moveDir == true && Greenfoot.isKeyDown("d")) { if (frame < 1 * delay) { setImage(base); } else if (frame < 2 * delay) { setImage(run2r); } else if (frame < 3 * delay) { setImage(run3r); } else if (frame < 4 * delay) { setImage(run4r); frame = 1; return; } frame++; } if (moveDir == false && Greenfoot.isKeyDown("a")) { if (frame < 1 * delay) { setImage(base); } else if (frame < 2 * delay) { GreenfootImage run2l = new GreenfootImage(run2r); run2l.mirrorHorizontally(); setImage(run2l); } else if (frame < 3 * delay) { GreenfootImage run3l = new GreenfootImage(run3r); run3l.mirrorHorizontally(); setImage(run3l); } else if (frame < 4 * delay) { GreenfootImage run4l = new GreenfootImage(run4r); run4l.mirrorHorizontally(); setImage(run4l); frame = 1; return; } frame++; } }
private void Special() { if (Greenfoot.isKeyDown("r") && specialShotInt > 120 && Spammo > 0) { addObjectAtOffset(new ChargeBeam(this), getX(), getY(), 80, getRotation()); w.addObject(new CoolDown(ACT2SEC(120)), 845, 640); Greenfoot.playSound("Laser_Cannon.mp3"); // !--------------!\\ specialShotInt = 0; shotInterval = -78; Spammo--; SpammoUI.addPoints(-1); } specialShotInt++; }
private void Shot() { int index = playerAmmunition.indexOf(playerAmmo); if (Greenfoot.isKeyDown("space") && shotInterval > playerAmmo.interval && ammo[index] > 0) { int f = getRotation(); Shot p = Shot.create(playerAmmo, Inimigo.class); addObjectAtOffset(p, getX(), getY(), 70, f); p.setRotation(f); // !--------------!\\ shotInterval = 0; ammo[index]--; ammoUI.addPoints(-1); } shotInterval++; }
/** * Moves the actor with appropriate image. Checks for obstacles and adjusts the position of the * actor accordingly. */ public void moveHorizontally() { setLocation(getX() + xSpeed, getY()); while (getOneObjectAtOffset(getImage().getWidth() / 2, 0, Block.class) != null) { setLocation(getX() - 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(-getImage().getWidth() / 2, 0, Block.class) != null) { setLocation(getX() + 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(getImage().getWidth() / 2, 0, Brick.class) != null) { setLocation(getX() - 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(-getImage().getWidth() / 2, 0, Brick.class) != null) { setLocation(getX() + 1, getY()); xSpeed = 0; } if (Greenfoot.isKeyDown("right")) { if (xSpeed < 0) { xSpeed = 0; } if (xSpeed < 5) { xSpeed = xSpeed + 1; } SWorld sWorld = (SWorld) getWorld(); sWorld.minionL = false; } if (Greenfoot.isKeyDown("left")) { if (xSpeed > 0) { xSpeed = 0; } if (xSpeed > -5) { xSpeed = xSpeed - 1; } SWorld sWorld = (SWorld) getWorld(); sWorld.minionL = true; } if (!Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("right")) { xSpeed = 0; } if (Greenfoot.isKeyDown("up")) { jump(); } if (Greenfoot.isKeyDown("space")) { shoot(); } }
/** * Act - do whatever the GameLogicVracht wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { float dt = 1.0f / 60.0f; //Deze code spawnt de containers en checkt of er collision is tussen containers en trucks met bijbehorende kleuren. Zo ja, dan worden er acties uitgevoerd. //Gele truck for(int i = 0; i < AantalContainersGeel; i++) { if(EpicVrachtOverslaan.Vector2.Distance(truckGeelPosition, containerGeelPosition.get(i)) <= 50.0) { //Als de container de vrachtwagen aangeraakt heeft, is er collision. Dan doen we: collisiongeel = 1; } if(collisiongeel == 1) { //Eerst veranderen we de sprite naar de volle versie. truckGeelAppearance = new EpicVrachtOverslaan.Texture2D("Truck Geel Vol.png"); //Dan rijdt de truck weg. truckGeelPosition = truckGeelPosition.sub(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(300.0f)); //eventueel kunnen we later nog toevoegen dat de trucks elkaars plaats innemen. } } //Blauwe truck for(int i = 0; i < AantalContainersBlauw; i++) { if(EpicVrachtOverslaan.Vector2.Distance(truckBlauwPosition, containerBlauwPosition.get(i)) <= 50.0) { //Als de container de vrachtwagen aangeraakt heeft, is er collision. Dan doen we: collisionblauw = 1; } if(1 == 1) { //Eerst veranderen we de sprite naar de volle versie. truckBlauwAppearance = new EpicVrachtOverslaan.Texture2D("Truck Blauw Vol.png"); //Dan rijdt de truck weg. truckBlauwPosition = truckBlauwPosition.sub(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(28.0f)); //eventueel kunnen we later nog toevoegen dat de trucks elkaars plaats innemen. } } //Groene truck for(int i = 0; i < AantalContainersGroen; i++) { if(EpicVrachtOverslaan.Vector2.Distance(truckGroenPosition, containerGroenPosition.get(i)) <= 50.0) { //Als de container de vrachtwagen aangeraakt heeft, is er collision. Dan doen we: collisiongroen = 1; } if(collisiongroen == 1) { //Eerst veranderen we de sprite naar de volle versie. truckGroenAppearance = new EpicVrachtOverslaan.Texture2D("Truck Groen Vol.png"); //Dan rijdt de truck weg. truckGeelPosition = truckGeelPosition.sub(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(300.0f)); //eventueel kunnen we later nog toevoegen dat de trucks elkaars plaats innemen. } } //Rood for(int i = 0; i < AantalContainersRood; i++) { if(EpicVrachtOverslaan.Vector2.Distance(truckRoodPosition, containerRoodPosition.get(i)) <= 50.0) { //Als de container de vrachtwagen aangeraakt heeft, is er collision. Dan doen we: collisionrood = 1; } if(collisionrood == 1) { //Eerst veranderen we de sprite naar de volle versie. truckRoodAppearance = new EpicVrachtOverslaan.Texture2D("Truck Rood Vol.png"); //Dan rijdt de truck weg. truckRoodPosition = truckRoodPosition.sub(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(300.0f)); } } for(int i = 0; i < AantalContainersRood; i++) { if(EpicVrachtOverslaan.Vector2.Distance(grijperPosition, containerRoodPosition.get(i)) <=50.0 && Greenfoot.isKeyDown(" ")) { JOptionPane.showMessageDialog(new JInternalFrame(), "Message content","Message title", JOptionPane.INFORMATION_MESSAGE); containerRoodPosition[i]; } } //Met deze code word het bewegen v.d. grijper met de w-a-s-d toetsen geregeld. if (Greenfoot.isKeyDown("A")) grijperPosition = grijperPosition.sub(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(300.0f)); if (Greenfoot.isKeyDown("D")) grijperPosition = grijperPosition.add(EpicVrachtOverslaan.Vector2.UnitX.mul(dt).mul(300)); if (Greenfoot.isKeyDown("W")) grijperPosition = grijperPosition.sub(EpicVrachtOverslaan.Vector2.UnitY.mul(dt).mul(300.0f)); if (Greenfoot.isKeyDown("S")) grijperPosition = grijperPosition.add(EpicVrachtOverslaan.Vector2.UnitY.mul(dt).mul(300.0f)); //Alle code hieronder doet het daadwerkelijke "plaatsen" v.d. objecten onder de door ons hierboven gegeven voorwaarden. EpicVrachtOverslaan.DrawingContext drawingContext = EpicVrachtOverslaan.DrawingContext; drawingContext.BeginDraw(); EpicVrachtOverslaan.DrawingContext.Draw(truckGeelAppearance, truckGeelPosition); EpicVrachtOverslaan.DrawingContext.Draw(truckRoodAppearance, truckRoodPosition); EpicVrachtOverslaan.DrawingContext.Draw(truckGroenAppearance, truckGroenPosition); EpicVrachtOverslaan.DrawingContext.Draw(truckBlauwAppearance, truckBlauwPosition); for(EpicVrachtOverslaan.Vector2 a : containerGeelPosition) { drawingContext.Draw(containerGeelAppearance, a); } for(EpicVrachtOverslaan.Vector2 a : containerRoodPosition) { drawingContext.Draw(containerRoodAppearance, a); } for(EpicVrachtOverslaan.Vector2 a : containerGroenPosition) { drawingContext.Draw(containerGroenAppearance, a); } for(EpicVrachtOverslaan.Vector2 a : containerBlauwPosition) { drawingContext.Draw(containerBlauwAppearance, a); } EpicVrachtOverslaan.DrawingContext.Draw(grijperAppearance, grijperPosition); EpicVrachtOverslaan.DrawingContext.Draw(voortgansbalkAppearance, voortangsbalkPosition); EpicVrachtOverslaan.DrawingContext.Draw(indicatiebalkAppearance, indicatiebalkPosition); }
public void checkKeys() { if Greenfoot.isKeyDown("up") }