Vol. Apr
3
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
W
ES AM G
by @Celinebins So many new games were released this month! If you missed them on the community pages, here they are.
FR ES H
N E
PLAY:
That will get you hooked
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 We’re digging the custom tee! So highest score wins one? :p
Made at the Arduboy Workshop in Medway, guide Boris down the slopes 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 rack
a
hat
@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 anything else you want the community to know!
Page 6 of 40
Creating this month’s
Featu re
ame G d
1010 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 an Arduboy for Christmas 2016. As well as the Arduboy, he wrote a game for it specifically for her. 1010 - described as “2-dimensional Tetris” - was one of her favorite games during the months leading up to Christmas, so seemed like a perfect game to have on the Arduboy for her. It took a couple of weeks to write and get working properly. The features unique to the Arduboy are using the right arrow key to shift from piece selection to piece placement, and the green and red LED’s to show whether or not the piece fits in it’s current position.
How to play: Moving mode Once you’ve selected a shape, the arrow keys will move it around on the board. The A button will drop it in that position and switch back to selection mode. The LED color indicates if the shape will fit where it is: green for yes or go ahead and place, red for no. Selection mode You start the game in selection mode, choosing from up to three shapes. The current shape is show on the left side of the screen. Each available shape is indicated by a - to the left of the displayed shape, with the current shape being a +. 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.
You can find the general version in the various Arduboy game repositories, and the source (including customized version for his family) are available in the fossil repository here. So, what does his mother think about her gift? She still plays 1010 on Arduboy, prefering the placement methods better than the desktop and mobile versions. More accurately, she thinks the arduboy is “really neat”, not only because she can fit it in her pocket, but especially that it survived her putting it through the washer.
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 moving mode. If the shape will not fit on the current board, the LED goes off and you are left in selection mode. Pause At any time, you can hit the B button and pause the game. This opens the menu so you can start a new game if you want. Game Over If it ever becomes impossible to place any of the available pieces, the game ends. Donwload & Play again here! Page 7 of 40
This month we chat with founder of Arduboy, Kevin Bates to find out more about his journey and story behind Arduboy. How did the idea for Arduboy come about? At the time I was working in a really boring job, and I hated telling people about what I did for money. It was a database administrator for a shipping logistics company, and I know everyone has their role but I wasn’t happy there. I wanted to tell people about my arduino projects I was making! A LED music visualizer or a servo controlled camera rig for taking panoramic photos. The problem is these kinds of projects are difficult to describe to someone who isn’t a hobbyist, and nearly impossible to bring with you to social events. At the time business cards were getting a lot of press because there were a stories coming out here and there about them being obsolete. But every once and a while you would see a cool business card idea show up and get some exposure so people could continue to talk about this decreasing phenomenon of exchanging business cards in the digital age. Other people had made digital business cards before out of circuit boards, so I thought I would try to make one myself. This was actually nothing that new, I wanted to make something with a few LEDs and could maybe play a game of Simon Says. At the time I was making it, I was also building a digital controller for a home made solder reflow oven converted from a toaster oven that used an OLED display.
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 2 weeks of circuit board design when I realized I was on to something big, but I didn’t yet know what. I knew I needed controls if there was to be a display, and figured that a directional pad, an OK button and a Cancel button would give me all the features I needed to control a menu, or play a simple game. Pretty soon it started to look like a familiar handheld device. I ordered the circuit boards, assembled them, made a youtube video like I did for all my other projects, and the rest is history! How have you found the whole process of manufacturing and all that for Arduboy? It’s exhausting and nearly impossible for one person to do! I’ve had a lot of help, and the open source community that has formed around the Arduboy is really what has been most incredible through the process. You just have to research a lot, have a constant unquenchable thirst for knowledge and wanting to know why something is the way it is. Directly, I mean you have to be curious and personally interested in manufacturing technologies and how factories work in order to get it right. The more you understand what happens in the factory, the better you can design the product. How did you start with the process of manufacturing close to 10,000 units? I had a ton of support already because I had been chose to participate in the HAX accelerator which gave us access to mentors and factory experts. This made 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 would otherwise be known as pounding the pavement. You have to network and create relationships with factories. Sending emails, making phone calls and going to events to meet people took 2 to 3 months of full time work before I was able to select a manufacturing partner. How many Devkits were made, and how did that help with the creation of Arduboy? Well we manufactured 400 in total, but we did it in stages and that actually helped us learn a lot before building the final kickstarter. We produced 100 units for sale on Tindie before the kickstarter campaign. But in reality we actually produced 200 units... 100 from two separate factories. Why do this? Well it helps us figure out which factory is better, but it’s actually more important than that. Because you have 2 experiences, you can get an idea of how things might be different if you went with still another factory. It’s less about the specific problems you have, or differences in costs, but the general types of problems you are going to experience. For example, we told one factory to use liquid adhesive to hold the screens down and another factory no instruction. The factory that used the glue, had problems finding the right kind of glue, and then when it was applied caused problems with fingerprints. The second factory without instruction used a double sided tape that was awesome. So not only did we learn that tape is the way forward, we also learned that for some things it’s better to just let the factory figure out what is best. When was the forum page created, and how has that been a pivotal role for growing the Arduboy community? The forum was created the same time we shipped the developer kits. I can’t
stress this enough but putting up the forum has been the single best decision the company has made. I was skeptical in the beginning but the number of high quality people who turn up to share their experiences is nothing but mind boggling to me. I’ve spent a lot of time on the Internet and I’m proud to confidently say we have one of the best if not the very best communities on the internet. There would be no Arduboy if it wasn’t for the forum, but really it represents all the contributions of all of it’s members. So thank you! I’m sure you had to overcome those difficulties producing Arduboy, what was your favorite thing about the Kickstarter campaign? By far and above, and I cannot stress it enough, the positive feedback and experiences I hear about from people. Arduboy didn’t exist before, and now there are all these people who maybe just have a little fun with it. But there are also people who somehow, it has transformed their lives. Some people have got job offers as a result of making games, others have learned to code and may have not learned otherwise. So that is amazing, there is potentially thousands of people with new experiences all because of this little thing. It makes it all worthwhile, and I hope there is a lot more to come. You appeared to be traveling all the time promoting Arduboy. What your favorite place to visit, and why? This is an incredibly difficult question because at first I think about all of the amazing people I’ve been lucky to meet in each place and I don’t want to single any one out! If I had to pick one I probably should say Japan because it was so unique and different from where I grew up, but at the same time I had always heard about and been exposed to some elements of Japanese culture. The stereotype of hospitality and politeness was not unfounded and blew me away, to be continued next page >> Page 9 of 40
I ate lots tasty Tonkatsu and Gyoza and was lucky to see a bunch of temples and I can’t forget Akihabara.
China is amazing and taught me so much about life and myself it’s difficult to explain. People ask me about my time in China and there is just no way to put it into words, or maybe it would take a whole book. But for me the language and culture barriers coupled with the restricted internet left me feeling home sick almost immediately entering the country. Luckily Hong Kong was only a bus ride away from where I lived in China, and that’s one of the most densely populated cities in the world. Incredibly international and I felt like I was living in the matrix or an anime. The Kickstarter saw colored units and goldbacks, but only white units are being produced now. Would we see anything like that again soon? There are no real solid plans for color versions or special backs, but I do want to do a black version at some point with anodized black back. I also think it would be really cool to try doing a translucent smoked black front cover, that the OLED could shine through... but we would need to buy a lot of that kind of plastic to do so. We saw that the Kickstarter units were serialised, and it looks like we got the first unit? (1 of 10,000) Everyone is number one! This is kind of a funny story, and people ask me about it pretty frequently. I originally wanted to
serialize the units and the factory said they could support this, so I went ahead 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 remake the back or send them a different number? What if someone gets the wrong number? But at the same time, I thought the units would be more special knowing how many others were made in the batch. So it’s an edition printing, not a serial number. It’s also kind of a prank to pull on people when they get so excited. I hope nobody is upset by it! Any advice for someone who is thinking of launching a crowdfunding campaign? If someone is really serious about it my suggestion is you spend several hours talking to someone who has done it before and can walk you through the process. It’s just too big and too huge to try and do on your own. I had a lot of help behind the scenes, and having gone to HAX we had good connections to people at Kickstarter and the media to help get things rolling. But there are some basic things that you need to have before getting started that I can easily list out. First, get all your social media going, Facebook, Twitter, Youtube, Instagram, Snapchat, and anything else I’m forgetting, you’ll want to sign up an account with your business and start giving people a reason to follow these accounts. Start building a community and getting people excited about what you are doing. The goal here is to have people who are going to buy the product the second you to be continued next page >> Page 10 of 40
launch and also help share it with their networks. Second is to start paying attention to the media and blogs you would want to see your campaign posted in. Figure out the names of individual writers that cover stories like yours. Once you have 2 or 3 major blogs identified, email or contact those writers and in one or two sentences explain what you are doing and link to your website. Bloggers have very little time to read a story, and get overloaded with press releases, so stand out by being authentic and real. Most of the emails they get aren’t from the project creators, but don’t talk their ear off, let them get interested on their own. Finally, and probably most important is to get your ducks in a row. You might not realize it but you are starting a business, a company. Get that setup, at least set up an LLC because that way you don’t have to pay personal income taxes. Figure out how much shipping is going to cost, and pad it because actual costs are almost always going to be higher than what you predict. You should have a very specific plan of how you will spend every dollar you are going to get. Plan what happens if you are over-funded. This was my biggest issue, I was not immediately ready to produce 12 times as much as was originally planned. In summary, I think the best thing you can do is get together with other people who have done it before. Why not make them part of your team? Oh and make sure you sign agreements with your co-founders to avoid conflicts in the future! Have you backed any Kickstarter campaigns yourself? I backed the Pebble Time and the Time 2, and actually got to meet their founder, sad to see them get gobbled up and canned by Fitbit.
I also helped fund the Voltera Circuit Board Printer but didn’t pony up to actually buy the device because I wanted to see the technology work before going all in. But it’s been a few years now and they’ve got great reviews. I make a lot of prototypes so it would save a lot of time! But in general, I advise people to be extra critical of hardware crowd funding campaigns. There are a lot of campaigns out there that are extremely exciting, but if you look at them from a technical or business perspective are doomed for failure. But it’s a narrow line for sure, products like the Arduboy probably would not exist if it wasn’t for Kickstarter so you need to evaluate every projects risks and rewards yourself. What is keeping you busy right now? We just finally finished shipping every last Pre-Order we have had! That is a big milestone. In one way or another I’ve been working on this project for almost 3 years and now everyone finally will have an Arduboy if they wanted one! Now I spend most of my time trying to figure out what comes next, I get asked that question a lot so I’m trying to come up with a good answer. Mostly just trying to figure out how I can support the community the best! Is there anything you would like to tell the Arduboy community? Thank you, thank you, thank you! The Arduboy community is amazing and is always coming up with creative new games and technical improvements to the code. Every day I see the Arduboy do new things I never thought possible like 3d with shading, gray scale, or procedural content generation. But I also see it changing peoples lives occasionally and that makes me extremely proud to help support things like that. Thank you everyone! 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
#1
“Simplicity is good because it means there’s no 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 will always be limited by hardware restrictions.” -@Pharap
55%
#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
Amount
40% of
#3
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 6%
story
6%
#86%Ability 3% 7%
#7
14% 18%
25%
to
Sound
line
load
saved
games
Effects
Effective sound can elevate a solid game to something even more fun and entertaining. Find out how to use Tunes and Tones on page 28!
of classic games #6 clones “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.
s k c i r T Tips &
by TEAM A.R.G
#3 - Keeping the “main loop” clean
by @jo3ri
In our previous article, we explained #define and why we use those and also about the naming of variables, functions and defines. This time let’s have look at “if else”, “switch cases” or “function pointers”. We will do this, while showing you how to keep the “main loop” as clean/empty as possible.
When you start coding, you probably just start putting code in the main loop and so the main loop grows and grows with code. In our first article we explained how to use multiple files. Well this will become very useful, once we simplify that “main loop”. 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; // arduboy.pollButtons(); // arduboy.clear(); // arduboy.display(); // } This will show the Arduboy logo, clear the screen and do nothing more. Now, before we continue, it is best to understand that a game, like a book, has at least 3 parts:
wait for the next frame (60/s) check button input clear the screen update the display a beginning, a middle and an ending. Probably a lot more, but for our example we’ll stick to these 3. to be continued next page >> Page 14 of 40
To help ourselves we are going to create a variable to keep track of what part we are currently executing code. Remember the #define explanation in the previous issue? #define STATE_GAME_INTRO #define STATE_GAME_PLAY #define STATE_GAME_OVER
We are going to name our parts too. Add the next part in your code, before: Arduboy2Base arduboy;
0 1 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” statements, by checking our gameState
variable. We’ll only show the loop to keep 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();
Now if we try out our little “game”, you will notice something is wrong. It is like the game just loops through all “if” statements and doesn’t stop, once we pressed a button, although we used justPressed. The reason? Well, if we only use “if” statements, our code will check the first “if” and if
// update the display
you press the button, it will immediately check the next “if”. But because there hasn’t been enough time passed, the button still seems to be pressed and so our gameState changes again and once more with the third “if” statement. to be continued next page >> Page 15 of 40
If you change the button to “B” in the second “if” statement, you’ll notice that the problem is solved. But this isn’t the solution we are looking for. We want to be able to use the same button for all actions. Here is where we need “if” and “else if”. This will make the code execute only one of the successive “if” statements. So add “else” in front of the second and third “if”. You can read more about it on the Arduino Reference Page. Remember the
difference between only “if” and “else if”. You can use this for example, when you want a sprite to walk only in 4 directions and in not 8 (diagonal). Once we have more than 3 “else if” statements, it might be better to have a look at switch cases. Again the Arduino Reference Page is a good starting point. Well, now that we know, we can replace “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 look, doesn’t it :) It’s time to re-read our first article on multiple tabs/files. In our example, each function isn’t very big, but you can imagine they will grow fast when adding game play. You probably add more cases in your switch case, holding different parts of the game, like: NEXT_ LEVEL, PAUSE, ... putting each function in a different .h file will help you to keep the overview.
Now that our game has been split out over different functions, it’s time to talk about functions by pointers in an array indexed by gameState, our last step in the process of getting a clean easy readable loop. Nope, there isn’t an Arduino reference page on this one; I’ll do my best to explain myself.
to be continued next page >> Page 17 of 40
It is possible to put our 3 game functions (or more) in an array in PROGMEM. Well, not the functions themselves, but a reference to them, a “pointer”. All we need to do is make a sequential list
of those functions (and you can add a function multiple times if needed) and create another function to read out the correct one. First let’s create the “list” and 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 ! If you managed to move all functions into different files and added a globals.h, like we explained in the first Tips & tricks, you’ll have a very clean, readable, setup and loop. As a reference, I have put the end result on github: https://github.com/JO3RI/ tips-tricks-3-example
You probably noticed your code is a bit bigger than when you had the switch case. This is one of the things you’ll have to consider yourself, but just so you know. There is lot of other places to regain those few lost bytes. If you have any questions about this 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.
SQ
U EEZ
ER
by JO3RI
#2 - Combining multiple booleans
by @jo3ri
In this issue let’s see how you can reduce size when combining multiple booleans into a byte, or even multiple bytes into 1 byte. First you need to understand the difference of bits and bytes. Now that you’re into coding, you should know that on an 8-bit system, you have 8 bits in 1 byte. If you look at this in Binary, you’ll “see” the bits. 0B11111111 equals to 255 in Decimals and 0xFF in Hexadecimals. Keep this in mind, because it will always help you, when working in bits. If you create a boolean and compile your code, the boolean will take the place of 1 byte, although 1 bit would suffice. The compiler can’t combine those booleans into 1 byte itself, so we have to do this on our own. Of course you might think, what is the gain in having 1 byte instead of 8 bytes ? Let’s assume you have a game with 256 levels and each level has for example 8 items. To keep track of those 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.
But even combining different booleans for keeping track of enemy statuses, like “alive”, “visible”, “dying”, “invincible”, “jumping” … could become byte saving, when you have a certain amount of enemies. Another place where this could become useful for is with tiles and maps. If you have a map using different tiles and you only use 16 (or less) different tiles, you could use “half” a byte to store map data. Look at a byte in hexadecimals and you’ll understand. In 0xFF, you have a “right” F and a “left” F (upper and lower), this means you can use both for storing a number from 0-15 and so combine 2 half bytes into one. If want this more explained have a look at the technical page of our game Virus LQP-79. There we combined 2 map parts in 1 byte, but it comes down to the same thing. Enough about the talking, here are some examples in the next page.
to be continued next page >> Page 19 of 40
byte chestsOne = 0B00010000; //|||||||└------> 0 chest //||||||└-------> 1 chest //|||||└--------> 2 chest //||||└---------> 3 chest //|||└----------> 4 chest //||└-----------> 5 chest //|└------------> 6 chest //└-------------> 7 chest
(0 (0 (0 (0 (0 (0 (0 (0
= = = = = = = =
false false false false false false false false
/ / / / / / / /
1 1 1 1 1 1 1 1
= = = = = = = =
true) true) true) true) true) true) true) true)
byte chestsTwo = 0B00000010; //|||||||└------> 0 chest 8 has been opened (0 //||||||└-------> 1 chest 9 has been opened (0 //|||||└--------> 2 chest 10 has been opened (0 //||||└---------> 3 chest 11 has been opened (0 //|||└----------> 4 chest 12 has been opened (0 //||└-----------> 5 chest 13 has been opened (0 //|└------------> 6 chest 14 has been opened (0 //└-------------> 7 chest 15 has been opened (0
= = = = = = = =
false false false false false false false false
/ / / / / / / /
1 1 1 1 1 1 1 1
= = = = = = = =
true) true) true) true) true) true) true) true)
In this example we used 2 bytes to keep track of 16 chets. As you can see chests 4 and 9 have been opened. Now let’s close those chests and open chests 6, 12, 15 . To do this we need toggle to the correct “flag”. We always read bytes from left (low) to right (high). Read all about bit math on the Arduino reference page, bitClear(chestsOne, 4); bitClear(chestsTwo, 1); bitSet(chestsOne, 6); bitSet(chestsTwo, 4); bitSet(chestsTwo, 7);
0 1 2 3 4 5 6 7
has has has has has has has has
been been been been been been been been
opened opened opened opened opened opened opened opened
so you have a better understanding of how it works. (Even I still use it every time I code). There are 2 ways of toggling the “flags” (bits). We can use bitSet (set flag to true) and bitClear (set flag to false), read about bitRead (read the flag) and the other commands on this Arduino reference page. Or by using bit math (see the previous link).
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! Let’s see how to do that on the next page.
to be continued 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 size of the array is limited to the size of RAM you have available. Here the size is
2 bytes( for 16 chets). Now let’s open en close the same chests as in the previous 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, changing the state of the chests at the beginning isn’t any shorter. Here we can show you how bit toggling can be used.
Because this is an 8-bit system, we can toggle 8 bits in 1 cycle and less cycles means increasing speed. We have to set 2 bytes in total:
allChests[0] ^= 0B01010000; allChests[1] ^= 0B10010010; Doing this means we toggled bits, bits that were on, will be off and visa versa. I know this isn’t easy to understand by just looking at it, but like I said before, I find the reference page for bit math by Arduino very helpful. Just take a pencil and some paper and write out the bytes in Binary with the mask under it, so you can write down the result. In our chests example, you might not find it useful to set 8 bits at the same time, but if you have 8 characteristic flags in a byte for enemies, you’ll find it very helpful to be able to set those all at once.
One final thing I want to show you is bit shifting, again Arduino has a very good webpage on this. shifting bits does exactly what it says. It moves bits in a byte left or right. The bits get lost if they fall out of the byte, which is an advantage we can use. Remember I started with asking you having to remember HEX notation of a byte (0xFF) ? Well let’s assume you have to store 4 numbers with a max of 16 into 1 byte, for example 9 and 4, in BIN those are 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 as 0x94. Recognize those numbers ? Getting out the numbers again is nothing byte firstByte = halfBytes & 0b00001111; bits byte SecondByte = halfBytes >> 4; right and copy
more than using a mask to get out the right part and bitshift the left part, like this: // only copy over the 4 most right // move the 4 most left bits to the
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 new library, Arduboy 2 (update available through Arduino IDE library manager), it’s time to explain how to use the sprite functions.
To really understand how it all works, we’ll start with explaining how the graphics actually work. As you know by now the screen size is 128x64 pixels. Also good to 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 can’t set half bytes.
to be continued next page >> Page 23 of 40
Even if you create an image of let’s say 12 pixels height, the actual bits used will be 16 and not 12. Never EVER forget this. Because point (x: 0, y: 0) on the screen is
the upper left corner, it’s best to always add empty rows at the bottom of your image/tile/sprite, until you reach a multiple of 8.
The second thing to keep in mind is: the way you create your pixel art should always use 100% black, 100% white and 100% transparent pixels for tiles and sprites.
An image can be just black & white. In the example above we set the transparent pixels to pink to make it clear. Even if you’re not going to use masks, use transparent pixels as your “background color”.
Third important thing is: naming. Give your graphics a name, but don’t use numbers — with one exception in a moment — or special characters. Converters don’t like them. Then postfix the name with an underscore and the dimensions of the asset. For an image, it’s the total width and height. For the tiles it’s the width and height of one tile (note that tiles should to be square). And for sprites, we use the dimensions of one sprite. Remember for every case, height must still be a multiple of 8.
And finally don’t forget to arrange your tiles and sprites vertically in one column. Now we know how we have to name and create our images. Time to convert them into code. For each type we use a different converter. You probably can find other converters on the internet, but we will show you how to use the online converters TEAM a.r.g. created. All these are based on Josh Goebel’s work, you can find on his github repository img2ard.
to be continued next page >> Page 24 of 40
Converting Images: For an image use Team a.r.g’s Image converter. An image is a picture in one piece shown on the screen. For a tile sheet use Team a.r.g’s tile converter. A tile sheet is a collection of smaller square images vertically arranged into one column as one big image. And finally for a sprite sheet use Team a.r.g’s sprite sheet converter. A sprite sheet is a collection of smaller images, each representing a frame of an animated image, vertically arranged into one column as one big image.
Each of these converters will give you an array of bytes. The image converter will only give you one array, including the size of the entire image. But it will also show you the image as it will be displayed on the screen. (You could look for pixels that might have changed, because the source image didn’t have 100% black/white pixels). This array is compatible with the drawSelfMasked function to display the image on screen. (If you want to use drawBitmap, you’ll have to comment the dimensions in the array).
sprites.drawSelfMasked(x, y, imageName, frameNumber); Arguments: x, y: coordinates on screen to draw image. imageName: name of the array in code. 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)
Don’t forget to initialize the Sprites object — after the line “Arduboy2Base arduboy;” — by writing:
Sprites sprites; The tile converter will also give you just one array, including the size of one tile (not the entire tilesheet). You will also see you’re tilesheet with every tile nicely ordered in rows and columns, for you to check if it was divided correctly. This array is perfect for use with the sprite function.
And this is the function you will normally use for tiles. Remember, tiles are used for background and normally will never need masking.
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 pixels, well now we need to create a
function that will draw this map, according 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 to compress them for the Arduboy, check out the technical pages for Mystic Balloon, Virus LQP-79, and Dungeons on the TEAM a.r.g. website. The sprite converter will give you not one but three arrays. In all three arrays the size of one sprite will be included. Again you’ll see an image, but this time it will be the sprite looping through all of its frames. Now depending on what you’re going to do with the sprite, you can use a different function.
If you don’t care about your sprite being “look through” (meaning you’ll see anything else behind the sprite too), you can use the drawSelfMasked function and use the “sprite” array. If you don’t want this behaviour, you’ll need a masked sprite which doubles the amount of bytes used by the sprite. Use the drawPlusMask function and use the “Sprite + Mask” array. If you only want a small mask behind your sprite, you can use the drawErase 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: drawOverwrite and drawExternalMask. The former works similarly to drawErase.
I won’t go into detail on the specifics, give them a try if you’re curious.
drawOverwrite(x, y, mask, frameNumber); The latter is different. It takes two separate arrays to draw a masked sprite, whereas drawPlusSelf only uses one array to do this. Using two arrays gives the developer a chance to use a mask created separately from the original sprite. For example if you want to mask only a part of your sprite. There is one thing you should remember though; the mask you’ll be using doesn’t need the first two bytes in its array to be
the dimensions because it uses the same values from the sprite, so you’ll have to comment out those numbers yourself. This means that the dimensions of your special mask have to be exactly the same as the dimensions of the sprite you use. drawExternalMask also allows using a different frame number for the mask than what is used for the sprite.
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 by crait
tips
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 a lot of stuff... I hate that I did that, but it’s really important to take away these three things from that article: 1) Work on games that you will finish so that you don’t have an excuse to give up. 2) A game’s theme can be removed from a game and it should still be fun. 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. One big debate is over which comes first in the design process. Personally, I think a good theme can come first or a good mechanic can come first. If the theme comes first, you just have to come up with some good mechanics that fit the theme. If the mechanics come first, you have to think of a good theme to have as a metaphor for the mechanics. I will show you an example of both of these! When coming up with a new game idea, I try to think about cool or interesting things that happened in my life. Sometimes, I purposely try to remember very vague situations I was in be that gives me more blank spaces to fill with my own creativity. I will take those experiences and try to turn them into a digital game.
One thing I loved doing as a kid was catching lizards. Where I lived, they were all over the place in the summer. I would try to find them behind bushes or climbing on people’s houses. In fact, I would even tresspass in order to find and catch them. I remember having a lot of fun doing this... Anytime I got close to one, it would run along the wall really fast and I’d have to chase it, trying to cup my hand over it so it can’t leave.
Let’s say I wanted to make a game with this as my inspiration... I already have the theme of catching lizards... I just need the mechanics... I could make a game where you run around into people’s yards and have a real hard time catching lizards, while avoiding being caught by the owner of the house. This would offer some challenge and could be done in 2D or 3D. There could even be a sneaking mechanic to make sure the lizards don’t run away so quickly. Okay, that sounds like a good start for a game, but let’s think about this experience in the opposite order. Let’s take the mechanics from catching the lizards, and give it another theme.
to be continued next page >> Page 28 of 40
It could be anything- I always start with something completely unrelalted. Instead of a game where you’re trying to trap lizards climbing on a wall, I could swap lizards out for... hmmm.... Let’s say evil robots that try to drill into the wall. And instead of them climbing on the wall of a neighbor’s house, maybe they’re climbing on the walls of banks and I’m a security guard trying to protect the money inside!
It’s kinda like the mixing method I mentioned in the first article. Come up with something that no one would ever think to mix a racing game with and play around with that idea. What about mixing in lumberjacks? What about mixing dentistry? Yeah, I don’t think I have ever heard of a game about racing and brushing your teeth. Maybe your car is a tooth brush and 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 up with game ideas because the games I tend to come up with really mean a lot 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.
I don’t know what I’ll write in next month’s article, but be sure to take a read when it comes out.
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 systems. Arduboy and Arduino When I got my Arduboy, I immediately set my computer with the Arduino Integrated Development Environment (IDE). But what is Arduino? Arduino is an open sourced computer hardware and software tool for building digital devices and interactive objects. For example, you could buy some sensors and LEDS and make an alarm that goes off when your pet leaves the house. As for the Arduboy, the board is already hooked up with sensors that detect input (buttons!) and display output (screen and speakers!), so no additional “hacking” is required to start. Next question, what is an IDE? The IDE is a platform for software development, storing libraries that make writing and debugging code more convenient. It is also where 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.
Arduino Leonardo
Image taken from Robotshop
Notes on working with the IDE: If you download a game file (let’s say it’s ABC game) from Github, sometimes it saves as ABC-master.zip. If you try to open and run the ABC.ino, it might report back with an error saying that the game file needs to be saved in a folder with the same name. If you delete the extra “-master” from the folder you should be able to solve that problem. Understanding C Even though C++ is exactly English, there are some terms used that help make sense of code, and the different color codes also help identify what will be read from the code (e.g: grayed out comments will not be). Following crait’s eight tutorials is a great start, as you get to practice with running some sketches on your Arduboy.
to be continued next page >> Page 30 of 40
Using & Making Images The best way for me to make images for the Arduboy is to use Windows Paint. If I wanted to trace an image I like, I save it, open it on Paint, resize it accordingly and trace it over with the pencil tool. Once done, it gets saved as a PNG file. When I was trying to make graphics using the ToChars tool, I g ot some errors when uploading a 71x71 pixel PNG file. That’s because the pixels need to be in multiples of 8! Hence it being called 8-bit. New Functions Do.. while If you want to display your own name after the Arduboy drop down logo, and only continue after you pressed the ‘A’ button, you can write: do{ } while( !arduboy.pressed(A_BUTTON) ); This function will make your code block (in this case your name displayed on screen) run until its condition is false. In this case our condition is the ‘A’ button, and will run only when the ‘A’ button is pressed (an exclamation mark means ‘not’). Once the condition is false it will exit the loop and move on to the next line of code.
Case After not having success with my if functions to get the backbone of my text game going, I posted it on the forum asking for help, and JO3RI replied with using the Case function. It provides a convenient alternative to the if when dealing with a multiple way branch. switch (gameProgress) { case GAME_INTRO: arduboy.println(“Press A to start!”); if (arduboy.justPressed(A_BUTTON)) gameProgress = GAME_START; break; case GAME_START: arduboy.println(“A: Player 1”); arduboy.println(“B: Player 2”); if (arduboy.justPressed(A_BUTTON)) gameProgress = PLAYER_ONE_WINS; else if (arduboy.justPressed(B_ BUTTON)) gameProgress = PLAYER_TWO_ WINS; break; case PLAYER_ONE_WINS: arduboy.print(“You Win!”); if (arduboy.justPressed(A_BUTTON | B_BUTTON)) gameProgress = GAME_ INTRO; break; case PLAYER_TWO_WINS: arduboy.print(“You Lose!”); if (arduboy.justPressed(A_BUTTON | 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 when using the standard Arduboy2 library, you need to pick a compatible sound library, include it in your sketch, and then use the particular functions that it provides to produce sound. There are a number of sound libraries that can be used with the Arduboy, including: -
ArduboyTones ArduboyPlaytune ArdVoice ATMlib
You can even just use the Arduino tone() function, but thereâ&#x20AC;&#x2122;s really no need since the ArduboyTones library can do the same thing (and more) and produces less code. Which library you choose depends on what features you want and the amount of program memory that you can afford to have it use. The ArduboyTones library is generally the simplest to use and produces the smallest code. ArduboyPlaytune provides the same features that were available in the original Arduboy library. ArdVoice is intended to produce crude speech. ATMlib (Arduboy Tracker Music library) plays sophisticated multichannel ChipTune type music and effects. To play sounds, you will need to include and set up the ArduboyPlaytune library and use the playScore() function.
To use this with the Arduboy2 library, you would include it after Arduoby2.h: #include <Arduboy2.h> #include <ArduboyPlaytune.h> and create an object for it after the Arduboy2 object: Arduboy2 arduboy; ArduboyPlaytune tunes(arduboy.audio. enabled); You then need to initialise the library in your setup() function: // audio setup tunes.initChannel(PIN_SPEAKER_1); #ifndef AB_DEVKIT // if not a DevKit tunes.initChannel(PIN_SPEAKER_2); #else // if itâ&#x20AC;&#x2122;s a DevKit tunes.initChannel(PIN_SPEAKER_1); // use the same pin for both channels tunes.toneMutesScore(true); // mute the score when a tone is sounding #endif The PlayTune example sketch included in the Arduboy2 library is an example of using ArduboyPlaytune. File > Examples > Arduboy2 > PlayTune
to be continued next page >> Page 32 of 40
If you’re writing a new sketch, you may find that using ArduboyTones is sufficient and simpler. To do this you need to include it after Arduboy2.h: #include <Arduboy2.h> #include <ArduboyTones.h> and create an object for it after the Arduboy2 object: Arduboy2 arduboy; ArduboyTones sound(arduboy.audio. enabled); You then use the sound.tone() or sound. tones() functions to play your sounds. The latest version of Flappy Ball1 is a good example of using ArduboyTones. NOTE: ArduboyTones – uses this code format: // this is a coin like sound const uint16_t point[] PROGMEM = { NOTE_B5,75, NOTE_E6,225, TONES_END }; while the ArduboyPlaytunes uses this format: // this is a coin like sound const byte PROGMEM point [] = { 0x90,83, 0,75, 0x80, 0x90,88, 0,225, 0x80, 0xf0}; Both are the SAME sound just different ways of doing things. Getting the correct translation of code for the Arduboy logo is what I would like to show next. We have all seen the logo come onto the screen at startup, but we all remember that Original Gameboy startup you can hear it in your head. The sounds that the old games had, that music stay with you still today. Think for a moment of your favorite Nintendo 8-bit game, now focus on the loading screen or that first level, what does your mind hear?
So below are two examples of the Gameboy Startup sound, one is right the other is not. // spot on sound of the old Gameboy start up -- for use with, ArduboyPlaytune const byte PROGMEM bing [] = { 0x90,0x30, 0,107, 0x80, 0x90,0x60, 1,244, 0x80, 0xf0}; // trying to get the same Gameboy sound-- for use with, ArduboyTones (but its not on the money) const uint16_t bing[] PROGMEM = { NOTE_FS1,107, NOTE_C4,500, TONES_ END }; So why can Playtune make a perfect Gameboy Start up sound but Tones can not? Well it comes down to how music really sounds. And what these two libraries are capable of. ArduboyPlaytune ‘s can produce TWO 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 combination of the Two. Its one sound but two notes all the same. Lets call this a PRO for Playtune. CON – this ability for two notes at the same time cause more code space to be used in the name of music. ArduboyTones uses the notes, you can see them in the code “C4”, this gives Tones the ability to be easily read. The down side can be one note played at a time, we lose the simultaneous note ability. BUT the PRO from this is our code is smaller. Now our coin sound is the same in both Libraries because its a series of notes played one at a time, but the Gameboy startup sound can only be heard truly in the ArduboyPlaytune version. Here is my code (Taken from Original 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:
In this section we’ll ask the same 10 questions to a different developer in every new issue.
Questions with game developers 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 Arduboy the first time?
5 . What do you read to learn how to code for Arduboy ?
From my mate @sones who brought one along to a Medway Makers meeting one Saturday.
I already knew how to code in C so read the library documentation.
2. What is the first program/game you created for Arduboy ? Jet Pac - A recreation of the classic ZX Spectrum game.
3. Did you have app/game developer experience before Arduboy ? Yes, I’ve been programming since I was about 12 years old. In my younger years I wrote games for the ZX81 and ZX Spectrum. Some of which got published in the computer magazines of the day. Today I write mainly in C for the Arduino based devices but also use Lua, Python and Javascript.
4. What programs do you use for creating Arduboy apps/games ? Pyxel for sprite creation. TeamARG tools for the HEX conversion. I use Atom with the PlatformIO plug-in for my IDE. Good old pen and paper for everything else.
6 . What app/game do you have currently on your Arduboy ? The current game I am working on.
7. What Arduboy app/program is your favorite ? Circuit Dude by @crait is a great puzzle game. For graphics I love Sirene by TeamARG.
8. What is the next app/program for Arduboy from your hand we can expect ? I’m currently working on an isometric view survival horror game.
9. What app/game would you love to see on the Arduboy ? Rebelstar! Maybe i’ll do it myself one day.
to be continued next page >> Page 36 of 40
10.What is your best tip for other people who want to start creating apps/games for Arduboy ? Just do it! The only thing worse than trying and failing is not trying at all. Get your game idea and just make it. Learn as you go along. Break your idea down into simple sub-components and do those one at a time.
e.g. Space Invaders : Just start by learning how to draw the alien Sprites to the screen. Then make them move left and right. Then add the ability for them to drop down one line when they reach the edges. Then make them drop random bombs, and so on. Break every large problem down into simple sub-problems, get them working then move onto the 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