RandomGuy wrote...
Wait so which line should i put the code in?getWorld().removeObject(this);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bullet here. * * @author (your name) * @version (a version number or a date) */ public class Bullet extends Actor { /** * Act - do whatever the Bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Bullet() { } public void act() { movement(); if (getWorld() != null && isTouching(Zombies.class)) { World world = getWorld(); world.removeObject(this); } } private void movement() { move(6); if (isAtEdge()) { World world = getWorld(); if(world != null) { world.removeObject(this); return; } } if (getWorld() != null && isTouching(Zombies.class)) { Counter counter = (Counter) getWorld().getObjects(Counter.class).get(0); counter.add(1); removeTouching(Zombies.class); GreenfootSound eating = new GreenfootSound("Gunshot.mp3"); if (eating != null) { eating.play(); } getWorld().removeObject(this); } } private void repeat() { } }
import greenfoot.*; public class Bullet extends Actor { public void act() { move(6); if (isAtEdge() || collidesWithZombie()) getWorld().removeObject(this); } private boolean collidesWithZombie() { if ( ! isTouching(Zombies.class)) return false; Greenfoot.playSound("Gunshot.mp3"); removeTouching(Zombies.class); ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1); return true; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bullet here. * * @author (your name) * @version (a version number or a date) */ public class Bullet extends Actor { /** * Act - do whatever the Bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Bullet() { } public void act() { movement(); if (isAtEdge()) { collidesWithZombie(); getWorld().removeObject(this); } } private boolean collidesWithZombie() { if ( ! isTouching(Zombies.class)) return false; { Greenfoot.playSound("Gunshot.mp3"); removeTouching(Zombies.class); ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1); return true; } } private void movement() { move(6); if (isAtEdge()) { World world = getWorld(); if(world != null) { world.removeObject(this); return; } } } private void repeat() { } }
import greenfoot.*; public class Bullet extends Actor { public void act() { move(6); if (isAtEdge() || collidesWithZombie()) getWorld().removeObject(this); } private boolean collidesWithZombie() { if ( ! isTouching(Zombies.class)) return false; Greenfoot.playSound("Gunshot.mp3"); removeTouching(Zombies.class); ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1); return true; } }
private final int speed = 3; // how many pixels the character moves per second if(Greenfoot.isKeyDown("W")||Greenfoot.isKeyDown("UP")){ setlocation(getX(), getY()-speed);} if(Greenfoot.isKeyDown("A")||Greenfoot.isKeyDown("LEFT")){ setlocation(getX()-speed, getY());} if(Greenfoot.isKeyDown("S")||Greenfoot.isKeyDown("DOWN")){ setlocation(getX(), getY()+speed);} if(Greenfoot.isKeyDown("D")||Greenfoot.isKeyDown("RIGHT")){ setlocation(getX()+speed, getY());}
import greenfoot.*; public class Bullet extends Actor { public void act() { move(6); if (isAtEdge() || collidesWithZombie()) getWorld().removeObject(this); } private boolean collidesWithZombie() { if ( ! isTouching(Zombies.class)) return false; Greenfoot.playSound("Gunshot.mp3"); removeTouching(Zombies.class); ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1); return true; } }