How would you make a radar system?

Smart Alec answer , by modifying the code to do that.

_ Honest answer _… I wrote that code a LONG time ago and can’t afford the time to answer this question.  However it is well commented so I think you should be able to work this out.

All it took was some basic math :0

--enemyHUD.lua createHUD = function(...) theHUD.object = centerObject end updateHUD = function( self ) -- localize for speedup local cx = theHUD.cx local cy = theHUD.cy local objectOffsetX = (theHUD.object.x - display.contentCenterX) \* theHUD.distScale local objectOffsetY = (theHUD.object.y - display.contentCenterY) \* theHUD.distScale local squareRadius = theHUD.radius2 for k, v in pairs( currentPips ) do local x = k.x - cx local y = k.y - cy x = x \* theHUD.distScale + objectOffsetX y = y \* theHUD.distScale + objectOffsetY v.x = x v.y = y -- Hide the pip if it is 'off radar' (beyond the HUD radius) v.isVisible = squareRadius \> vecSquareLen( x, y ) end end --levelmanager.lua local M = {} function M.createLevel(radarGroup, group, numOfAsteroids) masterM.enemyHUD.create(radarGroup, nil, nil, 100, display.contentHeight \* 1.5, nil, nil, player) end return M

Is there anything I can/should do to make it better? I mean, I am quite satisfied for now. :slight_smile:

Oh wait, something’s wrong…

If you’re happy, that is enough.  Glad you figured it out!

Nope, this is not done yet. There is something wrong with the radar, I need to figure out why though.

Wait, never mind I got it now.

Again thank you so much for the HUD system, I can wrap this topic up now.

Hi! By the way, I’ve made a little graph explaining how I would structure this code. It’s rough at the moment and needs extra explanation. I plan to do a tutorial on this soon, but for now it might already help to start.

It basically show how you can create a tree of objects all as children, grandchildren etc… of “appEngine”, and have them talk to eachother up and down the hierarchical tree by using “super”. Or course this means you need to pass each parent object to each child when creating a child object (and calling it self.super in the children). Like I said, it needs a lot of work but might alright shed some light on code architecture logic.

Thanks, this will be quite helpful in my game.