16
Programming Questions / Re: Ice Physics...
« on: November 16, 2015, 03:52:22 PM »
I'll see to it. I think that explanation and code modification is pretty much all I needed. Thanks a bundle, mate!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Hey, I implemented this real quick. The gist of it is I kept a state variable in the player called "slipping", which keeps track of if a player jumped off an ice block or not. I started off with my barebones project, and I marked my changes to the player's step event with comments starting with // PATRICK. Let me know if you have any questions I guess.
///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;
// If we're moving || 左右の移動
if (h != 0) {
// Set speed based on direction and maxSpeed || 走っている状態にする
hspeed = maxSpeed*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 {
// Set speed to zero || 直立状態にする
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();
}
}
Ours seem vastly different from one another.
var f,n;
dyingSave = argument0
n=EXECUTABLE_DIRECTORY + 'save' + string(global.savenum);
if (FS_file_exists(n)) {
f=FS_file_bin_open(n,2);
} else {
f=FS_file_bin_open(n,1);
}
FS_file_bin_write_dword(f,global.death);
FS_file_bin_write_dword(f,global.time);
if (!dyingSave) { //only save death,time for dying save
FS_file_bin_write_byte(f,global.difficulty);
FS_file_bin_write_dword(f,room);
FS_file_bin_write_dword(f,round(x));
FS_file_bin_write_dword(f,round(y));
FS_file_bin_write_byte(f,player.image_xscale+1); //+1 so -1=0, 1=2; bytes have no sign
//new values go under here
FS_file_bin_write_byte(f,global.hasPartner); //just a thing for the game I'm making
FS_file_bin_write_byte(f,global.clear[global.savenum]); //if this isn't an array then it will crash the game at the file select
}
FS_file_bin_close(f);
Loading script:var f,r,xx,yy,xs;
f = FS_file_bin_open(EXECUTABLE_DIRECTORY + 'save' + string(global.savenum),0);
global.death = FS_file_bin_read_dword(f);
global.time = FS_file_bin_read_dword(f);
global.difficulty = FS_file_bin_read_byte(f);
r = FS_file_bin_read_dword(f);
xx = FS_file_bin_read_dword(f);
yy = FS_file_bin_read_dword(f);
xs = FS_file_bin_read_byte(f)-1; //see saveGame to see why -1
//new values go under here
global.hasPartner = FS_file_bin_read_byte(f);
global.clear[global.savenum] = FS_file_bin_read_byte(f); //again, it will crash the game or just not save if it's not an array
FS_file_bin_close(f);
room_goto(r);
if (!instance_exists(player)) {
instance_create(xx,yy,player);
} else {
player.x=xx;
player.y=yy;
}
player.image_xscale=xs;
For some freakin' reason, even though it's in the order that klazen specified, this variable wants to choose whichever room you save in last as the clear value.// Init Other
timeCounter = 0;
// Init Menu Globals
for (i=1;i<=3;i++) {
global.menuDeath[i] = 0;
global.menuTime[i] = 0;
global.menuDiff[i] = 0;
global.clear[i] = 0;
}
// Checks Save Files
for(i = 1; i <= 3; i += 1){
if(FS_file_exists(EXECUTABLE_DIRECTORY + 'save' + string(i)) == true){
f = FS_file_bin_open(EXECUTABLE_DIRECTORY + 'save' + string(i),0);
// Load Data
global.menuDeath[i] = FS_file_bin_read_dword(f);
global.menuTime[i] = FS_file_bin_read_dword(f);
global.menuDiff[i] = FS_file_bin_read_byte(f);
global.clear[i] = FS_file_bin_read_byte(f);
FS_file_bin_close(f);
}
}
guiTimer=0; //time before GUI appears
guiOffset=0; //position of GUI
global.buildNumber = "Build 2";
Please tell me what I did wrong, as it's delaying the release of the game to some friends that want it (although I don't expect you to care).