Showing posts with label GameDev. Show all posts
Showing posts with label GameDev. Show all posts

Friday, 12 February 2016

Our top 5 Project management tips for time starved developers

We've all been there. A great idea forms in our head and we just have to build it. This often means casting aside a previous great idea which grew to a gargantuan size. An idea which grew so large that there was no hope of completing it without significant effort...

Ideas are strange things. They come when they want to and creativity isn't always on tap.


They need to be managed to keep them under control.

Well, when the ideas come, you need a strategy to make sure you make the most of them.

Here are 5 tips to help you to develop your idea into something which you can build.

You'll also need a few things.
  • A note book.
  • A pen.
  • A sketch book (optional).
  • A pencil (optional).
  • A wall or whiteboard.
  • Post-it notes. (several colours if possible).
  • A marker pen.
  • A pack of sticky stars. (the kind used when marking kids homework; do teachers give gold stars anymore?).
  • ..and that guys leg. (just kidding)

Or,  you can use an online tool like Trello. 


We use Trello for all our projects; It's free and it lets you do everything I talk about here - with the possible exception of getting your fingers covered in glue from sticky stars)

Trello lets you create lists of tasks, move those tasks between lists and add labels. If there is more than one person in your team, don't even consider a whiteboard. Not unless you're always in the same room with them when you work.


1. Write down your idea. 

Use Google docs, word or something.

The longer it stays in your head, the more it will grow into something unworkable. Either that or it'll slip your mind completely or even morph into something else. Ideas are funny like that.

By writing down your idea, you make the first conscious step on the journey to make your dream a reality.

Perhaps draw some basic concept art to help you to form the idea,

Once you've written your idea down, read it back to yourself - out loud. This is important.

If you're not comfortable reading out loud, there's a great Text to speech Extension for Google Chrome called "SpeakIt!".

You'll be amazed how much more you'll learn about your idea by just reading back what you have written out loud.

Remember; An idea not written down is just a dream. A written idea can be reviewed and amended. Most importantly, a written idea is only one step away from the next most important step...

2. Make a plan.

Your written idea can broken into pieces to determine what tasks needs you need to do. It's at this point where you're looking to identify sections of work. Break your idea down into general sections.

Start out high level with big, high level sections, things like:


  • Menu System. 
  • Game play.
  • Music.
  • Sound effects. 
  • Art.
  • Levels. 
  • Weapons.
  • Characters.
  • Physics.
  • Controllers.
  • Achievements.

The list can be long.

Create lists using Trello or "post-it notes". You can use different colours to denote your expertise in that area or apply labels.

Make sure you create one called "Done"- This is the most important list to create.

Write as many of these high level sections as you can. At this stage it doesn't matter if you have too many or if they seem to overlap.

You can always merge similar sections together later on.

If you're having difficulty working out the high level sections, you should re-read your idea and consider...

"What will it take to do that?" 


You can always change your idea if you think you've missed something,

Be careful; ideas always spawn new ideas... in fact, one of the challenges of developing your own games is controlling this.

Remember to be honest about your skills in each area. You can mark the sections with a difficulty rating if it helps.

Once you have a list of all the high level sections, you can start to flesh it out.

3. Add tasks to each section.

This is where the fun begins. In a way, this is the first part of development.

When you create tasks, you're actively considering the problems you're likely to encounter. This helps you to solve them. List as many of the things you need to do for each section as possible.

For instance in the Music section, you may have tasks for Title, In game, Game Over and Intro. Each of these would be a task to complete by someone.

In the art section, you might have tasks to draw and animate the main player sprite. This might include player walk animation, player run animation, player jump animation etc.

Note that I'm not just generalising with a single task called "Player Animations". That's too big a task and could roll on for weeks without seeing any progress.

You see the trick to keeping a project alive is to always make progress...  The only way to do this is to always have tasks you can complete.

You'll start to see a lot of tasks appearing as you break the design down into workable units of work. You'll see sets of tasks for entire features.

In some cases some tasks will be more important than others so you'll need to prioritise them as such. This is where our marking stars come in.

You see, you're trying to isolate the "MVP".  Minimum Viable Product.

It is the set of tasks you need to make the basic playable version of the game. You should focus the most on tasks which will get you to MVP.

Consider your tasks. Which of them are "absolutely essential" to get the most basic version of your game written and playable?

Put Trello labels or gold stars on each of them. They're the important ones.

As you create your tasks, you should think about breaking them down further. Can you complete each of your tasks within a reasonable amount of time or will each of them be a long slog?

To this end, you should...

4. Be honest with your time. 

and make each task something you can complete in a single sitting.

The amount of time you have will depend on several factors. Spouse,  children,  study time, day job, pets, hobbies. These all have demands on your time to some extent,  reducing your available time to spend on your game.

If you start the project believing you'll have your full allocation of time to spend then I've got news for you. Life happens.

Unless you're in a locked room without any contact with the outside world, you'll have distractions.

There is no point over estimating the amount of time you have available per sitting.  You will only be deceiving yourself and this will make you fail.

Be honest, place a post it next to your tasks with the number of hours per sitting you can spend written clearly on it. It doesn't matter if this number seems low, that you only have a few hours per sitting. At least you know, and this can change over time.

Note: I said per sitting,  not per day. If you can't work everyday that's fine. But when you do work, you should be sure you have the time  available to work on your tasks. Without too many distractions anyway.

Once you have calculated out how much time you have per sitting, you should use that as your guide. Use this value for estimating your tasks.

5. Create tasks sized to one sitting at a maximum. 

For instance, if you know that you can draw one character per evening, then have one task per character. Then every day, you 'll have something to put into the magical Complete column.

Maybe it takes one sitting to draw and one sitting to animate. It's entirely sensible then to make two tasks for that.

If you have a task which seems difficult to break down, you can break it down based on classes or drawings if you need to.

E.g. If you need a terrain renderer: This is only one part of your game but it's a large coding challenge.  Luckily this is something you can break down. I wrote a 2d random terrain generator and renderer. I needed a fractal height algorithm. I also needed a camera system with view frustrum. I needed  a polygonal renderer and terrain detail sprites. The terrain should be generated on the fly and destroyed when off the screen. I also needed Farseer collision detection.  

All these tasks fit under the generic task of "Terrain".

So I broke it down into achievable tasks and hit them one at a time per sitting.

There is no point in trying to fit too much into a task. If it can't be completed in a normal sitting,  it should be broken down further. You must have something to complete!

If you're not sure how to do something,  create a task solely for research.

Spend your entire allocated time on learning if you need to. You'll be better for it.

Researching is a task just as much as coding or drawing is.


Write it on a note, add it to the board.

6. Nothing is cast in stone.

Everything can change. Review your plan regularly. Update it, it will keep you on track. You should aim to do this either at the end of each sitting or at the beginning before you get to work.

It's OK to make changes too, sometimes we uncover things about the design we had no idea about. You can add new tasks, remove tasks or update them to cater for the new information.

Did you make an assumption which turned out to be incorrect?  No problem. Have a think about it, review your design and alter your plan. Follow the basic principles discussed above and you'll be fine.

If an idea turns out to be too difficult,  again no problem.  Simplify your design and review the plan. This is a good thing to do anyway.

You can do this review at any point in the process.  Just make sure any team members are aware of the changes to the design as it could affect their work.

It could be that the design is fine. But after looking at the sheer number of tasks it becomes obvious that the idea will take too much time to build. Don't worry, if your design seems to be too large, Simplify it. Remove features which aren't required or replace them with a simpler alternative.

You can always tackle the full idea later. Remember : before Halo, there was doom. Doom was once the pinnacle of 3D shooters. Yes its design was constrained by the limitations of the available hardware and skills of the developers at the time. It's OK for ideas to evolve and to make more advanced version of your game later once you've proven the concept.

If it's successful, you may even have a bigger team to work on the next iteration of the game idea.

But you must complete your initial version first.


Hang on, wasn't this supposed to be 5 tips?

Well, nothing in Project Management ever goes according to the initial plan. You'll always have something which comes out of the blue. The key part of project management is actually managing and controlling change. Customers may tell you they want something only to change their minds later. Ideas may start out as one thing only to become something else later.

If we stick to the initial ideas, we'll never complete our ideas.

Accept the change.

Understand the change.

But most of all, Manage the Change.


Best of luck.

Sunday, 1 November 2015

Batteries Not Included - The GameCraft London 2015 event


On Saturday the 31st of October 2015 - Halloween 



Our merry group of developers took a trip to London with one purpose. To make a game in a day. We had no idea what the theme for the game would be, it's always a closely guarded secret until the morning of the event.

With no way of knowing the subject, it was impossible to predict what kind of game we would be creating. So we pondered this for a while.
We arrived in London to nice weather, the streets were dry and it wasn't cold. Just the type of weather needed for sitting inside all day and writing games.

We'd not been to the location of the GameJam before so it took a little time to get our bearings and find the place.

After a little time spent looking for the new (and amazing) SkillsMatter building "CodeNode" we arrived with a little time to spare, got ourselves signed in and joined everyone in a large room where the plan for the day was given to everyone. There were people from various sponsors there, a group from Audi were there as well as a team developing devices for an "Internet of things". It was all very cool.

GameCraft London 2015

There were actually 3 events going on on the same day, such is the massiveness of the SkillsMatter building and how much in awe I am of it and grateful for their kind hospitality - You guys rock! People were encouraged to mingle and to see what others were working on. It's great to meet people who share a passion for development, no matter what the subject is.

11:00

It came time for the brief for our event.  Batteries not included.
The irony being that the majority of the machines being used to develop needed batteries to function.


With 8 hours to go, we had to come up with a design pretty quickly. Dean came up with an idea in a eureka moment and suggested a top down racing game where the cars operate on power from the sun. I'm a big fan of alternative energy and electric cars so I was all in. I also used to love the old top down racers on the Spectrum.

Within a short amount of time we had a very detailed design on paper and coding the game could begin proper.

Detailed and comprehensive design.

Design is everything. 

We took graph paper and pens to work out our design first before touching any code. It's probably a good rule of thumb that if the design is too complex to fit on a side of paper, it probably can't be made in a single day. Skillsmatter also provided graph paper - great minds think alike, but it's always best to come prepared.

With the design agreed, I set about designing the cars while Dean put the Farseer physics system into our framework. We'd set up a git repo the evening before so we could easily share code without stepping on eachother's feet.

Once again we would use our familiar tools of MonoGame and Xamarin studio with Spine, Mixcraft, Audacity. However this time, I thought I'd try to use Adobe Illustrator and Photoshop instead of my normal Xara.


The more we use these tools, the faster we become at producing content. But also it means that with MonoGame and Xamarin studio, we don't have to worry about trivial details like Operating Systems and hardware.

Dean used a Macbook pro and I used a Windows 10 laptop. A few years ago, this would have been almost impossible to share any kind of coding tasks between us - delegating one of us to graphics while the other gets on with code... thankfully this was not the case.

Although I did do a lot of the graphics...



The game started to take shape once I got the basic graphics to Dean so that he could animate them in Spine. He's getting rather good at it too and it wasn't long before we had a working race car.

I got to work making the track. I used Illustrator and Photoshop to put the basic track together.



13:Once I had the basic track, I sent that to Dean who then placed the bounding boxes for the physics system to use to contain the cars on the track. He did this also using Spine. 


MUSIC!

While he was doing that, I got to work on the music. A racing game needs music to set the mood and to keep the adrenaline flowing, but we didn't have much time to spend writing a magnum opus. So I fired up my trusty Mixcraft and started to layer some of the samples in the library.



The results of this can be heard on our Soundcloud.

With this done, I mixed it down to an mp3 and added it to the MonoGame content pipeline for inclusion into the game. Very Easy!

Then it came time for the game's title. Dean had the track and cars loading and was working on getting the collision detection working, so we took a short break and came up with a name. Both Harvey and Dom (a visiting old friend) came up with the idea of Solar Race Cars, shortened to Solar RC and then turned into a logo.



Following that, Harvey got to reprise his role of voice actor to give us the announcer sounds which we recorded using a RockBand microphone and processed in Audacity.



For the final push, once all of the assets had been created, Dean and I shared the remainder of the programming, tweaking the physics and getting the gameplay working as it should... finally resulting in a multi-player top down racing game.

Harvey liked it, we were on to a winner.
With very little time remaining, we had to polish the game into a game which others would enjoy. A few things were required, braking and reverse - We'd not added those initially, but it became apparent once cars started ramming into walls that brakes were probably a good idea.






19:00

Finally, the time was up and we had to down tools and let people play our games.


Not all entries could be completed unfortunately, but there were some decent games on display - one of which was a card game using NFC chips as part of the game mechanics - very interesting stuff.


Play time!

Things were getting very competitive on our table, once people got the hang of managing their power levels, they quickly learned how to defeat each-other, taking advantage of the sweet-spot on the controller where power output was balanced with the energy intake from the sun. Then they did what all people do in driving games, rammed each-other out of the way to get to the finish line first.

Finally, it came time for the voting to end and the judging began.

In 3rd Place

, was a game by Ross McKinlay who single handedly wrote another racing game with a different take on things - as well as a very impressive tunnel effect made entirely using trig.

In 2nd place

 was the NFC card game, lots of people enjoyed playing that game - although I didn't personally get a chance to play :-(

and finally in 1st place....




in case you were wondering, it was SolaRC

In closing

Everyone had a great time, we played some great new games which in the morning of the day didn't even exist as an idea in the developer's heads. They were born on the day.

It's always amazing to me how much people can create in such a short amount of time and how warm and kind everyone is even while working under such time constraints..

Thanks again to Skill Matter for hosting the event and thanks to GameCraft for organizing an amazing day.

Thank You!



Monday, 19 October 2015

Game Jams as a Catalyst for Busy People

...or how to build a game without p!$$ing off the missus. 

Using a Game Jam as a tool to kick an idea into action. All while being fair to those who share our lives.


Face it, we're all busy people.
Modern life is filled with distractions. Some more deserving of our time than others, some are essential and spending time on other things could be seen as neglect - but we won't dwell on those things. The distractions are there whether we like it or not.

Here's a few of the most common ones. Although it's not an exhaustive list. See if any of this rings true for you...

Most aspiring app or game developers have a day job. 

This takes between 7.5 to 8 hours a day from the pool of available hours, OK - it pays the bills, but it's not the ideal use of that time. Unfortunately, unless we catch a break, we cannot ditch the job. Most of the time the job is in a similar field as the idea (e.g. Software engineering) and when we return home after a grueling day of meetings, code and stress - there's not a lot of mojo remaining for that million dollar idea.

Some have partners.

Significant others who rightfully demand time. They too feel the hours taken by the day job and are often reluctant to allow or simply can't understand why there is a desire to put additional hours into a similar thing that their loved one was just complaining about five minutes ago - but has some idea they want to try which means more time alone. This one is the most tricky to deal with because partners are usually very forgiving and will tolerate a little time - but it's easy for this to become unbearable and they quickly put their foot down. This can lead to a lot of friction. (been there, got the tee-shirt)

Some have children. 

Similar in a way to the demands of a partner, children absolutely need time and don't like it when they don't get that time. Although, children can make good assistants if the game or app is written with them in mind. They make good testers and sometimes can provide their talents too. (Sounds, art etc)

Then there are competing hobbies.

like sports, going to the gym, the cinema, bowling with friends, parties.
These are the activities of a healthy life and a sign of a well rounded individual (apparently).
They're also a massive time sink leaving very little time to develop that killer app.

So how can we proceed? Most of these activities are essential or not easily avoided, so they take their price in hours, leaving very few hours remaining to get any work done and often leaving the developer very tired afterwards.

There are three options.

1. Abandon the idea. 

Knowing that there will never be enough time to devote to the idea to allow it to grow enough to see whether it would be worth extra development or not - may as well give up.

2. Steal a few hours from here and there. 

Hoping that a few hours will be enough to get into the zone, to focus for long enough without interruptions to make sound design ideas. Stealing a few hours makes the project take a very long time to get into a place where a clear path to completion becomes apparent.

3. Have a Jam. 

Book some time with your significant other, have a party and invite like minded friends to help - make an event of it. Brainstorm and see what you can produce in a few hours. This allows you to put the idea to the test very quickly. If you have helpers they can get parts of the application or game built while you focus on other parts. Setting goals to meet will keep you on track and at the end of the session, you'll have something to show for your efforts. Further more, you'll have had an entire day of uninterrupted work, you'll also have cleared it with your partner who will most likely use the time and have fun - all while knowing that they'll get you for the rest of the time.
It's also a great way to get the prototype ready so that you can demonstrate it - often buying more time to work on it.


Jams are worth their time investment a hundred fold.

Dean and I gave a talk about this very subject on the 1st of October 2015 at the Just Eat HQ in London.

We discussed our experiences in trying to get projects off the ground, the obstacles we'd come up against and our attempts to solve them. 

One of these attempts being the Game In a Month initiative. A very strict set of rules which if followed will produce a game in a month, but it may take several iterations before it comes out. 

Dean did produce a game using the system though, although he did stress that it was exhausting.

If you want to try it, go to www.gameinamonth.com


Then we discussed the tools we used during the process. Note the prominent placement of git. Having a source control system is essential in any project. We've lost far too many projects to the failings of hard drives and when working in a team, it is essential to have the ability to share and modify code without stepping on each-other's feet.

Most of the tools on the list are free or very reasonably priced.


So in summary:

A GameJam lets you focus your attention on the idea guilt free. It lets you collaborate or compete with others and gives you the opportunity to see if the idea bouncing around in your head is actually worth pursuing. Afterall, if the idea isn't worth it, it's best to know quickly before pulling all-nighters to get it polished and released.

London GameCraft 2014 Part Deux

Last year Dean and I attended the London GameCraft jam.
It was in an assisting capacity - providing video and effects support to any developer who wanted them.

This year, we're going again. Only this time, we're taking part!

We will be making a game in around 10 hours based on a brief that no-one will know until the morning.

It's going to be a blast and if last year is anything to go by, there'll be some amazing games made.

So if you want to go, there's still a little time remaining, so register by following this link.
https://skillsmatter.com/conferences/7378-gamecraft-london-2015



Sunday, 17 May 2015

10 Games.

I've read that you should make 10 games before you reach success in game development.
This isn't a strict value I'm guessing or any kind of hard and fast rule. However, I do feel that it's in a game developer's best interests to make as many games as possible. Partly to hone one's coding skills but mostly to understand what makes a game interesting and fun. It's also an important journey of self discovery, to understand one's talents and limitations.

I wrote many games on the spectrum, however none of them were what I would call "Finished" apart from the game I've listed here. Unfortunately, nothing remains of any of them, it was over 20 years ago. The rest of the games were for the PC platform and more recently for mobile devices..

So here's my list.

Treasure Caves

 ZX Spectrum. A platform game where you collect treasure in a scrolling maze like level to activate an exit which would appear after you'd collected enough treasure, all while avoiding traps and using teleports to move you to the next platform above. Perilous spike pits would plague your every fall.
The game included an editor where I would challenge a friend with a cunning level and he'd return the favour with an even more cunning level. This game was memorable to me because of the large levels, the large sprites. I had to write a Run Length Encoding compression system in Z80 (before I knew what RLE was) to fit the levels into memory. The game was fast and allowed for very devious traps. Even though the gameplay was simple, it was a lot of fun.

  • Language: Z80 Assembler, Basic
  • Status: Completed, Lost


SUOF: Subtle Use of Force

A vertically scrolling shooter where you must defeat an invading alien force using a previously mothballed fighter. You could collect weapons dropped from dead enemies, it had a variety of different aliens, each with their own abilities and tricks. There were also Bosses to defeat who also had their own patterns and abilities.

  • Language: Borland C
  • OS: PC MSDos. 
  • Status: Completed - Unreleased


CHAOS: Battle of the Wizards - Remake.

A remake of the classic gameby Julian Gollop. Chaos pits 2 or more wizards against each-other in a last man standing battle to the death.
It was abandoned due to really difficult to track down issues in the code which would take a massive amount of work to fix. However the gameplay was faithful to the original with every spell and monster re-created.

  • Language: VB6
  • OS: Windows
  • Status: Incomplete - Abandoned


GUNS: A DelphiX example. 

A turn based projectile warfare tank game where you control a squad of flying tanks who must fire at the opponents flying tanks on opposing mountain sides across a valley. AI behaviour aimed the turrets of the enemy tanks and raised shields. Limited fuel reserves and accurate aiming of the AI opponent meant that battles were usually quick and devastating -often needing quick reflexes and tactical uses of the shield. The terrain was fully destructible and this was the first game I'd written with a floating camera which worked independently of the player's control. It moved to focus on the selected tank and would also follow projectiles through the air to see where they landed - allowing the player to adjust their aim. All in real time. The game was published as a demonstration of how to make games using the DelphiX component set.

  • Language: Object Pascal
  • Framework: DelphiX
  • OS: Windows
  • Status: Completed - Released for free




Anomalous

 A rip in space has occurred following an unexpected situation during a science experiment trying to find a new source of energy to save our world from environmental disaster. The device causing the rip has fallen through the rift, it's up to  you to retrieve it before the earth and the alien world perishes. An entire story arc was planned involving alien civilizations and a civil war which would complicate your efforts.
It was a 2D platformer with skeletal animation - built from the ground up using a home grown engine called the CBCFoundation. An entire toolchain was developed to work alongside the engine including a level editor, skeletal animation editor and animator.
Unfortunately, a hard disk failure meant that I'd lost the source files for the majority of the art assets. It was an event which the project never recovered from.

  • Language: Object Pascal.
  • Framework: CBCFoundation, SDL
  • OS: Windows, Linux
  • Status: Incomplete - Abandoned due to hardware failure.



Lander


A variant on the old Lunar Lander game with a twist. You're in charge of a rocket which has to pickup and ferry spacemen from one part of the moon to another. Instead of using retro thrusters to control your descent, you have your main rocket which you must rotate around to move and slow down. Landing on the pad was tricky, you had to land at just the right speed and at the correct angle or Kaboom, however you could take some damage by hitting the mountains - making a horrible metal scraping sound as the rocket takes a pounding. I just couldn't get this game working as well as I wanted. The framerate suffered due to software rendering and the engine did not allow for the level of fidelity in the terrain I wanted.
I would later rebuild this in Unity as an example, however it wasn't as good or as much fun as I'd hoped and was ditched.

  • Language: Object Pascal.
  • Framework: CBCFoundation, SDL
  • OS: Windows, Linux
  • Status: Incomplete - Abandoned


Anomalous

A 3D version of Anomalous written using the Torque engine. This game was going to be the version of Anomalous it was meant to be. The earlier version being abandoned following a horrific hard drive failure. I created a lot of art assets however it seemed that no matter how many assets I created, I always needed more and the better I got at creating 3D assets, the worse my earlier work looked in comparison and my animation was horrible. Compared to professional offerings, I couldn't seem to compete. I needed to rethink this game. However I had a story fleshed out - just like the original attempt. It was just too big for a single person to build.

  • Language: C++
  • Engine: Torque Engine
  • OS: Windows
  • Status: Incomplete - Abandoned


Tetris

An example of how to build a tetris game, built in a weekend and offered on-line as an example. It was fully functional and surprisingly addictive, which I suppose goes to show how close I was to the original. It is an exercise that every game developer should do.

  • Language: VB6
  • OS: Windows
  • Status: Complete - Released for free.




GUNS

A 3D version of GUNS written using the Torque engine. A fully 3D version of the original game complete with a story about aliens using the Earth as a kind of courtroom to settle petty disputes with squad based tank combat. The human race being powerless to stop them, but the aliens appear oblivious to their plight although seem to have no designs on taking over the world. Abandoned due to complexities with the Torque engine in making it do what was needed for this game and because 3D games need a lot of good art assets in order to look even nearly nice. It became obvious that alone I wouldn't be able to make this game no matter how much work I put into it.

  • Language: C++ and TorqueScript
  • Engine: Torque Engine.
  • OS: Windows
  • Status: Incomplete - Abandoned



GUNS:Reloaded.

A back to basics reboot of GUNS with the intent to turn it into a completed game for sale. As the original however with the inclusion of multiple environments, better AI, refuel dropships, different turrets, friendly AI behaviour, A roster of pilots and a plot involving rival factions who do battle on the earth as their chosen combat zone.It even had a tutorial. It was abandoned due to the realisation that the CBCFoundation's inability to use hardware rendering had made it effectively obsolete. I'd also come to the conclusion that it wasn't that much fun to play.

  • Language: Object Pascal
  • Framework: CBCFoundation, SDL
  • OS: Windows, Linux
  • Status: Incomplete - Abandoned


Crashblock

Control a person inside a game of Tetris. The person clambers and vaults over the blocks in the arena to get into positions and calls the blocks into position and rotates them. The blocks are held by a chain of increasing fragility - it will eventually snap sending the block crashing down. The player can also request the drop however in either case, it's best to be out of the way when they fall or you'll get squashed. Multiple levels, 4 environments, power-ups. Character graphics were captured from real-time video and roto-scoped. Winner of the Pascal Game Development group's 2007 competition. Published in 2008. This was the last game I wrote using the CBCFoundation and Pascal for that matter. The CBCFoundation's inability to handle hardware rendering without a massive upgrade almost killed it, but it was the advent of C# and pascal's descent into obscurity which finished it off.

  • Language: Object Pascal
  • Framework: CBCFoundation, SDL
  • OS: Windows
  • Status: Complete - Released for sale.


SUOF: Subtle Use of Force - Mobile

A conversion of the DOS based vertically scrolling shooter. I started it as an exercise in getting a mobile game developed, to understand the technical requirements as well as the development process. I hooked in the tilt controls to act as steering and on screen buttons for firing. Unfortunately, it was slow and clunky requiring far more work than I had time for at the time. It also ran differently on different phones. It served as a insightful prototyle.

  • Language: Java
  • OS: PC MSDos. 
  • Status: Incomplete - Abandoned

Reversion Bureau

A science experiment has gone horribly wrong and you are called in to make it all better. Effectively a spiritual reboot of Anomalous. A platform puzzle game using live action footage captured against a greenscreen. Multiple characters and a story. This game is still in development but features physics as well as logical puzzles. A key feature of the game is that the main character does not resort to violence - instead solves problems using intelligence, the environment and science.


  • Language: LUA
  • Framework: MOAI
  • OS: Windows, OSx, OUYA
  • Status: In Progress

SchemeWars

Control a person inside a game of Galaga. The live action greenscreen captured person fires energy bolts from their hands at increasingly difficult waves of enemies. Complete with Boss creatures, all aliens have their own set of abilities and tricks. Completed and presented at an Insurance trade show.

  • Language: LUA
  • Framework: MOAI
  • OS: Windows, OSx, OUYA
  • Status: Complete - Released for Trade show.


ROO!

An endless runner where you have to rescue little Timmy from the well. Designed to be completely cross platform and created during a GameJam in January 2015. The game is notable for it's responsive controls, Spine animation and speed.The game was polished up over a period of 3 months and released on Android, OUYA and iOS.

  • Language: C#
  • Framework: Monogame
  • OS: Android, iOS, OUYA, Windows
  • Status: Complete - Released for sale.


Untitled Block Puzzle

We have a project on the go at the moment, which we'll announce shortly. The result of the second Songbird Creations Game Jam.

  • Language: C#
  • Framework: Monogame
  • OS: Android, iOS
  • Status: In Progress - Prototype


Thursday, 9 April 2015

Waiting for Review and an Easter treat.

So last weekend was busy...

It was Easter, so therefore in the UK, we had Friday and Monday as national holidays. So we used this time to launch ROO on the OUYA and to prepare for the iOS release.

ROO is currently (as of the 9th of April) waiting for Review. This apparently could take a little time so we all have to be patient. It will be really nice though when it's released as we've done a load of work to make it look nice on the iPad and iPhone with that lovely Retina screen.



Preparation is key

Of all the stores we've released on, the App store is probably the most difficult to get going with. There are many aspects of the store which take some research in order to get right. Luckily for us, Dean knew what he was doing and was able to steer our wayward ship through any potential rocks to get us out to sea. It's also the 3rd time I've had to fill out a Tax form. As Songbird Creations is a Limited UK company, we don't pay US taxes (instead we pay UK taxes) but Uncle Sam needs to be reassured that we're not trying to get away with his money, so we fill in a W-8BEN form and sign it.
For the OUYA I had to print it, physically sign it, scan it and send it back to them. Amazon had a version online and a handy helper, which while was handy could have used a "We're a UK company, just fill it in for me" button like Google does. 

Confirmation is key

While Preparation was certainly important, I've never had to confirm as many things in my life as I did getting the more legal aspects of the store running. Phew, glad that part is over is all I can say.

Customization is key

Phones typically have a slimline aspect ratio some are 1080p others a variation of, however for a landscape game, you're typically looking at most of the action being towards the bottom of the screen, certainly for ROO this was the case. Pretty clouds, blue skies and mountains cover the top to middle and give the illusion of distance and speed while the foreground and character reside towards the bottom to ground the action. 
For the OUYA, we needed to move things up a little otherwise the player is bombarded with a TV image made entirely of sky, for iPad it was worse as the aspect ratio is different again.

So we had to work out how much space was required to keep ROO in pretty much the optimal place while filling the rest of the screen with interesting but not too distracting detail. We had to make some more graphics to place at the bottom of the level.

Once we we done however, it looked and played really nicely. We also had to add an Achievement Toast system to complement the Game Center achievements which you can see in this video.


Feedback is key

On Friday evening, I went out around Cambridge and introduced a few people to ROO, one of the bits of feedback was to do with the Perfect Landing / Resurrection system. It waited for 2 seconds after ROOs failure and used a perfect landing token to burst back into the game (basically a lives system) however it turned out that people were becoming frustrated with the way it was implemented. Often they would reappear only to hit a cactus, a rock or worse - fall directly into a ravine. So something had to be done because while funny, I don't want unhappy players. So now there's a system where you're prompted to tap the screen to reappear when you want to or wait the full 2 seconds. Play testing this feature made it obvious that it was the correct solution. It makes failure your own fault as opposed to the game punishing you randomly.

A Happy Easter

It was really nice to see ROO on the OUYA store so I documented it with a little video. So you can see me install ROO for the first time on the OUYA as well as see how to get those pesky perfect landings. Stick around to the end for a little discussion in difficulty, game dev principles and a personal message from me.



So there you have it. ROO is on the OUYA market as well as Google Play store and the Amazon App store and we're awaiting  our entry to the App store.

If you'd like to know more, why not follow me on twitter @thecacktus

Have fun.

Wednesday, 1 April 2015

The little console that could.

A little Kickstart!

Back in January of 2013, I was procrastinating on the Escapist Magazine website and I came across an incredibly good idea. A micro console which takes advantage of the recent surge in phone processing power and the Android Operating System; all combined within a tiny stylishly designed box which wouldn't look out of place next to the nicest TV. A full HD 1080p console from the outset with it's own games market with games which must be free to try.



Kickstarter had shaken up the games industry and it seemed that the reported stranglehold publishers had over the various software houses would be weakened and it would usher in a new age of the bedroom coder.

Well, that happened somewhat; The bedroom coder did emerge and a lot of them released games; and some of them were really good. Kickstarter became the go-to place to get funding for the more adventurous or ambitious. There were a few bad apples of course but the net feeling was positive. There are debates as to whether Kickstarter has been over saturated with games and that it's become more difficult to be noticed among the crowd, but that discussion is for another day.

Mr Schafer I presume?

Anyway, I'd been following the antics of the people at Double Fine and backed their kickstarter for the game which would later be known as Broken Age.

Their kickstarter went on to demolish their originally requested amount to the tune of $3.3 million dollars. The internet went bananas.


As part of the deal, they would document everything and the documentaries would turn out to be really insightful to watch. 

It reminded me that Game developers, those people who create these amazing experiences that we love are regular people with hopes and dreams. They weren't too dissimilar to me, they had the same drive and passion as I did - just better funding. 



A large dose of gasoline was poured onto my previously thought to be extinguished candle.


So with both DoubleFine and the OUYA breaking records on Kickstarter, it seemed like the perfect time to get back into games... and the OUYA seemed to be the perfect platform to release it on with it's almost guaranteed success and it's open - yet moderated - marketplace.

I missed the Kickstarter for the OUYA however I did pre-purchase one in January and it arrived in July while I was in the USA - I wouldn't be able to get my mitts on it for another 2 weeks. The plane didn't get home faster because of tail-winds, it was by the sheer force of my will! :-)

I remember being surprised at how small and shiny it was and how the controllers felt really nice and solid. It was simple enough to set up and with it's online market and free to play nature was instantly appealing. I soon found myself purchasing many games. 

The biggest question became, what kind of game do I want to write? Platformer? RPG? Adventure? The ideas flowed fast and strong and eventually I settled on the game currently known as the Reversion Bureau, a puzzle platformer - which has had 2 years of development time spent on it. However more on that game later. 



Fast forward to now.

It's April 2015 and we now have a game released on the Android platforms. It's not the Reversion Bureau, ( that game will come ). Instead, it's a cool little endless runner where a kangaroo named ROO! must race across the Australian outback to rescue his best friend Timmy from a well he fell into. 

We've already released it onto Google Play, Amazon App store and now (pending) the OUYA. On top of this, we're putting a lot of work into preparing for the iOS release, as well as a Windows Phone release.

The OUYA is still going in spite of 2 difficult years in the industry which saw the launch of the new XBox One, the WiiU and the Playstation 4. OUYA have altered the rules a little in response to that; games no longer have to be free to try as long as they have a video to show the gameplay. So we've released our game for a very small fee.

To get this far it has taken a lot of work covering many aspects of the game development process.






  • Game Design
  • Lots of coding

  • Graphics creation
  • Rigging and Animation
  • Assets pipelines
  • Music authoring
  • Sound design
  • Video editing
  • Storefront management
  • Device Testing
  • Play Testing
  • Focus Testing
  • Project Management
  • Marketing
If it seems like a lot of work, that's because it is. 

Most of it goes unnoticed as it's mostly not fun or glamorous. 
For instance, Project Management and Marketing are incredibly taxing to do correctly and are utterly vital if the project is to have any chance of commercial success - or even being released as a product. Each market place has it's own store-front with it's own way of handling things. Marketing is hard work, even for something you love. It often feels like climbing to the top of every building in the city so you can shout from the rooftops. Those with money or sense employ others to climb the buildings for them, or employ those already positioned to shout.


So here's what I'm hoping for: That the OUYA can fulfil it's promise, that games made independently by small teams can reach those who want to have some fun, kick back on the couch and play games on their TV made by people who care. 

But no matter what happens,

 I'm grateful for that glorious moment where the stars seemed to align, the rebirth of the bedroom coder and the infinite possibilities which they could bring.. that and flappy bird, mostly flappy bird :-)


A plug for the cool little box 

The OUYA is being sold online at http://shop.ouya.tv/ as well as on Amazon and in Target stores in the USA. If you don't have one already, you should pick one up. There's a lot to be said for the games available and playing with the controller is great.

A note to travelling executives:

The OUYA packs away nicely into a travel bag and given that most hotel TVs have a HDMI socket, and there's rarely anything on the TV anyway, it makes a great travel gaming system. Something else to do on those long business trips.

Also, a note to parents: 

There are no disks, so no expensive games to break or scratch or leave cluttered all over the place. Kids can start the game they want, they're mostly for free and those which aren't are inexpensive. It supports up to 4 controllers, it's cheaper than an XBox, a Playstation and a Wii and it's still totally worth the money.





Thursday, 12 February 2015

Android games are easy to make! right?

So a couple of weeks ago, Dean Ellis and myself wrote a game in a weekend. It's a great game actually, loads of fun, addictive and has that one more go quality we were hoping for.

How did we make this? Well we used Monogame and Xamarin. We poured our combined 35+ years of experience into a 20 hour window; writing a fun game using C# without a pre-built game engine.

As I mentioned previously, we managed to get the game running on Android and iOS relatively quickly once the game was functionally complete. But it wasn't quite ready for the market.

What do we mean without a pre-built game engine?
Monogame is a framework, not an engine. Unity is an engine, Unreal is an engine.

I'm sure there's a better description to clarify the differences between the two, but to me a framework provides the tools to draw things, play sounds and to capture input on command, but you're effectively left to implement everything else yourself how you see fit. Everything from actors, physics, triggers, collision detection - every aspect of the game needs to be coded from scratch. And notice that I said "on command" this means that you have to tell your game to draw your textures, play your sounds and read the status of inputs with object methods in code.

This provides a great amount of flexibility in terms of what games you can write - in the same way as a word processor provides great flexibility in what documents you can create, it will provide the spelling and grammar checker, allow you to maintain versions of the file and even track changes. But it won't provide any further assistance when you want to write that book you have in you.

An engine on the other hand provides pretty much everything for you in a controlled way. You provide the assets and the ideas. You still have to code your game, but this is mostly done by hooking engine events to scripts. The rendering, input and sound are handled at a much higher level - mostly outside of your direct control - which allows you to create games very quickly because you can focus more on what you want instead of how it will happen; But you're more restricted in the types of games you want to produce - depending on the engine.

Engines are great and an entire industry has developed around them; after-all, why reinvent the wheel if you're making a different bicycle.

Why am I talking so much about the difference between a framework and an engine? Well, I suppose it's to highlight additional programming work required if an Framework is chosen over an Engine.

Choosing a framework over an engine allows you to choose how aspects of the game are implemented and enables you to write games with a much smaller memory footprint. But you do have to implement things which you would  normally take for granted if you were to use an engine.

It's a balancing act. If you want a lean codebase with a small memory footprint, a framework is probably the way to go - but it will mean a lot more code than building something in Unity.



So the game was completed, why isn't it in the store yet?
Well,  there's a bit more to consider than just putting the game into the store - even a game which appears to run on a developer's devices.

Sure, you can upload an APK to your store once you've set up your Google Play Developer account
and signed your app; But does it work on all devices? Or even the majority of devices on the market today? Will it be fun for all customers?

For Android developers, this poses quite a problem. The Android landscape is filled with a vast multitude of different configurations of hardware and software.

There are so many android devices on the market all with different screen resolutions, amounts of memory, processors and video hardware. On top of that, they often have different versions of Android and sometimes even custom builds of the operating system.

All of this makes guaranteeing that your game will run on all devices equally almost impossible.

Some of these differences are more of a concern than others.

  • Processor isn't a massive problem, but could be if the game compiles to native code and the processor can't support the compiled code ( Unlikely - the low level compiler includes code for various chipsets ). However the biggest concern is the speed of it. A slow processor might not be able to handle your game at the framerate you need.
  • Memory could be a problem if it's particularly low. Be sure to clear up after yourself and use object caching wherever possible to minimise the need for garbage collection.
  • The Screen resolution - in particular the aspect ratio (the ratio between width and height) will mean that your game will look different on different devices. Will that affect gameplay, giving a different play experience?
  • The video hardware may support different types of texture compression. This is important if you use a lot of art assets on screen at any given time. There isn't a 'one standard format' which everyone adheres to, it's dependant on chipsets for the most part.
    • GLES 2.0 ETC1 - (Supported on most devices - No Alpha, RGB only)
    • GLES 3.0 ETC2 - (Small percentage of market - RGBA)
    • PVRTC - Power VR - (Only supported on PowerVR chips / iOS - RGBA)
    • ATITC - ATI Compression - (Only supported on ATI chips - RGBA ) 
    • S3TC (DXT) - (DirectX Texture format, NVidia and others - Default for Monogame on Android)
  • The version of the O/S may throw unexpected spanners in the works. Different versions of Android may behave in slightly different ways and given that Android is open-source, there is always the chance that there are implementations of features which differ enormously from device to device.


The fact is that once on the market, the end customer will feel cheated if the game doesn't run properly on their device - and so they should, after-all the game was marketed to them and made available for purchase for their device and the vendor was happy enough to take their money.

It's not all bad though, understanding the problems only illuminates possible solutions.

The Google Play store offers tools to narrow down the sale to known devices or to restrict poorly preforming devices you can see metrics on how your app is performing (crashes and so on). It also offers the ability to roll out a staged release with Alpha and Beta testers being given access to install the game and report their findings.

Google also provide some fun things like achievements, leaderboards and events. These can be built into a game by accessing the Google Play API.

So back at Songbird HQ, we put more time into ROO!, more time than it took to create initially.

We've put in some more time to make sure that the game runs smoothly on different devices and that it supports various forms of texture compression - which means that we've had to alter the asset generation pipeline and that we have to publish 3 different APKs to the store.

To accomplish this, we modified the Monogame framework itself. One of the awesome benefits of using an Open Source framework over a closed source Engine is that you can make changes to it if you need to.

 Of course open source engines exist, however most people consider Unity before researching alternatives.

We've overhauled the UI to include buttons instead of the very simple menu we had before.

We've built in the Google Play API component to allow for achievements and leaderboards.

We've also been pepping up the graphics a little after getting feedback from players. Players who of their own volition wanted "just another go..." - very encouraging.

Get ready for the weekend!
We'll be working on the game some more on this weekend for a final push with the view to get it onto the Play store ready for Valentines evening.
Hopefully though this won't cause any rifts in relationships when partners are playing ROO! over a romantic Valentine's dinner.

We're not entirely settled on a price point yet, but it's going to be low - like a can of soda low. Cheaper than a burger or a game of pool at the local pub.

So in closing...
Games are easy to make if you know what you're trying to build and you have the experience to put them together.

If you don't have the experience, they'll take a bit longer while you obtain it and if you don't know what you're trying to build - well, that could take a while longer still, but keep trying anyway.

Understanding the obstacles in your way is the first step to overcoming them.










Tuesday, 25 November 2014

London Game Craft

On the 29th of November, Songbird Creations will be attending the London GameCraft Jam at The Skills Matter eXchange.


We won't be working on a game however we will be providing green-screen and image processing facilities for the developers there so they can quickly get some nice real-life graphics made without worrying about it. We'll be taking care of the capture, chromakey and processing - the end result being a nice texture file and plist using texture packer.

We'll be bringing some props with us although, the theme for the day hasn't been announced - so that'll be interesting.


So if you're attending the Jam, pop over and say Hi. I'll probably be decked out in a green-screen suit, so I'll be invisible.... :-)

https://skillsmatter.com/conferences/6610-london-gamecraft-2014-part-trois

Sunday, 28 September 2014

Box2D Raycasting with Category Masking with MOAI

What is Ray Casting?

Ray Casting is a technique used to determine whether something intersects a line drawn between one point and another. Normally Box2D uses circles, rectangles and polygons to determine collisions and resolve the forces and positions appropriately. However sometimes you just want to check for collisions along an imaginary line.

Imagine a Laser Pointer

One example for this is if you imagine a laser pointer.
Its beam is emitted from the end of the laser pen and it continues until it hits the wall at the far end of the room and leaves a pleasant red dot.

Should something break the beam, the red dot shows on the object breaking the beam and no longer on the wall.

Before MOAI 1.5

For a long time, MOAI did not support the ray casting features of Box 2D. Version 1.5 supports the closest raycast implementation where the closest object on the path of the ray is returned.

The Closest raycast feature is very much like the laser pen example. A ray is cast and the first thing which intersects the ray is returned.

A lot of the time, this is all you need.

It will find the closest Box2D fixture intersecting the ray no matter what it is.

Category Masking?

I needed something a little extra. Box2D supports categories. This is so you can designate an object as a particular type of thing so it can be included or excluded in specific collisions.

For my game I have several categories for objects.

  • FLOOR = 1
  • PLAYER = 2
  • OBJECT = 4
  • MONSTER =8
  • SWITCH = 16
  • POWERUP = 32

My laser beams should only be stopped by Players, Monsters and the Floor. Objects, Powerups and Switches should not get in the way - let alone be blown up by lasers.

I need a mask to filter only the categories I'm interested in.
FLOOR + PLAYER + MONSTER = 11

By performing a bitwise AND against the category for the object intersecting the ray and the mask, we can check to see if we're interested in it.

Here's a little binary refresher so you can see why the mask works.

Floor   = 00000001
Mask    = 00001011
Yup

Player  = 00000010
Mask    = 00001011
Yarp

Monster = 00001000
Mask    = 00001011
Yessir

Switch  = 00010000
Mask    = 00001011
Nope

However... 

Box2D doesn't support category masking for RayCasts, even though it supports categories and masks for all other types of collision detection.

This meant that even with the implementation in MOAI release 5, I couldn't use the Box2D ray casting. In fact, it meant I couldn't use Box2D* at all without making some changes.

*I'm using Box2D v 2.2.1 within MOAI - the most recent appears to be 2.3.0 (as of time of writing) however it too does not support masking.

So I modified Box2D to suit.

UDiff for Box2D 2.2.1


 3rdparty/box2d-2.2.1/Box2D/Collision/b2Collision.h     |  1 +
 3rdparty/box2d-2.2.1/Box2D/Collision/b2DynamicTree.h   |  1 +
 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp        | 18 ++++++++++++++++--
 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.h          |  3 +++
 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.h |  2 +-
 5 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/3rdparty/box2d-2.2.1/Box2D/Collision/b2Collision.h b/3rdparty/box2d-2.2.1/Box2D/Collision/b2Collision.h
index 8bb316c..62c7ee8 100644
--- a/3rdparty/box2d-2.2.1/Box2D/Collision/b2Collision.h
+++ b/3rdparty/box2d-2.2.1/Box2D/Collision/b2Collision.h
@@ -147,6 +147,7 @@ struct b2RayCastInput
 {
  b2Vec2 p1, p2;
  float32 maxFraction;
+ uint16 maskBits;
 };

 /// Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2
diff --git a/3rdparty/box2d-2.2.1/Box2D/Collision/b2DynamicTree.h b/3rdparty/box2d-2.2.1/Box2D/Collision/b2DynamicTree.h
index 0787785..ed4afce 100644
--- a/3rdparty/box2d-2.2.1/Box2D/Collision/b2DynamicTree.h
+++ b/3rdparty/box2d-2.2.1/Box2D/Collision/b2DynamicTree.h
@@ -254,6 +254,7 @@ inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) con
  b2RayCastInput subInput;
  subInput.p1 = input.p1;
  subInput.p2 = input.p2;
+ subInput.maskBits = input.maskBits;
  subInput.maxFraction = maxFraction;

  float32 value = callback->RayCastCallback(subInput, nodeId);
diff --git a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp
index d77e80a..b3497e1 100644
--- a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp
+++ b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp
@@ -1013,7 +1013,7 @@ struct b2WorldRayCastWrapper
  {
  float32 fraction = output.fraction;
  b2Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
- return callback->ReportFixture(fixture, point, output.normal, fraction);
+ return callback->ReportFixture(fixture, point, output.normal, fraction, input.maskBits);
  }

  return input.maxFraction;
@@ -1023,7 +1023,7 @@ struct b2WorldRayCastWrapper
  b2RayCastCallback* callback;
 };

-void b2World::RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const
+void b2World::RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2 ) const
 {
  b2WorldRayCastWrapper wrapper;
  wrapper.broadPhase = &m_contactManager.m_broadPhase;
@@ -1032,6 +1032,20 @@ void b2World::RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b
  input.maxFraction = 1.0f;
  input.p1 = point1;
  input.p2 = point2;
+ input.maskBits = 0;
+ m_contactManager.m_broadPhase.RayCast(&wrapper, input);
+}
+
+void b2World::RayCast2(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2, const uint16 maskBits ) const
+{
+ b2WorldRayCastWrapper wrapper;
+ wrapper.broadPhase = &m_contactManager.m_broadPhase;
+ wrapper.callback = callback;
+ b2RayCastInput input;
+ input.maxFraction = 1.0f;
+ input.p1 = point1;
+ input.p2 = point2;
+ input.maskBits = maskBits;
  m_contactManager.m_broadPhase.RayCast(&wrapper, input);
 }

diff --git a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.h b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.h
index 965a366..d910e23 100644
--- a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.h
+++ b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.h
@@ -121,6 +121,9 @@ public:
  /// @param point2 the ray ending point
  void RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const;

+ void RayCast2(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2, const uint16 maskBits ) const;
+
+
  /// Get the world body list. With the returned body, use b2Body::GetNext to get
  /// the next body in the world list. A NULL body indicates the end of the list.
  /// @return the head of the world body list.
diff --git a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.h b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.h
index 82ffc02..a485d8c 100644
--- a/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.h
+++ b/3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.h
@@ -149,7 +149,7 @@ public:
  /// @return -1 to filter, 0 to terminate, fraction to clip the ray for
  /// closest hit, 1 to continue
  virtual float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point,
- const b2Vec2& normal, float32 fraction) = 0;
+ const b2Vec2& normal, float32 fraction, uint16 maskBits) = 0;
 };

 #endif


As you can see, the changes merely extend Box2D's raycast feature to include a request for a specific set of maskBits.  Box2D doesn't perform any filtering internally with this change.

Category checking against the mask will be done within MOAI's implementation coming up next.

Note also that I create a function called RayCast2 which can be called with the maskBits parameter. This is just in case the Original RayCast function is used internally by Box2D and to ensure that other programs using it won't be broken by this change.


Initially it felt like overkill to modify Box2D to just pass a number through and back again. However this is required because the raycast function uses a callback to notify the program that it found something - this callback doesn't have any context as to how it's being called really to know what type of fixture you're looking for.

So apart from hard coding it to ignore sensor type fixtures, you're stuck just returning the closest object of any category unless you pass the mask through to the callback function.

Basically, Box2D doesn't know to inform the callback function that you're really only interested in UFOs and it can ignore Clouds.

Here's the UDiff for the MOAI code 

(Note patch is for 1.4r2 not for MOAI v1.5 - although the change is simple to apply to 1.5 )

 src/moaicore/MOAIBox2DWorld.cpp                  | 104 +++++++++++++++++++++++
 src/moaicore/MOAIBox2DWorld.h                    |   1 +

 2 files changed, 105 insertions(+)

diff --git a/src/lua-headers/run.sh b/src/lua-headers/run.sh
old mode 100755
new mode 100644
diff --git a/src/moaicore/MOAIBox2DWorld.cpp b/src/moaicore/MOAIBox2DWorld.cpp
index 943cbf0..20b39fe 100644
--- a/src/moaicore/MOAIBox2DWorld.cpp
+++ b/src/moaicore/MOAIBox2DWorld.cpp
@@ -46,6 +46,8 @@ MOAIBox2DPrim::MOAIBox2DPrim () :
  mDestroyNext ( 0 ) {
 }

+ 
+
 //================================================================//
 // local
 //================================================================//
@@ -600,6 +602,107 @@ int MOAIBox2DWorld::_getAutoClearForces ( lua_State* L ) {
  return 1;
 }

+// local
+ //================================================================//
+ 
+// RayCast modification from: http://getmoai.com/forums/post2723.html?hilit=raycast#p2723
+// Additional box2d modification to return fixtureIndex as well.
+class RayCastCallback : public b2RayCastCallback
+{
+public:
+    RayCastCallback()
+    {
+        m_fixture = NULL;
+ m_point.SetZero();
+ m_normal.SetZero();
+    }
+
+    float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction, uint16 maskBits)
+    {
+        
+ b2Filter filter = fixture->GetFilterData ();
+
+ 
+ //MOAILog ( state,MOAILogMessages::MOAIRayCast_MaskBits, maskBits );
+ if( (filter.categoryBits & maskBits) != filter.categoryBits )
+ {
+ return -1; 
+ }
+ /*if( ( MOAIBox2DFixture* )fixture->IsSensor()){
+ return -1; //filter
+ }*/
+
+ m_fixture = fixture;
+        m_point = point;
+        m_normal = normal;
+
+        return fraction;
+    }
+
+    b2Fixture* m_fixture;
+    b2Vec2 m_point;
+    b2Vec2 m_normal;
+};
+
+//----------------------------------------------------------------//
+/**     @name   getRayCast
+        @text   return RayCast 1st point hit
+
+        @in     MOAIBox2DWorld self
+        @in     number p1x
+        @in     number p1y
+        @in     number p2x
+        @in     number p2y
+        @out    bool true if hit, false otherwise
+        @out    number  hitpoint.x or nil
+        @out    number  hitpoint.y or nil
+ @out MOAIBox2DFixture fixture that was hit, or nil
+*/
+
+int MOAIBox2DWorld::_getRayCast ( lua_State* L ) {
+ MOAI_LUA_SETUP ( MOAIBox2DWorld, "U" )
+ float p1x=state.GetValue < float >( 2, 0 ) * self->mUnitsToMeters;
+ float p1y=state.GetValue < float >( 3, 0 ) * self->mUnitsToMeters;
+ float p2x=state.GetValue < float >( 4, 0 ) * self->mUnitsToMeters;
+ float p2y=state.GetValue < float >( 5, 0 ) * self->mUnitsToMeters;
+ uint16 maskBits = ( uint16 ) state.GetValue < u32 >( 6, 0 );
+
+ b2Vec2 p1(p1x,p1y);
+ b2Vec2 p2(p2x,p2y);
+
+ RayCastCallback callback;
+ self->mWorld->RayCast2(&callback, p1, p2, maskBits);
+
+ if (NULL != callback.m_fixture)
+ {
+ b2Vec2 hitpoint = callback.m_point;
+
+ lua_pushboolean( state, true );
+ lua_pushnumber ( state, hitpoint.x / self->mUnitsToMeters );
+ lua_pushnumber ( state, hitpoint.y / self->mUnitsToMeters );
+
+ // Raycast hit a fixture
+ MOAIBox2DFixture* moaiFixture = ( MOAIBox2DFixture* )callback.m_fixture->GetUserData ();
+ if ( moaiFixture )
+ {
+ moaiFixture->PushLuaUserdata ( state );
+
+ return 4;
+ }
+ else
+ {
+ return 3;
+ }
+ }
+ else
+ {
+ // Raycast did not hit a fixture
+ lua_pushboolean( state, false );
+
+ return 1;
+ }
+}
+
 //----------------------------------------------------------------//
 /** @name getGravity
  @text See Box2D documentation.
@@ -998,6 +1101,7 @@ void MOAIBox2DWorld::RegisterLuaFuncs ( MOAILuaState& state ) {
  { "setGravity", _setGravity },
  { "setIterations", _setIterations },
  { "setLinearSleepTolerance", _setLinearSleepTolerance },
+ { "getRayCast", _getRayCast },
  { "setTimeToSleep", _setTimeToSleep },
  { "setUnitsToMeters", _setUnitsToMeters },
  { NULL, NULL }
diff --git a/src/moaicore/MOAIBox2DWorld.h b/src/moaicore/MOAIBox2DWorld.h
index 61a6641..7d0880c 100644
--- a/src/moaicore/MOAIBox2DWorld.h
+++ b/src/moaicore/MOAIBox2DWorld.h
@@ -98,6 +98,7 @@ private:
  static int _getAutoClearForces ( lua_State* L );
  static int _getGravity ( lua_State* L );
  static int _getLinearSleepTolerance ( lua_State* L );
+ static int _getRayCast ( lua_State* L );
  static int _getTimeToSleep ( lua_State* L );
  static int _setAngularSleepTolerance ( lua_State* L );
  static int _setAutoClearForces ( lua_State* L );

So there you go. Raycasts with masking.
If I only want to shoot UFOs with my lasers, not the clouds in the sky, now I can.

So how do we use this in game?

Somewhere in your game code you'll have something which creates your MOAIBox2DWorld.
You'll be calling the getRayCast method on this object.

gameworld = MOAIBox2DWorld.new ()

Then somewhere you'll need a function to actually cast the ray and return the data back.
The function returns several parameters (typical for Lua).

  • Whether the ray hit something or not, 
  • the X co-ordinate of the hit,
  • the Y co-ordinate of the hit 
  • the object with a category matching the maskBits that the ray hit.


return gameworld:getRayCast( x1,y1,x2,y2, maskBits)



Sorry for the ugly formatting - I'm sure there's a nicer way to present a UDiff.

Have fun.


Special thanks to FiveVoltHigh.com for getting me started with their initial tutorial on patching MOAI with support for RayCasts.

http://www.fivevolthigh.com/2013/10/moai-exposing-box2d-world-ray-casting-to-moai/