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

eri0o

MODULE: Controlz 0.1.0
« on: 28 Aug 2019, 01:30 »
Controlz  0.1.0
controlz.scm | controlz_demo_windows.zip | 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));
  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: 28 Aug 2019, 13:37 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 »
Is this intended for Offline Multiplayer? Can it work with two separate joysticks (Player1) & (Player2)?
If so it could be pretty cool i guess!  :)
If i've had the knowledge i would have tried it with Joysticks, but i don't get my head around floats and such yet.

I'm thinking of using it for a plattformer, fighting game etc.

ISSUES WITH THE MODULE:

 It's not working very well with my settings tho, both players move which is great. However even if using movementlinkedtoanimation=true, the character walks like he has a limp, frames being skipped, for unknown reason. What's the prefered frames in each view loop? 8? 6?

The player runs extremely fast when i do the  movementlinkedtoanimation=false (laugh)  Looked into the script and it looks like it's not even mentioning movementlinkedtoanimation=false, which is what i'd use for a sidescroller plattform/beat em up. Where this module potentially could have it's usage  :)

It looks aweful without it for fast sidescrolling plattformer. Slowing down the animation frames makes it lag, or look like it's lagging. So i tried to speed it up the overall gamespeed, but it did not work as anticipated.

Maybe i am using the plugin wrong. ???
All i do is pretty much copy paste your example here and change it to whatever character i wanna use and make sure i have all various walking cycles in place for characters that is using controlz.

Thanks for your hardwork as usual! :)


Edit: Oh yes before i forgot. Would you please be so kind and show the synthax to asign these to Agscontroller?
I have Agscontroller running but everything i try give me, well nothing..

DLL's are in compiled folder and the mainfolder, AND debugfolder. Does not seem to be the issue. Just my limited knowledge, and plugin activated. It's activated inside AGS's plugin category.
Called the exampled at gamestart, etc. Yet when trying any example , it does not do anything.

Code: Adventure Game Studio
  1.       if (gamepad.GetPOV() == eKeyLeftArrow)
  2.     {
  3.      Display("");
  4.     }



« Last Edit: 20 Oct 2020, 23:14 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)