use glm; use mcproto; def PLAYER_MAX_HEALTH = 20.0f32; def PLAYER_MAX_FOOD = 20i32; def PLAYER_MAX_SATURATION = 5.0f32; let PLAYER_POS: glm::v3 = [0.0...]; let PLAYER_YAW = 0.0f32; let PLAYER_PITCH = 0.0f32; let PLAYER_HEALTH = PLAYER_MAX_HEALTH; let PLAYER_FOOD = PLAYER_MAX_FOOD; let PLAYER_SATURATION = PLAYER_MAX_SATURATION; let PLAYER_CONTROL_WALK = 0.0f32; let PLAYER_CONTROL_STRAFE = 0.0f32; let PLAYER_CONTROL_JUMP = false; let PLAYER_CONTROL_SNEAK = false; fn player_despawn() void = { PLAYER_POS = [0.0...]; PLAYER_YAW = 0.0; PLAYER_PITCH = 0.0; PLAYER_HEALTH = PLAYER_MAX_HEALTH; PLAYER_FOOD = PLAYER_MAX_FOOD; PLAYER_SATURATION = PLAYER_MAX_SATURATION; PLAYER_CONTROL_WALK = 0.0; PLAYER_CONTROL_STRAFE = 0.0; PLAYER_CONTROL_JUMP = false; PLAYER_CONTROL_SNEAK = false; }; fn player_control(control: *Control) void = { PLAYER_YAW += control.yaw; PLAYER_PITCH += control.pitch; PLAYER_CONTROL_WALK = control.walk; PLAYER_CONTROL_STRAFE = control.strafe; PLAYER_CONTROL_JUMP = control.jump; PLAYER_CONTROL_SNEAK = control.sneak; }; fn player_tick() void = { // as noted in game.ha, we need to negate yaw to obtain // a conventionally oriented angle. const yaw_trans = glm::rotation_make(-glm::rad(PLAYER_YAW), &glm::v3_new(0.0, 1.0, 0.0)); const motion: glm::v3 = [ PLAYER_CONTROL_STRAFE, (if (PLAYER_CONTROL_JUMP) 1.0f32 else 0.0f32) - (if (PLAYER_CONTROL_SNEAK) 1.0f32 else 0.0f32), PLAYER_CONTROL_WALK, ]; glm::v3_scale(&motion, 1.0); motion = glm::affine_mul_v3(&yaw_trans, &motion); PLAYER_POS = glm::v3_add(&PLAYER_POS, &motion); let out: []u8 = []; defer free(out); mcproto::encode_double(&out, PLAYER_POS[0]); mcproto::encode_double(&out, PLAYER_POS[1]); mcproto::encode_double(&out, PLAYER_POS[2]); mcproto::encode_float(&out, PLAYER_YAW); mcproto::encode_float(&out, PLAYER_PITCH); mcproto::encode_bool(&out, true); network_send(0x14, out); };