Convert old Blitz3d code

BlitzMax Forums/BlitzMax Beginners Area/Convert old Blitz3d code

How can i convert this code to BlitzMax

Graphics3D 800,600,16,1

Const PLAYER_COL= 3
Const LEVEL_COL = 7
Const ENEMY_COL = 6
Const BULLET_COL= 4
Const BLOOD_COL = 1


Collisions PLAYER_COL,LEVEL_COL,2,3
Collisions PLAYER_COL,ENEMY_COL,2,3
Collisions BULLET_COL,ENEMY_COL,2,1
Collisions BULLET_COL,LEVEL_COL,2,1
Collisions ENEMY_COL,PLAYER_COL,2,3
Collisions ENEMY_COL,ENEMY_COL,2,3
Collisions ENEMY_COL,LEVEL_COL,2,3
Collisions BLOOD_COL,LEVEL_COL,2,1


Type player
	Field x#,y#,z#
	Field ang#,speed#
	Field cam,cam_mode
	Field moving
	Field health
End Type

Type bullet
	Field x#,y#,z#
	Field ang#,speed#
	Field life#
	Field entity
End Type

Type enemy
	Field enx#,eny#,enz#
	Field life
	Field img
	Field hp
	Field state
	Field m_time
	Field dir
	Field speed
	Field hloc_x,hloc_z
End Type

Type blood
	Field entity,alpha#,y_speed#,stuck
End Type

Global blood_intensity=30	
Global clickedx#,clickedz#
Global p.player=New player
Global playerheight=6
Global enemyheight=-2
Global fired=0
Global bspeed=20
p\health=100
Global ow=LoadSound("ow.wav")							; "OW" sound
Global gunshot=LoadSound("shot.wav")					; gunfire sound

HidePointer

;game FPS
Const FPS=60

light=CreateLight()
TurnEntity light,90,0,0

Global blood=LoadSprite("blood.bmp",3)
EntityRadius blood,1
EntityType blood,BLOOD_COL
HideEntity blood

Global squish=LoadSound("squish.wav")

Global pbullet = CreateSphere()
;Global pbullet = LoadSprite("bigspark.bmp",3)
;ScaleSprite pbullet,5,5
ScaleEntity pbullet,.5,.5,.5
EntityColor pbullet,255,0,0
EntityShininess pbullet,1
EntityRadius pbullet,2,2
EntityType pbullet,BULLET_COL
;EntityFX pbullet,1
;EntityBlend pbullet,3
HideEntity pbullet


Global mousepointer=LoadImage("GFX\pointer.bmp")

Global cubepiv=CreatePivot()
Global cube=CreateSphere(16,cubepiv)
EntityRadius cube,3,3
ScaleEntity cube,3,3,3
EntityType cube,PLAYER_COL
EntityColor cube,50,200,50
PositionEntity cube,Rand(700),playerheight,Rand(500)
ResetEntity cube
EntityShininess cube,1
EntityPickMode cube,2,1

Global block=CreateCube()
ScaleEntity block,10,10,10
PositionEntity block,200,-28,200
	
	
Global campiv=CreatePivot()
p\cam=CreateCamera(campiv)
CameraRange p\cam,.1,1600
RotateEntity p\cam,90,0,0
EntityType p\cam,3

Global mapcam=CreateCamera( campiv )
CameraViewport mapcam,681,481,118,118

TurnEntity mapcam,0,180,0
EntityOrder mapcam,-1
PointEntity mapcam,cubepiv


city=LoadMesh("level.b3d")
PositionEntity city,0,-30,0
ScaleEntity city,.1,.1,.1
EntityType city,LEVEL_COL,1
EntityPickMode city,2,1

Global nme = 15
;Global enpiv=CreatePivot()

;CameraViewport p\cam,0,0,799,480

;Global cone=CreateCone(16,1)
;	RotateMesh cone,-90,0,0
;	PositionMesh cone,0,0,1
;	ScaleMesh cone,2,2,2
;	EntityColor cone,128,128,0
;	EntityAlpha cone,0.4

;enemy gfx-----------
For i=1 To nme

	en.enemy=New enemy
	enpiv=CreatePivot()
	en\enx=Rand(700)
	en\enz=Rand(700)
	en\img=CreateSphere(8)
	en\hp=100
	en\state=0
	en\speed=0
	en\dir=9
	en\hloc_x = 200
    en\hloc_z = 200
	ScaleEntity en\img,3,3,3
	EntityColor en\img,255,50,50
	EntityType en\img,ENEMY_COL
	EntityRadius en\img,3,3
	EntityShininess en\img,1
	PositionEntity en\img,en\enx,en\eny,en\enz
	EntityPickMode en\img,2,1
	
Next

;--------------------

SetBuffer BackBuffer()

AppTitle "FODDA-3D"
 	
While Not KeyHit(1)

period=1000/FPS
time=MilliSecs()-period

	Repeat
		elapsed=MilliSecs()-time
	Until elapsed

	;how many 'frames' have elapsed	
	ticks=elapsed/period
	
	;fractional remainder
	tween#=Float(elapsed Mod period)/Float(period)
	
	For k=1 To ticks
		If k=ticks Then CaptureWorld
		time=time+period
		
		UpdateWorld
	Next
	
				
		EntityParent p\cam,0
		PositionEntity p\cam,EntityX(cube),EntityY(cube),EntityZ(cube)
		TranslateEntity p\cam,0,200,-150
		PointEntity p\cam,cube,0
	
		CameraPick (p\cam,MouseX(),MouseY())
		PositionEntity campiv,PickedX(),PickedY()+1,PickedZ()
		TranslateEntity cube,0,-.6,0
		
		EntityParent mapcam,0
		PositionEntity mapcam,EntityX(cube),EntityY(cube),EntityZ(cube)
		TranslateEntity mapcam,0,250,0
		PointEntity mapcam,cube,0
		
			MovePlayer()
			
			MoveNME()

			MakeBullet()
			
			SpurtBlood()
	
;Zoom in / out	
	Select MouseZSpeed()
	
	Case 1
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
		
		zoom#=zoom#+1
			
	Case -1
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
		zoom#=zoom#-1
		
	End Select 

	If zoom#<1 Then zoom#=1 
	If zoom#>5 Then zoom#=5
	CameraZoom p\cam,zoom#	

If KeyHit(25)
	FlushKeys			
	While Not KeyHit (25)
		
		Text 400,300,"--PAUSED--",True,True
		Flip
		Delay 50
	Wend
EndIf
;MoveEntity cube,p\x,p\y,p\z+p\speed		
UpdateWorld
RenderWorld tween

For b.bullet = Each bullet				;iterate through all of the bullets
    If CountCollisions(b\entity) > 0		;check if bullet collided with something
      enemyhit = EntityCollided(b\entity,ENEMY_COL)	;note which enemy bullet collided with (if any)
      If enemyhit > 0 Then KillNME(enemyhit)			;enemyhit contains entity handle of enemy that was hit
      FreeEntity b\entity			;delete the bullet mesh
      Delete b.bullet
							;delete the bullet
    EndIf
Next

Rect 680,480,119,119,0

DrawImage mousepointer,MouseX(),MouseY()
Color 255,255,255
Text 0,0,"Enemy = "+nme


If EntityCollided(cube,ENEMY_COL)
	
	p\health#=p\health#-1
		
End If

If p\health=>100
	p\health=100
EndIf

If p\health<1
	p\health=0
EndIf	

Text 15,535,"Health "+p\health+"%"
Color 255,0,0
Rect 10,550,p\health,20,1
Color 0,255,0
Rect 10,550,101,20,0

Flip 

Wend

End

Function MovePlayer()

	If MouseDown(1)=True

		clickedx=PickedX()
		clickedz=PickedZ()
		p\speed=1
		
		p\ang=ATan2(p\x-clickedx,p\z-clickedz)
		p\ang=(360+(ATan2(clickedx-p\x,clickedz-p\z)))

		PositionEntity cubepiv,p\x,p\y,p\z
		
		MoveEntity cube,p\x,p\y,p\z+p\speed
		
		PointEntity cube,campiv
		RotateEntity cube,0,EntityYaw(cube),0
		
	EndIf
	
	If MouseDown(1) = False

		p\speed=0
		
	End If	

			
End Function

Function MakeBullet()

		fired=fired-1
		If fired<0 Then fired=0
		If MouseDown(2) And fired=0
		b.bullet = New bullet ;Create bullet
		b\entity = CopyEntity(pbullet,cube)
		EntityParent b\entity,0
		b\life=60
		b\speed=2
		b\entity=b\entity
		PointEntity b\entity,campiv
		EntityColor b\entity,100,100,100
		PositionEntity b\entity,EntityX(cube),EntityY(cube)+1,EntityZ(cube)
		fired=bspeed
		PlaySound(gunshot)
		End If

		;MoveBullet
		For b.bullet = Each bullet		
		MoveEntity b\entity,0,0,b\z+b\speed
		b\life=b\life-1
			
		If EntityCollided(b\entity,LEVEL_COL)
		FreeEntity b\entity			;delete the bullet mesh
    	  Delete b.bullet
		EndIf
			
		If b\life=0 ;Then Delete b.bullet
		FreeEntity b\entity
		Delete b 
		End If
		Next	


End Function

Function KillNME(enemyhit)

  		For en.enemy = Each enemy		;iterate through all of the badguys
   		If enemyhit = en\img		;check if the enemy hit = this badguy		
		
		nme = nme-1		
   
       	EntityType en\img, 0	;turn off collisions for this badguy
      		
		; New blood drops
		For i=1 To blood_intensity
		bl.blood=New blood
		bl\y_speed=0
		bl\alpha=5
		bl\entity=CopyEntity(blood)
		
		PositionEntity  bl\entity,EntityX(en\img),EntityY(en\img),EntityZ(en\img)
		
		ResetEntity bl\entity
		scale_randx#=Rnd(1,2)
		scale_randy#=scale_randx#+Rnd(.1,.5)
		ScaleSprite bl\entity,scale_randx#,scale_randy#
		RotateEntity bl\entity,Rnd(360),Rnd(360),Rnd(360)
		
		PlaySound(squish)
		
		Next	
			
		FreeEntity en\img
		Delete en.enemy
        Exit					;exits the badguy For-Next loop (no need to check rest of badguys)
      	EndIf
 
  		Next
End Function

Function MoveNME()

		For en.enemy=Each enemy
		
		If en\m_time = 0 
        en\dir = Rand(0,9) 
        en\m_time = Rand(10,1000)
        End If  

		Select(en\state)
		
		Case 0 


				If EntityDistance(cube,en\img)<80 
				EntityColor en\img,0,0,255
				PointEntity en\img,cube
				MoveEntity en\img,0,0,en\speed+.6
				End If
				
				If EntityDistance(en\img,cube)>100
				EntityColor en\img,255,50,50
				End If
		Case 1


								
		End Select
		
		Select (en\dir)
       
        Case 0
				;up
				RotateEntity en\img,0,0,0
						
        Case 1	
				;down
				RotateEntity en\img,0,180,0
				
        Case 2	;right
				RotateEntity en\img,0,270,0
				
        Case 3
				;left
				RotateEntity en\img,0,90,0
				
		Case 4
				;up-right
				RotateEntity en\img,0,315,0
				
		Case 5
				;down-right
				RotateEntity en\img,0,225,0
		
		Case 6
				;up-left
				RotateEntity en\img,0,45,0
		
		Case 7
				;down-left
				RotateEntity en\img,0,135,0
				
		Case 8

        End Select

		en\m_time=en\m_time-1
		MoveEntity en\img,0,0,en\speed+.2
		TranslateEntity en\img,0,-1,0
		
		
		Next

End Function

; --------------------
; Fresh blood function
; --------------------


Function SpurtBlood()

	; For each drop of blood...
	For bl.blood=Each blood
	

		; Update blood drops
		If bl\alpha>0
			EntityAlpha bl\entity,bl\alpha
			If bl\stuck<>True Then MoveEntity bl\entity,0,1.5,0
			If bl\stuck<>True Then TranslateEntity bl\entity,0,bl\y_speed,0
			If bl\stuck<>True Then bl\alpha=bl\alpha-0.01
			bl\y_speed=bl\y_speed-.1
		Else
			FreeEntity bl\entity
			Delete bl
		EndIf
		
	Next

End Function


Can any body help with this


Thanks

I belong to the group o'ppl who'd say "do a clean rewrite in BMax", note that I'm not into 3d, so I don't know how well the 3d would transport to BMax and some 3d lib I don't know about.

By installing MiniB3D then fiddling about a bit.

I.e.

The backslash for type field references isn't used in max - use a '.'.
; is a line separator in blitzmax, remarks use an apostrophe.

Ill be using the above code with LeadWerks engine if i can convert it to max first.


Thanks

Reading this will do miracles.

You cannot convert your code totally into blitzmax "first", since stuff like createSphere & 3rd dimension don't automatically exist in Bmax.

I'd suggest reading carefully that above guide, then reading this guide and then using bmax + leadwerks framework together... and simply changing the necessary commands. There's no much other way around.

Sorry if this comes "bit" late :)