fix: 优化跳跃和下落手感
This commit is contained in:
1 parent
ada64fe4be
commit
afe2f64b9b
25 files changed
+1197
-188
No files matched your search
+26
-15
@@ -6,11 +6,16 @@ import * as S from './sprites.js';
|
||||
import { T } from './level.js';
|
||||
|
||||
export const PHY = {
|
||||
GRAV: 0.4,
|
||||
GRAV: 0.25, // 上升段重力:小 = 跳跃飘
|
||||
GRAV_FALL: 0.32, // 下落段重力:小 = 下坠轻、飘落感(0.35→0.32,用户反馈"下落有点沉")
|
||||
GRAV_DJ: 0.35, // 二段跳上升段专属重力:比 GRAV 稍重——初速 6.7 与一段 6.6 一致,配 0.35 才能又冲(不起悬停)又只有 4.5 格总高
|
||||
MAXFALL: 9,
|
||||
JUMP: 8.5,
|
||||
DJUMP: 7.6,
|
||||
HSPD: 3,
|
||||
JUMP: 6.6,
|
||||
DJUMP: 6.7, // 二段跳冲量:起跳初速与一段 JUMP 6.6 几乎一致(起跳"嘭"感同款);顶点接二段总高 = 4.51 格
|
||||
DJ_INERTIA: 0, // 二段跳时下落速度对冲量的抵消比例:0=任何时机接二段都满力起跳(初速恒 -DJUMP,同 IWBT 原版),
|
||||
// 1=全额抵消(旧 bug:顶点晚几帧接二段直接归零)。0.35/0.5 都被用户反馈"好沉+短"——起跳初速被下落速度
|
||||
// 吃掉才是"沉"的根源(初速从 6.7 掉到 3~4,起跳那一下没劲),与上升重力无关。
|
||||
HSPD: 2.6,
|
||||
WATER_GRAV: 0.16,
|
||||
WATER_FALL: 2.6,
|
||||
WATER_RISE: 0.42,
|
||||
@@ -23,6 +28,7 @@ export const PHY = {
|
||||
SLIDE_BRAKE: 0.45, // 滑行中按反向键的刹车
|
||||
SLIDE_MIN: 0.35, // 冰面上攒到多大速度才算进入滑行状态
|
||||
SLIDE_STOP: 0.05, // 低于此速度惯性结束
|
||||
ICE_TOP: 1.6, // 冰面最高速度 = HSPD × ICE_TOP(调大=冰上能滑得更快,留更猛的惯性)
|
||||
};
|
||||
|
||||
export class Player {
|
||||
@@ -38,12 +44,12 @@ export class Player {
|
||||
this.x = sp.x; this.y = sp.y;
|
||||
this.vx = 0; this.vy = 0;
|
||||
this.jumps = 0;
|
||||
this.djUp = false;
|
||||
this.grounded = false;
|
||||
this.facing = 1;
|
||||
this.alive = true;
|
||||
this.dead = false;
|
||||
this.deadT = 0;
|
||||
this.squash = 1;
|
||||
this.inWater = false;
|
||||
this.animT = 0;
|
||||
this.shootCool = 0;
|
||||
@@ -78,7 +84,8 @@ export class Player {
|
||||
const sp = this.savePoint || L.spawn;
|
||||
this.x = sp.x; this.y = sp.y;
|
||||
this.vx = 0; this.vy = 0; this.jumps = 0;
|
||||
this.squash = 1; this.shootCool = 0; this.sliding = false;
|
||||
this.djUp = false;
|
||||
this.shootCool = 0; this.sliding = false;
|
||||
this.deadT = 0;
|
||||
// 安全兜底:万一重生点被地形/消失块堵住,向上顶出,别一复活就卡死
|
||||
let guard = 0;
|
||||
@@ -107,7 +114,7 @@ export class Player {
|
||||
if (moveL && !moveR) target = -PHY.HSPD;
|
||||
else if (moveR && !moveL) target = PHY.HSPD;
|
||||
|
||||
const ICE_MAX = PHY.HSPD * 1.35;
|
||||
const ICE_MAX = PHY.HSPD * PHY.ICE_TOP;
|
||||
const decel = f => {
|
||||
if (Math.abs(this.vx) <= f) this.vx = 0;
|
||||
else this.vx -= sgn(this.vx) * f;
|
||||
@@ -155,18 +162,22 @@ export class Player {
|
||||
if (Input.is('jump')) this.vy -= PHY.WATER_RISE;
|
||||
if (Input.is('down')) this.vy += 0.25;
|
||||
this.vy = clamp(this.vy, -3.2, PHY.WATER_FALL);
|
||||
this.jumps = 0;
|
||||
this.jumps = 0; this.djUp = false;
|
||||
} else {
|
||||
if (Input.hit('jump')) {
|
||||
if (this.grounded || this.jumps === 0) {
|
||||
this.vy = -PHY.JUMP; this.jumps = 1; this.grounded = false;
|
||||
this.squash = 1.28;
|
||||
// 不再做起跳拉伸:空中保持身体比例,避免跳跃时视觉上下晃动
|
||||
sfx.jump();
|
||||
L.particles.spawn(this.cx, this.y + this.h, 5,
|
||||
{ colors: ['#fff', '#cfcfe0'], speed: 1.6, life: 16, size: 2, dir: -Math.PI / 2, spread: 2 });
|
||||
} else if (this.jumps === 1) {
|
||||
this.vy = -PHY.DJUMP; this.jumps = 2;
|
||||
this.squash = 1.22;
|
||||
// 二段跳冲量叠减当前速度:上升中按 = 原版语义(直接获得 -DJUMP);
|
||||
// 下落中按 = 下落惯性只抵消一部分冲量(DJUMP 前乘 DJ_INERTIA)——
|
||||
// 全额抵消会让"满力一段跳到顶点、晚几帧接二段"的二段塌到接近 0(非常短),
|
||||
// 只抵消一半则顶点附近接二段保持满力,摔得快时才明显变弱
|
||||
this.vy = Math.max(this.vy, 0) * PHY.DJ_INERTIA - PHY.DJUMP; this.jumps = 2;
|
||||
this.djUp = this.vy < 0; // 二段上升段启用专属轻重力(与一段同款飘)
|
||||
sfx.djump();
|
||||
L.particles.spawn(this.cx, this.cy, 10,
|
||||
{ colors: ['#fff', '#9ad8ff'], speed: 2.2, life: 20, size: 2, spread: Math.PI * 2 });
|
||||
@@ -174,7 +185,9 @@ export class Player {
|
||||
}
|
||||
// 可变跳跃高度
|
||||
if (!Input.is('jump') && this.vy < -3) this.vy = -3;
|
||||
this.vy = Math.min(this.vy + PHY.GRAV, PHY.MAXFALL);
|
||||
// 上升轻、下落重:分手感。二段上升段用更轻的 GRAV_DJ(初速小,同款飘)
|
||||
this.vy = Math.min(this.vy + (this.vy < 0 ? (this.djUp ? PHY.GRAV_DJ : PHY.GRAV) : PHY.GRAV_FALL), PHY.MAXFALL);
|
||||
if (this.djUp && this.vy >= 0) this.djUp = false; // 二段到顶,交回普通重力
|
||||
}
|
||||
|
||||
// ---- 站在移动平台上则跟随 ----
|
||||
@@ -226,10 +239,8 @@ export class Player {
|
||||
const wasAir = !this.grounded;
|
||||
this.grounded = hitGround || (this.vy === 0 && L.solidRect(this.x, this.y + 1, this.w, this.h));
|
||||
if (this.grounded) {
|
||||
if (wasAir) { this.squash = 0.72; }
|
||||
this.jumps = 0;
|
||||
this.jumps = 0; this.djUp = false;
|
||||
}
|
||||
this.squash += (1 - this.squash) * 0.22;
|
||||
|
||||
// ---- 滑行反馈:超速滑行(冰上,或刚滑出冰块仍带惯性)时脚下溅起冰屑 ----
|
||||
if (this.sliding && this.grounded && Math.abs(this.vx) > PHY.HSPD && this.animT % 5 === 0) {
|
||||
|
||||
Reference in new issue
Block a user