mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-08 19:50:23 -04:00
parent
6013b579d9
commit
ca37eb97d7
36
src/game.zig
36
src/game.zig
@ -219,6 +219,26 @@ pub var fog = Fog{.color=.{0, 1, 0.5}, .density=1.0/15.0/128.0}; // TODO: Make t
|
||||
var nextBlockPlaceTime: ?i64 = null;
|
||||
var nextBlockBreakTime: ?i64 = null;
|
||||
|
||||
pub fn pressPlace() void {
|
||||
const time = std.time.milliTimestamp();
|
||||
nextBlockPlaceTime = time + main.settings.updateRepeatDelay;
|
||||
Player.placeBlock();
|
||||
}
|
||||
|
||||
pub fn releasePlace() void {
|
||||
nextBlockPlaceTime = null;
|
||||
}
|
||||
|
||||
pub fn pressBreak() void {
|
||||
const time = std.time.milliTimestamp();
|
||||
nextBlockBreakTime = time + main.settings.updateRepeatDelay;
|
||||
Player.breakBlock();
|
||||
}
|
||||
|
||||
pub fn releaseBreak() void {
|
||||
nextBlockBreakTime = null;
|
||||
}
|
||||
|
||||
pub fn update(deltaTime: f64) void {
|
||||
var movement = Vec3d{0, 0, 0};
|
||||
const forward = vec.rotateZ(Vec3d{0, 1, 0}, -camera.rotation[2]);
|
||||
@ -270,22 +290,6 @@ pub fn update(deltaTime: f64) void {
|
||||
}
|
||||
|
||||
const time = std.time.milliTimestamp();
|
||||
if(KeyBoard.key("placeBlock").pressed != (nextBlockPlaceTime != null)) {
|
||||
if(nextBlockPlaceTime != null) {
|
||||
nextBlockPlaceTime = null;
|
||||
} else {
|
||||
nextBlockPlaceTime = time + main.settings.updateRepeatDelay;
|
||||
Player.placeBlock();
|
||||
}
|
||||
}
|
||||
if(KeyBoard.key("breakBlock").pressed != (nextBlockBreakTime != null)) {
|
||||
if(nextBlockBreakTime != null) {
|
||||
nextBlockBreakTime = null;
|
||||
} else {
|
||||
nextBlockBreakTime = time + main.settings.updateRepeatDelay;
|
||||
Player.breakBlock();
|
||||
}
|
||||
}
|
||||
if(nextBlockPlaceTime) |*placeTime| {
|
||||
if(time -% placeTime.* >= 0) {
|
||||
placeTime.* += main.settings.updateRepeatSpeed;
|
||||
|
@ -294,8 +294,8 @@ pub const KeyBoard = struct {
|
||||
.{.name = "jump", .key = c.GLFW_KEY_SPACE},
|
||||
.{.name = "fall", .key = c.GLFW_KEY_LEFT_SHIFT},
|
||||
.{.name = "fullscreen", .key = c.GLFW_KEY_F11, .releaseAction = &Window.toggleFullscreen},
|
||||
.{.name = "placeBlock", .mouseButton = c.GLFW_MOUSE_BUTTON_RIGHT},
|
||||
.{.name = "breakBlock", .mouseButton = c.GLFW_MOUSE_BUTTON_LEFT},
|
||||
.{.name = "placeBlock", .mouseButton = c.GLFW_MOUSE_BUTTON_RIGHT, .pressAction = &game.pressPlace, .releaseAction = &game.releasePlace},
|
||||
.{.name = "breakBlock", .mouseButton = c.GLFW_MOUSE_BUTTON_LEFT, .pressAction = &game.pressBreak, .releaseAction = &game.releaseBreak},
|
||||
|
||||
.{.name = "takeBackgroundImage", .key = c.GLFW_KEY_PRINT_SCREEN, .releaseAction = &takeBackgroundImageFn},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user