Skip to content
Browse files

mah

  • Loading branch information...
1 parent 4683443 commit 0dfc24df7d60b6faf9ecbaaa39ff08d8531546de @potatono potatono committed May 27, 2012
Showing with 104 additions and 88 deletions.
  1. +37 −32 Pong.pde
  2. +5 −6 Seizure.pde
  3. +23 −20 Warp.pde
  4. +5 −3 WiiController.pde
  5. +34 −27 domeTransmitter.pde
View
69 Pong.pde
@@ -9,28 +9,32 @@ class Pong extends Routine {
long flashUntilFrame;
long ballFlashUntilFrame;
boolean deathLeft;
-
+ int lives;
+
void setup(PApplet parent) {
ballY = 0;
ballX = 0;
ballAngle = radians(45);
deathLeft = false;
- // Speed is whatever it takes to cross the screen in 1 sec.
ballSpeed = 0.25;
-
+ lives = 3;
+
paddleX = width/2;
paddleY = 0;
paddleSize = height/8;
ballFlashUntilFrame = frameCount + (long)frameRate * 3;
}
-
+
void draw() {
if (frameCount < flashUntilFrame) {
background(millis() % 255, (millis() % 255)/2, 0);
}
- else {
+ else if (lives > 0) {
drawGameplay();
}
+ else {
+ newMode();
+ }
}
void drawGameplay() {
@@ -40,11 +44,11 @@ class Pong extends Routine {
moveBall();
}
movePaddle();
-
+
drawBall();
drawPaddle();
}
-
+
void drawBall() {
if (frameCount < ballFlashUntilFrame) {
stroke(millis() % 255, (millis() % 255)/2, 0);
@@ -54,44 +58,42 @@ class Pong extends Routine {
}
point(ballX, ballY);
}
-
+
void drawPaddle() {
for (int i=0; i<paddleSize; i++) {
-
- stroke(255,64,64);
- point(paddleX,paddleY+i);
+
+ stroke(255, 64, 64);
+ point(paddleX, paddleY+i);
}
}
-
+
void movePaddle() {
- if (keyPressed) {
- if (keyCode == UP) {
- paddleY--;
- }
- else if (keyCode == DOWN) {
- paddleY++;
- }
+ if ((keyPressed && keyCode == UP) || controller.buttonUp) {
+ paddleY--;
}
-
+ else if ((keyPressed && keyCode == DOWN) || controller.buttonDown) {
+ paddleY++;
+ }
+
if (paddleY > height-paddleSize) {
paddleY = height-paddleSize;
}
else if (paddleY < 0) {
paddleY = 0;
}
}
-
+
void moveBall() {
float xVec = ballSpeed * cos(ballAngle);
float yVec = ballSpeed * sin(ballAngle);
-
+
if (abs(xVec) > 1) {
println("Ball is moving too fast. "+xVec);
}
-
+
ballX += xVec;
ballY += yVec;
-
+
if (ballY >= height) {
ballY = height-1;
bounceY();
@@ -100,10 +102,10 @@ class Pong extends Routine {
ballY = 0;
bounceY();
}
-
+
if (ballX >= width) {
ballX = ballX - width;
-
+
if (!deathLeft) {
playerDied();
}
@@ -113,7 +115,7 @@ class Pong extends Routine {
}
else if (ballX < 0) {
ballX = width + ballX;
-
+
if (deathLeft) {
playerDied();
}
@@ -124,30 +126,33 @@ class Pong extends Routine {
if (int(ballX) == paddleX && ballY >= paddleY && ballY <= paddleY+paddleSize) {
bounceX((paddleY+paddleSize-ballY-paddleSize/2)/(paddleSize/2.0));
-
+
if (deathLeft) {
ballX++;
}
else {
ballX--;
- }
+ }
}
}
-
+
void playerDied() {
ballY = paddleY;
ballX = 2;
ballAngle = radians(45);
deathLeft = false;
flashUntilFrame = frameCount + (long)frameRate*3;
ballFlashUntilFrame = flashUntilFrame + (long)frameRate*3;
+
+ lives--;
}
-
+
void bounceX(float spin) {
ballAngle = radians(180 - degrees(ballAngle) - spin*10);
}
-
+
void bounceY() {
ballAngle = radians(360 - degrees(ballAngle) + (random(40)-20));
}
}
+
View
11 Seizure.pde
@@ -2,8 +2,7 @@ class Seizure extends Routine {
int count = 0;
void draw() {
- long frame = frameCount - modeFrameStart;
-
+ /*
if (count == 0) {
background(0,0,0);
}
@@ -12,9 +11,9 @@ class Seizure extends Routine {
}
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));
}
}
View
43 Warp.pde
@@ -14,75 +14,78 @@ class Warp extends Routine {
warpSpeed = 1;
warpFactor = 1;
}
-
+
public Warp(Routine subroutine, boolean warpHorizontal, boolean warpVertical, float warpSpeed, float warpFactor) {
this.subroutine = subroutine;
this.warpHorizontal = warpHorizontal;
this.warpVertical = warpVertical;
this.warpSpeed = warpSpeed;
this.warpFactor = warpFactor;
}
-
+
void setup(PApplet parent) {
super.setup(parent);
-
+
if (this.subroutine != null) {
this.subroutine.setup(parent);
}
}
-
+
void hshift(int y, int xofs) {
if (xofs < 0)
xofs = width + xofs;
- PImage tmp = get(width-xofs,y,xofs,1);
- copy(0,y,width-xofs,1, xofs,y,width-xofs,1);
- image(tmp,0,y);
+ PImage tmp = get(width-xofs, y, xofs, 1);
+ copy(0, y, width-xofs, 1, xofs, y, width-xofs, 1);
+ image(tmp, 0, y);
}
void vshift(int x, int yofs) {
if (yofs < 0)
yofs = height + yofs;
- PImage tmp = get(x,height-yofs,1,yofs);
- copy(x,0,1,height-yofs, x,yofs,1,height-yofs);
- image(tmp,x,0);
+ PImage tmp = get(x, height-yofs, 1, yofs);
+ copy(x, 0, 1, height-yofs, x, yofs, 1, height-yofs);
+ image(tmp, x, 0);
}
void drawBackground() {
if (subroutine != null) {
subroutine.draw();
-
+
if (subroutine.isDone) {
newMode();
}
}
else {
background(0);
- fill(255);
- ellipseMode(CORNER);
- ellipse(0,0,width-1,height-1);
+ noFill();
+ ellipseMode(RADIUS);
+ 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() {
drawBackground();
-
+
if (warpVertical) {
for (int x=0; x<width; x++) {
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;
}
if (warpHorizontal) {
for (int y=0; y<height; y++) {
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;
}
}
View
8 WiiController.pde
@@ -107,18 +107,20 @@ class WiiController {
}
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) {
- acc.z = 10*value-5;
+ acc.y = (value-.5)*10;
}
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);
roll = (float) Math.atan2(acc.x, acc.z)*(180/3.14);
+ println(roll);
}
void connected(int theValue) {
View
61 domeTransmitter.pde
@@ -16,8 +16,11 @@ int FRAMERATE = 100;
String hostname = "127.0.0.1"; //"192.168.1.130";
int TYPICAL_MODE_TIME = 300;
Routine drop = new Seizure();
+Routine pong = new Pong();
Routine[] enabledRoutines = new Routine[] {
+// new Warp(new WarpSpeedMrSulu(), false, true, 0.25, 0.25)
+ new Warp(null, true, false, 0.5, 0.5)
/* new Bursts(),
new Flash(),
new Lines(),
@@ -31,8 +34,6 @@ Routine[] enabledRoutines = new Routine[] {
new FlashColors(),
new FollowMouse()
new Greetz()*/
-
- new Pong()
};
int w = 0;
@@ -109,36 +110,42 @@ void newMode() {
}
void draw() {
-// if (controller.buttonA) {
-// drop.draw();
-// }
-// else {
-
- if (fadeOutFrames > 0) {
- fadeOutFrames--;
- blend(fadeLayer, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, MULTIPLY);
-
- if (fadeOutFrames == 0) {
- fadeInFrames = FRAMERATE;
- }
+ if (((keyPressed && key == '1') || (controller.buttonOne && controller.buttonTwo)) && currentRoutine != pong) {
+ currentRoutine = pong;
+ pong.setup(this);
}
- else if (currentRoutine != null) {
- currentRoutine.predraw();
- currentRoutine.draw();
+
+ if (controller.buttonA || (keyPressed && key == 'a')) {
+ drop.draw();
}
else {
- println("Current method is null");
- }
+
+ if (fadeOutFrames > 0) {
+ fadeOutFrames--;
+ blend(fadeLayer, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, MULTIPLY);
- if (fadeInFrames > 0) {
- setFadeLayer(240 - fadeInFrames*8);
- blend(fadeLayer, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, MULTIPLY);
- fadeInFrames--;
- }
+ if (fadeOutFrames == 0) {
+ fadeInFrames = FRAMERATE;
+ }
+ }
+ else if (currentRoutine != null) {
+ currentRoutine.predraw();
+ currentRoutine.draw();
+ }
+ else {
+ println("Current method is null");
+ }
- if (currentRoutine.isDone) {
- currentRoutine.isDone = false;
- newMode();
+ if (fadeInFrames > 0) {
+ setFadeLayer(240 - fadeInFrames*8);
+ blend(fadeLayer, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, MULTIPLY);
+ fadeInFrames--;
+ }
+
+ if (currentRoutine.isDone) {
+ currentRoutine.isDone = false;
+ newMode();
+ }
}
// }

0 comments on commit 0dfc24d

Please sign in to comment.
Something went wrong with that request. Please try again.