Red Nose Day MonoGame Video Now Online - with Tutu Action

"Because the world definitely needs a man dressed in a tutu explaining how to create video games....."

After a bit of time learning how to use Adobe Premiere again (I learn to use it every time I have to make a video - at six month intervals) I have now got the recording of the Red Nose Day lecture ready for the waiting world.

You can choose to regard it as either a "Poetic masterpiece combining rhyme and technical achievement in a single, flawless whole" or "Twenty minutes of my life I won't get back". Whatever.

But if you do get anything out of it, please throw some money my way by visiting here:

http://my.rednoseday.com/sponsor/robmiles

Three Thing Game Finals

Hardy survivors...

Hardy survivors...

We had our Three Thing Game competition over this weekend. Just in case I wasn't busy enough writing poetry and whatnot. Anyhoo, great fun was had. A team of stalwart judges, including developers from Smashed Crab Studios, went through the final 17 teams and found us 6 finalists. As is the way of the competition, we had each team present their game at the aptly named finalist presentations. And here they are in no particular order.

Team: "I hope my friends don't bail on me"

Team: "I hope my friends don't bail on me"

Team "I hope my Friends don't bail on me", AKA Jason Powney, showed off the mayhem he had created from "chainsaw", "penguin" and "water". "Penguin Chainsaw Massacre" had tons of bloodthirsty action, with underwater mine hazards and even a sunken wreck. A very polished production.

Team: //TODO

Team: //TODO

Team //TODO, aka Daniel Masterson, had started of with "ASCII art", "sanctuary" and "error" and built, to our amazement, a 3D rendered graphical game displayed in a console window using text graphics. Something of an awesome technical achievement we reckoned. And the game looked fun to play too.

TEAM: aNOTHER BAD IDEA

TEAM: aNOTHER BAD IDEA

Team "Another Bad Idea", aka Robert Chisholm and Adam Thornes had crafted a very neat top down fighting game from "Toilet Plunger", "Small Mammals" and, not surprisingly, "fighting". The game had frantic one on one action as the players acted out the eternal struggle between fox and rabbit using toilet plunger weapons.

Team: You Will Lose

Team: You Will Lose

Team "You will Lose", aka Joseph Edwards and Tomasz Kope,c had turned up the particle generators to the max and produced an atmospheric game based on "square", "random" and "shooter". Some nice coloured effects and randomly generated play areas made for good looking gameplay.

Team: One Musketeer

Team: One Musketeer

 Team "Four Musketeers" was down to one musketeer by Saturday lunchtime, but that didn't stop them producing a very neat four player shooter game from "Scrapper", "Wombat" and "Hull". The action was fast and smooth, with multiple weapons and you could even use the gun to jump. Can you spot how the thing "Hull" was used?

Team: Bad Computer Pun

Team: Bad Computer Pun

Another technical tour-de-force from team "Bad Computer Pun, aka Nick Ross. We advise our students to use Three Thing Game as a place to test out hew game engines and Nick had certainly done that. Matlab is a serious mathematical package designed for serious mathematical stuff. Not for writing games. But the power of Three Thing Game compelled Nick to go against this and craft what is probably the first ever computer game written in Matlab. It is definitely the first ever Matlab game that involves "ostrich", "oasis" and "escape". And it looked pretty good too.

I didn't envy the judges their job as they went out to pick the winners. Thanks go to Warren Viant, Derek Wills, Lindsay West, Jon Purdy, David Parker and the Smashed Crab crew for giving up a Saturday afternoon to help out. Anyhoo, after much detailed discussion they come up with a first and second places, plus a technical achievement award.

Pic1 (17 of 25).jpg

First place went to "I hope my friends don't bail on me". The game was commended for the high quality of gameplay, completeness and the way it had stuck very well to the three things.

In second place we had"Another Bad Idea". Their game was singled out for the fun multi-player action and great looking graphics.

Pic1 (25 of 25).jpg

The award for Technical Achievement goes to //TODO. You just don't expect people to use shaders in ASCII art games. Awesome stuff.

I'm going to be chasing the teams for videos of their games and I'll update this post with more details when I get them.

Thanks to all the judges, to Lee Stott from Microsoft and Simon Jackson from MonoGame for dropping by and taking a look. And thanks to David Glover for making the Fenner Lab work so well and allowing us all in.

The next step for the teams is to get their game published. I'm going to be running some sessions about game publishing, keep an eye out for them.

Making a Universal MonoGame Project

At one of the sessions earlier this week we were talking about game development and I found out something really interesting. Thanks to Giles for passing me the link.

If you want to make a MonoGame solution that contains a Universal Application for Windows Phone 8.1 and Windows 8.1 you can find a build of MonoGame that contains templates that just work here.

You can deploy to phone or pc just by setting the start project. The distribution also contains the new content management stuff. I'm going to make an example application and a little screencast about how to use it when I get back to the UK.

This is completely wonderful. It will make it so much easier to make games which will be rady for both the Windows Phone and the Windows stores.

Return of XNA

Now here's a sight for sore eyes

Now here's a sight for sore eyes

I've mentioned this before, but I think it is worthy of mention again (since I've just done it and it works really well). If you are running later versions of Visual Studio (2010, 2012 or 2013) you can now get XNA goodness onto your machine really easily. Download the files from here and then just follow the instructions in the readme. Once you have installed the four components,  run the Visual Studio Extension file (don't do this first, that will end badly) and you can get a cornflower blue screen of your very own. 

Marvelous. 

XBOX 360 for Education

xbox360Education.JPG

Now, those of you with long memories will recall that XNA is a C# game development framework that is a great way to teach how to program by writing silly games. It was released way back in 2006. I've used it in our teaching ever since, written three books on the platform and I even spoke at the launch event in the UK.

You could say I rather like it.

Unfortunately, not everyone at Microsoft does (or did) and it was recently "sunsetted" or whatever the trendy name is for "made not really around any more". This was sad, but it would have been even sadder if that had been the end of the story. Fortunately, because of those wonderful folks at MonoGame, the framework lives on in a form that makes it possible for programmers to take their XNA skills and use them to make iPhone, Android, Playstation Vita, Windows Phone and Windows 8 games. And that's where the story was until today.

Microsoft UK have just done something very interesting. They've put together a package of hardware, software and educational materials that makes it very easy to set up a course that teaches programming and game development using XNA on real console hardware. And the fun thing for me is that they are bundling in all the XNA teaching materials that I've written over the years.

You can find out more, and sign up, here.  (although I must admit the website mystifies me at the moment, as I've no idea what a "Microsoft Volume Licence Agreement Number" actually is). However, Lee Stott will be able to help I'm sure. If you just want my XNA book you can find it here.

xna banner.JPG

As a kind of celebration I've dug into my copious archives and found the first video of a set I made ages ago for a local video game webzine. It is a little bit out of date (Visual Studio 2008 anyone?), but still mostly valid. If you want to see the rest of the series (it's worth watching just for the animated titles - in XNA of course - and the catchy theme song) then let me know and I'll transcode and upload them. Enjoy. 

What use is a structure?

DSCF1594.jpg

It is exam season here in Hull. Later in the week we have our programming exam. And I’m getting quite a few questions through about C# and stuff. Today I got asked the question “What use is a struct?”. I’ve been spending a lot of time talking about classes and references and how clever they are, and someone wants to know why, if classes are so wonderful, some objects in a program are managed by value. The answer is simple enough. It is because sometimes you really want a value which you can just copy around easily.

Consider the Rectangle type in XNA. We can use this to represent the position and size of something on the screen. And this is a struct, not a class. Take a look at this code:

a = b;
a.X = 99;

If a and b are both Rectangle variables the effect would be to set a to the value in b and then move the X position of a to 99. This would not affect the position of b.

If the Rectangle type was a class then we would have two references, a and b, that both refer to the same object in memory, so moving a would affect b as well. If we want to place objects in lots of different positions on the screen, and we don’t want them to be linked in any way, then structures managed by value is the way to do it.

Note that things like Textures are managed by reference. This makes a lot of sense too. An image is a large thing, and it is often very useful to be able to share one image for a whole bunch of things. Think multiple sprites in a space shooter. They will have a Rectangle value to give them a unique position and then a reference to a texture that they all share, to give them an appearance.

The XNA framework is full of objects that are actually structures because they work better this way. For example Color, Point and the Vector objects are all structs so that we can manage them by value. In fact, now that you know how it works, you should be able to look at any XNA type and figure out whether it is a class or a struct, just based on how it is used.

Sprites and Distances

Space Killlers Backdrop

At the moment quite a few of the first year are working on a “Space Killers” game. Above you can see my sample screenshot from the specification. You can see that my graphical design abilities are around the same as usual.

The idea is that the player (the green object) must survive in brightly coloured space while all around are trying to kill. Collision with any game object is instant death. Survive until the clock counts down to zero and you are rewarded with another level with more, and nastier, things in it.

One of the game objects is the “Master”. This is the one that looks a bit like a fried egg in the above screenshot. (Note to graphics department, fix that please).

Anyhoo, a Master sprite will sit and do nothing unless you get too close. Then it wakes up and chases you. To make this work the game needs to be able to work out how far the master is from the player. In my solution I have a sprite class:

public class Sprite
{
    public Texture2D SpriteTexture;
    public Rectangle SpriteRectangle;
    public Vector2 SpritePosition;
    public Color SpriteColor;
}

This contains stuff that we need to position and draw the sprite. The Update method for the parent sprite just uses the position vector (which I use to decide where the sprite is on the screen) to set the SpriteRectangle value (which I use to decide where to draw the sprite).

public virtual void Update(SpaceKillersGame game)
{
    SpriteRectangle.X = (int)(SpritePosition.X + 0.5f);
    SpriteRectangle.Y = (int)(SpritePosition.Y + 0.5f);
}

My sprite also contains another method, DistanceFrom, which is used by code in the Master sprite to decide how close it is to the player.

public float DistanceFrom(Sprite otherSprite)
{
    float dx = SpriteRectangle.Center.X -
               otherSprite.SpriteRectangle.Center.X;
    float dy = SpriteRectangle.Center.Y - 
               otherSprite.SpriteRectangle.Center.Y;
    return (float) Math.Sqrt((dx * dx) + (dy * dy));
}

This is how it works. It turns out that the Rectangle class contains a Point value which gives the coordinates of the centre of the rectangle. I can use the X and Y components from this to work out the difference in x and y between the two rectangles. I can then use Pythagoras Theorem to work out the distance between the sprites. Pythagoras said “The sum of the squares of the sides of a right angled triangle is equal to the square of the hypotenuse”.  My code works out the sum of the squares and then takes the square root of this to work out the distance value.

image

Hopefully the above diagram will make it all clear. If not, just enjoy the pretty colours.

My Master sprite then contains the following statement in its Update method (Update is called on the sprite to make it update itself. It is given a reference to the game that is currently active).

if (DistanceFrom(game.Player) < MasterRadarRange)
{
    ChaseActive = true;
}
MasterRadarRange is a value which controls how far the Master can “see”. If a player gets closer than the radar range the flag ChaseActive is set to true, which triggers the chase behaviour in the Master sprite.

XNA Resources Follow-up

DSCF1380_1_2.jpg

Further to the talk on XNA earlier this week, some folks have been in touch for any other XNA references that I might know of. Here are a couple.

You can find a complete course which teaches programming using XNA at Microsoft Faculty Connection here. There are slides, labs and all kinds of good bits and bobs that you an asset strip and use as the basis of your teaching.

My Microsoft Press XNA 3.0 book (not the most recent, but still good for getting started) can be found as a free download from here.

All of the stuff will work on MonoGame too.

Windows Gaming Awareness Event

DSCF1395.jpg 

A great audience. I kind of have to say that because I’ve not left Birmingham yet. Although they actually were a great audience.

Just done a talk at the Windows Gaming Awareness event about XNA and MonoGame.Great fun. Well worth getting up at 5:45 am to catch a train to Birmingham to deliver. You can find all the content here.

It has also been very interesting to see what other gaming tools and techniques there are out there. I’m going to have a play with quite a few of the things that have been discussed.

Game State Management in MonoGame on Windows 8

ApplicationLog

I’ve been trying to make sense of how Windows 8 and MonoGame interact when the application changes state. I think I’ve figured it out.

There seem to be broadly two things that can happen to your game when it is running. It can get deactivated (the user finds something better to do) or it can get “snapped” to the side of the screen. If you are going to sell the program in the marketplace it needs to handle both these situations.

protected override void OnActivated(object sender, EventArgs args)
{
    addMessage("activated");
    base.OnActivated(sender, args);
}
protected override void OnDeactivated(object sender, 
EventArgs args) { addMessage("deactivated"); base.OnDeactivated(sender, args); } protected override void OnExiting(object sender,
EventArgs args) { addMessage("exiting"); base.OnExiting(sender, args); }

To handle the activation issues you override the event methods above. I’ve just put some logging code in so that I can work out what is going on. The events are fired when you would expect them to be. When the game starts you get an “onActivated” message and when anything happens to interrupt your game (for example the user minimises it or switches to another application) you get a “onDeactivated” message. At the very end, when the user quits your game you get the “onExiting” message. The activated and deactivated message come in matched pairs. The only slight trickiness is that a game will get an activated message at when it starts and when someone returns to it, but you can use a variable to keep track of this.

When your game is deactivated it should probably pause the game (because the user will not be able to interact with it). When your game is reactivated you can either resume the game or stay in pause mode and give the player a few seconds to compose themselves before continuing. When the game is exited your game should store any persistent game state and the first time it is activated your game should load the state.

The next thing you need to do is handle changes to the application view. These occur when the user “snaps” you to the side window or when the orientation/size of the screen changes. The first thing you need to do is bind an event handler to the event which fires when the application view changes:

ApplicationViewChanged += 
(sender, args) => ViewChanged(args.ViewState);

Your event handler will have to deal with changes in orientation and also “snapping” to the edge of the screen.

private void ViewChanged(ApplicationViewState viewState)
{
    switch (viewState)
    {
        case ApplicationViewState.Filled:
            addMessage("filled");
            break;

        case ApplicationViewState.FullScreenLandscape:
            addMessage("fullLand");
            break;

        case ApplicationViewState.FullScreenPortrait:
            addMessage("fullPort");
            break;

        case ApplicationViewState.Snapped:
            addMessage("snapped");
            break;
    }
}
This is my test method. It just sends a message out for the different states.

When you get snapped your game could display a “Mini-screen” in the snapped area. Above you can see what a snapped game looks like. The cornflower blue area on the right is the snapped area. When the game is unsnapped it will get a message to indicate the orientation of the screen. My games just pause when they are snapped.

One thing to remember is that when you get snapped the size of the screen changes.You need to change the size of the screen so that things are still drawn correctly in the snap panel area. You can grab the new values of the viewport size to do this.

cheeseRectangle = new Rectangle(0, 0, 
_graphics.GraphicsDevice.Viewport.Width,
_graphics.GraphicsDevice.Viewport.Height);

The above snippet resizes a cheese drawing rectangle to fit the whole screen. I could use this to make sure that my cheese is always displayed full size (although when the program is snapped this will make for a rather long and thin display).

Having got this far you are pretty much sorted. There is just one more thing you need to know, and that is the sequence of the messages. The log sequence at the top of this post will help here. The important thing to note is that you get viewport changed messages after you have been deactivated. If you think about it, this makes sense. The user can start to drag your application screen and then either put it back, or drop it into the snap area. It is important that the application is stopped when the user begins to perform such an action. So if your program is snapped you will get the sequence:

  1. deactivated
  2. snapped
  3. activated

You never get the view changed messages in isolation. This even the case when you use the Windows + . command to snap the game from the keyboard.

Gaming in Academia Event

Doncaster

I got this email from TripIt today. It doesn’t seem to understand that I’m changing trains in Doncaster to go on to Birmingham for the Windows Gaming Awareness event. Not that there is anything wrong with spending time in Doncaster.

I’m doing a session tomorrow in Birmingham about XNA and MonoGame in Windows 8 and Windows Phone 8. If you want to come along too, I think there may be a few places left if you are quick.

Farseer Physics in MonoGame

screenshot_02132013_165926

I really like MonoGame. I also like physics. Particularly the Farseer engine, which works very well with XNA and lets you make things bounce around very nicely. I’ve had some success putting Farseer on Windows Phone, so today I thought I’d see if I could get Farseer to work with MonoGame. So I opened up my venerable old Destruction Golf demo from ages ago and just copied across the Farseer library and the code.

And it worked. Pretty much first time. Took me fifteen minutes in total. Amazing. The only problem was with the sound effect that plays when the ball hits the house. This wouldn’t play for some reason. But everything else seemed to move very realistically. If you want to add a bit of physics to your XNA then it is well worth a look. It is the older version of Farseer, but I kind of prefer that.

You can find the sample code for MonoGame Windows 8 here. You can find my video presentation about how the code works here.

Ex NA

image

Things you might not know about me. I’m fluent in Algol 68. I know the George III Operating System (and its amazing editor) really well. If you ever need a VMS System Manager, I’m your man. I can write Modular II and Coral 66 programs, use Forth and Turbo Pascal with aplomb and and perform low level programming of the 6522 PIA (Programmable Interface Adapter chip) in 6502 machine code, should you ever need someone to do that.

Of course these skills are pretty much useless these days, as the above technologies are well past their sell by date. The good news, for me at least, is that all of these skills translate into useful ones using today’s technology. I know about operating systems, programming languages and low level interfacing. And although the relentless march of change has forced me to pick up new skills over the years, I’ve never lost sight of the fact that working with computers is just taking a machine that can do stuff and making it useful.

Today Microsoft formally started to pull the shutters on XNA. I was there at the start and I’ve followed the technology ever since. I’ve loved making games with it, and loved what other people have made with it. When Version 4.0 came out I remember thinking that they had put so much into it that the only way was down. My big concern was that they would keep on adding things until it became too complex and cumbersome to be useful.

XNA has done great things for programming and we’ve used it to good effect at Hull for many years. In reality it is not going away, it will still be possible to make XNA programs and distribute them, and the folks at MonoGame will take the XNA torch and carry it on to great things. However XNA will no longer have the seal of Microsoft support. It’s sad that Microsoft have moved on, but I think it was kind of inevitable. From a business point of view I never really understood how it could make a profit for the company, and in these tough times that probably spelt the end for the technology as a Microsoft product.

However, I don’t think that anyone who has built up a skill set in XNA has wasted their time. All games work in fundamentally the same way and all game developers need to address the same problems irrespective of the platform they are using. You just need to take a leaf out of my book (which I’ve had a while) and move the things you have learnt into a shiny new context. Take a look at Unity for some very interesting new directions. And find out more about MonoGame, which I think is wonderful.

Cheese Lander is Coming To Windows 8

Untitled

I spent some time today (lunchtime actually) playing with the latest version of MonoGame 3.0. This is the awesome framework that lets you take XNA games and run them on a growing number of platforms. I was interested in seeing if I could get a game to run on my Microsoft Surface. And I did. Behold, above you can see the venerable Cheese Lander actually running on my machine. Works a treat, and you can remote debug over WiFi. I’ll be talking more about this in my Rather Useful Seminar tomorrow.

Very Useful Seminar

image

We did our Rather Useful Seminar today about presentation skills. You can find out more here. Then I went over to a student presented seminar about game development. This was run by the Video Game Society. It was excellent. I had to leave early as I had to go off to a meeting, but what I saw set out very well what we had been talking about earlier. There were some nerves, but one of my rules is that the day I don’t get a bit nervous before I go out before an audience is the day that I retire from this job. If you don’t worry about doing it right, then you might not do it right.

Great work guys, looking forward to the next one. You can find the slides and sample code here.

MonoGame Demo

screenshot_08022012_142049

Last week I discovered how MonoGame is making it possible to write XNA games for the Windows 8 Metro environment. And I managed to draw a blue screen, which was nice enough, but not much of a basis for a game. So today I thought I’d make a sample project that had all the bits that you need to make your own game, including art assets, using the touch panel, using the accelerometer, drawing text and making sounds.

I’ve made a single, one-stop, demo that does all these things. It also includes the source of the MonoGame code as part of the project. I’ve found this to be quite useful when working out how the XNA implementation works. If you download the zip archive you should have everything you need. Here is how to get started.

Pre-Requisites

You will need three things before you can move any further:

  • Windows 8 Release Preview – this is where you run everything
  • Visual Studio 2012 Release Candidate for Windows 8 – this is where you build your program
  • Visual Studio 2010 for Windows Phone – this is where you create the XNA resources that you want to add to your game

Getting the Files

To get started just download the file from here. This is around 22MB. Before you unzip the file it is a good idea to Unblock it. This will stop Visual Studio from giving you warnings when you open any of the projects. To unblock the file you just have to right click on the file where you have download it, select Properties from the context menu and then click Unblock and then OK as shown in the badly highlighted screenshot below.

image

Then unzip the files. There are quite a lot of them. Once you have completed the download you will have the whole MonoGame framework and my little test project. Open the folder and find the Visual Studio Solution “MonoGame.Framework.Windows8” and open it. Make sure you open it with Visual Studio 2012 Release Candidate. If you double click the solution you will probably start up the wrong version of Visual Studio (I do) which doesn’t end well.

Running the Sample Program

The solution contains a project called Test Project which runs a port of a Windows Phone demo I wrote that lets you draw lines of dots on the screen using your finger. The dots that you draw will also fall down the screen in a way that is controlled by the accelerometer. You can clear the dots by double tapping on the screen, the game will make a “Ding” sound when you do this. The game also writes some text on the screen.

Resources and Fun

The MonoGame XNA part of things works very well, apart from content. At the moment there is no way of getting Visual Studio 2012 to pre-process XNA content for use in a game. We get around this by creating a Visual Studio 2010 XNA project and using it to produce the xmb files that are read by the content manager when the game runs. The content in the sample program came from existing XNA projects that I had around the place. If you are migrating an XNA game onto Metro you can do the same. The tricksy bit is where you put the xmb files for the game to use. I had no success adding them to the Visual Studio project, instead I had to put the xmb files in the specific directory read by the game when it runs.

image

Here you can see the path to the AppX\Content folder where I put the XMB files for the sample game. These include the two textures, the font and the ding sound file. If you want to add more content to your game, just drop your files here and then refer to them in the program as you would in any other resource:

protected override void LoadContent()
{
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);
demoTexture = Content.Load<Texture2D>("DemoArtwork"); demoRectangle = new Rectangle(0,0,GraphicsDevice.Viewport.Width,
GraphicsDevice.Viewport.Height); smudgeTexture = Content.Load<Texture2D>("Smudge"); font = Content.Load<SpriteFont>("MessageFont"); dingSound = Content.Load<SoundEffect>("ding"); }

You should be able to use my TestProject as the basis of anything that you fancy making.

XNA for Windows 8 Metro

image

One of the sad things about the move to the new Windows 8 Metro platform is the way that XNA seems to have been left by the wayside, with no way forward for the platform and no workable alternative from Microsoft. I see this as a bit of an own goal really, just when people like Sony are releasing a suite that makes it easy for C# developers to create and deploy applications, and when Microsoft are looking for a way to get developers on board with the Windows 8 way of doing things, they seem to have pulled the plug on the best way to do this.

However, it is not all bad news. The people at MonoGame are beavering away on a solution that will let you leverage your XNA experience and make games for Windows 8 Metro. Following the instructions in this blog post I managed to get a screen full of Cornflower Blue on my Windows 8 system. The familiar Update and Draw methods are present and correct, along with all the XNA types that you know and love. At the moment getting content (fonts, textures and sounds) into your game is a bit of a faff, in that you have to make a Visual Studio 2010 project and use that to prepare the content for use in your Metro program. Having said that, it does work and, thanks to the dedication of the Mono team it looks like we will have an XNA trajectory on Windows 8 Metro. It is just a shame that it is not coming from Microsoft.

Book News

image

Two bits of interesting book news today. O’Reilly are having a special offer on all kinds of great books for the next week, up to 5th July. One of them is my XNA book (the one on the left above). Follow this link to get your hands on this, and any other titles that take your fancy (but buy mine first…)

http://oreil.ly/LFXgno

Also, Start Here! Learn the Kinect API! is coming out soon, I think some folk have already managed to buy a copy. One clarification, just as we went to print Microsoft released version 1.5 of the Kinect SDK. The book doesn’t cover any of the new APIs provided in version 1.5, but all of the content will work fine.