Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - johnbbq

Pages: 1 2
16
Hi there. Today I have been creating new sprites for our game, and I've been having a hard time finding how I can set up an RGB color. I am not sure what's the right format.

I found this page: http://www.barth-dev.de/online/rgb565-color-picker/ . But if I use their color values (for example 0xFE82), I get a completely different color on screen.

The only colors that work well are the ones defined in the library (TS_16b_Yellow for example).

Can you tell me what format should I enter the color values for each sprite pixel?

Thank you,


17
I was able to create the bullets for the game my son and I are working on. I wanted to share my solution in the thread. Please let me know if this is the right approach or if there is a way to improve it.

The first thing I did is to create an offscreen global variable I can use throughout the game:

int offscreen = -100;

I then created a bulletBitmap, and 5 sprite instances for it:

ts_sprite bullet1 = { offscreen, offscreen, 3, 4, 0, bulletBitmap };
ts_sprite bullet2 = { offscreen, offscreen, 3, 4, 0, bulletBitmap };
ts_sprite bullet3 = { offscreen, offscreen, 3, 4, 0, bulletBitmap };
ts_sprite bullet4 = { offscreen, offscreen, 3, 4, 0, bulletBitmap };
ts_sprite bullet5 = { offscreen, offscreen, 3, 4, 0, bulletBitmap };


I added these sprites to the spriteList array, but I also created a playerBulletList array, pointing to the same references. This way I could use the spriteList array just for the drawBuffer function, and keep a separate array to iterate through when I'm updating bullets:

int amtSprites = 6;
ts_sprite * spriteList[6] = { &player, &bullet1, &bullet2, &bullet3, &bullet4, &bullet5 };
int amtPlayerBullets = 5;
ts_sprite * playerBulletList[5] = { &bullet1, &bullet2, &bullet3, &bullet4, &bullet5 };


I then added two global variables:

int playerBulletIndex = 0;
int playerLastShot = 0;


playerBulletIndex allows the function to go through an index of bullets, and know which of the 5 I used last, and the playerLastShot variable records the last time in millis when a bullet was last shot.

Here is the function (added to loop() to run in every cycle):

void playerBulletsMovement() {
  //Check if button is pressed
  if (checkButton(TAButton1) && millis() > playerLastShot + 400) {
    ts_sprite *cb = playerBulletList[playerBulletIndex];
    cb->x = player.x;
    cb->y = player.y;
    playerBulletIndex += 1;
    if (playerBulletIndex > 4) playerBulletIndex = 0;
    playerLastShot = millis();
  }
 
  //Update all bullets
  for (int playerBulletIndex = 0; playerBulletIndex < amtPlayerBullets; playerBulletIndex++) {
    ts_sprite *cb = playerBulletList[playerBulletIndex];
    if (cb->y != offscreen) {
      cb->y = cb->y -1;
      if (cb->y < 0) cb->y = offscreen; 
    }
  }
}


The first part checks if the player pressed Button1 to fire a shot. But so the player doesn't fire indiscriminately, we only allow the player to fire every .4 of a second. So this part of the function only runs when both of these conditions are met.

if (checkButton(TAButton1) && millis() > playerLastShot + 400)

If the condition is met, the next step is to create a variable in order to access the bullet reference I need:
 
ts_sprite *cb = playerBulletList[playerBulletIndex];

So the first time the player presses Button1, the program requests the first bullet in the playerBulletList.

Right away I set the position of the bullet (currently offscreen) to be where the player is:

cb->x = player.x;
cb->y = player.y;


And then I move the index to the next bullet I can use:

playerBulletIndex += 1;

But I make sure that if the playerBulletIndex goes beyond the size of the array, then I reset the index to the beginning:

if (playerBulletIndex > 4) playerBulletIndex = 0;

Lastly, I store the time in millis since this shot was executed, so it can be compared by this if statement in every loop cycle:

playerLastShot = millis();

The next part of the function runs in every cycle. It is the part of the function that updates the positions of all the bullets. The structure is inspired in how the drawBuffer function works:

 //Update all bullets
  for (int playerBulletIndex = 0; playerBulletIndex < amtPlayerBullets; playerBulletIndex++) {
    ts_sprite *cb = playerBulletList[playerBulletIndex];
    if (cb->y != offscreen) {
      cb->y = cb->y -1;
      if (cb->y < 0) cb->y = offscreen; 
    }
  }

The for loop goes through all the bullets in the playerBulletIndex. The first thing I do is to create a variable to reference one bullet at a time:

ts_sprite *cb = playerBulletList[playerBulletIndex];

Then I check if the bullet is offscreen (because if it is, there is no need to update it):

if (cb->y != offscreen)

I am making a game where bullets fly vertically, from the bottom to the top of the screen:

cb->y = cb->y -1;

And lastly I check if the bullet has left the screen, to move it to the offscreen area and not update it anymore until it's used again:

if (cb->y < 0) cb->y = offscreen;

And that's it! As a last note, the amount of bullets you need may vary depending on how many you effectively can have on the screen at the same time. Be sure to include enough, but not too many as to not waste memory.

Cheers,

18
Hey Hunter, thanks for getting back to me. Makes sense, I'll create an array of bullets and bring them onscreen when I need them.

Cheers,

19
Awesome Hunter, thank you! I'll check this out and I'll let you know how it went.

Cheers,

20
Hi there. One question I have (as I started coding my first game) is: is there a way of creating multiple instances of a sprite? I see that the source code for Tiny Brick and Flappy Birdz they both do not do this. Even though they could use the same bitmaps, the source code specify many instances of the same sprite and they live offscreen until they are needed. But ideally I would like to create the instances on the fly, as I need them (like for example, bullets, or different enemies).

Is this an Arduino limitation? I looked online on how I could push items to an array but it seems that is not possible. Is there a different way?

Thanks.

21
And I'm done! The last part about getting the livesprite was a little bit confusing, as I had a hard time understanding how it works in the Tiny Brick source code. If you guys can expand that part, I think it would be great. However, the tutorial can live off without it as it is understandable that this is the tutorial for the lite version of the game.

This was really fun. Thank you guys. I will now start working on our first game.

Cheers.

22
Hi there! I'm almost done with the tutorial. Another recommendation: In the Splashscreen section, it is not mentioned that start should be a boolean. The if condition did not work for me as an int.

23
Hi again. I just finished the Pointers section. Fun stuff!

One recommendation: where it says "*NOTE: We have effectively used the spriteList[ ] array...", it would be good to have the final spriteList[] array under this paragraph, to make it super clear how it should be in order for the game to work.



24
Another recommendation: In the section about random, please mention the open pins in the TinyArcade (as 0 is cannot be used, and that's what's recommended in the Arduino reference).

25
Tiny Arcade & Pocket Arcade / Re: Truly Random Numbers
« on: July 11, 2018, 01:34:08 AM »
Fantastic Hunter, thank you! I used 8 and the seed worked great.

Cheers,

26
Tiny Arcade & Pocket Arcade / Truly Random Numbers
« on: July 09, 2018, 10:19:22 PM »
Has anyone figured how to create truly random numbers with the TinyArcade?

Per the tutorial (https://tinycircuits.com/blogs/learn/how-to-develop-a-game-for-the-tinyarcade-new), I checked the Arduino reference at https://www.arduino.cc/reference/en/language/functions/random-numbers/randomseed/

But pin 0 seems to be in use by the TinyArcade. The joystick does not work properly. I looked at the TinyArcade manual and it seems all pins are used. Or isn't it?

Any help will be really appreciated. Thanks!

27
Another recommendation: where it says "Adding the following lines to the code will make the ball move around..."

I would say "Adding the following lines to the loop function will make the ball move around".

In the next paragraph you mention that it would be a good idea to create a new function, but since in the previous paragraph you were talking about the TinyArcade.h file, it's disorienting as there is no indication you are talking about going back to the main file.

28
Hello! I'd like to recommend an amendment to:

https://tinycircuits.com/blogs/learn/how-to-develop-a-game-for-the-tinyarcade-new

Since the start of the tutorial, in the screenshots you can see GameTutorialSprites.h as a tab, but there is no explanation that we need to create the file from scratch. It's also confusing because you are instructed to download TinyArcade.h, but no reference to the other file.

So I would explain that GameTutorialSprites.h will be created later, and then in the "The Header File..." section I would start explaining to create a new tab (pointing to the button where that is), and save the file.

I know this info may be obvious for you Arduino devs, but I'm a gamedev who has never done Arduino before.

29
Hello everyone! Thesko and Hunter, thank you for your replies. I'm happy to report that I made it work with your help. Thank you!

Just to make sure I did all the right things, I basically started again with a fresh new install of Arduino. Also, I did not have the build option as "Internal 32KHz Oscillator".

As of yesterday, on my work laptop, even when the settings were correct and based on all the articles I read, the machine was not showing up as a port in Arduino, when it was on and in Bootloader Mode. I'm going to try to see if I can fix the other laptop and post back if I find a solution.

For now, I'm happy that at least we've got the machine back in one of our laptops and start coding.

Thanks again.

30
Unfortunately our time with the TinyArcade was cut short. We put it together and we had fun playing the installed games.

Then we followed these instructions in order to set up Arduino in my son's computer:
https://tinycircuits.com/blogs/learn/158833543-tinyscreen-setup

Board showed up, port showed up fine. We initiated the upload of the TinyScreenExample. Arduino said it was completed. But our TinyArcade shows nothing. In fact, now the TinyArcade doesn't work anymore. On/off/on again, nothing.

The instructions point to another page on the oWatch web site, where it explains how to reset the TinyScreen:
http://theowatch.com/start/troubleshooting/reset-tinyscreen/

But the web page says:
To reset the TinyScreen, power off the TinyScreen using the slide switch. Use a pencil or some other similar object to slide the switch down to the OFF position.

"Then press and hold the button closest to the usb connector while sliding the switch to the ON position. Then try uploading your program and it should work. Repeat this step if it doesn’t. If it still doesn’t resolve the problem please contact us for support."

Excuse me? What button closer to the USB port? Well, we tried both buttons. We held them as we turn the TinyArcade back on. Nothing.

Can anybody recommend us what to do?


Pages: 1 2
SMF spam blocked by CleanTalk