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

2019/4/24

I need help making a Boss player automatically fire a laser in a greenfoot game I created called SuperBros

ak02 ak02

2019/4/24

#
I'm currently creating a greenfoot game called SuperBros for a class project and I was having trouble finding the java code to make the Boss player in my game fire the lasers automatically. So I was wondering what would be a good java code to put in greenfoot to make the Boss player automatically fire lasers rapidly in the game I created?
Proprogrammer04 Proprogrammer04

2019/4/24

#
I would create an variable which is downsized by one every tic in the game. When the variable is 0, the boss shoot an laser and the variable reset itself on the same number it has before…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int laser=50;
 
public void act()
{
 
}
 
public void lasershoot()
{
    laser=laser-1;
    if(laser<=0)
    {
        shootLaser();
        laser=50;
    }
}
 
public void shootLaser()
{
    //here is the code which shoot an Laser
}
To implement this, you have to copy it into the class of the boss and replace the empty public void act in my code with your‘s. The variable laser gives the intervalls in which the laser are shooted. You have to play around with this and try different numbers. Hope it‘ll help ;-)
ak02 ak02

2019/4/24

#
Thank you.
You need to login to post a reply.