Ooops
January 26, 2021, 05:00:03 AM

Author Topic: [bb] B3D 'Zelda' Hearts by _PJ_ [ 1+ years ago ]  (Read 429 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] B3D 'Zelda' Hearts by _PJ_ [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : B3D 'Zelda' Hearts
Author : _PJ_
Posted : 1+ years ago

Description : Although I never played the Zelda games (I know, I missed out :( ) The cncept of 'lives' and Health etc. being shown as hearts which deplete partially is quite common.

The actual images here are not great, but I wanted something quick and functional.

There are constants at the top for resolution, and number of hearts as well as te health they should represent.
Note that having a large heart size and/or too many max hearts as well as small graphics width will of course lead to hearts being drawn off-screen...


Code :
Code: BlitzBasic
  1. Const Gwidth=800
  2. Const Gheight=600
  3.  
  4. Const MaxHearts%=5
  5. Const MaxHealth%=100
  6. Const HeartSize=48
  7. Const HealthDivs=MaxHealth/MaxHearts
  8.  
  9. Graphics Gwidth,Gheight
  10.  
  11. Global HeartImage%=CreateHeartImage%(HeartSize)
  12. MidHandle HeartImage
  13. Global Health%=MaxHealth
  14.  
  15. Function RenderHearts()
  16.         Local x,y,img,rx,ry,angle,count
  17.         For count=1 To Health/MaxHealth*MaxHearts
  18.                 y=Gheight-(HeartSize)
  19.        
  20.                 x=((count-1)*(HeartSize))+(Gwidth/80)+(HeartSize Shr True)
  21.                
  22.                 ;set the background for hearts
  23.                 Colour(8396832)
  24.                 Rect x-HeartSize Shr True,y-HeartSize Shr True,HeartSize,HeartSize,True
  25.                
  26.                 ;Shade the heart according to health remaining
  27.                 angle=(((HeartHealth(count))/HealthDivs )*360) Mod 360
  28.                
  29.                 rx=x+(HeartSize Shr True)*(Sin(angle))
  30.                 ry=y+(HeartSize Shr True)*(Cos(angle))
  31.                
  32.                 Colour(8392894)
  33.                
  34.                 Line x-1,y-1,rx,ry
  35.                 Line x+1,y-1,rx,ry
  36.                 Line x,y-1,rx,ry
  37.                 Line x+1,y,rx,ry
  38.                 Line x+1,y+1,rx,ry
  39.                
  40.                 ;overlay with a heart template
  41.                 DrawImage HeartImage,x,y
  42.         Next
  43. End Function
  44.  
  45. Function HeartHealth(Heart)
  46.         Local fFract#=(MaxHealth/HealthDivs)
  47.         fFract=fFract-(MaxHearts-Heart)
  48.         Return fFract*HealthDivs
  49. End Function
  50.        
  51. Function Colour(Col,ClsCol=False)
  52.         If ClsCol
  53.                 ClsColor(Col Shr 16) And 255,(Col Shr 8) And 255,Col And 255
  54.         Else
  55.                 Color (Col Shr 16) And 255,(Col Shr 8) And 255,Col And 255
  56.         End If
  57. End Function
  58.  
  59. Function CreateHeartImage%(SmallSize)
  60.         Local img=CreateImage(SmallSize,SmallSize)
  61.         SetBuffer ImageBuffer(img)
  62.         Colour(16777215,False)
  63.         Colour(False,True)
  64.         Oval SmallSize Shr 2, SmallSize  Shr 2,SmallSize Shr True, SmallSize - (SmallSize Shr 2),True
  65.         Oval SmallSize Shr 2, SmallSize  Shr 2,SmallSize - (SmallSize Shr 2), SmallSize Shr True,True
  66.         SetBuffer BackBuffer()
  67.         RotateImage img,225
  68.         MaskImage img,255,255,255
  69.         Return img
  70. End Function
  71.  
  72. While Not KeyDown(1)
  73.         RenderHearts()
  74.         Flip
  75. Wend


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal