How to make a pause before continuing method
Posted
by
user1766728
on Stack Overflow
See other posts from Stack Overflow
or by user1766728
Published on 2012-10-25T22:52:58Z
Indexed on
2012/10/25
23:00 UTC
Read the original article
Hit count: 167
Now, I know that this has been asked, but I need to know how to do this NOT on html or anything. Heres my code, not including all of the other java files.
package rtype;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class aa {
private int xd;
private int yd;
private int dx;
private int dy;
private int x;
private int y;
private Image image;
private ArrayList missiles;
private final int CRAFT_SIZE = 70;
public aa() {
ImageIcon ii = new ImageIcon(this.getClass().getResource("/aa.png"));
image = ii.getImage();
missiles = new ArrayList();
x = 10;
y = 10;
xd = -14;
yd = 140;
}
public void move() {
if(y >=xd)
y += dx;
else if(y < xd)
y += 1;
if(y <=yd)
y += dy;
else if(y > yd)
y += -1;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Image getImage() {
return image;
}
public ArrayList getMissiles() {
return missiles;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_SPACE) {
fire();
}
if (key == KeyEvent.VK_UP) {
dy = -1;
}
if (key == KeyEvent.VK_DOWN) {
dy = 1;
}
if (key == KeyEvent.VK_RIGHT) {
yd++;
}
if (key == KeyEvent.VK_LEFT) {
yd--;
}
if (key == KeyEvent.VK_W) {
xd++;
}
if (key == KeyEvent.VK_S) {
xd--;
}
}
public void fire() {
try{
missiles.add(new Missle(x + CRAFT_SIZE, y + CRAFT_SIZE));
}catch(Exception e){}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_UP) {
dy = 0;
}
if (key == KeyEvent.VK_DOWN) {
dy = 0;
}
}
}
So, at the method, fire(), I want to make it delay between shots. HOW?
sorry if this is n00bish
© Stack Overflow or respective owner