Jump to content

  • Log In with Google      Sign In   
  • Create Account






VaW progress: Week 6

Posted by SuperMaximo93, 21 September 2011 · 227 views

Hello once again!

This week, I've dabbled in a bit of scheduling, path finding, and map-editor-making...

Screenshot time:
Posted Image


It looks a bit more interesting this time! I've started to make a map editor, which at this moment in time is very primitive. The only thing you can do with it at the moment is put assets around the place. And when I press the reset button, it all disappears and we're left with the same thing you've been seeing for the past few weeks. But it's a start! To get into the map editor, just hit the '`' key (the one to the left of the '1' key), which allows you to enter Ruby commands via the terminal, and type 'start_map_editor'. To stop, do the same thing with 'stop_map_editor'.

I've added a scheduling system to the AI, inspired by Source Engine's thinking system. At a basic level, you can delay the AI run method from executing for a time using the delay method, passing the amount of time to delay in seconds. More interestingly, you can schedule functions to be called at a later time, by using the schedule method, passing the function to call and the time to delay the execution in seconds. You can use Ruby Procs, Lambdas, and class methods, like so:

class ExampleAi < Ai
  def this_works
    puts "This works!"
  end

  def init
    # scheduling the class method this_works to be called in three seconds
    schedule :this_works, 3.0

    # using a Proc
    this_also_works = Proc.new { puts "This also works!" }
    schedule this_also_works, 4.5

    #or just
    schedule Proc.new { puts "This also works!" }, 4.5

    # basically the same thing with a Lambda
    schedule lambda { puts "This works too!" }, 6.0
  end
end
An example of where this would be useful is when you might be running a bunch of stuff that needs to be done per frame, like moving along a path, in the run method, and then scheduling a function that checks the world conditions and modifies the current state of the AI depending on those conditions, so that the code in the run method will do something different. Or maybe you could schedule pathfinding every so often so that you can chase some guy who's running away without bogging down the CPU with pathfinding every single frame!

Speaking of pathfinding, that's another thing I've added. This is the first time I have actually dabbled with it! Before touching VaW, I decided to implement an A* algorithm in Pascal. I chose Pascal because the CRT unit is so useful for basic terminal graphics! I haven't found a C++ equivalent yet (although I can't say I've tried looking Posted Image). The first time I saw it work, even with a tiny wall separating the start and finish, was a big 'wow' moment for me! Here's a quick screenshot of the finished program:

Posted Image


Then I started implementing something similar for VaW. Rather than using grid spaces as nodes I've created a Node class so that I can put instances of them in optimal positions around the map. The only heuristic at the moment is the distance the current node is away from the end. I haven't really given it a proper test yet but I want to get the map editor up to a reasonable standard first, so that I can intuitively place nodes around the map rather than guessing and sticking them in various places via a script.

That's it for this week! Thanks for reading, and any comments are appreciated!

See you next Wednesday Posted Image

Max
@supermaximo93




September 2014 »

S M T W T F S
 1 2 3456
78910111213
14151617181920
21222324252627
282930    

Recent Entries

PARTNERS