下面的是你的问题描述的翻译结果:
我正在用GameMaker制作一个2D平台游戏(刚刚开始4天),不久前我添加了半固体墙和半固体移动平台,但玩家无法站在它们上面。
我的角色事件代码:
//输入处理
var xspd = 0;
var yspd = 0;
var moveDir = 0;
var jumpCount = 0;
var onGround = true;
var myFloorPlat = noone;
//获取输入
getControls();
//水平移动
//获取输入方向
moveDir = rightKey - leftKey;
//获取角色方向
if moveDir != 0 {
face = moveDir;
};
//水平速度
runType = runKey;
xspd = moveDir * moveSpd[runType];
//水平碰撞检测
var _subPixel = 0.5;
//检测是否遇到墙
if place_meeting(x + xspd, y, obj_wall) {
//检测是否有斜坡时向上移动
if !place_meeting(x + xspd, y - abs(xspd) - 1, obj_wall) {
//向下移动直到遇到墙
while place_meeting(x + xspd, y, obj_wall) {
y -= _subPixel;
};
}
//检测是否有天花板斜坡时向上移动
else {
//检测是否有天花板斜坡
if !place_meeting(x + xspd, y + abs(xspd * 2) + 1, obj_wall) {
//向下移动直到遇到墙
while place_meeting(x + xspd, y, obj_wall) {
y += _subPixel;
};
}
//正常水平碰撞检测
else {
//计算遇到墙后的水平位置
var pixelCheck = _subPixel * sign(xspd);
//向右移动直到遇到墙
while !place_meeting(x + pixelCheck, y, obj_wall) {
x += pixelCheck;
};
//水平速度设置为0
xspd = 0;
};
};
};
//检测是否有下方斜坡
if yspd <= 0 && !place_meeting(x + xspd, y + 1, obj_wall) && place_meeting(x + xspd, y + abs(xspd) + 1, obj_wall) {
//向下移动直到遇到墙
while !place_meeting(x + xspd, y + _subPixel, obj_wall) {
y += _subPixel;
};
};
//水平移动
x += xspd;
//垂直移动
//重力
if coyoteHangTimer > 0 {
//减少时间
coyoteHangTimer--;
} else {
//应用重力
yspd += grav;
//告诉游戏角色不再在平台上
setOnGround(false);
};
//跳跃准备
if onGround {
//重置跳跃计数
jumpCount = 0;
//重置半秒跳跃时间
coyoteJumpTimer = coyoteHangFrames;
} else {
//减少半秒跳跃时间
coyoteJumpTimer--;
//检查是否可以进行额外跳跃
if jumpCount == 0 && coyoteJumpTimer <= 0 {
jumpCount = 1;
};
};
//跳跃
if jumpKeyBuffered && jumpCount < jumpMax {
//重置跳跃缓冲
jumpKeyBuffered = false;
//重置跳跃计时器
jumpKeyBufferTimer = 0;
//增加跳跃次数
jumpCount++;
//设置跳跃持续时间
jumpHoldTimer = jumpHoldFrames[jumpCount - 1];
//告诉游戏角色不再在平台上
setOnGround(false);
//重置半秒跳跃时间
coyoteJumpTimer = 0;
} //切断跳跃
if !jumpKey {
//清除跳跃计时器
jumpHoldTimer = 0;
};
//跳跃控制
if jumpHoldTimer > 0 {
//设置当前跳跃速度
yspd = jspd[jumpCount - 1];
//减少跳跃计时器
jumpHoldTimer--;
};
//垂直碰撞检测
#region
//检测是否超速
if yspd > termVel {
//限制速度
yspd = termVel;
};
//垂直碰撞检测
var _subPixel = 0.5;
//检测是否有上方碰撞
if yspd > 0 && place_meeting(x, y + yspd, obj_wall) {
//向上移动到下方
var _slopeSlide = false;
//检测是否有左斜坡
if moveDir != 1 && !place_meeting(x - abs(yspd) - 1, y + yspd, obj_wall) {
//向右移动直到遇到墙
while place_meeting(x, y + yspd, obj_wall) {
x -= 1;
};
_slopeSlide = true;
}
//检测是否有右斜坡
if moveDir != -1 && !place_meeting(x + abs(yspd) + 1, y + yspd, obj_wall) {
//向右移动直到遇到墙
while place_meeting(x, y + yspd, obj_wall) {
x += 1;
};
_slopeSlide = true;
}
//检测是否有正常碰撞
if !_slopeSlide {
//计算下方碰撞位置
var _pixelCheck = _subPixel * sign(yspd);
//向下移动直到遇到墙
while !place_meeting(x, y + _pixelCheck, obj_wall) {
y += _pixelCheck;
};
//清除垂直速度
yspd = 0;
//告诉游戏角色已站在平台上
setOnGround(true);
};
};
//检测是否有下方碰撞
#endregion
//检测是否有固体和半固体平台
var _clamYspd = max(0, yspd);
//创建一个空的列表
var list = ds_list_create();
//创建一个空的数组
var array = array_create(0);
//将固体和半固体平台添加到数组中
array_push(array, obj_wall, obj_semiSolidWall);
//检测是否有碰撞并将碰撞实例添加到列表中
var listSize = instance_place_list(x, y + 1 + _clamYspd + moveplatMaxYspd, array, list, false);
//遍历列表中所有碰撞实例
for (var i = 0; i < listSize; i++) {
//取出列表中的实例
var listInst = list[i];
//避免磁铁效应
if (listInst.yspd <= yspd || instance_exists(myFloorPlat)) {
//检测是否有碰撞实例的下方
if (listInst.yspd > 0 || place_meeting(x, y + 1 + _clamYspd, listInst)) {
//检测是否有固体或半固体实例
if (listInst.object_index == obj_wall || object_is_ancestor(listInst.object_index, obj_wall) || listInst.object_index == obj_semiSolidMovePlat || floor(bbox_bottom) <= ceil(listInst.bbox_top - listInst.yspd)) {
//检测是否有最高的墙实例
if (!instance_exists(myFloorPlat) || listInst.bbox_top + listInst.yspd <= myFloorPlat.bbox_top + myFloorPlat.yspd || listInst.bbox_top + listInst.yspd <= bbox_bottom) {
//设置最高的墙实例
myFloorPlat = listInst;
}
}
}
}
};
//释放列表
ds_list_destroy(list);
//最后一次检查是否有碰撞
if instance_exists(myFloorPlat) && !place_meeting(x, y + moveplatMaxYspd, myFloorPlat) {
//清除碰撞实例
myFloorPlat = noone;
};
//跳跃到下方平台
if instance_exists(myFloorPlat) {
//计算下方碰撞位置
var _subPixel = 0.5;
//向下移动直到遇到墙
while !place_meeting(x, y + _subPixel, myFloorPlat) && !place_meeting(x, y, obj_wall) {
y += _subPixel;
}
//检测是否有半固体实例
if (myFloorPlat.object_index == obj_semiSolidWall || object_is_ancestor(myFloorPlat.object_index, obj_semiSolidWall) || myFloorPlat.object_index == obj_semiSolidMovePlat) {
//向上移动直到遇到墙
while place_meeting(x, y, myFloorPlat) {
y -= _subPixel;
}
}
//设为整数
y = floor(y);
//设置垂直速度为0
yspd = 0;
//告诉游戏角色已站在平台上
setOnGround(true);
};
//最后一次垂直移动
y += yspd;
//最终移动平台检测和移动
//向下移动
//Sprite控制
//行走
if abs(xspd) > 0 {
sprite_index = walkSpr;
};
//奔跑
if abs(xspd) >= moveSpd[1] {
sprite_index = runSpr;
};
//静止
if xspd == 0 {
sprite_index = idleSpr;
};
//空中行走
if !onGround {
sprite_index = jumpSpr;
};
//设置碰撞面
mask_index = idleSpr;
下面的是create事件的翻译结果:
//自定义函数
function setOnGround(_val = true) {
if _val == true {
onGround = true;
coyoteHangTimer = coyoteHangFrames;
} else {
onGround = false;
myFloorPlat = noone;
coyoteHangTimer = 0;
}
};
//设置深度
depth = -30;
//控制设置
controlsSetup();
//设置角色方向
face = 1;
//设置sprite
maskSpr = spr_Waluigi;
idleSpr = spr_Waluigi;
walkSpr = spr_waluigi_run;
runSpr = spr_waluigi_dash;
jumpSpr = spr_waluigi_jump;
//设置移动速度
moveDir = 0;
runType = 0;
moveSpd[0] = 4;
moveSpd[1] = 5.5;
xspd = 3;
yspd = 0;
//设置跳跃速度
grav = 0.275;
termVel = 8;
onGround = true;
jumpMax = 1;
jumpCount = 0;
jumpHoldTimer = 0;
jspd[0] = -3.15;
jumpHoldFrames[0] = 18;
jspd[1] = -2.85;
jumpHoldFrames[1] = 10;
//设置半秒时间
coyoteHangFrames = 2;
coyoteHangTimer = 0;
coyoteJumpFrames = 10;
coyoteJumpTimer = 0;
//设置移动平台
myFloorPlat = noone;
moveplatXspd = 0;
moveplatMaxYspd = termVel;
评论 (0)