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

Report as inappropriate.

ThatCodingGuy
ThatCodingGuy presents ...

2014/3/20

SubmArena

A very early game i am in the process of making. Player 1 who is on the bottom is controlled with the arrow keys and uses space to fire. Player 2 who is on the top uses wasd to move a the e key to fire. First person to 15 points wins.

1054 views / 287 in the last 7 days

Tags: game demo

Your browser does not support the canvas tag.
danpostdanpost

2014/3/20

I think the keystrokes are being consumed by one player and the other player will not be able to fire. This is probably the case if you are using the 'getKey' method instead of 'isKeyDown' method.
ThatCodingGuyThatCodingGuy

2014/3/20

Actually i am using the "isKeyDown" method. Here is the code for the submarine import greenfoot.*; public class Submarine extends Movement { private int gunReloadTime = 200; private int reloadDelayCount = 0; public void act() { move(); reloadDelayCount++; } public void move() { if(Greenfoot.isKeyDown("up")) //The different moving keys { move(3); } if(Greenfoot.isKeyDown("down")) { move(-3); } if(Greenfoot.isKeyDown("right")) { turn(3); } if(Greenfoot.isKeyDown("left")) { turn(-3); } if(Greenfoot.isKeyDown("shift")) { shoot(); } } public void setGunReloadTime(int reloadTime) //Defines the reload time { gunReloadTime = reloadTime; } public void shoot() { if(reloadDelayCount >= gunReloadTime) //Fires a torpedo { getWorld().addObject(new Torpedo(getRotation()), getX(), getY()); reloadDelayCount = 0; Greenfoot.playSound("fire.wav"); } } }
danpostdanpost

2014/3/20

I see. Your description says 'space' to fire and the code uses 'shift'. That is what was throwing me.
ThatCodingGuyThatCodingGuy

2014/3/21

Im sorry, I didnt realize I had done that

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.