Pang! A Pong-Like

Description

PANG is a Pong-Like for Arudoby! It’s a digital game of tennis that harkens back to the games that first launched the idea of a game console. Play two players on one Arduboy or see how long you can volley by yourself!

I got my dev kit the other night and I’ve never done Arduino development so after cutting my teeth on the Dev Env and API I whipped up a Pong-like. It was mostly built in two evenings. I’m quite happy with myself. Please post comments, feedback, etc.

Instructions

First player to score 3 points wins! Move your paddle up and down to meet the ball and hit it back to your opponent. If you get it passed your opponent, you score a point! The ball speeds up as the volley goes on so be quick!

Media

Installation

  1. Download Zip or Git Clone from: https://github.com/wvillanueva/Pang
  2. Open Pang.ino with Arduino IDE
  3. Upload to your Arduboy

Version 1.0

First version. My first Arduboy and Arduino project. Mostly completed in a couple of nights. I feel that there are some inefficiencies in the code that someone will let me know about. I may try to reduce the footprint in future versions. 66% for a Pong-Like? Sheesh!

Known Bugs:

  1. If you volley long enough the ball will speed up to the point that it goes through the paddle. The solution is to base collision on forward interpolation but even then, eventually it will just jump across the screen.
6 Likes

Hey, when you are ready, github a version and move this thread to the games sections!

Ok. I finished the clean up and added sounds yesterday. I spent last night learning Git so I’ll do it tonight. Thanks!
(I’ve used P4, Subversion and SVN before but Git is new :smile: )

Haha, yeah it took me a few attempts to get used to git. Still working on getting good with it. When it’s all formatted, this thread can be moved to the games section. Just edit it with all of the links and a title. Here is an info page on how to format. http://community.arduboy.com/t/about-the-games-category/139

Beautiful formatting! I like the addition of a change log. Makes me wonder if there is a way to link a github readme.md from a thread : )

After pulling this down from github and compiling with the Arduino IDE, I am getting many multiple definition errors.

Here are the error messages I am receiving.

Arduino: 1.6.5 (Mac OS X), Board: “Arduino Leonardo”

Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Ball()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Ball()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Ball(int, int, int)‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Ball(int, int, int)‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Draw()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Serve()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::BounceBall(float, float, int)‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Simulate()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Reset()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Show()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/ball.cpp.o: In function Ball::Ball()': /Users/aallshouse/Documents/Arduino/libraries/Pang/ball.cpp:3: multiple definition ofBall::Hide()‘
ball.cpp.o:ball.cpp:3: first defined here
Pang/bitmaps.cpp.o:(.progmem.data.title+0x0): multiple definition of title' bitmaps.cpp.o:(.progmem.data.title+0x0): first defined here Pang/bitmaps.cpp.o:(.progmem.data.arduboyBitmap+0x0): multiple definition ofarduboyBitmap’
bitmaps.cpp.o:(.progmem.data.arduboyBitmap+0x0): first defined here
Pang/globals.cpp.o:(.bss.arduboy+0x0): multiple definition of arduboy' globals.cpp.o:(.bss.arduboy+0x0): first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of debug' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of TitleXPos' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of ArduboyMarkerPosY' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of ballReboundRange' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of paddleMoveSpeed' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of PaddleXPositions' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of PaddleHeight' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of PaddleWidth' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of TimeOnGameOverScreenDefault' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of TimeOnGameOverScreen' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of TimeToServerDefault' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of TimeToServe' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of PlayToScore' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of text' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of lastUpdateTime' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of milliPerFrame' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of targetFPS' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of screenHeight' globals.cpp.o:globals.cpp:3: first defined here Pang/globals.cpp.o: In function__static_initialization_and_destruction_0’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/globals.cpp:3: multiple definition of screenWidth' globals.cpp.o:globals.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of Paddle::Paddle()' paddle.cpp.o:paddle.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of Paddle::Paddle()' paddle.cpp.o:paddle.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of Paddle::Paddle(int, int, int, int, int)' paddle.cpp.o:paddle.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of Paddle::Paddle(int, int, int, int, int)' paddle.cpp.o:paddle.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of Paddle::Draw()' paddle.cpp.o:paddle.cpp:3: first defined here Pang/paddle.cpp.o: In functionPaddle::Paddle()’:
/Users/aallshouse/Documents/Arduino/libraries/Pang/paddle.cpp:3: multiple definition of `Paddle::Move(float)'
paddle.cpp.o:paddle.cpp:3: first defined here
collect2: error: ld returned 1 exit status
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Can you check the files in your clone? Did it clone twice or something? I just deleted the project and cloned it again and I was able to compile it on 1.6.5 with no issues.

Its weird, it’s like everything is doubled up some how… Does anyone with GIT experience see if I setup the repository correctly?

1 Like

It does look like you setup the git repo correctly. I deleted the repo and re-pulled it and it appears to be working now. It looks like putting the repo in my Arduino libraries folder was causing the issue. Putting the repo in another location and compiling from there works with no issues. Thanks for your help.

1 Like

In file included from /home/ramonml/Arduino/Pang/Pang.ino:20:0:
sketch/sound.h:12:1: warning: narrowing conversion of ‘300’ from ‘int’ to ‘const byte {aka const unsigned char}’ inside { } [-Wnarrowing]
};
^
sketch/sound.h:12:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]
/home/ramonml/Arduino/Pang/Pang.ino: In function ‘void setup()’:
/home/ramonml/Arduino/Pang/Pang.ino:47:17: warning: ‘void Arduboy::start()’ is deprecated (declared at /home/ramonml/Arduino/libraries/Arduboy/src/Arduboy.h:48): use begin() instead [-Wdeprecated-declarations]
arduboy.start();
^
/home/ramonml/Arduino/Pang/Pang.ino: In function ‘void loop()’:
/home/ramonml/Arduino/Pang/Pang.ino:64:24: warning: ‘void Arduboy::clearDisplay()’ is deprecated (declared at /home/ramonml/Arduino/libraries/Arduboy/src/Arduboy.h:58): use clear() instead [-Wdeprecated-declarations]
arduboy.clearDisplay();
^
/home/ramonml/Arduino/Pang/Pang.ino: In function ‘void GameLoop()’:
Pang:160: error: ‘CheckCollision’ was not declared in this scope
CheckCollision();
^
exit status 1
’CheckCollision’ was not declared in this scope

The Arduino IDEs “magic” function prototyping seems to be getting confused.

In file ball.h comment out line 26:

    void Serve();
//    void CheckCollision(); <- comment out or remove this
    void BounceBall( float dX, float dY, int soundType );  // Direction by sign
    void Reset();
2 Likes

And … It works.
You are the king!!! :clap::clap::clap:

1 Like

Thanks MLXXXp! I forgot to update this project since I released it. It was made on the Dev Board ><’ . I’ll check in the fixes to GitHub tonight. I know some of the audio stuff has changed too so I’ll update those as well.

Changes you should make:

In file Pang.ino

Replace arduboy.start(); with arduboy.begin();

Replace arduboy.clearDisplay(); with arduboy.clear();

In file sound.h, array titleScore contains:

92, 1, 300, 0x80,

The values are bytes so 300 is too high. If you wanted the tone duration to be 300 ms then it should be:

92, 1, 44, 0x80,

If you don’t want ARDUBOY to scroll down twice at the start, you should remove the one from the game and just let the bootLogo() call in begin() do it.

You shouldn’t have to make any changes for audio (other than the value of 300 above).

1 Like

Apologies, I’ve been very very busy at work and haven’t been on my computer at all. I’ve updated PANG in the Git Hub with bug fixes. I removed the tunes since that’s been removed from the lib. I tried to hack it back in but I’m on my lunch hour and wanted to just get the fixes in. There seems to be a bug when the ball scores where it draws across the screen. I’ll revisit that.

The changes you’ve made seem to be for the master branch of the Arduboy library. This is still under development and shouldn’t be used. Use the V1.1 version of the library.

tunes hasn’t been removed from the Arduboy library for certain. The next version of the library is still under development and how tunes will be handled is still under discussion.

So for now, you may as well leave the sound code the way it is and change it when the next stable version of the library is released.

I tried to compile this, but I get the following error: fatal error: ab_printer.h: No such file or directory. I’m using Arduino 1.6.9.

Looks like you opened the program without unpacking it. If you open it while it’s in a ZIP/RAR, it will only unzip this one thing out of the whole folder. This causes problems when the thing you unzipped looks for other things that are normally in the same folder. But since it’s the only unzipped data it won’t find anything and give you this error.
Just unzip the whole folder and THEN doubleclick on the file :slight_smile:

//Sorry, but this is my 1 AM I haven’t had enough sleep english

1 Like

Actually, that is not the case. I am using OS X Yosemite and it automatically unzipped the file after downloading. There are 13 items in this folder and it will not compile because of the fatal error. I am using IDE 1.6.9 and Arduboy library 1.1.1 is installed. Any other ideas?

1 Like

Hey, I like this.
There’s just one thing that has been slightly bugging me for ages…the name.

Pang is already a much loved game (my favorite is the original Gameboy version).
Now I really want to make an Arduboy clone of the original ‘Pang’ game…should i call it Pong?

1 Like

Although @Wenceslao_Villanueva has made changes, it appears that the version of Pang on GitHub is still broken.

A fork with the fixes that I mentioned above can be found here:

2 Likes