I really need help [learning to code]! >-<

Creating RPG? It’s cool!

Please try this. You can describe a painting for Arduboy easily :smiley:
https://emutyworks.github.io/BitmapEditor/

Please refer to this as a reference article for developers.
http://community.arduboy.com/t/welcome-new-developers-a-listing-of-development-links-and-articles/1857

1 Like

Have you installed the IDE @Cyndelia?

Yes I have, and I’ve begun fiddling with some of the functions and such so I know what some things do already.

Thanks so much! This has helped me kickstart (lol sorry I love that word) my development! The only thing is, I still need to know how to draw the sprites in, but I’m sure that isn’t to hard, right?

I’ve also got a picture of my first sprite! I can’t decide if I want him to be the player character, or an enemy…

I hope he looks ok; :stuck_out_tongue:

2 Likes

Hello, Please check this! :smiley:
http://community.arduboy.com/t/drawsprite-a-demo-showing-one-function-doing-an-animation/375

1 Like

Thanks! The thing is, how do I get the bitmaps (or sprites) into the sketch?

I did a display test. please try it! :smiley:
…I made a mistake. Not enough one dot

#include “Arduboy.h”

Arduboy arduboy;

PROGMEM const unsigned char f[] =
{
0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

void setup() {
arduboy.start();
arduboy.clearDisplay();
//arduboy.drawBitmap(0, 0, f, 8, 8, WHITE);
arduboy.drawBitmap(0, 0, f, 16, 16, WHITE);
//arduboy.drawBitmap(0, 0, f, 32, 32, WHITE);
//arduboy.drawBitmap(0, 0, f, 64, 64, WHITE);
//arduboy.drawBitmap(0, 0, f, 128, 64, WHITE);
arduboy.display();
}

void loop() {
}

2 Likes

Oohhh, that’s how you do that. Thx so much! this will help a lot!

1 Like

Hey, I’m having trouble with variables. I can’t seem to completely understand how they work. Could you help me out?

Also, how do you convert an integer to a string?

Hey! Looks like you’re jumping into coding the same way that I did. I wrote a post describing the very basics of variables for you. I know it’s a lot of reading, but I made sure to explain them as simple as possible. :slight_smile:





Variables are way to ‘hold’ data for your program. In many languages, certain variables are restricted to what kind of data they can hold. In C/C++, you can store numbers into integers (int), for instance, or letters into characters (char). You can make it hold data, then retrieve it later to manipulate things with. Lemme give you an example.

int firstvalue = 10;
int secondvalue = 20;
int thirdvalue = 30;
firstvalue = 2;
thirdvalue = 52 + 5 - 9;
firstvalue = thirdvalue + secondvalue;
firstvalue = firstvalue + 1;

In the example above, I initiated the variables named firstvalue, secondvalue, and thirdvalue. Initiating variables is pretty much creating them and telling the computer what to store into them. For instance, firstvalue holds the number 10.

If I didn’t want it to be 10, I could assign it another value. Assigning a value means that you are storing new data into it. You can see that I store 2 into firstvalue using the equal sign.

You can also evaluate mathematical values and store those into variables. Notice how I store 52 + 5 - 9 into thirdvalue. If I were to ask the computer how much thirdvalue has, it would tell me 48!

Next, take a look at the next line… In firstvalue, I store the value of thirdvalue plus secondvalue. If I were to ask the computer what the value of firstvalue is, it would tell me 68 since 48 + 20 is 68!

You can even use the same variable when assigning values! Notice the last line uses firstvalue on both the left-hand and right-hand side of the equal sign. This line of code is actually increasing the value of firstvalue by 1. The computer looks at the right-side of the equal sign and figures out what firstvalue + 1 is equal to. After that, it stores it into firstvalue.

Besides just storing data into variables, you can also ask the computer to evaluate them. There are several types of ways to do this, but let me just give you the most basic example… Let’s say that you have a video game that is like Galiga. You might have some code like this:

if( level < 4 ) {
	speed = 1;
}

if( level == 4 ) {
	speed = 3;
}

if( level > 4 ) {
	speed = 5;
}

Whenever code is being run by the computer, it can check the data inside of variables. This code would change the speed of your rocket ship that is stored in the variable called speed by checking which level you are on, which is stored in a variable called level. The way you can do this is by running certain lines of code, depending on the value of variables.

In C/C++, and many other languages, you can use the if statement to check the value of something. If the value is correct, then you run the code, but if it isn’t, then you skip the code. The lines of code that will be run are inside of the { braces } right after the if statement. The value that you are checking to be true or not is inside of of the ( parentheses ).

The first line of code says, if the value inside of level is less than 4, then make speed equal to 1.

That means if you’re on the first few levels, your ship will be moving with a speed of 1.

If you want to see if the player is on level 4, then you need to compare level and 4, you have to use the double-equal sign (==) since the single equal sign is what we use to save a value. Look at the next if statement. It says, if the value of level is equal to 4, then we will set speed to 3.

This means that once you get to level 4, you’ll be moving a bit fast!

Take a look at the last if statement. What do you think that means? if the value inside of level is greater than 4, then make speed equal to 5. This means once you get past level 4, your ship will be moving a lot faster.

3 Likes

Thank you! The thing is, I can’t seem to get the variables to work the way I want them to. I need to convert an integer to a character for an animation, but there doesn’t seem to be a simple or working way for Arduboy. Do you know how I could do that?

1 Like

Because I do not have an Arduboy, I cannot give you a guaranteed answer of how the best way to handle string manipulation… But… A string is a collection of characters, so it can be used to form a sentence and some words and put them onto the screen. Technically speaking, characters are integers. This means that anything you are wanting to do with a character, you can do with an integer. Do you mind telling me why you would need a string to handle animation? Maybe you can do it with integers instead.

What I’m doing is I’m just having the animation on a loop, and to determine which frame of the animation to draw I have set up a variable that changes by one every 3 frames and then resets after a number of frames, and so I just add the frame variable to the name of the animation. But it can’t just convert int to str, so I thought I needed to do that. Any ideas on how to fix it or change it?

Hmmm… It’s hard to visualize what you mean without seeing the code, but if I’m understanding correctly, you definitely would want to use integers for this instead of strings. String manipulation can slow your code down and uses a lot of memory. (Normally, this wouldn’t be too bad, but the Arduboy is very limited.)

I imagine just having a counter variable that checks the frames. Every frame, increase it by 1. If the integer is 3, then set the counter to 0 and increase a frame variable. The code could look something like this…

counter = counter + 1;
if( counter == 3 ) {
	counter = 0;
	frame = frame + 1;
	if( frame > 4 ) {
		frame = 0;
	}
}

the thing is, I don’t know how to make “frame” actually be my frames, I was just using “frame” as a counter.

I’m going to base some code off of @emutyworks’s post and combine it with mine that I just posted.

#include "Arduboy.h"

Arduboy arduboy;

PROGMEM const unsigned char frameone[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

PROGMEM const unsigned char frametwo[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

PROGMEM const unsigned char framethree[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

int counter = 0;
int frame = 0;

void setup() {
	arduboy.start();
	arduboy.clearDisplay();
	arduboy.display();
}

void loop() {
	arduboy.clearDisplay();
	counter = counter + 1;
	if( counter == 3 ) {
		counter = 0;
		frame = frame + 1;
		if( frame == 3 ) {
			frame = 0;
		}
	}
	if(frame == 1) {
		arduboy.drawBitmap(0, 0, frameone, 16, 16, WHITE);
	}
	if(frame == 2) {
		arduboy.drawBitmap(0, 0, frame two, 16, 16, WHITE);
	}
	if(frame == 3) {
		arduboy.drawBitmap(0, 0, framethree, 16, 16, WHITE);
	}
	arduboy.display();
}

NOTE: I do not have an Arduboy to test this on, so I cannot be sure it’s correct.

This code should work this way: The loop will loop around and clear the display, then counter will increase. When it gets to 3, it’ll reset to 0 and increase frame. If frame is ever 3, then it’ll reset to 0, too. The second part of the loop is simple… If frame is 1, then output the first frame. If it’s 2, then output the second frame. If it’s 3, then output the third frame.

1 Like

It sounds like you want to put your frames into an array and then index into the array with your frame number. There’s no need to convert the frame number to a string unless you want to actually display that number on the screen.

http://www.cplusplus.com/doc/tutorial/arrays/

#include <Arduboy.h>

Arduboy arduboy;

PROGMEM const unsigned char animation[][32] =
{
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 },
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 },
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 }
};

int animNum = 0;

void setup() {
  arduboy.begin();
  arduboy.setFrameRate(15); // Set to 15 frames per second
}

void loop() {
  if (!arduboy.nextFrame()) { // if not time for the next frame
    return;
  }
  
  arduboy.clear();
  arduboy.drawBitmap(0, 0, animation[animNum], 16, 16, WHITE);
  arduboy.display();

  if (arduboy.everyXFrames(3)) { // if 3 frames have elapsed
    animNum++;
    if (animNum == 3 ) {
      animNum = 0;
    }
  }
}
1 Like

Thank you so much! I was able to get it done! Now I have a different problem; I have a menu, and I want an “in-game,” but with the “loop” function I can’t put it in my original file, so do I put it in a .cpp? If so, what do I put in the matching .h?

By the way, I’m so sorry for asking for so much, I really just want to understand this new language. Please forgive me.