Author Topic: MODULE: Controlz 0.1.0  (Read 101 times)

MODULE: Controlz 0.1.0
« on: 28 Aug 2019, 01:30 »
Controlz  0.1.0
controlz.scm | | controlz_demo_linux.tar.xz | GitHub repo

Move your character with keyboard or joystick controlz for Adventure Game Studio.

This code was originally made by Dualnames for Strangeland and I eri0o got his permission to open source and wrapped in this function to be easier for consumption.

Usage example

Call it on repeatedly execute, in your Global Script or in the script that you deal with player input, passing a character and some way to check for directional keys, once for each direction (down, left, right, up).

In the example below, WASD will be used to control the player character, and arrow keys will be used to control a second character named cEgo2.

Code: Adventure Game Studio
  1. // called on every game cycle, except when the game is blocked
  2. function repeatedly_execute()
  3. {
  4.   Controlz(player,
  5.     IsKeyPressed(eKeyDownArrow),
  6.     IsKeyPressed(eKeyLeftArrow),
  7.     IsKeyPressed(eKeyRightArrow),
  8.     IsKeyPressed(eKeyUpArrow));
  10.   Controlz(cEgo2,
  11.     IsKeyPressed(eKeyS),  IsKeyPressed(eKeyA),
  12.     IsKeyPressed(eKeyD),  IsKeyPressed(eKeyW));
  13. }

script API

Controlz only has a single function

Controlz(Character* c, bool down, bool left, bool right, bool up)

Call it on your repeatedly execute or repeatedly execute always, passing a character and which keys are pressed at that time. If you need to control more characters, just call Controlz again, passing the new character and the buttons that are mapped to move it.

You can check for multiple keys or inputs too.

Code: Adventure Game Studio
  1. function repeatedly_execute()
  2. {
  3.   Controlz(player,
  4.     IsKeyPressed(eKeyDownArrow) || IsKeyPressed(eKeyS),
  5.     IsKeyPressed(eKeyLeftArrow) || IsKeyPressed(eKeyA),
  6.     IsKeyPressed(eKeyRightArrow) || IsKeyPressed(eKeyD),
  7.     IsKeyPressed(eKeyUpArrow) || IsKeyPressed(eKeyW));
  8. }


This code is licensed with MIT LICENSE.
« Last Edit: 28 Aug 2019, 13:37 by eri0o »