Title
if( isTouching(Border.class) ){
setRotation(getRotation()+180);
move(4);
}if( isTouching(Border.class) ){
setRotation(getRotation()+180);
move(4);
}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
{
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int gunReloadTime;
int reloadDelayCount;
public static double bulletsshot;
public static int k=30;
public static int timerA = 100;
public static boolean l= false;
public Player ()
{
gunReloadTime = k;
reloadDelayCount = 0;
}
public void act()
{
if( isTouching(Border.class) ){
turn(180);
move(4);
}
checkKeypress();
reloadDelayCount++;
if (l == true)
{
timerA--;
if(timerA == 0)
{
k = 30;
l = false;
timerA = 100;
}
}
}
public void checkKeypress()
{
if (Greenfoot.isKeyDown("W") && Greenfoot.isKeyDown("D"))
{
setRotation(315);
move(4);
}
else if (Greenfoot.isKeyDown("A") && Greenfoot.isKeyDown("W"))
{
setRotation(225);
move(4);
}
else if (Greenfoot.isKeyDown("D") && Greenfoot.isKeyDown("S"))
{
setRotation(45);
move(4);
}
else if (Greenfoot.isKeyDown("A") && Greenfoot.isKeyDown("S"))
{
setRotation(135);
move(4);
}
else if (Greenfoot.isKeyDown("W"))
{
setRotation(270);
move(4);
}
else if (Greenfoot.isKeyDown("S"))
{
setRotation(90);
move(4);
}
else if (Greenfoot.isKeyDown("D"))
{
setRotation(0);
move(4);
}
else if (Greenfoot.isKeyDown("A"))
{
setRotation(180);
move(4);
}
if (Greenfoot.isKeyDown("space"))
{
shoot();
}
}
public void setGunReloadTime(int reloadTime)
{
gunReloadTime = reloadTime;
}
public void shoot()
{
if (reloadDelayCount >= gunReloadTime)
{
gunReloadTime = k;
Bullet bullet = new Bullet ();
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(getRotation());
reloadDelayCount = 0;
bullet.move(10.0);
bulletsshot++;
}
}
public static void fasterShooting()
{
k = 5;
l = true;
}
}
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
{
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int gunReloadTime;
int reloadDelayCount;
public static double bulletsshot;
public static int k=30;
public static int timerA = 150;
public static boolean l= false;
public Player ()
{
gunReloadTime = k;
reloadDelayCount = 0;
}
public void act()
{
checkKeypress();
if( isTouching(Border.class) ){
turn(180);
move(4);
}
reloadDelayCount++;
if (l == true)
{
timerA--;
if(timerA == 0)
{
k = 30;
l = false;
timerA = 150;
}
}
}
public void checkKeypress()
{
if (Greenfoot.isKeyDown("W") && Greenfoot.isKeyDown("D"))
{
setLocation(getX()+3, getY()-3);
}
else if (Greenfoot.isKeyDown("A") && Greenfoot.isKeyDown("W"))
{
setLocation(getX()-3, getY()-3);
}
else if (Greenfoot.isKeyDown("D") && Greenfoot.isKeyDown("S"))
{
setLocation(getX()+3, getY()+3);
}
else if (Greenfoot.isKeyDown("A") && Greenfoot.isKeyDown("S"))
{
setLocation(getX()-3, getY()+3);
}
else if (Greenfoot.isKeyDown("W"))
{
setLocation(getX(), getY()-4);
}
else if (Greenfoot.isKeyDown("S"))
{
setLocation(getX(), getY()+4);
}
else if (Greenfoot.isKeyDown("D"))
{
setLocation(getX()+4, getY());
}
else if (Greenfoot.isKeyDown("A"))
{
setLocation(getX()-4, getY());
}
shoot();
}
public void setGunReloadTime(int reloadTime)
{
gunReloadTime = reloadTime;
}
public void shoot()
{
if (reloadDelayCount >= gunReloadTime)
{
gunReloadTime = k;
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse == null) return;
int x = mouse.getX();
int y = mouse.getY();
Bullet bullet = new Bullet();
getWorld().addObject(bullet, getX(), getY());
bullet.turnTowards(x, y);
reloadDelayCount = 0;
bullet.move(10.0);
bulletsshot++;
}
}
public static void fasterShooting()
{
k = 5;
l = true;
}
}
private void checkKeypress()
{
final int speed = 3;
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("d")) dx++;
if (Greenfoot.isKeyDown("a")) dx--;
if (Greenfoot.isKeyDown("s")) dy++;
if (Greenfoot.isKeyDown("w")) dy--;
if (dx == 0 && dy == 0) return;
setLocation(getX()+speed *dx, getY()+speed *dy);
if (isTouching(Border.class))
{
setLocation(getX()-speed *dx, getY()-speed *dy);
}
}private void checkKeypress()
{
final int speed = 3;
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("d")) dx++;
if (Greenfoot.isKeyDown("a")) dx--;
if (Greenfoot.isKeyDown("s")) dy++;
if (Greenfoot.isKeyDown("w")) dy--;
if (dx == 0 && dy == 0) return;
setLocation(getX()+speed *dx, getY()+speed *dy);
if (isTouching(Border.class))
{
setLocation(getX()-speed *dx, getY()-speed *dy);
}
}