[Game]cPong [WIP]

That’d be pretty cool. Honestly I haven’t even tried yet with the simulator so if I have trouble I’ll definitely let you know!

The docs say EEPROM works the same as Arduino so saving to EEPROM should be as simple as:

EEPROM.put(eepromAddress, highscore);

And loading:

ulong highscore = EEPROM.get<ulong>(eepromAddress);

yep. and if you avoid saving in say lowest 256 bytes we wont have conflicts at this point in time

2 Likes

Looks great, I love the particles!

I remember this being one one of the first games I ever made! I did have issues with the predictability of the ball considering you’re playing with 180 degrees on the inside of the circle.

1 Like

Yeah, coming from Lua I’ve had the ball react in some weird ways. I realized that it’s a sign issue, so calculating the angle then adding pi to that works alot better. My new issue is the ball seems to bounce off the player at different speeds, which makes absolutely no sense to me considering sine and cosine compliment each other and I should get the same velocity no matter the input angle.

If you need help saving a short to SD card, assuming you’ve followed my tutorial, here’s some code for saving a short instead of a char (don’t know if this works – I think it will, but I haven’t tested it out yet):

void saveHiscore() {
  char byte2 = hiscore % 256;
  char byte1 = (hiscore - byte2) / 256;
  fileOpen("hiscore.txt", FILE_MODE_READWRITE);
  fileSetPosition(0);
  filePutChar(byte1);
  fileSetPosition(1);
  filePutChar(byte2);
  fileClose();
}

char readHiscore() {
  char tempByte;
  char tempHiscore;
  fileOpen("hiscore.txt",FILE_MODE_READWRITE);
  fileSetPosition(0);
  tempByte = (char)fileGetChar();
  fileSetPosition(1);
  tempHiscore = tempByte * 256 + (char)fileGetChar();
  fileClose();
  return tempHiscore;
}
1 Like

Awesome thanks! You definitely saved me some time figuring that part out. Looks pretty straightforward. I haven’t tried saving yet, as soon as my Pokitto is functional I’ll let you know how it goes!

I’m not trying to undermine you here, but I think there’s an easier way:

void saveHiscore() {
  fileOpen("hiscore.txt", FILE_MODE_READWRITE);
  fileSetPosition(0);
  fileWriteBytes(reinterpret_cast<uint8_t *>(&hiscore), static_cast<uint16_t>(sizeof(hiscore)));
  fileClose();
}

short readHiscore() {
  short result;
  fileOpen("hiscore.txt",FILE_MODE_READWRITE);
  fileSetPosition(0);
  fileReadBytes(reinterpret_cast<uint8_t *>(&result), static_cast<uint16_t>(sizeof(result)));
  fileClose();
  return result;
}

I admit I haven’t tested it, but I’m fairly certain it works.

(Also the second fileSetPosition in each function is redundant since the API is for sequential file access - it already advances the file position every time a byte is read.)

2 Likes

It works fine :yum:

2 Likes

Current look with the new title screen. Also, @VonBednar was able to test for me and reported back that the game is running incredibly slow on HW. I’ll have to tone some effects and stuff down a bit when I can test for myself. The game it’s self though is pretty much finished.

6 Likes

Looks very inviting!

2 Likes

Lots of floating point calculations?

1 Like

Yes, as well as mutiple sin calls in loops that I don’t think is really needed. I can just do it outside of the loops. I think I’ll be able to optimize. If not the particles will be the first to go.

bin file added. I had to remove some effects and stuff. Circle drawing was taking a huge toll on framerate. To achieve the thick circles I was drawing 2 filled circles.

Enjoy!

3 Likes

Haha! The games page PHP script is not picking up the game because it starts with a small letter. I’ll fix that.

edit:done

Thanks for a great game @trelemar !

2 Likes

Thanks Jonne! I’ve been messing with some other stuff as well. The lowres mode runs way faster than I was expecting. It’s pretty awesome! Hoping to come up with something a little deeper next.

1 Like

Yes, that is, in addition to having 1/4 of pixels of Hi-Res mode, because Lo-Res drawing is optimized. Hi-Res drawBitmap is not yet optimized.

1 Like

Does anyone know the math involved in translating an xyz (pitch roll yaw) accelerometer output to control the ball ??

I just got ADXL345 working and thought of hooking it up to this game.

Meeting some investors from Japan tomorrow. Wanted to make a demo #itsonly8pm !

1 Like

https://www.dfrobot.com/wiki/index.php/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing

Did you see this site?

3-axis accelerometers are on my ‘to learn’ list so it’ll be interesting to see the result.

Seeing Euler angles makes me wonder if gimbal lock is going to be a problem.
We don’t want another Apollo 11 incident :P.