Community Project - Alien Breed game

Miscellaneous Forums/Blitz Showcase/Community Project - Alien Breed game

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ok, I've added a hud that looks like AB 1's. Here's the code for hud.bb:
You can get the hud image from here:

I've hardedcoded all the coords for drawing to 640x480, but could change it if you wanted to change res at a later date.
; simple hud
Global hud_block,hud_background,lives_block


Function setupHUD()
	hud_background=LoadImage("gfx\hud.png")
	; create block images on the fly
	hud_block=CreateImage(4,16)
	SetBuffer ImageBuffer(hud_block)
	Color 96,24,0 : Rect 0,0,4,2 : Rect 0,14,4,2
	Color 144,40,0: Rect 0,2,4,2 : Rect 0,12,4,2
	Color 180,84,0: Rect 0,4,4,2 : Rect 0,10,4,2
	Color 216,140,0:Rect 0,6,4,4
	SetBuffer BackBuffer()	

	; this'll have a green hue
	lives_block=CreateImage(4,16)
	SetBuffer ImageBuffer(lives_block)
	Color 0,96,24 : Rect 0,0,4,2 : Rect 0,14,4,2
	Color 0,144,40: Rect 0,2,4,2 : Rect 0,12,4,2
	Color 0,180,84: Rect 0,4,4,2 : Rect 0,10,4,2
	Color 0,216,140:Rect 0,6,4,4
	SetBuffer BackBuffer()	
End Function

Function drawHUD()
	vy=GraphicsHeight()-40

	; no transparency
	DrawBlock hud_background,0,vy
	
	; draw player lives, ammo and health
	For p.player=Each player
		;lives 
		If p=First player Then x=248 Else x=569
		y=0
		For i=1 To p\lives
			DrawBlock lives_block,x+(i*6),vy+y
		Next
	
		; health
		If p=First player Then x=62 Else x=382
		y=2
		For i=1 To p\health Step 3
			DrawBlock hud_block,x+((i/3)*4),vy+y
		Next		

		; clips
		If p=First player Then x=62 Else x=382
		y=24
		For i=1 To p\clip
			DrawBlock hud_block,(x+(i*5)),vy+y
		Next
		If p\clip > 5		
			Color 255,255,255
			; indicate we've got more than 5 clips with a plus '+'
			If p = First player Then Text 50,vy+16,"+" Else Text 211,vy+16,"+"
		EndIf

		; ammo
		If p=First player Then x=114 Else x=432
		y=24
		
		ammo=p\ammo
		clipSize=p\weapon\ammo_in_a_clip
		width#=(65/6)
		k#=(width/clipSize)*ammo
		
		For i=1 To k
			DrawBlock hud_block,x+(i*6),vy+y
		Next

		; keys
		y=18
		j1=0 : j2=0 ; count variables
		
		For pu.pickedup = Each pickedup			
			ok=True
			Select objectName(pu\obj)
				Case "Generic Key"	:frame=2
				Case "Red Key"		:frame=3
				Case "Green Key"	:frame=4
				Case "Blue Key"		:frame=5
				Default:			ok=False
			End Select
			; if ok=false then we're attempting to draw 
			; a pickedup object that isn't a key.
			; we only want to draw objects that are given
			; the ok by the above select.
			If ok
				If pu\player=1
					j1=j1+1
					Viewport 250,vy+y,55,20
					DrawImage Objects,(240+(10*j1)),vy+y,frame
					Viewport 0,0,GraphicsWidth(),GraphicsHeight()
				EndIf
				If pu\player=2
					j2=j2+1
					Viewport 570,vy+y,55,20
					DrawImage Objects,560+(10*j2),vy+y,frame
					Viewport 0,0,GraphicsWidth(),GraphicsHeight()
				EndIf
			EndIf					
		Next
	Next
	
End Function



Call setupHUD() to create/load images, etc.
and
drawHUD() instead of the bit at the end of the draw loop that draws the ammo and stuff.

I've added a "lives" field to the player and set it to 5 when the player is created in Player_Create.player(Name$,X%,Y%,id%)

I'm not sure about displaying the keys. See what you think by adding this piece of code:
; uncomment for a test of the player key HUD
If False
	; give the player five keys to test GUI.
	For u=3 To 5
		p.pickedup=New pickedup
		p\obj=u
		p\player=1
	Next
	p.pickedup=New pickedup
	p\obj=3
	p\player=1
	p.pickedup=New pickedup
	p\obj=3
	p\player=1	
EndIf

after
Type pickedup
	Field player
	Field obj
End Type
that bit.