Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/buerli/src/game_loader.cc @ 3114

Last change on this file since 3114 was 2707, checked in by bensch, 20 years ago

orxonox/branches/buerli: merged back from trunk, with new configure makefile and so forth.

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
121
122
123
124Campaign* 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*/
138bool 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
170void GameLoader::nextLevel()
171{
172  if(this->currentCampaign != NULL)
173    this->currentCampaign->nextLevel();
174}
175
176void GameLoader::previousLevel()
177{
178  if(this->currentCampaign != NULL)
179    this->currentCampaign->previousLevel();
180}
Note: See TracBrowser for help on using the repository browser.