I just about have my rpg working. Granted you can't gain any levels, but it at least goes through the routines of figuring out who hits who and whatnot. I have all of the code in the "repeatedly execute" part of the script. The problem is updating the fight. I need to be able to put something in that makes the system check to see if the fight is overwith. If it isn't, it should repeat the fight. I already have an if else statement in the program, but it doesn't work. If I take that out...when you press (f) it will display how one round ended with player vs monster and then you hit fight again and it will have a different monster...it needs to stick with one monster until that monster is dead. Everything is set up with globalints.
int random=Random(20);
if (random==(5 || 15))
{
int battle_screen;
int weapon_screen;
int fight_done=0;
if (fight_done==0)
{
Display("(F)ight/(W)eapon/(I)tem/(E)scape");
if (IsKeyPressed(70)==1)
{
int dmg;
int equip;
string weapon_name;
int enemyhp;
int en_dmg;
int en_hit_per;
int en_evade;
int ran;
string enemy_name;
if (GetGlobalInt(87)==0)
{
if (GetGlobalInt(80)==0)
{
equip=0;
StrCopy(weapon_name,"axe");
dmg=(GetGlobalInt(72));
}
else if (GetGlobalInt(80) == 1)
{
equip=1;
StrCopy(weapon_name,"shotgun");
dmg=(GetGlobalInt(73));
}
else if (GetGlobalInt(80) == 2)
{
equip=2;
StrCopy(weapon_name,"super shotgun");
dmg=(GetGlobalInt(74));
}
else if (GetGlobalInt(80) == 3)
{
equip=3;
StrCopy(weapon_name,"nailgun");
dmg=(GetGlobalInt(75));
}
else if (GetGlobalInt(80) == 4)
{
equip=4;
StrCopy(weapon_name,"super nailgun");
dmg=(GetGlobalInt(76));
}
else if (GetGlobalInt(80) == 5)
{
equip=5;
StrCopy(weapon_name,"grenade launcher");
dmg=(GetGlobalInt(77));
}
else if (GetGlobalInt(80) == 6) {
equip=6;
StrCopy(weapon_name,"rocket launcher");
dmg=(GetGlobalInt(78));
}
else if (GetGlobalInt(80) == 7)
{
equip=7;
StrCopy(weapon_name,"thunderbolt");
dmg=(GetGlobalInt(79));
}
ran=Random(11)+15; //random enemy (enemy speed)
if (ran==16)
{
StrCopy(enemy_name,"Rotweiler");
enemyhp=(GetGlobalInt(5));
en_dmg=(GetGlobalInt(61));
en_hit_per=(GetGlobalInt(38));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==17)
{
StrCopy(enemy_name,"Grunt");
enemyhp=(GetGlobalInt(6));
en_dmg=(GetGlobalInt(62));
en_hit_per=(GetGlobalInt(39));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==18)
{
StrCopy(enemy_name,"Enforcer");
enemyhp=(GetGlobalInt(7));
en_dmg=(GetGlobalInt(63));
en_hit_per=(GetGlobalInt(40));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==19)
{
StrCopy(enemy_name,"Knight");
enemyhp=(GetGlobalInt(8));
en_dmg=(GetGlobalInt(64));
en_hit_per=(GetGlobalInt(41));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==20)
{
StrCopy(enemy_name,"Deathknight");
enemyhp=(GetGlobalInt(9));
en_dmg=(GetGlobalInt(65));
en_hit_per=(GetGlobalInt(42));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==21)
{
StrCopy(enemy_name,"Zombie");
enemyhp=(GetGlobalInt(10));
en_dmg=(GetGlobalInt(66));
en_hit_per=(GetGlobalInt(43));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==22)
{
StrCopy(enemy_name,"Scrag");
enemyhp=(GetGlobalInt(11));
en_dmg=(GetGlobalInt(67));
en_hit_per=(GetGlobalInt(44));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==23)
{
StrCopy(enemy_name,"Ogre");
enemyhp=(GetGlobalInt(12));
en_dmg=(GetGlobalInt(68));
en_hit_per=(GetGlobalInt(45));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==24)
{
StrCopy(enemy_name,"Fiend");
enemyhp=(GetGlobalInt(13));
en_dmg=(GetGlobalInt(69));
en_hit_per=(GetGlobalInt(46));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==25)
{
StrCopy(enemy_name,"Vore");
enemyhp=(GetGlobalInt(14));
en_dmg=(GetGlobalInt(70));
en_hit_per=(GetGlobalInt(47));
en_evade=(GetGlobalInt(ran))/10;
}
else if (ran==26)
{
StrCopy(enemy_name,"Shambler");
enemyhp=(GetGlobalInt(15));
en_dmg=(GetGlobalInt(71));
en_hit_per=(GetGlobalInt(38));
en_evade=(GetGlobalInt(ran))/10;
}
ran=(ran/10);
}
else if ((GetGlobalInt(87) > 0) && (GetGlobalInt(87) < 1000))
{
int player_hp=(GetGlobalInt(0));
int player_speed=(GetGlobalInt(1))/10; //player speed
int player_evade=(GetGlobalInt(2))/10; //player evade %
int hit_per=(GetGlobalInt(3))/10; //player hit %
int wp_per=(GetGlobalInt(4))/10; //weapon %
en_hit_per=GetGlobalInt(en_hit_per)/10; //enemy hit %
int ran2=Random(9);
if ((GetGlobalInt(player_speed))>=(GetGlobalInt(ran)))
{
if ((ran2 <= wp_per) && (ran2 <= hit_per))
{
if (ran2 >= en_evade)
{
Display("You aim your %s and hit %s for %d damage.", weapon_name, enemy_name, dmg); //all hit
enemyhp=(enemyhp - dmg);
Display("%s %d", enemy_name, enemyhp);
}
else if (ran2 < en_evade)
{
Display("%s dodges your attack.",enemy_name);
}
}
else if ((ran2 > wp_per) && (ran2 > hit_per))
{
Display("You miss the %s.",enemy_name);
}
else if ((ran2 > wp_per) && (ran2 <= hit_per))
{
Display("You miss the %s.",enemy_name);
}
else if ((ran2 <= wp_per) && (ran2 > hit_per))
{
Display("You miss the %s.",enemy_name);
}
}
else if ((GetGlobalInt(player_speed))<(GetGlobalInt(ran)))
{
if ((ran2 <= en_hit_per) && (ran2 <= player_evade))
{
Display("You dodge %s attack.", enemy_name); //dodge enemy attack
}
else if ((ran2 <= en_hit_per) && (ran2 > player_evade))
{
Display("%s hits you for %d.", enemy_name, en_dmg);
player_hp=(player_hp - en_dmg);
Display("Jack %d", player_hp);
}
else if ((ran2 > en_hit_per) && (ran2 <= player_evade))
{
Display("You dodge %s attack.", enemy_name);
}
else if ((ran2 > en_hit_per) && (ran2 > player_evade))
{
Display("You dodge %s attack.", enemy_name);
}
if ((player_hp > 0) && (enemyhp <= 0))
{
SetGlobalInt(87, GetGlobalInt(87)+1000);
fight_done=1;
Display("Victory!");
}
else if ((player_hp <= 0) && (enemyhp > 0))
{
SetGlobalInt(87, GetGlobalInt(87)+1000);
Display("Game Over!");
fight_done=1;
RestartGame();
}
else if ((player_hp > 0) && (enemyhp > 0))
{
SetGlobalInt(87, GetGlobalInt(87)+1);
}
}
}
else if (IsKeyPressed(88)==1)
{
Display("(A)xe/(S)hotgun/S(u)per shotgun/(N)ailgun/Su(p)er nailgun/(G)renade launcher/(T)hunderbolt");
if (IsKeyPressed(65)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(83)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(85)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(78)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(80)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(71)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(82)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
if (IsKeyPressed(84)==1)
{
SetGlobalInt(80, GetGlobalInt(80));
}
}
else if (IsKeyPressed(73)==1)
{
Display("(H)ealth/(A)mmo/(S)pecial");
if (IsKeyPressed(72)==1)
{
if (GetGlobalInt(84)==0)
{
Display("You don't have any health packs.");
}
else if (GetGlobalInt(84)!=0)
{
Display("You have %d health packs.");
}
}
else if (IsKeyPressed(65)==1)
{
if (GetGlobalInt(85)==0)
{
Display("You don't have any ammo.");
}
else if (GetGlobalInt(85)!=0)
{
Display("You have %d ammo.");
}
}
else if (IsKeyPressed(83)==1)
{
if (GetGlobalInt(86)==0)
{
Display("You don't have any special items.");
}
else if (GetGlobalInt(86)!=0)
{
Display("You have %s special items.");
}
}
}
else if (IsKeyPressed(69)==1)
{
int escape=Random(1);
if (escape==0)
{
Display("Escape attempt failed.");
}
else if (escape==1)
{
Display("Escape attempt succeeded.");
fight_done=1;
}
}
}
}
}
Well, if the battle system is turn based I'd implement it as a standalone function like ComputeRound(int key) which is called from within on_key_pressed(). So player presses a certain key - thus on_key_pressed runs and calls ComputeRound passing keycode (a key player has pressed) as parameter.
How does Display(...) work? Does it show a text window or displays the text as speech?
Try moving int fight_done=0; outside the repeatedly_execute function because currently it's reset every round and therefore the following if (fight_done==0) is always true.
I would have it as a function, but I haven't worked with functions a whole lot...therefore I wouldn't know how to make the battle update and keep track of health and what weapon and whatnot. Using Display simply just displays what happen. So, basically, if the script determines the a monster would avoid your attack it would simply Display("You miss %s", enemy_name); I would do the CreateTextOverlay but no matter what it always tells me I end up creating too many of them even if I have the RemoveOverlay after each overlay I make. Grrrrrrr.
Yes, that's what I want. And yes, for what I'm trying to accomplish it would be a good idea if I learned how to use functions. I just don't want to have to rewrite the code completely cause it took me a few weeks to simply my 2000+ lines of code down to 200 and have it actually work.
Here is an example I've written to demonstrate what I mean:
// main global script file
//===================================
// Turn-based Battle Script Example:
//===================================
//===============================================================================
//
// It's an example script to demonstrate how a turn-based battle system
// can be implemented.
// The fight consist of several rounds. Each round the player choose
// what his action is.
// To start the fight a 'Fight(int player_class, int enemy_class)'
// function must be called, example:
//
//Ã, Ã, on player enters screen (after fadein):
//
//Ã, Ã, Fight(CLASS_HERO, CLASS_ZOMBIE);
//
//
// 'fight_result' variable can be used to check how combat's progressing.
//
//===============================================================================
// Let's define some names, so instead of 'weapon = 1'
// we could type 'weapon = WEAPON_AXE'
// That will be much more readable :)
// The important thing: any two names in the same group
// shouldn't have identical values assigned.
// Otherwise we couldn't distinguish between, for example,
// CLASS_HERO and CLASS_ZOMBIE.
//-------------------------------------------------------------------------------
// So here we go:
// First some classes. Well, we use CLASS_HERO for our player character.
// Others will be enemies. It doesn't actually matter and we can
// even play the Deathknight :)
#define CLASS_HEROÃ, Ã, Ã, Ã, Ã, Ã, 1 // Hero
#define CLASS_GRUNTÃ, Ã, Ã, Ã, Ã, Ã, 2 // Grunt
#define CLASS_ZOMBIEÃ, Ã, Ã, Ã, Ã, 3 // Zombie
#define CLASS_DEATHKNIGHTÃ, Ã, Ã, 4 // Deathknight
#define CLASS_SCRAGÃ, Ã, Ã, Ã, Ã, Ã, 5 // Scrag
//-------------------------------------------------------------------------------
// Next, some weapons:
#define WEAPON_AXEÃ, Ã, Ã, Ã, Ã, Ã, 1 // Axe
#define WEAPON_SHOTGUNÃ, Ã, Ã, Ã, 2 // Shotgun
#define WEAPON_THUNDERBOLTÃ, Ã, 3 // Thunderbolt (should be a harmfull one :)
//-------------------------------------------------------------------------------
// Now, Fight results. There will be a 'fight_result' variable
// to store one of this values depending on how the fight progresses:
#define FIGHT_RESULT_NONEÃ, Ã, Ã, 0 // Fight isn't started
#define FIGHT_RESULT_FIGHTING 1 // In progress
#define FIGHT_RESULT_ESCAPEDÃ, 2 // Ended - player escaped
#define FIGHT_RESULT_WINÃ, Ã, Ã, 3 // Ended - player won
#define FIGHT_RESULT_LOSSÃ, Ã, Ã, 4 // Ended - player lost
//-------------------------------------------------------------------------------
// We need some kind of a menu so that the player could
// interact by choosing between various options.
// There is a 'menu' variable to store the currently opened menu.
//
//Ã, Ã, x----x
//Ã, Ã, |MAIN|
//Ã, Ã, x----x
//Ã, Ã, Ã, Ã, |-- AttackÃ, Ã, Ã, x-------x
//Ã, Ã, Ã, Ã, |-- Weapons --->|WEAPONS|
//Ã, Ã, Ã, Ã, |-- EscapeÃ, Ã, Ã, x-------x
//Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, |-- Axe
//Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, |-- Shotgun
//Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, |-- Thunderbolt
//
#define MENU_MAINÃ, Ã, Ã, Ã, Ã, Ã, Ã, 1 // Main menu
#define MENU_WEAPONSÃ, Ã, Ã, Ã, Ã, 2 // Weapons list
//-------------------------------------------------------------------------------
// And finally, two names to distinguish between
// the player and his enemies.
#define PLAYERÃ, Ã, Ã, Ã, Ã, Ã, Ã, Ã, 0 // Player
#define ENEMYÃ, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, 1 // Enemy
//-------------------------------------------------------------------------------
// Next, we need a variable to store player's health, weapon, etc.
// attributes. We could, of course, declare a bunch of variables - each one for
// the corresponding attribute, and then repeat the same for the enemy but
// here is a shorter way to go:
//Ã, Ã, Ã, We define a new type (FIGHTER) which will include all the attributes
// we may want to use:
struct FIGHTER {
Ã, Ã, // Attributes:
Ã, Ã, int class;Ã, Ã, Ã, // fighter class (ex: CLASS_HERO, CLASS_GRUNT, etc.)
Ã, Ã, int health;Ã, Ã, // fighter health points
Ã, Ã, int speed;Ã, Ã, Ã, // fighter speed (UNUSED!)
Ã, Ã, int evade;Ã, Ã, Ã, // fighter evade (UNUSED!)
Ã, Ã, int weapon;Ã, Ã, // fighter weapon to attack in the next round;
};
// Ok, as we have the FIGHTER type now, we can declare
// variables of that type.
// But instead of having something like:
//
//Ã, Ã, FIGHTER player;
//Ã, Ã, FIGHTER enemy;
//
// we create an array of two variables of the FIGHTER type.
// This way fighter[ 0 ] will be storing our player attributes
// while fighter[ 1 ] - the enemy ones.
// And do you remember we have PLAYER and ENEMY names
// defined several lines above? They are stand for 0 and 1
// respectively, therefore we can even type:
//
// fighter[PLAYER] is equal to fighter[ 0 ]
// fighter[ENEMY]Ã, is equal to fighter[ 1 ]
// Then we use a dot ('.') to access fighter attributes.
// For example, to set PLAYER health to 100 we have:
//
//Ã, Ã, fighter[PLAYER].health = 100;
//
// The same goes for other attributes.
// And for the enemy, for example:
//
//Ã, Ã, fighter[ENEMY].weapon = WEAPON_AXE;
//
// So here is the array declared:
FIGHTER fighter[2];
//-------------------------------------------------------------------------------
// stores the current menu the player is in:
int menu = MENU_MAIN;
//-------------------------------------------------------------------------------
// stores fight state;
// It can be checked at any time to get info
// on how the fight is progressing:
int fight_result = FIGHT_RESULT_NONE;
//-------------------------------------------------------------------------------
// GetFighterName fills the 'name' string variable
// with the name of the class depending on the 'int class'
// parameter passed in:
function GetFighterName(int class, string name) {
Ã, Ã, StrCopy(name, "Unknown fighter");
Ã,Â
Ã, Ã, ifÃ, Ã, Ã, (class == CLASS_HERO)Ã, Ã, Ã, Ã, StrCopy(name, "Hero");
Ã, Ã, else if (class == CLASS_GRUNT)Ã, Ã, Ã, Ã, StrCopy(name, "Grunt");
Ã, Ã, else if (class == CLASS_ZOMBIE)Ã, Ã, Ã, StrCopy(name, "Zombie");
Ã, Ã, else if (class == CLASS_DEATHKNIGHT) StrCopy(name, "Deathknight");
Ã, Ã, else if (class == CLASS_SCRAG)Ã, Ã, Ã, Ã, StrCopy(name, "Scrag");
}
//-------------------------------------------------------------------------------
// GetWeaponName fills the 'name' string variable
// with the name of the weapon depending on the 'int weapon'
// parameter passed in:
function GetWeaponName(int weapon, string name) {
Ã,Â
Ã, Ã, StrCopy(name, "Unknown weapon");
Ã,Â
Ã, Ã, ifÃ, Ã, Ã, (weapon == WEAPON_AXE)Ã, Ã, Ã, Ã, Ã, StrCopy(name, "Axe");
Ã, Ã, else if (weapon == WEAPON_SHOTGUN)Ã, Ã, Ã, StrCopy(name, "Shotgun");
Ã, Ã, else if (weapon == WEAPON_THUNDERBOLT)Ã, StrCopy(name, "Thunderbolt");
}
//-------------------------------------------------------------------------------
// ComputeAttack calculates the result of the 'attacker' fighter
// attacking 'defender' fighter.
// 'attacker' and 'defender' can either be PLAYER or ENEMY
// if PLAYER attacks ENEMY then we have: ComputeAttack(PLAYER, ENENY);
// if ENEMY attacks PLAYER then we have: ComputeAttack(ENENY, PLAYER);
function ComputeAttack(int attacker, int defender) {
Ã,Â
Ã, Ã, string attackerName;
Ã, Ã, string defenderName;
Ã,Â
Ã, Ã, GetFighterName(fighter[attacker].class, attackerName);
Ã, Ã, GetFighterName(fighter[defender].class, defenderName);
Ã, Ã,Â
Ã, Ã, string weaponName;
Ã, Ã,Â
Ã, Ã, GetWeaponName(fighter[attacker].weapon, weaponName);
Ã,Â
Ã,Â
Ã, Ã, // calculate damage points:
Ã, Ã, int damage_points = 5 * Random(fighter[attacker].weapon);
Ã, Ã,Â
Ã, Ã, // calculate miss chance:
Ã, Ã, int miss_chance = Random(fighter[attacker].weapon);
Ã, Ã,Â
Ã, Ã, // attack result:
Ã, Ã, if (miss_chance == 0)
Ã, Ã, {
Ã, Ã, Ã, Ã, Display("%s misses!", attackerName);
Ã, Ã, }
Ã, Ã, else
Ã, Ã, {
Ã, Ã, Ã, Ã, fighter[defender].health -= damage_points;
Ã, Ã, Ã, Ã, Display("%s aim his %s and hit %s for %d damage.",
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, attackerName, weaponName, defenderName, damage_points);
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, // fight result (if defender's health <= 0):
Ã, Ã, if (fighter[defender].health <= 0)
Ã, Ã, {
Ã, Ã, Ã, Ã, if (attacker == PLAYER) fight_result = FIGHT_RESULT_WIN;
Ã, Ã, Ã, Ã, elseÃ, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, fight_result = FIGHT_RESULT_LOSS;
Ã, Ã, }
}
//-------------------------------------------------------------------------------
// DisplayMenu displays menu (text overlay)
// stored in the 'menu' variable:
int overlay;
function DisplayMenu() {
Ã,Â
Ã, Ã, // remove previously created overlay;
Ã, Ã, if (IsOverlayValid(overlay)) RemoveOverlay(overlay);
Ã, Ã,Â
Ã, Ã,Â
Ã, Ã, // do not draw anything if the fight is finished, just end function.
Ã, Ã, if (fight_result != FIGHT_RESULT_FIGHTING) return;
Ã, Ã,Â
Ã,Â
Ã, Ã, // draw MAIN menu:
Ã, Ã, if (menu == MENU_MAIN)
Ã, Ã, {
Ã, Ã, Ã, Ã, string sMenu;
Ã, Ã, Ã, Ã, StrFormat(sMenu, "(Player:%d / Enemy:%d) (A)ttack / (W)eapons / (E)scape",
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, fighter[PLAYER].health,
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, fighter[ENEMY].health);
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, overlay = CreateTextOverlay(10, 20, 320, 0, 15, sMenu);
Ã, Ã, }
Ã,Â
Ã, Ã, // draw Weapons menu:
Ã, Ã, if (menu == MENU_WEAPONS)
Ã, Ã, {
Ã, Ã, Ã, Ã, overlay = CreateTextOverlay(10, 20, 320, 0, 15,
Ã, Ã, Ã, Ã, "(A)xe / (S)hotgun / (T)hunderbolt");
Ã, Ã, }
Ã,Â
}
//-------------------------------------------------------------------------------
// fight_on_key_pressed reads the player input
// and chooses an action accordingly.
// This function runs many times (each time we press a key)
//
//
//******************************************************************
// NOTE: it must be called from within the on_key_pressed function!
//******************************************************************
function fight_on_key_pressed(int key) {
Ã,Â
Ã, Ã, // if we aren't fighting stop running and return.
Ã, Ã, if (fight_result != FIGHT_RESULT_FIGHTING) return;
Ã,Â
//---------------------------------------------
Ã, Ã, ifÃ, Ã, Ã, (menu == MENU_MAIN)
Ã, Ã, {
Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, ifÃ, Ã, Ã, (key == 'A')
Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, // we attack enemy
Ã, Ã, Ã, Ã, Ã, Ã, if (fight_result == FIGHT_RESULT_FIGHTING) ComputeAttack(PLAYER, ENEMY);
Ã, Ã, Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, Ã, Ã, // now he attacks back (if still alive) :)
Ã, Ã, Ã, Ã, Ã, Ã, if (fight_result == FIGHT_RESULT_FIGHTING) ComputeAttack(ENEMY, PLAYER);
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, if (key == 'W')
Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, menu = MENU_WEAPONS;
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, if (key == 'E')
Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, // on trying to escape:
Ã, Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, Ã, Ã, int escape_chance = Random(1);
Ã, Ã, Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, Ã, Ã, if (escape_chance == 0)
Ã, Ã, Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("Escape attempt failed.");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, // Failed! we have to pay for that :)
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, ComputeAttack(ENEMY, PLAYER);
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, else
Ã, Ã, Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, // thanks god, that was close!
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, fight_result = FIGHT_RESULT_ESCAPED;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("Escape attempt succeeded.");
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, }
Ã, Ã, Ã,Â
Ã, Ã, }
//---------------------------------------------Ã,Â
Ã, Ã, else if (menu == MENU_WEAPONS)
Ã, Ã, {
Ã, Ã, Ã, Ã, // let's see what we have to hurt the thingy with:
Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, ifÃ, Ã, Ã, (key == 'A') fighter[PLAYER].weapon = WEAPON_AXE;
Ã, Ã, Ã, Ã, else if (key == 'S') fighter[PLAYER].weapon = WEAPON_SHOTGUN;
Ã, Ã, Ã, Ã, else if (key == 'T') fighter[PLAYER].weapon = WEAPON_THUNDERBOLT;
Ã, Ã, Ã, Ã, menu = MENU_MAIN;
Ã, Ã, }
//---------------------------------------------Ã,Â
Ã,Â
Ã, Ã, // Just displays the results of the fight:
Ã, Ã, ifÃ, Ã, Ã, (fight_result == FIGHT_RESULT_ESCAPED) Display("Escaped");
Ã, Ã, else if (fight_result == FIGHT_RESULT_WIN)Ã, Ã, Ã, Display("Win");
Ã, Ã, else if (fight_result == FIGHT_RESULT_LOSS)Ã, Ã, Display("Loss");
Ã, Ã, Ã, Ã,Â
Ã, Ã, // Update menu state:
Ã, Ã, DisplayMenu();
}
// Fight initiates the combat itself.
// Use it to assign starting values.
function Fight(int player_class, int enemy_class) {
Ã,Â
Ã, Ã, // Prepare player:
Ã,Â
Ã, Ã, fighter[PLAYER].classÃ, = player_class;
Ã, Ã, fighter[PLAYER].health = 50;
Ã, Ã, fighter[PLAYER].weaponÃ, = WEAPON_AXE;
Ã,Â
Ã, Ã, // Prepare enemy:Ã,Â
Ã,Â
Ã, Ã, fighter[ENEMY].classÃ, Ã, = enemy_class;
Ã, Ã, fighter[ENEMY].healthÃ, = 50;
Ã, Ã, fighter[ENEMY].weaponÃ, = WEAPON_SHOTGUN;
Ã, Ã,Â
Ã, Ã,Â
Ã, Ã, // Fight begins, and from now on the 'fight_on_key_pressed'
Ã, Ã, // function takes care of everything.
Ã, Ã,Â
Ã, Ã, fight_result = FIGHT_RESULT_FIGHTING;
Ã, Ã,Â
Ã, Ã,Â
Ã, Ã, // Select MAIN menu and display it:
Ã, Ã,Â
Ã, Ã, menu = MENU_MAIN;
Ã, Ã, DisplayMenu();
}
function on_key_press(int keycode) {
Ã,Â
Ã, Ã, fight_on_key_pressed(keycode);
Ã,Â
Ã, Ã, if (keycode == 13) Fight(CLASS_HERO, CLASS_GRUNT);
}
[ edited to fix fighter[ENEMY].weaponÃ, = WEAPON_AXE;
- should be fighter[PLAYER].weaponÃ, = WEAPON_AXE; ]
I don't want to sound whiney...but when I was in C++ programming class I understood just about everything, but as soon as the teacher started talking about arrays he lost me.
I understand the concept of functions, but arrays just seem too advanced for me. I will read over your reply several times to try and fully understand it.
Ok, everything makes sense to me now. What did you do to have the battle randomly happen?
How can the function "fight_on_key_press" be put within the "on_key_pressed" function if nested functions aren't supported?