Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working on Pong - moved old files (maintained in trunk) for reference…

… and preservation.
  • Loading branch information...
commit 57a504791a6f227eeba27d277bf1d7bd112400ce 1 parent 9309d3c
@jayscribbs jayscribbs authored
View
1  AUTHORS
@@ -1,3 +1,4 @@
Brian Muller <bmuller@butterfat.net>
Matt Shotwell <shotwelm@musc.edu>
Zenko B. Klapko Jr. <CovertCodeOp1@gmail.com>
+Josh West <jayscribbs@gmail.com>
View
1  blobber/blobber.cpp
@@ -32,6 +32,7 @@ You can find out more at http://trac.butterfat.net/public/blobber
\li Brian Muller <bmuller@butterfat.net>
\li Matt Shotwell <shotwelm@musc.edu>
\li Zenko B. Klapko Jr. <CovertCodeOp1@gmail.com>
+\li Josh West <jayscribbs@gmail.com>
*/
#include "application.h"
View
2  modules/Makefile.am
@@ -14,7 +14,7 @@ libprojectionoptions_la_SOURCES = projection_options/projection_options.cpp
# Modules that are conditionally compiled
if PONG
pkglib_LTLIBRARIES += libpong.la
- libpong_la_SOURCES = pong/pong.cpp pong/ball.cpp pong/paddle.cpp
+ libpong_la_SOURCES = pong/pong.cpp
endif
if INVADERS
View
130 modules/pong/pong.cpp
@@ -1,33 +1,64 @@
-#include "pongmod.h"
-#include <cstdlib>
+/* Origin is set at upper left hand corner of screen
+ *
+ * Vectors are converted to rectangular coordinates
+ * using:
+ * delta x = speed * cos(angle)
+ * delta y = speed * sin(angle)
+ * Rectangular coordinates are converted to vectors
+ * using:
+ * speed = sqrt[x^2 + y^2]
+ * angle = tan^-1(y/x)
+ *
+ * 90
+ * |
+ * |
+ * 180----------0
+ * |
+ * |
+ * 270
+ *
+ * Laser "hotspots are the left and right 10% of the
+ * screen.
+ *
+ * Everything is scaled/interpolated to pw resolution
+ */
+
+#include "pong.h"
+#include "blobber.h"
#include <iostream>
using namespace blobber;
using namespace std;
-Pong::Pong() : ModInterface("Pong", "Old school pong") { }
+Pong::Pong() : ModInterface("Pong", "The first-ish video game") { }
-void Pong::init(Camarea &area, ProjectionWindow &pw) {
+Pong::~Pong() { }
- register_poi(area, 2); //????
+void Pong::init(Camarea &area, ProjectionWindow &pw) {
+ register_poi(area, 2);
- court.width = 400;
- court.height = 150;
+ ball.coord.x = 50 * hPercent;
+ ball.coord.y = 50 * vPercent;
- ball = Ball(6,6,5,10,court);
- right_paddle = Paddle(court.width-30, 100, 10, 50, 5, court);
- left_paddle = Paddle(20, 100, 10, 50, 5, court);
+}
- debug("Greetings from the Pong Module!");
+void Pong::update(Camarea &area, ProjectionWindow &pw) {
+
+ // Adjust scaling - FIXME Should only be done if win geometry changes
+ hPercent = pw.dimensions.width / 100;
+ vPercent = pw.dimensions.height / 100;
- //used to draw court -- temporary
- origin.x = 0;
- origin.y = 0;
+ ball.coord.x = 50 * hPercent;
+ ball.coord.y = 50 * vPercent;
- paddle_moving_up = 1; //TEMPORARY, JUST TO GET STUFF HAPPENING
-}
+ for (int i = 0; i < 2; i++) {
+ paddle[i].width = 3 * hPercent;
+ paddle[i].height = 10 * vPercent;
+ }
+
+ ball.radius = hPercent;
-void Pong::update(Camarea &area, ProjectionWindow &pw) {
+ // Handle POI
vector<PIXEL> poi;
get_poi(area, poi);
@@ -36,35 +67,34 @@ void Pong::update(Camarea &area, ProjectionWindow &pw) {
}
else {
//debug("poi found!");
- for(int i = 0; i < poi.size(); ++i) {
+ for(int i = 0; i < poi.size(); i++) {
+
+ // Interpolate POI
+ COORD p;
+ p.x = static_cast<int>((
+ static_cast<float>(poi[i].coord.x - area.bounds.left) /
+ static_cast<float>(area.bounds.width())) *
+ static_cast<float>(pw.dimensions.width));
+ p.y = static_cast<int>((
+ static_cast<float>(poi[i].coord.y - area.bounds.top) /
+ static_cast<float>(area.bounds.height())) *
+ static_cast<float>(pw.dimensions.height));
+
+ if (i == 0 && p.x <= 10 * hPercent)
+ laser[0] = p;
+ if (i == 1 && p.x >= 90 * hPercent)
+ laser[1] = p;
}
}
- //cout << "num poi: " << poi.size() << endl;
-
/** move stuff **/
- ball.move();
//here is where we'll need to move the left paddle based on the poi
- //TEMPORARY MOVEMENT OF PADDLES, JUST TO GET STUFF HAPPENING
- if(rand()%10 == 5)
- paddle_moving_up = -paddle_moving_up;
- if(paddle_moving_up == 1) {
- left_paddle.moveUp();
- right_paddle.moveDown();
- }
- else {
- left_paddle.moveDown();
- right_paddle.moveUp();
- }
- //END TEMPORARY MOVEMENT OF PADDLES
/** end move stuff **/
/** Check for stuff **/
- ball.processCollision(&left_paddle);
- ball.processCollision(&right_paddle);
/** end check for stuff **/
/** Clear stuff **/
@@ -72,16 +102,18 @@ void Pong::update(Camarea &area, ProjectionWindow &pw) {
/** end clear stuff **/
/** draw stuff **/
- pw.draw_box_absolute(origin,
- pw.dimensions.width,
- pw.dimensions.height,
- BLUE); //draw the court (TEMPORARY)
-
- pw.draw_circle_absolute(scale(pw.dimensions, court, ball.pos),
- scale(pw.dimensions.width, court.width, ball.radius),
+ for (int i = 0; i < 2; i++)
+ pw.draw_circle_absolute(laser[i], 1, BLUE, true);
+// pw.draw_box_absolute(origin,
+// pw.dimensions.width - 10,
+// pw.dimensions.height - 10,
+// BLUE); //draw the court (TEMPORARY)
+
+ pw.draw_circle_absolute(ball.coord,
+ ball.radius,
WHITE,
true);
-
+/*
pw.draw_box_absolute(scale(pw.dimensions, court, left_paddle.pos),
scale(pw.dimensions.width, court.width, left_paddle.width),
scale(pw.dimensions.height, court.height, left_paddle.height),
@@ -96,17 +128,7 @@ void Pong::update(Camarea &area, ProjectionWindow &pw) {
/** end draw stuff **/
}
-int Pong::scale(int pw, int real_val, int coord) {
- float scale_factor = (float) pw/real_val;
- return (int) coord*scale_factor;
-}
-
-COORD Pong::scale(DIMENSION pw, DIMENSION real_val, COORD coord) {
- COORD return_val;
- return_val.x = scale(pw.width, real_val.width, coord.x);
- return_val.y = scale(pw.height, real_val.height, coord.y);
- return return_val;
-}
+// Interpolate POI
extern "C" {
ModInterface *get_module() { return new Pong(); };
View
32 modules/pong/pong.h
@@ -1,23 +1,31 @@
+#include "blobber.h"
+
using namespace blobber;
class Pong : public ModInterface {
public:
Pong();
- COORD origin;
- DIMENSION court;
+ ~Pong();
+
void init(Camarea &area, ProjectionWindow &pw);
void update(Camarea &area, ProjectionWindow &pw);
private:
- Ball ball;
- Paddle left_paddle;
- Paddle right_paddle;
-
- int scale(int pw, int real_val, int coord);
- COORD scale(DIMENSION pw, DIMENSION real_val, COORD coord);
-
- //temp variables to be removed later
- short int paddle_moving_up;
-};
+ COORD laser[2];
+ float vPercent, // Pixels in one percent of the vertical
+ hPercent; // and horizontal for scaling
+ struct Ball {
+ COORD coord;
+ float radius,
+ angle, // Ball velocity vector angle
+ speed; // Ball velocity magnitude (screen fraction/sec)
+ } ball;
+ struct Paddle {
+ COORD coord;
+ float height,
+ width,
+ speed; // Paddle velocity magnitude (screen fraction/sec)
+ } paddle[2];
+};
View
0  modules/pong/ball.cpp → modules/pong/semmy/ball.cpp
File renamed without changes
View
0  modules/pong/ball.h → modules/pong/semmy/ball.h
File renamed without changes
View
0  modules/pong/paddle.cpp → modules/pong/semmy/paddle.cpp
File renamed without changes
View
0  modules/pong/paddle.h → modules/pong/semmy/paddle.h
File renamed without changes
View
116 modules/pong/semmy/pong.cpp
@@ -0,0 +1,116 @@
+#include "pongmod.h"
+#include <cstdlib>
+#include <iostream>
+
+using namespace blobber;
+using namespace std;
+
+Pong::Pong() : ModInterface("Pong", "Old school pong") { }
+
+void Pong::init(Camarea &area, ProjectionWindow &pw) {
+
+ register_poi(area, 2); //????
+
+ court.width = 400;
+ court.height = 150;
+
+ ball = Ball(6,6,5,10,court);
+ right_paddle = Paddle(court.width-30, 100, 10, 50, 5, court);
+ left_paddle = Paddle(20, 100, 10, 50, 5, court);
+
+ debug("Greetings from the Pong Module!");
+
+ //used to draw court -- temporary
+ origin.x = 0;
+ origin.y = 0;
+
+ paddle_moving_up = 1; //TEMPORARY, JUST TO GET STUFF HAPPENING
+}
+
+void Pong::update(Camarea &area, ProjectionWindow &pw) {
+ vector<PIXEL> poi;
+ get_poi(area, poi);
+
+ pw.clear();
+
+ if(poi.size() == 0) {
+ //debug("no poi");
+ }
+ else {
+ //debug("poi found!");
+ for(int i = 0; i < poi.size(); ++i) {
+ pw.draw_circle_absolute(poi[i].coord, 5, BLUE, true);
+
+ }
+ }
+
+ //cout << "num poi: " << poi.size() << endl;
+
+ /** move stuff **/
+ ball.move();
+
+ //here is where we'll need to move the left paddle based on the poi
+
+ //TEMPORARY MOVEMENT OF PADDLES, JUST TO GET STUFF HAPPENING
+ if(rand()%10 == 5)
+ paddle_moving_up = -paddle_moving_up;
+ if(paddle_moving_up == 1) {
+ left_paddle.moveUp();
+ right_paddle.moveDown();
+ }
+ else {
+ left_paddle.moveDown();
+ right_paddle.moveUp();
+ }
+ //END TEMPORARY MOVEMENT OF PADDLES
+ /** end move stuff **/
+
+ /** Check for stuff **/
+ ball.processCollision(&left_paddle);
+ ball.processCollision(&right_paddle);
+ /** end check for stuff **/
+
+ /** Clear stuff **/
+// pw.clear();
+ /** end clear stuff **/
+
+ /** draw stuff **/
+// pw.draw_box_absolute(origin,
+// pw.dimensions.width - 10,
+// pw.dimensions.height - 10,
+// BLUE); //draw the court (TEMPORARY)
+
+ pw.draw_circle_absolute(scale(pw.dimensions, court, ball.pos),
+ scale(pw.dimensions.width, court.width, ball.radius),
+ WHITE,
+ true);
+
+ pw.draw_box_absolute(scale(pw.dimensions, court, left_paddle.pos),
+ scale(pw.dimensions.width, court.width, left_paddle.width),
+ scale(pw.dimensions.height, court.height, left_paddle.height),
+ WHITE,
+ true);
+
+ pw.draw_box_absolute(scale(pw.dimensions, court, right_paddle.pos),
+ scale(pw.dimensions.width, court.width, right_paddle.width),
+ scale(pw.dimensions.height, court.height, right_paddle.height),
+ WHITE,
+ true);
+ /** end draw stuff **/
+}
+
+int Pong::scale(int pw, int real_val, int coord) {
+ float scale_factor = (float) pw/real_val;
+ return (int) coord*scale_factor;
+}
+
+COORD Pong::scale(DIMENSION pw, DIMENSION real_val, COORD coord) {
+ COORD return_val;
+ return_val.x = scale(pw.width, real_val.width, coord.x);
+ return_val.y = scale(pw.height, real_val.height, coord.y);
+ return return_val;
+}
+
+extern "C" {
+ ModInterface *get_module() { return new Pong(); };
+};
View
23 modules/pong/semmy/pong.h
@@ -0,0 +1,23 @@
+using namespace blobber;
+
+class Pong : public ModInterface {
+ public:
+ Pong();
+ COORD origin;
+ DIMENSION court;
+ void init(Camarea &area, ProjectionWindow &pw);
+ void update(Camarea &area, ProjectionWindow &pw);
+
+ private:
+ Ball ball;
+ Paddle left_paddle;
+ Paddle right_paddle;
+
+ int scale(int pw, int real_val, int coord);
+ COORD scale(DIMENSION pw, DIMENSION real_val, COORD coord);
+
+ //temp variables to be removed later
+ short int paddle_moving_up;
+};
+
+
View
0  modules/pong/pongmod.h → modules/pong/semmy/pongmod.h
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.