Jumping Right In - Second Dev Log


Wow alot has happened to get to this point releasing dev log 2

The next thing I did after last release was to add jumping and gravity functionality... I added a class expiclity for managing velocity called the velocity trait - Traits are how I manage functionality that I might want on more then one class from different families. Each trait containing the code for how it should work and interact with other traits...

Anyway in the velocity trait, I created a function called apply force.... apply force simply adds a force to the target vector which we use to work out how much to translate the object across the screen that frame... To get gravity working i simply apply a downward force every frame...

however the apply force and velocity system in general has a degree of acceleration and interpolation between the target vector and the actual speed; this makes gravity work out youd expect it, and doesnt look as jaring as your character suddenly starting and stopping, but its very subtle.... 

anyway because of this I could not use apply force for jumping.... instead i just added lots of force to the current velocity variable, and let the interpolation pull the velocity back to the target vector bring the player back down.

During this I was thinking ways to get collision to work for platforms, I worked out complicated maths that would allow you to work out when intersecting with an object with the collision trait where it should collide. I programmed this and it worked to some degree but it needed some ironing out, and I disliked it in its complicateness, maintaining a project with complicated code is harder after all. When trying to clean the code I accentally stumbled on a much more elligant solution for my purposes... If the players velocity is going down, and player/object bounds intersecting with the collison objects bounds, set the players Y position to the top of the platforms poition, after, if we set the Y velocity to 0, we can still allow the player to still jump (since jumping is based on vertical velocity... and yes that does mean u can do a double jump... but since the numbers are times by a delta time (time between frames) variable the chance there would be a velocity of 0 mid air is low)

When messing around with adding background before I noticed some serious slow down... my simple game was seemingly foiled with barely a character and a moving background... luckily for me after some searching I found a lovely reply on stack overflow explaining how to make drawing images to screen more efficent (https://stackoverflow.com/questions/11020710/is-graphics-drawimage-too-slow-for-bigger-images), mad props to him...

One thing that seems small but caused some issues was the squish and strech on the character. In animation when practing squish and strech it is important to keep the overal area of the object the same, only issue however that if i want to make the character strech as he jumps, i have to change the width, but, in my game objects are drawn from bottom left corner (as previously mentioned its normally drawn from the top but i flipped the Y axis). when i say I draw things from a certain direction... I dont... no the draw call still works the same... I just have offset maths in the rendering, which in the end is how i achieved squish and strech in my code... theres an offset based on the scale and the width in the draw function... world space and game logic wise however the size of the character never changes, this was done because if we drew everything from the center with different widths collision would break as things would appear that they are drawn from the center but the collison maths doesnt care how its drawn...

Another thing I implimented was the ablity to changed the game speed (programming wise), I added a variable into the delta time calculation for game speed... this means at a game speed of 0 no forces can be applied to anything in the scene since everything from gravity to the cameras movements are include the delta time calculation.

I use this game speed variable when you escape the application or when you press escape...

I also made it so when the game speed variable was 0... I would stop drawing frames... this might have to be changed in future tho for pause menus and stuff but for now means resources can be saved.

Finally I learnt, although its not very complicated, how to make an alert/dialogue pop up. I use this to ask a user if they want to quit the application when they press the escape key.

In the future I would like to obviously add enemies and obsticals, but to be honest what im really looking forward to is learning...

Heres some stuff I want to learn:

Create an installer program

looking into and impliment signing to stop that dam WARNING PROGRAM IS DANGERIOUS

DirectX (probably not this project but a future one)

Better practice when using .NET

and stuff I dont even know I got yet to learn

Files

Pixel Bot.zip 417 kB
Aug 31, 2020

Get Pixel Bot (.Net Experiment #2)

Comments

Log in with itch.io to leave a comment.

Well hot damn!!! That's some heavy lifting right there

Keep it up