Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Healthcode

Author
Message
Crystal shadow
17
Years of Service
User Offline
Joined: 6th Feb 2008
Location:
Posted: 13th May 2008 21:13 Edited at: 14th May 2008 20:43
My code to create a health system refuses to work. I have used arays, but it still wont work. here are the 4 bits of code that matter







and 2 functions










Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th May 2008 23:40
you haven't explained what you are trying to do so we can't help very much.

what i did notice is you've declared a variable 1t12 that is an illegal name; variable names can't begin with a number.

It is far better to complete a 10 line program than to start a 10,000 line program.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 14th May 2008 01:13
Also, please use the code box, makes the thread so much easier to read, and it puts in indentation in your code (Is you did) making it easier for us to help you.

Crystal shadow
17
Years of Service
User Offline
Joined: 6th Feb 2008
Location:
Posted: 14th May 2008 20:40 Edited at: 14th May 2008 21:12
I must have messed up the code box. dont know why it didnt work, bbut anyways Im gona fix it. I am trying to make it so that at each color the enemy is represents a different ammount of health. At level 2 it is possible to encounter harder enemies with more health, but it is still random. If you shoot a blue one it will turn yellow and at yellow another shot will kill. however no matter what color it is a OHKO despite my efforts

oh and it is DBC
The crazy
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Behind you
Posted: 14th May 2008 23:47
It looks to me like you're resetting the 1t12 variable to one every time. I'm not sure what that variable does but if you're trying to increase it for whatever reason (as in the bit near the bottom that says 1t12=1t12+1) it's just going to go back to 1 when it comes back around in the loop.

Your signature has been erased by a mod because with the text beside the image it's way too long.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th May 2008 00:00 Edited at: 15th May 2008 00:27
i think i understand your method; you want to store the possible colours in the array and reference the array using the enemy's health.

You dont need an array though, a simple formula will churn out the correct colours, and with much finer variance than you could achieve by hard-coding the colours into an array.

So, you want a health indicator that starts off blue and progresses up the spectrum to red as more damage is taken.
The blue and red values are simple to code; blue intensity will change in direct relation to health: blue starts at maximum intensity (255) and degrades as health is lost. red also changes in direct relation to health but in the opposite direction.


It is far better to complete a 10 line program than to start a 10,000 line program.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th May 2008 00:19 Edited at: 15th May 2008 00:21
So there we have the basis of what we want, now the tricky part is putting green into the formula.
Red and blue peak at opposite ends of the spectrum, we now want green to peak in the middle.
The mid-value for a colour is 127 (approx half 255), green will be brightest at this point, distance from the centre in either direction will weaken green's intensity.
Replace the g line in the first snippet with this :


It is far better to complete a 10 line program than to start a 10,000 line program.
Crystal shadow
17
Years of Service
User Offline
Joined: 6th Feb 2008
Location:
Posted: 15th May 2008 20:51
that sounds like it would only work for one enemy. I am creating the enemies correctly, they just are dieing to fast. In case it helps here is my entire code.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th May 2008 00:29
the formula can work with as many enemies as you want. the example just shows that the hp variable can be anything and the formula will output the right colour. would you like me to make it a function for you?

as for the enemies dying too quickly.
i dont have a pc to test your code so it's harder for me, you'll have to talk me through what happens.

Firstly, are there any other bugs in the code?

A good method of debugging is to print all variables to the screen, that way you can spot any strange behaviour.
When you've done that, if you still can't solve it yourself, post the results and i'll see if i can help.

It is far better to complete a 10 line program than to start a 10,000 line program.
Stig Design Stig Magne
19
Years of Service
User Offline
Joined: 23rd Mar 2006
Location: Norway
Posted: 26th May 2008 04:14 Edited at: 26th May 2008 04:14
i maked this code one time



i think my code whas some thing like that
Health Variabel is the Health
and innside the loop it takes a way the Health by 0.5
Try this inside DBC

Stig Design (Free Games,Sources,Textures,Photo`s)
Lisence Free at http://StigDesign.piczo.com

Login to post a reply

Server time is: 2025-06-05 21:20:11
Your offset time is: 2025-06-05 21:20:11