07.04.2020by adminC Game Dev Spherical GravityGame Development SoftwareGame Dev TycoonComputer Programming - C Programming Language - Games and Graphics Sample Codes - Build a C Program with C Code Examples - Learn C Programming. Aug 19, 2016 Technical Demo - Minetest on a spherical world. Contribute to Jeija/spheretest development by creating an account on GitHub.28 Feb 2015CPOLHow I made my 2D Game, a Mario platformer type of game. I searched around the internet for most of these things, but had trouble finding it. Especially collision detection that I ended up creating a simple solution by myself.IntroductionThis is work by a simple guy doing it for fun.When I made my first 2D game in C#, I had some problems with adding new blocks also getting working collision physics so the player wouldn't fall through the block or get stuck.That's when I searched around the cyberweb for some pointers, or any working code that I could learn from. But I never found any that isn't using the XNA framework. I find XNA pretty aids to work with.So I made my own, a simple collision detection that I would like to explain for others like myself.Here's an image of the game I made.Explanation of the gameYou're Mario, going against 2 Goombas following you and falling bombs as well as that Rockets are fired at you from the sides. (Not shown in the image however)There's 2 platforms, 1 Pipe (doesn't let you go through it :P)Whilst everything is happening, your goal is to collect as many coins as possible (falling from the sky randomly) and staying alive as long as possible.Keyboard InputThe keyboard input, where I move the character with Arrow keys (or (WASD) were used with the forms KeyDown/KeyUp event. Just an example how I did mine, as you can read there's a switch on which keypress is made and from there it does something depending on the key.If I press left arrow key, it changes my 'Move player Left' variable to true. GravityFor Gravity in this game, I was using a Timer that moves the character up and down depending on the following variables.Here's how the Space keyDown is set up: What this says is that, if the Player is not already jumping and the player is NOT in the air as well as NOT colliding with any block (also checks so the player is within the worldframe). My physics in this game works in the way that if there is any value in Force, the player is moved upwards (unless head is colliding with a block). If the Force is down at 0, the player starts falling.I made this with 2 timers (Can be done with 1, I like to sort them aside however). Here's how I did the falling code: And this is the jumping code: MovementLike in my example in the Keyboard input section, I use the following code to start moving: A Boolean for Player_Left, Player_RightI also have a timer that moves the character depending on whether the Boolean is true or not. This is just an example of how I use the code, like the Speed_movement is just an Int set to in my case 3. Block Collision In my code, I'm using PictureBoxes as the Player as well as WorldObjects. In this example, let's just have the following variables: I use 4 Boolean functions, to check if the Player is intersecting with the blocks sides, but to achieve this, I had to create some temporary rectangle on each side of the Block. For example, top collision:Line #1 What this does is that it creates a new pictureboxLine #2 Copies the bounds (The size of the source block, this case Block_1)Line #3 Sets the new bounds, at the same X axis, but 1 point above Block_1 and just as wide as Block_1See 'Using the code' section for the entire code, or download the source and try it out yourself.Using the CodeThis is the InAirNoCollision code as well as all the 4 Collision functions: Precision auto tune owings mills state inspection price. I've uploaded a .zip file containing an executable file, resource files (all the images), and a full documented source code.If you have any questions, feel free to email me at robert@hydeen.se.Game Development SoftwareGame Dev Tycoon