Blog week 4 – Smart code? Powerup that influence the speed
|
However! I started to create the whole power up giving it the proper functions and variables, nothing to majorly fancy. I got it to spawn and behave like the other power ups, so now it was only the functioning of the power up left. I needed something that could change the speed of every scrolling entity in the program, or well that was how far I had thought trough before hand. So I created a variable wich would control the speed, so when I activated the power up it would change that to a higher value, and after a while it would change it back to the original value. Alright got that covered, now I only needed to make every active object adapt to this speed, so i created a loop for each of the different entities and set so their scrolling speed to what I would set the value to from the power up. Easy enough, so I tested it. Worked out great until i saw what happened when a new entity would spawn, it was as fast as if I would not have a power activated, it was easily fixed by just sending in the extra speed they would have before spawning it in. Alright, now we have a working speed up system with smart code wich could change the speed with the power up. Now I needed to create something that would slow down the game, like mud! Same story short, i created the class and so forth. So i spawned in the mud and when the mud intersected the player’s hit box it would slow down. This needed its own variable because I can not set the variable to be minus something since then everything would fly away in rocket speed. So i just had to send in the other variable with the first when im setting the speed of every entity. Either way, if the player would intersect with the mud it will slow down, else it would not. Since it checks every mud tile I can’t have it like this, so I needed something that could check if it still is intersecting the other time around, so I gave the mud class its own bool if it is slowing or not. So after the first collision test I made another that would check the first tile that would have the bool set to true and checked if the player still where colliding with the player, if it did slowed would still be true, otherwise it would turn it off making it a functioning way of controlling speed. |
