Static Member Variables

There is a bug in the collision code that is easy to address, a mover can get stuck on the border of the window if it’s gone far enough past the edge before getting tested, to address this, we can move the object away from the edge to prevent it getting stuck. [pastacode lang=”markup” manual=”void%20mover%3A%3AedgeCollision()%0A%7B%0A%20%20%20%20if%20(%20(position.getX()%20%2B%20width%20%3E%3D%20SCREEN_WIDTH)%20)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20position.setX(SCREEN_WIDTH%20-%20width)%3B%0A%20%20%20%20%20%20%20%20velocity.setX(velocity.getX()%20*%20-1)%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(position.getX()%20%3C%3D%200)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20position.setX(0)%3B%0A%20%20%20%20%20%20%20%20velocity.setX(velocity.getX()%20*%20-1)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20if%20(%20(position.getY()%20%2B%20height%20%3E%3D%20SCREEN_HEIGHT)%20)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20position.setY(SCREEN_HEIGHT%20-%20height)%3B%0A%20%20%20%20%20%20%20%20velocity.setY(velocity.getY()%20*%20-1)%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(position.getY()%20%3C%3D%200)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20position.setY(0)%3B%0A%20%20%20%20%20%20%20%20velocity.setY(velocity.getY()%20*%20-1)%3B%0A%20%20%20%20%7D%0A%0A%7D”

Smart Mass

Smart Mass Now we need to add mass to our objects to make the physics system a little more robust: we’ll simply add float mass to our object, update the constructor to allow us to set this float, and in the applyForce() function we’ll divide the force by the mass of the object to get our

Force Bug

Last time we ran into a bug where forces were not having the expected effect, today we’ll look into solving that. To start off with, we have two vec2 objects: wind and gravity. Wind has a value of 5,0 and gravity has a value of 0,1. We want a sum of the force vectors and we create

A Force to be Reckoned With

Newton’s second law states that Force = Mass * Acceleration and with this simple statement we can add forces to our objects. To simplify things, we’ll say for now that all of our objects have a mass of one, which simplifies the expression to Force = Acceleration, therefore we can simply apply the net of

Thinking Objectively

Our code is getting quite messy now that we’ve added all these variables to track velocity, position, acceleration, etc in the main function, so I think it’s time to roll another class that will contain all the things we need for an object with the following traits: position velocity acceleration max speed SDL_Texture and have

Picking up the pace

Today I’m looking at adding acceleration (another vector!) to my code, essentially it works like this: Our location vector is our current point in space. Our Velocity vector is our change in location over time. Our Acceleration vector is our change in velocity over time. The reason we were having issues with strangeness when we

Getting Physical

Here’s where things get interesting, I will be referring to Daniel Shiffman’s work over at shiffman.net, he’s done excellent work on simple physics for programming, most of his work is done in P5.JS but it should be easily adaptable to any language.   First we will create a vector that contains the objects position and set

Getting a handle on things

The event handler is a way for us to interface with the program, it will monitor for events, store them in a queue and let us iterate through them and have actions taken based on the input. This will let us use the x to close the window and end the program, among other things.

More cleanup!

Now that Christmas is over with I can get back to some work (play?) on my SDL experience, todays order of business is splitting the code from the main.cpp file into several header and source files to help make everything more tidy and to also remind myself how this all works.   First a few

Completing the second tutorial section

In completing the second section of the TwinkleBearDev tutorial, they pose an exercise for the reader: given an image to small to fill the background, how do we tile the background such that the image fills the available area? My solution was to use SDL_QueryTexture to get the width and height of the image and