Sunday, September 28, 2014

Hero Worship - Better Living Through Surfaces

Apologies for the lack of updates.  As the semester just started, I've been otherwise preoccupied. Students can be somewhat... needy.  Deservedly so.  In any event, I've continued to plug along.

I'm making decent progress on getting explorers/ soldiers into the game so the player can go on the offensive. Of course I discovered that since I don't want this to work like a traditional RTS, I needed to first work on how the player will cast spells.  Spells, which currently consume Mana (generic, I know.  Sue me!) will in part be used to suggest to the villagers places on the map to explore.  Think of it as a "Mission from God".  If anything interesting is discovered, I would hope to either have the villagers react appropriately, or perhaps give the player some more direct involvement.

Spells vs The Current Interface

But before I could get spells working, I had to rethink the interface a bit.  It was initially tied to the town center building.  Click on the town center and it brings up the build / cast interface.  Well, that's pretty stupid.  What if I have to build or cast something all the way across the map?  So I detached that functionality from the town center completely.  Click anywhere on the screen and you'll get the interface.  Move your mouse far enough away and the interface will disappear.  Click near the edge of the screen and the interface will offset so you can see the whole thing... most of the time.  There's probably a better way to make this work than what I came up with, but since I'm going to move to gamepad controls, I'll be redoing the whole thing again anyway.

Here's what it looks like now.  Active buttons highlight on mouse over and I added tooltips to explain what they do.   Standard Disclaimer about Programmer Art!!



The other thing I wanted to get working was the build distance limiter.  I decided to go with each new building extending the build area.  The logic to get it working wasn't too hard... still a quirk or two that I'll eventually work out.  But I want to make sure the player is absolutely clear where they can or cannot build.  Currently your cursor turns red when you can't build at a location.  It needed to be more obvious.  I first tried just drawing to the screen and while it worked, I kept getting strange visual errors.  I flailed around in color blending and other effects, but upon remembering someone recommending I investigate "surfaces" in game maker, I hit the websites to see if this was what would work.  And it was.

A surface is just another visual layer.  It's highly versatile, and from what I understand has low overhead.  I thought it was going to be complicated, but as I'm discovering more and more, you just need to take it one small step at a time.  Get one part working, make sure you understand what you did, and move on to the next bit.

Here's the script:

"overlay" is just a variable holding the surface I created for this task.

 surface_set_target(overlay); //need to tell GM which surface you are drawing to.
            draw_set_color(c_red);
                with(obj_buildings)//do this with all building in game
                {
                draw_set_alpha(.2);//my circles should be transparent
                draw_circle(x,y,buildRadius,false);
                draw_set_alpha(1);//set transparency back to normal
                }
            
            surface_reset_target();//done drawing to surface
            draw_surface(overlay, 0, 0);//now draw surface in the game

That's it.  It works!  See?
There's the build radius around the town center.  Note the house cursor is in red.

With a new house built, there's an additional area to put down this stoneworks building.

My little village is growing.  The workers are busy gathering wood and stone.