Ok, I am making a game in Java, (but this is overall code design help, not specific to Java) and I have made a (poorly designed) primitive version of a future game. It has no loop, when it detects input it re renders. At first this worked fine... But I want to add an AI. I tried making it into a game loop but it freezes and dies. Can someone give help on this sort of problem? It gets consumed by the while loop and nothing else happens. HELP!
Thanks, Awesomeness
Pseudo code:
main()
Sorry if the pseudo code is bad, I'm not sure how you're supposed to write pseudo code, so if this is not the right way, please show how it's supposed to be done.
Ok, with mufflon's post (thanks!) and a little help from the internet, I found the answer! Hooray!
Thanks, Awesomeness
Pseudo code:
main()
Code:
import window stuffs;
import painty stuffs;
public class NewGame {
public static void main() {
new window;
new GamePanel(width, height) inside;
make window visible;
}
}
public class GamePanel extends Canvas {
GamePanel(int width, int height) {
set bg to green; // only once, I use dirty rects
player = new Dot(x, y, width, height, dotColor, bgColor);
if key pressed:
move player according to key pressed;
repaint();
}
//note that Dot is just a square class that I made.
//It's very useful! It uses dirty rects. I left out
//some of thew painting code because it doesn't matter.
}
Sorry if the pseudo code is bad, I'm not sure how you're supposed to write pseudo code, so if this is not the right way, please show how it's supposed to be done.
Ok, with mufflon's post (thanks!) and a little help from the internet, I found the answer! Hooray!