Arduboy Memory Game #4: User Input And Cursor

It is time to add user input to my little Arduboy Memory game. And an animated cursor such that it is easy to see which game card the player is currently able to select.

You can find the source code for this dev log on GitHub.

Animating a cursor

We want to make it easy for the player to see which card she/he can currently chose. For this we animate a simple cursor sprite.

I used Pixen to create the three frames for the cursor animation above.

The sprites for the animation are prepared and added to the sprites array just like we did with all the other sprites previously.

We then draw the current frame of the cursor animation instead of a square at the position of the cursor.

Changing frames

To keep track of frame times, we use a variable to store the offset (currentSprite) of the current frame and one for storing ho many ticks there is to the next frame (ticksToFrame). We store the number of ticks between each frame in the constant integer FRAMETIME.

The draw function implementation in the Cursor.cpp file then choses which frame to draw, and change frames when it is time.

User Input

We want the user to be able to move the cursor around, so that it is possible to chose whatever game card she/he likes.

To do this we add a moveCursor function to our Cursor files, and create two new Input files to control input from the user.

In the function handleInput, we then decide what happens when a specific button is pressed. To move the cursor we read the Left, Right, Up and Down buttons and decide which direction the user wants to move the cursor.

To keep all Arduboy specific code in the Device files, a enum called Button is created in the Device.hpp file. This is used to convert our own button names into those used for the Arduboy.

Next up is turning then game card the cursor is on, when the player presses the ‘A’ button. We also still need to implement the rest of the gameplay, such as checking if two turned cards match.

Dev logs in this series:

  1. Getting Started
  2. Preparing Sprites
  3. Randomized Game Board
  4. User Input And Cursor (this)

3 thoughts on “Arduboy Memory Game #4: User Input And Cursor”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.