import ddf.minim.*;
/**
* Game 30: "Somnius ex Machina"
*
*
* Background music written by John Axon.
*
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 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;
PFont font;
int NUM_MOTES = 400;
float NOISE_SPACE_SCALE = 0.006;
float NOISE_TIME_SCALE = 0.0007;
float NOISE_SCROLL_SCALE = 0.002;
float MAX_MOTE_SPEED = 0.6;
float SENSE_RADIUS = 20;
float HILL_ACCEL = 0.007;
float REPEL_RADIUS = 60;
float WIGGLE_PENALTY = 0.0006;
float WIGGLE_DREAM_ADD = 0.00002;
float ESCAPE_PENALTY = 0.1;
float BASE_ALERTNESS_DECAY = 0.0008;
float alert_decay;
float DECAY_DREAM_PENALTY = 1.0;
float SAFE_SPEED = 2.0;
float gravity = 0.01;
float antigravity = 0.01;
float gameover_lift = 0.02;
float slide = 0;
PVector last_mouse;
float alertness;
int dreams;
int physframe = 0;
GameList motes;
float noiseAt(float x, float y)
{
return(noise(x*NOISE_SPACE_SCALE, y*NOISE_SPACE_SCALE + physframe*NOISE_SCROLL_SCALE, physframe*NOISE_TIME_SCALE));
}
AudioPlayer bgm;
void audioInit()
{
minim = new Minim(this);
bgm = minim.loadFile("Somnius Loop Edit One Piece.mp3", 2048);
bgm.loop();
}
void audioClose()
{
bgm.close();
minim.stop();
}
void setup()
{
size(550, 550);
frameRate(600);
audioInit();
newGame();
last_mouse = new PVector(mouseX, mouseY);
font = loadFont("BookAntiqua-BoldItalic-48.vlw");
background(0);
}
void newGame()
{
motes = new GameList();
for(int i = 0; i < NUM_MOTES; i++) motes.add(new Mote());
alertness = 0;
dreams = 0;
physframe = 0;
alert_decay = BASE_ALERTNESS_DECAY;
slide = height/2;
game_over = false;
}
void stop()
{
audioClose();
super.stop();
}
boolean was_out;
void physicsStep()
{
if(!game_over) physframe++;
motes.tick();
if(!game_over) while(motes.size() < NUM_MOTES) motes.add(new Mote());
PVector cur_mouse = new PVector(mouseX, mouseY);
float speed = PVector.dist(cur_mouse, last_mouse);
speed -= SAFE_SPEED;
if(speed > 0) alertness += speed * (WIGGLE_PENALTY + dreams*WIGGLE_DREAM_ADD);
last_mouse = cur_mouse;
if(!game_over) alertness = max(0, alertness - alert_decay);
if(alertness > 1) {
alertness =1;
game_over = true;
}
if(game_over)
{
if(abs(mouseY - slide) < 24)
{
if(slide > mouseY) slide = mouseY + 24;
else slide = mouseY - 24;
}
if(slide < 0 || slide > height) newGame();
}
}
void drawingStep()
{
//background(0);
fill(0, 16);
if(game_over)fill(255, 24);
noStroke();
rect(0, 0, width, height);
if(!game_over)
{
noFill();
strokeWeight(3);
stroke(64);
ellipse(width/2, height/2, height/2, height/2);
stroke(128);
// noFill();
float alr = alertness * height / 2;
ellipse(width/2, height/2, alr, alr);
}
else
{
textFont(font);
textAlign(CENTER, CENTER);
fill(128, 32);
text("Dreams: "+dreams, width/2, slide);
}
noStroke();
strokeWeight(1);
motes.draw();
}
void draw()
{
cursor(CROSS);
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(!keys[keyCode])
{
keys[keyCode] = true;
down(keyCode);
}
}
void keyReleased()
{
if(keys[keyCode])
{
keys[keyCode] = false;
up(keyCode);
}
}
void down(int theKey)
{
println(theKey + " down");
if(theKey == 'M')
{
muted = !muted;
if(muted) bgm.mute();
else bgm.unmute();
}
if(theKey == 'P' && !title) paused = !paused;
}
void up(int theKey)
{
println(theKey + " up");
}