as it is currently set to my sprites name
Welcome to one of my entry into the January 2008 Competition entry.
This is a code a developed for my upcoming game Assassins esscape.
Ill explain each line of code piece by piece.
The following code goes in the create event of your player dude
collision=1
down=1
cob=0
What this does since it being placed in the create event it defines them so you want come up with a error called Unknown variable. The create event is also where you can put code that you want only to happen when it gets created.
Used in dudes step event
if keyboard_check(vk_left) or keyboard_check(ord("A" )) then{ x-=4 if down=1 sprite_index=dude_L else sprite_index=dude_duck_L};
if keyboard_check(vk_right) or keyboard_check(ord(" D" )) then{ x+=4 if down=1 sprite_index=dude_r else sprite_index=dude_duck_r};
This two pieces of code are the codes for going LEFT or Right it first checks if you pressed vk_left or on the other hand right.Yes most games use the arrow keys but i rather using the W,A,S,D controlls so i added in the next part or keyboard_check(ord("A" )) what it does is check if the keyboard letter(thats what ord is for)is pressed if you dont have the quote around the letter you want it wont work and if the letter isnt in capitals it wont work either.
Used in dudes step event
if keyboard_check_pressed(vk_up) or keyboard_check_pressed(ord("W" ))and collision=1 and down=1 then { gravity=1 vspeed=-15 collision=0 };
This code is for the jumping.
You should know what the two first parts of code mean if you read the above.So why is there Collision=1 and down=1 This makes sure the collision is true before you can jump and your not ducking the codes that set these are further on in the tutorials.
So What does Gravity and vspeed do

Well Gravity is what makes you slower after you jump just like you jump in real life.You jump you come right back down.And vspeed is what makes it jump if you make it += instead of -= it would go down so dont make that mistake the opposite to vspeed is hspeed.
Goes in step event
if keyboard_check_pressed(vk_down)or keyboard_check_pressed(ord("S" ))and collision=1 and not place_free(x,y + vspeed + 1)then { sprite_index=dude_duck_r {gravity=20} down=0};
Yep another code this is for ducking this is quite simple all it does is change the sprite and change the varible down to 0
You can try it out now but there a small problem you dont change back so thats what the following code is for.
if keyboard_check_released(vk_down)or keyboard_check_released(ord("S" ))and down=0 then {cob=1 vspeed=-20 sprite_index=dude_r gravity=20 down=1};
This code does the same thing with the keyboard_check but it is set to released now do when you let go of a the specified key it would do the code after it if down=0 then it checks if the varible cob=1 and sets the vspeed to 20 to dislodge you from the ground and makes the gravity 20 and sets down to 1.
One problem with that is that you jump really high.
So i made a collision system which uses the cob variable we set earlier.
You require to make a object for this and call it cobo make it a sprite random that is not transparent but isnt visible.
Collision event with cobo
if cob=1 then{
cob=0
vspeed=0
}
Well this code check if cob=1 then it changes it to 0 and stops vspeed.
NOTE: This object has to be made 1 pixel higher then the dude in every part of the map to avoid the very high jump.
You may have noticed that sometimes the dude hovers in the air sometimes so i made this code.
Its goes in step event
if place_free(x,y + vspeed + 1) then gravity=1 else gravity=0
This checked if the place below the object is empty if it is it sets gravity to one else it sets it 0 kind of self explanatory.
The collisions for other objects.
Well heres what i did i made two parent object one for the wall and one for the floor so heres the two codes.
Collision event with Wall_parent
collision=1
speed=0
Collision event with floor_parent
vspeed=0
gravity=0
collision=1
This should give a double jump effect.
Hmm arent i forgetting something

Oh yeah the joystick support ill will only explain the joystick functions as the rest ive already explained
WARNING JOYSTICK CONTROLLS STUFF UP SOME STUFF WITH KEYBOARD CONTROLS SOME TIMES
if joystick_exists(1) then{
if joystick_check_button(1,2) and collision=1 and down=1 then { gravity=1 vspeed=-15 collision=0 };
if joystick_xpos(+0.25) then{ x+=4 if down=1 sprite_index=dude_r else sprite_index=dude_duck_r};
if joystick_xpos(1)<-0.3 then{ x-=4 if down=1 sprite_index=dude_L else sprite_index=dude_duck_L};
if joystick_check_button(1,1)and collision=1 and not place_free(x,y + vspeed + 1)then { sprite_index=dude_duck_r {gravity=20} down=0};
if not joystick_check_button(1,1) and down=0 then {cob=1 vspeed=-20 sprite_index=dude_r gravity=20 down=1};
}
joystick_exists(1)
This checks if the joystick exists
joystick_check_button(1,2)
This checks if the second button is pressed NOTE:the second number is the button number
joystick_xpos(+0.25)
Checks if the Joystick is right
joystick_xpos(1)<-0.3
Checks if the joystick is left
joystick_check_button(1,1)
Checks if the first button is pressed usually the trigger button
This is the end of the tutorial i hope you learn a lot from it and enjoy if you want to see this code in action look here [url=http://mihd.net/h975el[Download[/url]This is not a source code it is the start of my game im just showing it so you can see what it can do.
No joystick support in it tho
I write this tutorials in two hours

Death-Droid
Comments
Loading comments...