The aim of this cycle is to get a working terrain generation which has a simple sine wave for collision.
Objectives
Key functions
Function Name
Use
generateTerrain
Renders a drawing of the terrain which will be randomized in a later cycle but is a sine wave for now
tCollision
Spawns in objects to add collision to the terrain as drawings don't have collision
Pseudocode
FUNCTION drawTerrain:
for i in WIDTH:
draw line from bottom of screen to sine wave in center
FUNCTION tCollision:
for i in WIDTH:
add collision rectangle every 16 pixels along the sine wave
onDraw(drawTerrain())
during "practice" scene:
tCollision()
Development
Outcome
The outcome is a sine wave terrain with collision coloured red and players now spawn on top of the terrain.
Challenges
There were many challenges encountered while completing this cycle. The first was finding an efficient way to render the terrain. Using a single polygon from the kaboom.js codebase and creating an array of points for the polygon to fill doesn't work as expected, as the fill attribute creates lines from the first point to all the other points on the polygon making it look wrong. To fix this a line from the bottom of the screen to the point on the sine wave was created on every 3rd pixel with a 3 pixel width in order to keep detail but also retain a higher fps count.
Another challenge was that the lines rendered by draw functions in kaboom have no collisions. This meant that small invisible rectangles with collision had to be put along the terrain, originally on every pixel, which created a lot of frame drops due to approximately 2000 objects being calculated by the game. Therefore they were made big enough to stop bullets falling through the ground with one being placed every 16th pixel along, which functions just as good as you would want it to.
Testing
Tests
Test
Instructions
What I expect
What actually happens
Pass/Fail
1
Run code
Kaboom should run
Kaboom ran normally
Pass
2
Enter "practice"
Terrain visualising a sine wave should be present
Terrain works
Pass
Evidence
A sine wave being used as the pattern for our generated terrain