Link Bar

Home | Games | Programming | Tutorials | Donate | Legal (These are mostly empty right now. Placeholders!)

warning code

This website contains adult content.

Thursday, March 15, 2012

Day 24: "Hula" Beta Update

New and Improved Hula beta here.  Source code below the jump.

Notes:
  • Fixed levels, thanks to Zach's excellent suggestion.  Now working as intended.
  • Added NPC "The Janitor."  Still no NPCs in the world, though.
  • Finished the introduction blurb, smoothed the transition into the game proper.
  • Refined the "consult device" mechanic; still not quite sure how I want this to work, but it's backburner material for now.
  • Put fish in the world for the player to mine, one per location (except inside the CoW or the Inner Hoop).
  • Added a "hunger" stat:  each action adds 1 hunger, player receives suggestions to eat at 90+ hunger, loses health at 101+ hunger (eating a fish restores all health and removes all hunger).
  • Sneaking through the CoW's armory now provides ten bullets to the player.  I'll make it a one-time thing later, but I'll need infinity bullets for future playtesting.
  • There is now an empty pistol at the starting screen.
  • Note to self:  not quite sure if cover is working like I want it to (even in the rudimentary build I've got at the moment).  Probably not.  Display auxiliary counters to check.
Zach's been encouraging me to look into object-oriented programming, and I've been putting it off because I have so many good ideas for my simple conditionals and so I wanted to just run with them while the creative juices were flowing.  But I am now thoroughly convinced that OOP will make NPCs way the Hell easier to handle, as I've been thinking about just exactly how to handle them without it, and it seems like a terrible exploding brute force problem.  So I'm going to read up on that over the weekend, and we'll see what I've got by Monday.

OK, that's all for now.  Tomorrow:  back to project 2 in TECS.  Ciao!

Hula source code (Hula_main.cpp):
#include "Hula_Header.h"
#include "stdafx.h"
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>


using namespace std;


// To get log(2)n...  
double Log2( double n )  
{  
if (n==1/2) {
return -1;
}
    // compute log(10)n/log(10)2 (use const b/c windows complains w/2 logs...)  
    else return ((log( n )) / (log ( 2. )));  
}


// CHARACTER INITIALIZATION


int playerActionCount = 0;
int playerAttackCount = 0;
int playerStealthCount = 0;
int playerCoverCount = 0;
int playerHealth = 12;
int playerHunger = 0;
int playerLocation = 4;
string speechDivider[] = {"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"};


// GAME WORLD:
// ZONE NAMES:
string zoneName[] = {"the Column of Winter", "the Rolling Plains", "the Dense Forest", "the Craggy Mountains", "the Inner Hoop"};


// PLACE NAMES:
string placeNameCOW[] = {"Boarding Platform", "Bridge", "Pod Bay", "Crew Quarters", "Cryo Deck", "Armory", "Airlock"};
string placeNameTRP[] = {"the outskirts", "the edge", "the middle", "the middle", "the middle", "the edge", "the outskirts"};
string placeNameTDF[] = {"the outskirts", "the edge", "the middle", "the middle", "the middle", "the edge", "the outskirts"};
string placeNameTCM[] = {"the outskirts", "the edge", "the middle", "the middle", "the middle", "the edge", "the outskirts"};
string placeNameTIH[] = {"the outskirts", "the edge", "the middle", "the middle", "the middle", "the edge", "the outskirts"};


//FULL PLACE TITLE:
//described in GAME WORLD DESCRIPTION


//NPC NAMES:
string npcName[] = {"Catana", "Tiny Kitten", "Little Cat", "Maine Coon", "Tiger", "Frud", "The Janitor", "CoW Drop"};


//INVENTORY ITEMS:
string itemName[] = {"Nunchaku", "Pistol", "Rifle", "Water Pistol", "Water Rifle", "Bullets", "Fish"};


//STARTING INVENTORY:
int playerBullets = 0;
int playerFishCount = 0;
bool inCover = false;
bool havePistol = false;
bool equipPistol = false;
bool haveRifle = false;
bool equipRifle = false;
bool haveWaterPistol = false;
bool equipWaterPistol = false;
bool haveWaterRifle = false;
bool equipWaterRifle = false;
bool haveNunchaku = true;
bool equipNunchaku = false;
bool haveCatana = true;
bool haveJanitor = false;
bool examinedOnce = false;
bool examinedTwice = false;
bool examinedThrice = false;


//WORLD INITIAL CONDITIONS
//FISH
bool locationMined[] = {true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true};
//ITEMS
//NPCs


// PLAYER DEATH:
bool playerDeath = false;


//MAIN FUNCTION!
int _tmain(int argc, _TCHAR* argv[])
{
//PRELIMINARIES:
cout<<"One Man Show"<<endl;
cout<<endl;
cout<<endl;
cout<<"H   H  U   U  L       A"<<endl;
cout<<"H   H  U   U  L      A A"<<endl;
cout<<"H   H  U   U  L     A   A"<<endl;
cout<<"HHHHH  U   U  L  (( A   A ))"<<endl;
cout<<"H   H  U   U  L     A---A"<<endl;
cout<<"H   H  U   U  L     A   A"<<endl;
cout<<"H   H   UUU   LLLL  A   A"<<endl;
cout<<"---------------------------"<<endl;
cout<<"   HOOP-JUMPING REVOLVED"<<endl;
cout<<endl;
cout<<endl;
cout<<"Press 'Ender' to begin a game."<<endl;
char playerAction[10];
cin.getline(playerAction,10);


//PLAYER NAMING and INTRO
cout<<endl;
cout<<"What is your cat's name?"<<endl;
char playerName[100];
cin.getline(playerName,100);
cout<<"Your cat has been promoted to Sergeant " <<playerName <<".  Aren't you proud?\n(Press 'Ender' to continue.)" <<endl;
cin.getline(playerAction,10);
cout<<"Our story begins on a dark and stormy night in space."<<endl;
cout<<"It's always dark and stormy in space, what with the"<<endl;
cout<<"darkness and all the radiation and whatnot."<<endl;
cout<<"(Press 'Ender' to continue.)"<<endl;
cin.getline(playerAction,10);
cout<< speechDivider[0] <<endl;
cout<<"FEMALE VOICE:  Sergeant?"<<endl;
cout<< speechDivider[0] <<endl;
cin.getline(playerAction,10);
cout<< speechDivider[0] <<endl;
cout<<"FEMALE VOICE:  Sergeant " <<playerName <<"?"<<endl;
cout<< speechDivider[0] <<endl;
cin.getline(playerAction,10);
cout<< speechDivider[0] <<endl;
cout<<"FEMALE VOICE:  Sarge!  You need to wake up!"<<endl;
cout<< speechDivider[0] <<endl;
cin.getline(playerAction,10);
cout<<"You wake up inside a cryopod, the haze of interstellar sleep"<<endl;
cout<<"dissipating with the pneumatic hiss of the releasing locks."<<endl;
cout<<"The familiar voice of the shipboard AI crackles in your ear."<<endl;
cout<< speechDivider[0] <<endl;
cout<<"CATANA:  Glad to have you back with us, Sergeant.  Now,"<<endl;
cout<<"ready up!  There's no time to waste!  The Coven Cats have"<<endl;
cout<<"boarded the Column of Winter and slaughtered the crew!"<<endl;
cout<< speechDivider[0] <<endl;
cout<<"Your HUD powers up and confirms Catana's report.  There is a"<<endl;
cout<<"tiny kitten pawing over the remains of a dead lieutenant."<<endl;


//GAME LOOP!
while (playerDeath == false) {

//GAME GOES HERE!

//CALCULATE PLAYER STATS
int playerLevel = Log2((playerActionCount + 1 )/2)+1;
int playerAttackLevel = Log2((playerAttackCount + 1)/2)+1;
int playerStealthLevel = Log2((playerStealthCount + 1)/2)+1;
int playerCoverLevel = Log2((playerCoverCount + 1)/2)+1;
int playerMaxHealth = 12 + (playerLevel * 4);

//GAME WORLD DESCRIPTION
cout<<"You are at the ";
if (playerLocation >= 28) {
cout<<placeNameTIH[playerLocation - 28];
}
else if (playerLocation >= 21) {
cout<<placeNameTCM[playerLocation - 21];
}
else if (playerLocation >= 14) {
cout<<placeNameTDF[playerLocation - 14];
}
else if (playerLocation >= 7) {
cout<<placeNameTDF[playerLocation - 7];
}
else {
cout<<placeNameCOW[playerLocation];
}
cout<<" of " <<zoneName[playerLocation/7] <<"."<<endl;


//PLAYER DESCRIPTION
if (playerHunger >= 90) {
cout<<"You are very hungry and ought to eat some fish."<<endl;
}
if (playerHunger >= 101) {
playerHealth = playerHealth - (playerHunger - 100);
cout<<"You lose " <<(playerHunger - 100) <<" health due to hunger."<<endl;
}
cout<<"You have " <<playerHealth <<" HP and are level " <<playerLevel <<"."<<endl;

//OFFER PLAYER ACTION
cout<<"What do you do?  (Ender 'H' to access Help screen.)"<<endl;
cin.getline(playerAction,10);
cout<<"x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x"<<endl;

//RESOLVE PLAYER ACTION


//QUEST ACTION SUBROUTINE
if (playerAction[0]=='q') {
cout<<"There are no quest actions to be performed here."<<endl;
}


//TRAVEL SUBROUTINE
if (playerAction[0]=='w') {
cout<<"You advance through " <<zoneName[playerLocation/7] <<"."<<endl;
playerLocation = playerLocation +1;
playerActionCount = playerActionCount +1;
playerHunger = playerHunger +1;
inCover = false;
}


//RETREAT SUBROUTINE (R)
if (playerAction[0]=='r') {
cout<<"You retreat back through " <<zoneName[playerLocation/7] <<"."<<endl;
playerLocation = playerLocation -1;
playerActionCount = playerActionCount +1;
playerHunger = playerHunger +1;
inCover = false;
}


//EAT FISH SUBROUTINE (E)
if (playerAction[0]=='e') {
if (playerFishCount==0) {
cout<<"You have no fish to eat."<<endl;
}
else {
cout<<"You eat a fish and restore your health."<<endl;
playerFishCount = playerFishCount -1;
playerHealth = playerMaxHealth;
playerActionCount = playerActionCount + 1;
playerHunger = 0;
}
}


//ATTACK SUBROUTINE (A)
if (playerAction[0]=='a') {
cout<<"There is nobody to attack here."<<endl;
}


//STEALTH SUBROUTINE (S)
if (playerAction[0]=='s') {
if (playerLocation == 5) {
cout<<"Sneaking through the CoW's Armory, you find ten bullets."<<endl;
playerBullets = playerBullets + 10;
playerLocation = playerLocation + 1;
}
else cout<<"There is nobody to sneak past here."<<endl;
}


//DEVICE SUBROUTINE (D)
if (playerAction[0]=='d') {
cout<<"You consult ";
if (haveCatana==true) {
cout<< npcName[0] <<"."<<endl;
} else cout<< npcName[6] <<"."<<endl;
cout<< speechDivider[0] <<endl;
//CONDITIONAL DIALOGUE BASED ON DEVICE AND LOCATION
}


//MINE FOR FISH SUBROUTINE (F)
if (playerAction[0]=='f') {
if (playerLocation<=6) {
cout<<"You can't mine for fish inside a spaceship, stupid."<<endl;
}
else if (locationMined[playerLocation] == false) {
cout<<"You sniff around and find a fish to dig up."<<endl;
playerFishCount = playerFishCount +1;
playerHunger = playerHunger +1;
playerActionCount = playerActionCount +1;
locationMined[playerLocation] = true;
}
else if (locationMined[playerLocation] == true) {
cout<<"There are no fish to be mined here."<<endl;
}
}


//COVER SUBROUTINE (C)
if (playerAction[0]=='c') {
if (inCover==true) {
cout<<"You're already behind cover."<<endl;
}
if (playerLocation/7==1) {
cout<<"You can't find any cover in " <<zoneName[playerLocation/7] <<"."<<endl;
}
cout<<"You take cover behind ";
if (playerLocation/7==0) {
cout<<"a doorway";
}
if (playerLocation/7==2) {
cout<<"a tree";
}
if (playerLocation/7==3) {
cout<<"a rock";
}
if (playerLocation/7==4) {
cout<<"a corner";
}
cout<<"."<<endl;
playerHunger = playerHunger +1;
playerActionCount = playerActionCount +1;
playerCoverCount = playerCoverCount +1;
inCover = true;
}
//EXAMINE SUBROUTINE (X)
if (playerAction[0]=='x') {
cout<<"You spend a moment taking in your surroundings."<<endl;
if (examinedOnce==true) {
if (examinedTwice==true) {
if (examinedThrice==true) {
cout<<"You have seen all that there is to see.\nDo not gaze too harshly, or you shall see no more."<<endl;
}
else {
cout<<"You perceive the ultimate nature of reality, but cannot put it into words."<<endl;
examinedThrice=true;
}
}
else {
cout<<"You begin to see the connections among all things, and you feel at one with the world."<<endl;
examinedTwice=true;
}
}
if (examinedOnce==false) {
cout<<"Looking closely at the world, you begin to see the beauty in all things."<<endl;
examinedOnce=true;
}
}
//TAKE ITEM SUBROUTINE (Z)
if (playerAction[0]=='z') {
if (playerLocation == 4) {
if (havePistol == false) {
cout<<"You find an empty pistol on the dead lieutenant's body."<<endl;
havePistol = true;
}
else cout<<"There are no more items here for you to take."<<endl;
}
else cout<<"There are no items here for you to take."<<endl;
}


//INVENTORY SUBROUTINE (I)
if (playerAction[0]=='i') {
cout<<"You have ";
if (havePistol==true) {
cout<<"a " <<itemName[1] <<", ";
} else {cout<<"";}
if (haveRifle==true) {
cout<<"a " <<itemName[2] <<", ";
} else {cout<<"";}
if (haveWaterPistol==true) {
cout<<"a " <<itemName[3] <<", ";
} else {cout<<"";}
if (haveWaterRifle==true) {
cout<<"a " <<itemName[4] <<", ";
} else {cout<<"";}
cout<<endl <<playerBullets <<" bullets, " <<playerFishCount <<" fish, and a pair of nunchaku."<<endl;
cout<<"To equip an item, enter 1 for your Pistol, 2 for Rifle,"<<endl;
cout<<"3 for Water Pistol, 4 for Water Rifle, or 5 for Nunchaku."<<endl;
char equipItem[10];
cin.getline(equipItem,10);
if (equipItem[0]==1) {
if (havePistol = true) {
equipPistol = true;
equipRifle = false;
equipWaterPistol = false;
equipWaterRifle = false;
equipNunchaku = false;
} else {cout<<"You have no pistol to equip."<<endl;}
}
if (equipItem[0]==2) {
if (haveRifle = true) {
equipPistol = false;
equipRifle = true;
equipWaterPistol = false;
equipWaterRifle = false;
equipNunchaku = false;
} else {cout<<"You have no rifle to equip."<<endl;}
}
if (equipItem[0]==3) {
if (haveWaterPistol = true) {
equipPistol = false;
equipRifle = false;
equipWaterPistol = true;
equipWaterRifle = false;
equipNunchaku = false;
} else {cout<<"You have no water pistol to equip."<<endl;}
}
if (equipItem[0]==4) {
if (haveWaterRifle = true) {
equipPistol = false;
equipRifle = false;
equipWaterPistol = false;
equipWaterRifle = true;
equipNunchaku = false;
} else {cout<<"You have no water rifle to equip."<<endl;}
}
if (equipItem[0]==5) {
if (haveNunchaku = true) {
equipPistol = false;
equipRifle = false;
equipWaterPistol = false;
equipWaterRifle = false;
equipNunchaku = true;
} else {cout<<"You have no nunchaku to equip.  How did that happen?"<<endl;}
} else {cout<<"You can't equip that."<<endl;}
}


//HELP SUBROUTINE (H)
if (playerAction[0]=='h') {
cout<<"You are able to take the following actions:"<<endl;
cout<<"W - Move forward through the world,"<<endl;
cout<<"R - Move backward (retreat) through the world."<<endl;
cout<<"Q - Perform Quest action.  E - Eat fish."<<endl;
cout<<"A - Attack enemies.  S - Sneak past enemies."<<endl;
cout<<"D - Consult Device AI.  F - Mine for fish."<<endl;
cout<<"C - Take cover. X - Examine surroundings."<<endl;
cout<<"Z - Take item.  I - Inventory."<<endl;
}

//DEATH CONDITION:
if (playerHealth<=0) {
playerDeath = true;
}


//END OF TURN DIVIDER:
cout<<"x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x"<<endl;
}

cout<<"The game is now over.  Press 'Ender' to quit."<<endl;
//GAME ENDS
return 0;
}

No comments:

Post a Comment