Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/game_loader.cc @ 3220

Last change on this file since 3220 was 3220, checked in by patrick, 19 years ago

orxonox/trunk: fixed a lot of bugs with StoryEntity management, also cleared up some old unused code

File size: 3.3 KB
Line 
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
32using namespace std;
33
34
35GameLoader* GameLoader::singletonRef = 0;
36
37
38GameLoader::GameLoader () {}
39
40
41GameLoader::~GameLoader () {}
42
43
44GameLoader* GameLoader::getInstance()
45{
46  if(singletonRef == NULL)
47    singletonRef = new GameLoader();
48  return singletonRef;
49}
50
51
52Error GameLoader::init()
53{
54  if(this->currentCampaign != NULL)
55    this->currentCampaign->init();
56}
57
58
59Error GameLoader::loadCampaign(char* name)
60{
61  Error errorCode;
62 
63  this->currentCampaign = this->fileToCampaign(name);
64}
65
66Error 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
75        World* world0 = new World(DEBUG_WORLD_0);
76        world0->setNextStoryID(WORLD_ID_1);
77        debugCampaign->addEntity(world0, WORLD_ID_0);
78
79        World* world1 = new World(DEBUG_WORLD_1);
80        world1->setNextStoryID(WORLD_ID_GAMEEND);
81        debugCampaign->addEntity(world1, WORLD_ID_1);
82
83        this->currentCampaign = debugCampaign;
84        break;
85      }
86    }
87}
88
89Error GameLoader::start()
90{
91  if(this->currentCampaign != NULL)
92    this->currentCampaign->start();
93}
94
95
96Error GameLoader::stop()
97{
98  if(this->currentCampaign != NULL)
99    this->currentCampaign->stop();
100  this->currentCampaign = NULL;
101}
102
103
104Error GameLoader::pause()
105{
106  this->isPaused = true;
107  if(this->currentCampaign != NULL)
108    this->currentCampaign->pause();
109}
110
111
112Error GameLoader::resume()
113{
114  this->isPaused = false;
115  if(this->currentCampaign != NULL)
116    this->currentCampaign->resume();
117}
118
119Error GameLoader::free()
120{}
121
122
123Campaign* GameLoader::fileToCampaign(char *name)
124{
125  /* do not entirely load the campaign. just the current world
126     before start of each world, it has to be initialized so it
127     can load everything it needs into memory then.
128  */
129}
130
131
132/**
133   \brief handle keyboard commands
134   \param cmd: the command to handle
135   \return true if the command was handled by the system
136*/
137bool GameLoader::worldCommand (Command* cmd)
138{
139  if( !strcmp( cmd->cmd, "up_world"))
140    {
141      if( !cmd->bUp) 
142        {
143          this->nextLevel();
144        }
145      return true;
146    }
147  else if( !strcmp( cmd->cmd, "down_world"))
148    {
149      if( !cmd->bUp)
150        {
151          this->previousLevel();
152        }
153      return true;
154    }
155  else if( !strcmp( cmd->cmd, "pause"))
156    {
157      if( !cmd->bUp)
158        {
159          if(this->isPaused)
160            this->resume();
161          else
162            this->pause();
163        }
164      return true;
165    }
166  else if( !strcmp( cmd->cmd, "quit"))
167    {
168      if( !cmd->bUp) this->stop();
169      return true;
170    }
171  return false;
172}
173
174void GameLoader::nextLevel()
175{
176  if(this->currentCampaign != NULL)
177    this->currentCampaign->nextLevel();
178}
179
180void GameLoader::previousLevel()
181{
182  if(this->currentCampaign != NULL)
183    this->currentCampaign->previousLevel();
184}
Note: See TracBrowser for help on using the repository browser.