Ok,
Seems to work better now.
But my beam seems to hit beyond the cube. Not sure what I have done here.
Is there something I have done wrong? Sorry about the lack of comments!
Mango
;==================================================================
Global graphic_x$=1600
Global graphic_y$=900
Global graphic_depth$=32
Global graphic_window$=1
Global started$
Global fntarial$=LoadFont("Arial",8,False,False,False)
Global temp$
Global screendebug = 1
Global movement = 0
Global Collision$
Global torplive#
Global wp_id$
Global appname$="Face Off"
Global enemy1col=1
Global torpcol=1
Global title$ = appname+" - Build "+versionlong+" - Version "+versionshort
Global specs$ = "Available Memory: "+AvailPhysicalRAM()+" Total Ram Used: "+TotalPhysicalRAM()+" CPU Speed: "+CPUSpeed()
AppTitle (title)
; create screen
SetBuffer BackBuffer()
graphic_window=screendebug
Graphics3D graphic_x, graphic_y, graphic_depth, graphic_window
; Creation of standard game variables
Global ship_power# = 5000
Global shield# = 100
Global torp_capacity# = 100
Global torp_max# = 100
Global torp_recharge# = 0.25
Global torp_yield# = 20
Global phaser_capacity# = 100
Global phaser_max# = 100
Global phaser_yield#= 5
Global phaser_recharge# = 1.25
Global enemy1_shippower#
Global enemy1_shield# = 1000
Global enemy1_torp_recharge#
Global enemy1_phaser_recharge#
; setup 3d components
Global tex2 = LoadTexture("beam.bmp",3)
Global enemy1=CreateCube()
Global tex=LoadTexture( "borg.jpg",1 )
EntityTexture enemy1,tex
EntityFX enemy1,2
PositionEntity enemy1,+4,+1,+4
EntityRadius enemy1,1.5
EntityPickMode enemy1,2 ; check if pick mode is quicker on rectangle
EntityRadius (enemy1,1)
EntityType (enemy1, 2)
Global shieldsph=CreateSphere()
ScaleEntity shieldsph,0.01,0.01,0.01
EntityFX shieldsph,1
EntityTexture shieldsph, tex2
Global torp=CreateSphere(8)
EntityRadius (torp,1)
EntityType (torp,1)
ScaleEntity torp,0.25,0.25,0.25
HideEntity torp
Global beam=CreateCylinder(8)
;FitMesh beam,-1,0,-1,2,2,2
RotateMesh (beam,90,0,0)
PositionMesh beam,0,0,1
ScaleEntity beam,0.5,0.5,1
HideEntity beam
EntityFX beam,1
EntityTexture beam, tex2
Global camera=CreateCamera()
PositionEntity camera,0,0,-4
Global light=CreateLight(1)
PositionEntity light,0,-4,0
Global crosshair=LoadImage ("crosshair.bmp")
Global conftorp=LoadSound("torp-fired.wav")
Global torpsnd=LoadSound("torp.wav")
Global locked=LoadSound("locked.wav")
Global explosion=LoadSound("explosion.wav")
Global phasersnd=LoadSound("phaser.wav")
Collisions 1,2,2,1
; Main Loop
While Not KeyHit(1)
Locate 0,850:Print"System Information: "+specs
Locate 10,700:Print "Ship Power: "+ship_power
Locate 10,710:Print "Torp Capacity: "+torp_capacity
Locate 10,720:Print "Phaser Capacity: "+phaser_capacity
Locate 10,730:Print "Enemy Shield: "+enemy1_shield
Locate 10,750:Print "Enemy Distance: "+EntityDistance(camera,shieldsph)
DebugLog("Main loop")
enemymove()
PositionEntity (shieldsph,EntityX (enemy1),EntityY (enemy1), EntityZ (enemy1))
locktarget()
If wp_id = enemy1 And MouseHit(1) Then
fire_torp()
EndIf
If torplive = 1 Then
torp()
EndIf
If MouseDown(2) And phaser_capacity => 0
PointEntity beam,enemy1
ScaleEntity beam,0.10,0.10,EntityDistance(camera,shieldsph)
ShowEntity beam
phaser_capacity = phaser_capacity - 2
PlaySound phasersnd
EndIf
If phaser_capacity =< 0 Then HideEntity beam
If MouseDown(2) = False Then HideEntity beam
If torplive = 1 Then MoveEntity torp, 0, 0, 2
collide()
energy()
UpdateWorld
RenderWorld
DrawImage crosshair,MouseX(),MouseY() ; Draw the image!
Flip
Wend
; FUNCTIONS
Function torp()
If EntityX(torp) > 300 Then HideEntity torp:torplive=0
If EntityY(torp) > 300 Then HideEntity torp:torplive=0
If EntityZ(torp) > 300 Then HideEntity torp:torplive=0
;If torplive = 1 Then MoveEntity torp, 0, 0, 2
End Function
Function fire_torp()
If torp_capacity => torp_max
Locate 10,30:Print"Target Locked"
ShowEntity torp
PositionEntity torp,0,0,0
PointEntity torp, enemy1
PlaySound(conftorp)
PlaySound(torpsnd)
torplive=1
torp_capacity = torp_capacity - 100
EndIf
End Function
Function enemymove()
TurnEntity enemy1,.0,-0.1,.0
MoveEntity enemy1,-0.05,0,0
End Function
Function locktarget()
wp_id=CameraPick ( camera,MouseX(),MouseY())
Locate 10,10:Print wp_id
If wp_id = enemy1 Locate 10,30:Print"Target Locked"
End Function
Function collide()
If EntityCollided(enemy1,torpcol)
Text 30,40,"Hit2"
HideEntity torp
torplive=0
PlaySound(explosion)
enemy1_shield=enemy1_shield - torp_yield
EndIf
End Function
Function energy()
If enemy1_shield < 0 Then enemy1_shield = 0
If torp_capacity < 0 Then torp_capacity = 0
If torp_capacity => torp_max Then torp_capacity = torp_max
;If phaser_capacity <= Then phaser_capacity = 0
If phaser_capacity => phaser_max Then phaser_capacity = phaser_max
torp_capacity = torp_capacity + torp_recharge
phaser_capacity = phaser_capacity + phaser_recharge
If torp_capacity =< 100
ship_power=ship_power - torp_recharge
EndIf
End Function