RPG Floating Stats

Started by Rocco, Fri 16/07/2010 15:54:44

Previous topic - Next topic

Rocco

i want to add a FLoating RGP-Stats system, like the old rpg games,
to give the player direct visible feedback, if he takes a  few dollars, or reach a higher skill level.


Maybe like this - the text (dollars +25) is faded in at player position, maybe moves a bit up and disappears a little over the players head.
I guess i saw a code snippet with similar functionality around here, but cant find it.
If i have to code this by myself, was would be the best approach to achieve this?





Calin Leafshade

Something like this:

Code: ags


struct TextMessage {
  String Message;
  float x; 
  float y;
  float speed;
  float transparency;
  float decay;
  int colour;
  bool on;
};

TextMessage TextMessages[6];


function NewTextMessage(String Message, float x,  float y, float speed, float decay, int colour){
  bool found;
  int counter = 0;
  int NextFree = -1;
  while (!found && counter < 5){
    if (TextMessages[counter].on == false){
      NextFree = counter;
      found = true;
    }
    counter ++;
  }
  if (found){
    TextMessages[NextFree].Message = Message;
  TextMessages[NextFree].x = x;
  TextMessages[NextFree].y = y;
  TextMessages[NextFree].speed = speed;
  TextMessages[NextFree].decay = decay;
  TextMessages[NextFree].transparency = 0.0;
  TextMessages[NextFree].on = true;
  TextMessages[NextFree].colour = colour;
       
  }
  
  
}


function UpdateTextOverlays(){ //run this every loop
  int counter = 0;
  while (counter < 5){
   if(TextMessages[counter].on){
     TextMessages[counter].y += TextMessages[counter].speed;
    gui[counter + 1].X = FloatToInt(TextMessages[counter].x);
    gui[counter + 1].Y = FloatToInt(TextMessages[counter].y);
    gui[counter + 1].Controls[0].AsLabel.Text = TextMessages[counter].Message;
    gui[counter + 1].Controls[0].AsLabel.TextColor = TextMessages[counter].colour;
    TextMessages[counter].transparency += TextMessages[counter].decay;
    if (TextMessages[counter].transparency > 100.00) TextMessages[counter].transparency = 100.00;
    gui[counter + 1].Transparency = FloatToInt(TextMessages[counter].transparency);
    if (gui[counter + 1].Transparency == 100) TextMessages[counter].on = false;
    
  }
  counter ++;
  }

  
}



this code isnt very generic since it's ripped straight from the McCarthy RPG

ok this will use guis with the ids 1-7 (you can easily change this providing all your guis are in sequential) with a label as their first control (i.e gui[index].Controls[0])
this is the label that gets updated.

an example of a function call is something like this (although its specific to my game and wont work in yours):

Code: ags
NewTextMessage(String.Format("%d", Damage), IntToFloat(character[CharToDamage].x - 5), IntToFloat(character[CharToDamage].y - 65),-0.4, 1.5, 65535);


Rocco

bigthanks,  ;D
i will check that soon.  :D

SMF spam blocked by CleanTalk