Skip to content

Commit d841f34

Browse files
committed
dash jump is the greatest traveling method
1 parent 534846a commit d841f34

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ export const gravity = 0.02;
44
// Player 関連
55
export const playerWidth = 0.6;
66
export const playerHeight = 0.9;
7-
export const maxMoveVX = 0.1;
7+
export const maxMoveVX = 0.1; // これを超えると player の入力では加速しなくなるが、ジャンプで加速できる
88
export const playerAccelOnGround = 0.05;
99
export const playerDecelOnGround = 0.05;
1010
export const playerAccelInAir = 0.01;
1111
export const playerDecelInAir = 0.01;
12+
export const jumpAccelRate = 1.1; // ジャンプした瞬間に加速
1213
export const jumpVY = 0.12;
1314
export const jumpFrames = 10;
1415
// Fallable block 関連

src/player.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ export function tick(cx: Context, ticker: Ticker) {
140140
}
141141
switch (playerIntent) {
142142
case 1:
143-
player.vx += accel * blockSize;
144-
if (player.vx >= consts.maxMoveVX * blockSize) {
145-
player.vx = consts.maxMoveVX * blockSize;
143+
if (player.vx < consts.maxMoveVX * blockSize) {
144+
player.vx += accel * blockSize;
146145
}
147146
break;
148147
case -1:
149-
player.vx -= decel * blockSize;
150-
if (player.vx <= -consts.maxMoveVX * blockSize) {
151-
player.vx = -consts.maxMoveVX * blockSize;
148+
if (player.vx > -consts.maxMoveVX * blockSize) {
149+
player.vx -= decel * blockSize;
152150
}
153151
break;
154152
case 0:
@@ -168,6 +166,7 @@ export function tick(cx: Context, ticker: Ticker) {
168166
if (player.onGround) {
169167
player.vy = -consts.jumpVY * blockSize;
170168
player.jumpingBegin = elapsed;
169+
player.vx *= consts.jumpAccelRate;
171170
} else if (player.jumpingBegin && elapsed - player.jumpingBegin < consts.jumpFrames) {
172171
player.vy = -consts.jumpVY * blockSize;
173172
} else {

0 commit comments

Comments
 (0)