Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

/orxonox/trunk: discovered a minor bug and fixed some code style issues…

File size: 3.2 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        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
87Error GameLoader::start()
88{
89  if(this->currentCampaign != NULL)
90    this->currentCampaign->start();
91}
92
93
94Error GameLoader::stop()
95{
96  if(this->currentCampaign != NULL)
97    this->currentCampaign->stop();
98  this->currentCampaign = NULL;
99}
100
101
102Error GameLoader::pause()
103{
104  this->isPaused = true;
105  if(this->currentCampaign != NULL)
106    this->currentCampaign->pause();
107}
108
109
110Error GameLoader::resume()
111{
112  this->isPaused = false;
113  if(this->currentCampaign != NULL)
114    this->currentCampaign->resume();
115}
116
117Error GameLoader::free()
118{}
119
120
121Campaign* GameLoader::fileToCampaign(char *name)
122{
123  /* do not entirely load the campaign. just the current world
124     before start of each world, it has to be initialized so it
125     can load everything it needs into memory then.
126  */
127}
128
129
130/**
131   \brief handle keyboard commands
132   \param cmd: the command to handle
133   \return true if the command was handled by the system
134*/
135bool GameLoader::worldCommand (Command* cmd)
136{
137  if( !strcmp( cmd->cmd, "up_world"))
138    {
139      if( !cmd->bUp) 
140        {
141          this->nextLevel();
142        }
143      return true;
144    }
145  else if( !strcmp( cmd->cmd, "down_world"))
146    {
147      if( !cmd->bUp)
148        {
149          this->previousLevel();
150        }
151      return true;
152    }
153  else if( !strcmp( cmd->cmd, "pause"))
154    {
155      if( !cmd->bUp)
156        {
157          if(this->isPaused)
158            this->resume();
159          else
160            this->pause();
161        }
162      return true;
163    }
164  return false;
165}
166
167void GameLoader::nextLevel()
168{
169  if(this->currentCampaign != NULL)
170    this->currentCampaign->nextLevel();
171}
172
173void GameLoader::previousLevel()
174{
175  if(this->currentCampaign != NULL)
176    this->currentCampaign->previousLevel();
177}
Note: See TracBrowser for help on using the repository browser.