Floaty text

Need help with using DizzyAGE then look here
delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Fri Oct 30, 2009 6:37 pm

DizzyFanUK wrote:Would someone be able to pop a screenshot of just what floaty text looks like in a game?

Im trying to imagine it in practice?
is it like the intro screen where big DIZZY letters dance about?
or is it like when you click on a power up and for a few seconds some flashy points numbers float up into the air, then fade away?
Cool effects :)
I think the closest thing to what he's trying to do is the '10' points text that appears in the arcade games in IID when you kill the baddies. That, however, was just a 3 or 4 frame graphical animation.
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Fri Oct 30, 2009 8:07 pm

Right, here is how to display 'floating' text as a message:

firstly, put the following in gamedef.gs:

Code: Select all

#def G_FLOAT		80			// set floating text display. 0=off, 1+ =on
#def G_FLOATXPOS	81			// set floating text X position
#def G_FLOATYPOS	82			// set floating text Y position
#def G_FLOATNUM		83			// set floating text Maximum movement


#def FLOATTEXT					// set floating text message
use different numbers to 80-83 if you're already using those for other game variables.

At the bottom of util.gs, put the following code:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////
// IN: int; x; horizontal coordinate in characters, multiple of 8 pixels
// IN: int; y; vertical coordinate in characters, multiple of 8 pixels
// IN: str; text; message text
// IN: int; speed; amount of pixels to float up by
// Sets a transparent message (floating up) in a similar way to Message()
/////////////////////////////////////////////////////////////////////////////////
func MesFloatUp( x, y, text , speed )
{
	GameSet(G_FLOATNUM, speed*2);
	GameSet(G_FLOATXPOS,x);
	GameSet(G_FLOATYPOS,y);

	FLOATTEXT = text;

	GameSet(G_FLOAT, 1);
}

/////////////////////////////////////////////////////////////////////////////////
// IN: int; x; horizontal coordinate in characters, multiple of 8 pixels
// IN: int; y; vertical coordinate in characters, multiple of 8 pixels
// IN: str; text; message text
// IN: int; speed; time to display message (in seconds, roughly)
// Sets a transparent message (static) in a similar way to Message()
/////////////////////////////////////////////////////////////////////////////////
func MesFloatStatic( x, y, text , speed )
{
	GameSet(G_FLOATNUM, 0);
	GameSet(G_FLOATXPOS,x);
	GameSet(G_FLOATYPOS,y);

	FLOATTEXT = text;

	GameSet(G_FLOAT, speed*37);
}

/////////////////////////////////////////////////////////////////////////////////
// Updates the floating text to move up / disappear after a set time
/////////////////////////////////////////////////////////////////////////////////
func UpdateFloatText()
{
	floattext = GameGet(G_FLOAT);
	floatnum = GameGet(G_FLOATNUM);
	if(floattext>=1&&floatnum!=0)								// if text is to float up
	{
		GameSet(G_FLOAT,floattext+1);
		if (GameGet(G_FLOAT)>=floatnum) { GameSet(G_FLOAT,0); }				// stop text when planned

		if ((GameGet(G_FLOATYPOS)*8)-(floattext/2)<=2)  { GameSet(G_FLOAT,0); }	// stop text if it tries to move higher than the game screen
	}
	if(floattext>=1&&floatnum==0)								// if text is to stay static
	{
		GameSet(G_FLOAT,floattext-1);
	}
}
in function HandlerGameUpdate() in handlers.gs, put the following line of code:

Code: Select all

	UpdateFloatText();
and at the bottom of function HandlerDrawHud() in handlers.gs, put the following code:

Code: Select all

	// float text
	floattext = GameGet(G_FLOAT);
	floatnum = GameGet(G_FLOATNUM);
	fx = GameGet(G_FLOATXPOS);
	fy = GameGet(G_FLOATYPOS);

	if(floattext>=1&&floatnum!=0)
	{
		text = FLOATTEXT;
		w = HudGetTextWidth( text );
		h = HudGetTextHeight( text );
		HudColor(0xff000000);							// set colour as black
		HudDrawText( fontid, (fx*8)+8,(fy*8)+47-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, (fx*8)+8,(fy*8)+49-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, (fx*8)+7,(fy*8)+48-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, (fx*8)+9,(fy*8)+48-(floattext/2),w,h, text, 0 );	// background text
		HudColor(0xffffff00);							// set colour as yellow
		HudDrawText( fontid, (fx*8)+8,(fy*8)+48-(floattext/2),w,h, text, 0 );	// foreground text
	}
	if(floattext>=1&&floatnum==0)
	{
		text = FLOATTEXT;
		w = HudGetTextWidth( text );
		h = HudGetTextHeight( text );
		HudColor(0xff000000);							// set colour as black
		HudDrawText( fontid, (fx*8)+8,(fy*8)+47,w,h, text, 0 );			// background text
		HudDrawText( fontid, (fx*8)+8,(fy*8)+49,w,h, text, 0 );			// background text
		HudDrawText( fontid, (fx*8)+7,(fy*8)+48,w,h, text, 0 );			// background text
		HudDrawText( fontid, (fx*8)+9,(fy*8)+48,w,h, text, 0 );			// background text
		HudColor(0xffffff00);							// set colour as yellow
		HudDrawText( fontid, (fx*8)+8,(fy*8)+48,w,h, text, 0 );			// foreground text
	}
you may have noticed that there are two functions you can call. They are MesFloatUp and MesFloatStatic. These do pretty much as they say, MesFloatUp makes the floating message float up, and MesFloatStatic displays the floating message as static in one place.

They are used in almost exactly the same way as you'd use Message(), with the first two numbers being the X and Y positions, and the text between the "" being, well, the text that is displayed. The additional number at the end differs depending on which function is used. In MesFloatUp it is the number of pixels the text will rise up by before disappearing, and in MesFloatStatic it is the (rough) number of seconds the text will display for.

They are called in the normal places you'd call a message from, as so:

Code: Select all

	MesFloatUp(4,9,"THIS TEXT WILL FLOAT UP BY 40 PIXELS",40);

	MesFloatStatic(4,9,"THIS TEXT WILL STAY STATIC FOR 3 SECONDS",3);
MessagePop() is not used with either of the two functions.

Note that when using MesFloatUp, if the text gets higher than the top of the 'room' window (which is 40 pixels from the top of the HUD), then the text will automatically disappear, so that it doesn't overlap the HUD.

any questions, just ask! :)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Fri Oct 30, 2009 8:18 pm

Regarding doing the message when you find a coin, you'd need to replace the following highlighted code in function DoPickupObject(idx) in action.gs:

Code: Select all

	if(class==CLASS_COIN) // coins are to be collected
	{
		coins = PlayerGet(P_COINS)+1;
		ObjSet(idx, O_DISABLE, 1); // make disabled (picked up)
		PlayerSet(P_COINS,coins); // store coins counter
		SamplePlay(FX_COIN);
		
		// check if found them all - edit these messages
		if( coins==MAXCOINS )
			[color="#ff0000"]OpenDialogMessage("YOU HAVE FOUND\nALL THE COINS");[/color]
		else
			[color="#ff0000"]OpenDialogMessage("YOU HAVE FOUND\nA COIN");[/color]
	}
with this code:

Code: Select all

	if(class==CLASS_COIN) // coins are to be collected
	{
		coins = PlayerGet(P_COINS)+1;
		ObjSet(idx, O_DISABLE, 1); // make disabled (picked up)
		PlayerSet(P_COINS,coins); // store coins counter
		SamplePlay(FX_COIN);
		
		// check if found them all - edit these messages
		if( coins==MAXCOINS )
			[color="Red"]MesFloatUp(8,7,"YOU HAVE FOUND\nALL THE COINS",40);[/color]
		else
			[color="#ff0000"]MesFloatUp(8,7,"YOU HAVE FOUND\nA COIN",40);[/color]
	}
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Queex
Hard Boiled Egg
Posts: 124
Joined: Thu Oct 22, 2009 5:04 pm

Post by Queex » Sat Oct 31, 2009 11:11 pm

That's excellent! Pretty much exactly what I needed.

I'm going to embellish it a little- making the text change based on which graphic is used (possible by accessing the tilemap properties and more foolproof than setting it for each coin individually).

I'll also fiddle with it to use pixel co-ordinates (so it's easy to snap and centre to Dizzy's position when he collects the coin).

But many thanks for showing me the way!
- Lost Temple Dizzy -
- Iron Tower Dizzy -

Queex
Hard Boiled Egg
Posts: 124
Joined: Thu Oct 22, 2009 5:04 pm

Post by Queex » Sat Oct 31, 2009 11:33 pm

For reference, my adjustments:

In HandlerDrawHud():

Code: Select all

// float text
	floattext = GameGet(G_FLOAT);
	floatnum = GameGet(G_FLOATNUM);
	fx = GameGet(G_FLOATXPOS);
	fy = GameGet(G_FLOATYPOS);
	absx = fx - GameGet(G_ROOM X) *GameGet(G_ROOMW);
	absy = fy - GameGet(G_ROOMY)*GameGet(G_ROOMH);

	if(floattext>=1&&floatnum!=0)
	{
		text = FLOATTEXT;
		w = HudGetTextWidth( text );
		h = HudGetTextHeight( text );
		
		HudColor(0xff000000);							// set colour as black
		HudDrawText( fontid, absx+8,absy+47-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, absx+8,absy+49-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, absx+7,absy+48-(floattext/2),w,h, text, 0 );	// background text
		HudDrawText( fontid, absx+9,absy+48-(floattext/2),w,h, text, 0 );	// background text
		HudColor(0xffffff00);							// set colour as yellow
		HudDrawText( fontid, absx+8,absy+48-(floattext/2),w,h, text, 0 );	// foreground text
	}
	if(floattext>=1&&floatnum==0)
	{
		text = FLOATTEXT;
		w = HudGetTextWidth( text );
		h = HudGetTextHeight( text );
		HudColor(0xff000000);							// set colour as black
		HudDrawText( fontid, absx+8,absy+47,w,h, text, 0 );			// background text
		HudDrawText( fontid, absx+8,absy+49,w,h, text, 0 );			// background text
		HudDrawText( fontid, absx+7,absy+48,w,h, text, 0 );			// background text
		HudDrawText( fontid, absx+9,absy+48,w,h, text, 0 );			// background text
		HudColor(0xffffff00);							// set colour as yellow
		HudDrawText( fontid, absx+8,absy+48,w,h, text, 0 );			// foreground text
	}
In DoPickUpObject():

Code: Select all

	if(class==CLASS_COIN) // coins are to be collected
	{
		coins = PlayerGet(P_COINS)+1;
		ObjSet(idx, O_DISABLE, 1); // make disabled (picked up)
		PlayerSet(P_COINS,coins); // store coins counter
		SamplePlay(FX_COIN);
		
		//floaty message
		coinhash= ObjGet(idx,O_MAP)*1000+ObjGet(idx,O_MAP+1);
		if(coinhash==0){
			text="+1 coin";
		} else if(coinhash==16000){
			text="+1 ankh";
		} else if(coinhash==16){
			text="+1 pearl";
		} else if(coinhash==16016){
			text="+1 diamond";
		} else {
			text="+1 treasure";
		}
		x = PlayerGet(P_ X) - HudGetTextWidth(text)/2;
		y = PlayerGet(P_Y) - 16;
		MesFloatUp(x,y,text,15);
	}
This works best if all coins are in the same tga file.
- Lost Temple Dizzy -
- Iron Tower Dizzy -

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Sat Oct 31, 2009 11:54 pm

nice. I see what you've done to center it above the player. :)

I also see what you've done to differentiate the different 'collect' items. However, i'd have done it a different way :p

in gamedef.gs, set the following:

Code: Select all

#def O_COINTYPE		40			// coin type for setting messages
then change your DoPickUpObject() code to the following:

Code: Select all

	if(class==CLASS_COIN) // coins are to be collected
	{
		coins = PlayerGet(P_COINS)+1;
		ObjSet(idx, O_DISABLE, 1); // make disabled (picked up)
		PlayerSet(P_COINS,coins); // store coins counter
		SamplePlay(FX_COIN);
		
		//floaty message
		coinhash= ObjGet(idx,O_COINTYPE);
		if(coinhash==1) { text="+1 coin"; }
		if(coinhash==2) { text="+1 ankh"; }
		if(coinhash==3) { text="+1 pearl"; }
		if(coinhash==4) { text="+1 diamond"; }
		if(coinhash==5) { text="+1 treasure"; }
		x = PlayerGet(P_ X) - HudGetTextWidth(text)/2;
		y = PlayerGet(P_Y) - 16;
		MesFloatUp(x,y,text,15);
	}
then i'd use object property 40 to set in the map which collectible 'type' each one is.

hmmm, looking at it now, it actually requires a bit more work in the map than your way (albeit not much). The advantage is that this way doesn't rely on all the collectibles being on the same tile, and you could even swap them all around at a later date and the code wouldn't be affected.

ah well, if your way works fine for you, then that's cool :)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Queex
Hard Boiled Egg
Posts: 124
Joined: Thu Oct 22, 2009 5:04 pm

Post by Queex » Sun Nov 01, 2009 11:37 pm

I thought about doing it that way, but I then decided I didn't trust myself to not forget a coin somewhere. That would have been embarrassing.

The difficult part was in working out how to display the text and updating in the right place. I let you do all of that :v2_dizzy_tongue2:

I guess an even better solution would have separate calls for by map position and by screen position, but I've got what I wanted and I'll never get anything else done if I keep tinkering. The text is still painted and floats up when menus are open- a thorough solution wouldn't do that, I guess. I hope it doesn't break on a save and reload, but it's difficult to test.
- Lost Temple Dizzy -
- Iron Tower Dizzy -

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Mon Nov 02, 2009 6:02 am

there shouldn't be a problem on save/reload. test it just to be sure though.

you can also use the 'select' feature in the map editor to search for tiles that are class=coin, and specific tile/mapping properties. I don't see that there's any real need for specific calls by map/screen position.
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Post Reply