-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgame_mgr.h
executable file
·48 lines (37 loc) · 1.25 KB
/
game_mgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef __GAMEMANAGER_H_
#define __GAMEMANAGER_H_
#include <allegro.h>
#define DEFAULT_WIDTH 1024
#define DEFAULT_HEIGHT 768
class GameSequence
{
public:
GameSequence(GameSequence *returnScreen)
: iReturnScreen(returnScreen) {}
virtual ~GameSequence(){};
GameSequence* run() { GameSequence* s=doRun(); if (s!=iReturnScreen && iReturnScreen) delete iReturnScreen; return s; };
protected:
virtual GameSequence* doRun() = 0 ;
GameSequence *ReturnScreen() const { return iReturnScreen; };
private:
GameSequence *iReturnScreen;
};
class GameManager
{
public:
static void Init();
static void Shutdown();
static void Run(GameSequence *aSeq);
};
class InterruptTimer
{
public:
static void init() { reset(); install_timer(); install_int(&InterruptTimer::irq, 25); }; // install interrupt timer 1/40s (25 ms)
static void shutdown() { remove_timer(); };
static volatile int timing_counter;
inline static void start() { timing_counter = 0; };
inline static void reset() { timing_counter = -1; };
static void irq() { if (timing_counter>=0) ++timing_counter; };
static bool wasTriggered() { if (timing_counter>0) { timing_counter--; return true; } return false; };
};
#endif