MicroQuest – Adding the Unit

by marc 2. July 2008 06:01

Now that the map is displaying in the way we want, the next step is to add some kind of representation of the player or unit.

This is going to require a little bit more plumbing, as we haven't actually created a Unit object yet. And it's probably about time to think about tying things together in a representation of the GameWorld.

I've created a simple GameWorld class which will create a Unit and a Map (a List<Location>) when instantiated. At this point I've also implemented a Singleton utility class (found in C# 3.0 Design Patterns). I'm sure I don't really need a Singleton, but this implementation makes things easy for the time being, and can be refactored later.

I'm going to expose this GameWorld as an ObjectDataProvider to the WPF application in a resource dictionary. Here is the ODP:

I'm now making a few decisions about the content of the WPF application too. Here I'm beginning to create a series of resource dictionaries, which I'm splitting by general concern. This makes things a little easier to navigate and understand as the number of objects, styles and templates increases.

These are then merged in App.xaml.

To render a Unit on screen, we can add some more XAML to the MapViewer control. Notice here that I'm overlaying a new Canvas on top of the main panel, and then adding the Unit to that. This is for convenience, but also some separation of concerns in case I decide to alter either of these parts (or use them separately). This canvas and its contents have IsHitTestVisibile=false as I am only interested in using the Locations (Tiles) for interactivity though it will look like the Unit is interactive.

The MapViewer now plots a Unit as follows.

A quick change to the logic for Unit means it will initialise at X, Y = 2,2. We can bind up the properties on Unit as follows:

And we can see the rendered result.

clip_image008

At this point I decided to refactor some of the MapViewer bindings to a series of constants which allow me to change the size of a tile, and the dimensions of the map as I wish without impacting on the rendering and interaction logic.

Here are a few useful constants:

And here is an example of a binding to enable that flexibility. This means I can amend my 'real' GameWorld to 50px tiles on a 16x12 grid just by changing these parameters.

Next time we'll make the unit move around.

Technorati Tags: , ,

MicroQuest - A WPF GameWorld

by marc 1. July 2008 06:10

    In the last post, I cobbled together something that was serviceable as a pathfinding routine, and was left with the beginnings of some structures - such as Location and Unit - that would be needed in MicroQuest.

    In this post, we'll look at building the beginning of the WPF application that will represent the MicroQuest game, and start binding up the functionality to a user interface.

    Right now, I have two main projects in my solution:

    • The 'Engine' which is a UI independent domain model for the game (and so contains the logic and classes for pathfinding, units etc.)
    • The 'Viewer' which is a WPF application that will visualise the game world and provide an interaction model.

    There's also a test project, and a console app for some quick spelunking.

    We'll start small with the UI and build out some limited interactivity for the map before we think about game loops and the like.

    To interact with the map, I'm going to build a control (MapViewer) that will render the map correctly and respond to mouse interactions.

    I've wrapped the List<Location> structure as a Map, and then added a little functionality that will return a test map (simple 10x10 representation). In order to bind this to the UI, I'm hacking in some calls into the MapViewer for the time being.

    The MapCanvas is actually a ListBox at the moment (though I'm sure you can see where I'm going with this). So our application looks like this:

    clip_image002

    That's not a bad start. We just need to get the layout and rendering to look right. Shouldn't be a problem.

    In this case, I'm swapping from a ListBox (which offers stuff I don't need right now) to a plain old ItemsControl and then creating a panel template (a Canvas which sets it's Left and Top (i.e. X and Y)) and then a data template for a location which will be a button (as I want the Click event).

    clip_image003

    With the addition of this code, then the location list now looks as follows:

    clip_image004

    With the addition of a new button template (in this case just a green rectangle with a lighter stroke) we have the basis for a map.

    This is a little boring, so the next step will be to get our Unit rendered and then move on to interaction.

    Technorati Tags: , ,

Video Players

by marc 30. June 2008 08:06

The new BBC iPlayer Beta has impressed me. Not so much because it changes the general iPlayer experience in terms of play out, but simply because of the approach to releasing the software.

The new additions of recommendations, last played and the consolidation of radio and TV are helpful, but it’s more about the confident forward motion of the overall strategy that indicates a platform that has been well planned, executed and will be successful.

I don’t often think too hard about the player experience itself as it seems like a very normal thing to do on the web now. But I’ve been looking at some player stuff myself in the past couple of weeks, and with the iPlayer release and Tim Heuer’s work on a generic Silverlight player, I thought I’d see what the general breadth of player experiences looked like.

I’ve created a series of screen grabs on ScrnShots comprising the main UK broadcasting channels and then the list of stuff from the Wikipedia list of Video Sharing websites.

The similarity of each is striking, but hardly surprising, and it would make sense given the statistics that a player should have a similar control set to that of the YouTube player. There are nuances in the behaviours of each of course – particularly in the non-core features (sharing, rating/ranking, advertising) that are still up for grabs in some respects.

So which is my favourite? Ultimately I’m familiar with YouTube and am drawn to that and I like the Hulu player, but actually I think Vimeo is the best. Chunky, friendly and simple. Just like me.

Anyway, maybe there’s some inspiration for you in the list. I’d be interested to know which players I’ve missed and which you prefer.

Technorati Tags:

MicroQuest – AStar Pathfinding

by marc 25. June 2008 10:22

The first thing I want to be able to do in MicroQuest is move my "unit" around the "game world". So I need to establish a mechanism for the movement of the unit.

Given this is a tile based game then it seems obvious that my unit can move a certain number of tiles per turn. Taking my cue from GBA games such as Advance Wars then those games use (at least something similar to) the A* algorithm to perform pathfinding and costing on a map. I just need to code up a generic A* algorithm (it won't be super optimal) to provide the movement capability for my unit.

The AStar class only needs to perform one job, and that is to solve the current path from a starting location to a goal location.

I'm not going to describe how the AStar algorithm works - you can see that in the Wikipedia article, suffice to say that it relies on a sorted set of costs for a given 'node' in a search space (in other words, a tile on the map has a cost which is an assessment of its value as a possible solution).

To make AStar efficient, we try to ensure that we trim the available set of nodes such as those that have already been evaluated. These are kept in the lists of open and closed nodes. So, our AStar class looks like:

AStar

The costing algorithm can vary according to need, but the easiest heuristic for a square tile map is that of 'Manhattan Distance' which calculates how many blocks away from a goal a given node is using some basic maths. (In a regular space, then Euclidean Distance may be preferable). I've implemented this as a simple strategy pattern. Not so much because I'm likely to change the algorithm: just for clarity/intent.

ManhattanDistance

The 'Node' is the main class we need. A node essentially wraps a tile on the map (which I'm calling a Location at this point, as Tile has UI connotations).

A Node knows where it is (from its Location) and can assess its cost. This is described as f = g + h which means: total cost = cost so far + estimated cost to goal.

clip_image003

It's important to understand the cost so far and the estimated cost separately as the actual cost may differ from the Manhattan distance heuristic. (For instance, on a tile map, the tiles may have differing movement costs representative of the 'terrain' of the tile).

Finally, a Node can return its 'children' (or neighbours I suppose). And it can generate the path from itself to its origin.

clip_image004

Node

LINQ comes in really handy here as you can see. The GenerateChildren method doesn't just return all possible children. It will also trim that set for those locations that are not passable (obstacles or some such).

 

 

 

 

 

 

 

 

This leaves the core of the AStar Solve method looking something like:

clip_image006

Finally, the GetPath method on a Node will return a list of co-ordinates (it could also just return a list of nodes, or locations. That may be helpful later on but this will do for now.

clip_image007

Testing this is straightforward. Creating a simple 10x10 map and then solving various paths (with and without obstacles) are the basic tests needed.

clip_image008

Now this is written, I need to be able to interact with the map in a UI and build on the work so far thinking about Locations and Units. So I'll kick up a WPF application to do just that.

In the process of this, I came across this excellent guide on AStar from the smart chaps at Vertigo. I toyed with the idea of using that implementation, but decided I didn't need the flexibility that it offered and I was also keen on implementing AStar as I understand it which is not necessarily the correct way, but it works for me... ;)

Ah, and then I discovered Eric Lippert's 4 part series on implementing A* in C#3.0. Oh well, done now!

 

Technorati Tags: , ,

Embarking on a MicroQuest

by marc 25. June 2008 06:27

In a previous post I talked about inspiration and decided that I'd spend more time 'just coding'. This series of posts on 'MicroQuest' will be about my adventures doing just that.

It’s sort of a vague attempt to copy from the master (Andrew Braybrook of course!) and keep a diary on the creation of a simple game (from the point of view of someone who doesn’t know how to do it…). I like game programming because it saves me having to think about real-life troubles (such as integration) and allows you to construct a domain model from scratch.

About MicroQuest

This is a bit of an exploration, so I haven't fully formed exactly what MicroQuest will look like when it's finished, but a few principles for how it will work:

  • A turn-based game (so I'm not concentrating on game loops and perf and stuff)
  • A tile-based game (lends itself to layout and controls in WPF)
  • A little bit of online/multiplayer stuff - I have some ideas on this which I'll think about later.

I want to create a game that's a little RPG-ish, and a little Strategy-ish. Influences are Advance Wars, Golden Sun and Fire Emblem on the GBA. I've done some of the basics of coding for this a couple of times using GDI+, but this will be the first time using WPF.

The game loop will be something like:

  • From 1 until x turns (x will have a concrete number)
    • Move, Check for Events, Combat, Check for Events, Action, End Turn
  • At x turns, assess achievements and ranking

About Technology

I'm going to use WPF to create my game. It's not the technology I should probably choose - maybe I'd be better off using XNA. Actually I'd probably be better off using Popfly Game Creator...

But the point here is to flex my general coding skills with the mainstream techs such as WPF and Silverlight, and the surrounding technologies such as LINQ, Astoria and all that.

And have some fun along the way.

Finally

I'd be happy to put this on CodePlex or similar if anyone is interesting in contributing. Feel free to contribute some graphics too. Best set gets to decide the actual game!

 

Technorati Tags: , ,

Feedback on A-Z Architecture Article

by marc 11. June 2008 05:46

We (myself and Mark) have been really pleased with the feedback we’ve received on the A-Z article we published in the Architecture Journal. We had some very kind and constructive emails and we saw this on the web too:

Anyway, it seems to have resonated with some, and given we like writing about this sort of stuff, then let us know what else you’d like to think about.

Technorati Tags:

Takeaways from Architect Insight

by marc 2. May 2008 09:57

I quite enjoyed Architect Insight this year - lots of useful sessions, and in particular the keynotes - which were mainly thinking about the issues surrounding the delivery and scaling of cloud services - were engaging and interesting.

If you were there, hopefully you enjoyed my session with Paul Dawson from Conchango - thanks very much Paul! - thinking about user experience for consumers and enterprise users.

The main things I took away this year:

  • AtomPub is important. There's a lot of standardisation of Microsoft services on AtomPub and it seems to me that it will be increasingly important to understand and use this.
  • POA. A new acronym: "Pod-Oriented Architecture". A Pod is defined as a unit in a datacenter capable of running an entire cloud service. So, to scale out, you just keep adding new pods.
  • Brewer's Conjecture. This is the notion that one of Consistency, Availability or Partition Tolerance has to be traded away when designing distributed/cloud systems.
  • Simon Thurman's 20/20 (20 slides lasting 20 seconds each) format session was very successful.
  • Thinking about the use of cloud services from an enterprise perspective is a challenge.

An A-Z of being an Architect

by marc 22. April 2008 12:25

Architecture Journal 15 has just been released. Myself and Mark Bloodworth have contributed an article to this issue: "An A-Z Guide to Being an Architect".

Hope you enjoy it! We'd be really happy to hear your feedback and alternative A-Zs.

Web Sites with MOSS

by marc 1. April 2008 15:33

Working with a customer the other day it came as a bit of a surprise to me that they didn't realise that MOSS (SharePoint in old money) could be used as an externally facing website. But it certainly is.

Take a look at:

It's worth weighing up the value that MOSS may bring to a web site development in terms of framework, workflows, and all of the familiar collaboration capabilities.

Technorati Tags: ,

Real-time/Push Data to HTML with Sockets and Silverlight

by marc 18. March 2008 10:07

Silverlight is, of course, great for providing a rich UI. But as it brings the power of .NET to the browser, it is interesting to consider how it can be used to enhance a web page in other ways. I've put together a quick 'Marchitecture' on doing just this...

The article and demo explains how to use a ‘headless’ Silverlight 2 solution to deliver ‘real-time’ or ‘push’ data into a browser.

HTTP is inherently a pull mechanism: make a request, receive a response - and so it is difficult to provide real-time data to an HTML page. Some of the limitations of HTTP can be overcome through the use of a long-lived HTTP connection allowing the streaming of real-time data to a client browser. This solution is an unconventional use of HTTP and may suffer from reliability problems. The following pattern describes ‘HTTP Streaming’: http://ajaxpatterns.org/HTTP_Streaming

Silverlight 2 has socket-based networking capabilities that can be used for this task in a more appropriate fashion. We could write a Silverlight UI that renders the data from the socket-based service, but we may not wish to amend an existing UI. So, if we combine the sockets capabilities with the Silverlight 2 HTML Bridge means that an existing web site can be integrated with Silverlight to provide true socket-based communication without the need to create a ‘Rich Internet Application’ UI, but still providing the ‘push’ capability.

image 

Read the whole thing and download from here.

Powered by BlogEngine.NET 1.4.0.0
Original Theme by Mads Kristensen and adjusted by me

About the author

Marc Marc Holmes
An Architect Evangelist at Microsoft

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008