1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: ... |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "game_loader.h" |
---|
20 | #include "campaign.h" |
---|
21 | #include "world.h" |
---|
22 | #include "player.h" |
---|
23 | #include "orxonox.h" |
---|
24 | #include "camera.h" |
---|
25 | #include "command_node.h" |
---|
26 | #include "vector.h" |
---|
27 | #include "track.h" |
---|
28 | |
---|
29 | #include <string.h> |
---|
30 | |
---|
31 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | |
---|
35 | GameLoader* GameLoader::singletonRef = 0; |
---|
36 | |
---|
37 | |
---|
38 | GameLoader::GameLoader () {} |
---|
39 | |
---|
40 | |
---|
41 | GameLoader::~GameLoader () {} |
---|
42 | |
---|
43 | |
---|
44 | GameLoader* GameLoader::getInstance() |
---|
45 | { |
---|
46 | if(singletonRef == NULL) |
---|
47 | singletonRef = new GameLoader(); |
---|
48 | return singletonRef; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | Error GameLoader::init() |
---|
53 | { |
---|
54 | if(this->currentCampaign != NULL) |
---|
55 | this->currentCampaign->init(); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | Error GameLoader::loadCampaign(char* name) |
---|
60 | { |
---|
61 | Error errorCode; |
---|
62 | |
---|
63 | this->currentCampaign = this->fileToCampaign(name); |
---|
64 | } |
---|
65 | |
---|
66 | Error GameLoader::loadDebugCampaign(Uint32 campaignID) |
---|
67 | { |
---|
68 | switch(campaignID) |
---|
69 | { |
---|
70 | // Debug Level 0: Debug level used to test the base frame work. |
---|
71 | case DEBUG_CAMPAIGN_0: |
---|
72 | { |
---|
73 | Campaign* debugCampaign = new Campaign(); |
---|
74 | World* world0 = new World(DEBUG_WORLD_0); |
---|
75 | world0->setNextStoryID(DEBUG_WORLD_1); |
---|
76 | debugCampaign->addEntity(world0, WORLD_ID_0); |
---|
77 | World* world1 = new World(DEBUG_WORLD_1); |
---|
78 | world1->setNextStoryID(WORLD_ID_GAMEEND); |
---|
79 | debugCampaign->addEntity(world1, WORLD_ID_1); |
---|
80 | |
---|
81 | this->currentCampaign = debugCampaign; |
---|
82 | break; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | Error GameLoader::start() |
---|
88 | { |
---|
89 | if(this->currentCampaign != NULL) |
---|
90 | this->currentCampaign->start(); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | Error GameLoader::stop() |
---|
95 | { |
---|
96 | if(this->currentCampaign != NULL) |
---|
97 | this->currentCampaign->stop(); |
---|
98 | this->currentCampaign = NULL; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | Error GameLoader::pause() |
---|
103 | { |
---|
104 | this->isPaused = true; |
---|
105 | if(this->currentCampaign != NULL) |
---|
106 | this->currentCampaign->pause(); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | Error GameLoader::resume() |
---|
111 | { |
---|
112 | this->isPaused = false; |
---|
113 | if(this->currentCampaign != NULL) |
---|
114 | this->currentCampaign->resume(); |
---|
115 | } |
---|
116 | |
---|
117 | Error GameLoader::free() |
---|
118 | {} |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | Campaign* GameLoader::fileToCampaign(char *name) |
---|
125 | { |
---|
126 | /* do not entirely load the campaign. just the current world |
---|
127 | before start of each world, it has to be initialized so it |
---|
128 | can load everything it needs into memory then. |
---|
129 | */ |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /** |
---|
134 | \brief handle keyboard commands |
---|
135 | \param cmd: the command to handle |
---|
136 | \return true if the command was handled by the system |
---|
137 | */ |
---|
138 | bool GameLoader::worldCommand (Command* cmd) |
---|
139 | { |
---|
140 | if( !strcmp( cmd->cmd, "up_world")) |
---|
141 | { |
---|
142 | if( !cmd->bUp) |
---|
143 | { |
---|
144 | this->nextLevel(); |
---|
145 | } |
---|
146 | return true; |
---|
147 | } |
---|
148 | else if( !strcmp( cmd->cmd, "down_world")) |
---|
149 | { |
---|
150 | if( !cmd->bUp) |
---|
151 | { |
---|
152 | this->previousLevel(); |
---|
153 | } |
---|
154 | return true; |
---|
155 | } |
---|
156 | else if( !strcmp( cmd->cmd, "pause")) |
---|
157 | { |
---|
158 | if( !cmd->bUp) |
---|
159 | { |
---|
160 | if(this->isPaused) |
---|
161 | this->resume(); |
---|
162 | else |
---|
163 | this->pause(); |
---|
164 | } |
---|
165 | return true; |
---|
166 | } |
---|
167 | return false; |
---|
168 | } |
---|
169 | |
---|
170 | void GameLoader::nextLevel() |
---|
171 | { |
---|
172 | if(this->currentCampaign != NULL) |
---|
173 | this->currentCampaign->nextLevel(); |
---|
174 | } |
---|
175 | |
---|
176 | void GameLoader::previousLevel() |
---|
177 | { |
---|
178 | if(this->currentCampaign != NULL) |
---|
179 | this->currentCampaign->previousLevel(); |
---|
180 | } |
---|