logologologologo
  • home
  • learn to code
    • Space Invaders – Beginner’s Course
    • Asteroids – Beginner’s Level 2
    • Snake – a Beginner’s Challenge
  • learn to make
    • Arduino Tutorials
  • blog
    • Computer Science
    • Coding
      • Collision Detection
    • Retro Gaming
    • Computer Games for Vision Therapy
  • contact me
Simulating velocities with vectors code tutorial
Learn to Code Asteroids – Lesson 2 – Moving With Vectors
19th December 2019
Point in Polygon Collision Detection Tutorial
Learn to Code Asteroids – Lesson 4 – Point in Polygon Collision Detection
1st January 2020
Published by Bob at 1st January 2020
Categories
  • Learn to Code Asteroids
Tags
Random Vector Asteroids Tutorial

Learn to Code Asteroids – Lesson 3 – Generating Random Vector Asteroids

We’ve now got all the code we need to create move and draw our vector shapes on screen. We’ve got our player ship moving and rotating and we can use thrust button to accelerate it in any direction. We now need to add in some asteroids.

These too will be defined as vector objects but we don’t want them all to be the same shape. In this lesson will work out an algorithm that lets us generate random vector asteroids so that we can use our vector handling code to model them and include them in our game.

Creating algorithms, which are basically methods for performing certain tasks, is one of the main parts of writing any program. Some algorithms will be quite short such as our code to rotate a point around the origin. Others will be a bit more complex and requires to design the way in which algorithm will work before we go anywhere near our computer. For our random vector asteroid algorithm we’re going to have to work out how to create a series of points that describe the shape of asteroid keeping it within a certain range of sizes, but also making sure it looks like a proper boulder floating in space.

Again I’ll be talking you through all the theory behind the algorithm before asking you to have a go at programming it yourself. The more programming practice you get the better you’ll become. Once you’ve had a chance to develop their own code I’ll then take you through my solution to the algorithm so we can all get to a full working model by the end of the lesson.

As usual the full code for this lesson is available below.

Code for Lesson 3

Download the code for this lesson
Share
2
Bob
Bob

Related posts

Lesson 9
11th April 2020

Learn to Code Asteroids – Lesson 11 – Alien Missiles Incoming


Read more
Lesson 9
29th March 2020

Learn to Code Asteroids – Lesson 10 – Alien Ships Sighted


Read more
Lesson 9
5th February 2020

Learn to Code Asteroids – Lesson 9 – Speeding Up The Code


Read more

Comments are closed.

  • Privacy Policy
  • Contact Me
© 2020 Bytes N Bits