hey, i'm kind of stuck trying to work this out. I want to be able to pick up a power-up which will enable me to shoot quicker, but i don't know how to do so.
here is my current code.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class FrenchMan here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FrenchMan extends ScrollingActor
{
private int timerPistol;
private int timerRifle;
public int direction;
private boolean Rifle = false;
/**
* Act - do whatever the FrenchMan wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int health = 3;
public void act()
{
move();
eat();
GreenfootImage left = new GreenfootImage("preview_idle.gif");
MouseInfo mouse = Greenfoot.getMouseInfo();
turning();
shoot();
}
public void move()
{
if (Greenfoot.isKeyDown("d")){
setLocation(getX() + 5, getY());
}
if (Greenfoot.isKeyDown("w")){
setLocation(getX(), getY() - 5);
}
if (Greenfoot.isKeyDown("a")){
setLocation(getX() - 5, getY());
}
if (Greenfoot.isKeyDown("s")){
setLocation(getX(), getY() + 5);
}
}
public void eat()
{
Actor Rock;
Rock = getOneObjectAtOffset(0,0, Rock.class);
if (Rock != null)
{
World world;
world = getWorld();
world.removeObject(Rock);
Greenfoot.playSound("332629__treasuresounds__item-pickup.wav");
}
}
public void turning()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse != null) {
setRotation((int)(180*Math.atan2(mouse.getY()-getY(),mouse.getX()-getX())/Math.PI));
}
}
public void shoot() {
if (Rifle = false)
setImage("preview_idle.gif");
if (timerPistol > 0) timerPistol--; // run timer
if (timerPistol == 0 && Greenfoot.isKeyDown("space"))
{
Bullet b = new Bullet();
getWorld().addObject(b, getX(), getY());
direction = getRotation();
b.setRotation(direction);
Greenfoot.playSound("gun-gunshot-02.wav");
timerPistol = 30; // start timer (adjust value as needed)
}
}
}