Help With Game Develeopment

Thank you for pointing me to the unit circle! That helped. I think I’d like to go with the more complicated option, as I think the way the game feels and plays will be a big portion of the overall game, as there won’t be much story or anything like that.

I’ll make sure to fix all of things you pointed out as well.

So now that I know how to properly do the gun animation, how can I use that bullet struct @filmote showed me in my gameplay code? As in, how do I initialize the bullet and where do I plop in that segment of code?

Thanks!

1 Like

Well, here I am, couple hours later, asking for help on how to make an array of fixed points. The problem I am having is that in the current config the angle of the gun varies too wildly. When my ‘gunAngle’ variable is changed, since the gun is very small, an increment of just 1 increases the actual angle by maybe 40, so I either need to know how to change the variable by a decimal, or take the time to make the fixed angles.

Here is my current iteration of code;

I tried to make a separate file for the images, by looking at the way other games had done it, and i couldn’t get the IDE to recognize the file, even though the .ino and .h were in the same folder.

As for the justpressed thing, i found that my way of using the variable seemed faster and more reliable than the justPressed function.

Upload the code to your arduboy or emulator or whatever and you will quickly see what I mean about the angle increments.

I need to start spending more time before asking for help. I got it to work XD

Edit: i will just keep the github page up to date whenever i add something new.

@filmote, I have absolutely no idea where to start on launching the bullets. I see the struct in your earlier message, but I’m not sure where to put that or even how to use it. If you could point me to an article or give me some basic instructions on how to initialize said bullet, that would be awesome.

I’ve spent the past 30 minutes looking over 1943’s code, but I can’t find where to start with shooting the bullets. Thanks!

Alright, I went ahead and submitted one last revision for the day. I have a laser which fires (without looking super weird) when the gunAngle variable is at 0, 0.20, and 0.39. Putting in the others is just a matter of time. Thank you for all of your guy’s help on this! I really appreciate it.

I thought it would.
The unit circle is often overlooked when teaching trigonometry,
but I find it illustrates the meaning of sin and cos perfectly.

Firstly it’ll need a semicolon on the end,
and I think both 'delta’s are supposed to be signed:

struct Bullet
{
  uint8_t x;
  uint8_t y
  int8_t xDelta;
  int8_t yDelta;
  bool active;
};

(If you’re definitely going with fixed points, I’d suggest changing the types of x and y to UQ8x8 and xDelta and Delta to SQ7x8.)

You have to put this either at the top of your code, or in a separate header file that you then #include at the top of your code (e.g. #include "Bullet.h").

Then to initialise a bullet you can use value initialisation, e.g:

// Bullet at 32, 32, travelling right and up
Bullet bullet = { 32, 32, 1, -1, true };

You then have to handle the movement yourself by doing bullet.x += bullet.xDelta; and bullet.y += bullet.yDelta;.
You’ll probably want to do collision checks either immediately before, during or immediately after moving the bullets.

The same way you make an array of any type.
Declare with type name[size]; or initialise with type name[] = { values };

For example UQ8x8 values[10]; or UQ8x8 values[] = { 0.5, 1.4, 3.5 };

If you’re using a fixed point type or a floating point type, something like gunAngle += 0.25 will work.

Strange, it should be able to.
Were you using #include <Images.h> instead of #include "Images.h"?

That shouldn’t be the case.
Perhaps you weren’t calling arduboy.pollButtons()?
Or perhaps you were calling it at the top of loop() instead of after the if(!arduboy.nextFrame()) return; line?

The bullet arrays are declared here (EnemyBullet is effectively the same as Bullet).
The player bullets are ‘launched’ here.
Player bullets are moved and rendered here, the same is done for enemy bullets here.
The code for bullet.move is here.
I’m not quite sure where the collision checking is, but @filmote will probably be able to find that when he wakes up.

(In hindsight, separating the player and enemy bullets into two different classes makes no sense other than for conserving RAM.)

Lasers can be done by doing ray-box or ray-circle collisions,
but it’s been a while since I’ve done one of those so I can’t remember offhand how to do it, I’d have to look into it.
(I vaguely remember ray-circle being easier.)


The reason you haven’t had much feedback on this for several hours from either of us is that I’ve been busy sorting other stuff (mainly handling github issues and doing some work on another project) and @filmote’s been asleep since it was nighttime in Australia when you asked (at the time of posting this it’s morning, but only ~9am.)

(Also I only got a notification for your first comment.
People only get notifications for @-mentions, direct replies and having something they said quoted.)

No problem about the waiting thing; my family celebrates Saint Patty’s day anyways so I have been working on this on and off. Once again, thank you so much for helping me with this. It really means a lot to me. :smile:

Awake now!

Small point - the x delta on the strict is unsigned as the bullets travel left to right.

We celebrate ST Paddy’s day in Oz as well. People with no hint of being Irish suddenly adopt accents while slurping pints of Guineas and Kilkenny.

1 Like

I hear that’s the case in quite a lot of places.


Nobody I personally know celebrates St.Patrick’s day, but it always gets mentioned on the news and there probably are a few people who celebrate it here.

(Probably the same people who like going to town late and night and drinking until they vomit on the street corner - i.e. they use it as an excuse.)

In general it’s not particularly popular with the English.


Will the bullets definitely only ever move left to right in this game?

@Pharap, technically, if I add in enough of an arc for the gun to travel, they could could go up --> down or down --> up, but as it is right now, no they do not.

I’m not sure I understand this. I put the bullet struct along with my other variables, but I’m not sure what to do to get it to launch at the press of a button. I’ve tried a few different things, but nothing has worked yet. I will upload the code i have right now to my github page.

Edit: it’s the bullet.x += bullet.xDelta and bullet.y += bullet.yDelta that I don’t know what to do with, i havent gotten to the collision stuff yet :smile:

That’s the bit that actually does the movement.
It should happen once per update.

It’s essentially a representation of the concept of velocity (a combination of speed and direction of travel).

So where how do I implement this code so that a bullet fires when I press a button? I know I need an if statement, and I know each of these segments needs to exist. But where do I put each of the things? sorry for being such a noob :sweat_smile:

To launch a bullet, right underneath your existing up and down buttons add:

if(arduboy.pressed(UP_BUTTON)) {
  if(gunAngle > MIN_GUN_ANGLE)
    gunAngle--;
}
if(arduboy.pressed(DOWN_BUTTON)){
  if(gunAngle < MAX_GUN_ANGLE)
    gunAngle++;
}
if(arduboy.pressed(A_BUTTON)){
  .. launch a bullet.
}

The actual code for launching, needs to do the following:

  • Loop through the existing array of bullets looking for the first inactive one.
  • Work out the X and Y delta values based on the angle of the barrel.
  • Work out the initial X and Y coordinates of the bullet. This might always be the same, ie the base of the barrel never actually moves only the end does.
  • Set Active to true.

To render the bullets:

  • Immediately after you draw the gun barrel and other bits and pieces, loop through the bullet array looking for any active ones. Draw these at the current x and Y positions.

Move the bullets:

At the end of the loop, add the code to update the bullets. Loop through your array of bullets looking for the active ones. For each of these, do the …

bullet.x += bullet.xDelta; 
bullet.y += bullet.yDelta;

You can also test to see if the bullet has gone out of range, for example:

if (bullet.x > WIDTH) bullet.active = false;

Alright, here’s what I’ve got so far. I was mainly trying to just get the bullet moving on the screen before worrying about where it’s going, but I couldn’t even manage that. It took me pretty dang long just to get it to upload.

I think I’ve got the right idea? I think what I’m doing wrong has to do with the array, searching through it and just assigning an array to the class Bullet in general. Just tell me what I’ve done wrong, then I should be able to figure out what to work on next.

Try this code:

//ThaddeusSM
//03/16/18

//Libraries
#include <Arduboy2.h>
#include <FixedPoints.h>
#include <FixedPointsCommon.h>
#define MAX_GUN_ANGLE 1.1
#define MIN_GUN_ANGLE -1.1
#define NUMBER_OF_BULLETS 10

Arduboy2 arduboy;


//Variables
const unsigned char titleScreen[] PROGMEM = { 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x1f, 0xf, 0x8f, 0xc7, 0xc7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf1, 0xf1, 0xf1, 0xe1, 0xc3, 0x87, 0x8f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x8f, 0x87, 0xc3, 0xe1, 0xf1, 0xf1, 0xf1, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xe3, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xc7, 0xc7, 0x8f, 0xf, 0x1f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x3, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x3f, 0x3, 0x3, 0x3, 0x3, 0x3f, 0x3f, 0x3f, 0x3, 0x3, 0x3, 0x3, 0x3f, 0x3f, 0x3f, 0x3, 0x3, 0x3, 0x3, 0x3f, 0x3f, 0x3f, 0x3, 0x3, 0x3, 0x3, 0x3f, 0x3f, 0x3f, 0x3, 0x3, 0x3, 0x3, 0x3f, 0x3f, 0x1f, 0xf, 0x7, 0x3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x80, 0x3, 0x1f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x7, 0x00, 0xe0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xe2, 0xe2, 0x6, 0x6, 0xdc, 0xc0, 0x9e, 0x5e, 0xc0, 0xdc, 0xdc, 0x1c, 0xd0, 0x80, 0x1c, 0xc0, 0x9c, 0x9c, 0x9c, 0x1c, 0x1c, 0x9c, 0x9c, 0x9c, 0xc0, 0xdc, 0xdc, 0xdc, 0x1c, 0xdc, 0xdc, 0xc0, 0xde, 0xde, 0xde, 0xde, 0x6, 0x6, 0xe2, 0xe2, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 0x00, 0x7, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7, 0x00, 0xf0, 0x3c, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1, 0xf7, 0x6, 0x21, 0xc3, 0xe7, 0xc0, 0xb7, 0x77, 0x64, 0xe9, 0xe7, 0xef, 0xcf, 0x00, 0x00, 0xef, 0xef, 0xef, 0xef, 0xe7, 0xf7, 0xf7, 0xf0, 0xf7, 0xf7, 0xf7, 0x7, 0xb7, 0x1, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0xbf, 0xbf, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0x9f, 0x9f, 0x8f, 0x87, 0xc7, 0xe1, 0xe0, 0xfc, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0x7f, 0xbf, 0xbf, 0xbf, 0x7f, 0xff, 0x7f, 0x3f, 0xbf, 0x3f, 0x7f, 0x1, 0xff, 0x7f, 0xbf, 0xbf, 0xbf, 0x7f, 0xff, 0x3f, 0x7f, 0xbf, 0xbf, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x3e, 0xbc, 0xb2, 0xae, 0x80, 0xbe, 0xbe, 0xbe, 0x3c, 0x3c, 0x00, 0x5d, 0x00, 0x00, 0x7d, 0x3d, 0xbd, 0xbc, 0x2, 0xb8, 0xbc, 0x80, 0xbc, 0xbe, 0xbe, 0x3e, 0xa2, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xef, 0xef, 0xef, 0xef, 0x00, 0xff, 0xef, 0x1, 0xef, 0xff, 0xef, 0x1, 0xef, 0xff, 0x7f, 0xbf, 0xbf, 0xbf, 0x7f, 0x3f, 0xff, 0x7f, 0xbf, 0xbf, 0xff, 0x1, 0xff, 0x7f, 0xbf, 0xff, 0xff, 0xfc, 0xe0, 0xe1, 0xc7, 0x87, 0x8f, 0x9f, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xfc, 0xf9, 0xfb, 0xf9, 0xfc, 0xf8, 0xff, 0xfc, 0xfa, 0xfa, 0xfa, 0xfa, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x00, 0x00, 0xf0, 0xf6, 0xf7, 0xf0, 0xf7, 0xf7, 0xf7, 0x7, 0xf7, 0xf7, 0xe7, 0xef, 0x6f, 0x28, 0x43, 0x00, 0x00, 0xcf, 0xcf, 0xcf, 0xef, 0xe0, 0xf7, 0xf7, 0x7, 0xf7, 0xf7, 0xf7, 0xf0, 0xf7, 0xf6, 0xf0, 0x00, 0x00, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xfc, 0xfb, 0xfb, 0xfb, 0xfc, 0xf8, 0xff, 0xfc, 0xfb, 0xfb, 0xff, 0xf8, 0xfe, 0xfd, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xdf, 0xdf, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0x7f, 0xff, 0x3f, 0x9f, 0xdf, 0x9f, 0x3f, 0xff, 0x7f, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x7, 0x3, 0x1, 0x00, 0x00, 0x00, 0x30, 0xb8, 0x3d, 0x9d, 0x9d, 0x81, 0xad, 0xb5, 0x81, 0x38, 0xbd, 0x3d, 0xbc, 0x80, 0xbd, 0xbc, 0xb1, 0xa4, 0x8c, 0x1d, 0xbd, 0xbd, 0x81, 0xbd, 0x3d, 0xbd, 0xbc, 0xbd, 0xbd, 0xbd, 0x81, 0xbd, 0xbd, 0x3d, 0xb8, 0xb0, 0x80, 0x00, 0x00, 0x1, 0x3, 0x7, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xfd, 0xfd, 0xfe, 0x83, 0xf7, 0xfb, 0xf7, 0xff, 0xc7, 0xab, 0xff, 0xa7, 0xab, 0xdb, 0xff, 0xa7, 0xab, 0xdb, 0xff, 0xff, 0xff, 0xff, 0x80, 0xfb, 0xfb, 0xfb, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf7, 0xf7, 0x7, 0xe0, 0xe7, 0x7, 0xf3, 0x3, 0x73, 0x4, 0xf6, 0xf7, 0xf0, 0x7, 0xf7, 0xf7, 0xf7, 0x7, 0xf7, 0xf7, 0x00, 0xf7, 0xe7, 0xe7, 0x7, 0xd0, 0xd7, 0xb7, 0x7, 0x97, 0xd7, 0xb7, 0x7, 0x27, 0xe0, 0x7, 0xf7, 0xf7, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
};
const unsigned char PROGMEM Gameplay1[] =
{
// width, height,
128, 64,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0xff, 0x7f, 0x3e, 0x18, 0x18, 0xf8, 0x1e, 0x1f, 0x3f, 0x7e, 0xf8, 0xf8, 0xf8, 0x3e, 0x1f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x04, 0xfc, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0xfc, 0x04, 0x0f, 0xff, 0xf0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x59, 0xc9, 0x49, 0x49, 0x49, 0x7f, 0x51, 0x51, 0x59, 0xc9, 0x49, 0x49, 0xff, 0xff, 0xa2, 0xa2, 0xff, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x10, 0x1f, 0x10, 0x10, 0x10, 0xf0, 0x10, 0x10, 0x10, 0x1f, 0x10, 0x10, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x04, 0xfc, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0xfc, 0x04, 0x04, 0x04, 0x05, 0x07, 0x07, 0x0e, 0x1c, 0xfc, 0xf8, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x0c, 0x0f, 0x4c, 0x8c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0f, 0x0c, 0x0c, 0x8c, 0x8c, 0x0c, 0x4c, 0x0c, 0x0e, 0x0f, 0x4f, 0x0f, 0x08, 0x08, 0x08, 0x48, 0x48, 0x48, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x48, 0x48, 0x48, 0x48, 0x08, 0x08, 0x08, 0x08, 0x08, 0xc8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xc8, 0x88, 0x48, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x48, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xc8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x88, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 
0x00, 0x00, 0x08, 0x18, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x20, 0x21, 0x60, 0x00, 0x00, 0x04, 0x03, 0x04, 0x04, 0x00, 0x40, 0x20, 0x00, 0x00, 0x0e, 0x08, 0x06, 0x00, 0x22, 0x60, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x60, 0x20, 0x46, 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x40, 0x00, 0x30, 0x0c, 0x40, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x10, 0x20, 0x28, 0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x01, 0x10, 0x50, 0x00, 0x05, 0x04, 0x00, 0x00, 0x1c, 0x30, 0x00, 0x00, 0xe0, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x84, 0x04, 0x04, 0x00, 0x70, 0x00, 0x03, 0x06, 0x00, 0x60, 0x00, 0x09, 0x01, 0x01, 0x01, 0x00, 0x04, 0x01, 0x21, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x20, 0x24, 0x06, 0x00, 
};
const unsigned char PROGMEM Explosion[] =
{
// width, height,
16, 16,
0x00, 0x00, 0x20, 0x00, 0x80, 0x90, 0x00, 0x20, 0x80, 0xe0, 0x10, 0x40, 0x20, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x02, 0x08, 0x02, 0x0b, 0x02, 0x05, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 
};


int gamestate = 0;
const int x1 = 20;
const int y1 = 27;
float gunAngle = 0.0;
const float GAinc = 0.1953125;
int x2;
int y2;
int x3;
int y3;
struct Bullet
{
  uint8_t x;
  uint8_t y;
  uint8_t xDelta;
  int8_t yDelta;
  bool active;
};



Bullet bullets[NUMBER_OF_BULLETS];
//Bullet bullet = {28, 27, 1, -1, false};




//Setup Script
void setup() {
  arduboy.begin();
  arduboy.initRandomSeed();
  arduboy.setFrameRate(60);
  arduboy.clear();
}

//Game Code
void loop() {
  if(!arduboy.nextFrame()) {
    return;
  }
  arduboy.pollButtons();
  arduboy.clear();
  switch(gamestate){
    case 0:
    arduboy.drawBitmap(0, 0, titleScreen, 128, 64, WHITE);
    if(arduboy.justPressed(A_BUTTON)) {
      gamestate = 1;
    }
      break;
    case 1:
    arduboy.drawBitmap(0, 0, Gameplay1, 128, 64, WHITE);
    x2 = x1 + cos(gunAngle) * 8;
    y2 = y1 + sin(gunAngle) * 8;
    x3 = x1 + cos(gunAngle) * 100;
    y3 = y1 + sin(gunAngle) * 100;
    arduboy.drawLine(x1, y1, x2, y2, WHITE);
    if(arduboy.justPressed(A_BUTTON)) {
      gamestate = 0;
    }
    if(arduboy.justPressed(UP_BUTTON)) {
      if(gunAngle > MIN_GUN_ANGLE){
        gunAngle = gunAngle - GAinc;
      }
    }
    if(arduboy.justPressed(DOWN_BUTTON)){
      if(gunAngle < MAX_GUN_ANGLE){
         gunAngle = gunAngle + GAinc;
      } 
    }
    if(arduboy.justPressed(B_BUTTON)) {
      if (gunAngle == 0.390625) {
        x3 = x3 - 46;
        y3 = y3 - 20;
      }
      if (gunAngle == -0.390625){
        x3 = x3 - 46;
        y3 = y3 + 20;
      } 
        arduboy.drawLine(x2, y2, x3, y3, WHITE);
        arduboy.drawBitmap(x3 - 8, y3 - 8, Explosion, 16, 16, WHITE);
     }
     
     if(arduboy.justPressed(RIGHT_BUTTON)) {
arduboy.print("bul");
        for (uint8_t x = 0; x < NUMBER_OF_BULLETS; x++) {

          if (!bullets[x].active) {
arduboy.print("sdf");
            bullets[x].x = 28;
            bullets[x].y = 27;
            bullets[x].xDelta = 1;
            bullets[x].yDelta = -1;
            bullets[x].active = true;
            break;  // We found one so we can leave the loop.
            
          }
          
        }

     }




    // Render the bullets ..

    for (uint8_t x = 0; x < NUMBER_OF_BULLETS; x++) {
    
      if (bullets[x].active) {
      
        arduboy.drawPixel(bullets[x].x, bullets[x].y, WHITE);

      }
      
    }






    // Move the bullets ..

    for (uint8_t x = 0; x < NUMBER_OF_BULLETS; x++) {
    
      if (bullets[x].active) {
      
        bullets[x].x += bullets[x].xDelta; 
        bullets[x].y += bullets[x].yDelta;

        // Out of range ?

        if (bullets[x].x > WIDTH || bullets[x].y < 0 || bullets[x].y > HEIGHT) {

          bullets[x].active = false;
          
        }

      }
      
    }
    arduboy.setCursor(0, 0);
    arduboy.print(gunAngle);

      break;
    }


   
   arduboy.display();
}

Note the array itself. It is an array of bullets whereas you had a bullet (struct) with an array within it.

Thanks! Trying to read through it and see how it all works :smile:

1 Like

Obviously, the ‘angles’ are all wrong as the bullets head off diagonally up the page regardless of where the barrel is pointing.

Thank you so much! That was exactly where I was trying to get to, now I’m gonna work on getting the bullets to move in the proper direction.

I’m also gonna go ahead and delete my laser XD

Edit: what did you think about my laser idea? just curious

Bullets are better for me …

Call out if you have any more issues!