This site requires JavaScript, please enable it in your browser!
Greenfoot back
Beebon
Beebon wrote ...

2022/4/27

how do u make shots delay

Beebon Beebon

2022/4/27

#
can some pls give the code to this?
danpost danpost

2022/4/27

#
Beebon wrote...
how do u make shots delay can some pls give the code to this?
Need more info. Show current shooting codes.
Beebon Beebon

2022/4/27

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Gun here. * * @author (your name) * @version (a version number or a date) */ public class Gun extends Actor { /** * Act - do whatever the Gun wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.isKeyDown("t") ) { turn(10); } if(Greenfoot.isKeyDown("space") ) { getWorld().addObject(new Bullet(getRotation()), getX(), getY()); } } }
Beebon Beebon

2022/4/27

#
this for the gun
Beebon Beebon

2022/4/27

#
import greenfoot.*; public class Bullet extends Actor { private int direction, speed; public Bullet(int dir) { direction = dir; speed = 15; } public void act() { setRotation(direction); move(speed); eat(); } public void eat() { Actor adsasd; adsasd = getOneObjectAtOffset(0 , 0 ,adsasd.class); if (adsasd != null) { World world; world = getWorld(); world.removeObject(adsasd); } } }
danpost danpost

2022/4/27

#
The Gun class needs a field for the number of bullets it has to shoot. When shooting, the value should be decremented and then checked to see if any are left. If none left, remove gun from world.
You need to login to post a reply.