You are on page 1of 40

Vol.

3
Apr 2017
Contents:

PLAY
New games out this month!
The story behind the 1010 game
Mr Arduboy: Kevin Bates
Community Polls: What makes an Arduboy game great?

LEARN
Tips & Tricks with Team a.r.g (Vol 3)
Squeezing Bits to maximise your code with JO3RI (Vol 2)
Arduboy graphics with Gaveno112
Game design with crait
Using tunes and tones with Cronck
Notes from a new user - Scribbled Notes

EXPLORE
10 Questions with Game Developer Mike McRoberts
Pixel Page with Davit Masia
Cover page game index

Page 2 of 40
A welcome note:

Well, with the introduction of 3 new contributers, now


is the best time to have a flick through this magazine.
Welcome to volume 3!

This volume we have new articles, a new feature, and


another awesome front page! Thank you for reading
this magazine, and if you have any issues, appraisals or
anything at all, give us a shout.

-@widehaslet

Do you wish to contribute?


Have an interesting article you wish to share with the Arduboy
community? A cool project you did, your experience on
working on it? A funny joke? We want to hear it!
Send arduboymag a message through the Arduboy
community page or a DM on Twitter!

Page 3 of 40
Thank you to this month’s contributors!
@crait: Creator of various Arduboy games such as Circuit
Dude and Train Dodge, crait has written tutorials on how to
get started with creating your own game, and developed
Arduboy Manager; an easy way to upload games to your
Arduboy without using the Arduino IDE. http://www.crait.net/

@Cronck: He works in the field of networking, but enjoys


learning and teaching. Open source is another passion of
his, and because of this he has shared his new found info for
sound in the Arduboy. He also created this months cover art,
created in Inkscape, an open source program free for all.

@Davitmasia: an independent game developer and


artist. Owns indie development studio called Kronbits using
Construct 2 for developing games that you can find on Itch.
https://www.patreon.com/davitmasia

@Dmian: This talented graphic & web Designer from


Madrid, Spain created the Magazine’s Logo and various
icons. https://damianvila.com/

@gaveno112: Gavin Atkin, a member of TEAM a.r.g., creator


of the Arduboy game “Trolly Fish” and the featured game
“Mystic Balloon”.

@JO3RI: Better known as TEAM a.r.g, some of Arduboy’s


community favorite games are written by them, as well as
their own Arduboy Game Loader, where you can easily
upload your favorite Team a.r.g games without using the
Arduino IDE. http://www.team-arg.com/

@mwm: Mike Meyer is and independent contractor who has


been programming for 4 decades, and says writing the 1010
game for the Arduboy reminded him of writing games for v6
Unix on the PDP-11. His community icon is from the Great Seal
of the Chickasaw Nation, of which he is a citizen.

@TheArduinoGuy: Author of the ArduBoy games - Jet Pac &


Arcodia.. Author of ‘Beginning Arduino’. Medway Makers.
Maidstone Hackspace. http://thearduinoguy.org/

Page 4 of 40
Arduboy Company news:
What’s happening at headquarters?
@Celinebins
The Arduboy Blog is up! Updates on
what’s been happening on social
media and the community pages.

Also, the Tetris ® Microcard is ready


to ship! If you ordered one be sure
to check your inbox/spam for email
notifications.
More about
the Microcard
in the next
issue. ;-)

Where to buy one?


In order to better deliver the Arduboy to you, a distribution
model for sales has been currently implemented.
You can now purchase the Arduboy from a variety of different
retailers from around the world!

New!

New!

New!

Talk to us! Page 5 of 40


ES
AM
by @Celinebins
PLAY:
G
So many new games
E W were released this
month! If you missed
N
them on the community
pages, here they are.
H
ES

That will
get you
hooked
FR

ARD DRIVIN
@remz & @LouisP

A driving game rendered in 3 colors -


Black, White and Grey! It’s new release has
gotten the community in a frenzy over its
graphics and use of greyscale.

Boris goes
Skiing
@sones
Made at the Arduboy Workshop in
We’re digging the custom tee! Medway, guide Boris down the slopes
So highest score wins one? :p through the flags to score points, and
avoid the trees!

kemono_patrol
@metalidol

This listing was taken from Twitter. You


guide a battle bus over ditches, shoot
away debris and enemies while your
Japanese speaking assistant gives you tips.

Not just a hat


rack
@Hundstrasse
All hats just want to end up safe and
secure at the hat rack, right? So guide
Karlville (the hat) through all 40 levels in the
fastest time. Read the blog here.
Want us to feature your game? Write in to us
with your game, how you made it, and any-
thing else you want the community to know! Page 6 of 40
Creating this Game 1010
d
month’s Featu re by mwm

This month we take a closer look at one of the games - 1010, written as a
Christmas gift for his mother in 2016.
Mike Meyer (@mwm) gave his mother How to play:
an Arduboy for Christmas 2016. As well Moving mode
as the Arduboy, he wrote a game for it Once you’ve selected a shape, the arrow
specifically for her. keys will move it around on the board. The
A button will drop it in that position and
1010 - described switch back to selection mode.
as “2-dimensional
Tetris” - was one The LED color indicates if the shape will fit
of her favorite games during the months where it is: green for yes or go ahead and
leading up to Christmas, so seemed like a place, red for no.
perfect game to have on the Arduboy for
her. It took a couple of weeks to write and Selection mode
get working properly. You start the game in selection mode,
choosing from up to three shapes. The
The features unique to the Arduboy are current shape is show on the left side
using the right arrow key to shift from piece of the screen. Each available shape is
selection to piece placement, and the indicated by a - to the left of the displayed
green and red LED’s to show whether or shape, with the current shape being a
not the piece fits in it’s current position. +. Once a shape is placed, it’s symbol is
gone.

The left arrow places the current shape


in the upper right corner and changes to
moving mode.

The A button will try and find a place


where it fits, making the LED red while
it searches. If it finds one, it switches to
You can find the general version in the moving mode. If the shape will not fit on
various Arduboy game repositories, and the current board, the LED goes off and
the source (including customized version you are left in selection mode.
for his family) are available in the fossil
repository here. Pause
At any time, you can hit the B button and
So, what does his mother think about pause the game. This opens the menu so
her gift? She still plays 1010 on Arduboy, you can start a new game if you want.
prefering the placement methods better
than the desktop and mobile versions. Game Over
If it ever becomes impossible to place any
More accurately, she thinks the arduboy of the available pieces, the game ends.
is “really neat”, not only because she can
fit it in her pocket, but especially that it
survived her putting it through the washer. Donwload & Play again here!
Page 7 of 40
Looking at the data sheet for the OLED
one day made me realize it might be
possible to power it with a coin cell
battery, what I was planning on using to
power the business card. I built a circuit
with an arduino and an OLED break out on
a solderless breadboard all powered by
single coin cell and was surprised when it
worked! From that point on it was a frantic
This month we chat with founder of 2 weeks of circuit board design when I
Arduboy, Kevin Bates to find out more realized I was on to something big, but I
about his journey and story behind didn’t yet know what.
Arduboy.
How did the idea for Arduboy come I knew I needed controls if there was to be
about? a display, and figured that a directional
pad, an OK button and a Cancel button
At the time I was working in a really boring would give me all the features I needed
job, and I hated telling people about to control a menu, or play a simple game.
what I did for money. It was a database Pretty soon it started to look like a familiar
administrator for a shipping logistics handheld device. I ordered the circuit
company, and I know everyone has their boards, assembled them, made a youtube
role but I wasn’t happy there. I wanted video like I did for all my other projects,
to tell people about my arduino projects and the rest is history!
I was making! A LED music visualizer or
a servo controlled camera rig for taking How have you found the whole process of
panoramic photos. The problem is these manufacturing and all that for Arduboy?
kinds of projects are difficult to describe
to someone who isn’t a hobbyist, and It’s exhausting and nearly impossible for
nearly impossible to bring with you to one person to do! I’ve had a lot of help,
social events. At the time business cards and the open source community that
were getting a lot of press because there has formed around the Arduboy is really
were a stories coming out here and there what has been most incredible through
about them being obsolete. But every the process. You just have to research a
once and a while you would see a cool lot, have a constant unquenchable thirst
business card idea show up and get some for knowledge and wanting to know why
exposure so people could continue to talk something is the way it is. Directly, I mean
about this decreasing phenomenon of you have to be curious and personally
exchanging business cards in the digital interested in manufacturing technologies
age. and how factories work in order to get
it right. The more you understand what
Other people had made digital business happens in the factory, the better you can
cards before out of circuit boards, so I design the product.
thought I would try to make one myself.
This was actually nothing that new, I How did you start with the process of
wanted to make something with a few manufacturing close to 10,000 units?
LEDs and could maybe play a game of
Simon Says. At the time I was making it, I I had a ton of support already because
was also building a digital controller for a I had been chose to participate in the
home made solder reflow oven converted HAX accelerator which gave us access to
from a toaster oven that used an OLED mentors and factory experts. This made
display. life a lot easier than the average person
trying to start building hardware. But at the
to be continued next page >>
Page 8 of 40
end of the day, it just comes down to what stress this enough but putting up the
would otherwise be known as pounding forum has been the single best decision
the pavement. You have to network and the company has made. I was skeptical
create relationships with factories. Sending in the beginning but the number of high
emails, making phone calls and going to quality people who turn up to share their
events to meet people took 2 to 3 months experiences is nothing but mind boggling
of full time work before I was able to select to me. I’ve spent a lot of time on the
a manufacturing partner. Internet and I’m proud to confidently
say we have one of the best if not the
How many Devkits were made, and how very best communities on the internet.
did that help with the creation of Arduboy? There would be no Arduboy if it wasn’t
for the forum, but really it represents all
Well we manufactured the contributions of all of it’s members. So
400 in total, but we did thank you!
it in stages and that
actually helped us learn I’m sure you had to overcome those
a lot before building difficulties producing Arduboy, what was
the final kickstarter. your favorite thing about the Kickstarter
We produced 100 campaign?
units for sale on Tindie
before the kickstarter By far and above, and I cannot stress
campaign. But in reality it enough, the positive feedback and
we actually produced experiences I hear about from people.
200 units... 100 from two separate factories. Arduboy didn’t exist before, and now
Why do this? Well it helps us figure out there are all these people who maybe just
which factory is better, but it’s actually have a little fun with it. But there are also
more important than that. Because you people who somehow, it has transformed
have 2 experiences, you can get an idea their lives. Some people have got job
of how things might be different if you offers as a result of making games, others
went with still another factory. It’s less have learned to code and may have not
about the specific problems you have, or learned otherwise. So that is amazing,
differences in costs, but the general types there is potentially thousands of people
of problems you are going to experience. with new experiences all because of this
little thing. It makes it all worthwhile, and I
For example, we told one factory to use hope there is a lot more to come.
liquid adhesive to hold the screens down
and another factory no instruction. The You appeared to be traveling all the time
factory that used the glue, had problems promoting Arduboy. What your favorite
finding the right kind of glue, and then place to visit, and why?
when it was applied caused problems with
fingerprints. The second factory without This is an incredibly difficult question
instruction used a double sided tape that because at first I think about all of the
was awesome. So not only did we learn amazing people I’ve been lucky to
that tape is the way forward, we also meet in each place and I don’t want to
learned that for some things it’s better to single any one out! If I had to pick one I
just let the factory figure out what is best. probably should say Japan because it
was so unique and different from where
When was the forum page created, and I grew up, but at the same time I had
how has that been a pivotal role for always heard about and been exposed to
growing the Arduboy community? some elements of Japanese culture. The
stereotype of hospitality and politeness
The forum was created the same time was not unfounded and blew me away,
we shipped the developer kits. I can’t to be continued next page >>
Page 9 of 40
I ate lots tasty Tonkatsu and Gyoza and serialize the units and the factory said
was lucky to see a bunch of temples and I they could support this, so I went ahead
can’t forget Akihabara. and produced a sample that showed 1 of
10,000 to get an idea of how it looked. I
showed it around the office and everyone
got really excited about having the first
one and it was about that time we figured
out the logistical implications of trying
to fulfill orders this way. How would we
keep track of each persons order during
the assembly process? What happens if
a package gets lost, do we have to re-
make the back or send them a different
number? What if someone gets the wrong
number? But at the same time, I thought
China is amazing and taught me so the units would be more special knowing
much about life and myself it’s difficult to how many others
explain. People ask me about my time were made in
in China and there is just no way to put the batch.
it into words, or maybe it would take a
whole book. But for me the language and So it’s an edition
culture barriers coupled with the restricted printing, not a
internet left me feeling home sick almost serial number. It’s also kind of a prank to
immediately entering the country. Luckily pull on people when they get so excited. I
Hong Kong was only a bus ride away from hope nobody is upset by it!
where I lived in China, and that’s one of
the most densely populated cities in the Any advice for someone who is thinking of
world. Incredibly international and I felt like launching a crowdfunding campaign?
I was living in the matrix or an anime.
If someone is really serious about it my
suggestion is you spend several hours
The Kickstarter saw colored units and talking to someone who has done it before
goldbacks, but only white units are being and can walk you through the process. It’s
produced now. Would we see anything just too big and too huge to try and do on
like that again soon? your own. I had a lot of help behind the
scenes, and having gone to HAX we had
There are no real solid plans for color good connections to people at Kickstarter
versions or special backs, but I do want and the media to help get things rolling.
to do a black version at some point with But there are some basic things that you
anodized black back. I also think it would need to have before getting started that I
be really cool to try doing a translucent can easily list out.
smoked black front cover, that the OLED
could shine through... but we would need First, get all your social media going,
to buy a lot of that kind of plastic to do so. Facebook, Twitter, Youtube, Instagram,
Snapchat, and anything else I’m
forgetting, you’ll want to sign up an
We saw that the Kickstarter units were account with your business and start giving
serialised, and it looks like we got the first people a reason to follow these accounts.
unit? (1 of 10,000) Start building a community and getting
people excited about what you are doing.
Everyone is number one! This is kind of a The goal here is to have people who are
funny story, and people ask me about it going to buy the product the second you
pretty frequently. I originally wanted to to be continued next page >>
Page 10 of 40
launch and also help share it with their I also helped fund the Voltera Circuit
networks. Board Printer but didn’t pony up to
actually buy the device because I wanted
Second is to start paying attention to the to see the technology work before going
media and blogs you would want to see all in. But it’s been a few years now and
your campaign posted in. Figure out the they’ve got great reviews. I make a lot of
names of individual writers that cover prototypes so it would save a lot of time!
stories like yours. Once you have 2 or 3
major blogs identified, email or contact But in general, I advise people to be
those writers and in one or two sentences extra critical of hardware crowd funding
explain what you are doing and link to campaigns. There are a lot of campaigns
your website. Bloggers have very little out there that are extremely exciting,
time to read a story, and get overloaded but if you look at them from a technical
with press releases, so stand out by being or business perspective are doomed
authentic and real. Most of the emails for failure. But it’s a narrow line for sure,
they get aren’t from the project creators, products like the Arduboy probably would
but don’t talk their ear off, let them get not exist if it wasn’t for Kickstarter so you
interested on their own. need to evaluate every projects risks and
rewards yourself.
Finally, and probably most important is
to get your ducks in a row. You might not What is keeping you busy right now?
realize it but you are starting a business,
a company. Get that setup, at least set We just finally finished shipping every last
up an LLC because that way you don’t Pre-Order we have had! That is a big
have to pay personal income taxes. Figure milestone. In one way or another I’ve been
out how much shipping is going to cost, working on this project for almost 3 years
and pad it because actual costs are and now everyone finally will have an
almost always going to be higher than Arduboy if they wanted one! Now I spend
what you predict. You should have a very most of my time trying to figure out what
specific plan of how you will spend every comes next, I get asked that question a
dollar you are going to get. Plan what lot so I’m trying to come up with a good
happens if you are over-funded. This was answer. Mostly just trying to figure out how
my biggest issue, I was not immediately I can support the community the best!
ready to produce 12 times as much as was
originally planned.
Is there anything you would like to tell the
In summary, I think the best thing you can Arduboy community?
do is get together with other people who
have done it before. Why not make them Thank you, thank you, thank you! The
part of your team? Oh and make sure you Arduboy community is amazing and is
sign agreements with your co-founders to always coming up with creative new
avoid conflicts in the future! games and technical improvements to
the code. Every day I see the Arduboy
Have you backed do new things I never thought possible
any Kickstarter like 3d with shading, gray scale, or
campaigns yourself? procedural content generation. But I also
see it changing peoples lives occasionally
I backed the Pebble and that makes me extremely proud to
Time and the Time 2, help support things like that. Thank you
and actually got to everyone!
meet their founder,
sad to see them get
gobbled up and canned by Fitbit. Thank you Kevin!

Page 11 of 40
Community
POLLs!
by @Celinebins

This month we took to th


asked you what makes a
We got 74 votes and

Simplicity of gameplay
“Simplicity is good because it means there’s no #1
pressure on people to make something fantastic and
because (let’s be honest) something complicated
isn’t likely to get played much on a tiny screen and 55%
will always be limited by hardware restrictions.”
-@Pharap

#2
Pixel art
If you want some ideas for pixel art, check out our
new Pixel page (page 30) to check out work from
Pixel artist Davit Masia. 48%
“Visibility- I think Arduboy games need to be easily
seen on the screen. Even though some games are
fun, they are hard to look at for a long period of time.
Great graphics and animations usually really help the
long-term playability of games on the system. There
really are some beautiful games for the system.”
-@crait
40%
#3
Amount of levels
“Replayability- This includes things like... Randomness
to each game, or maybe a lot of levels to hold you
over, or something that changes so that you aren’t
bored each time you play.” -@crait

Page 12 of 40
What makes an
arduboy game great?

he community pages and


an Arduboy game great.
d these are the results!

#10 bullets
#9 Original story line
6%
6%
#86%Ability to load saved games

3% 7%
14% #7 Sound Effects
Effective sound can elevate a solid game to
18% something even more fun and entertaining. Find out
how to use Tunes and Tones on page 28!

25% #6 clones of classic games


“Clones of classic games are nice because nostalgia
and making things easy, but also because most
people know how they work and what the rules are
so they’re good to try to copy and to learn from.”
-@Pharap
25%
#5 Animation

33%

#4 Easy to edit source code


“Generally I’m not a major proponent of open source
(certainly not Richard Stallman level) but because
Arduboy is meant to be educational I think it’s
important that people make the source code of their
games available for others to learn from.” -@Pharap
“If there is something you dont like in a game, its
generaly prety simple to change it.. My favourite
thing about Arduboy” -@curly

Page 13 of 40
LEARN:
In this topic we would like to present
you some tips & tricks to help you
code your games for Arduboy.
What we present doesn’t intend to
be the absolute truth, it’s just a way
we at TEAM a.r.g. code.
So always remember,
these are not golden rules.

ricks
T
Tips & by TEAM
A.R.G

#3 - Keeping the “main loop” clean


by @jo3ri
In our previous article, we explained #define When you start coding, you probably just
and why we use those and also about the start putting code in the main loop and so
naming of variables, functions and defines. the main loop grows and grows with code.
This time let’s have look at “if else”, “switch In our first article we explained how to use
cases” or “function pointers”. We will do multiple files. Well this will become very
this, while showing you how to keep the useful, once we simplify that “main loop”.
“main loop” as clean/empty as possible.
Start with setting up the basic code in your
prefered program like this:
#include <Arduino.h>
#include <Arduboy2.h>

Arduboy2 arduboy;

void setup() {
arduboy.begin();
arduboy.setFrameRate(60); // set the frame rate at 60 fps
}

void loop() {
if (!(arduboy.nextFrame())) return; // wait for the next frame (60/s)
arduboy.pollButtons(); // check button input
arduboy.clear(); // clear the screen
arduboy.display(); // update the display
}

This will show the Arduboy logo, clear the a beginning, a middle and an ending.
screen and do nothing more. Now, before Probably a lot more, but for our example
we continue, it is best to understand that we’ll stick to these 3.
a game, like a book, has at least 3 parts:
to be continued next page >>
Page 14 of 40
To help ourselves we are going to create a We are going to name our parts too.
variable to keep track of what part we are Add the next part in your code, before:
currently executing code. Remember the Arduboy2Base arduboy;
#define explanation in the previous issue?
#define STATE_GAME_INTRO 0
#define STATE_GAME_PLAY 1
#define STATE_GAME_OVER 2

And the variable for the game state, right


before: void setup() {
byte gameState = STATE_GAME_INTRO;
Now we can do a simple check with “if” variable. We’ll only show the loop to keep
statements, by checking our gameState it smaller.
void loop() {
if (!(arduboy.nextFrame())) return; // wait for the next frame (60/s)
arduboy.pollButtons(); // check button input
arduboy.clear(); // clear the screen

if (gameState == STATE_GAME_INTRO)
{
arduboy.setCursor(0, 10);
arduboy.println(“Welcome”);
arduboy.println(“Press A to START”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_PLAY;
}
if (gameState == STATE_GAME_PLAY)
{
arduboy.setCursor(0, 10);
arduboy.println(“The Game is on”);
arduboy.println(“Press A to END”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_OVER;
}
if (gameState == STATE_GAME_OVER)
{
arduboy.setCursor(0, 10);
arduboy.println(“GAME OVER”);
arduboy.println(“Press A”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_INTRO;
}

arduboy.display(); // update the display


}

Now if we try out our little “game”, you you press the button, it will immediately
will notice something is wrong. It is like the check the next “if”. But because there
game just loops through all “if” statements hasn’t been enough time passed, the
and doesn’t stop, once we pressed a button still seems to be pressed and so
button, although we used justPressed. The our gameState changes again and once
reason? Well, if we only use “if” statements, more with the third “if” statement.
our code will check the first “if” and if
to be continued next page >>
Page 15 of 40
If you change the button to “B” in the difference between only “if” and “else if”.
second “if” statement, you’ll notice that You can use this for example, when you
the problem is solved. But this isn’t the want a sprite to walk only in 4 directions
solution we are looking for. We want to be and in not 8 (diagonal).
able to use the same button for all actions.
Here is where we need “if” and “else if”. Once we have more than 3 “else if”
This will make the code execute only one statements, it might be better to have a
of the successive “if” statements. So add look at switch cases. Again the Arduino
“else” in front of the second and third Reference Page is a good starting point.
“if”. You can read more about it on the Well, now that we know, we can replace
Arduino Reference Page. Remember the “if … else”. Let’s give it a try (showing the
replaced code part):
switch (gameState)
{
case STATE_GAME_INTRO:
arduboy.setCursor(0, 10);
arduboy.println(“Welcome”);
arduboy.println(“Press A to START”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_PLAY;
break;
case STATE_GAME_PLAY:
arduboy.setCursor(0, 10);
arduboy.println(“The Game is on”);
arduboy.println(“Press A to END”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_OVER;
break;
case STATE_GAME_OVER:
arduboy.setCursor(0, 10);
arduboy.println(“GAME OVER”);
arduboy.println(“Press A”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_INTRO;
break;
}

Let’s continue with cleaning out our main


loop. Each case has its own part of code
to be executed, when the corresponding
gameState is selected. We can make
a separate “function” for each of those
parts. Because we have to declare those
functions BEFORE we can use them, you’ll
have to add them before the “setup”:

to be continued next page >>


Page 16 of 40
void gameIntro()
{
arduboy.setCursor(0, 10);
arduboy.println(“Welcome”);
arduboy.println(“Press A to START”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_PLAY;
}

void gamePlay()
{
arduboy.setCursor(0, 10);
arduboy.println(“The Game is on”);
arduboy.println(“Press A to END”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_OVER;
}

void gameOver()
{
arduboy.setCursor(0, 10);
arduboy.println(“GAME OVER”);
arduboy.println(“Press A”);
if (arduboy.justPressed(A_BUTTON)) gameState = STATE_GAME_INTRO;
}

Now we can change the loop into a


switch case with functions, like this (only
showing the switch case):

switch (gameState)
{
case STATE_GAME_INTRO:
gameIntro();
break;
case STATE_GAME_PLAY:
gamePlay();
break;
case STATE_GAME_OVER:
gameOver();
break;
}

It looks like our main loop is getting a clean Now that our game has been split out over
look, doesn’t it :) It’s time to re-read our different functions, it’s time to talk about
first article on multiple tabs/files. In our functions by pointers in an array indexed
example, each function isn’t very big, but by gameState, our last step in the process
you can imagine they will grow fast when of getting a clean easy readable loop.
adding game play. You probably add Nope, there isn’t an Arduino reference
more cases in your switch case, holding page on this one; I’ll do my best to explain
different parts of the game, like: NEXT_ myself.
LEVEL, PAUSE, ... putting each function in
a different .h file will help you to keep the
overview.

to be continued next page >>


Page 17 of 40
It is possible to put our 3 game functions of those functions (and you can add a
(or more) in an array in PROGMEM. function multiple times if needed) and
Well, not the functions themselves, but create another function to read out the
a reference to them, a “pointer”. All correct one. First let’s create the “list” and
we need to do is make a sequential list name the “type” of the list:
typedef void (*FunctionPointer) ();

const FunctionPointer PROGMEM mainGameLoop[] = {


gameIntro,
gamePlay,
gameOver,
};

And as a final step we replace the


“switch case” with the code that uses the
gameState to pick to correct function out
of our “list” we have put in PROGMEM.
((FunctionPointer) pgm_read_word (&mainGameLoop[gameState]))();

That’s it ! You probably noticed your code is a bit


bigger than when you had the switch
If you managed to move all functions into case. This is one of the things you’ll have
different files and added a globals.h, like to consider yourself, but just so you know.
we explained in the first Tips & tricks, you’ll There is lot of other places to regain those
have a very clean, readable, setup and few lost bytes.
loop. As a reference, I have put the end
result on github: https://github.com/JO3RI/ If you have any questions about this
tips-tricks-3-example article, do send us a DM on twitter, or
drop us a message @arduboymag in the
community pages.

Next time, we’ll talk about how we can pass variables into
a function and how we can receive a variable back from
a function. Have fun coding your games.
BIT
In this “small” part of
the magazine I would
like to tell you about the
possibilities you have to
reduce coding size when
creating your app/game.

by JO3RI
SQ
U EEZ ER

#2 - Combining multiple booleans


by @jo3ri

In this issue let’s see how you can reduce But even combining different booleans
size when combining multiple booleans for keeping track of enemy statuses, like
into a byte, or even multiple bytes into “alive”, “visible”, “dying”, “invincible”,
1 byte. First you need to understand the “jumping” … could become byte saving,
difference of bits and bytes. Now that when you have a certain amount of
you’re into coding, you should know that enemies.
on an 8-bit system, you have 8 bits in 1
byte. If you look at this in Binary, you’ll Another place where this could become
“see” the bits. 0B11111111 equals to 255 in useful for is with tiles and maps. If you have
Decimals and 0xFF in Hexadecimals. Keep a map using different tiles and you only
this in mind, because it will always help use 16 (or less) different tiles, you could
you, when working in bits. use “half” a byte to store map data. Look
at a byte in hexadecimals and you’ll
If you create a boolean and compile your understand. In 0xFF, you have a “right”
code, the boolean will take the place of F and a “left” F (upper and lower), this
1 byte, although 1 bit would suffice. The means you can use both for storing a
compiler can’t combine those booleans number from 0-15 and so combine 2 half
into 1 byte itself, so we have to do this on bytes into one. If want this more explained
our own. Of course you might think, what have a look at the technical page of our
is the gain in having 1 byte instead of 8 game Virus LQP-79. There we combined 2
bytes ? Let’s assume you have a game map parts in 1 byte, but it comes down to
with 256 levels and each level has for the same thing. Enough about the talking,
example 8 items. To keep track of those here are some examples in the next page.
8 items being picked up, you can use a
“flag” (a boolean). That would mean,
you’ll need 2048 bytes in RAM ... , so here
the gain of stuffing 8 “flags” in 1 byte
becomes more obvious.

to be continued next page >>


Page 19 of 40
byte chestsOne = 0B00010000;
//|||||||└------> 0 chest 0 has been opened (0 = false / 1 = true)
//||||||└-------> 1 chest 1 has been opened (0 = false / 1 = true)
//|||||└--------> 2 chest 2 has been opened (0 = false / 1 = true)
//||||└---------> 3 chest 3 has been opened (0 = false / 1 = true)
//|||└----------> 4 chest 4 has been opened (0 = false / 1 = true)
//||└-----------> 5 chest 5 has been opened (0 = false / 1 = true)
//|└------------> 6 chest 6 has been opened (0 = false / 1 = true)
//└-------------> 7 chest 7 has been opened (0 = false / 1 = true)

byte chestsTwo = 0B00000010;


//|||||||└------> 0 chest 8 has been opened (0 = false / 1 = true)
//||||||└-------> 1 chest 9 has been opened (0 = false / 1 = true)
//|||||└--------> 2 chest 10 has been opened (0 = false / 1 = true)
//||||└---------> 3 chest 11 has been opened (0 = false / 1 = true)
//|||└----------> 4 chest 12 has been opened (0 = false / 1 = true)
//||└-----------> 5 chest 13 has been opened (0 = false / 1 = true)
//|└------------> 6 chest 14 has been opened (0 = false / 1 = true)
//└-------------> 7 chest 15 has been opened (0 = false / 1 = true)

In this example we used 2 bytes to keep so you have a better understanding of


track of 16 chets. As you can see chests how it works. (Even I still use it every time
4 and 9 have been opened. Now let’s I code). There are 2 ways of toggling the
close those chests and open chests 6, “flags” (bits). We can use bitSet (set flag
12, 15 . To do this we need toggle to the to true) and bitClear (set flag to false),
correct “flag”. We always read bytes from read about bitRead (read the flag) and
left (low) to right (high). Read all about the other commands on this Arduino
bit math on the Arduino reference page, reference page. Or by using bit math (see
the previous link).
bitClear(chestsOne, 4);
bitClear(chestsTwo, 1);
bitSet(chestsOne, 6);
bitSet(chestsTwo, 4);
bitSet(chestsTwo, 7);
Once those are all toggled, we can use
an “if” statement to determine what to do,
or even switch the sprite used:
for (byte i = 0 ; i < 8; i++)
{
if (bitRead(chestsOne,i) == false) // if a chest is closed
{
player.score += 500; // add score
bitSet(chetsOne, i); // open the chest
}
if (bitRead(chestsTwo,i) == false) // if a chest is closed
{
player.score += 500; // add score
bitSet(chetsTwo, i); // open the chest
}
}
Haha fun you say, but you still need to
write an “if” statement for every group of 8
chests! Well we can even combine those!
to be continued next page >>
Let’s see how to do that on the next page.
Page 20 of 40
So lets combine the “if” statements for
every group of 8 chests.
byte allChests[] = { 0B00010000, 0B00010000};

Indeed, we used an array of bytes. The 2 bytes( for 16 chets). Now let’s open en
size of the array is limited to the size of close the same chests as in the previous
RAM you have available. Here the size is example. And then have the same “if “
statement.
bitClear(allChests[0], 4);
bitClear(allChests[1], 1);
bitSet(allChests[0], 6);
bitSet(allChests[1], 4);
bitSet(allChests[1], 7);

for (byte i = 0 ; i < 16; i++)


{
if (bitRead(allChests[i / 8],i) == false) // if a chest is closed
{
player.score += 500; // add score
bitSet(allChests[i / 8], i); // open the chest
}
}

While the “if” statement is shorter, Because this is an 8-bit system, we can
changing the state of the chests at the toggle 8 bits in 1 cycle and less cycles
beginning isn’t any shorter. Here we can means increasing speed. We have to set 2
show you how bit toggling can be used. bytes in total:
allChests[0] ^= 0B01010000;
allChests[1] ^= 0B10010010;

Doing this means we toggled bits, bits One final thing I want to show you is bit
that were on, will be off and visa versa. shifting, again Arduino has a very good
I know this isn’t easy to understand by webpage on this. shifting bits does exactly
just looking at it, but like I said before, I what it says. It moves bits in a byte left
find the reference page for bit math by or right. The bits get lost if they fall out of
Arduino very helpful. Just take a pencil the byte, which is an advantage we can
and some paper and write out the bytes use. Remember I started with asking you
in Binary with the mask under it, so you having to remember HEX notation of a
can write down the result. In our chests byte (0xFF) ?
example, you might not find it useful to set
8 bits at the same time, but if you have 8 Well let’s assume you have to store 4
characteristic flags in a byte for enemies, numbers with a max of 16 into 1 byte,
you’ll find it very helpful to be able to set for example 9 and 4, in BIN those are
those all at once. 0B0001001 and 0B00000100. Here is how:

byte halfBytes = 0B0001001 << 4; // move and store 4 bits to the left (=
0B10010000)
halfBytes += 0B00000100; // add the other byte (= 0B10010100)

to be continued next page >>


Page 21 of 40
This results in 0B10010100 or if seen in HEX more than using a mask to get out the
as 0x94. Recognize those numbers ? right part and bitshift the left part, like this:
Getting out the numbers again is nothing

byte firstByte = halfBytes & 0b00001111; // only copy over the 4 most right
bits
byte SecondByte = halfBytes >> 4; // move the 4 most left bits to the
right and copy

One could use this mechanic to store a


frame counter in the 4 most right bits and 4
characteristics in the 4 most left bits. Keep
in mind that the gain will be a lot bigger if
you have a lot of elements using the same
sort of bytes, like enemies, treasure and
map data.

Voila, this a small way of reducing bytes, but by


following or monthly bit squeeze tips, you’ll soon find
out you can gain a lot of bytes, by doing this kind of
bit squeezing. Next time let’s have look at “do you
really need a switch case, use math instead”.

Page 22 of 40
Arduboy
Graphics
by @Gaveno112

Understand how making graphics for the Arduboy works with Team a.r.g’s
Gaveno, and find links to useful tools in the article.
With the Arduboy having moved on to it’s To really understand how it all works, we’ll
new library, Arduboy 2 (update available start with explaining how the graphics
through Arduino IDE library manager), actually work. As you know by now the
it’s time to explain how to use the sprite screen size is 128x64 pixels. Also good to
functions. remember is that a byte holds 8 bits (true/
false flags) OR 8 pixels.

const unsigned char PROGMEM trollyFish[] =


{
// TILE 00
0xf0, 0xc0, 0x80, 0xc0, 0x61, 0x77, 0xfb, 0xfb, 0x9a, 0x28, 0x08, 0x90, 0xe0,
0xc0, 0x00, 0xc0,
0x0f, 0x03, 0x01, 0x43, 0x74, 0x6b, 0x6a, 0x5f, 0x1f, 0x1b, 0x15, 0x15, 0x0d,
0x0e, 0x0b, 0x01,
};

If you look closely at the picture, you’ll see


that the 8 pixels highlighted in blue are
one byte vertically orientated. This means
the height of every image, tile or sprite will
always be a multiple of 8, because you
to be continued next page >>
can’t set half bytes.
Page 23 of 40
Even if you create an image of let’s say the upper left corner, it’s best to always
12 pixels height, the actual bits used will add empty rows at the bottom of your
be 16 and not 12. Never EVER forget this. image/tile/sprite, until you reach a multiple
Because point (x: 0, y: 0) on the screen is of 8.

The second thing to keep in mind is: the An image can be just black & white. In the
way you create your pixel art should example above we set the transparent
always use 100% black, 100% white and pixels to pink to make it clear. Even
100% transparent pixels for tiles and sprites. if you’re not going to use masks, use
transparent pixels as your “background
color”.

Third important thing is: naming. Give your And finally don’t forget to arrange your
graphics a name, but don’t use numbers tiles and sprites vertically in one column.
— with one exception in a moment — Now we know how we have to name
or special characters. Converters don’t and create our images. Time to convert
like them. Then postfix the name with an them into code. For each type we use
underscore and the dimensions of the a different converter. You probably can
asset. For an image, it’s the total width find other converters on the internet, but
and height. For the tiles it’s the width and we will show you how to use the online
height of one tile (note that tiles should converters TEAM a.r.g. created. All these
to be square). And for sprites, we use the are based on Josh Goebel’s work, you can
dimensions of one sprite. Remember for find on his github repository img2ard.
every case, height must still be a multiple
of 8.

to be continued next page >>


Page 24 of 40
Converting Images: Each of these converters will give you an
For an image use Team a.r.g’s Image array of bytes. The image converter will
converter. An image is a picture in one only give you one array, including the size
piece shown on the screen. of the entire image. But it will also show
you the image as it will be displayed on
For a tile sheet use Team a.r.g’s tile the screen. (You could look for pixels that
converter. A tile sheet is a collection of might have changed, because the source
smaller square images vertically arranged image didn’t have 100% black/white
into one column as one big image. pixels).

And finally for a sprite sheet use Team This array is compatible with the
a.r.g’s sprite sheet converter. A sprite sheet drawSelfMasked function to display the
is a collection of smaller images, each image on screen. (If you want to use
representing a frame of an animated drawBitmap, you’ll have to comment the
image, vertically arranged into one dimensions in the array).
column as one big image.

sprites.drawSelfMasked(x, y, imageName, frameNumber);

Arguments: Don’t forget to initialize the Sprites object


x, y: coordinates on screen to draw image. — after the line “Arduboy2Base arduboy;”
imageName: name of the array in code. — by writing:
frameNumber: always zero (0) when
displaying an image. (the frame to draw
when drawing a sprite, or the tile to draw
when drawing a tile)

Sprites sprites;

The tile converter will also give you just one And this is the function you will normally
array, including the size of one tile (not the use for tiles. Remember, tiles are used for
entire tilesheet). You will also see you’re background and normally will never need
tilesheet with every tile nicely ordered in masking.
rows and columns, for you to check if it
was divided correctly. This array is perfect
for use with the sprite function.

sprites.drawSelfMasked (x, y, tileSheet, tileNumber);

By changing the tileNumber, you can


select a different tile to be drawn. What
you actually should do, is create a
“map” representing a number out of your
tileSheet. Best is, if you put this “map” in
PROGMEM.
I’m not going to explain PROGMEM here,
but I’ll give you an example of a 5x5
tileMap on the next page.

to be continued next page >>


Page 25 of 40
const unsigned char PROGMEM tileMap[] =
{
0, 0, 0, 0, 0,
1, 2, 1, 2, 1,
3, 3, 4, 4, 3,
1, 2, 1, 2, 1,
0, 0, 0, 0, 0,
}

Imagine your tileSheet uses tiles of 8x8 function that will draw this map, according
pixels, well now we need to create a the numbers in the array, using the tiles
from your tileSheet.
void drawMap()
{
for (byte y = 0; y < 5; y++)
{
for (byte x = 0; x < 5; x++)
{
sprites.drawSelfMasked (x * 8, y * 8, tileSheet, pgm_read_
byte(&tileMap[x + (5 * y)]));
}
}
}

To learn more about tile maps and ways If you don’t care about your sprite being
to compress them for the Arduboy, check “look through” (meaning you’ll see
out the technical pages for Mystic Balloon, anything else behind the sprite too), you
Virus LQP-79, and Dungeons on the TEAM can use the drawSelfMasked function and
a.r.g. website. use the “sprite” array. If you don’t want
this behaviour, you’ll need a masked sprite
The sprite converter will give you not one which doubles the amount of bytes used
but three arrays. In all three arrays the by the sprite.
size of one sprite will be included. Again
you’ll see an image, but this time it will be Use the drawPlusMask function and use
the sprite looping through all of its frames. the “Sprite + Mask” array. If you only
Now depending on what you’re going to want a small mask behind your sprite,
do with the sprite, you can use a different you can use the drawErase function
function. and the “mask” array, followed by the
drawSelfMasked function and the “sprite”
array.

sprites.drawSelfMasked (x, y, sprite, frameNumber);

sprites.drawPlusMask(x, y, sprite_plus_mask, frameNumber);

sprites.drawErase(x, y, mask, frameNumber);


sprites.drawSelfMasked (x, y, sprite, frameNumber);

to be continued next page >>


Page 26 of 40
The Sprites class has 2 more functions: I won’t go into detail on the specifics, give
drawOverwrite and drawExternalMask. The them a try if you’re curious.
former works similarly to drawErase.

drawOverwrite(x, y, mask, frameNumber);

The latter is different. It takes two separate the dimensions because it uses the same
arrays to draw a masked sprite, whereas values from the sprite, so you’ll have to
drawPlusSelf only uses one array to do this. comment out those numbers yourself.
Using two arrays gives the developer a This means that the dimensions of your
chance to use a mask created separately special mask have to be exactly the same
from the original sprite. For example if you as the dimensions of the sprite you use.
want to mask only a part of your sprite. drawExternalMask also allows using a
different frame number for the mask than
There is one thing you should remember what is used for the sprite.
though; the mask you’ll be using doesn’t
need the first two bytes in its array to be

drawExternalMask(x, y, sprite, mask, spriteFrameNumber, maskFrameNumber);

The procedures you’ll be using most for


sprites and tiles are drawSelfmasked or
drawPlusMask. If you want to draw a single
image, you can use drawSelfmasked.

You could also use drawBitmap, but this is


not recommended as it is redundant and
will increase code byte usage. It is most
efficient to stick to using either drawBitmap
(legacy) or the Sprites class, but not both
together.

Have fun with making some graphics


for your game!

Page 27 of 40
game design tips
by crait
Programming a video game can be fun, but once you create a few games,
sometimes you can feel burnt out and not really know what to do next.
Maybe you’re a beginner and you don’t really know how to come up with
your own game. Either way, you can follow this guide to help come up with
a game concept.

In last month’s article, I rambled on about One thing I loved doing as a kid was
a lot of stuff... I hate that I did that, but it’s catching lizards. Where I lived, they were
really important to take away these three all over the place in the summer. I would
things from that article: try to find them behind bushes or climbing
on people’s houses. In fact, I would even
1) Work on games that you will finish so tresspass in order to find and catch them.
that you don’t have an excuse to give up. I remember having a lot of fun doing this...
Anytime I got close to one, it would run
2) A game’s theme can be removed from along the wall really fast and I’d have to
a game and it should still be fun. chase it, trying to cup my hand over it so it
can’t leave.
3) A game’s theme can be thought up
during the ideation phase of planning.

In this month’s article, which will be the


final part of this 3-part series, I want to talk
a little more about mechanics and theme. Let’s say I wanted to make a game with
this as my inspiration... I already have the
One big debate is over which comes first theme of catching lizards... I just need the
in the design process. Personally, I think mechanics...
a good theme can come first or a good
mechanic can come first. If the theme I could make a game where you run
comes first, you just have to come up with around into people’s yards and have
some good mechanics that fit the theme. a real hard time catching lizards, while
If the mechanics come first, you have avoiding being caught by the owner of
to think of a good theme to have as a the house. This would offer some challenge
metaphor for the mechanics. I will show and could be done in 2D or 3D. There
you an example of both of these! could even be a sneaking mechanic to
make sure the lizards don’t run away so
When coming up with a new game idea, I quickly.
try to think about cool or interesting things
that happened in my life. Sometimes, I Okay, that sounds like a good start for a
purposely try to remember very vague game, but let’s think about this experience
situations I was in be that gives me more in the opposite order. Let’s take the
blank spaces to fill with my own creativity. mechanics from catching the lizards, and
I will take those experiences and try to turn give it another theme.
them into a digital game.

to be continued next page >>


Page 28 of 40
It could be anything- I always start with It’s kinda like the mixing method I
something completely unrelalted. Instead mentioned in the first article. Come up with
of a game where you’re trying to trap something that no one would ever think to
lizards climbing on a wall, I could swap mix a racing game with and play around
lizards out for... hmmm.... Let’s say evil with that idea. What about mixing in
robots that try to drill into the wall. And lumberjacks? What about mixing dentistry?
instead of them climbing on the wall of a Yeah, I don’t think I have ever heard of
neighbor’s house, maybe they’re climbing a game about racing and brushing your
on the walls of banks and I’m a security teeth. Maybe your car is a tooth brush and
guard trying to protect the money inside! you have to drive around teeth to clean
them? Dirty parts of the teeth get you
more points and tooth paste make you
slide faster? See, just mix two unrelated
topics and work with the gameplay to see
what you can come up with.

There is so much information on the


internet about game design and how
to get started that I can’t possibly cover
everything in these three past articles.
Even so, I hope that these articles helped
open your mind a little about different
ways to think about game design.

This is one of my favorite ways of coming I don’t know what I’ll write in next month’s
up with game ideas because the games article, but be sure to take a read when it
I tend to come up with really mean a lot comes out.
to me. When they do, I feel like I have
a lot higher chance of actually finishing
them and feeling proud about what I’ve
made. In fact, many popular games have
stemmed from this kind of creative thinking
and your game can be next.

Sometimes, coming up with a general


theme is quite easy. Maybe you know that
you want to make a racing game. What
next? There are so many sub-genres of
games out there, you may not know which
one you want to try out. What kind of
racing game do you want to do?

If I am making a game and it sounds a


bit generic, one good way to make it
interesting is to combine that idea with
some other cocept that wouldn’t seem to
even fit.

Until next time, take care, keep


expirementing, and be sure to
share your game ideas on the
Arduboy community forum!

Page 29 of 40
Scribbled notes
by @celinebins
I’ve started with little programming experience, so I decided to make a
game to better understand all the users that are trying to do so, prove that
if I can do it, then anyone can too, and of course have something cool to
show off. This series is going to summarize some of the lessons I’ve learnt as I
try to create my own game. Hope it will help and inspire other users!

Different languages
So when I first started my journey to learn
programming, I realized there are a TON
of programming languages, as existing
languages constantly evolve to fit new
problems that need to be solved. Ruby
and Python are great languages for writing
code used for web applications, and C++
is used in most packaged software; for
games, office applications and operating Arduino Leonardo
Image taken from Robotshop
systems.

Arduboy and Arduino Notes on working with the IDE:


When I got my Arduboy, I immediately set If you download a game file (let’s say
my computer with the Arduino Integrated it’s ABC game) from Github, sometimes
Development Environment (IDE). But what it saves as ABC-master.zip. If you try to
is Arduino? Arduino is an open sourced open and run the ABC.ino, it might report
computer hardware and software tool for back with an error saying that the game
building digital devices and interactive file needs to be saved in a folder with
objects. For example, you could buy some the same name. If you delete the extra
sensors and LEDS and make an alarm that “-master” from the folder you should be
goes off when your pet leaves the house. able to solve that problem.
As for the Arduboy, the board is already
hooked up with sensors that detect input Understanding C
(buttons!) and display output (screen and Even though C++ is exactly English, there
speakers!), so no additional “hacking” is are some terms used that help make sense
required to start. of code, and the different color codes
also help identify what will be read from
Next question, what is an IDE? The IDE is a the code (e.g: grayed out comments will
platform for software development, storing not be). Following crait’s eight tutorials is
libraries that make writing and debugging a great start, as you get to practice with
code more convenient. It is also where running some sketches on your Arduboy.
you upload your code to the Arduboy.
The Arduboy’s microcontroller – the 32u4
is the same as the Arduino Leonardo,
which is why you have to select “Arduino
Leonardo” when you select your board on
the Arduino IDE.

to be continued next page >>


Page 30 of 40
Using & Making Images Case
The best way for me to make images for After not having success with my if
the Arduboy is to use Windows Paint. If I functions to get the backbone of my
wanted to trace an image I like, I save text game going, I posted it on the forum
it, open it on Paint, resize it accordingly asking for help, and JO3RI replied with
and trace it over with the pencil tool. using the Case function. It provides a
Once done, it gets saved as a PNG file. convenient alternative to the if when
When I was trying to make graphics using dealing with a multiple way branch.
the ToChars tool, I g ot some errors when switch (gameProgress)
uploading a 71x71 pixel PNG file. That’s {
because the pixels need to be in multiples case GAME_INTRO:
of 8! Hence it being called 8-bit. arduboy.println(“Press A to
start!”);
New Functions if (arduboy.justPressed(A_BUT-
Do.. while TON)) gameProgress = GAME_START;
If you want to display your own name after break;
the Arduboy drop down logo, and only case GAME_START:
continue after you pressed the ‘A’ button, arduboy.println(“A: Player 1”);
you can write: arduboy.println(“B: Player 2”);
do{ if (arduboy.justPressed(A_BUT-
} while( !arduboy.pressed(A_BUT- TON)) gameProgress = PLAYER_ONE_WINS;
TON) ); else if (arduboy.justPressed(B_
BUTTON)) gameProgress = PLAYER_TWO_
This function will make your code block (in WINS;
this case your name displayed on screen) break;
run until its condition is false. In this case case PLAYER_ONE_WINS:
our condition is the ‘A’ button, and will run arduboy.print(“You Win!”);
only when the ‘A’ button is pressed (an if (arduboy.justPressed(A_BUT-
exclamation mark means ‘not’). Once the TON | B_BUTTON)) gameProgress = GAME_
condition is false it will exit the loop and INTRO;
move on to the next line of code. break;
case PLAYER_TWO_WINS:
arduboy.print(“You Lose!”);
if (arduboy.justPressed(A_BUT-
TON | B_BUTTON)) gameProgress = GAME_
INTRO;
break;
}
In my code, the variable that needs to
be checked is the progress of the game,
and once
the matching
label is found,
the next line
of code will
be run.

Hope this has been informative for users


who are starting off! Check back next
issue for more scribbled notes..
Page 31 of 40
using tunes
and tones by @Cronck
In this article, @Cronck will explore the sounds of Arduboy. Thanks to @
MLXXXp for helping the writer understand more about Arduboy Sound.

If you want to play sounds on the Arduboy To use this with the Arduboy2 library, you
when using the standard Arduboy2 library, would include it after Arduoby2.h:
you need to pick a compatible sound #include <Arduboy2.h>
library, include it in your sketch, and then #include <ArduboyPlaytune.h>
use the particular functions that it provides
to produce sound. and create an object for it after the
There are a number of sound libraries that Arduboy2 object:
can be used with the Arduboy, including:
Arduboy2 arduboy;
- ArduboyTones ArduboyPlaytune tunes(arduboy.audio.
- ArduboyPlaytune enabled);
- ArdVoice
- ATMlib You then need to initialise the library in
your setup() function:
You can even just use the Arduino tone()
function, but there’s really no need since // audio setup
the ArduboyTones library can do the same tunes.initChannel(PIN_SPEAKER_1);
thing (and more) and produces less code. #ifndef AB_DEVKIT
Which library you choose depends on // if not a DevKit
what features you want and the amount tunes.initChannel(PIN_SPEAKER_2);
of program memory that you can afford to #else
have it use. // if it’s a DevKit
The ArduboyTones library is generally the tunes.initChannel(PIN_SPEAKER_1);
simplest to use and produces the smallest // use the same pin for both channels
code. tunes.toneMutesScore(true);
ArduboyPlaytune provides the same // mute the score when a tone is
features that were available in the original sounding
Arduboy library. #endif
ArdVoice is intended to produce crude
speech. The PlayTune example sketch included in
ATMlib (Arduboy Tracker Music library) the Arduboy2 library is an example of using
plays sophisticated multichannel ChipTune ArduboyPlaytune.
type music and effects. File > Examples > Arduboy2 > PlayTune

To play sounds, you will need to include


and set up the ArduboyPlaytune library
and use the playScore() function.
to be continued next page >>
Page 32 of 40
If you’re writing a new sketch, you may So below are two examples of the
find that using ArduboyTones is sufficient Gameboy Startup sound, one is right the
and simpler. To do this you need to include other is not.
it after Arduboy2.h: // spot on sound of the old
#include <Arduboy2.h> Gameboy start up -- for use with,
#include <ArduboyTones.h> ArduboyPlaytune
const byte PROGMEM bing [] = {
and create an object for it after the 0x90,0x30, 0,107, 0x80, 0x90,0x60,
Arduboy2 object: 1,244, 0x80, 0xf0};

Arduboy2 arduboy; // trying to get the same Gameboy


ArduboyTones sound(arduboy.audio. sound-- for use with, ArduboyTones
enabled); (but its not on the money)
You then use the sound.tone() or sound. const uint16_t bing[] PROGMEM = {
tones() functions to play your sounds. The NOTE_FS1,107, NOTE_C4,500, TONES_
latest version of Flappy Ball1 is a good END
example of using ArduboyTones. };
So why can Playtune make a perfect
NOTE: Gameboy Start up sound but Tones can
ArduboyTones – uses this code format: not? Well it comes down to how music
really sounds. And what these two libraries
// this is a coin like sound are capable of.
const uint16_t point[] PROGMEM = { ArduboyPlaytune ‘s can produce TWO
NOTE_B5,75, NOTE_E6,225, TONES_END notes at the same time, think of this as
}; playing TWO keys on a piano at the same
time creating a note if you will thats a
while the ArduboyPlaytunes uses this combination of the Two. Its one sound but
format: two notes all the same. Lets call this a PRO
for Playtune.
// this is a coin like sound CON – this ability for two notes at the same
const byte PROGMEM point [] = { time cause more code space to be used
0x90,83, 0,75, 0x80, 0x90,88, 0,225, in the name of music.
0x80, 0xf0};
ArduboyTones uses the notes, you can see
Both are the SAME sound just different them in the code “C4”, this gives Tones
ways of doing things. the ability to be easily read. The down side
can be one note played at a time, we
Getting the correct translation of code lose the simultaneous note ability. BUT the
for the Arduboy logo is what I would like PRO from this is our code is smaller.
to show next. We have all seen the logo
come onto the screen at startup, but we Now our coin sound is the same in both
all remember that Original Gameboy Libraries because its a series of notes
startup you can hear it in your head. The played one at a time, but the Gameboy
sounds that the old games had, that startup sound can only be heard truly in
music stay with you still today. Think for a the ArduboyPlaytune version.
moment of your favorite Nintendo 8-bit
game, now focus on the loading screen or Here is my code (Taken from Original
that first level, what does your mind hear? FlappyBall game and imported for use in
Arduboy2 lib) for starting up the Arduboy
so that I get that original Gameboy Sound.

I hope that this helps some of you the way that


it has helped me. Happy Coding!
Page 33 of 40
In this segment of the
magazine we feature
work from pixel artists.
Do contact them if you
would like work with
them or use their work,
their contact information
is listed below.

Copyright By @DavitMasia

Twitter: https://twitter.com/DavitMasia
Patreon: https://www.patreon.com/davitmasia
Note: These
screenshots are
Arduboy sized:
128 x 64 pixels
EXPLORE:

Questions
In this section we’ll ask
the same 10 questions to with game
a different developer in developers
every new issue.
by @widehaslet

If you’ve been on the forums recently with a question, it was likely


answered by Mike McRoberts (@TheArduinoGuy). We sit down with
him to find out more about his
programming background, and
his first Arduboy game - Jet Pac.

1. Where did you find out about 5 . What do you read to learn how to
Arduboy the first time? code for Arduboy ?
From my mate @sones who brought one I already knew how to code in C so read
along to a Medway Makers meeting one the library documentation.
Saturday.
6 . What app/game do you have
2. What is the first program/game you currently on your Arduboy ?
created for Arduboy ? The current game I am working on.
Jet Pac - A recreation of the classic ZX
Spectrum game.
7. What Arduboy app/program is your
3. Did you have app/game developer favorite ?
experience before Arduboy ?
Circuit Dude by @crait is a great puzzle
Yes, I’ve been programming since I game. For graphics I love Sirene by
was about 12 years old. In my younger TeamARG.
years I wrote games for the ZX81 and ZX
Spectrum. Some of which got published
in the computer magazines of the day. 8. What is the next app/program for
Today I write mainly in C for the Arduino Arduboy from your hand we can
based devices but also use Lua, Python expect ?
and Javascript. I’m currently working on an isometric view
survival horror game.
4. What programs do you use for
creating Arduboy apps/games ? 9. What app/game would you love to
Pyxel for sprite creation. TeamARG tools see on the Arduboy ?
for the HEX conversion. I use Atom with the Rebelstar! Maybe i’ll do it myself one day.
PlatformIO plug-in for my IDE. Good old
pen and paper for everything else.
to be continued next page >>
Page 36 of 40
10.What is your best tip for other
people who want to start creating e.g. Space Invaders : Just start by learning
how to draw the alien Sprites to the
apps/games for Arduboy ?
screen. Then make them move left and
Just do it! The only thing worse than trying right. Then add the ability for them to
and failing is not trying at all. Get your drop down one line when they reach the
game idea and just make it. edges. Then make them drop random
bombs, and so on. Break every large
Learn as you go along. Break your idea problem down into simple sub-problems,
down into simple sub-components and do get them working then move onto the
those one at a time. next.

Are you a developer and want to be


featured here? Reach out to the Magazine
through Twitter DM @arduboymag

日本のユーザーに叫ぶ:
私たちは日本語フォーラムを持っています

この公式カテゴリは日本語を書くことができます。
私たちはプログラミングの質問や、ゲームやアプリケーション
の投稿を歓迎します。
もちろん、他のカテゴリで、あなたは英語で話すことができま
す。
を楽しんでください。(^_^)

ありがとうございました!

東京2016
Page 37 of 40
#arduboy:

@fdd776 @incoranger @ mithykyl

@astro_andre @JuiceLizard @darkam_

Figurine Fun with Arduboy!


This month’s inspiration comes from visiting the “The Art of the
Brick” installation. Loved the seeing modern art recreated with
Legos, so here are some of the #arduboy with figurines.

Post your photos with Arduboy on


Instagram and Twitter with #arduboy.
We want to feature them in this segment!

Page 38 of 40
Thank you!
Thank you for reading the Magazine!
Hope you enjoyed it as much as we did putting it together.

We want to know how to make Volume 4 better than


the last, so write in to us to tell us what you think!
https://twitter.com/arduboymag

You might also like