Implemented the jump command
This commit is contained in:
parent
a9c30f6236
commit
8dd5eff733
3 changed files with 22 additions and 0 deletions
|
@ -28,6 +28,11 @@ pub const Brother = struct {
|
||||||
_ = try rc.buffer.writer().write(line);
|
_ = try rc.buffer.writer().write(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn moveJump(self: *Brother) void {
|
||||||
|
if (self.dy == 0) { // no double jumps! TODO allow kicks off the wall
|
||||||
|
self.dy -= 4 / (1000 / 60.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn moveLeft(self: *Brother) void {
|
pub fn moveLeft(self: *Brother) void {
|
||||||
self.dx -= 5 / (1000 / 60.0);
|
self.dx -= 5 / (1000 / 60.0);
|
||||||
self.moveDuration = 24;
|
self.moveDuration = 24;
|
||||||
|
@ -37,6 +42,7 @@ pub const Brother = struct {
|
||||||
self.moveDuration = 24;
|
self.moveDuration = 24;
|
||||||
}
|
}
|
||||||
pub fn step(self: *Brother) void {
|
pub fn step(self: *Brother) void {
|
||||||
|
// Horizontal movement
|
||||||
const x = self.x + self.dx;
|
const x = self.x + self.dx;
|
||||||
const ll = leftLimit[@enumToInt(self.side)];
|
const ll = leftLimit[@enumToInt(self.side)];
|
||||||
const rl = rightLimit[@enumToInt(self.side)];
|
const rl = rightLimit[@enumToInt(self.side)];
|
||||||
|
@ -57,6 +63,17 @@ pub const Brother = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Vertical movement
|
||||||
|
const y = self.y + self.dy;
|
||||||
|
if (y < 12) { // jumping
|
||||||
|
self.y = 12;
|
||||||
|
self.dy = -self.dy;
|
||||||
|
} else if (y > 17) { // falling
|
||||||
|
self.y = 17;
|
||||||
|
self.dy = 0;
|
||||||
|
} else {
|
||||||
|
self.y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn reset(self: *Brother, side: ?Side) void {
|
pub fn reset(self: *Brother, side: ?Side) void {
|
||||||
if (side) |s| {
|
if (side) |s| {
|
||||||
|
|
|
@ -12,6 +12,9 @@ pub const Game = struct {
|
||||||
try self.brothers[0].draw(rc);
|
try self.brothers[0].draw(rc);
|
||||||
try self.brothers[1].draw(rc);
|
try self.brothers[1].draw(rc);
|
||||||
}
|
}
|
||||||
|
pub fn moveJump(self: *Game) void {
|
||||||
|
self.brothers[@enumToInt(self.side)].moveJump();
|
||||||
|
}
|
||||||
pub fn moveLeft(self: *Game) void {
|
pub fn moveLeft(self: *Game) void {
|
||||||
self.brothers[@enumToInt(self.side)].moveLeft();
|
self.brothers[@enumToInt(self.side)].moveLeft();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ pub fn main() !void {
|
||||||
gs.moveLeft();
|
gs.moveLeft();
|
||||||
} else if (in.eqlDescription("arrow-right") or in.eqlDescription("d")) {
|
} else if (in.eqlDescription("arrow-right") or in.eqlDescription("d")) {
|
||||||
gs.moveRight();
|
gs.moveRight();
|
||||||
|
} else if (in.eqlDescription("arrow-up") or in.eqlDescription("space")) {
|
||||||
|
gs.moveJump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue