Skip to content

Commit

Permalink
mah
Browse files Browse the repository at this point in the history
  • Loading branch information
potatono committed May 28, 2012
1 parent 4683443 commit 0dfc24d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 88 deletions.
69 changes: 37 additions & 32 deletions Pong.pde
Expand Up @@ -9,28 +9,32 @@ class Pong extends Routine {
long flashUntilFrame; long flashUntilFrame;
long ballFlashUntilFrame; long ballFlashUntilFrame;
boolean deathLeft; boolean deathLeft;

int lives;

void setup(PApplet parent) { void setup(PApplet parent) {
ballY = 0; ballY = 0;
ballX = 0; ballX = 0;
ballAngle = radians(45); ballAngle = radians(45);
deathLeft = false; deathLeft = false;
// Speed is whatever it takes to cross the screen in 1 sec.
ballSpeed = 0.25; ballSpeed = 0.25;

lives = 3;

paddleX = width/2; paddleX = width/2;
paddleY = 0; paddleY = 0;
paddleSize = height/8; paddleSize = height/8;
ballFlashUntilFrame = frameCount + (long)frameRate * 3; ballFlashUntilFrame = frameCount + (long)frameRate * 3;
} }

void draw() { void draw() {
if (frameCount < flashUntilFrame) { if (frameCount < flashUntilFrame) {
background(millis() % 255, (millis() % 255)/2, 0); background(millis() % 255, (millis() % 255)/2, 0);
} }
else { else if (lives > 0) {
drawGameplay(); drawGameplay();
} }
else {
newMode();
}
} }


void drawGameplay() { void drawGameplay() {
Expand All @@ -40,11 +44,11 @@ class Pong extends Routine {
moveBall(); moveBall();
} }
movePaddle(); movePaddle();

drawBall(); drawBall();
drawPaddle(); drawPaddle();
} }

void drawBall() { void drawBall() {
if (frameCount < ballFlashUntilFrame) { if (frameCount < ballFlashUntilFrame) {
stroke(millis() % 255, (millis() % 255)/2, 0); stroke(millis() % 255, (millis() % 255)/2, 0);
Expand All @@ -54,44 +58,42 @@ class Pong extends Routine {
} }
point(ballX, ballY); point(ballX, ballY);
} }

void drawPaddle() { void drawPaddle() {
for (int i=0; i<paddleSize; i++) { for (int i=0; i<paddleSize; i++) {

stroke(255,64,64); stroke(255, 64, 64);
point(paddleX,paddleY+i); point(paddleX, paddleY+i);
} }
} }

void movePaddle() { void movePaddle() {
if (keyPressed) { if ((keyPressed && keyCode == UP) || controller.buttonUp) {
if (keyCode == UP) { paddleY--;
paddleY--;
}
else if (keyCode == DOWN) {
paddleY++;
}
} }

else if ((keyPressed && keyCode == DOWN) || controller.buttonDown) {
paddleY++;
}

if (paddleY > height-paddleSize) { if (paddleY > height-paddleSize) {
paddleY = height-paddleSize; paddleY = height-paddleSize;
} }
else if (paddleY < 0) { else if (paddleY < 0) {
paddleY = 0; paddleY = 0;
} }
} }

void moveBall() { void moveBall() {
float xVec = ballSpeed * cos(ballAngle); float xVec = ballSpeed * cos(ballAngle);
float yVec = ballSpeed * sin(ballAngle); float yVec = ballSpeed * sin(ballAngle);

if (abs(xVec) > 1) { if (abs(xVec) > 1) {
println("Ball is moving too fast. "+xVec); println("Ball is moving too fast. "+xVec);
} }

ballX += xVec; ballX += xVec;
ballY += yVec; ballY += yVec;

if (ballY >= height) { if (ballY >= height) {
ballY = height-1; ballY = height-1;
bounceY(); bounceY();
Expand All @@ -100,10 +102,10 @@ class Pong extends Routine {
ballY = 0; ballY = 0;
bounceY(); bounceY();
} }

if (ballX >= width) { if (ballX >= width) {
ballX = ballX - width; ballX = ballX - width;

if (!deathLeft) { if (!deathLeft) {
playerDied(); playerDied();
} }
Expand All @@ -113,7 +115,7 @@ class Pong extends Routine {
} }
else if (ballX < 0) { else if (ballX < 0) {
ballX = width + ballX; ballX = width + ballX;

if (deathLeft) { if (deathLeft) {
playerDied(); playerDied();
} }
Expand All @@ -124,30 +126,33 @@ class Pong extends Routine {


if (int(ballX) == paddleX && ballY >= paddleY && ballY <= paddleY+paddleSize) { if (int(ballX) == paddleX && ballY >= paddleY && ballY <= paddleY+paddleSize) {
bounceX((paddleY+paddleSize-ballY-paddleSize/2)/(paddleSize/2.0)); bounceX((paddleY+paddleSize-ballY-paddleSize/2)/(paddleSize/2.0));

if (deathLeft) { if (deathLeft) {
ballX++; ballX++;
} }
else { else {
ballX--; ballX--;
} }
} }
} }

void playerDied() { void playerDied() {
ballY = paddleY; ballY = paddleY;
ballX = 2; ballX = 2;
ballAngle = radians(45); ballAngle = radians(45);
deathLeft = false; deathLeft = false;
flashUntilFrame = frameCount + (long)frameRate*3; flashUntilFrame = frameCount + (long)frameRate*3;
ballFlashUntilFrame = flashUntilFrame + (long)frameRate*3; ballFlashUntilFrame = flashUntilFrame + (long)frameRate*3;

lives--;
} }

void bounceX(float spin) { void bounceX(float spin) {
ballAngle = radians(180 - degrees(ballAngle) - spin*10); ballAngle = radians(180 - degrees(ballAngle) - spin*10);
} }

void bounceY() { void bounceY() {
ballAngle = radians(360 - degrees(ballAngle) + (random(40)-20)); ballAngle = radians(360 - degrees(ballAngle) + (random(40)-20));
} }
} }

11 changes: 5 additions & 6 deletions Seizure.pde
Expand Up @@ -2,8 +2,7 @@ class Seizure extends Routine {
int count = 0; int count = 0;


void draw() { void draw() {
long frame = frameCount - modeFrameStart; /*

if (count == 0) { if (count == 0) {
background(0,0,0); background(0,0,0);
} }
Expand All @@ -12,9 +11,9 @@ class Seizure extends Routine {
} }
count = (count + 1) % 2; count = (count + 1) % 2;

*/
// if (frame > FRAMERATE*TYPICAL_MODE_TIME) {
// newMode(); // Four blinks per second.
// } background(frameCount / (int(frameRate)/4) % 2 == 0 ? color(255,128,0) : color(255,64,64));
} }
} }
43 changes: 23 additions & 20 deletions Warp.pde
Expand Up @@ -14,75 +14,78 @@ class Warp extends Routine {
warpSpeed = 1; warpSpeed = 1;
warpFactor = 1; warpFactor = 1;
} }

public Warp(Routine subroutine, boolean warpHorizontal, boolean warpVertical, float warpSpeed, float warpFactor) { public Warp(Routine subroutine, boolean warpHorizontal, boolean warpVertical, float warpSpeed, float warpFactor) {
this.subroutine = subroutine; this.subroutine = subroutine;
this.warpHorizontal = warpHorizontal; this.warpHorizontal = warpHorizontal;
this.warpVertical = warpVertical; this.warpVertical = warpVertical;
this.warpSpeed = warpSpeed; this.warpSpeed = warpSpeed;
this.warpFactor = warpFactor; this.warpFactor = warpFactor;
} }

void setup(PApplet parent) { void setup(PApplet parent) {
super.setup(parent); super.setup(parent);

if (this.subroutine != null) { if (this.subroutine != null) {
this.subroutine.setup(parent); this.subroutine.setup(parent);
} }
} }

void hshift(int y, int xofs) { void hshift(int y, int xofs) {
if (xofs < 0) if (xofs < 0)
xofs = width + xofs; xofs = width + xofs;


PImage tmp = get(width-xofs,y,xofs,1); PImage tmp = get(width-xofs, y, xofs, 1);
copy(0,y,width-xofs,1, xofs,y,width-xofs,1); copy(0, y, width-xofs, 1, xofs, y, width-xofs, 1);
image(tmp,0,y); image(tmp, 0, y);
} }


void vshift(int x, int yofs) { void vshift(int x, int yofs) {
if (yofs < 0) if (yofs < 0)
yofs = height + yofs; yofs = height + yofs;


PImage tmp = get(x,height-yofs,1,yofs); PImage tmp = get(x, height-yofs, 1, yofs);
copy(x,0,1,height-yofs, x,yofs,1,height-yofs); copy(x, 0, 1, height-yofs, x, yofs, 1, height-yofs);
image(tmp,x,0); image(tmp, x, 0);
} }


void drawBackground() { void drawBackground() {
if (subroutine != null) { if (subroutine != null) {
subroutine.draw(); subroutine.draw();

if (subroutine.isDone) { if (subroutine.isDone) {
newMode(); newMode();
} }
} }
else { else {
background(0); background(0);
fill(255); noFill();
ellipseMode(CORNER); ellipseMode(RADIUS);
ellipse(0,0,width-1,height-1); for (int i=0; i<10; i++) {
stroke(i%2==0 ? color(255,64,64) : color(255,128,0));
ellipse(width/2,height/2,i*(width/10),i*(height/10));
}
} }
} }

void draw() { void draw() {
drawBackground(); drawBackground();

if (warpVertical) { if (warpVertical) {
for (int x=0; x<width; x++) { for (int x=0; x<width; x++) {
r = x*1.0/height*PI + rofs; r = x*1.0/height*PI + rofs;
vshift(x,int(sin(r)*(height*warpFactor))); vshift(x, int(sin(r)*(height*warpFactor)));
} }

rofs += 0.0314 * warpSpeed; rofs += 0.0314 * warpSpeed;
} }


if (warpHorizontal) { if (warpHorizontal) {
for (int y=0; y<height; y++) { for (int y=0; y<height; y++) {
r = y*1.0/width*PI + rofs; r = y*1.0/width*PI + rofs;
hshift(y,int(sin(r)*(width*warpFactor))); hshift(y, int(sin(r)*(width*warpFactor)));
} }

rofs += 0.0314 * warpSpeed; rofs += 0.0314 * warpSpeed;
} }
} }
Expand Down
8 changes: 5 additions & 3 deletions WiiController.pde
Expand Up @@ -107,18 +107,20 @@ class WiiController {
} }


void wiiosc_accX(int id, float value) { void wiiosc_accX(int id, float value) {
acc.x = 10*value-5; // value goes from .4 (-90) to .6 (90)
acc.x = (value-.5)*10;
} }


void wiiosc_accY(int id, float value) { void wiiosc_accY(int id, float value) {
acc.z = 10*value-5; acc.y = (value-.5)*10;
} }


void wiiosc_accZ(int id, float value) { void wiiosc_accZ(int id, float value) {
acc.z = 10*value-5; acc.z = (value-.5)*10;


pitch = (float) Math.atan2(acc.y, acc.z)*(180/3.14); pitch = (float) Math.atan2(acc.y, acc.z)*(180/3.14);
roll = (float) Math.atan2(acc.x, acc.z)*(180/3.14); roll = (float) Math.atan2(acc.x, acc.z)*(180/3.14);
println(roll);
} }


void connected(int theValue) { void connected(int theValue) {
Expand Down

0 comments on commit 0dfc24d

Please sign in to comment.