Hi folks, I started making a little 3d space shooter game.
I put together a radar and targetting setup for the first time and it would be great if it could be tested on different computers to see if it works or not.
If you give it a test then please let me know your screen width and height. It's displayed on screen.
Also, the green dot should be able to move all around the radar display and hopefully will not move outside the border.
With this type of radar, if the dot is near any outer edge then the target is behind you.
Cheers.
// Project: radar test by ando
// Created: 20-05-28
SetErrorMode(2)
width# = GetMaxDeviceWidth()
height# = GetMaxDeviceHeight()
SetWindowSize(width#,height#,1)
SetVirtualResolution(width#,height#)
SetSyncRate(30,0)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
SetSunActive(1)
SetGenerateMipmaps(1)
SetAmbientColor(160,160,160)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx set all item ID's to names
// CAMERA
cam1=1
// OBJECTS
starsphere=1
man1=2
cubechild=3
asteroid1=4
asteroid2=5
asteroid3=6
asteroid4=7
asteroid5=8
// IMAGES
startex=1
sightstex=2
dashtex=3
rendertex=4
bliptex=5
targettex=6
asteroid1tex=7
asteroid2tex=8
asteroid3tex=9
asteroid4tex=10
asteroid5tex=11
// SPRITES
sightsprite=1
dashsprite=2
rendersprite=3
targetsprite=4
targetblipsprite=5
// LIGHTS
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx skybox
LoadObject(starsphere,"misc/starsphere1.obj")
SetObjectposition(starsphere,0,0,-1000)
SetObjectScalePermanent(starsphere,1000,1000,1000)
LoadImage(startex,"misc/stars.png")
SetObjectImage(starsphere,startex,1)
SetImageWrapU(startex,1)
SetImageWrapV(startex,1)
SetObjectMeshUVScale(starsphere,1,0,5,5)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx asteroids
LoadObject(asteroid1,"asteroid1/asteroid1.obj",0)
SetObjectposition(asteroid1,-200,4000,-1000)
SetObjectRotation(asteroid1,0,0,0)
SetObjectScalePermanent(asteroid1,50,50,50)
LoadImage(asteroid1tex,"asteroid1/asteroid1_d.png")
SetObjectImage(asteroid1,asteroid1tex,0)
LoadObject(asteroid2,"asteroid2/asteroid2.obj",0)
SetObjectposition(asteroid2,10,1400,3000)
SetObjectRotation(asteroid2,0,0,0)
SetObjectScalePermanent(asteroid2,50,50,50)
LoadImage(asteroid2tex,"asteroid2/asteroid2_d.png")
SetObjectImage(asteroid2,asteroid2tex,0)
LoadObject(asteroid3,"asteroid3/asteroid3.obj",0)
SetObjectposition(asteroid3,300,900,-100)
SetObjectRotation(asteroid3,0,0,0)
SetObjectScalePermanent(asteroid3,50,50,50)
LoadImage(asteroid3tex,"asteroid3/asteroid3_d.png")
SetObjectImage(asteroid3,asteroid3tex,0)
LoadObject(asteroid4,"asteroid4/asteroid4.obj",0)
SetObjectposition(asteroid4,700,200,2200)
SetObjectRotation(asteroid4,0,0,0)
SetObjectScalePermanent(asteroid4,50,50,50)
LoadImage(asteroid4tex,"asteroid4/asteroid4_d.png")
SetObjectImage(asteroid4,asteroid4tex,0)
LoadObject(asteroid5,"asteroid5/asteroid5.obj",0)
SetObjectposition(asteroid5,-100,-1000,1500)
SetObjectRotation(asteroid5,0,0,0)
SetObjectScalePermanent(asteroid5,50,50,50)
LoadImage(asteroid5tex,"asteroid5/asteroid5_d.png")
SetObjectImage(asteroid5,asteroid5tex,0)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Player sphere and camera
// man1 (the player sphere) has 2 children, cam1 and cubechild (it's a strange family)
// cam1 is rotated 180 to man1 so forwards for man1 is now negative Z direction.
// this places 180 degrees in front of man1 and the 360 to 1 degree "jump" directly
// behind man1 and makes the radar dot jump from one side of the radar to the other.
// cubechild looks at the target and provides the angle relative to man1.
CreateObjectSphere(man1,5,6,12)
SetObjectVisible(man1,0)
SetObjectPosition(man1,0,0,-10000)
SetObjectRotation(man1,0,180,0)
SetCameraRange(cam1,0.1,5000000 )
SetCameraposition(cam1,0,0,0)
SetCameraRotation(cam1,0,180,0)
mypos#=CreateVector3(GetObjectX(man1),GetObjectY(man1),GetObjectZ(man1))
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx player sights
LoadImage(sightstex,"player/sights4.png")
CreateSprite(sightsprite,sightstex)
SetSpriteSize(sightsprite,height#/2,height#/2)
SetSpritePosition(sightsprite,width#/2-height#/4,height#/2-height#/4)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx player dash
CreateRenderImage(rendertex,512,512,0,1)
CreateSprite(rendersprite,rendertex)
SetSpriteSize(rendersprite,width#/8.5,height#/7.2)
SetSpritePosition(rendersprite,width#/3.224,height#-height#/5.5)
LoadImage(dashtex,"player/dash6.png")
CreateSprite(dashsprite,dashtex)
SetSpriteSize(dashsprite,width#,height#/4)
SetSpritePosition(dashsprite,0,height#-height#/4)
// cubechild looks at target and gets angle relative to man1 (player), used for radar blip positioning
CreateObjectBox(cubechild,2,2,2)
SetObjectposition(cubechild,0,0,0)
SetObjectRotation(cubechild,0,0,0)
FixCameraToObject(cam1,man1)
FixObjectToObject(cubechild,man1)
setobjectvisible(cubechild,0)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx radar blips
LoadImage(bliptex,"player/blip.png")
CreateSprite(targetblipsprite,bliptex)
SetSpriteSize(targetblipsprite,width# * 0.0045,height# * 0.007)
SetSpritePosition(targetblipsprite,width#/2-width# * 0.0505,height#-height#/7.58)
setspritecolor(targetblipsprite,100,255,200,200)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx target square
LoadImage(targettex,"player/targetbox1.png")
CreateSprite(targetsprite,targettex)
SetSpriteSize(targetsprite,height#/25,height#/25)
SetSpritePosition(targetsprite,width#/1.5,height#/1.5)
target=asteroid1
targetpos#=CreateVector3(GetObjectX(target),GetObjectY(target),GetObjectZ(target))
lookDist=200
help=1
man1X#=0
man1Y#=0
man1Z#=-10000
SetRawMousePosition(width#/2,height#/2)
setrawmousevisible(0)
do // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx MAIN LOOP
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx prepare scene for render to the target screen
SetRenderToImage(rendertex,-1)
SetSpriteVisible(targetblipsprite,0)
setspritevisible(sightsprite,0)
setspritevisible(dashsprite,0)
setspritevisible(rendersprite,0)
setspritevisible(targetsprite,0)
SetObjectPosition(man1,GetObjectX(target),GetObjectY(target),GetObjectZ(target))
SetObjectLookAt(man1,man1X#,man1Y#,man1Z#,man1AngleZ#)
MoveObjectLocalZ(man1,lookDist)
ClearScreen()
SetSpriteImage(rendersprite,rendertex,0)
Render()
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx set render to main screen
SetRenderToScreen()
SetSpriteVisible(targetblipsprite,1)
setspritevisible(sightsprite,1)
setspritevisible(dashsprite,1)
setspritevisible(rendersprite,1)
setspritevisible(targetsprite,1)
SetObjectPosition(man1,man1X#,man1Y#,man1Z#)
SetObjectRotation(man1,man1AngleX#,man1AngleY#,man1AngleZ#)
targetDist#=GetVector3Distance(mypos#,targetpos#)
RotateObjectLocalX(asteroid1,0.35)
RotateObjectLocalY(asteroid1,0.53)
RotateObjectLocalX(asteroid2,0.15)
RotateObjectLocalZ(asteroid2,0.33)
RotateObjectLocalY(asteroid3,0.43)
MoveObjectLocalZ(asteroid3,200.0)
RotateObjectLocalZ(asteroid4,0.35)
RotateObjectLocalY(asteroid4,-0.53)
RotateObjectLocalX(asteroid5,0.16)
RotateObjectLocalZ(asteroid5,-0.22)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx cycle through targets
if GetRawKeyPressed(84) // T
target=target+1
if target>8 then target=4
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx player
mouseX# = (GetRawMouseX()-width#/2)*0.003
mouseY# = (GetRawMouseY()-height#/2)*0.003
RotateObjectLocalX(man1,-mouseY#)
RotateObjectLocalY(man1,mouseX#)
// player click MMB to stop rotation and hold in for fine control
if GetRawMouseMiddleState()
SetRawMousePosition(width#/2,height#/2)
endif
SetVector3(mypos#,man1X#,man1Y#,man1Z#)
SetVector3(targetpos#,targetX#,targetY#,targetZ#)
SetObjectLookAt(cubechild,targetX#,targetY#,targetZ#,man1AngleZ#)
childXangle#=GetObjectAngleX(cubechild)
childYangle#=GetObjectAngleY(cubechild)
childZangle#=GetObjectAngleZ(cubechild)
// player roll
if GetRawKeyState(65)
RotateObjectLocalZ(man1,1)
endif
if GetRawKeyState(68)
RotateObjectLocalZ(man1,-1)
endif
// player speed
if GetRawMouseRightState()
man1speed = -50 // backwards is forwards
else
man1speed = 0
endif
MoveObjectLocalZ(man1,man1speed)
man1X#=GetObjectX(man1)
man1Y#=GetObjectY(man1)
man1Z#=GetObjectZ(man1)
man1AngleX#=GetObjectAngleX(man1)
man1AngleY#=GetObjectAngleY(man1)
man1AngleZ#=GetObjectAngleZ(man1)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx radar
// radar X blip movement
spriteXpos#=width#*0.449375+childYangle#*(width#*0.00027)
SetSpriteX(targetblipsprite,spriteXpos#)
// radar Y blip movement
spriteYpos#=height#*0.868+childXangle#*(height#*0.00105)
SetSpriteY(targetblipsprite,spriteYpos#)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx update target square
targetX#=GetObjectX(target)
targetY#=GetObjectY(target)
targetZ#=GetObjectZ(target)
if GetObjectInScreen(target)
if not GetSpriteVisible(targetsprite)
setspritevisible(targetsprite,1)
endif
TboxXpos#=GetScreenXFrom3D(targetX#,targetY#,targetZ#)
TboxYpos#=GetScreenYFrom3D(targetX#,targetY#,targetZ#)
SetSpritePosition(targetsprite,TboxXpos#-height#/50,TboxYpos#-height#/50)
else
if GetSpriteVisible(targetsprite)
setspritevisible(targetsprite,0)
endif
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SetObjectPosition(starsphere,GetObjectX(man1),GetObjectY(man1),GetObjectZ(man1))
framerate = ScreenFPS()
if GetRawKeyPressed(72) then help=1-help // key H for help on / off
if help
Print( " " + str(framerate))
Print( " H hide text")
Print( " width# "+str(width#)+" height# "+str(height#))
Print( " blipX "+str(GetSpriteX(targetblipsprite)))
Print( " blipY "+str(GetSpriteY(targetblipsprite)))
Print( " RMB move ")
Print( " T cycle targets")
Print( " targetDist " + str(targetDist#))
endif
// Update(0)
// Render()
// Swap()
sync()
if GetrawKeyPressed(27) then end // Escape key
loop
Never play leap frog with a unicorn.