133
« on: November 15, 2015, 10:15:57 PM »
Ah, I'm assuming you started with the KS engine. I started with Yoyo's engine, which includes the yuuutu slip block logic, which I slightly modified. Here's a modified version of the code you just provided. It would have been nice to have your player step code from the start, now that I think about it.
///Movement and Controls
var L,R,h;
// Check if pressing left/right || 左右のキー入力のチェック
L = keyboard_check_direct(global.leftbutton);
R = keyboard_check_direct(global.rightbutton);
// If pressing right, go right || 右ボタンを押していれば右
// If not pressing right, and pressing left, go left || 右ボタンを押していない状態で左ボタンを押していれば左
h = R;
if (h == 0) h = -L;
// If frozen, don't move || frozenに値が入っていれば行動禁止
if (frozen == true) h = 0;
// PATRICK CHANGE - set slipping and slipval
var slipBlockTouching = instance_place(x,y+4*global.grav,oSlipBlock)
var blockTouching = instance_place(x,y+4*global.grav,block)
if slipBlockTouching != noone {
slipping = true
slipval = slipBlockTouching.slip
}
if (blockTouching != noone) and (slipBlockTouching == noone) {
slipping = false
}
// If we're moving || 左右の移動
if (h != 0) {
// PATRICK CHANGE - do either normal or slippery movement
if not slipping {
// Set speed based on direction and maxSpeed || 走っている状態にする
hspeed = maxSpeed*h;
}
else {
if (h == 1 and hspeed < maxSpeed) or (h == -1 and hspeed > -maxSpeed) {
hspeed += slipval * h
}
}
// 画像の左右を指定(負が入ると画像が左右反転する)
//flip=(image_xscale!=h);
xScale = h;
//image_xscale = h;
// Set the sprite to the running sprite || 走っている画像に変更
sprite_index = sprPlayerRunning;
image_speed = 0.5;
} else {
// PATRICK CHANGE - do either normal or slippery stopping
if not slipping {
// Set speed to zero || 直立状態にする
hspeed = 0;
}
else {
if hspeed > 0 {
hspeed -= slipval
if hspeed <= 0 hspeed = 0
}
else if hspeed < 0 {
hspeed += slipval
if hspeed >= 0 hspeed = 0
}
}
// Set the sprite to the idle sprite || 直立画像に変更
sprite_index = sprPlayerIdle;
image_speed = 0.2;
}
if (!onPlatform) {
// Set the sprite to jumping/falling if we're moving vertically and were not on a platform || ジャンプ・落下画像に変更
if (vspeed < -0.05) {
sprite_index = sprPlayerJump;
}
if (vspeed > 0.05) {
sprite_index = sprPlayerFall;
}
} else { // If we were on a platform, but we're not anymore, then set onPlatform to false || 動く台に乗ってる状態から解除された瞬間
if (place_meeting(x,y+4,platform) == false) {
onPlatform = 0;
}
}
// Limit vspeed || vspeedが最大値を超えたら、最大値に固定
if (vspeed > maxVspeed) {
vspeed = maxVspeed;
}
// If not frozen || frozenに値が入っていない(行動可能)
if (!frozen) {
// Shoot || プレイヤーの攻撃
if (keyboard_check_pressed(global.shotbutton)) {
playerShoot();
}
// Jump || ジャンプ(押した)
if (keyboard_check_pressed(global.jumpbutton)) {
playerJump();
}
// Jump Release || ジャンプ(離した)
if (keyboard_check_released(global.jumpbutton)) {
playerVJump();
}
}
The object oSlipBlock should be solid and have block as its parent. it should also have the variable "slip" set in its create event; the default value in yuuutu is 0.2.
Also, in the create event of the player, you should define these variables:
slipping = false
slipval = 0
You should look through the player step code and find all the comments where I changed something, and get the gist of how it works. You might have to modify it a little, I'm not sure.
EDIT: here's the gist of how my changes work:
1. In the player object, keep track of a variable called "slipping", which keeps track of whether the player should currently be slipping or not. To do this, we set it to true if we detect we're standing on a slippery block, and false if we're standing on a normal block. This way it remembers the state until we next touch a ground. This is the first code block I added towards the top.
2. Modify the player horizontal movement and stopping behavior to each have alternate slipping behaviors. I added if statements depending on the slipping variable, and copied the slip behaviors from the yuuutu engine. These are the second and third code blocks I modified.
3. Also keep track of a variable called "slipval", which keeps track of the "slip" variable of the last slippery block the player touched. The yuuutu slippery block behavior didn't need this because the player could just re-check the slip value of the block it was standing on, but since we're in the air sometimes we need to keep track of it. This explanation isn't the clearest, but I hope it helps a little.