Users browsing this thread: 2 Guest(s)
Kyrodian Legends
#9
(10-23-2014, 01:58 PM)DragonDePlatino Wrote: Whoa, very nice, man! I'm still working out the basics of acceleration-based movement in pygame, so the fluidity of your movement here looks simply astonishing. Big Grin

Oh, it's actually pretty simple. Here's what you'd put in your events. The logic can be easily ported into any language.

Create event/constructor:
Code:
xSpeed = 0;
ySpeed = 0;
maxSpeed = 4;

Step/frame:
Code:
//Friction
if(!place_free(x, y + 1)){
 if(xSpeed > 0) xSpeed -= 0.5;
 if(xSpeed < 0) xSpeed += 0.5;
};

//Gravity
if(place_free(x, y + 1)) ySpeed += 1;
else ySpeed = 0;

//Keyboard
if(keyboard_check(vk_left) && xSpeed > -maxSpeed) xSpeed -= 1;
if(keyboard_check(vk_right) && xSpeed < maxSpeed) xSpeed += 1;
if(keyboard_check_pressed(vk_space) && !place_free(x, y + 1)) ySpeed = -10;

//////////////////////////////////////////////////
//INSERT REST OF YOUR STEP EVENT HERE//
//////////////////////////////////////////////////

move(xSpeed, ySpeed);

Move script:
Code:
/*First we get a couple variables.
h is horizontal movement.
v is vertical movement.*/
h=argument0;
v=argument1;

/*Now what we do is instead of checking if a point is free a certain distance away,
we check every pixel ahead and then move a pixel until the loop runs out or we hit
a solid object.

i has to be absolute because if the speed is negative, it will cause the loop to
break, and we don't want that.*/
for(i=abs(h); i>0; i-=1){
   if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y+1) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width){
   x += h/abs(h);
   y += 1;
   }
   else
   if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y-1) && !place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width){
   x+=h/abs(h);
   y -= 1;
   }
   else
   if(place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width) x+=h/abs(h)
   else break;
};

for(i=abs(v); i>0; i-=1){
   if(place_free(x,y+(v/abs(v)))) y+=v/abs(v)
   else break;
};
Reply
Thanked by:


Messages In This Thread
Kyrodian Legends - by Kelvin - 07-28-2014, 12:32 PM
RE: Kyrodian Legends - by Kelvin - 07-31-2014, 05:12 PM
RE: Kyrodian Legends - by Kelvin - 09-13-2014, 04:30 PM
RE: Kyrodian Legends - by Kelvin - 09-24-2014, 02:03 PM
RE: Kyrodian Legends - by TheShyGuy - 09-24-2014, 03:14 PM
RE: Kyrodian Legends - by Kelvin - 09-26-2014, 07:38 AM
RE: Kyrodian Legends - by Kelvin - 10-23-2014, 07:52 AM
RE: Kyrodian Legends - by DragonDePlatino - 10-23-2014, 01:58 PM
RE: Kyrodian Legends - by Kelvin - 10-23-2014, 03:40 PM
RE: Kyrodian Legends - by Kelvin - 10-25-2014, 12:49 PM
RE: Kyrodian Legends - by Koh - 10-25-2014, 05:58 PM
RE: Kyrodian Legends - by Kelvin - 10-26-2014, 07:14 PM
RE: Kyrodian Legends - by UltraEpicLeader100 - 10-27-2014, 12:48 PM
RE: Kyrodian Legends - by Kelvin - 10-29-2014, 07:05 AM
RE: Kyrodian Legends - by Key0808 - 10-29-2014, 07:37 AM
RE: Kyrodian Legends - by Kelvin - 10-29-2014, 07:50 AM
RE: Kyrodian Legends - by Key0808 - 10-29-2014, 08:04 AM
RE: Kyrodian Legends - by Kelvin - 10-29-2014, 12:57 PM
RE: Kyrodian Legends - by Dragon_Throne - 10-29-2014, 09:53 AM
RE: Kyrodian Legends - by Quirby64 - 10-29-2014, 05:06 PM
RE: Kyrodian Legends - by Kelvin - 10-29-2014, 07:27 PM
RE: Kyrodian Legends - by Gors - 10-30-2014, 06:23 AM
RE: Kyrodian Legends - by Kelvin - 10-30-2014, 04:34 PM
RE: Kyrodian Legends - by Kelvin - 11-27-2014, 12:20 PM
RE: Kyrodian Legends - by Kelvin - 01-06-2015, 02:45 PM

Forum Jump: