Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Information about object: obj_dude
- Sprite: spr_dude
- Solid: false
- Visible: true
- Depth: -1
- Persistent: false
- Parent: <no parent>
- Mask: <same as sprite>
- Create Event:
- execute code:
- //controller variables for returning the current velocity of movment
- yspeed=0
- xspeed=0
- //variables to check player input
- ymove=0
- xmove=0
- //inital velocity, and momentum
- inivel=2.5
- inimo=0.2
- //create an instance of our window controlling tool
- //instance_create(x,y,obj_windowcontrol)
- //create an instance of our debug tool
- instance_create(x,y,obj_debug)
- //and set the speed of animation down so we don't have to repeat frames manually
- image_speed=0.1
- Step Event:
- execute code:
- //shoot
- if keyboard_check(ord("Z")){
- instance_create(x+24,y+10,obj_bullet1)
- }
- //this codeblock controls movement
- //move up
- if keyboard_check(vk_up){
- if yspeed<inivel{
- yspeed+=inimo
- }
- ymove=1
- }
- //move down
- if keyboard_check(vk_down){
- if yspeed>-inivel{
- yspeed-=inimo
- }
- ymove=1
- }
- //move left
- if keyboard_check(vk_left){
- if xspeed<inivel{
- xspeed+=inimo
- }
- xmove=1
- }
- //move right
- if keyboard_check(vk_right){
- if xspeed>-inivel{
- xspeed-=inimo
- }
- xmove=1
- }
- //now we check to see if the player is pressing multiple keys at once, or pressing no keys
- if !keyboard_check(vk_right)&&!keyboard_check(vk_left){
- xmove=0
- }
- if !keyboard_check(vk_up)&&!keyboard_check(vk_down){
- ymove=0
- }
- if keyboard_check(vk_right)&&keyboard_check(vk_left){
- xmove=0
- }
- if keyboard_check(vk_up)&&keyboard_check(vk_down){
- ymove=0
- }
- //and finally, this codeblock controls the decending momentum
- if xmove=0&&xspeed>0{
- xspeed-=inimo
- }
- if ymove=0&&yspeed>0{
- yspeed-=inimo
- }
- if xmove=0&&xspeed<0{
- xspeed+=inimo
- }
- if ymove=0&&yspeed<0{
- yspeed+=inimo
- }
- //now we just update the x and y position of the player relative to our variables and we are good to go
- x-=xspeed
- if place_meeting(x,y,obj_block) { x+=xspeed; xspeed=0; }
- y-=yspeed
- if place_meeting(x,y,obj_block) { y+=yspeed; yspeed=0; }
- //debug controlling
- if keyboard_check_pressed(ord("O")){
- inimo+=0.1
- }
- if keyboard_check_pressed(ord("L")){
- inimo-=0.1
- }
- if keyboard_check_pressed(ord("I")){
- inivel+=0.5
- }
- if keyboard_check_pressed(ord("K")){
- inivel-=0.5
- }
- Draw Event:
- execute code:
- //fix graphics tearing
- draw_sprite(sprite_index,image_index,round(x),round(y))
Add Comment
Please, Sign In to add comment