Results 1 to 2 of 2

Thread: Scrolling Map RTS

  1. #1
    Join Date
    Nov 2011

    Default Scrolling Map RTS


    Novashell seems to have the basic features I need to create an Isometric view RTS, with ability to add functionality using Lua or C++ scripts. So kudos.

    Anyway, I need to find a way for a large map to "scroll" when the mouse hits the edge of the visible screen.

    I have made an appropriate map and a "cursor" entity bound to the mouse. I figure to do the scrolling, it would need to get the position of the cursor and scroll the camera there as it attempts to leave the screen boundary, revealing the map there.

    The only examples I could find included the camera keeping the entity centered on the map for the most part.

    Any suggestions?

  2. #2
    Join Date
    Nov 2011

    Default Almost there...

    Ok, so I figured out how to attach an animated cursor to the mouse pointer (mod of Beer Invaders example):

    function Update(step)--this is run every logic tick (a minimum of 60 times a second of game-time).
    	ProcessMovement(); --update this function every tick
    function ProcessMovement()
    	if (m_vLastMousePos != GetInputManager:GetMousePos()) then --GetMousePos returns Vector2(x) and Vector2(y).
    		m_vLastMousePos = GetInputManager:GetMousePos(); --this updates mouse position if its moving.
    		this:SetPos(m_vLastMousePos); --sticks cursor to mouse. not working correctly when out of 0,0 or 1:1
    the cursor can call an entity (npc soldier, asset, structure, whatever, as long as its an entity) making it display its name or ID, cursor also displays map coordinates upon choosing an empty location (using Novashell Scripting Reference example):

    function OnMouseLeft(bKeyDown) --handles mouse clicks for cursor
    	LogMsg("Cursor OnMouseLeft"); --I want to see when this function is called in the console.
        if (bKeyDown) then
            --LogMsg("You pressed the left mouse button down."); --we want output on release not depress.
    	local vPos = ScreenToWorld(GetInputManager:GetMousePos());
    	local pt = ScreenToWorld(GetInputManager:GetMousePos());
    	local ent = GetEntityByWorldPos(pt, this, true); --get all entities but ignore ourself, be pixel accurate
    		if (ent != nil) then --what entity is the cursor hovering over?
    			this:SetAnimByName("select"); --make the cursor have animation on select
    			GetTextManager:Add(ent:GetName() .. " Standing By", ent); --verify communication
    			GetTextManager:Add(tostring(vPos), this); --display world coordinates above cursor
    			this:SetAnimByName("idle"); --reset the cursor animation because we are selecting nothing
    	return true; --keep calling callbacks for this keypress.
    Note: the cursor is technically the player, as all other entities on the map are essentially npc's. I copied a script icon from System Palette and assigned it to be the player. Cursor entity had to be pasted directly on the active map instead of in a placeholding palette (like a palette just used to store images like in the Dink example), as it caused the cursor to double its text output on left click unless it only has a single instance running. No big deal.

    I attempted to add functionality to scroll the map when the cursor touches the edge, but it doesn't work correctly yet. For some reason the above code to "stick" the cursor to the pointer only works in 1:1 zoom and when the camera is at 0,0. Otherwise, it just rips the cursor off the pointer for some reason. I don't see anything that restricts the cursor image to that part of the map, so until I figure it out, I won't bother posting my hacked up test code.

    Oh, and I also have little "foot soldier" animations (only walk and attack for now) that work perfectly, but I have yet to perfect the script to make the soldier move to a valid map world coordinates using the cursor. I imagine it would have to be in the cursor script or an external script (like maybe select.lua or something), as the soldiers all run off the same script, so they would ALL run in the same direction simultaneously and there would be no way to tell each individual entity to perform a unique task from the npc code (that I know of).

    I'll update here when I figure it out. Sorry if this is too long of a post. I hope this helps anyone trying to do the same types of tasks.

Similar Threads

  1. Scrolling in RTSimpleApp
    By BigBMan in forum Proton SDK
    Replies: 4
    Last Post: 12-10-2010, 04:40 AM
  2. Screen scrolling
    By Blint in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 08-21-2008, 08:40 PM
  3. scrolling shooter...
    By harrio in forum Novashell Game Creation System
    Replies: 2
    Last Post: 02-19-2008, 02:17 AM
  4. Scrolling to optimize?
    By Snakesoft in forum Novashell Game Creation System
    Replies: 6
    Last Post: 03-28-2007, 11:57 AM
  5. Strange scrolling bug in OSX version:
    By whisperstorm in forum Novashell Game Creation System
    Replies: 3
    Last Post: 03-22-2007, 05:20 AM



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts