Computer Science Canada Realistic Movement & Player Control |
Author: | Zasalamel [ Sun Dec 20, 2009 2:50 pm ] |
Post subject: | Realistic Movement & Player Control |
Most People know how to create moveable characters on the screen but may not know how to make it more realistic. But if you do not know how to create a movable character then that is here too. |
Author: | Zasalamel [ Sun Dec 20, 2009 4:11 pm ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Post subject: | First the basic movement controls!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Here is how the tutorial will be posted: - Below will be step by step code with comments in between the blocks of code - At the end i will add attachments of uncommented and commented completed code files - Also if you have any semblance of coding knowledge bear with me I go into some detail - If you have any questions please post them... First the screen...
These are the three most common window customizing commands View.Set and setscreen are basically the same but will not let you control the window var win := Window.Open will allow you to open and close the window screen is setting the screen in inches ( screen:10;20 ) graphics sets the screen in pixels max will automayically set the screen or graphics to fit the size of the monitor used. Next you will need your variables More Posted Later on the subject...
[size=16] chars is the variable that will store the keys pressed the x's are the x positions of your player ( we will be using a box as the player) the y's are the y position of the player the xv and yv are the velocities (speeds) of you player g is the gravity this is just for convenience so you can change it at the top of the screen ground is a boolean (true or false) that will be used to indicate that the player is touching a platform (this will be used only for multi-platform games) Next is the main loop:
This gives a value of the keys being pressed to chars
this basically says if keys being pressed equals (w key on keyboard) and and the player is on the screen and touching the ground then do this:
this will make the player jump by adding to the y velocity
else if key being pressed equals (a key on keyboard) and the box is on the screen then do this:
This subtracts 1 from the players y velocity (which will make the player move left)
if key pressed equals (d on keyboard) then
add 1 to x velocity to move the player right
if the bottom of the box not touching the ground then
subtract gravity from the velocity until the player moves down and touches the ground
if the bottom of the box is below the screen then
stop the box
move the box to the bottom of the screen
if the box is moving then
slow it down
if the box has gone off the left side of the screen then
move the box to the edge of the screen
stop the box
if the box has passed the right side of the screen then
move the box to the edge of the screen
and stop the box
if the box has passed the top of the screen then
move it to the top of the screen
stop the box
if the box is touching the bottom of the screen
ground = true (thus allowing the player to jump
otherwise
box cannot jump
adds the velocity to the x position to create movement *side note - xv needs to be rounded because it is not an integer but a real( or a decimal) round will convert xv to integer
adds the velocity to the y position to create movement *side note - yv needs to be rounded because it is not an integer but a real( or a decimal) round will convert yv to integer
the right side of the box = the left side plus 10 pixels This keeps the box the same size
the top of the box = the bottom of the box plus 10 pixels *keeps the box the same size
This Draws our player
brings the drawn images to the screen
makes the controls less responsive and easier to control
erases everything on the screen * so only the currently drawn box will show
More will be posted on the subject later Zasalamel |
Author: | SNIPERDUDE [ Sun Dec 20, 2009 6:05 pm ] | ||
Post subject: | RE:Realistic Movement & Player Control | ||
For those who want the code all in one place (for a nice copy and paste):
A couple things I changed: - There was a bug with jumping, the character kept getting stuck under 0 y, and thus couldn't jump (the velocity was automatically set back down to zero without moving the character) - I split the if statements for 'w' and the rest so you can both jump and move at the same time - I added an end using the ESC key. - I minimized the jump height so it looks about average for a side-scrolling game - I changed the setscreen and just added a title (and got rid of the buttons on top, since you can exit with the ESC key now). Also, I don't see any need to go into windows for this tutorial, just using the default will work fine for now (unless you get into multi-window games [ex: one window for gameplay, one for a map. Or two different windows for two different players {same keyboard}, one for a minimap]). Good post, I'm sure this will be useful for some. |
Author: | Zasalamel [ Sun Dec 20, 2009 6:17 pm ] | ||
Post subject: | RE:Realistic Movement & Player Control | ||
Keep in mind that this was just the very basic version of the tutorial With Improvements Later On. oh and the Window.Open is useful for the ESC key (ie:
it looks neater and more professional |
Author: | Tony [ Sun Dec 20, 2009 6:55 pm ] |
Post subject: | Re: RE:Realistic Movement & Player Control |
Zasalamel @ Sun Dec 20, 2009 6:17 pm wrote:
Window.Close(win) will never execute. |
Author: | Zasalamel [ Sun Dec 20, 2009 8:58 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
oops i was typing to fast i guess |
Author: | andrew. [ Sun Dec 20, 2009 11:06 pm ] | ||
Post subject: | RE:Realistic Movement & Player Control | ||
Here's what it should be:
|
Author: | TheGuardian001 [ Sun Dec 20, 2009 11:40 pm ] |
Post subject: | Re: First the basic movement controls!!! |
Zasalamel @ Sun Dec 20, 2009 4:11 pm wrote: screen is setting the screen in inches ( screen:10;20 ) No it isn't. screen and text modes both set the window in terms of rows and columns, based on the character sizes used by the put command. Just thought I'd point that out. |
Author: | Zasalamel [ Mon Dec 21, 2009 3:01 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
Thank you TheGuardian001 i was not sure. ( rows and columns do make more sense) |
Author: | livingheaven [ Sat Jan 09, 2010 10:02 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
Great tutorial =D best so far |
Author: | blizzard4800 [ Sun Jan 17, 2010 10:57 am ] |
Post subject: | RE:Realistic Movement & Player Control |
How do u make more than one platform |
Author: | Turing_Gamer [ Sun Jan 17, 2010 3:31 pm ] | ||
Post subject: | Re: Realistic Movement & Player Control | ||
Here you would have to array the platform pictures, like so...
|
Author: | SNIPERDUDE [ Sun Jan 17, 2010 4:02 pm ] |
Post subject: | Re: Realistic Movement & Player Control |
I'm sure the question was regarding collision detection regarding platforms as opposed to drawing multiple platforms. I'd look into the whatdotcolour and the collision detection tutorials on the Turing Walkthrough. (<- Link provided) |
Author: | evildaddy911 [ Thu Dec 08, 2011 11:43 am ] |
Post subject: | RE:Realistic Movement & Player Control |
looking through, I think that you should add a velocity cap, also, if you are using real variables for more realistic movement, make the x and y coords real too, the round() should be at the draw command |
Author: | Alex C. [ Wed Jan 11, 2012 10:15 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
thats great, but if you could add wall jumping into your tutorial i feel that it would be better |
Author: | evildaddy911 [ Sun May 06, 2012 10:37 am ] | ||
Post subject: | Re: Realistic Movement & Player Control | ||
add this in if you want wall jumping not sure how long constitutes necroing... sorry if 4 months counts |
Author: | Raknarg [ Sun May 06, 2012 2:40 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
It's only necroing if what you're putting up isn't useful, like how some people might post "Oh thats really cool" on a two year old post. |
Author: | eddie2222 [ Thu Jun 07, 2012 11:42 am ] |
Post subject: | RE:Realistic Movement & Player Control |
hey can you show me how to make a platform using the drawfill option so the box can actually stand and jump off of it thanks |
Author: | Raknarg [ Thu Jun 07, 2012 1:06 pm ] |
Post subject: | RE:Realistic Movement & Player Control |
1. Make your own topic for this sortof this please 2. HAve you looked into whatdotcolour before? |