Posted: 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.
Sponsor Sponsor
Zasalamel
Posted: 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...
Turing:
setscreen("screen:max;max,offscreenonly") /* OR */ View.Set("graphics:500;500,offscreenonly") /* OR */ var win:=Window.Open("graphics:max;max,offscreenonly")
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...
Turing:
var chars :arraycharofboolean var x1 :int:=1 var x2 :int:= x1 + 10 var y1 :int:=1 var y2 :int:= y1 + 10 var xv :real:=0 var yv :real:=0 var g :real:=1 var ground :boolean:=false
[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)
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
Turing:
x2 := x1 + 10
the right side of the box = the left side plus 10 pixels
This keeps the box the same size
Turing:
y2 := y1 + 10
the top of the box = the bottom of the box plus 10 pixels
*keeps the box the same size
erases everything on the screen
* so only the currently drawn box will show
Turing:
endloop
More will be posted on the subject later
Zasalamel
SNIPERDUDE
Posted: 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):
Turing:
var chars :arraycharofboolean var x1 :int:=1 var x2 :int:= x1 + 10 var y1 :int:=1 var y2 :int:= y1 + 10 var xv :real:=0 var yv :real:=0 var g :real:=1 var ground :boolean:=true
setscreen("graphics:450;450,offscreenonly,nobuttonbar,title:Player Movement Tutorial")
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.
Zasalamel
Posted: 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:
Posted: 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)
evildaddy911
Posted: 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
Alex C.
Posted: 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