CP - Alien Breed Remake - 7

Miscellaneous Forums/Blitz Showcase/CP - Alien Breed Remake - 7

player.bb->keyCheck()
Function keycheck(player,keyid%)
	For p.pickedup = Each pickedup
		If p\player\id = player And p\obj =keyid Then Delete p:Return True
	Next
	Return False
End Function

Remove the pickedUp type from the util.bb include
If you run it, you'll be prompted to change something in the script.bb file. This is:
			Case "checkkey"
			   	If Not keycheck(pl\id,Int(si\param)+2) Then ClearScriptFrom(si):Return

			Case "addkey"
				InvItem_Create(Int(si\param)+2,0,pl,objects,1)			

			Case "addcredit" ; TODO: Credits! (done!)
				givePlayerCredits(pl\id,Int(si\param))

The "InvItem_Create(Int(si\param)+2,0,pl,objects,1)" function adds an object to your inventory. You can specify the weight and obj number as well as the image and frame to use to draw it in the inventory.

Which just changes the pv\player. Instead of just passing the player ID (which we don't really need), we pass the actual object.

I've added these fields to the player type:
	Field itemsCarrying,maxWeight,weight
	Field inv.pickedup[20]
	Field showingInv,over,overWait

Add this to the engine.bb->draw() function, wherever you want:
drawBothInventories()

I've temporarily added this to the engine.bb->loop function to open the inventory for player one on a toggle:
If KeyHit(57) Then showInventory(First player)

Use this to set the player weights on the player creation:
setPlayerInvLevels(p.player,maxWeight)

If you don't want to use the weight feature, make everything you pick up weigh 0.
here's a revised inventory.bb:
; inventory
Const INVITEM_WIDTH = 70

Type pickedup
	Field player.player
	Field obj,weight
	Field x,y,image,imageFrame	
End Type


Function useInventoryItem(p.player,i.pickedup)
End Function


Function InvItem_Create(obj,weight,p.player,image,frame)
	i.pickedup=New pickedup
	i\obj=obj
	i\weight=weight	
	i\image=image
	i\imageFrame=frame
	addInvItem(p,i)		
End Function

Function setPlayerInvLevels(p.player,maxWeight)
	p\maxWeight=maxWeight
	p\weight=0
	p\itemsCarrying=0	
	p\showingInv=0
	p\overWait=MilliSecs()
End Function

Function showInventory(p.player)
	p\showingInv=1-p\showingInv
End Function

Function UpdateInventories(p.player)
	; this handles the controls
	If p=First player
		max=(GraphicsWidth()/2)-10
	Else
		max=(GraphicsWidth())
	EndIf
	
	If (MilliSecs()-p\overWait) > 200
		If control(pright,p\id)
			p\over=p\over+1
			p\overWait=MilliSecs()
			
		ElseIf control(pleft,p\id)
			p\over=p\over-1
			p\overWait=MilliSecs()
		EndIf	
	EndIf
	If p\over<0 Then p\over=p\itemsCarrying-1
	If p\over>p\itemsCarrying-1 Then p\over=0
End Function

Function addInvItem(p.player,item.pickedup)
	If p=Null Then Return
	
	If item= Null Then
		DebugLog "Inv Item is NULL"
		Return		
	EndIf
	
	If p\weight+item\weight <= p\maxWeight
		; pickup
		item\player=p
		p\inv[p\itemsCarrying]=item
		p\weight=p\weight+item\weight
		p\itemsCarrying=p\itemsCarrying+1
		refreshInvItems()	
	Else
		DebugLog "Cannot pick up "+item\obj+". It's too heavy"
		Return
	EndIf	
End Function

Function refreshInvItems()

	For p.player=Each player
		If p = First player
			min=5
			x=min
			max=(GraphicsWidth()/2)-10
		Else
			min=(GraphicsWidth()/2)+10
			x=min
			max=(GraphicsWidth())
		EndIf
	
		y=10
		If p\itemsCarrying>0
			For i=0 To p\itemsCarrying-1
				inv.pickedup=p\inv[i]
				If inv<>Null								
					If x > max-INVITEM_WIDTH
						x=min
						y=y+INVITEM_WIDTH
					EndIf
					inv\x=x
					inv\y=y	
					x=x+INVITEM_WIDTH
				EndIf
			Next
		EndIf
	Next
End Function

Function drawInvItems(p.player)
	If p\showingInv=0 Then Return
	
	If p=First player
		max=(GraphicsWidth()/2)-10
		; player one
		Color 150,150,150:Rect 0,0,max,GraphicsHeight()
		Color 200,200,200:Rect max,0,1,GraphicsHeight()
		;btext 10,GraphicsHeight()-10,p\weight+" / "+p\maxWeight
	Else
		max=(GraphicsWidth()/2)-10
		Color 150,150,150:Rect max,0,GraphicsWidth()/2,GraphicsHeight()
		Color 200,200,200:Rect max,0,GraphicsWidth()/2,GraphicsHeight()
		;btext (GraphicsWidth()/2)+10,GraphicsHeight()-10,p\weight+" / "+p\maxWeight
	EndIf

	If p\itemsCarrying>0
		For i=0 To p\itemsCarrying-1
			inv.pickedup=p\inv[i]
			If inv<>Null
				If inv\image<>0
					DrawImage inv\image,inv\x,inv\y,inv\imageFrame
				EndIf
				Color 255,255,255
				Rect inv\x,inv\y,INVITEM_WIDTH,INVITEM_WIDTH,0
				Color 0,0,0
				;bText inv\x+INVITEM_WIDTH/2,inv\y+INVITEM_WIDTH/2,inv\obj,1,1
				If i=p\over
					Color 255,0,0
					Rect inv\x,inv\y,INVITEM_WIDTH,INVITEM_WIDTH,0
				EndIf
			EndIf
		Next
	EndIf	
End Function

Function drawBothInventories()
	drawInvItems(First player)
	drawInvItems(Last player)
End Function

Hope you can get it working. I'll get to work on the hud. I've got very very very very little spare time, but I'm hoping to get something done. I'm not ignoring this project, guys.