在編程方面,我有些初學者,最近我在GameMaker Studio:Professional中爲一個學校項目編寫了一個遊戲代碼,並且遇到了一個小問題玩家在另一個敵人之上登陸。因爲現在我的玩家在足夠高的速度下不會註冊登陸並摧毀敵人的實例,而只是受到傷害(或者遊戲將會重啓,因爲我還沒有實現該部分)。已經測試了一些東西,似乎以更高的速度玩家跳過它可以摧毀敵人的範圍,而是傳遞到敵人附近受到傷害,儘管在低速時玩家只與敵人發生碰撞精細。玩家在可變高度跳轉,這個高度由他們持有空格鍵的時間量來控制。我相信這可能是由於我的重力價值,因爲它不是一個整數,但我不確定。我也嘗試給玩家添加一個終極速度,但是我嘗試過的仍然保持相同遊戲審美的數字並沒有解決這個問題。GameMaker Collision工作速度太快
這裏是我的兩個選手對象與敵方目標代碼: Player對象:
Create Event:
execute code:
hsp = 0
vsp = 0
grav = 1.5
movespeed = 8
move = 0
jumpsmax = 2
jumps = 0
jumpspeed = 18
dir = 0
Step Event:
execute code:
//Movement
//Main controls
key_right = keyboard_check(ord("D"));
key_left = keyboard_check(ord("A")) * -1;
key_jump = keyboard_check_pressed(vk_space);
key_jump_held = keyboard_check(vk_space);
move = key_left + key_right;
hsp = move * movespeed;
vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
jumps = jumpsmax;
}
if (keyboard_check(vk_down) != 1)
{
if (key_jump) && (jumps > 0)
{
jumps -= 1;
vsp = -jumpspeed;
}
}
if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-jumpspeed/3)
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Shooting
key_k = keyboard_check_pressed(ord("K"))
if (key_k > 0)
{
bullet = instance_create(x+5*move,y,obj_pellet);
bullet.hsp = image_xscale * 20;
}
//Animation
if (move!=0) image_xscale= move;
dir = image_xscale;
if (place_meeting(x,y+1,obj_wall))
{
if (move != 0)
{
sprite_index = spr_playerwalk;
}
else
{
sprite_index = spr_playeridle;
}
}
if (vsp = -18) sprite_index = spr_playerjump;
if (sprite_index = spr_playerjump) && (image_index = 11) sprite_index = spr_playerrise;
if (vsp = 1.5) sprite_index = spr_playerfall;
if (sprite_index = spr_playerfall) && (image_index = 11) sprite_index = spr_playerdescend;
//Bullet Collision
if (place_meeting(x,y,obj_badpellet))
{
with (obj_badpellet)
{
if (place_meeting(x +- 2,y,obj_player))
{
game_restart();
}
}
instance_destroy();
}
restart = keyboard_check(ord("R"))
if (restart = 1) game_restart();
敵方目標:
execute code:
dir = 1;
hsp = 0;
vsp = 0;
grav = 0.8;
movespeed = 3;
Step Event:
execute code:
hsp = dir * movespeed;
vsp += grav;
image_xscale = dir * -1;
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Enemy Collison
if (place_meeting(x,y,obj_player))
{
if (obj_player.y < y-16)
{
with (obj_player) vsp = -jumpspeed;
instance_destroy();
}
else
{
game_restart();
}
}
if (place_meeting(x,y,obj_pellet))
{
with (obj_pellet)
{
if (place_meeting(x,y,obj_enemy))
{
instance_destroy();
}
}
instance_destroy();
}
if (place_meeting(x,y,obj_badpellet))
{
with (obj_badpellet)
{
if (place_meeting(x,y,obj_enemy))
{
instance_destroy();
}
}
instance_destroy();
}