-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathbinding.js
69 lines (60 loc) · 1.77 KB
/
binding.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// @ts-check
// You can set the input bindings for your game!
kaplay({
buttons: {
// Buttons for jumping
"jump": {
// When using a gamepad the button for jumping will be south
gamepad: ["south"],
// When using a keyboard the button will be "up" or "w"
keyboard: ["up", "w"],
// When using a mouse the button will be "left"
mouse: "left",
},
// Buttons for inspecting
"inspect": {
gamepad: "east",
keyboard: "f",
mouse: "right",
},
},
});
loadBean();
// Set the gravity acceleration (pixels per second)
setGravity(1600);
// Add player game object
const player = add([
sprite("bean"),
pos(center()),
area(),
// body() component gives the ability to respond to gravity
body(),
]);
// Add a platform to hold the player
add([
rect(width(), 48),
outline(4),
area(),
pos(0, height() - 48),
// Give objects a body() component if you don't want other solid objects pass through
body({ isStatic: true }),
]);
// Adds an object with a text
add([
text("Press jump button", { width: width() / 2 }),
pos(12, 12),
]);
// This runs when the button for "jump" is pressed (will be on any input device)
onButtonPress("jump", () => {
// You can get the type of device that the last input was inputted in!
debug.log(getLastInputDeviceType());
// Now we'll check if the player is on the ground to make it jump
if (player.isGrounded()) {
// .jump() is provided by body()
player.jump();
}
});
// When the button for inspecting is pressed we will log in the debug console for our game the text "inspecting"
onButtonDown("inspect", () => {
debug.log("inspecting");
});