Hello All, I am quite new to greenfoot and need some assistance in making my character shoot, i would like to make it so when you press space it shoots in the direction the character is facing and that the bullets disapear when touching the edge. (which is controlled by WASD) i have been trying for weeks but the code has failed many times, would love to hear back from you.
As extra questions can someone tell me if there is a way to make the world edge smaller while still retaining the picture
How i can make characters die on collision with the bullets
How i can make it so when youve killed a certain amount of enemies the stage changes to level 2
Thanks in advance heres my current code for both King (Character thats shooting) and my Bullet
Again thanks in advanced
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class King here. * * @author (your name) * @version (a version number or a date) */ public class King extends Actor { /** * Act - do whatever the King wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown("D")) { move(2); setImage("King Right.png"); } else if (Greenfoot.isKeyDown("A")) { move(-2); setImage("King Left.png"); } else if (Greenfoot.isKeyDown("W")) { setLocation(getX(), getY()-2); setImage("King Up.png"); } else if (Greenfoot.isKeyDown("s")) { setLocation(getX(), getY()+2); setImage("King Down.png"); } } private GreenfootImage left = new GreenfootImage("King Left.png"); private GreenfootImage right= new GreenfootImage("King Right.png"); private GreenfootImage up= new GreenfootImage("King Up.png"); private GreenfootImage down= new GreenfootImage("King Down.png"); }
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 void act() { move(3); } }