3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1] 2

Author Topic: Sprite Health Bar  (Read 2551 times)

« on: May 13, 2010, 12:34:36 AM »
Hey everyone

I'm having a bit of trouble getting my health bar to work. What I did is place 10 sprites in my project which are not visible at start. I then placed a counter in game with an initial Value of 10 and an increment of -1. I then placed an EventOnValue in the project which monitors the counter value, continuous detection is enabled and min/max range is set to 0. I then attached the following script to the Counter and EventOnValue.

Code: [Select]
void Main()
{
    if (IN_0 == 1) ///Counter value(Player_Health)
      {
      iObjectHide(OBJ_44); ///Sprite 1
      iObjectHide(OBJ_66); ///Sprite 2
      iObjectHide(OBJ_88); ///Sprite 3
      iObjectHide(OBJ_110); /// Sprite 4
      iObjectHide(OBJ_132); ///Sprite 5
      iObjectShow(OBJ_154); ///Sprite 6
      iObjectHide(OBJ_176); ///Sprite 7
      iObjectHide(OBJ_198); ///Sprite 8
      iObjectHide(OBJ_220); /// Sprite 9
      iObjectHide(OBJ_242); /// Sprite 10
      }
    if (IN_0 == 2)
      {
      iObjectShow(OBJ_44);
      iObjectHide(OBJ_66);
      iObjectHide(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 3)
      {
      iObjectShow(OBJ_44);
      iObjectHide(OBJ_66);
      iObjectHide(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectShow(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 4)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectHide(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 5)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectHide(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectShow(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 6)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectShow(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 7)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectShow(OBJ_88);
      iObjectHide(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectShow(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 8)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectShow(OBJ_88);
      iObjectShow(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
    if (IN_0 == 9)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectShow(OBJ_88);
      iObjectShow(OBJ_110);
      iObjectHide(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectShow(OBJ_242);
      }
    if (IN_0 == 10)
      {
      iObjectShow(OBJ_44);
      iObjectShow(OBJ_66);
      iObjectShow(OBJ_88);
      iObjectShow(OBJ_110);
      iObjectShow(OBJ_132);
      iObjectHide(OBJ_154);
      iObjectHide(OBJ_176);
      iObjectHide(OBJ_198);
      iObjectHide(OBJ_220);
      iObjectHide(OBJ_242);
      }
}

I also added an EventOnContact and EventOnValue to monitor the collision between the car, the bullets and to run the counter above.

I figure its something wrong with the script since I�m pretty new to it. What happens is this, when I run the game the sprites load up like they are suppose to but 99% of the time the Sprites don't refresh and disappear  when my vehicle is hit. It works once every 50 hits id say but it�s random.  Anyone have any suggestions as to what I am doing wrong?

Thanks

jestermon

« Reply #1 on: May 13, 2010, 12:47:32 AM »
Do you use sprites to overlap each other to simulate a sliding guage, and then hide and show them according to value... I can't really see what you are trying to do with out the complete project.. Perhaps a compiled project dropped here can help us see?

However here is a little plug-in that may do what you have in mind

SLIDE METER GAUGE

Edit: As usual, as I Edit, someone beats me to the draw to say what I inteded to .. :P
« Last Edit: May 13, 2010, 12:51:53 AM by jestermon »
« Reply #2 on: May 13, 2010, 12:48:47 AM »
If you want help with the project, create it using default 3drad resources and upload the project file.
« Reply #3 on: May 13, 2010, 01:58:39 AM »
Sorry about that I posted it below along with the sprites I'm using, I'm also working off of Rad version 6.46 as well.

.......

I also forgot to mention W,S,A,D to move, Enter to shoot. I left the Computer car in one spot so you dont have to drive all over shooting at it. As you can see after a few hits the computer car will reset back to where it started which is what I wanted. If you drive in front of the computer car it will still shoot, the problem is when the bullets hit you your car doesn't take any damage, in other words the sprites at the top should change.
« Last Edit: May 13, 2010, 02:04:42 AM by omega »
« Reply #4 on: May 13, 2010, 03:27:20 AM »
Your project is a bit confusing. Rather than spend time trying to figure it out, I'll just give you this project that effectively does what you need and leave you to adapt it to your own game:

« Reply #5 on: May 13, 2010, 10:15:27 AM »
Something like this has been done before, I have attached the files (you can use the ZIP or the RAR, they are identical). I believe it was jestermon who originally uploaded this. The project is compiled using v6.43.

Hope it helps,

StarKiller53861
« Last Edit: February 05, 2011, 01:18:39 PM by StarKiller53861 »
Using 3D Rad v7.10, Windows 7 / Arch Linux, AMD Sempron 2.1GHz, ATI Radeon HD 3200.

Advanced Script Editor for 3D Rad (v3.0.2)
« Reply #6 on: May 13, 2010, 02:51:35 PM »
or you can simplify your entire script and setup to a single animated sprite, and a script to switch frames

the script would be something like
Code: [Select]
void Main()
{
   OUT_XX = IN_0
}
XX being the OUT_ for the current frame number

Currently using 7.22
« Reply #7 on: May 13, 2010, 03:09:32 PM »
bad thing is that VauleLabelBar object bug...
@Fernando: could u fix that up so health/gas/whatever system gets implemented easier?

System Specs: Win7 - Intel Core Duo 1.80GHz - 2gbRAM - 232gb
Molten Games - moltengames.webs.com
« Reply #8 on: May 13, 2010, 03:39:03 PM »
I thought I'd put dart's idea to the test as I'm hoping to make a similar game at some point. Here ya go omega, same as my previous upload but uses your images as an animated sprite to display health. I even added smoke particles and the opponent car stops when defeated!
Just unzip to your 3drad folder, a lot simpler than your original project I'd say...

jestermon

« Reply #9 on: May 13, 2010, 03:58:56 PM »
Ok, Now I get it. I had missed the point of the animated sprite.. (As per Dart's concept)
This shows a need for a few simple object based  gauges that are easy to use..
hmmmm.... I could use this idea for something I am working on, instead of my fully scripted gauges....
Thanks for the enlightenment chebob... and Dart
« Reply #10 on: May 13, 2010, 04:20:45 PM »
How about stretching a single frame sprite, if it was a solid color? Hmm...... ::)
Have a 3DRad problem? There's a topic for that.
(And if there's not, you can always make one.)
My project: http://www.3drad.com/forum/index.php?topic=4337.0
« Reply #11 on: May 13, 2010, 05:37:14 PM »
Thanks for the help everyone, looks like I just went about it the wrong way. Yours works great chebob69, I'm still having the same issue in mine though, the EventOnContact seems to be having a little trouble detecting the collisions between the bullets and the car but I'm going to keep playing with it.  ;D
« Reply #12 on: May 13, 2010, 05:50:55 PM »
Look carefully at how my one worked. You weren't really using eventoncontact correctly.

jestermon

« Reply #13 on: May 13, 2010, 08:16:10 PM »
How about stretching a single frame sprite, if it was a solid color? Hmm...... ::)
Been there, done that
http://www.3drad.com/forum/index.php?topic=1620.msg33456#msg33456
« Reply #14 on: May 14, 2010, 04:15:18 AM »
Oh.  :(
Have a 3DRad problem? There's a topic for that.
(And if there's not, you can always make one.)
My project: http://www.3drad.com/forum/index.php?topic=4337.0
Pages: [1] 2