hello i have got some code which include get key and string key but they both do not shoot heres the code
That is for the penival
this is for the dimentions
If anyone can help that would be really helpful
Thanks
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class penival here. * * @author (your name) * @version (a version number or a date) */ public class penival extends Actor { /** * Act - do whatever the penival wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown("left")) { move(-3); } if (Greenfoot.isKeyDown("right")) { move(3); } String key = Greenfoot.getKey(); if ("space".equals(key)) { fire(); } } /** * Fire the penival */ private void fire() { Bullet bullet = new Bullet(); getWorld().addObject(bullet, getX(), getY()); bullet.setRotation(getRotation()); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Dimentions here. * * @author (your name) * @version (a version number or a date) */ public class Dimentions extends Actor { /** * Act - do whatever the Dimentions wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown("a")) { move(-3); } if (Greenfoot.isKeyDown("d")) { move(3); } if ("z".equals (Greenfoot.getKey())) { fire(); } } /** * Fire the dimentions */ private void fire() { Bullet2 bullet2 = new Bullet2(); getWorld().addObject(bullet2, getX(), getY()); bullet2.setRotation(getRotation()); } }