Simple cheat code class (My first attempt at using Monkey2!)

About Monkey 2 Forums Monkey 2 Code Library Simple cheat code class (My first attempt at using Monkey2!)

Tagged: 

This topic contains 7 replies, has 2 voices, and was last updated by  jondecker76 6 months, 1 week ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #13597

    jondecker76
    Participant

    I wanted to get a small start playing with Monkey2, so I thought I would build something simple but fun. I made a quick class to implement simple sequential cheat codes, and whipped up a quick demo of the old NES Contra cheat (Up, Up, Down, Down, Left, Right, Left, Right, B, A, B, A, Enter)

    I’m still learning all of these new features, so please chime in if you see something that could have been done more efficiently.

    Issues:
    No real issues, only keyboard is supported right now. I would like to get away from using the event system for checking keyboard input, but I haven’t found an elegant way to check that A) a key was pressed and B) which key it was – so for now until I figure it out, the OnKeyEvent will have to do..

    Plans:
    I do plan on making this a full-fledged module that supports Keyboard, Joystick, Mouse Buttons and even other sequences as individual strokes (so that sequences can be chained or share a common base)

    Anyways, give it a try and see what you think

    #13599

    nerobot
    Participant

    A few notes:

    • There is App.KeyEventFilter event you can subscribing to instead of OnKeyEvent – it allow us grab events outside of View class hierarchy
    • You can also provide method AddStrokes( strokeType:Int,strokeValues:Int[] ) so that we can add sequences simplier way passing array.
    #13606

    jondecker76
    Participant

    Thanks for the tips nerobot

    I implemented the AddStrokes method, and you’re right – it’s much cleaner for usage

    I’m lost on the App.KeyEventFilter though… There is no real documentation, and looking at the source has me scratching my head. It’s a field, but has a void return type?? And parameters? Wouldn’t that make it a method instead of a field? So confusing! I also looked at event.monkey2 and was left equally confused. There’s so much I have to learn about Monkey 2 🙁

    #13607

    nerobot
    Participant

    I’m lost on the App.KeyEventFilter though
 There is no real documentation, and looking at the source has me scratching my head. It’s a field, but has a void return type?? And parameters? Wouldn’t that make it a method instead of a field? So confusing!

    It is called “First class functions”, it’s a reference to a function/method stored in a variable.

    It uses for signals, like KeyEventFilter, and you can to subscribe to it via += operator.

    or

    And there is my variant of your class (with comments):

    As you can see I added OnSuccess signal that will be emitted right after user press key that finished the sequence.

    To use this signal you should to subscribe to it, somewhere you create the sequence – inside of MyWindow::New() in your case:

    And you should remove all usages of Succes and Update methods of CheatSequence from MyWindow code – they are private now!

    So, now CheatSequence became more independant of Window class or any other – you just create sequence and fill it with keys and subscribe to its OnSucces.

    #13608

    jondecker76
    Participant

    Thank you!

     

    I just learned more from this single exercise than I have in the last week reading everything I could.  Very clean and elegant, now it’s making a lot more sense!

    #13613

    jondecker76
    Participant

    I’ve been improving on this today and playing with it more. There’s only one problem so far with using the key event filter.

    The App.KeyEventFilter isn’t a one-shot, so each press of the key registers 2-3 hits even on quick strokes. Since Update is only called when the KeyEventFilter is fired, there isn’t an elegant way to hand my own one-shot code. For now I’m hacking my way around it with a timer to ensure at least so much time goes by between keypresses, but it’s definitely not optimal.

    It would be nice if A) KeyEventFilter was only sent once at the beginning of each press or B) a certain code was sent on release of the key. But neither of these are present. So for now I will have to either keep using the delta timing method I’m using now, or have an Update that needs run from Main each iteration so that the KeyEventFilter can be one-shotted.

    #13615

    nerobot
    Participant

    Did you try to check event.Type property inside your filter method?

    If Not event.Type=EventType.KeyReleased Return

    #13616

    jondecker76
    Participant

    Thank you again. I think I’m finally getting a handle on things

    Here is the current state of things. I’ll start on joystick stuff soon then look for ways to clean things up a bit

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.