Source code: jdstar/GameLoop.java
1 /*
2 * Copyright (C) 1999-2001 Max Gilead <gilead@linart.pl>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 package jdstar;
19
20 import huf.misc.Timer;
21 import huf.misc.TimerListener;
22 import javax.swing.JOptionPane;
23
24 class GameLoop
25 implements TimerListener
26 {
27 private static final boolean _ = false;
28
29 /** How many times per one tile of movement timer should update GameLoop. */
30 static final int FRAMES_PER_TILE = 3;
31 /** Speed of movement - how many tiles actor will travel per second. */
32 static final int TILES_PER_SECOND = 40;
33
34 Komander komander = null;
35 Timer timer = null;
36 Board board = null;
37 Display display = null;
38 Player player = null;
39 Buddy buddy = null;
40
41 GameLoop(Board board, Input input, Display display)
42 {
43 timer = new Timer((double)TILES_PER_SECOND * (double)FRAMES_PER_TILE);
44 timer.add(this);
45 this.display = display;
46 this.board = board;
47 player = board.player;
48 buddy = board.buddy;
49 }
50
51 public void start()
52 {
53 timer.start();
54 }
55 public void tick()
56 {
57 if(_)System.out.println("GameLoop: tick()");
58 player.go();
59 buddy.go();
60 display.repaint();
61 if(_)System.out.println("GameLoop: tick(): items left: "+ board.itemsLeft);
62 if (board.itemsLeft == 0)
63 komander.k_null_board_finished();
64 }
65 public void stop()
66 {
67 timer.stop();
68 }
69 }
70