Game 41: "Circus Peanuts: Jam edition"
Press Enter to start.
X = sword, Z = rocks, A = bombs, arrow keys = move, P = pause, M = mute.
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;
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;
int game_mode = -1;
int PC_MAX_LIFE = 6;
int pc_life;
int BASIC_SPRITE_RADIUS = 20;
float SMOOTH_GROUND_THRESH = 2;
color SAND_COLOR = color(247, 215, 164);
color[] floor_color = {color(160, 225, 120), color(120, 200, 90), color(255, 225, 174), color(235, 205, 150), color(128, 128, 128), color(108, 128, 108), color(108, 88, 88)};
color[] wall_color = {color(192, 192, 192), color(192, 192, 192),color(192, 192, 192),color(192, 192, 192),color(192, 192, 192),color(192, 192, 192),color(192, 192, 192)};
PVector pc_facing;
int SWORD_TIME = 30;
boolean has_16bit_sword;
boolean has_spin_attack;
boolean has_bombs;
boolean has_slingshot;
int carried_bombs;
int carried_rocks;
int max_bombs;
int max_rocks;
int START_BOMBS = 5;
int START_ROCKS = 10;
Minim minim;
AudioSample swordSound;
AudioSample bushSound;
AudioSample peanutSound;
AudioSample heartSound;
AudioSample painSound;
AudioSample killSound;
AudioSample hitSound;
AudioSample gotSound;
AudioSample secretSound;
AudioSample blonkSound;
AudioSample rockSound;
AudioSample bombSound;
void audioInit()
{
minim = new Minim(this);
swordSound = minim.loadSample("sword.wav", 1024);
bushSound = minim.loadSample("bush.wav", 1024);
peanutSound = minim.loadSample("peanut.wav", 1024);
heartSound = minim.loadSample("heart.wav", 1024);
painSound = minim.loadSample("pain.wav", 1024);
killSound = minim.loadSample("kill.wav", 1024);
hitSound = minim.loadSample("hit.wav", 1024);
gotSound = minim.loadSample("gotathing.wav", 1024);
secretSound = minim.loadSample("secret.wav", 1024);
blonkSound = minim.loadSample("blonk.wav", 1024);
rockSound = minim.loadSample("rock.wav", 1024);
bombSound = minim.loadSample("bomb.wav", 1024);
}
void audioClose()
{
minim.stop();
swordSound.close();
bushSound.close();
peanutSound.close();
heartSound.close();
painSound.close();
killSound.close();
hitSound.close();
gotSound.close();
secretSound.close();
blonkSound.close();
rockSound.close();
bombSound.close();
}
GameList stuff = new GameList();
GameList sprites = new GameList();
ArrayList blocks = new ArrayList();
ArrayList done_rooms = new ArrayList();
PlayerSprite pc;
int pc_busy_timer;
int room_x;
int room_y;
int room_z;
float DANGER_XY_SCALE = 0.3;
float DANGER_Z_SCALE = PI;
int DUNGEON_THRESH = 3;
float roomDanger(int rmx, int rmy, int rmz)
{
return 7 * noise(rmx * DANGER_XY_SCALE + 128, rmy * DANGER_XY_SCALE + 128, rmz * DANGER_Z_SCALE + 128);
}
void buildRoom()
{
int x = room_x; int y = room_y; int z = room_z;
int room_level = (int)roomDanger(x, y, z);
if(room_level > DUNGEON_THRESH) bgmLoopPolite("obstinate_dungeon.mp3"); else bgmLoopPolite("peanut_field.mp3");
blocks.clear();
sprites.clear();
sprites.add(pc);
blocks.addAll(transitionDecorations(x, y, z));
blocks.addAll(northWall(x, y, z));
blocks.addAll(southWall(x, y, z));
blocks.addAll(eastWall(x, y, z));
blocks.addAll(westWall(x, y, z));
blocks.addAll(nwCorner(x, y, z));
blocks.addAll(neCorner(x, y, z));
blocks.addAll(swCorner(x, y, z));
blocks.addAll(seCorner(x, y, z));
if(poi(x, y, z) == 0) spawnOrdinaryStuff();
else spawnSpecialStuff();
if(hasDown(x, y, z-1) && room_z > 0) sprites.add(new StairsUp());
}
int random_step;
int GEOGRAPHY = 0;
int CHEST = 1;
int STAIRS_DOWN = 2;
int BOSS = 3;
int PLAIN = 0;
int ALL_ENEMIES_DEAD = 1;
int SECRET_SWITCH = 2;
void giveSpecial()
{
randomSeed(6 + room_x + 256 * room_y + 65535 * room_z);
int prize_peanuts = 1 + (int)random(hereLevel() + room_z * 2) + room_z;
int type = int(random(3));
if(type == 2 && max_bombs <= START_BOMBS * room_z)
{
max_bombs += START_BOMBS;
carried_bombs += START_BOMBS;
particles.add(new PrizeParticle(START_BOMBS, BOMBS));
}
else if(type == 1 && max_rocks <= START_ROCKS * room_z)
{
max_rocks += START_ROCKS;
carried_rocks += START_ROCKS;
particles.add(new PrizeParticle(START_ROCKS, ROCKS));
}
else
{
prize_peanuts *= 10;
pc_score += prize_peanuts;
particles.add(new PrizeParticle(prize_peanuts, PEANUTS));
}
}
boolean hasDown(int x, int y, int z)
{
if(poi(x, y, z) >= 1 && (int)roomDanger(x, y, z + 1) > DUNGEON_THRESH/*roomDanger(x, y, z)*/ && (int)roomDanger(x, y, z) > DUNGEON_THRESH) return true;
else return false;
}
float roomScary(int x, int y, int z)
{
return(roomDanger(x, y, z) + z);
}
void spawnSpecialStuff()
{
randomSeed(8 + room_x + 256 * room_y + 65535 * room_z);
int special_type = 0;
if(hereLevel() > DUNGEON_THRESH)
{
if(poi(room_x, room_y, room_z) >= 1)
{
if(hasDown(room_x, room_y, room_z)) special_type = STAIRS_DOWN;
else special_type = CHEST;
}
else special_type = (int)random(2);
}
int special_trigger = (int)random(2);
if(special_type == STAIRS_DOWN)
{
sprites.add(new StairsDown());
spawnOrdinaryStuff();
}
if(done_rooms.contains(new PVector(room_x, room_y, room_z)))
{
if(special_type == CHEST) blocks.add(new EmptyChest());
}
else
{
if(special_type == CHEST)
{
if(special_trigger == ALL_ENEMIES_DEAD)
{
blocks.add(new HidingChest());
spawnFoes(hereLevel()*2 + room_z * 3);
}
else
blocks.add(new FullChest());
}
}
}
void spawnOrdinaryStuff()
{
randomSeed(8 + room_x + 256 * room_y + 65535 * room_z);
int room_level = (int)roomDanger(room_x, room_y, room_z);
if(room_level < DUNGEON_THRESH)
{
for(int x = -3; x <= 3; x++) for(int y = -3; y <= 3; y++)
{
if(random(1) < 0.08) blocks.add(new Bush(width/2 + x * BASIC_SPRITE_RADIUS * 3, height/2 + y * BASIC_SPRITE_RADIUS * 3));
}
}
spawnFoes(hereLevel() + random(hereLevel() + room_z * 3));
}
void spawnFoes(float difficulty)
{
if(hereLevel() > DUNGEON_THRESH) //dungeon enemies
{
if(difficulty > 100)
{}
else if(difficulty > 10)
{
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 9.8)
{
sprites.add(new MetalSlime(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 8)
{
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 7)
{
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 6)
{
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 5)
{
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Bat(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 4)
{
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
}
}
else //field enemies
{
if(difficulty > 100)
{}
else if(difficulty > 4)
{
sprites.add(new Copter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Copter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Copter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Copter(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 3.8)
{
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 3.5)
{
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 3)
{
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new WanderDude(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 2.5)
{
sprites.add(new Spitter(random(width/2)+width/4, random(height/2)+height/4));
}
else if(difficulty > 2)
{
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
sprites.add(new Slime(random(width/2)+width/4, random(height/2)+height/4));
}
}
}
float roomRandom(float x, float y, float z)
{
return noise(x * 0.23, y * 0.23, z*0.23 + random_step++);
}
ArrayList transitionDecorations(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx, rmy-1, rmz))
{
wall_blocks.add(new Decoration(width/2, 0, width/2, height/10,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx, rmy-1, rmz)], 0.25)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx, rmy+1, rmz))
{
wall_blocks.add(new Decoration(width/2, height, width/2, height/10,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx, rmy+1, rmz)], 0.25)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx-1, rmy, rmz))
{
wall_blocks.add(new Decoration(0, height/2, height/10, height,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx-1, rmy, rmz)], 0.25)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx+1, rmy, rmz))
{
wall_blocks.add(new Decoration(width, height/2, height/10, height,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx+1, rmy, rmz)], 0.25)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx, rmy-1, rmz))
{
wall_blocks.add(new Decoration(width/2, 0, width/2, height/30,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx, rmy-1, rmz)], 0.5)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx, rmy+1, rmz))
{
wall_blocks.add(new Decoration(width/2, height, width/2, height/30,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx, rmy+1, rmz)], 0.5)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx-1, rmy, rmz))
{
wall_blocks.add(new Decoration(0, height/2, height/32, height,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx-1, rmy, rmz)], 0.5)));
}
if((int)roomDanger(rmx, rmy, rmz) != (int)roomDanger(rmx+1, rmy, rmz))
{
wall_blocks.add(new Decoration(width, height/2, height/32, height,
blendColors(floor_color[(int)roomDanger(rmx, rmy, rmz)], floor_color[(int)roomDanger(rmx+1, rmy, rmz)], 0.5)));
}
return wall_blocks;
}
ArrayList nwCorner(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
if(!northWall(rmx, rmy, rmz).isEmpty() || !westWall(rmx, rmy, rmz).isEmpty() ||
!northWall(rmx-1, rmy, rmz).isEmpty() || !westWall(rmx, rmy-1, rmz).isEmpty())
wall_blocks.add(new Block(0, 0, height/8, height/8, B_SOLID));
return wall_blocks;
}
ArrayList neCorner(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = nwCorner(rmx + 1, rmy, rmz);;
for(Block b : wall_blocks) b.pos.x += width;
return wall_blocks;
}
ArrayList swCorner(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = nwCorner(rmx, rmy+1, rmz);
for(Block b : wall_blocks) b.pos.y += height;
return wall_blocks;
}
ArrayList seCorner(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = nwCorner(rmx+1, rmy+1, rmz);
for(Block b : wall_blocks){b.pos.x += width; b.pos.y += height;}
return wall_blocks;
}
int poi(int x, int y, int z)
{
float my_d = roomDanger(x, y, z);
if(my_d > roomDanger(x-1, y-1, z) &&
my_d > roomDanger(x, y-1, z) &&
my_d > roomDanger(x+1, y-1, z) &&
my_d > roomDanger(x-1, y, z) &&
my_d > roomDanger(x+1, y, z) &&
my_d > roomDanger(x-1, y+1, z) &&
my_d > roomDanger(x, y+1, z) &&
my_d > roomDanger(x+1, y+1, z))
return 1;
if(my_d < roomDanger(x-1, y-1, z) &&
my_d < roomDanger(x, y-1, z) &&
my_d < roomDanger(x+1, y-1, z) &&
my_d < roomDanger(x-1, y, z) &&
my_d < roomDanger(x+1, y, z) &&
my_d < roomDanger(x-1, y+1, z) &&
my_d < roomDanger(x, y+1, z) &&
my_d < roomDanger(x+1, y+1, z))
return -1;
return 0;
}
ArrayList northWall(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
if(((int)roomDanger(rmx, rmy, rmz) > DUNGEON_THRESH && (int)roomDanger(rmx, rmy-1, rmz) <= DUNGEON_THRESH))
wall_blocks.add(new Block(width/2, 0, width/2, height/8, B_SOLID));
if(((int)roomDanger(rmx, rmy-1, rmz) > DUNGEON_THRESH && (int)roomDanger(rmx, rmy, rmz) <= DUNGEON_THRESH))
{
float my_d = roomDanger(rmx, rmy, rmz);
if(my_d > roomDanger(rmx-1, rmy, rmz) && my_d > roomDanger(rmx+1, rmy, rmz) && rmz == 0)
{
// wall_blocks.add(new DoorShade(width/2, 0, width/4, height/10));
// wall_blocks.add(new DoorShade(width/2, 0, width/4, height/30));
wall_blocks.add(new Block(width/5, 0, width/5, height/8, B_SOLID));
wall_blocks.add(new Block(width*4/5, 0, width/5, height/8, B_SOLID));
}
else
wall_blocks.add(new Block(width/2, 0, width/2, height/8, B_SOLID));
}
return wall_blocks;
}
ArrayList westWall(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
if(((int)roomDanger(rmx, rmy, rmz) > DUNGEON_THRESH && (int)roomDanger(rmx-1, rmy, rmz) <= DUNGEON_THRESH))
wall_blocks.add(new Block(0, height/2, height/8, height/2, B_SOLID));
if(((int)roomDanger(rmx-1, rmy, rmz) > DUNGEON_THRESH && (int)roomDanger(rmx, rmy, rmz) <= DUNGEON_THRESH))
{
wall_blocks.add(new Block(0, height/2, height/8, height/2, B_SOLID));
}
return wall_blocks;
}
ArrayList southWall(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
wall_blocks.addAll(northWall(rmx, rmy+1, rmz));
for(Block b : wall_blocks) b.pos.y += height;
return wall_blocks;
}
ArrayList eastWall(int rmx, int rmy, int rmz)
{
ArrayList wall_blocks = new ArrayList();
wall_blocks.addAll(westWall(rmx+1, rmy, rmz));
for(Block b : wall_blocks) b.pos.x += width;
return wall_blocks;
}
void setup()
{
size(640, 560);
frameRate(600);
audioInit();
info_font = loadFont("PressStartK-16.vlw");
title = true;
/*
stuff.add(new Mote(new PVector(width/6 * 2, height * 2 / 3), M_RED));
stuff.add(new Mote(new PVector(width/6 * 3, height * 2 / 3), M_GREEN));
stuff.add(new Mote(new PVector(width/6 * 4, height * 2 / 3), M_BLUE));
Source code: ld19_circus_peanuts_jam Classes Jukebox Utility_Stuff
Built with Processing