Skip to content

Commit

Permalink
make sending inputs less obnoxious
Browse files Browse the repository at this point in the history
  • Loading branch information
evolutionleo committed Dec 3, 2024
1 parent 6c4c13f commit 61cb5ba
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 53 deletions.
22 changes: 13 additions & 9 deletions Client/objects/oPlayer/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ use_states({ idle: 0, walk: 1 })
name = ""

// controls
kright = false
kleft = false
kup = false
kdown = false
inputs = {
kright : false,
kleft : false,
kup : false,
kdown : false,

kjump = false
kjump_rel = false
kjump_press = false
kjump : false,
kjump_rel : false,
kjump_press : false,

move_x = 0
move_y = 0
move: {
x: 0,
y: 0
}
}
22 changes: 12 additions & 10 deletions Client/objects/oPlayer/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/// @description platformer inputs logic

if (!remote) {
kup = keyboard_check(ord("W")) || keyboard_check(vk_up)
kleft = keyboard_check(ord("A")) || keyboard_check(vk_left)
kdown = keyboard_check(ord("S")) || keyboard_check(vk_down)
kright = keyboard_check(ord("D")) || keyboard_check(vk_right)
with (inputs) {
kup = keyboard_check(ord("W")) || keyboard_check(vk_up)
kleft = keyboard_check(ord("A")) || keyboard_check(vk_left)
kdown = keyboard_check(ord("S")) || keyboard_check(vk_down)
kright = keyboard_check(ord("D")) || keyboard_check(vk_right)

kjump = keyboard_check(vk_space)
kjump_press = keyboard_check_pressed(vk_space)
kjump_rel = keyboard_check_released(vk_space)
kjump = keyboard_check(vk_space)
kjump_press = keyboard_check_pressed(vk_space)
kjump_rel = keyboard_check_released(vk_space)

move_x = kright - kleft
move_y = kdown - kup
move.x = kright - kleft
move.y = kdown - kup
}


sendPlayerControls()
sendPlayerControls(inputs)
}

if (state == states.walk) {
Expand Down
27 changes: 11 additions & 16 deletions Client/scripts/gameplaySenders/gameplaySenders.gml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
function sendPlayerControls() {
send({
cmd: "player controls",
move: {
x: move_x,
y: move_y
},
kright: kright,
kleft: kleft,
kup: kup,
kdown: kdown,

kjump: kjump,
kjump_rel: kjump_rel,
kjump_press: kjump_press
})
function sendPlayerControls(inputs) {
var data = { cmd: "player controls" }

var input_names = variable_struct_get_names(inputs)
for(var i = 0; i < variable_struct_names_count(inputs); i++) {
var input_name = input_names[i]
data[$ input_name] = self.inputs[input_name]
}


send(data)
}
5 changes: 3 additions & 2 deletions Client/scripts/partySenders/partySenders.gml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function sendPartyInvite(uname = "", profile_id = "") {
send({ cmd: "party invite", profile_id, uname })
// invite either via username or via profile_id
function sendPartyInvite(username = "", profile_id = "") {
send({ cmd: "party invite", profile_id, username })
}

function sendPartyLeave() {
Expand Down
20 changes: 4 additions & 16 deletions TypescriptServer/src/cmd/handlers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@ import { addHandler } from "#cmd/handlePacket";
import Point from "#types/point";
import { clamp } from "#util/maths";


addHandler('player controls', (c, data) => {
if (!c.entity) return;

c.entity.inputs = {
move: data.move as Point,
kright: data.kright,
kleft: data.kleft,
kup: data.kup,
kdown: data.kdown,

kjump: data.kjump,
kjump_rel: data.kjump_rel,
kjump_press: data.kjump_press
for(let input_name in c.entity.inputs) {
if (data[input_name] !== undefined)
c.entity.inputs[input_name] = data[input_name];
}

c.entity.inputs.move.x = clamp(c.entity.inputs.move.x, -1, 1);
c.entity.inputs.move.y = clamp(c.entity.inputs.move.y, -1, 1);
});

});

0 comments on commit 61cb5ba

Please sign in to comment.