Jump to content

Minimap


havenphillip
 Share

Recommended Posts

    if              enemyDrawX >= x and
                    enemyDrawX <= self.miniMapSize.x and
                    enemyDrawY <= self.miniMapSize.y and
                    enemyDrawY >= y then

 

I'm trying to get this to work but it's eliminating all the dots. Maybe something in my script that I did somewhere that negates it? Or maybe is there a way to say "not greater than"? Like a ~>? I tried but figured probably not.

Mini Map.lua

Link to comment
Share on other sites

Ah that would not work I see now. Can you undo the if statement with the last changes and make a screenshot of what your are currently seeing.

That last if statement is also confusing me a little since I would not expect any enemies to found outside the drawing rectangle. But perhaps with an offset here and there, some enemies might slip through. Alternatively the calculation for drawing the enemy pos is not correct.

Everything so has been from the top of my head. If you want I can have a look at your project. Can you send the project via pm? (excluding assets I do not need.)

 

Link to comment
Share on other sites

Actually this is working pretty good. It's close to perfect. Maybe you can explain why. Instead of x and y I used dotX and dotY which I made in order to get the zoom to work right. Originally the dots were sort of "slipping" over the terrain and that's fixed:

    --set enemy entities dot color and position
    local miniMapEnemySize = Vec2(self.miniMapSize.x/25,self.miniMapSize.y/25)
    --local radarHalf = self.miniMapSize.y/2 * (self.miniMapSize.x), self.miniMapSize.y/2 * (self.miniMapSize.y)
    local radarHalf = Vec2((self.radar / 2 / self.radar) * (self.miniMapSize.x), (self.radar / 2 / self.radar) * (self.miniMapSize.y))
    local dotX = (self.miniMapSize.x / self.cameraRng / self.zoom)
    local dotY = (self.miniMapSize.y / self.cameraRng / self.zoom)

    for k, v in pairs(self.enemyEntities) do
        if self.enemyEntities[k].script.enabled == true then
            if self.enemyEntities[k].script.mode ~= "dying" and self.enemyEntities[k].script.mode ~= "dead" then
                enemy = self.enemyEntities[k]:GetPosition()
                enemyDrawX = dotX * (enemy.x - pos.x) + radarHalf.x
                enemyDrawY = dotY * (pos.z - enemy.z) + radarHalf.y

                if   enemyDrawX > dotX and
                    enemyDrawX <= self.miniMapSize.x and
                    enemyDrawY <= self.miniMapSize.y and
                    enemyDrawY > dotY then
                
                    context:SetColor(1,0,0,1)
                    context:DrawRect(x + enemyDrawX, y + enemyDrawY, miniMapEnemySize.x, miniMapEnemySize.y, 0, 1)
                end
            end
        end
    end


Yeah, man. You can check out whatever I got. I don't have a game, per se, but I'll send you my whole project. I'm mostly just learning Leadwerks and getting the basics of making a game. But whatever I got you can check out, but you'll have to explain to me how to send a project through pm. I don't even know where the pm button is lol. 

One last thing is that the minimap shows my other HUD elements inside the minimap. I don't know of any way to get rid of that but I would love to get rid of it. It's workable as is but it's one of those little annoyances in the back of my mind.

Here's the most recent version:

 

Mini Map.lua

Link to comment
Share on other sites

Oh ok. It's no problem but you may have to explain to me how to do that. I'll look it up and see if I can figure out .zip files. But the code should work in any project so long as you put "GetKeyValue("type","enemy") in your enemy scripts (you can use crawlers) and have the code attached to a pivot and childed to a player, and have the shader at the bottom of the code named right and in the right folder..But whatever you want, man. I appreciate your help with this. I'm totally stoked on it!

I'm going to go see if I can figure it out...

Link to comment
Share on other sites

Sorry hadn't had time to look at the project yet.

On 2/20/2018 at 5:28 PM, havenphillip said:

One last thing is that the minimap shows my other HUD elements inside the minimap. I don't know of any way to get rid of that but I would love to get rid of it. It's workable as is but it's one of those little annoyances in the back of my mind.

As for the UI being drawn inside the minimap: disable all UI widgets before rendering the world for the minimap. In you minimap script do something like:

DisbaleUI()
world:Render()
EnableUI()

The documentation contains a Hide and Show function for widgets you can use for this. https://www.leadwerks.com/learn?page=API-Reference_Object_Widget_Hide 

Link to comment
Share on other sites

Ok I did this but it didn't work. I'm still trying to understand but it looks like the minimap takes a snapshot of the screen right at the start and renders it from the top view? So wouldn't I have to delay the healthbar, etc. within that code? Seems like delaying the minimap wouldn't work.

in Minimap:
function Script:UpdateWorld()
    if     self.toggle==0 then
        self:DisableUI()
        world:Render()
        self:EnableUI()
    end

function Script:DisableUI()
    self.player:Hide()

end

function Script:EnableUI()
    self.player:Show()

end

Link to comment
Share on other sites

Are you using Leadwerks widgets or just drawimage etc? Can you post a screenshot of what is going wrong? I can't see the hud being drawn in the minimap.

So during the update, your player camera is placed in the sky, rotated so that it looks down and then what the camera sees is being stored in a buffer. this buffer will result in to the minimap texture drawn on to the screen.

Link to comment
Share on other sites

Yeah I'm using the FPSPlayerStatusBar from the workshop and if you zoom out the minimap (down arrow) the health bar and stamina and ammo and the minimap itself can be seen in the minimap. I noticed the health, stamina, and ammo shown in the minimap don't change which leads me to conclude that it takes a snapshot of the first frame of the player cam, which I presume is what you mean about saving in a buffer.

 

minimap second buffer.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...