Looking to do a 6 chamber revolver reload system, ie fires six shots, then a lengthy reload (say 3 seconds, to account for half a second per round) i know my timer approxes, just need help with the code. im newish to greenfoot. Ive included my current code, which includes a timer delay between shots already, its the full player class. i want it to reload automatically, no reload between chamber empties.
Thanks in advance for any help :)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
//class level attributes
private int prevX;
private int prevY;
private int setRotation;
private int getRotation;
private int delay;
private int timer=0;
private int shoot;
public byte GunX, GunY;
//private int lives;
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
storeCurrentPosition();
storeCurrentRotation();
checkMove();
//checkCollision();
checkWalls();
}
//public int getTapes()
//{
// return Tapes;
//}
//private void updateTapes(int change)
//{
// Tapes += change;
// updateImage();
//}
private void storeCurrentPosition()
{
prevX = getX();
prevY = getY();
}
// private void setRotation()
// {
//if(Greenfoot.getKey()=="a")
// getRotation == setRotation(0);
//if(Greenfoot.getKey()=="d")
// getRotation == setRotation(180);
//if(Greenfoot.getKey()=="w")
// getRotation == setRotation(90);
//if(Greenfoot.getKey()=="s")
// getRotation == setRotation(270);
//}
private void storeCurrentRotation()
{
//getRotation = setRotation();
}
//private void checkCollision()
//{
//if(atWallsEdge(this))
// setLocation(prevX, PrevY);
// if(!getObjectsInRange(35, Walls.class).isEmpty())
// setLocation(prevX, prevY);
//}
private void checkMove()
{
if(Greenfoot.isKeyDown("A"))
setLocation(getX() -1, getY());
if(Greenfoot.isKeyDown("D"))
setLocation(getX() +1, getY());
if(Greenfoot.isKeyDown("W"))
setLocation(getX() , getY()-1);
if(Greenfoot.isKeyDown("S"))
setLocation(getX() , getY()+1);
if(Greenfoot.isKeyDown("left"))
setRotation(0);
if(Greenfoot.isKeyDown("up"))
setRotation(90);
if(Greenfoot.isKeyDown("right"))
setRotation(180);
if(Greenfoot.isKeyDown("down"))
setRotation(270);
if(timer>0)
timer--;
if(timer==0 && Greenfoot.isKeyDown("space"))
{
fireGun();
timer=30;
}
//if(Greenfoot.getKey() =="A, D, S, W")
// aimGun();
}
//private void checkFire()
//{
//if(timer>0)timer--;
//if(timer==0 && Greenfoot.isKeyDown("space"))
//{
// fireGun();
// timer=120;
//}
//}
private void checkWalls()
{
Actor walls = getOneIntersectingObject(Walls.class);
if (walls != null)
{
setLocation(prevX, prevY);
}
}
public void fireGun()
{
//Projectile projectile = new Projectile();
//if ((Greenfoot.isKeyDown("space")))
//{
// ProjectileW projectileW = new ProjectileW();
// getWorld().addObject (projectileW, getX() -14, getY());
//
// //rotations?
//}
if ((Greenfoot.isKeyDown("left")))
{
GunX = -1;
ProjectileW projectileW = new ProjectileW();
getWorld().addObject (projectileW, getX() -14, getY());
timer=60;
//delay = timer+1000;
//shoot = false;
//rotations?
}
else if ((Greenfoot.isKeyDown("right")))
{
GunX = +1;
ProjectileE projectileE = new ProjectileE();
getWorld().addObject (projectileE, getX() +14, getY());
timer=60;
//delay = timer+1000;
//shoot = false;
//to add, [REDACTED] rotations
}
else if ((Greenfoot.isKeyDown("up")))
{
GunY = -1;
ProjectileN projectileN = new ProjectileN();
getWorld().addObject (projectileN, getX(), getY() -15);
timer=60;
//delay = timer+1000;
//shoot = false;
//rotations?
}
else if ((Greenfoot.isKeyDown("down")))
{
GunY = +1;
ProjectileS projectileS = new ProjectileS ();
getWorld().addObject (projectileS, getX(), getY() +15);
timer=60;
//delay = timer+1000;
//shoot = false;
//to add, [REDACTED] rotations
}
//if(delay <= timer)
//{
// shoot = true;
//}
} //aimGun();
//consider adding a 'set aim to X' code on checkMove as well
//end of method
}




