-
Pong in 80 Lines of code.
04/19/2023 at 02:05 • 0 commentsI said 100, got it done with 80 lines of "Game code".
Could be cleaner, the whole sketch is about double and the padal placement needs a bit of work.
- Adding a ball Spin or acceleration when a hit is made with the padal moving.
- a ball Split extra if you match the ball speed and hit on the corner of the padal.
Pong Arduino Oled Code Below...
---------- more ----------void drawrect(int x, int y, int l, bool filled) { if(filled) display.fillRect(x, y, 4, l, SSD1306_INVERSE); else display.drawRect(x, y, 4, l, SSD1306_WHITE); } int p1 = 0, p2 = 0; int tik = 0; int bx = 32, by = 32; int vx = 1, vy = 1; int bs = 6, pl = 10; int s1 =0, s2 = 0; int hp = bs+6; bool paused = false; void one(){ paused = true; s1++; char l1[12]; sprintf(l1," %02d : %02d ", s1, s2); testdrawoled( "POne Wins!", l1); delay(511); } void two(){ paused = true; s2++; char l1[12]; sprintf(l1," %02d : %02d ", s1, s2); testdrawoled( "pTWO Wins!", l1); delay(511); } void drawBall() { int hit = -1; //check for points. if(bx > display.width()-bs) one(); else if(bx < bs) two(); else if(bx > display.width()-hp and vx > 0){ //if the ball is on p2 side. if((by < (p2+pl)) and (by > p2) ) vx*=-1; hit = 1; } else if(bx < hp and vx < 0){ //p1 side if((by < (p1+pl)) and (by > p1) ) vx*=-1; hit = 2; } if( (hit ==-1) and (bx > display.width()-bs or bx < bs) ) vx *= -1; if(by > display.height()-bs/2 or by < bs/2) vy *= -1; bx += vx; by += vy; display.drawCircle(bx, by, bs, SSD1306_WHITE); display.drawCircle(bx, by, bs/2, SSD1306_WHITE); //double ball for spin?/acceleration. } void drawGame() { display.clearDisplay(); drawrect(2, p1, pl, false); drawrect(display.width()-4, p2, pl, false); char score[12]; sprintf(score,"%02d : %02d", s1, s2); display.setTextSize(1); display.setCursor(38,0); // Start at top-left corner display.println(score); drawrect(62, 0, 64, false);//net drawBall(); display.display(); delay(1); if(!paused) if(tik++ > 1000) tik = 0; }
-
Touchless Controls?
04/12/2023 at 23:01 • 0 commentsAdded an oled screen to my ultrasonic walking stick mock up test circuit for testing/finding limits.
Immediately realized it would make the perfect PicoPong Circuit.
- 2 Player pong - Distance sensor output maps to paddle position.
- alternate xy or other inputs for other games...
Need to convert/rewrite the game for the full oled library but pong is pretty easy, I think I can do it in less than 100 lines of code... maybe..
-
Is this a bug?
04/08/2023 at 07:55 • 1 commentOr I really should have done a kickstarter for this.
310 views and 310 follows? so everyone that looked followed.... ?