Translations of this page:

This is an old revision of the document!
—-

9. Finetuning the game

Before we go further, we need to fix a few things we didn't pay attention in the previous chapter and demonstrate a few little concepts along the way. This will be only a little relaxing chapter, so we could gather some energy for the upcoming chapters.

First problem is that our character should walk from the correct spot depending on the previous scene. If you now for example exit through the door in the Room, you appear next to the car. Let's fix it!

Open the scene_init.script in the Street scene and change the beginning to read:

if (Game.PrevScene == "Room") 
{ 
	actor.SkipTo(680, 340); 
	actor.Direction = DI_LEFT; 
 
} 
else 
{ 
	actor.SkipTo(253, 571); 
	actor.Direction = DI_RIGHT; 
} 
 
actor.Active = true;

What we're doing here is referencing Game.PrevScene which contains the name of the room we've just left (previous scene). If it's room, we appear next to the door, otherwise we
appear next to the car. You can of course add as many previous scenes as you like.

Another little thing we add is a small hint animation which would draw attention to the painting. Let's make his eye twinkle. Inside of the folder Room create another folder called Twinkle and copy files eye1 - eye5.jpg there. Then open Sprite Edit and create a sprite which would have delay 70 for all frames. Save this sprite as a twinkle.sprite and open the Room scene in the scene edit. Create the Sprite entity called Twinkle and place the twinkle.sprite there. Position it in the eye of the painting.

Now modify the scene_init.script of the Room scene.

#include "scripts\base.inc" 
 
// here comes the stuff which initializes the scene 
 
 
actor.SkipTo(706, 405); 
actor.Direction = DI_DOWN; 
actor.Active = true; 
 
 
//////////////////////////////////////////////////////////////////////////////// 
// scene state 
global StateRoom; 
 
// default values 
if(StateRoom==null) 
{ 
  StateRoom.Visited = false; 
  // add scene states here 
} 
 
//////////////////////////////////////////////////////////////////////////////// 
// setup scene according to state variables 
 
//////////////////////////////////////////////////////////////////////////////// 
if(!StateRoom.Visited) 
{ 
  StateRoom.Visited = true; 
 
	Game.Interactive = false; 
	var e = Scene.GetNode("Twinkle"); 
	e.Active = true;	 
 
	var sp = e.GetSpriteObject(); 
	while (!sp.Finished) Sleep(1); 
 
        e.Active = false; 
 
	Game.Interactive = true; 
 
  // this is our first visit in this scene... 
} 
 
actor.GoTo(635,459);

What we've done here needs a bit of explaining. The code takes place only when player enters the room for the first time.

First we display the sprite.

  var e = Scene.GetNode("Twinkle"); 
  e.Active = true;

Then we get it's sprite object. Sprite objects are the means how we can manipulate with entities on the lower level. This code provides that the code will wait until the animation still runs. In this case it's not that useful, but many times you need to synchronize your game with animation and this is the way how we can do it:

  var sp = e.GetSpriteObject(); // e is the Node and we get it's low level sprite 
  while (!sp.Finished) Sleep(1); // Finished is set whenever the animation is over


 
wmebook/ch9.1197218556.txt.gz · Last modified: 2007/12/09 17:42 by metamorphium
Recent changes RSS feed Creative Commons License Driven by DokuWiki