Protect your Carrot

April 30th, 2010

Just finished attending Indie9000 gamejam here in Aalborg. We had a lot of fun. The theme (revealed friday evening) was Rabbits.
We were intent on making a combined "Shoot-the-little-varmints" and Tower Defense game where we would partly shoot the little rodents with a shotgun (instant gratisfaction ;-) ) and partly set up traps and obstacles to keep them out of the garden.
In the end we only implemented the shoot-em-up part, but had great fun getting there.
One thing we laughed a lot about was the fact that we had to implement some censorship. We wanted the rabbits to be able to "spawn" new rabbits when amorous feelings arose. But they had very few inhibitions. To begin with we found out that they were jumping members of their own sex. While we have nothing morally against that - it didn't lead to offspring (which was our intention to begin with) so we put a stop to that.
Then we found out that they were copulating with the deceased which we also chose to stop, and finally when all was well and dandy and little rabbitcouples were having rabbit offspring we saw some deviants sexually assaulting the babies. So finally, after three "censorship IF-sentences" we got the game up and running :) .

There were a lot of other very well made games and we saw our chances of winning any of the categories as very slim :) .
One thing we were very happy about was making a score system to tempt the good gamers into making the game harder for themselves: We awarded the player 1 point for every kill. But if you kept shooting at the rabbitcorpse you got additional points. Two points for the next shot, then three, four, etc. for the entire two seconds before the corpse was removed from the playingfield. this makes it possible to get up around 1+2+3+.....+15+16 points if you go on a splatterspree :) . This also lets the other rabbits get closer to your carrot, gives them time to make new rabbits and even more rabbits are spawned from the rabbitholes around the border of the playing board.
The judges apparently thought this was a great balancer for the game - and also liked how easy the game was to learn (and addictive - we had to wait for one of the judges to beat our highscore :) ).

If you want to play the game - it's available for download here.

You need the XNA redistributable if you don't already have the XNA framework installed.

The sourcecode will be available soon, it's being beautified *G*.

Enjoy!

Small project to show drawing items with the mouse in XNA

February 3rd, 2010

I saw a post today on the XNA Community Forums asking how to give a player the possibility of adding things to a game, and storing the position of the added images.

I made a Downloadlittle project to show how to do this. Basically it adds a Vector2 to a generic List when the left mouse button is pressed and removes a Vector2 when the right mousebutton is pressed.

Here's a small demo:

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SmallXNADrawingGame
{
    /// <summary>
    /// Small class to show how to be able to draw and store objects in XNA.
    ///
    /// Jakob "XNAFAN" Krarup - February 2010
    /// http://www.xnafan.net
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        //a list to store the dots in
        List<Vector2> positionOfDots = new List<Vector2>();

        //the dot to use for drawing
        Texture2D textureDot;

        //stores half the size of the dot for centering the texture
        Vector2 halfSizeOfDot;

        //stores the current and previous states of the mouse
        //they are used to compare in Update() to make sure
        //a mouseclick is a new one and not just the button being held
        MouseState currentMouse, oldMouse;

        //font for writing instructions
        SpriteFont defaultFont;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            //set size of screen
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 800;
            Content.RootDirectory = "Content";

            //make sure to display mouse cursor
            this.IsMouseVisible = true;
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            textureDot = Content.Load<Texture2D>("dot");
            //calculate half the size of a dot and store it
            //for drawing the dot centered on the mouseclick (se Draw())
            halfSizeOfDot = new Vector2(textureDot.Width / 2, textureDot.Height / 2);

            //load the font
            defaultFont = Content.Load<SpriteFont>("DefaultFont");
        }

        protected override void Update(GameTime gameTime)
        {
            //store the current state of the mouse (buttons, position, etc.)
            currentMouse = Mouse.GetState();

            //if the mousebutton was pressed between this and last update...
            //this check makes certain that one click doesn't create multiple dots because the button is held down
            if (currentMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)
            {
                positionOfDots.Add(new Vector2(currentMouse.X, currentMouse.Y));
            }

            //if right mousebutton was pressed
            if (currentMouse.RightButton == ButtonState.Pressed && oldMouse.RightButton == ButtonState.Released)
            {
                //and there are still dots left
                if (positionOfDots.Count > 0)
                {
                    //remove the last
                    //"-1" is because the list i zero-indexed,
                    //so a count of 1 would remove the dot at position 1-1 (zero).
                    positionOfDots.RemoveAt(positionOfDots.Count - 1);
                }
            }

            base.Update(gameTime);

            //store the current state in oldMouse
            //to be able to determine when buttons have JUST been pressed
            //by comparing the two states in an update
            oldMouse = currentMouse;
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            //write instructions
            spriteBatch.DrawString(defaultFont, "Left mousebutton to draw dot", new Vector2(20, 20), Color.White);
            spriteBatch.DrawString(defaultFont, "Right mousebutton to delete dots", new Vector2(20, 40), Color.White);

            foreach (Vector2 position in positionOfDots)
            {
                //draw the dot centered on the position of the mouse
                //by subtracting the Vector
                //which has half the textures width for X and half the textures height for Y
                //from the position stored.
                spriteBatch.Draw(textureDot, position - halfSizeOfDot, Color.White);

                //draw the dot's position
                spriteBatch.DrawString(defaultFont, position.ToString(), position, Color.White);
            }
            base.Draw(gameTime);
            spriteBatch.End();
        }
    }
}

We won a “Juror’s Special Pick” award!!

February 3rd, 2010

I had to leave Nordic Game Jam before the votes were counted in the semifinals. Apparently we first made it to the finals and then were picked by the juror Thor Frølich (Graphics Designer and Ninja Extraordinaire from IO Interactive). He liked the simplicity - that the game had one core gameconcept chase and the simplistic graphical expression.
Apparently (I wasn't there, but Rasmus was) suddenly everybody could see the benefits in our simple game as opposed to the graphically superior games :)
GREAT :)

Chasing Dots – Our contribution to Global Game Jam 2010

January 31st, 2010


This is the game we created at the Nordic Game Jam 2010.
Finally ... after liters of chocolate milk, coffee and chocolate.
After playtesting, debugging, playtesting, debugging.... etc for 48 hours - we finally have a playable version out.
The theme for this years Game Jam was "Deception" and there was a constraint saying that you had to have a DonKEY, a MonKEY or a KEY in your game.

We chose to make a little player-vs-player maze game. The hunter (black) is faster than the hunted (white) but the hunted can spawn clones of himself.
The KEY is used to unlock the teleports (red squares).

We are considering selling the game on Xbox Live Marketplace, but let's see :)

Here's a demo of the game - have fun and let me know what you think.
You will probably need to install the XNA 3.1 framework redistributable first, if you don't already develop XNA games.
Credits:

Project Manager/Music
Lars Nysom

Audio/Concept/Leveldesign
Rasmus Lønne

Code
Malte Baden Hansen
Jesper Eiby
Jakob Lund Krarup

Fanpic with Peter Molyneux :)

January 30th, 2010

The Legendary Games Creator and a great fan!

I am attending the Nordic Game Jam chapter of the Global Game Jam that is going on this weekend in all timezones.
The keynote speaker is Peter Molyneux - and since I got the chance to meet a legend I just HAD to brag.

To all the Teenage-Game-Tycoons out there :)

January 28th, 2010

Someone posted on the XNA Forums about how all of his projects gradually slowed down and finally ground to a halt far from being finished and far from being anything like what he was striving for.

The original post was deleted while I was responding - but since I know there are many TGT's out there I thought I'd post it here.
If you're a TGT - this one's for you!

"Well if you want to hear my solution:

Do a little and do it well
Start out simple - but finish it!
If you have to create XNA-tic-tac-toe or XNA-Pong for you to finish a complete game including titlescreen, options and help, then by all means DO THAT :)
Better to have a fully finished game to show off, expand and learn from than 20 barely-begun projects laying around.

Be proud of what you do - because YOU did it!
This has worked for me in many endeavors.
Continually praise yourself saying "well done - you finished another sprite/method/class/level" and remind yourself of how far you've gotten on this project.
It is really a benefit to have high thoughts about what YOU produce - even despite what others may think or compare your games to. :)

Join hands - it just makes for better results :)
Only start something by yourself if you are content with failure or another "draft-gone-prealpha-gone-stale" :)
Find someone on the forums to make your first little game with. All gameprogrammers started small, but very few got to where they are today without the moraleboost of being in a group.

Go get'em tiger!

Kind regards - Jakob "xnaFan" Krarup"

Nordic Game Jam this weekend – yay! :)

January 27th, 2010

This weekend a buddy of mine and I are driving to Copenhagen to participate in Nordic Game Jam.
The sign-up closed at 260 participants, that will be my biggest jam yet :) .
For those of you who haven't participated in a Game Jam yet - DO IT!
Here's a short excerpt from the NGJ webpage about why you should try it. It sums it up pretty well:

But why participate in a game jam? And why go through 48 hours of: very little sleep, hard work, great ideas, crunching, problem solving & technical issues? Because a game jam encourages innovation and experimentation. It is one of the vehicles behind the new generation of game developers that can experiment with platforms and game ideas in an intense and yet still informal atmosphere. This is the space where the new generation of talents can be found.

If you urge to create a game, collaborate and meet other game developers - then Nordic Game Jam is the perfect place for you. As a participant at the Nordic Game Jam you will be part of a global event of creativity and fun.

The Nordic Game Jam 2010 will follow the same format like previous years, as an event where students, hobbyists and professional game developers, meet up for a weekend to develop and experiment with new and innovative game ideas.

My version of the 10 second pitch sounds like this:
"It's an excellent chance to pick up new skills and friends while doing what you like best - code XNA ;-) ."

Nordic Game Jam will be opened by Carina Christensen, Danish Minister of Culture - which I think is a proper recognition for the role games play in the development of a common culture.
But more importantly: Peter Molyneux, yes THE Peter "Populous-DungeonKeeper-Black and White" Molyneux will be doing the Keynote speech.
To me Peter is synonymous with Artificial Intelligence. Like no other he made me believe that the characters you saw on the screen had a life of their own, even after turning off the PC :)

Can hardly wait!

XNA extension methods page

January 24th, 2010

Just a short note to let you know that I will gather my extensionmethods on a separate page with sample usage for handy reference.

XNA Pixel Robots library

January 20th, 2010

A while ago I came across Dave Bollinger's PixelRobots and PixelSpaceships.


He has invented a way of generating simple, random robot-like or spaceship-like sprites. He has implemented his code in Java, and you can try out an applet there that will generate many different versions of the millions and millions of possible variations.
I really liked the idea, and thought that it would be very nice to have an XNA implementation for anyone who needed generic spaceships or robots in a game.
So I created an XNA version from his description.

Before you go any further I suggest you go and read about PixelRobots and PixelSpaceships, so you understand what the basic functionality of the API is.
You don't have to understand the internals of my API to use it, as everything is wrapped up in simple methods. But all the helpermethods and variables are available for use if you want to create something more advanced.

It can be as simple as this:

using System.Drawing;
using PixelRobots;

namespace XNAFAN.Net
{
    class Sample
    {
        public void Main()
        {
            //create two bitmaps scaled by 5 with different colors
            Bitmap spaceship = PixelMaskGenerator.GetCompletedRandomSpaceshipImage(5, Color.CornflowerBlue);
            Bitmap robot = PixelMaskGenerator.GetCompletedRandomRobotImage(5, Color.LightGreen);
        }
    }
}

The above code would generate the following two images:

If you'd rather generate SpriteSheets and then use them as Content files instead of creating the spaceships runtime there's also support for that. The spritesheet below was created with the following code:

//create spritesheet
//scaled 3 times, 10 rows and 10 columns
//using spaceships in CornFlowerBlue
Bitmap spritesheet =
    PixelMaskGenerator.GenerateRandomSample(3, 10, PixelMaskType.SpaceShip, Color.CornFlowerBlue);
spritesheet.Save(@"C:\spritesheet.png");
spritesheet.Dispose();

Samples spaceships

And then if you need to convert the Bitmaps to Texture2D runtime, it can be done using Cristopher M. Park's excellent method:

//Converts a Bitmap to a Texture2D
//Code found here:
//http://christophermpark.blogspot.com/2008/10/converting-systemdrawingbitmap-to-xna.html
Texture2D BitmapToTexture2D(Bitmap bmp)
{
    Texture2D tx = null;
    using (MemoryStream s = new MemoryStream())
    {
        bmp.Save(s, System.Drawing.Imaging.ImageFormat.Png);
        s.Seek(0, SeekOrigin.Begin); //must do this, or error is thrown in next line
        tx = Texture2D.FromFile(GraphicsDevice, s);
    }
    return tx;
}

Code
The Download code is available here.
The solution includes three projects:

PixelRobots is the main project is the project which contains all the code needed to generate SpaceShips, Robots and SpinedRobots (robots that are ensured a cohesive spine) for your game.
ConsoleTester is a consoleproject which goes through step-by-step what is done behind the curtains. It saves the generated images to disk and displays them in an HTML page.
TestingPixelRobotsInXNA is a little XNA demo which lets you generate spaceships with the left mousebutton and robots with the right mousebutton.

TestingPixelRobotsInXNA

Screenshot from the running TestingPixelRobotsInXNA project

I made a short video presenting the API in use in TestingPixelRobotsInXNA:

Hope it is of use to somebody - it was fun making :)
If you use it for something I'd love to see for what.

More links
Want your own PixelRobot Tee?
Want the code in PHP for your website?
Want to see the PixelRobot idea used in a windowsgame? (non-XNA)

MouseState ExtensionMethod

January 20th, 2010

Just a little helpermethod to get the mouse's position as a Vector2.

For those of you who still haven't gotten started with extension methods here's a quick writeup'n'sample

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace XNAFAN
{
    public static class MouseStateExtensionMethods
    {

        /// <summary>
        /// Returns the mouseposition as a Vector2
        /// </summary>
        /// <param name="mouse">The current MouseState</param>
        /// <returns>The mouseposition as a Vector2</returns>
        public static Vector2 GetPosition(this MouseState mouse)
        {
            return new Vector2(mouse.X, mouse.Y);
        }
    }
}

This way you don't have to convert x and y every time along the lines of

MouseState mouseState = Mouse.GetState();
Vector2 position = new Vector2(mouseState.X, mouseState.Y);

Instead you just add a reference to the code with the extensionmethod and this enables you to write:

Vector2 position = mouseState.GetPosition();

Nifty - eh...? :-)