Jibble

Author Topic: MODULE: Controlz 0.3.0  (Read 1829 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!

Re: MODULE: Controlz 0.3.0
« Reply #9 on: 30 Jun 2021, 10:30 »
This is a fantastic module, Eri0o - thanks!

Quick questions - how do I map this to joystick controls? Do I need to use the Joystick module alongside it?

Also, when the player reaches the end of a walkable area, is it possible to have the player continue to animate in their walkcycle (while standing in place) rather than coming to a stop mid animation?

Many thanks,
Shaun
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

eri0o

Re: MODULE: Controlz 0.3.0
« Reply #10 on: 30 Jun 2021, 12:36 »
Quote
Quick questions - how do I map this to joystick controls? Do I need to use the Joystick module alongside it?

The module API is just that single function, so it's only a matter of passing a true for the direction that is pressed and false on the others (the module supports diagonals if your character has 8 loops).

I usually don't do this directly though, because I want to be able to remap buttons - I have a script for button remapping but I haven't open sourced it basically because it's a bit ingrained in my game menus and a bit hard to pull out...

Unfortunately for now joystick in AGS requires a plugin. So you use either the hat check (for arrows) or the analog stick stuff (for the left analog) and then convert them to a binary like check to pass the resulting boolean. I have been thinking a lot of adding a GamePad API (all joysticks as Xbox360 gamepads) in AGS directly (no plugins) since this would make much easier to support joysticks in Android and WebGL builds. With the new SDL Port I can't think of a reason why not.

My joystick handling is wrapped in a separate module that handles joystick button mapping, so it's not transparent and ends up looking like this:

Code: Adventure Game Studio
  1. bool downkeyLA = adventureJoy.isWalkDownPressed() || IsKeyPressed(eKeyS);
  2. bool leftkeyLA = adventureJoy.isWalkLeftPressed() || IsKeyPressed(eKeyA);
  3. bool rightkeyLA = adventureJoy.isWalkRightPressed() || IsKeyPressed(eKeyD);
  4. bool upkeyLA = adventureJoy.isWalkUpPressed() || IsKeyPressed(eKeyW);
  5.        
  6. movement_state = Controlz(player, downkeyLA, leftkeyLA, rightkeyLA, upkeyLA);

Quote
Also, when the player reaches the end of a walkable area, is it possible to have the player continue to animate in their walkcycle (while standing in place) rather than coming to a stop mid animation?

I haven't tried but have you tried adding a iddle animation for this? Alternatively, the function is not void, it returns a state bit that may be useful for this. Other than this I am not sure how to handle this for people that want the full stop - aka, me.  :-\

I may not have understood exactly if the full stop you mean is the one I think you are, so a gif/video to show what you mean would be nice.
« Last Edit: 30 Jun 2021, 13:33 by eri0o »