xxxxxxxxxx
298
// try creating some colonists who already exist on the island but are invisible
// when the ship docks with the island, they become visible
let colonial1;
let colonial2;
let colonial3;
let colonial4;
let colonial5;
let northwall;
let southwall;
let eastwall;
let westwall;
let ship;
let shipvx = 0.25;
let shipvy = 0.25;
let island;
let landx = 500;
let landy = 300;
let landsx = 400;
let landsy = 400;
let islandgod;
let ix = 25;
let iy = 25;
let bigjungle;
// function preload() {
// img = loadImage();
// }
function setup() {
createCanvas(800, 600);
score = 10000;
island = createSprite(landx, landy, 400, 400);
island.shapeColor = color('yellow');
bigjungle = createSprite(random(350, 650), random(150, 450), random(75, 100), random(75, 100));
northwall = createSprite(500, 100, 400, 10);
northwall.immovable = true;
northwall.visible = false;
southwall = createSprite(500, 500, 400, 10);
southwall.immovable = true;
southwall.visible = false;
eastwall = createSprite(705, 300, 10, 390);
eastwall.immovable = true;
eastwall.visible = false;
westwall = createSprite(295, 300, 10, 390);
westwall.immovable = true;
westwall.visible = false;
islandgod = createSprite(50, 50, 25, 25);
islandgod.shapeColor = color('green');
colonial1 = createSprite(random(landx - landsx / 2, landx + landsx / 2), random(landy - landsy / 2, landy + landsy / 2), 10, 10);
colonial1.visible = false;
colonial2 = createSprite(random(landx - landsx / 2, landx + landsx / 2), random(landy - landsy / 2, landy + landsy / 2), 10, 10);
colonial2.visible = false;
colonial3 = createSprite(random(landx - landsx / 2, landx + landsx / 2), random(landy - landsy / 2, landy + landsy / 2), 10, 10);
colonial3.visible = false;
colonial4 = createSprite(random(landx - landsx / 2, landx + landsx / 2), random(landy - landsy / 2, landy + landsy / 2), 10, 10);
colonial4.visible = false;
colonial5 = createSprite(random(landx - landsx / 2, landx + landsx / 2), random(landy - landsy / 2, landy + landsy / 2), 10, 10);
colonial5.visible = false;
ship = createSprite(-50, random(0, height), 15, 15);
ship.velocity.x = shipvx;
}
function draw() {
background(255);
text(score, 100, 100);
drawSprites();
colonial1.bounce(northwall);
colonial1.bounce(southwall);
colonial1.bounce(eastwall);
colonial1.bounce(westwall);
colonial2.bounce(northwall);
colonial2.bounce(southwall);
colonial2.bounce(eastwall);
colonial2.bounce(westwall);
colonial3.bounce(northwall);
colonial3.bounce(southwall);
colonial3.bounce(eastwall);
colonial3.bounce(westwall);
colonial4.bounce(northwall);
colonial4.bounce(southwall);
colonial4.bounce(eastwall);
colonial4.bounce(westwall);
colonial5.bounce(northwall);
colonial5.bounce(southwall);
colonial5.bounce(eastwall);
colonial5.bounce(westwall);
if (ship.collide(island) && ship.visible) {
colonial1.velocity.x = random(-1, 1.25);
colonial1.velocity.y = random(-1, 1);
colonial2.velocity.x = random(-1.25, 1);
colonial2.velocity.y = random(-1, 1);
colonial3.velocity.x = random(-1, 1);
colonial3.velocity.y = random(-1, 1.25);
colonial4.velocity.x = random(-1, 1);
colonial4.velocity.y = random(-1.25, 1);
colonial5.velocity.x = random(-2, 2);
colonial5.velocity.y = random(-2, 2);
if (frameCount % 500 == 0) {
colonial1.visible = true;
}
if (frameCount % 750 == 0) {
colonial2.visible = true;
}
if (frameCount % 1000 == 0) {
colonial3.visible = true;
}
if (frameCount % 1250 == 0) {
colonial4.visible = true;
}
if (frameCount % 1500 == 0) {
colonial5.visible = true;
}
}
if (islandgod.overlap(ship)) {
ship.visible = false;
}
if (ship.position.x + ship.width / 2 > width && ship.visible) {
ship.visible = false;
}
if (ship.position.y + ship.height / 2 > height && ship.visible) {
ship.visible = false;
}
if (ship.position.y + ship.height / 2 < 0 && ship.visible) {
ship.visible = false;
}
if (ship.visible == false) {
colonial1.visible = false;
// colonial1.velocity.x = false;
// colonial1.velocity.y = false;
colonial2.visible = false;
// colonial2.velocity.x = false;
// colonial2.velocity.y = false;
colonial3.visible = false;
// colonial3.velocity.x = false;
// colonial3.velocity.y = false;
colonial4.visible = false;
// colonial4.velocity.x = false;
// colonial4.velocity.y = false;
colonial5.visible = false;
// colonial5.velocity.x = false;
// colonial5.velocity.y = false;
{
let diceA = random(0, 1);
if (diceA < 0.33) { // 33% chance this happens
// move from top to bottom
ship.position.x = random(50, width - 50);
ship.position.y = 50;
ship.visible = true;
ship.velocity.y = shipvy;
ship.velocity.x = 0;
} else if (diceA < 0.66) {
// move from bottom to top
ship.position.x = random(50, width - 50);
ship.position.y = 550;
ship.visible = true;
ship.velocity.y = -shipvy;
ship.velocity.x = 0;
} else {
// move from left to right
ship.position.x = 50;
ship.position.y = random(50, height - 50);
ship.visible = true;
ship.velocity.y = 0;
ship.velocity.x = shipvx;
}
}
}
if (colonial1.visible == true) {
text("colonize!", colonial1.position.x, colonial1.position.y - 10);
if (colonial1.overlap(bigjungle)) {
score = score - 1;
push();
noFill();
stroke('red');
rectMode(CENTER);
rect(bigjungle.position.x, bigjungle.position.y, bigjungle.width, bigjungle.height);
pop();
}
}
if (colonial2.visible == true) {
text("i crave meat!", colonial2.position.x, colonial2.position.y - 10);
if (colonial2.overlap(bigjungle)) {
score = score - 1;
push();
noFill();
stroke('red');
rectMode(CENTER);
rect(bigjungle.position.x, bigjungle.position.y, bigjungle.width, bigjungle.height);
}
}
if (colonial3.visible == true) {
text("technology is my god!", colonial3.position.x, colonial3.position.y - 10);
if (colonial3.overlap(bigjungle)) {
score = score - 1;
push();
noFill();
stroke('red');
rectMode(CENTER);
rect(bigjungle.position.x, bigjungle.position.y, bigjungle.width, bigjungle.height);
pop();
}
}
if (colonial4.visible == true) {
text("down with the green!", colonial4.position.x, colonial4.position.y - 10);
if (colonial4.overlap(bigjungle)) {
score = score - 1;
push();
noFill();
stroke('red');
rectMode(CENTER);
rect(bigjungle.position.x, bigjungle.position.y, bigjungle.width, bigjungle.height);
pop();
}
}
if (colonial5.visible == true) {
text("raze this island!", colonial5.position.x, colonial5.position.y - 10);
if (colonial5.overlap(bigjungle)) {
score = score - 1;
push();
noFill();
stroke('red');
rectMode(CENTER);
rect(bigjungle.position.x, bigjungle.position.y, bigjungle.width, bigjungle.height);
pop();
}
}
// collision debug
for (let s of allSprites) {
s.debug = mouseIsPressed;
}
print(mouseX, mouseY);
}
function keyPressed() {
if (key == 'a') {
islandgod.position.x -= ix;
} else if (key == 'd') {
islandgod.position.x += ix;
} else if (key == 'w') {
islandgod.position.y -= iy;
} else if (key == 's') {
islandgod.position.y += iy;
}
}