Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Division by Zero/Health Bar  (Read 2822 times)

0 Members and 1 Guest are viewing this topic.

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Division by Zero/Health Bar
« on: April 27, 2020, 11:26:21 PM »

Hi..

I am trying to build a health bar that is based on the number of hit points.  So the hitpoints obviously change and increase through the game.

Variables:
HP=70 'this is the value that increases through the game but reduces in fights
STHP=HP 'this is the value kept when going into the fight before the loop
AP1=RDN(10)+1 ' amount of the attack so reduce hit points in the loop
SBAR=90 ' end of the bar and the value used to reduce hit points.

I have the bar set at 50 pixels. so

Ink 5:Bar 40,140 to 90,142
So as the hitpoints reduce use the second bar to reduce the no of hit points. so

Ink 6: Bar 40,140 to X,142

X being the amount reduced and it works backwards towards 40 as the hitpoints reduce.

I can use a nominal value for x eg;

HP=HP-AP1 ' so for each round your hitpoints reduce

SBAR=90-"The Amount of the Attack"

So here is my problem is that as the bar is only 50 pixels and someone attacks for 5 hit points i could reduce that bar by 5 pixels but that is
really only that is 10% of the bar when the attack is really only 7%.  (5/70)*100

So i can do the maths to work out the percentage, divide by 2 and that would give me a pixel count to reduce based on the 50 pixels in the bar.

What i cannot get to work is the division of (5/7)*100 or (HP/STHP)*100 i just get a zero value.

Hopefully this makes sense...

Any help appreciated

Can post my code if required.

Cheers
 
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Division by Zero/Health Bar
« Reply #1 on: April 27, 2020, 11:42:53 PM »

Integer division is never a fraction.  Try multplying by 100 first, then dividing.  Otherwise you'll have to use floating point division which is typically much slower on Amigas.  (Especially if you don't have an FPU and SET DOUBLE PRECISION at the top of your code to switch to it.)
Logged

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Re: Division by Zero/Health Bar
« Reply #2 on: April 28, 2020, 12:58:17 AM »

Hey.


Thanks for the reply.. .. Will give that a go :) Been a long time since i programmed and it was on a crappy Tandy TRS80.

Turn based so hopefully not too worried about speedy sprites etc.

Thanks again
CM
Logged

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Re: Division by Zero/Health Bar
« Reply #3 on: April 28, 2020, 02:11:45 AM »

Hi.

Sorry to sound thick..

But even if i do

Print "Calc";100*(44/55)

I am still getting zero...

Any suggestions? Too many years using Excel..

Thanks
CM
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Division by Zero/Health Bar
« Reply #4 on: April 28, 2020, 03:03:43 AM »

44/55 is zero in whole numbers.  Try removing the parentheses or putting them around the multiply.
Logged

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Re: Division by Zero/Health Bar
« Reply #5 on: April 28, 2020, 03:40:01 AM »

100*44/55  get 0

(100)*(44/55) get 0

(100*(44/55)) get 0

I did try using fix to set the decimals but you are right that it is division by zero.

Any other tricks on how to create a percentage..

Appreciate your efforts :)
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Division by Zero/Health Bar
« Reply #6 on: April 28, 2020, 03:42:17 AM »

(100 * 44) / 55 should do it.
Logged

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Re: Division by Zero/Health Bar
« Reply #7 on: April 28, 2020, 03:58:08 AM »

Bloody legend.. appreciate your help...
CM
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Division by Zero/Health Bar
« Reply #8 on: April 28, 2020, 04:01:28 AM »

You're welcome!
Logged

supercruiser

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 8
  • Generic Amiga User
Re: Division by Zero/Health Bar
« Reply #9 on: April 28, 2020, 05:42:39 AM »

Thanks again..

Its the small things in life.

Here is a quick youtube of it in action..

https://youtu.be/vQfQDsCEPFc

Cheers
CM[youtube]https://youtu.be/vQfQDsCEPFc[/youtube]
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022