CP - Alen Breed Remake - 6

Miscellaneous Forums/Blitz Showcase/CP - Alen Breed Remake - 6

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.

- TileTimers only repeat 5 times. You can change this by altering the function runOnLoadScripts() in script.bb
- Players are loaded via the "kind$" param at the end of the player_create function. This gives them classes
- Players are given certain weapons they can carry using flags. So a player with 1+2+4 can carry the first three weapons. A player with 1+32 can carry the lightest and heaviest weapon. These are set in the player_create function.



Here're the updates:

engine.bb (The player_Create has a new param)
btext 40,200,"Creating player/s...":Flip
;Player Initialization - name, x, y, id
Player_Create.player("player2",player_one_start_x,player_one_start_y,1,"light")
;Player_Create.player("player3",player_two_start_x,player_two_start_y,2)

players.bb
; add this to the player type:
Field weaponsAllowed ; flags 1,2,4,8,16,32

; new function
Function allowPlayerToHaveTheseWeapons(p.player,weapons=32) ; 32=all
	If p = Null Then Return
	p\weaponsAllowed =weapons
End Function

;update:
Function Player_Create.player(Name$,X%,Y%,id%,kind$="light")
	Local pl.player = New player
	
	pl\name = Name$
	
	Select Lower(kind)
		Case "light":
			filename$="gfx/player1.png"			
			allowPlayerToHaveTheseWeapons(pl,1+2+4) ; all weapons
			speed#=1.5
			
		Case "medium"
			filename$="gfx/player2.png"
			allowPlayerToHaveTheseWeapons(pl,4+8+16) ; all weapons
			speed#=1.0
			
		Case "heavy"
			filename$="gfx/player2.png"
			allowPlayerToHaveTheseWeapons(pl,8+16+32) ; all weapons
			speed#=0.7			
	End Select	
	
	playergfx(id) = LoadAnimImage(filename,64,64,0,128) : MaskImage playergfx(id),255,0,255
	pl\x = X
	pl\y = Y
	pl\frame = 0
	pl\health = 100
	pl\fpause = 0
	pl\dir = 0
	pl\id = id
	;Ammo stuff
	pl\Clip = 2
	pl\ammo = 15
	pl\lives = 5
	pl\speed=speed
	
	CheckVis(Floor(pl\x/32),Floor(pl\y/32))	
	
	Player(id)=pl
	Return pl
End Function

script.bb
;update:
Type tileTimer
	Field x,y ; map coords to run
	Field time ; in seconds
	Field milli,loops,l
End Type

Function tileTimer(x,y,time,loops=5)
	t.tileTimer=New tileTimer
	t\x=x : t\y=y : t\time=time
	t\milli=MilliSecs()
	t\loops=loops
End Function

;update:
Function handleScriptRunning()
	For i.tileTimer=Each tileTimer
		dcircle(i\x*32,i\y*32,32,255,0,0)
		dtext(i\x*32,i\y*32,i\l+"/"+i\loops)	
		If MilliSecs()-i\milli > (i\time*1000) ; convert to milliseconds (*1000)			
			; do it.
			tile=map(i\x,i\y,LayerObject)
			If tile > 0
				RunScript(First player,objectdef(tile),"onevery",i\x*32,i\y*32); not specific.
				i\milli=MilliSecs() ; reset
				For j=0 To 5
					; if we've got a remove(me) in the script somewhere then delete this
					; tileTimer and stop it from repeating
					; sort of defeats the point of onEvery, but hey...
					If Instr(objectdef(tile)\script[j],"remove")
						Delete i
						Exit
					EndIf
				Next										
			EndIf
			i\l=i\l+1
			If i\l=i\loops				
				puttile(i\x,i\y,LayerObject,0) ; clear object at this location
				Delete i
			EndIf
		EndIf
	Next
End Function

;update:
Function runOnLoadScripts()
	; this is only run once when the map is loaded.
	; it's kept out of map.bb for script compatability reasons.
	For i=0 To 255-1
		For j=0 To 255-1
			tile=map(i,j,LayerObject)
			If tile>0				
				If Instr(objectdef(tile)\trigger,"onload")								
					; run on first player
					;DebugLog "OnLoad running script '"+objectdef(tile)\name+"'"
					RunScript(First player,objectdef(tile),"onload",i*32,j*32); not specific.
				
				ElseIf Instr(objectdef(tile)\trigger,"onevery")
					p=Instr(Lower(objectdef(tile)\trigger),"onevery")
					time=Mid(objectdef(tile)\trigger,p+8,Instr(objectdef(tile)\trigger,")",p+8)-1)					
					tileTimer(i,j,time+Rand(-1,2),5)	; plus add a bit of randomness to the times
					;DebugLog "tile timer created at "+i+","+j+". Duration: "+time+" seconds."
				EndIf
			EndIf
		Next
	Next
End Function

;update:
Function RunScript(pl.player,obj.objdef,trigger$,x,y)
	p=Instr(obj\trigger,trigger)
	n=CountString(Left(obj\trigger,p),"|")
	si.scriptitem=ParseScript(obj\script[n])
	While si<>Null
		Select si\command
			Case "intex"
				IntexMenu(pl):time=MilliSecs()-period
			
			Case "positionplayer"		
				; here we set some global vars ready for when we're created. see engine.bb
				If Int(si\param)=1
					player_one_start_x=x
					player_one_start_y=y
				ElseIf Int(si\param)=2
					player_two_start_x=x
					player_two_start_y=y				
				EndIf				
		
		
			Case "pickupweapon"								
				wee=Int(si\param)
				If wee Then ok=True
				Select wee
					Case 1:
						If (pl\weaponsAllowed And 1)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponBroadhurst))
						Else
							ok=False	
						EndIf
					Case 2:
						If (pl\weaponsAllowed And 2)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponDalton)) 
						Else 
							ok=False
						EndIf
					Case 3:
						If (pl\weaponsAllowed And 4)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponRobinson)) 
						Else 
							ok=False
						EndIf
					Case 4:
						If (pl\weaponsAllowed And 8)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponRyxx)) 
						Else 
							ok=False
						EndIf
					Case 5:
						If (pl\weaponsAllowed And 16)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponStyrling)) 
						Else
							ok=False
						EndIf
					Case 6:
						If (pl\weaponsAllowed And 32)
							giveWeaponToPlayer(pl,getWeaponFromName(weaponImpact)) 
						Else 
							ok=False
						EndIf
				End Select
	
				If ok=False Then 
					; can't pick it up
					DebugLog "can't pick up weapon "+wee
					ClearScriptFrom(si)					
				EndIf

			Case "createalien"				
				Select si\param
					Case "alien":SpawnAlien(x,y,-1,STANDARD_ALIEN)
					Case "hugger":SpawnAlien(x,y,-1,FACE_HUGGER_ALIEN)
				End Select
						
			Case "addammo"
				givePlayerAmmo(pl,Int(si\param$))

			Case "opendoor"
				opendoor(Floor(x/32),Floor(y/32))
				;Update counter for player status
				pl\doors = pl\doors + 1

			Case "checkkey"
			   	If Not keycheck(pl\id,Int(si\param)+2) Then ClearScriptFrom(si):Return

			Case "addkey"
				Pv.pickedup = New pickedup
				Pv\player = pl\id ; allowing for multiple players
				Pv\obj=Int(si\param)+2				

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

			Case "addhealth"				
				pv.pickedup = New pickedup
				pv\player = pl\id ; allowing for multiple players
				pv\obj = 2

			Case "playsoundonce"
				Select si\param
					Case "health_pickup":playoneshot(health_pickup,x,y)
					Case "key_pickup":playoneshot(key_pickup,x,y)
				End Select

			Case "remove"
				If si\param="me" Then puttile(x,y,LayerObject,0)
				If si\param="collision" Then puttile(x,y,LayerCollision,0)
				
			Case "explode"
				explode(x,y)
				
				

			Default:RuntimeError "Unrecognised command : "+si\command

		End Select
		nsi.scriptitem=After si
		Delete si
		si=nsi
	Wend

End Function

Also, I wrote a help file for the editor a while ago. You can find it here: www.3030deathwar.co.uk/downloads/ab/editor.txt

I think that's everything. it's getting a little hard to update as there are bits here and bits there to be changed. I'll be back with more in a few minutes.