import ddf.minim.*;
/**
* Friday Prototype: "Petal Meter"
*
*
Go play more games at NMcCoy.net!
*
This work by Nathan McCoy is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
*/
boolean[] keys = new boolean[256];
boolean title;
boolean paused;
boolean muted;
boolean game_over;
int score;
int top_score;
int drawing_ms_last;
int physics_ms_last;
int CORE_FPS = 540;
int DRAWING_FPS = 60;
int PHYSICS_FPS = 180;
int DRAW_MS = 1000 / DRAWING_FPS;
int PHYS_MS = 1000 / PHYSICS_FPS;
Minim minim;
void audioInit()
{
minim = new Minim(this);
}
void audioClose()
{
minim.stop();
}
float FLOWER_RADIUS = 200;
float HUESCALE = 1;
int petals = 20;
boolean squirt;
void setup()
{
size(720, 480);
frameRate(600);
audioInit();
info_font = loadFont("PressStartK-16.vlw");
setTitle();
colorMode(HSB);
}
void setTitle()
{
title = true;
game_over = true;
}
void newGame()
{
game_over = false;
title = false;
score = 0;
}
void stop()
{
audioClose();
super.stop();
}
void physicsStep()
{
if(!title)
{
//main game loop
if(keys[UP]) petals++;
if(keys[DOWN]) petals--;
if(keys[LEFT]) HUESCALE-= 0.01;
if(keys[RIGHT]) HUESCALE+= 0.01;
top_score = max(score, top_score);
}
//jukebox stuff
info_time --;
}
void drawingStep()
{
if(title)
{
drawTitle();
}
else
{
background(32,64,96);
for(int i = 0; i < petals; i++)
{
float angle = 1.0/1.618 * i * TWO_PI - PI/4;
float radius = (i+0.5) / petals;
if(squirt) radius = sqrt(radius);
radius = radius * FLOWER_RADIUS;
colorMode(HSB);
fill(int(i * HUESCALE)%255, 255, 255);
noStroke();
ellipseMode(RADIUS);
ellipse(cos(angle)*radius + width/2, sin(angle)*radius + height/2, 10, 10);
}
if(paused) drawPauseOverlay();
}
//jukebox stuff
drawSongInfo();
}
void drawTitle()
{
background(128, 0, 128);
fill(255);
textFont(info_font, 32);
textAlign(CENTER, CENTER);
text("Petal Meter", width/2, height/2);
textFont(info_font, 16);
text("up and down to adjust dot count\nleft and right to adjust hue scale\nspace to toggle square root mode\npress enter", width/2, height*2/3);
}
void drawPauseOverlay()
{
rectMode(CORNER);
strokeWeight(1);
noStroke();
fill(0, 128);
rect(0, 0, width, height);
fill(255);
textFont(info_font, 16);
textAlign(CENTER, CENTER);
text("[ PAUSED ]", width/2, height/2);
}
void draw()
{
while(physics_ms_last + PHYS_MS < millis())
{
if(!paused)
{
physicsStep();
}
physics_ms_last += PHYS_MS;
}
if(drawing_ms_last + DRAW_MS < millis())
{
drawingStep();
drawing_ms_last = millis();
}
}
void keyPressed()
{
if(keyCode < 256)
if(!keys[keyCode])
{
keys[keyCode] = true;
down(keyCode);
}
}
void keyReleased()
{
if(keyCode < 256)
if(keys[keyCode])
{
keys[keyCode] = false;
up(keyCode);
}
}
void down(int theKey)
{
println(theKey + " down");
if(theKey == 'M') jbToggleMute();
if(theKey == 'P' && !title) paused = !paused;
if(theKey == ' ') squirt = !squirt;
if(theKey == ENTER && game_over) newGame();
}
void up(int theKey)
{
println(theKey + " up");
}