fixed die text

This commit is contained in:
lee2sman 2021-03-25 00:36:20 -04:00
parent da2fa10f3c
commit b494be94e9
1 changed files with 484 additions and 416 deletions

View File

@ -1,484 +1,552 @@
//gobi by lee2sman 2020-21
//an attempt at recreating a lost favorite 90s Mac system 7 or 9 shareware game, original title unknown
let progress = 0, goal = 800, water = 20, food = 20, camelHealth = 5, played = false, searchedPreviously = false
let currentScene, nextScene
let oasisCount = 11, nomadsCount = 8, ruinsCount = 8, desertCount = 14
let oasisImg = [], nomadsImg = [], ruinsImg = [], desertImg = [], cityImg
let soundtrack, insects, camel_noise, camel_cry, waterSnd, grunt, footsteps
let progress = 0,
goal = 800,
water = 20,
food = 20,
camelHealth = 5,
played = false,
searchedPreviously = false;
let currentScene, nextScene;
let oasisCount = 11,
nomadsCount = 8,
ruinsCount = 8,
desertCount = 14;
let oasisImg = [],
nomadsImg = [],
ruinsImg = [],
desertImg = [],
cityImg;
let soundtrack, insects, camel_noise, camel_cry, waterSnd, grunt, footsteps;
function setup() {
if (!played) {
noCanvas();
played = true;
}
function setup(){
if (!played){
noCanvas()
played=true
}
currentScene = chooseScene();
nextScene = chooseScene();
//debug()
currentScene = chooseScene()
nextScene = chooseScene()
//debug()
start();
start()
//load soundtrack
soundFormats("mp3");
soundtrack = loadSound("assets/sound/bg.mp3");
insects = loadSound("assets/sound/insects.mp3");
camel_noise = loadSound("assets/sound/camel_noise.mp3");
camel_cry = loadSound("assets/sound/camel_cry.mp3");
waterSnd = loadSound("assets/sound/water.mp3");
grunt = loadSound("assets/sound/grunt.mp3");
footsteps = loadSound("assets/sound/footsteps.mp3");
//load soundtrack
soundFormats('mp3');
soundtrack = loadSound('assets/sound/bg.mp3')
insects = loadSound('assets/sound/insects.mp3')
camel_noise = loadSound('assets/sound/camel_noise.mp3')
camel_cry = loadSound('assets/sound/camel_cry.mp3')
waterSnd = loadSound('assets/sound/water.mp3')
grunt = loadSound('assets/sound/grunt.mp3')
footsteps = loadSound('assets/sound/footsteps.mp3')
//event loop
//
select("#advance").mousePressed(advance);
select("#rush").mousePressed(rush);
select("#rest").mousePressed(rest);
select("#search").mousePressed(search);
//event loop
//
select('#advance').mousePressed(advance)
select('#rush').mousePressed(rush)
select('#rest').mousePressed(rest)
select('#search').mousePressed(search)
//nav
select('#soundtrack').mousePressed(soundtrackToggle)
select('#restart').mousePressed(restart)
//nav
select("#soundtrack").mousePressed(soundtrackToggle);
select("#restart").mousePressed(restart);
}
function main(){
function main() {
displayStats();
displayStats()
background(255);
if (currentScene.name == "oasis") {
oasis();
} else if (currentScene.name == "nomads") {
nomads();
} else if (currentScene.name == "ruins") {
ruins();
} else if (currentScene.name == "desert") {
desert();
} else {
print("error");
}
background(255)
if (currentScene.name == 'oasis'){
oasis()
} else if (currentScene.name == 'nomads'){
nomads()
} else if (currentScene.name == 'ruins'){
ruins()
} else if (currentScene.name == 'desert'){
desert()
} else {
print('error')
}
//decrease food
food--;
//decrease water
water--;
checkHealth();
checkProgress();
//decrease food
food--
//decrease water
water--
printInfo();
checkHealth()
checkProgress()
printInfo()
// debug()
// debug()
}
function chooseScene(){
let sceneProb = random()
if (sceneProb > 0.92) { //8% chance of oasis
return {
name: 'oasis',
imgNum: int(random(oasisCount))
}
} else if (sceneProb > 0.85){ //7% chance of nomads
return {
name: 'nomads',
imgNum: int(random(nomadsCount))
}
} else if (sceneProb > 0.77){ //8% chance of ruins
return {
name: 'ruins',
imgNum: int(random(ruinsCount))
}
} else {
return {
name: 'desert',
imgNum: int(random(desertCount))
}
}
function chooseScene() {
let sceneProb = random();
if (sceneProb > 0.92) {
//8% chance of oasis
return {
name: "oasis",
imgNum: int(random(oasisCount))
};
} else if (sceneProb > 0.85) {
//7% chance of nomads
return {
name: "nomads",
imgNum: int(random(nomadsCount))
};
} else if (sceneProb > 0.77) {
//8% chance of ruins
return {
name: "ruins",
imgNum: int(random(ruinsCount))
};
} else {
return {
name: "desert",
imgNum: int(random(desertCount))
};
}
}
function start(){
function start() {
select("#photo").attribute("src", "assets/start_end/fort.jpg");
select("#console").html(
"You are a trader, having traveled far and wide along the silk road to buy and sell wares. Now far from home as the season starts to turn you begin the long journey back home, through the Gobi desert.<br><br>You'll need your supplies to hold out, and a little luck, to make it 800km across the desert."
);
select('#photo').attribute('src','assets/start_end/fort.jpg')
select('#console').html("You are a trader, having traveled far and wide along the silk road to buy and sell wares. Now far from home as the season starts to turn you begin the long journey back home, through the Gobi desert.<br><br>You'll need your supplies to hold out, and a little luck, to make it 800km across the desert.")
searchedPreviously = false;
searchedPreviously = false;
}
function displayStats(){
select('#console').html("") //reset text in console
select('#console').html(food+' <em>meals</em> | '+water+' <em>canteens</em> <br> '+progress+' / 800<em> kilometers</em><br><br>')
select('#console').html('<strong>'+currentScene.name.charAt(0).toUpperCase()+ currentScene.name.slice(1)+ '</strong><br><br>',true)
function displayStats() {
select("#console").html(""); //reset text in console
select("#console").html(
food +
" <em>meals</em> | " +
water +
" <em>canteens</em> <br> " +
progress +
" / 800<em> kilometers</em><br><br>"
);
select("#console").html(
"<strong>" +
currentScene.name.charAt(0).toUpperCase() +
currentScene.name.slice(1) +
"</strong><br><br>",
true
);
}
function oasis(){
select('#photo').attribute('src','assets/oasis/'+currentScene.imgNum+'.jpg')
function oasis() {
select("#photo").attribute(
"src",
"assets/oasis/" + currentScene.imgNum + ".jpg"
);
//increaseMileage()
//increaseMileage()
if (random()>0.15){
if (random() > 0.15) {
waterSnd.play();
waterSnd.play()
if (camelHealth < 5) {
camelHealth = 5;
}
//refill water
water = 20;
if (camelHealth < 5){
camelHealth=5
}
//increase food
//refill water
water = 20
food += int(random(2, 5)); //increase food
if (food > 24) food = 24; //but there are limits!
//increase food
displayStats();
food+=int(random(2,5)) //increase food
if (food>24)(food = 24) //but there are limits!
select("#console").html("You refill your water and rest your camel. ");
} else {
//small chance (15%) that it was mirage
displayStats()
displayStats();
select('#console').html("You refill your water and rest your camel. ")
select("#console").html("The oasis you spotted turns out to be a mirage. ");
} else { //small chance (15%) that it was mirage
//hack. works because there are less imagecount for oasis images
select("#photo").attribute(
"src",
"assets/desert/" + currentScene.imgNum + ".jpg"
);
}
displayStats()
//increaseMileage()
}
function nomads() {
select("#photo").attribute(
"src",
"assets/nomads/" + currentScene.imgNum + ".jpg"
);
select('#console').html("The oasis you spotted turns out to be a mirage. ")
let event = random();
if (event < 0.03) {
//3% chance
//hack. works because there are less imagecount for oasis images
select('#photo').attribute('src','assets/desert/'+currentScene.imgNum+'.jpg')
select("#console").html(
"The nomads attack you to get your supplies. They steal all your food and water. ",
true
);
food = 0;
water = 0;
grunt.play();
} else if (event < 0.3) {
//27% chance
select("#console").html(
"The nomads attack and steal some of your food and water. ",
true
);
grunt.play();
food -= int(random(2, 5));
water -= int(random(2, 5));
} else if (event < 0.5) {
//20% chance
select("#console").html(
"This looks like a rough group. You steer wide around their party, hoping they will ignore you. ",
true
);
} else {
//50% chance
displayStats();
select("#console").html(
"The nomads are a friendly group. You travel together for a bit and they give you some food and drink. ",
true
);
water += int(random(2, 8)); //increase water
if (water > 20) water = 20; //but there are limits!
food += int(random(2, 8)); //increase food
if (food > 24) food = 24; //but there are limits!
displayStats();
increaseMileage();
}
}
function ruins() {
select("#photo").attribute(
"src",
"assets/ruins/" + currentScene.imgNum + ".jpg"
);
select("#console").html("You come across some ruins. ", true);
increaseMileage();
}
function desert() {
select("#photo").attribute(
"src",
"assets/desert/" + currentScene.imgNum + ".jpg"
);
increaseMileage();
}
function printInfo() {
if (nextScene.name == "nomads") {
if (random() < 0.7) {
//70% chance of spotting nomads in advance
select("#console").html("You see nomads ahead.", true);
}
} else if (nextScene.name == "ruins") {
if (random() < 0.5) {
//50% chance of spotting ruins in advance
select("#console").html("You see ruins ahead.", true);
}
} else if (nextScene.name == "oasis") {
select("#console").html("You see an oasis ahead!", true);
}
}
function checkHealth() {
if (food < 0 || water < 0) {
if (food < 0 && water < 0) {
select("#console").html("You die of thirst and starvation.", true);
} else if (food < 0) {
select("#console").html("You die of starvation.", true);
} else if (water < 0) {
select("#console").html("You die of thirst.", true);
}
die();
} else if (food < 3 || water < 3) {
if (food < 3 && water < 3) {
select("#console").html("You are hungry and thirsty. ", true);
} else if (food < 3) {
select("#console").html("You are hungry. ", true);
} else if (water < 3) {
select("#console").html("You are thirsty. ", true);
}
} else if (camelHealth < 0) {
die();
} else if (camelHealth < 2) {
camel_noise.play();
select("#console").html("Your camel is very sick. ", true);
} else if (camelHealth < 4) {
camel_cry.play();
select("#console").html("Your camel is sick. ", true);
}
}
function checkProgress() {
if (progress > goal) {
win();
}
}
function die() {
select("#photo").attribute("src", "assets/start_end/bluff.jpg");
select("#console").html(
"The high desert air dries out your body. Wild animals soon come across your corpse, reducing you to bone. Over the weeks and years your remains scatter in the wind, blown up the bluffs, another nomad lost to the desert."
);
if(camelHealth<0){
select("#console").html(
"Your camel is lame, unable to continue on. You start out on foot but the mission to continue is surely impossible. Within days your are exhausted, delirious. Finally you pass out, blanched dry by the seering desert sun, the sand shifting in the wind covering up your remains."
);
}
select(".actions").hide();
select("#rush").hide();
select("#rest").hide();
select("#search").hide();
select("#soundtrack").hide();
//increaseMileage()
}
function nomads(){
select('#photo').attribute('src','assets/nomads/'+currentScene.imgNum+'.jpg')
let event = random()
if (event < 0.03){ //3% chance
select('#console').html("The nomads attack you to get your supplies. They steal all your food and water. ",true)
food = 0
water = 0
grunt.play()
} else if (event < 0.3){ //27% chance
select('#console').html("The nomads attack and steal some of your food and water. ",true)
grunt.play()
food-=int(random(2,5))
water-=int(random(2,5))
} else if (event < 0.5) { //20% chance
select('#console').html("This looks like a rough group. You steer wide around their party, hoping they will ignore you. ",true)
} else { //50% chance
displayStats()
select('#console').html("The nomads are a friendly group. You travel together for a bit and they give you some food and drink. ",true)
water+=int(random(2,8)) //increase water
if (water>20)(water= 20) //but there are limits!
food+=int(random(2,8)) //increase food
if (food>24)(food = 24) //but there are limits!
displayStats()
increaseMileage()
}
}
function ruins(){
select('#photo').attribute('src','assets/ruins/'+currentScene.imgNum+'.jpg')
select('#console').html("You come across some ruins. ",true)
increaseMileage()
}
function desert(){
select('#photo').attribute('src','assets/desert/'+currentScene.imgNum+'.jpg')
increaseMileage()
insects.play();
}
function printInfo(){
if (nextScene.name == 'nomads'){
if (random()<0.7){ //70% chance of spotting nomads in advance
select('#console').html('You see nomads ahead.',true)
}
} else if (nextScene.name == 'ruins'){
if (random()<0.5){ //50% chance of spotting ruins in advance
select('#console').html('You see ruins ahead.',true)
}
} else if (nextScene.name == 'oasis'){
select('#console').html('You see an oasis ahead!',true)
}
function win() {
select("#console").html(
"You crest a dune and see the outskirts of a city with hundreds of tents, market stalls and houses. In the distance is a great body of water. You can't wait to get home with your supplies and fortune. Your friends and family will certainly be pleased to see you. "
);
select("#photo").attribute("src", "assets/start_end/city.jpg");
select(".actions").hide();
select("#rush").hide();
select("#rest").hide();
select("#search").hide();
}
function rush() {
select("#console").html(""); //reset text in console
select("#console").html(
"You rush ahead, pushing your camel to its limit. It injures it slightly."
);
currentScene = nextScene;
nextScene = chooseScene();
//we do this twice! we are advancing fast!
currentScene = nextScene;
nextScene = chooseScene();
increaseMileage();
increaseMileage();
camelHealth -= 2;
footsteps.play();
searchedPreviously = false;
main();
}
function checkHealth(){
if (food < 0){
select('#console').html('You die of starvation.',true)
die()
} else if (food < 3){
function rest() {
displayStats();
select('#console').html('You are hungry. ',true)
}
if (water < 0){
select('#console').html('You die of thirst.',true)
die()
} else if (water < 3){
select('#console').html('You are thirsty. ',true)
}
if (camelHealth < 0){
select('#console').html('Your camel is lame and cannot continue. You set out on foot but soon succumb to the heat. You die of heat stroke.')
die()
} else if (camelHealth < 3){
camel_noise.play()
select('#console').html('Your camel is very sick. ',true)
} else if (camelHealth < 4){
camel_cry.play()
select('#console').html('Your camel is sick. ',true)
}
if (camelHealth < 5) {
camelHealth++;
select("#console").html(
"You and your camel take a much needed rest.",
true
);
} else {
select("#console").html("You rest.", true);
}
//we do not advance when resting
//
//main()
}
function checkProgress(){
if (progress > goal){
win()
}
function search() {
if (!searchedPreviously) {
if (currentScene.name === "ruins") {
let event = random();
if (event < 0.2) {
food += int(random(2, 8)); //increase food
if (food > 24) food = 24; //but there are limits!
displayStats();
select("#console").html(
" You find the remains of some leftover meal abandoned in an old firepit. ",
true
);
} else if (event < 0.4) {
water += int(random(2, 8)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(" You find a canteen with some water. ", true);
} else if (event < 0.55) {
//increase food and water
food += int(random(3, 7)); //increase food
if (food > 24) food = 24; //but there are limits!
water += int(random(3, 6)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You find remnants of an old meal and a bit of water in a basin that you add to your canteen.",
true
);
} else {
displayStats();
select("#console").html(" You don't find anything. ", true);
}
} else {
//print('not at a ruins when searching');
let event = random();
if (event < 0.23) {
//found food
food += int(random(3, 6));
if (food > 24) food = 24; //but there are limits!
displayStats();
select("#console").html(
"You search for food and find some berries that will sustain you for a while.",
true
);
} else if (event < 0.45) {
//add water
water += int(random(3, 5)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You press the bark of some saxaul bushes for a little bit of much-needed water.",
true
);
} else if (event < 0.54) {
//found food and water
food += int(random(3, 6)); //increase food
if (food > 24) food = 24; //but there are limits!
water += int(random(3, 6)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You find some cornmeal and left behind canteens that you eagerly add to your inventory.",
true
);
} else {
displayStats();
select("#console").html(
"You search but don't come across anything you can eat.",
true
);
}
}
searchedPreviously = true;
} else {
displayStats();
select("#console").html(
"You've already searched. No rock has been left unturned.",
true
);
}
}
function die(){
select('#photo').attribute('src','assets/start_end/bluff.jpg')
select('#console').html("The high desert air dries out your body. Wild animals soon come across your corpse, reducing you to bone. Over the weeks and years your remains scatter in the wind, blown up the bluffs, another nomad lost to the desert.")
select('.actions').hide()
select('#rush').hide()
select('#rest').hide()
select('#search').hide()
select('#soundtrack').hide()
insects.play()
function increaseMileage() {
progress += int(random(5, 15));
}
function win(){
select('#console').html("You crest a dune and see the outskirts of a city with hundreds of tents, market stalls and houses. In the distance is a great body of water. You can't wait to get home with your supplies and fortune. Your friends and family will certainly be pleased to see you. ")
function advance() {
select("#console").html(""); //reset text in console
select('#photo').attribute('src','assets/start_end/city.jpg')
//important!
currentScene = nextScene;
nextScene = chooseScene();
select('.actions').hide()
select('#rush').hide()
select('#rest').hide()
select('#search').hide()
}
function rush(){
//small chance of camel improving health
if (camelHealth < 5 && random() < 0.15) {
camelHealth++;
select('#console').html("") //reset text in console
displayStats();
select("#console").html("Your camel is improving"); //reset text in console
}
select('#console').html('You rush ahead, pushing your camel to its limit. It injures it slightly.')
searchedPreviously = false;
currentScene = nextScene
nextScene = chooseScene()
//we do this twice! we are advancing fast!
currentScene = nextScene
nextScene = chooseScene()
increaseMileage()
increaseMileage()
camelHealth-=2
footsteps.play()
searchedPreviously = false;
main()
main();
}
function rest(){
displayStats()
function restart() {
if (soundtrack.isPlaying()) {
//select('#soundtrack').style('background-color','LightSlateGrey');
}
if (camelHealth<5){
camelHealth++
select('#console').html("You and your camel take a much needed rest.",true)
} else {
select('#console').html("You rest.",true)
}
//we do not advance when resting
//
//main()
(progress = 0), (goal = 800), (water = 20), (food = 20), (camelHealth = 5);
select(".actions").show();
select("#rush").show();
select("#rest").show();
select("#search").show();
select("#soundtrack").show();
//nav
//select('#soundtrack').mousePressed(soundtrackToggle)
start();
}
function search(){
if (!searchedPreviously){
if (currentScene.name === "ruins") {
let event = random();
if (event < 0.2) {
food += int(random(2, 8)); //increase food
if (food > 24) food = 24; //but there are limits!
displayStats();
select("#console").html(
" You find the remains of some leftover meal abandoned in an old firepit. ",
true
);
} else if (event < 0.4) {
water += int(random(2, 8)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(" You find a canteen with some water. ", true);
} else if (event < 0.55) { //increase food and water
food += int(random(3, 7)); //increase food
if (food > 24) food = 24; //but there are limits!
water += int(random(3, 6)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You find remnants of an old meal and a bit of water in a basin that you add to your canteen.",
true
);
} else {
displayStats();
select("#console").html(" You don't find anything. ", true);
}
} else { //print('not at a ruins when searching');
let event = random();
if (event < 0.23) { //found food
food += int(random(3, 6));
if (food > 24) food = 24; //but there are limits!
displayStats();
select("#console").html(
"You search for food and find some berries that will sustain you for a while.",
true
);
} else if (event < 0.45) { //add water
water += int(random(3, 5)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You press the bark of some saxaul bushes for a little bit of much-needed water.",
true
);
} else if (event < 0.54) { //found food and water
food += int(random(3, 6)); //increase food
if (food > 24) food = 24; //but there are limits!
water += int(random(3, 6)); //increase water
if (water > 20) water = 20; //but there are limits!
displayStats();
select("#console").html(
" You find some cornmeal and left behind canteens that you eagerly add to your inventory.",
true
);
} else {
displayStats();
select("#console").html(
"You search but don't come across anything you can eat.",
true
);
}
}
searchedPreviously = true;
} else {
displayStats();
select("#console").html(
"You've already searched. No rock has been left unturned.",
true
);
}
function soundtrackToggle() {
if (soundtrack.isPlaying()) {
soundtrack.pause();
select("#soundtrack").html("Soundtrack OFF");
select("#soundtrack").style("background-color", "#d0c8b1");
} else {
soundtrack.loop();
//highlight
select("#soundtrack").html("Soundtrack ON");
select("#soundtrack").style("background-color", "LightSlateGrey");
}
}
function increaseMileage(){
progress+=int(random(5,15))
}
function advance(){
select('#console').html("") //reset text in console
//important!
currentScene = nextScene
nextScene = chooseScene()
//small chance of camel improving health
if (camelHealth<5 && random()<0.15){
camelHealth++;
displayStats()
select('#console').html("Your camel is improving") //reset text in console
}
searchedPreviously = false;
main()
}
function restart(){
if(soundtrack.isPlaying()){
//select('#soundtrack').style('background-color','LightSlateGrey');
}
progress = 0, goal = 800, water = 20, food = 20, camelHealth = 5
select('.actions').show()
select('#rush').show()
select('#rest').show()
select('#search').show()
select('#soundtrack').show()
//nav
//select('#soundtrack').mousePressed(soundtrackToggle)
start()
}
function soundtrackToggle(){
if(soundtrack.isPlaying()){
soundtrack.pause()
select('#soundtrack').html("Soundtrack OFF")
select('#soundtrack').style('background-color','#d0c8b1');
} else {
soundtrack.loop()
//highlight
select('#soundtrack').html("Soundtrack ON")
select('#soundtrack').style('background-color','LightSlateGrey');
}
}
function debug(){
print('currentScene: '+currentScene.name+'| nextScene: '+nextScene.name)
print('food: '+food+' | water: '+water+' | camelHealth: '+camelHealth+' progress: '+progress)
function debug() {
print(
"currentScene: " + currentScene.name + "| nextScene: " + nextScene.name
);
print(
"food: " +
food +
" | water: " +
water +
" | camelHealth: " +
camelHealth +
" progress: " +
progress
);
}