Sprites, Picks, and Collisions, oh my!

Blitz3D Forums/Blitz3D Programming/Sprites, Picks, and Collisions, oh my!

wizzlefish(Posted 2004) [#1]
I've had a sprite problem recently. I created a "bullethole" sprite, and the loading works fine and everything, but it doesn't place itself correctly.

I used this code:

;------------------------------------START-UP SETTINGS-------------------------------------------
Graphics3D 800,600,16,1
Print "Starting up..."
Print ""
ldf = LoadFont("Courier New", 14, 0, 0, 0)
SetFont ldf
WBuffer True 
SetBuffer BackBuffer()
AppTitle "Operation 600"
SeedRnd MilliSecs()
AutoMidHandle True
;-------------------------------END OF START-UP SETTINGS----------------------------------------- 





;-------------------------------------------GLOBALS-CONSTANTS------------------------------------
Print "Reticulating splines..."
;CAMERA
Global cam_x#,cam_z#,cam_pitch#,cam_yaw#						; Current
Global dest_cam_x#,dest_cam_z#,dest_cam_pitch#,dest_cam_yaw#	; Destination
;GUN KICK
Global kick = False
Global kickamount = 0
Global kickmaxamount = 30
Global kickspeed# = 1
Global delta = 0
Global z_memo#
;MISC
Global numberofenemies = 10
Global ButtonHit$
Global menu
Global level
Global start
Global levelname$ = "1 - Rural"
;TIMERS
Global timer = MilliSecs()
Global uzitimer = MilliSecs()
Global lazertimer = MilliSecs()
Global machineshottimer = MilliSecs()
;MODIFIERS
Global prone = False
Global time = 100
Global health = 100
Global kills = 0
Global info$
Global logic$
Global n = -200
Global ammo = 100
Global reloads = 6
Global gun = 1
Global help = 0

;COLLISION CONSTANTS
Const PLAYER_COL= 1
Const LEVEL_COL = 2
Const ENEMY_COL = 3
Const BULLET_COL= 4
Const INVISICOL = 5
Const CANNONCOL = 6
Const BARN__COL = 7
Const HAYCOL = 8
Const HAY2COL = 9
Const PLANECOL = 10
;----------------------------------------END OF GLOBALS-CONSTANTS---------------------------------






;---------------------------------------------TYPES-----------------------------------------------
Print "Creating characters..."
Print "   BULLET"
;The bullet type
Type bullettype
	Field entityhandle
	Field from
End Type
Print "   ENEMY"
;The enemy type
Type badguytype
	Field entityhandle
	Field state
	Field light
End Type
Print "   WEAPON"
;The weapon type
Type weapon
	Field category 
	Field index 

	Field offsetx#
	Field offsety# 
	Field offsetZ#  

	Field entityhandle  
	Field gotit 
	Field ammo
End Type
Print "   PLAYER"	 
;The player type
Type player 
	Field entityhandle 
	Field activeweaponindex
	Field gotweapon
	Field weapon 
End Type
Print "   PLANE"
;the plane type
Type plane
	Field entityhandle
	Field x, y, z
	Field speed
	Field destination
End Type
Print "   PARTICLE"
Print "Rendering particles..." 
;the particle type
Type particle
	Field mesh, name$, alpha#
	Field vX#, vY#, vZ#
End Type
Print "   BULLETHOLE"
Print "Rendering bulletholes..."
Type hole
	Field entityhandle
	Field alpha#
End Type 
;--------------------------------------END OF TYPES---------------------------------------------------





;---------------------------LIGHTS-LEVEL-CAMERA-PLAYER SET-UP-----------------------------------------
Print "Generating playing area..."
Print "Creating camera..."
;Lights, camera, and player...
Global camera = CreateCamera()
EntityRadius camera, 1.5, 2.5
PositionEntity camera, 0, 0, 0
;TranslateEntity camera, 0, -2, 0
;CameraFogRange camera, 1, 10
;CameraFogMode camera, 1
;CameraFogColor camera, 100,100,150
Global guntype$
Print "Rendering level..."
;Level
Global level1 = LoadMesh("levels\nsabase.b3d")
PositionEntity level1, 0, 0, 0
ScaleEntity level1, 2, 2, 2
Print "Generating lights..."
;lights
light=CreateLight()
LightColor light, 100,100,255
;--------------------------END OF LIGHTS-LEVEL-CAMERA-PLAYER SET-UP-----------------------------------






;-----------------------------------------WEAPON SET-UP-----------------------------------------------
Print "Creating arms..."
;pistol (gun1)
Global pistol.weapon = New weapon
pistol\category = "C90-KL"
Print "Setting weapon statistics..."
pistol\index = 1
pistol\offsetx = .95
pistol\offsety = -.84
pistol\offsetz = 1.6
pistol\entityhandle = LoadMesh("weapons\pistol1\pistol1.x",camera)
pistol\gotit = True 
;lazer (gun2)
Global lazer.weapon = New weapon
lazer\category = "LAS-74"
lazer\index = 2
lazer\offsetx = .95
lazer\offsety = -.84
lazer\offsetz = 1.8
lazer\entityhandle = LoadMesh("weapons\lazer\lazer.3ds", camera)
lazer\gotit = False
;setup
ScaleEntity pistol\entityhandle, 2.5, 2.5, 2.5
ScaleEntity lazer\entityhandle, .2, .2, .2
TranslateEntity pistol\entityhandle, pistol\offsetx, pistol\offsety, pistol\offsetz
TranslateEntity lazer\entityhandle, lazer\offsetx, lazer\offsety, lazer\offsetz
RotateEntity pistol\entityhandle, 0, 0, 0

For w.weapon = Each weapon
	
	If w\gotit = False
		HideEntity w\entityhandle
	EndIf

Next
;-------------------------------END OF WEAPON SET-UP--------------------------------------------------





;--------------------------------MISC MODEL SET-UP----------------------------------------------------
Print "Loading miscullaneous models..."
Print "Generating enemies..."
Global badguymesh = CreateSphere()
Print "Rendering bullets..."
Global bulletmesh = CreateSphere()
RotateMesh bulletmesh, 90, 0, 0
ScaleEntity bulletmesh, .1, .1, .1
Print "Performing misc. operations..."
HideEntity bulletmesh
HideEntity badguymesh
EntityType camera,PLAYER_COL
EntityType level1, LEVEL_COL
EntityType badguymesh, ENEMY_COL
EntityType bulletmesh, BULLET_COL
EntityAlpha bulletmesh, 1
Print "Loading fonts..."
;fonts
Global font=LoadFont("Courier New", 14, 0, 0, 0)
Global bigfont=LoadFont("Courier New",50, 0, 0, 0)
;------------------------------END OF MISC MODEL SET-UP----------------------------------------------






;--------------------------------------2D PICTURE SETUP----------------------------------------------
Print "Loading sprites..."
Print "Loading explosion sprite..."
Global copySprite = LoadSprite("sprites\flare.bmp")
Print "Loading bullethole sprite..."
Global bullethole = LoadSprite("sprites\flare.bmp")
Print "Loading crosshairs sprite..."
Global hairs = LoadImage("sprites\pistolhairs.bmp")
Print "Creating menu images..."
Global title = LoadImage("menu\title.png")
Global bottom = LoadImage("menu\bottomimage.png")
HideEntity copySprite
HideEntity bullethole
;----------------------------------END OF 2D PICTURE SETUP-------------------------------------------




;-------------------------------------SOUND SET-UP---------------------------------------------------
Print "Loading sounds..."
Print "Rendering shots..."
shoot = LoadSound("sounds\shoot.mp3")
Print "Loading machine gun..."
machineshoot = LoadSound("sounds\machineshoot.mp3")
Print "Loading 'reload' sound..."
reload1 = LoadSound("sounds\reload05.wav")
Print "Loading music..."
music = PlayMusic("sounds\Metal Keys.mp3")
StopChannel menumusic
;-------------------------------------END OF SOUND SETUP---------------------------------------------




;--------------------------------OTHER SET-UP--------------------------------------------------------
Print "Rendering enemy forces..."
;Create Enemies
For iter = 1 To 10
	badguy.badguytype = New badguytype
	badguy\entityhandle = CopyEntity(badguymesh)
	PositionEntity badguy\entityhandle, Rnd(200,-200), 15, Rnd(171,-171) 
	badguy\state = Rnd(1,2)
	EntityType badguy\entityhandle, 3
	EntityRadius badguy\entityhandle, .7
	Print iter
Next

;Place player
Print "Creating player..."
PositionEntity camera, 0, 0, 0
Print "Creating collisions..."
;Collisions! Everybody likes collisions!
Collisions PLAYER_COL, LEVEL_COL, 2, 3 ;player to level
Collisions ENEMY_COL, LEVEL_COL, 2, 3 ;badguy to level
Collisions BULLET_COL, LEVEL_COL, 2, 1 ;bullet to level
Collisions BULLET_COL, ENEMY_COL, 2, 1 ;bullet to badguy
Collisions PLAYER_COL, INVISICOL, 2, 3 ;player to floor
Collisions PLAYER_COL, PLANECOL, 2, 1  ;player to plane
Collisions BULLET_COL, PLANECOL, 2, 1  ;bullet to plane
;----------------------------------------END OF OTHER SET-UP---------------------------------------------





;-----------------------------------------------MAIN LOOP------------------------------------------------
Print "Starting game..."
SetFont font
PointEntity camera, level1
Global machinetimer = MilliSecs()
Global startlogic$ = "game"
While Not KeyHit(1) Or Collisions 
	
	UpdateLogic(startlogic$)
	
	info$ = ""
	
Wend
;---------------------------------------------------END OF MAIN LOOP--------------------------------------
;End the game
End

;----------------------------------------------------FUNCTIONS---------------------------------------------

;CreateSkyBox()
;this function creates the skybox for the game
Function CreateSkyBox()
    mesh = CreateMesh()

    ;front face
    brush = LoadBrush("sprites\Sky\brightsky_FR.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,-1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,-1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;right face
    brush = LoadBrush("sprites\Sky\brightsky_LF.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,-1,0,0
    AddVertex surface,+1,+1,+1,1,0
    AddVertex surface,+1,-1,+1,1,1
    AddVertex surface,+1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;back face
    brush = LoadBrush("sprites\Sky\brightsky_BK.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,-1,+1,+1,1,0
    AddVertex surface,-1,-1,+1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
 
    ;left face
    brush = LoadBrush("sprites\Sky\brightsky_RT.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,0
    AddVertex surface,-1,+1,-1,1,0
    AddVertex surface,-1,-1,-1,1,1
    AddVertex surface,-1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;top face
    brush = LoadBrush("sprites\Sky\brightsky_UP.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,1
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,-1,+1,-1,1,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
   
    ;bottom face 
    brush = LoadBrush("sprites\Sky\brightsky_DN.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,-1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddVertex surface,-1,-1,+1,0,0
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
    
    ScaleMesh mesh,400,400,400
    FlipMesh mesh
    EntityFX mesh,1 ; make fullbright
    Return mesh
End Function

;UpdateLogic()
;determines if it is menu or game
Function UpdateLogic(logic$)
	
	If logic$ = "menu"
		ClsColor 0, 0, 0
		Cls
		UpdateMenu()
		RenderWorld
		UpdateWorld
		Flip 
	ElseIf logic$ = "game"
		UpdateCamera()
		UpdateShoot()
		UpdateBullets()
		UpdateWorld
		UpdateParticles()
		UpdateEnemies()
		UpdateMiscActions()
		;draw crosshairs
		DrawImage hairs, 400, 310
		RenderWorld
		UpdateGUI()
		Flip
		
		;gravity
		TranslateEntity camera, 0, -0.2, 0 
	EndIf
	
End Function 
		
;Ititi

;Quit()
;ends the game
Function Quit()
	SetFont bigfont
	SetGammaRed(50)
	Color 0, 500, 500
	Text 400, 300, "YOU ARE DEAD", True, True		
	Flip
	Delay 3000
	End
End Function

;GAMMA FUNCTIONS
;sets gamma red
Function SetGammaRed( n )
	For k=0 To 255
		SetGamma k,k,k,k+n,0,0
	Next
	UpdateGamma
End Function

;sets gamma intensity
Function SetGammaIntensity( n )
	For k%=0 To 255
		SetGamma k,k,k,k+n,k+n,k+n
	Next
	UpdateGamma
End Function

;PARTICLE FUNCTIONS
;CreateSomeParticles
;creates some particles
Function CreateSomeParticles(x, y, z, r, g, b, numParticles)

	For i = 1 To numParticles
		p.Particle = New Particle
		p\mesh = CopyEntity(copySprite)
		PositionEntity(p\mesh,x, y, z)
		p\vX# = Rnd(-.2, .2)
		p\vY# = Rnd(.2)
		p\vZ# = Rnd(-.2, .2)
		p\alpha = 1
	Next
	
End Function

;UpdateParticles
;updates particles
Function UpdateParticles()

	For p.particle = Each particle
		If p\alpha# <= 0
			FreeEntity(p\mesh)
			Delete(p)
		Else
			p\vY# = p\vY# - .01
			TranslateEntity(p\mesh,p\vX#, p\vY#, p\vZ#)
			p\alpha# = p\alpha# - .02
			EntityAlpha(p\mesh, p\alpha#)
		EndIf
	Next
	
End Function

;====== CORRECTX ==========================================================

Function CorrectX(pixel)
	
	Return (pixel * GraphicsWidth() / 1280)

End Function

;==========================================================================



;====== CORRECTY ==========================================================

Function CorrectY(pixel)
	
	Return (pixel * GraphicsHeight() / 1024) 

End Function 

;==========================================================================

;UpdateGUI
;updates the UI
Function UpdateGUI()

	;GUI
	Color 0,0,20
	Rect -20, -20, 830, 70
	Color 0,0,255
	Text 5, 5, realm$
	Text 5, 30, "Weapon: " + guntype$
	Line -20, 25, 1320, 25
	Line -20, 50, 1320, 50
	Line 125, -20, 125, 50
	Line 0, 0, 1280, 0
	Text 130, 5, "Kills: " + kills
	Text 200, 5, "Ammo: " + ammo + " - " + reloads
	Text 300, 5, "Time: " + time
	Text 370, 5, "CameraX: " + EntityX(camera)
	Text 500, 5, "CameraY: " + EntityY(camera)
	Text 630, 5, "CameraZ: " + EntityZ(camera)
	Text 370, 30, info$
	Color 0, 0, 100
	Rect 130, 30, 130 + health, 15
	;Help menu
	If help = 1
		Color 0, 0, 255
		Text 30, 100, "W, S, A, D - Walk"
		Text 30, 120, "MOUSE - look around"
		Text 30, 140, "LMB - shoot"
		Text 30, 160, "[SPACE] - jump"
		Text 30, 180, "[CTRL] - Misc. Action"
		Text 30, 200, "H - toggle help"
	EndIf 
	
End Function

;UpdateCamera
;updates the camera
Function UpdateCamera()
	
	; Mouse look
	;-----------
	; Mouse x and y speed
	mxs=MouseXSpeed()
	mys=MouseYSpeed()
	
	; Mouse shake (total mouse movement)
	mouse_shake=Abs(((mxs+mys)/2)/1000.0)

	; Destination camera angle x and y values
	dest_cam_yaw#=dest_cam_yaw#-mxs
	dest_cam_pitch#=dest_cam_pitch#+mys

	; Current camera angle x and y values
	cam_yaw=cam_yaw+((dest_cam_yaw-cam_yaw)/5)
	cam_pitch=cam_pitch+((dest_cam_pitch-cam_pitch)/5)
	
	;Turn camera
	RotateEntity camera, cam_pitch#/2,cam_yaw#/2,0
	
	; Rest mouse position to centre of screen
	MoveMouse 640,512
	SetFont bigfont
	Text 640,522, "+", True, True
	SetFont font
	; Camera move
	; -----------
	
	; Forward/backwards - destination camera move z values
	If KeyDown(17)=True Then dest_cam_z=.4
	If KeyDown(31)=True Then dest_cam_z#=-.4

	; Strafe - destination camera move x values
	If KeyDown(30)=True Then dest_cam_x=-.4
	If KeyDown(32)=True Then dest_cam_x=.4
	If ammo <= 0
	If reloads >= 1
		If KeyHit(19)= True Then 
			ammo = ammo + 100
			If gun = 1
				PlaySound reload1
			ElseIf gun = 2
				PlaySound reload1
			EndIf
			reloads = reloads - 1
		EndIf
	EndIf
	EndIf
	; Current camera move x and z values
	cam_z=cam_z+((dest_cam_z-cam_z)/5)
	cam_x=cam_x+((dest_cam_x-cam_x)/5)

	; Move camera
	MoveEntity camera,cam_x,0,cam_z
	dest_cam_x=0 : dest_cam_z=0
	
	;Misc functions
	If help = 0
		If KeyHit(35)
			help = 1
		EndIf
	ElseIf help = 1
		If KeyHit(35)
			help = 0
		EndIf
	EndIf
	If KeyHit(2)
		gun=1
	ElseIf KeyHit(3)
		gun=2
	EndIf
	If KeyHit(209)
		prone = True
	ElseIf KeyHit(201)
		prone = False
	EndIf
	If prone = True
		camradius = 3
	ElseIf prone = False
		camradius = 4
	EndIf
	If MouseHit(2)
		zoom = Not zoom
	EndIf
	If zoom = True
		zoomamount = 4
	ElseIf zoom = False
		zoomamount = 1
	EndIf
	CameraZoom camera, zoomamount
	
End Function

;UpdateEnemies()
;updates all enemy operations
Function UpdateEnemies()

	;enemy AI (yeah, just right here)
	For spin.badguytype = Each badguytype
		TurnEntity spin\entityhandle, 0, 5, 0
		If MilliSecs() >= shottimer + 5000
			enemyshot.bullettype = New bullettype
			enemyshot\entityhandle = CopyEntity(bulletmesh)
			enemyshot\from = 2
			PositionEntity enemyshot\entityhandle, EntityX(spin\entityhandle, 1), EntityY(spin\entityhandle, 1), EntityZ(spin\entityhandle, 1)
			RotateEntity enemyshot\entityhandle, EntityPitch(spin\entityhandle, 1), EntityYaw(spin\entityhandle, 1), EntityRoll(spin\entityhandle, 1)
			EntityType enemyshot\entityhandle, 4
			EntityRadius enemyshot\entityhandle, .01
		EndIf
	Next

	
End Function 

;UpdateBullets()
;updates all bullet functions
Function UpdateBullets()

	;Update Bullets
	For biter.bullettype = Each bullettype
		If biter\from = 1
			MoveEntity biter\entityhandle, 0, 0, 5
		ElseIf biter\from = 2
			MoveEntity biter\entityhandle, 0, 0, 5
		EndIf
		If Abs(EntityX(biter\entityhandle, 1)) > 10000
			FreeEntity biter\entityhandle
			Delete biter
		ElseIf Abs(EntityY(biter\entityhandle)) > 10000
			FreeEntity biter\entityhandle
			Delete biter
		ElseIf Abs(EntityZ(biter\entityhandle)) > 10000
			FreeEntity biter\entityhandle
			Delete biter
		EndIf
		
		If EntityCollided (biter\entityhandle, 2)
			FreeEntity biter\entityhandle
			Delete biter
		EndIf
	Next
	
	;lower health if shot
	For biter2.bullettype = Each bullettype
		If CountCollisions(biter2\entityhandle) > 0
			playerhit = EntityCollided(biter2\entityhandle, 1)
			For playersearch.player = Each player
				If playerhit = playersearch\entityhandle
					If biter2\from = 2
						CreateSomeParticles(EntityX(playersearch\entityhandle), EntityY(playersearch\entityhandle), EntityZ(playersearch\entityhandle), 255, 255, 100, 100)							
						health = health - 5	
						Exit
					EndIf
				EndIf
			Next
			Delete biter
		EndIf
	Next
	
	;Kill the badguy if shot
	For biter.bullettype = Each bullettype
		If CountCollisions(biter\entityhandle) > 0
			badguyhit = EntityCollided(biter\entityhandle, 3)
			For badguysearch.badguytype = Each badguytype
				If badguyhit = badguysearch\entityhandle
					If badguysearch\state <> 5
						If biter\from = 1
							CreateSomeParticles(EntityX(badguysearch\entityhandle), EntityY(badguysearch\entityhandle), EntityZ(badguysearch\entityhandle), 255, 255, 100, 100)							
							badguysearch\state = 5
							RotateEntity badguysearch\entityhandle, 0, 0, 180
							kills = kills + 1
							TranslateEntity badguysearch\entityhandle, 0, -1, 0
							HideEntity badguysearch\entityhandle	
							Delete badguysearch
							Exit
						EndIf
					EndIf
				EndIf
			Next
			Delete biter
		EndIf
	Next 
	
End Function

;UpdateShoot()
;updates the player's shot
Function UpdateShoot()

	;Shoot
	;-----
	If gun=1
	If ammo >= 1
	If MouseHit(1)
		PlaySound shoot
		bullet.bullettype = New bullettype
		bullet\entityhandle = CopyEntity(bulletmesh)
		bullet\from = 1
		PositionEntity bullet\entityhandle, EntityX(camera), EntityY(camera), EntityZ(camera)
		RotateEntity bullet\entityhandle, EntityPitch(camera), EntityYaw(camera), EntityRoll(camera)
		EntityType bullet\entityhandle, 4
		EntityRadius bullet\entityhandle, .01
		ammo = ammo - 1
		CameraPick(camera, MouseX(), MouseY())
		h.hole = New hole
		h\entityhandle = CopyEntity(bullethole)
		h\alpha = 0.9
		PositionEntity h\entityhandle, PickedX(), PickedY(), PickedZ()
	EndIf
	EndIf
	EndIf
	
	For b.hole = Each hole
		EntityAlpha b\entityhandle, b\alpha
		b\alpha = b\alpha-0.1
		If b\alpha <= 0
		FreeEntity b\entityhandle
		Delete b
		EndIf
	Next

End Function 

;UpdateMiscActions()
;updates misc. features of the game, such as gamma, etc.
Function UpdateMiscActions()

	If KeyHit(57)
		jump = 10
	EndIf 

	If jump > 0 
		MoveEntity camera,0,jump,0
		jump = jump 
	EndIf 
		
	n = n + 4
	If n >= -25
		n = -25
	EndIf 
	SetGammaIntensity(n)
	Cls
	SeedRnd 1234
	;Update timer
	If MilliSecs() >= timer + 1000
		time = time - 1
		timer = MilliSecs()
	EndIf
	
	;Quit if timer is out
	If time <= -1
		Quit()
	EndIf
	
	If time <= 10
		info$ = "You have " + time + " seconds left."
	EndIf
	
	If gun=1
		guntype$ = "Semi-Auto"
	ElseIf gun=2
		guntype$ = "Full Auto"
	EndIf
 

End Function

;UpdateMenu()
;updates the game menu, if applicable
Function UpdateMenu()

	If menu = 1  ;campaign
		Text 5, 250, "Currently selected: " + levelname$
		Button("1 - Rural",300,200,200,30,17)
		Button("2 - Suburban",300,240,200,30,18)
		Button("3 - Urban",300,280,200,30,19)
		Button("Start",300,360,200,30,20)
		Button("Back",300,420,200,30,10)
	ElseIf menu = 10  ;main menu
		Button("Campaign",300,200,200,30,1)
		Button("Skirmish",300,240,200,30,2)
		Button("Options",300,280,200,30,3)
		Button("About",300,320,200,30,4)
		Button("Exit",300,420,200,30,16)
	ElseIf menu = 3  ;options
		Button("Music",300,200,200,30,6)
		Button("Sound",300,240,200,30,7)
		Button("Graphics",300,280,200,30,8)
		Button("Gameplay",300,320,200,30,9)
		Button("Back",300,420,200,30,10)
	EndIf
	If start = True 
		UpdateLogic("game")
	EndIf
	Rect 0, 0, 800, 600
	DrawImage title,420,75
	DrawImage bottom,400,300
	
End Function

;makes a button
Function Button(ButtonAssetType$,ButtonX,ButtonY,ButtonWidth,ButtonHeight,ButtonAction)
		If MouseX() > ButtonX And MouseX() < ButtonX+ButtonWidth And MouseY() > ButtonY And MouseY() <Buttony+ButtonHeight Then
			Color 75,0,0
			doaction = 1
		Else 
			Color 0,0,0
			doaction = 0
		End If
		
		If doaction = 1
			If MouseHit(1)
				If ButtonAction <= 15
					menu = ButtonAction
				ElseIf ButtonAction = 16
					End
				ElseIf ButtonAction <= 19 And ButtonAction >= 17
					level = ButtonAction - 1
					levelname$ = ButtonAssetType
				ElseIf ButtonAction = 20
					start = True
				EndIf
			EndIf
		EndIf
			
		;Make Button
		Rect ButtonX, ButtonY, ButtonWidth, ButtonHeight
		;HighLights
		Color 255,0,0
		Line ButtonX,ButtonY,ButtonX+ButtonWidth, ButtonY
		Line ButtonX,ButtonY,ButtonX,ButtonY+ButtonHeight
		;Shadow
		Color 255,0,0
		Line ButtonX,ButtonY+ButtonHeight,ButtonX+ButtonWidth, ButtonY+ButtonHeight
		Line ButtonX+ButtonWidth,ButtonY,ButtonX+ButtonWidth,ButtonY+ButtonHeight
		;Text
		Color 255,0,0
		Text ButtonX+(ButtonWidth/2), Buttony+(ButtonHeight/2),ButtonAssetType$,True,True	
End Function


When you shoot, the picked place by the camera, (UpdateShoot()) doesn't place the sprite. The sprite is always in the same spot, 0, 0, 0. I think I used "FreeEntity" correctly, but the sprite doesn't place itself in the right place. It places itself at 0, 0, 0, instead of the picked location.

Any ideas? (and yes, my code is a bit messy)


Ross C(Posted 2004) [#2]
To use camera pick correctly, you need to make the level geometry "pickable", using EntityPickMode.

I noticed something else too. In your UpdateLogic function:

	ElseIf logic$ = "game"
		UpdateCamera()
		UpdateShoot()
		UpdateBullets()
		UpdateWorld
		UpdateParticles()
		UpdateEnemies()
		UpdateMiscActions()
		;draw crosshairs
		DrawImage hairs, 400, 310
		RenderWorld
		UpdateGUI()
		Flip


Your drawing the crosshairs, then calling renderworld, which will cause the crosshairs not to be seen. Draw all your 2d graphics after the renderworld and before the flip, and you should be ok.


wizzlefish(Posted 2004) [#3]
ok, thanks.

And I was wondering about those crosshairs...


wizzlefish(Posted 2004) [#4]
With this code, would it be better to check if an entity was "picked" instead of testing collisions against a bullet mesh?


Ross C(Posted 2004) [#5]
You could do. It would get around the moving collisions problem :o) Try it out and see whats best.


aab(Posted 2004) [#6]
Yeah, its definately better to just return pickedx,y,and z than check for collissions. Definately.

Crosshairs?