JNR
stageIntro.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 #include "stdafx.h"
31 #include "laStagesJR.h"
32 
33 stageIntro::stageIntro(void)
34 {
35  _pTS = NULL;
36  _pNarrator = NULL;
37  _pb = NULL;
38 
39  strcpy(_strTitle, "Untitled Intro");
40  strcpy(_strNarrator, "Unknown Narrator");
41 
42  _bNarrator_AutoEmotions = _bNarrator_AutoEmotions_OnCompletion = M_TRUE;
43 
44  _ttEmotionSwitch.parameters(0.5);
45  _ttEmotionSwitch.force();
46 
47  _mkEnter.set(KEY_RETURN, 0.4, 1);
48  _mkEscape.set(KEY_ESCAPE, 0.4, 1);
49 }
50 
51 stageIntro::~stageIntro(void) {
52 }
53 
54 //Command event
55 void uiDesktop_Intro::onCommand(unsigned long uID, unsigned long nCmd)
56 {
57  //::laSystemIntegrator::getGame()->setStage(M_STAGE_GAME);
58 }
59 
60 //Load or reload intro
61 //
62 void stageIntro::load(laFileParser *fp)
63 {
64  fp->readText(_strTitle);
65  fp->readText(_strNarrator);
66  fp->readBool(&_bNarrator_AutoEmotions);
67  fp->readBool(&_bNarrator_AutoEmotions_OnCompletion);
68 
69  // Read up the narrator script
70  fp->readObj(&_fxNarratorText, M_FALSE);
71  _fxNarratorText.parameters(
72  laSystemIntegrator::getRenderer()->font("plain"),
73  15, 1.7, laColor(255,255,255, 200));
74 
75  //_fxNarratorText.enableSlideFX(1,50,0,1,1);
76  _fxNarratorText.enableRambleFX();
77  //_fxNarratorText.enableChaosFX();
78 }
79 
80 void stageIntro::onInit()
81 {
82  _uiDesktop.create("ui\\desktop-mm.dsk");
83 
84  // Add "Proceed..." button
85  //
86  _pb = new uiButton();
87  _pb->create( laPoint3(), laPoint3(100, 50) );
88  _pb->setText("CONTINUE");
89  _uiDesktop.insert( _pb );
90  _pb->move( laPoint3(0, 40), M_AC, M_AB);
91  _pb->hide();
92 }
93 
94 void stageIntro::onFini(){
95  delete _pb;
96  _pb = NULL;
97 }
98 
99 void stageIntro::onActivate()
100 {
101  ASSERT(_pTS, "Nil tileset");
102 
103  laSystemIntegrator::getEnvironment()->setTitle(_strTitle);
104  _uiDesktop.getMousePointer()->show();
105  _uiDesktop.get(1)->hide();
106 
107  // Get narrator
108  //
109  unsigned nNaratorID = _pTS->getElementIndex(_strNarrator);
110  if( nNaratorID >= _pTS->getElementCnt() ) throw laError("stageIntro::onFrame(): Narrator of type '%s' is not present in the TS", _strNarrator);
111  laElement* pNaratorElement = _pTS->getElement(nNaratorID);
112 
113  _pNarrator = new laStateObject();
114  _pNarrator->setTS(_pTS);
115  _pNarrator->setObject(nNaratorID, (laElement*)pNaratorElement);
116  _pNarrator->create();
117  _pNarrator->setOutline( laOutline(M_TRUE, laColor(250,250,250)) );
118 }
119 
120 void stageIntro::onDeactivate()
121 {
122  ASSERT(_pTS, "Nil tileset");
123  ASSERT(_pNarrator, "Nil narrator object");
124 
125  _pTS = NULL; // level obj takes care for the TS
126 
127  delete _pNarrator; // get rid of the narrator
128  _pNarrator = NULL;
129 }
130 
131 void stageIntro::onFrame(laRenderer *pr, laInputManager *pi, laTimer *pt)
132 {
133  ASSERT(_pTS, "Nil tileset");
134  ASSERT(_pNarrator, "Nil narrator object");
135 
136  // Draw interface
137  //
138  pr->modeInterface();
139  _uiDesktop.drawBackground();
140  _uiDesktop.reply();
141  _uiDesktop.draw();
142 
143  // Skip introduction on user request
144  //
145  _mkEnter.animate(pi, *pt);
146  _mkEscape.animate(pi, *pt);
147 
148  if( _mkEnter.isActivated() || _mkEscape.isActivated() )
149  {
150  _mkEnter.reset();
151  _mkEscape.reset();
152 
153  if( _fxNarratorText.isFinished() )
154  ::laSystemIntegrator::getGame()->setStage(M_STAGE_GAME);
155  else
156  {
157  _fxNarratorText.force();
158  if(_bNarrator_AutoEmotions_OnCompletion) _bNarrator_AutoEmotions = M_TRUE;
159  }
160  }
161 
162  //Draw text and animate
163  //
164  double w = laSystemIntegrator::getSettings()->graphics_resolution_w;
165  double h = laSystemIntegrator::getSettings()->graphics_resolution_h;
166  double y_min = h - _fxNarratorText.height() - 150;
167 
168  _fxNarratorText.draw(pr, laPoint3(w/2, y_min, 0));
169  _fxNarratorText.animate( *pt );
170 
171  if( _fxNarratorText.visibleCount() >= _fxNarratorText.totalCount() ) _uiDesktop.get(1)->show();
172 
173  // Draw narrator
174  //
175  pr->modeWorld( laPoint3( 0, 0, M_UNIT*10 ), laPoint3(10, 0) );
176  pr->transRotate( -10, laPoint3(1,0,0) );
177 
178  //if(_nVisible==1) pr->styleSet( laColor(255, 255, 255, alpha) );
179  /*else*/ pr->styleSet( laColor(255, 255, 255, 255) );
180 
181  pr->modeLight(M_TRUE);
182  pr->lightAmbient(0, laColor(100,100,100,255) );
183  pr->lightMakeSunlight(0, laPoint3( 0, 0, -M_UNIT*10 ) );
184 
185  _pNarrator->drawGeometry( pr, laPoint3() );
186  _pNarrator->animate( *pt );
187  //_pNarrator->getObject()->animate( *pt );
188  //_pNarrator->drawFx( pr, laPoint3(0, M_UNIT) );
189 
190  _pTS->getBackgroundElement()->drawGeometry(pr);
191  _pTS->getBackgroundElement()->drawFx(pr);
192  _pTS->animate(*pt);
193 
194  //Animate narrator emotions
195  //
196  _ttEmotionSwitch.animate( *pt );
197 
198  if( !_bNarrator_AutoEmotions )
199  {
200  _pNarrator->state( _fxNarratorText.currentEmotion() );
201  }
202  else if( _ttEmotionSwitch.isElapsed())
203  {
204  _pNarrator->state( rand()% (_pNarrator->getObject()->getModelCnt()) );
205 
206  _ttEmotionSwitch.parameters( 1 + (rand()%10)/10.0 );
207  _ttEmotionSwitch.reset();
208  }
209 }
#define M_AB
Text align bottom.
#define M_UNIT
Unit of 1 meter.
virtual void onCommand(unsigned long uID, unsigned long nCmd)
Command event handler.
Definition: stageIntro.cpp:55
Base Class for Tileset Elements.
Definition: laElement.h:48
Multi-state Level Object.
Definition: laStateObject.h:64
Object outline properties.
Definition: laRenderer.h:66
GUI Push-button.
Definition: uiButton.h:41
#define M_AC
Text align center.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void modeInterface()=0
Switch to interface rendering (2D projection mode)
virtual void modeLight(M_BOOL bOn)=0
Enable/disable lighting.
virtual void modeWorld(const laPoint3 &pos, const laPoint3 &ang=laPoint3())=0
Switch to "world rendering" (3D projection mode)
Error handling class.
Definition: laError.h:46
File Parser.
Definition: laFileParser.h:41