Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Example / Listing] A little bit about Link's movement.  (Read 2141 times)

0 Members and 1 Guest are viewing this topic.

cloudsquall

[Example / Listing] A little bit about Link's mo...
« on: May 07, 2006, 11:59:37 am »
You might have noticed a problem with handling Link's movement with the conventional method
(you know, the
Code: [Select]
if place_free(x-something,y) {x-=something}thingy)

If for example something=2 and there is a solid object 3 pixels to the left of Link,Link will stop 1 pixel away from it.Most of the time this isn't
noticable,but when Link can just pass between two objects, a problem might occur.
So here's a workaround  for this:

Set two variables first:
Code: [Select]
global.xspeed=3;//or any other number
global.yspeed=3;//same here
Then in the step event:
Code: [Select]
if keyboard_check(vk_left)
{
     for (i=1; i<=global.xspeed; i+=1)
     {
           if place_free(x-1,y)  {x-=1}
     }
}

if keyboard_check(vk_right)
{
     for (i=1; i<=global.xspeed; i+=1)
     {
           if place_free(x+1,y)  {x+=1}
     }
}

if keyboard_check(vk_up)
{
     for (i=1; i<=global.yspeed; i+=1)
     {
           if place_free(x,y-1)  {y-=1}
     }
}

if keyboard_check(vk_down)
{
     for (i=1; i<=global.yspeed; i+=1)
     {
           if place_free(x,y+1)  {y+=1}
     }
}

That way Link will move by one pixel three times(or however many you want) each step
instead of moving by three pixels each step and the place_free check will occur for every pixel,letting Link move as close to a solid
object as possible.

[Alex Edit] - That colour is pretty much invisible on other skins. Your post has been edited to include code tags.
« Last Edit: February 09, 2012, 02:43:09 pm by Niek »
Logged
Re: A little bit about Link's movement.
« Reply #1 on: May 07, 2006, 12:08:15 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
Could I copy and paste this into the FAQ?
Logged

cloudsquall

Re: A little bit about Link's movement.
« Reply #2 on: May 07, 2006, 12:11:30 pm »
Of course  :D
Logged
Re: A little bit about Link's movement.
« Reply #3 on: May 07, 2006, 12:18:50 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
Hm.... prefect. Thats pretty amazing, but I write my own walking engines. It might be useful for someone though.

Great job.
Logged

Ben

Re: A little bit about Link's movement.
« Reply #4 on: May 07, 2006, 01:39:08 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Why can I not see that unless highlighted?

Well it's certainly an idea, yes. buuuuut seeing as you don't use i within the for loop just use GMs wonderful repeat syntax.
I love it :-p.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion

cloudsquall

Re: A little bit about Link's movement.
« Reply #5 on: May 07, 2006, 01:57:20 pm »
Okay then for everyone who wants something a bit easier, instead of typing:
for (i=1;i<=global.xspeed;i+=1)
{
     if place_free(x-1,y)
     {
            x-=1;
     }
}

type:
repeat(global.xspeed) {if place_free(x-1,y) {x-=1}}

Thanks Ben.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.313 seconds with 49 queries.

anything