Jump to content


Photo

Simple Movement Code


  • This topic is locked This topic is locked
6 replies to this topic

#1 santa22

santa22

    GMC Member

  • GMC Member
  • 249 posts

Posted 02 July 2005 - 04:09 PM

i have a movement code.
put this in step of character
if keyboard_check(vk_right) then x += 4
if keyboard_check(vk_left) then  x -= 4

Edited by santa22, 02 July 2005 - 04:10 PM.

  • 0

#2 santa22

santa22

    GMC Member

  • GMC Member
  • 249 posts

Posted 02 July 2005 - 04:24 PM

i have made somting better scripts for a platform game
put in step event of char
{
  gravity_direction = 270;
  if place_free(x,y+1)
    gravity = 0.5
  else
    gravity = 0;
  if (vspeed > 12) vspeed = 12;

{

if keyboard_check(vk_up) then if(!place_free(x,y+1)) vspeed:=-10;
   if keyboard_check(vk_right) then x += 4
  if keyboard_check(vk_left) then  x -= 4
  }
}


and put this in collision of a block

{
  if (vspeed > 0 && not place_free(x,y+vspeed)) move_contact(270);
  vspeed = 0;
}

Edited by santa22, 02 July 2005 - 04:26 PM.

  • 0

#3 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 02 July 2005 - 04:38 PM

i have made somting better scripts for a platform game

<{POST_SNAPBACK}>

Now only one question remains :

WHY HAVE YOU POSTED THOSE MESSAGES ? :D
  • 0

#4 santa22

santa22

    GMC Member

  • GMC Member
  • 249 posts

Posted 02 July 2005 - 04:45 PM

i dont know
  • 0

#5 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 02 July 2005 - 05:00 PM

i dont know

<{POST_SNAPBACK}>

Well, that makes two of us than :D
  • 0

#6 leif902

leif902

    GreenMan Games

  • New Member
  • 748 posts

Posted 02 July 2005 - 05:09 PM

hey santa22, since your new to gml try this, don't use a bunch of if statements use switch!

Like this:

switch (keyboard_key)
{
case vk_right: x+=4; break;
case vk_left: x-=4; break;
case vk_up: y-=4; break;
case vk_down: y+=4; break;
}

now, while this is more compact... theirs one problem... you can't move diagonal!

But anyway, just trying to help you out.

For more info on the switch statement, read the help file!

-Leif902
  • 0

#7 Smarty

Smarty

    GMC Member

  • Retired Staff
  • 7465 posts
  • Version:GM:Studio

Posted 02 July 2005 - 07:35 PM

Normally, things like this could go in the FAQ forum - except this may even be too easy for the FAQ forum.

I'm afraid not every scrap of GML is interesting enough to be be a topic's worth...

Smarty
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users