rob cummings fps shell

Blitz3D Forums/Blitz3D Beginners Area/rob cummings fps shell

Hi guy's im pretty noobie when it comes to coding, i have been using rob cummings fps shell code to mess around with making a basic FPS game/engine. Anyway i've been trying to add a water splash sprite for when the bullet hits a cube with a water texture, but it doesn't seem to be working. No bullet holes spawn on the floor below and no water sprite is seen on the top of the cube of water, so im just wondering what i've done wrong.

Heres the code:

;framerate variables
Const FPS=70
Const debug=0

;collision variables
Global col_level=1,col_player=2,col_bullet=3 col_water=4

;other vars
Global firetex,firetexpos#,bob#,target,holesprite,plasmasprite,shockwavesprite,recoil#,watersprite

Global cameraheight#=3.5	;height of player eyes
Global playerheight#=5		;height of collision sphere
Global playerradius#=2.5	;radius of collision sphere

;types
Type plasma
	Field ent,rot#
End Type

Type scorch
	Field ent,life#
End Type

Type shockwave
	Field ent,life#,size#
End Type

Type water
	Field ent,life#
End Type

Type plasmawater
	Field ent,rot#
End Type

;display
AppTitle "FPS Engine Alpha"
Text 20,2,"Choose mode by pressing a number key:"
Text 20,32,"(1) 800,600   windowed  "
Text 20,48,"(2) 1024,800  fullscreen"
Text 20,64,"(3) 1280,1024 fullscreen"
Text 20,80,"(4) 1600,1200 fullscreen"
Repeat
	If KeyDown(2) Or debug Then xres=800:yres=600:mode=2:Exit
	If KeyDown(3) Then xres=1024:yres=800:mode=1:Exit
	If KeyDown(4) Then xres=1280:yres=1024:mode=1:Exit
	If KeyDown(5) Then xres=1600:yres=1200:mode=1:Exit
	VWait
Forever
Graphics3D xres,yres,0,mode
HidePointer

;setup
camera=CreateCamera()
CameraRange camera,0.2,400
CameraFogMode camera,1
CameraFogColor camera,140,140,120
CameraFogRange camera,-100,800

;music
sndMusic=LoadSound("media/music.mp3")
;loop
LoopSound sndMusic
PlaySound sndMusic

;gun sound
sndgunshot=LoadSound("media/gunshot.wav") 

;hud
tex=LoadTexture("media/target.png",2)
TextureBlend tex,2
target=CreateSprite()
EntityTexture target,tex
EntityFX target,1
EntityOrder target,-1
EntityBlend target,3
EntityParent target,camera
MoveEntity target,0.25,-0.25,12
EntityAlpha target,0.8

;player
player=CreatePivot()
hand=CreatePivot()
EntityParent hand,camera
MoveEntity hand,.8,-.8,.8

;gun
gun=LoadAnimMesh("media/ar15.3ds")
ScaleEntity gun,0.03,0.03,0.03
MoveEntity gun, 22,0,0
 firetex=LoadTexture("media/ar15.jpg")
 For i=1 To CountChildren(gun)
	If EntityName(GetChild(gun,i))="red" EntityTexture GetChild(gun,i),firetex
	Next
gunsight=CreatePivot()
EntityParent gunsight,camera
MoveEntity gunsight,-3,2,500
guntarget=CreatePivot()
	
;sky
Sphere=CreateSphere()
PositionEntity Sphere, 50,100,-50
ScaleEntity Sphere, 250,250,250

texture=LoadTexture("media/sky1.jpg")
EntityTexture Sphere,texture
FlipMesh Sphere

;weapon effects - plasma
tex=LoadTexture("media/blank.png",2)
TextureBlend tex,2
plasmasprite=CreateSprite()
EntityTexture plasmasprite,tex
EntityFX plasmasprite,1
EntityBlend plasmasprite,3
EntityAlpha plasmasprite,0.8
ScaleSprite plasmasprite,1,2
HideEntity plasmasprite

;weapon effects - scorch
tex=LoadTexture("media/bullethole.png",2)
TextureBlend tex,2
holesprite=CreateSprite()
EntityTexture holesprite,tex
EntityFX holesprite,1
EntityAlpha holesprite,1
ScaleSprite holesprite,0.25,0.25
SpriteViewMode holesprite,2
HideEntity holesprite


;weapon effects - shockwave
tex=LoadTexture("media/blank.png",2)
TextureBlend tex,2
shockwavesprite=CreateSprite()
EntityTexture shockwavesprite,tex
EntityFX shockwavesprite,1
EntityBlend shockwavesprite,3
EntityAlpha shockwavesprite,0.8
ScaleSprite shockwavesprite,1,2
SpriteViewMode shockwavesprite,2
HideEntity shockwavesprite

;watersplash - water
tex=LoadTexture("media/watersplash.png",2)
;TextureBlend tex,2
watersprite=CreateSprite()
EntityTexture watersprite,tex
EntityFX watersprite,1
EntityAlpha watersprite,1
ScaleSprite watersprite,10,10
SpriteViewMode watersprite,1
HideEntity watersprite

;level
level=LoadAnimMesh("media/level.b3d")
ScaleEntity level, 5, 5, 5
PositionEntity level, 100, 0, -60

;create water plane
tex=LoadTexture( "media/Water-2_mip.bmp",3 )
ScaleTexture tex,1,1
water=CreateCube()
EntityTexture water,tex
EntityBlend water,1
EntityAlpha water,0.75
PositionEntity water,125,-5.2,50
ScaleEntity water,20,0.1,30
EntityFX water,1

;level collisions
EntityType level,col_level,1
EntityType water,col_water,1


;set up picking - this is because shooting and stair climbing needs pickable geometry. You can use picks for other stuff too
ent = level ; specify your level
While ent
	EntityPickMode ent,2
	ent = NextChild(ent)
Wend


;other collisions
EntityType player,col_player
EntityRadius player,playerradius,playerradius/2
Collisions col_player,col_level,2,2
PositionEntity player,100,10,-65
ResetEntity player
Collisions col_bullet,col_level,2,1
Collisions col_bullet,col_water,2,1



;mainloop
period=1000/FPS
time=MilliSecs()-period
While Not KeyHit(1)
	Repeat
		elapsed=MilliSecs()-time
	Until elapsed

	ticks=elapsed/period
	tween#=Float(elapsed Mod period)/Float(period)

	For k=1 To ticks
		time=time+period
		If k=ticks Then CaptureWorld
		
		UpdateWorld
		UpdatePlayer
		UpdatePlasma
		UpdateScorch
		UpdateShockwave
		UpdateWater
		
	Next

	RenderWorld
	Flip
Wend
End

Function UpdatePlayer()
	
	;look
	mxspd=MouseXSpeed()*0.25
	myspd=MouseYSpeed()*0.25
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	pitch=pitch+myspd
	yaw=yaw-mxspd
	If pitch<-90 Then pitch=-90
	If pitch>90 Then pitch=90
	RotateEntity camera,pitch,yaw,0
	RotateEntity player,0,yaw,0
	
	;movement
	If KeyDown(17)
		vz=vz+0.04
	ElseIf KeyDown(31)
		vz=vz-0.03
	EndIf
	vz=vz*0.9
	If KeyDown(30)
		vx=vx-0.04
	ElseIf KeyDown(32)
		vx=vx+0.04
	EndIf
	vx=vx*0.9
	If KeyDown(42) And KeyDown(17)
		vz=vz+0.045	
	EndIf
	If KeyDown(29)
		vy=vy-0.02
	EndIf
	If KeyDown(57)
		vy=vy+0.02
	EndIf
	vy=vy*0.9


	;steps and floor collisions
	pick=LinePick (EntityX(player),EntityY(player),EntityZ(player),0,-playerheight,0)
	If pick
		PositionEntity player,EntityX(player),PickedY()+playerheight#,EntityZ(player)
		vy=0
	EndIf
	vy=vy-.2
	vy=vy*0.9
		
		
	;move player pivot
	MoveEntity player,vx,0,vz
	TranslateEntity player,0,vy,0

	;move camera + player meshes smoothly
	PositionEntity camera,EntityX(player),EntityY(camera),EntityZ(player)
	TranslateEntity camera,0,(EntityY(player)-(EntityY(camera)-cameraheight))*0.1,0

	;gun
	x1#=EntityX(gun,1)
	y1#=EntityY(gun,1)
	z1#=EntityZ(gun,1)
	x2#=EntityX(gunsight,1)
	y2#=EntityY(gunsight,1)
	z2#=EntityZ(gunsight,1)
	pick=LinePick(x1,y1,z1,x2-x1,y2-y1,z2-z1)
	If pick
		PositionEntity guntarget,PickedX(),PickedY(),PickedZ()
	EndIf
	
	PositionEntity gun,EntityX(hand,1),EntityY(hand,1)-((Cos(bob)*Sqr(vx*vx+vz*vz))*.2),EntityZ(hand,1)
	MoveEntity gun,0,0,recoil#
	PointEntity gun,guntarget
	PositionTexture firetex,firetexpos,firetexpos
	firetexpos=firetexpos+0.01
	bob=bob+4
	recoil=recoil*.9
	
	;firing code
	If MouseHit(1) ShootPlasma() : recoil=-.6 : PlaySound sndgunshot

	
End Function

Function ShootPlasma()
	p.plasma=New plasma
	p\ent=CopyEntity(plasmasprite)
	PositionEntity p\ent,EntityX(gun),EntityY(gun),EntityZ(gun)
	PointEntity p\ent,guntarget
	MoveEntity p\ent,0,0,-1
	p\rot=Rand(360)
	EntityType p\ent,col_bullet
End Function

Function UpdatePlasma()
	For p.plasma=Each plasma
		MoveEntity p\ent,0,0,2.5
		RotateSprite p\ent,p\rot
		p\rot=p\rot+20
		If EntityCollided(p\ent,col_level)
			
			;find angle of collision
			nx#=0
			ny#=0
			nz#=0
			num#=CountCollisions(p\ent)
			For i=1 To num
				nx=nx+CollisionNX(p\ent,i)
				ny=ny+CollisionNY(p\ent,i)
				nz=nz+CollisionNZ(p\ent,i)
				x#=x#+CollisionX(p\ent,i)
				y#=y#+CollisionY(p\ent,i)
				z#=z#+CollisionZ(p\ent,i)
			Next
			nx=nx/num
			ny=ny/num
			nz=nz/num
			x=x/num
			y=y/num
			z=z/num
			
			;scorch
			s.scorch=New scorch
			s\ent=CopyEntity(holesprite)
			s\life#=1
			RotateSprite s\ent,Rand(360)
			temp#=1+Rnd(2)

			PositionEntity s\ent,x,y,z
			AlignToVector s\ent,-nx,-ny,-nz,0
			MoveEntity s\ent,0,0,-0.5
			
			;shockwave
			w.shockwave=New shockwave
			w\ent=CopyEntity(shockwavesprite)
			w\life#=2
			w\size=0.2
			RotateSprite w\ent,Rand(360)
			PositionEntity w\ent,x,y,z
			RotateEntity w\ent,EntityPitch(s\ent),EntityYaw(s\ent),0
			MoveEntity w\ent,0,0,-0.5
		
		
			FreeEntity p\ent
			Delete p
		EndIf
	Next
End Function

Function UpdatePlasmawater()
	For p.plasma=Each plasma
		MoveEntity p\ent,0,0,2.5
		RotateSprite p\ent,p\rot
		p\rot=p\rot+20
		If EntityCollided(p\ent,col_water)
			
			;find angle of collision
			nx#=0
			ny#=0
			nz#=0
			num#=CountCollisions(p\ent)
			For i=1 To num
				nx=nx+CollisionNX(p\ent,i)
				ny=ny+CollisionNY(p\ent,i)
				nz=nz+CollisionNZ(p\ent,i)
				x#=x#+CollisionX(p\ent,i)
				y#=y#+CollisionY(p\ent,i)
				z#=z#+CollisionZ(p\ent,i)
			Next
			nx=nx/num
			ny=ny/num
			nz=nz/num
			x=x/num
			y=y/num
			z=z/num
			
			;water splash
			q.water= New water
			q\ent=CopyEntity(watersprite)
			q\life#=1
			RotateSprite q\ent,Rand(360)
			temp#=1+Rnd(2)
			
			PositionEntity q\ent,x,y,z
			AlignToVector q\ent,-nx,-ny,-nz,0
			MoveEntity q\ent,0,0,-0.5
			
			;shockwave
			w.shockwave=New shockwave
			w\ent=CopyEntity(shockwavesprite)
			w\life#=2
			w\size=0.2
			RotateSprite w\ent,Rand(360)
			PositionEntity w\ent,x,y,z
			RotateEntity w\ent,EntityPitch(q\ent),EntityYaw(q\ent),0
			MoveEntity w\ent,0,0,-0.5
			FreeEntity p\ent
			Delete p
			
		EndIf
	Next
End Function

Function UpdateScorch()
	For s.scorch=Each scorch
		EntityAlpha s\ent,s\life
		s\life=s\life-0.00000005
		If s\life<0
			FreeEntity s\ent
			Delete s
		EndIf
	Next
End Function

Function UpdateShockwave()
	For s.shockwave=Each shockwave
		EntityAlpha s\ent,s\life
		ScaleSprite s\ent,s\size,s\size
		s\life=s\life-0.06
		s\size=s\size+0.1
		If s\life<0
			FreeEntity s\ent
			Delete s
		EndIf
	Next
End Function

Function UpdateWater()
	For q.water=Each water
		EntityAlpha q\ent,q\life
		q\life=q\life-1
		If q\life<0
			FreeEntity q\ent
			Delete q
		EndIf
	Next
End Function

Function NextChild(ent)
	If CountChildren(ent)>0
		Return GetChild(ent,1)
	EndIf

	Local foundunused=False
	Local foundent = 0, parent,sibling
	While foundunused=False And ent<>0
		parent = GetParent(ent)
		If parent<>0
			If CountChildren(parent)>1
				If GetChild(parent,CountChildren(parent))<>ent
					For siblingcnt = 1 To CountChildren(parent)
						sibling = GetChild(parent,siblingcnt)
						If sibling=ent
							foundunused = True
							foundent = GetChild(parent,siblingcnt+1)
						EndIf
					Next
				EndIf
			EndIf
		EndIf
		ent = parent
	Wend
	Return foundent
End Function


Hi, now this is old...

I think you just need to make your water entity pickable by setting entitypickmode or something. Been a few years........

Put the water object on the collision table, or set its pick mode. That would be your only issue really.

Thanks for the help i have now got it to work :)

Great news pal! Good luck with the game.