Seek and Destroy Mock Up - Overhead rotated Object field

Started by kevin, December 11, 2020, 08:09:55 AM

Previous topic - Next topic

kevin

  Seek and Destroy Mock Up  -  Overhead rotated Object field


      This code shows a method for doing top-down rotated sprite scenes.   Had to flip the axis to make it feel ok, but in a nut shell we're rotating the objects to the camera and working out their orientation at this rotation, then drawing the object as a rotating image.  

       To take this further, I'd render out the scene as sprites So i could just use sprite collisions to resolve intersections.  You can add height also, but it's not included here.  



Video




 
PlayBASIC Code: [Select]
; PROJECT : Seek and Destory - Mockup
; AUTHOR : Kev Picone - http://playbasic.com
; CREATED : 11/12/2020
; EDITED : 12/12/2020
; ---------------------------------------------------------------------


// -------------------------------------------------------------
// -------------------------------------------------------------
// ------------------>> SETUP MEDIA & DISPAY <<-----------------
// -------------------------------------------------------------
// -------------------------------------------------------------


// Load MEDIA from the PlayBASIC HELP files
Path$ =programdir$()+"Help\Commands\Media\"
global image_SHIP =loadnewimage(path$+"ship.bmp",2)
global image_BUBBLE =loadnewimage(path$+"bubble_64x64.bmp",2)




// -------------------------------------------------------------
// -------------------------------------------------------------
// ---------------------->> TYPES <<------------------------
// -------------------------------------------------------------
// -------------------------------------------------------------


Type tObject
x#,y# ; position in world space
Angle# ; Angle this is object is point
Rotation_Speed# ; Turning speed of object within scene
Endtype

// Scene contains 1000 objects
Dim Object(1000) as tObject


// define the Player / Camera as the same as the tOBJECT
Type tPLayer as tObject
EndType

Dim Player as tPlayer

player.x = 500
player.y = 500
player.angle = 0



// -------------------------------------------------------------
// -------------------------------------------------------------
// ---------------------->> MAIN LOOP <<------------------------
// -------------------------------------------------------------
// -------------------------------------------------------------

Main()

end


// -------------------------------------------------------------
// -------------------------------------------------------------
// ---------------------->> MAIN FUNCTION <<------------------------
// -------------------------------------------------------------
// -------------------------------------------------------------

Function Main()

setfps 60
initobjects()



do


// clear screen to the default colour of black
cls

// draw the objects in the view to the camera/players rotation
DrawObjects()


// move player forward/backward UP / DOWN keys
UpdatePLayer(2)


// draw player / camera info on screen

print "Player X:"+str$(PLayer.x)
print "Player Y:"+str$(PLayer.y)
print "Player angle:"+str$(PLayer.angle)


// Check if the ENTER key was pressed ?
if Enterkey()
// If it was, we spawn a new version of the
initObjects()

endif

sync
loop Spacekey()

EndFunction


// -------------------------------------------------------------
// -------------------------------------------------------------
// --------------->> UPDATE PLAYER FUNCTION <<------------------
// -------------------------------------------------------------
// -------------------------------------------------------------


Function UpdatePlayer(Speed#=2)

// Note the inverted controls
if upkey() then MoveFlag=-1
if downkey() then MoveFlag=1

if MoveFlag
angle#=wrapangle(Player.angle)
Speed#*=MoveFlag
x#=cos(angle#)*Speed#
y#=sin(angle#)*Speed#
Player.x+=x#
Player.y+=y#
endif

if leftkey() then PLayer.angle=wrapangle(Player.Angle,1)
if Rightkey() then PLayer.angle=wrapangle(Player.Angle,-1)


angle#=PLayer.angle

ViewPortCenterX# = getScreenwidth()/2
ViewPortCenterY# = getScreenHeight()/2

ScreenX#=ViewPortCenterX#
ScreenY#=ViewPortCenterY#

HandleX#=GetImageWidth(IMage_Ship)/-2
HandleY#=GetImageHeight(IMage_Ship)/-2


// Draw the player/camera
drawrotatedimage image_SHIP , ScreenX#, ScreenY#, 0, 2.0,2.0, HandleX#,HandleY#,true
Login required to view complete source code



Related examples:


     - Transplant