Reloading

Blitz3D Forums/Blitz3D Beginners Area/Reloading

Happy Llama(Posted 2012) [#1]
I'm not to good with Types so I need some help. I got some help from Drak and he suggested to use types instead of arrays to simulate throwing snowballs. I typed in the new code and now I want to add reloading. How would one do this?



Last edited 2012


Matty(Posted 2012) [#2]


Graphics3D 800,600,0,2
SetBuffer BackBuffer()

;variables
Global spacebar=57,escape=1,leftkey=208,rightkey=205
Global gravity=0.3
Global cam_y#=-3
Global cam_x#=0 
Global magazine	= 25
Global health=100

HidePointer

shoosh=LoadSound("swoosh.wmv")

;Types

Type snowball
	Field mesh	
	Field id	
	Field damage
End Type

Type player
Field health
End Type
 
Type enemy
Field health
End Type

AmbientLight 255,255,255


;Light
sun=CreateLight()

;Player
player=CreateCamera()
CameraFogRange player,0.1,400
CameraFogMode player,True
CameraClsColor player,100,130,150
CameraFogColor player,100,130,150


;Terrain
ground=CreatePlane()
PositionEntity ground,0,-5,0
EntityColor ground,200,200,200


;Sky
sky=CreatePlane()
PositionEntity sky,0,100,0
RotateEntity sky,-180,0,0
;Sky texture
skytex=LoadTexture("sky.jpg")
EntityTexture sky,skytex
ScaleTexture skytex,5,5
ScaleTexture skytex,500,500

;Load the enemy

enemy=LoadMesh("enemy.3ds")
PositionEntity enemy,0,-4,30
ScaleEntity enemy,0.5,0.5,0.5

snowball=CreateSphere(36)
ScaleEntity snowball,0.2,0.2,0.2
HideEntity snowball

;Make the snow forts:

;Fort 1
fort1=LoadMesh("snowfort.3ds")
PositionEntity fort1,0,-3.5,4
EntityColor fort1,255,255,255
ScaleEntity fort1,1,1,2.5
RotateEntity fort1,0,-90,0


;Fort 2
fort2=CreateCube()
PositionEntity fort2,0,-4,30
EntityColor fort2,255,255,255
ScaleEntity fort2,2,1,1



;Making it snow!

Dim snowflake(1000)

For p=0 To 1000

snowflake(p)=CreateSphere()

ScaleEntity snowflake(p),0.05,0.05,0.05

PositionEntity snowflake(p),Rnd(-50,50),Rnd(1,100),Rnd(-50,50)

Next


;###############
;#  Main Loop  #
;###############
While Not KeyDown (escape)

;Shooting the player snowballs

If MouseHit(1) And magazine > 0	
	s.snowball = New snowball 		
	s\mesh = CopyEntity(snowball)		
	s\id = 1						
	s\damage = 5				
	PositionEntity s\mesh,EntityX(player),EntityY(player),EntityZ(player)			
	RotateEntity s\mesh, EntityPitch(player),EntityYaw(player),EntityRoll(player)	
	magazine = magazine -1			
End If 

;New Code added 27/1/2012
If MouseHit(2)>0 And magazine < 25 Then 
	magazine = 25
	;play reloading sound
	;perhaps have a limited number of clips as well?	

EndIf 

For s.snowball = Each snowball		
	MoveEntity s\mesh, 0,0,1		
	If Abs(EntityZ(s\mesh)) > 400 	
	    FreeEntity s\mesh			
		Delete s					
	End If
Next

;Reloading



;Move the snow downwards
For l=0 To 1000
MoveEntity snowflake(l),0,Rnd(-0.002,-0.1),0
Next

;duck 

If KeyDown(57) Then  
cam_y=-3.7
Else
cam_y=-3
EndIf

PositionEntity player,cam_x,cam_y,3

;straffting  

If KeyDown(30) Then cam_x=cam_x-0.1

If KeyDown(32) Then cam_x=cam_x+0.1


If cam_x > 0.5 Then cam_x=0.5
If cam_x < -0.5 Then cam_x=-0.5 

;point the enemy at the player
PointEntity enemy,player

;FPS Camera Stuff
mxs#=mxs#+MouseXSpeed()
mys#=mys#+MouseYSpeed()

If mxs# > 100 Then mxs# = 100
If mxs# < -100 Then mxs# = -100

If mys# > 40 Then mys# = 40
If mys# < -80 Then mys# = -80

RotateEntity player,mys#,-mxs#,0

If magazine < 0
Text 100,100,"Hold E to reload"
EndIf 

RenderWorld

UpdateWorld 

Color 0,0,0

Rect 10,10,200,100,False

Text 20,20,"Snowballs left: "+ magazine
Text 20,40,"Health: "+health



Flip




Wend



End


See "new code added" section above.

(here it is again :

;New Code added 27/1/2012
If MouseHit(2)>0 And magazine < 25 Then 
	magazine = 25
	;play reloading sound
	;perhaps have a limited number of clips as well?	

EndIf 


Last edited 2012


Drak(Posted 2012) [#3]
Yep, that's correct. All you need to do is reset the variable magazine to 25 to "reload" your shots.


Happy Llama(Posted 2012) [#4]
Wow I feel stupid. Thanks, so simple!

Last edited 2012


Charrua(Posted 2012) [#5]
Wow I feel stupid.


happens to me all the time