Author Topic: MODULE: Controlz 0.3.0  (Read 1273 times)

eri0o

MODULE: Controlz 0.3.0
« on: 28 Aug 2019, 01:30 »
Controlz  0.3.0

controlz.scm | controlz_demo_windows.zip | controlz_demo_linux.tar.gz | 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. Since 0.3.0, solid characters collide with solid characters.

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));
  9.  
  10.   Controlz(cEgo2,
  11.     IsKeyPressed(eKeyS),  IsKeyPressed(eKeyA),
  12.     IsKeyPressed(eKeyD),  IsKeyPressed(eKeyW));
  13. }
  14.  

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. }

License

This code is licensed with MIT LICENSE.
« Last Edit: 25 Feb 2021, 00:25 by eri0o »

Olleh19

  • I'm an AGS n00b, please don't kill me
Re: MODULE: Controlz 0.1.0
« Reply #1 on: 20 Oct 2020, 21:38 »
Edit: Got it working. I was dumb  (laugh)


« Last Edit: 27 Oct 2020, 18:59 by Olleh19 »

arj0n

  • Mittens Vassal
  • art consists in drawing a line somewhere
    • arj0n worked on one or more games that won an AGS Award!
    •  
    • arj0n worked on one or more games that was nominated for an AGS Award!
Re: MODULE: Controlz 0.1.0
« Reply #2 on: 20 Oct 2020, 22:38 »
DLL's are in compiled folder and the mainfolder.

The only thing u have to do, is make sure u put SDL2.dll inside ur debug and compiled folders, otherwise you'll get error messages.

Olleh19

  • I'm an AGS n00b, please don't kill me
Re: MODULE: Controlz 0.1.0
« Reply #3 on: 20 Oct 2020, 22:41 »
DLL's are in compiled folder and the mainfolder.

The only thing u have to do, is make sure u put SDL2.dll inside ur debug and compiled folders, otherwise you'll get error messages.

Actually i forgot to type that in, ofc i've followed his instructions! But thanks for reminding me, i should edit the post!  (laugh)

Re: MODULE: Controlz 0.1.0
« Reply #4 on: 23 Feb 2021, 14:15 »
Hi!

I'm using your module and enjoying it!

But I have a problem: it seems not to play sound related to walking frames. I assigned a step sound to some frames and usually this way I can hear sounds.
If I move the character with arrow keys, I can't hear any sound. But if I move him from script (or via mouse click as well, but my game won't be mouse-controlled) using the .Walk() method, sound is correctly played

thanks!
Bye!
Manu

eri0o

Re: MODULE: Controlz 0.2.0
« Reply #5 on: 23 Feb 2021, 15:16 »
Probably lockviewframe doesn't play sound, so I need to handle it manually. I actually never noticed sounds weren't playing. I will fix this later tonight and update it here!

Edit: I think I fixed, please verify!
« Last Edit: 24 Feb 2021, 01:17 by eri0o »

Re: MODULE: Controlz 0.2.0
« Reply #6 on: 24 Feb 2021, 08:17 »
It works!  :wink:
Awesome!
thanks!

eri0o

Re: MODULE: Controlz 0.3.0
« Reply #7 on: 25 Feb 2021, 00:27 »
Hi, I added support for solid characters. If you control a solid character it should collide with other solid character.

Re: MODULE: Controlz 0.3.0
« Reply #8 on: 25 Feb 2021, 09:00 »
Hi!
Good job, it works!
I also had to set the character's .BlockingHeight to obtain the proper blocking

Thanks!