Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/src/campaign.cc @ 2775

Last change on this file since 2775 was 2636, checked in by patrick, 20 years ago
  • Added a GameLoader to the game. This enables orxonox to load a campaign consisting of multimple worlds and cinematics etc. However, cinematics are not yet implemented.

In the game you can jump from one level to the other by pressing x. Currently there are only two very simple levels defined. (DEBUG_LEVEL_0, DEBUG_LEVEL_1).

  • Added Error Handling structs to signal the error source and code
File size: 3.0 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 "campaign.h"
20#include "world.h"
21#include "camera.h"
22#include "story_entity.h"
23
24using namespace std;
25
26
27Campaign::Campaign () 
28{
29  this->entities = new List<StoryEntity>();
30  this->isInit = false;
31}
32
33Campaign::~Campaign () {}
34
35
36Error Campaign::init()
37{
38  this->isInit = true;
39}
40
41/**
42    \brief adds an game stroy entity to the campaign
43
44    \param se: The entity
45    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
46
47    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
48    want to queue up in the campaign.
49*/
50void Campaign::addEntity(StoryEntity* se, Uint32 storyID)
51{
52  se->setStoryID(storyID);
53  this->addEntity(se);
54}
55
56void Campaign::addEntity(StoryEntity* se)
57{
58  this->entities->add(se);
59}
60
61
62void Campaign::removeEntity(Uint32 storyID)
63{
64  this->removeEntity(this->getStoryEntity(storyID));
65 
66}
67
68
69void Campaign::removeEntity(StoryEntity* se)
70{
71  this->entities->remove(se);
72}
73
74
75Error Campaign::start()
76{
77  this->start(0);
78}
79
80Error Campaign::start(Uint32 storyID = 0)
81{
82  printf("World::start() - starting new StoryEntity Nr:%i\n", storyID);
83  Error errorCode;
84  if(!this->isInit) return errorCode; 
85  if(storyID == WORLD_ID_GAMEEND) return errorCode;
86  this->running = true;
87  StoryEntity* se = this->getStoryEntity(storyID);
88  while(se != NULL && this->running)
89    {
90      se = this->getStoryEntity(storyID);
91      this->currentEntity = se;
92     
93      se->displayEntityScreen();
94      se->load();
95      se->init();
96      se->releaseEntityScreen();
97      se->start();
98
99      int nextWorldID = se->getNextStoryID();
100      if(nextWorldID == WORLD_ID_GAMEEND) return errorCode;
101      se = this->getStoryEntity(nextWorldID);
102      if(se == NULL)
103        printf("Campaign::start() - ERROR: world it not found, oh oh...");
104    }
105}
106
107Error Campaign::stop()
108{
109  this->running = false;
110  if(this->currentEntity != NULL) 
111    {
112      this->currentEntity->stop();
113      delete this->currentEntity;
114      this->currentEntity = NULL;
115    }
116}
117
118Error Campaign::pause()
119{
120  if(this->currentEntity != NULL)
121    this->isPaused = true;
122}
123
124
125Error Campaign::resume()
126{
127  if(this->currentEntity != NULL)
128    this->isPaused = false;
129}
130
131
132void Campaign::nextLevel()
133{
134  printf("Campaign|nextLevel\n");
135  int nextID = this->currentEntity->getNextStoryID();
136  this->stop();
137  this->start(nextID);
138}
139
140void Campaign::previousLevel()
141{}
142
143
144StoryEntity* Campaign::getStoryEntity(Uint32 storyID)
145{
146  List<StoryEntity>* l;
147  StoryEntity* entity;
148  l = this->entities->get_next(); 
149  while( l != NULL) 
150    { 
151      entity = l->get_object();
152      l = l->get_next();
153      if(entity->getStoryID() == storyID)
154        return entity;
155    }
156  return NULL;
157}
Note: See TracBrowser for help on using the repository browser.