Shooter

Blitz3D Forums/Blitz3D Programming/Shooter

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.

Does somebody know how to shoot? The sight targets the person and you click to fire.
AppTitle "Internet Game"

SetBuffer BackBuffer()

SeedRnd MilliSecs()

Game = StartNetGame()	

Graphics3D 1024,768,32,1

Global Name$ = Input$("Enter Your Name: ")

id = CreateNetPlayer(Name$)

If Game = 1 Then
	SendNetMsg 1,Name$,id,0,False
EndIf

Cls

Cls

Dim sight(2)

sight(0) = LoadImage("Sight.bmp")
sight(1) = 0

Building = LoadMesh("Building.b3d")

enemy = LoadMesh("Person.3ds")

players = 0

If Building = 0 Then
	RuntimeError "File: 'Building.b3d' Not Found"
EndIf

Collisions 1,2,2,2

Global player = CreatePivot()
PositionEntity player,0,1,0
EntityRadius player,.3
EntityType player,1

Global box = CreateCube()
ResizeMesh(box,1,1,1)

Randomize()		

Global camera = CreateCamera(player)
CameraRange camera,.1,200

Global light = CreateLight()
LightColor light,32,32,32
TurnEntity light,45,-45,0

EntityFX Building,1
EntityType Building,2

sp#=.05
ey#=EntityY(player)

While Not KeyHit(1)
	
	yv#=EntityY(player)-ey
	ey=EntityY(player)
	
	If KeyHit(57) yv=.1

	MoveEntity player,0,yv-.005,0
	
	If KeyHit(31) sight(1) = Not sight(1)
	
	If KeyDown(30) TurnEntity camera,-2,0,0
	If KeyDown(44) TurnEntity camera,+2,0,0
	
	If KeyDown(203) TurnEntity player,0,2,0
	If KeyDown(205) TurnEntity player,0,-2,0
	
	If KeyDown(200) MoveEntity player,0,0,sp
	If KeyDown(208) MoveEntity player,0,0,-sp
	
	Distance = EntityDistance(player,box)
	
	SendNetMsg 2,EntityX(player) + "," + EntityY(player) + "|" + EntityZ(player),id
	RecvNetMsg()
	
	If NetMsgType() = 2 Then
		start = Instr(NetMsgData(),",")
		x = Left(NetMsgData(),start - 1)
		start2 = Instr(NetMsgData(),"|")
		y = Mid(NetMsgData(),start + 1,start2 - 1)
		z = Right(NetMsgData(),Len(NetMsgData()) - start2)
		PositionEntity enemy,x,y,z
	EndIf
		
	CheckMail()
	
	CheckBox()
	
	Locate 0,0
	Print EntityDistance(player,box)
	
	UpdateWorld
	RenderWorld
	If sight(1) = 1 Then
		DrawImage sight(0),MouseX(),MouseY(),0
	EndIf
	Flip
Wend

EndGame()

End

Function ResizeMesh(mesh,width#,height#,depth#)
   
ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth#

End Function

Function CheckBox()

RecvNetMsg()

If NetMsgType() = 99 And Left(NetMsgData$(),3) = "Win" Then
	Cls
	Locate 0,0
	Print "You lost."
	EndGame()
EndIf

If EntityDistance(player,box) < 1 Then
	Cls
	Locate 0,0
	Print "You Won!!!"
	SendNetMsg 99,"Win " + Name$,id,0,0
	EndGame()
EndIf

End Function	

Function EndGame()

FreeEntity Building
FreeEntity box
FreeImage sight(0)

EndGraphics

End

End Function

Function CheckMail()

RecvNetMsg()

If NetMsgType() = 1
	Locate 0,0
	Print NetMsgData() + " has joined"
	Delay 500
	players = players + 1
EndIf

End Function

Function Randomize()

Select Rand(1,6)
	Case 1
		PositionEntity box,-7,0,-7
	Case 2
		PositionEntity box,19,0,-18
	Case 3
		PositionEntity box,18,4,-18
	Case 4
		PositionEntity box,25,-3,-10
	Case 5
		PositionEntity box,5,-2,22
	Case 6
		PositionEntity box,Rand(-8,30),0,Rand(-22,26)
End Select	

End Function