Hello again :D
I have some problem again here ( i hope you guys not tired helping me xD)
so i want when i click the mouse the object will appear and then it will delayed before my actor can shoot again, but in my case
when i click the mouse it will not appear(i need click many times to make it appear) and lets assume i change it to isKeyDown("Space"), on the first time i press the Space it will be delayed first before my actor can shoot .-.
here's my code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Hero1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Hero1 extends Actor
{
/**
* Act - do whatever the Hero1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
boolean ready = true;
int loading = 1;
int step = 1;
public void act()
{
heroMovement();
turntoMouse();
shootDelay();
delayA();
step++;
}
public void heroMovement()
{
int dx=0, dy=0;
if (Greenfoot.isKeyDown("w")) dy--;
if (Greenfoot.isKeyDown("s")) dy++;
if (Greenfoot.isKeyDown("d")) dx++;
if (Greenfoot.isKeyDown("a")) dx--;
// if(Greenfoot.mouseClicked(getWorld()))
//{
// getWorld().addObject(new Projectile2(getRotation()),getX(),getY());
//}
setLocation(getX()+dx*5, getY()+dy*5);
}
public void turntoMouse()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse!=null)
{
turnTowards(mouse.getX(),mouse.getY());
}
}
public void shootDelay()
{
if(ready == true)
{
if (Greenfoot.mouseClicked(getWorld()))
{
getWorld().addObject(new Projectile2(getRotation()),getX(),getY());
}
}
ready = false;
}
public void delayA()
{
if(step%40==1)
{
ready = true;
}
}
}
