How to code games for the PC and Xbox 360

After that, there's a call to the Vector2.Clamp() method. 'Clamping' a number means to ensure it falls within a specific range – in this example, we want to ensure that a player's velocity falls within the range -10.0f to 10.0f, otherwise they would be able to reach stupidly fast speeds.

Once the velocity has been clamped to acceptable levels, we add the player's velocity to their current position, which has the effect of moving the player as requested.

Over to you

You can add various other features to the game: asteroids are created and moved in much the same way the player is moved, you can fire lasers, and those lasers can collide with asteroids.

Try your hand at adapting the game by implementing these challenges:

Fun: Make those asteroids collide dangerously with the player.
Tricky: Make asteroids that move off the screen re-appear on the other side as if they had wrapped around.
Taxing: Make the laser recharge rather than have infinite shots.
Mayhem: Load more than one asteroid image: create different types of asteroid rather than just one type.

All code required to implement these can be figured out from existing code in your download: steal code freely, copy and paste like you mean it, then fiddle to get what you want.

XNA takes all the hard work out of making games, so you can focus on coming up with an original idea then implementing it with awesome-looking assets. Have fun!

-------------------------------------------------------------------------------------------------------

First published in PC Format, Issue 223

Now read 14 arcade machines that led to a misspent youth

Sign up for the free weekly TechRadar newsletter
Get tech news delivered straight to your inbox. Register for the free TechRadar newsletter and stay on top of the week's biggest stories and product releases. Sign up at http://www.techradar.com/register

Follow TechRadar on Twitter

Latest in Gaming
Indiana Jones talking to a friend in a university setting with a jaunty smile on his face
New leak claims Indiana Jones and the Great Circle PS5 release will come in April
The main character from Intergalactic: The Heretic Prophet performing a jump attack on a robot enemy.
Neil Druckmann reveals new details about Naughty Dog's Intergalactic: The Heretic Prophet, says it's 'a game about faith and religion' and wants players to be 'lost' and 'confused'
Doom: The Dark Ages
Doom: The Dark Ages' director confirms DLC is in the works and says the game won't end the way 2016's Doom begins: 'If we took it all the way to that point, then that would mean that we couldn't tell any more medieval stories'
Nintendo Switch 2
A Nintendo Switch 2 FCC filing confirms Wi-Fi 6 and NFC support for the upcoming console
A close-up of the PS5 Pro
PS5 Pro games will soon get something 'very similar' to FSR 4 for what Sony is calling 'the next evolution of PSSR'
Xbox Series X
Xbox is reportedly teaming up with a mystery manufacturer to launch a PC gaming handheld this year
Latest in News
An Nvidia GeForce RTX 4060 on a table with its retail packaging
Nvidia RTX 5060 GPU spotted in Acer gaming PC, suggesting rumors of imminent launch are correct – and that it’ll run with only 8GB of video RAM
Indiana Jones talking to a friend in a university setting with a jaunty smile on his face
New leak claims Indiana Jones and the Great Circle PS5 release will come in April
A close up of the limited edition vinyl turntable wrist watch from AndoAndoAndo
This limited-edition timepiece turns the iconic Technics SL-1200 turntable into a watch, and I want one
A close up of Gemma sitting down in Severance season 2 episode 7
'I'm like Gemma, I'm in the dark': Severance star Dichen Lachman shares disappointing filming update for the popular Apple TV+ show's third season
OpenAI
OpenAI wants to help your business build its next generation of AI agents
The main character from Intergalactic: The Heretic Prophet performing a jump attack on a robot enemy.
Neil Druckmann reveals new details about Naughty Dog's Intergalactic: The Heretic Prophet, says it's 'a game about faith and religion' and wants players to be 'lost' and 'confused'