Hello. I really need help with adding graphics. I have skimmed through multiple tutorials, but all of them have been wicked long, and I honestly don't know how to execute them properly.
So I was wondering if any of you had a code snippet that would allow me to add a single 2d image. If you do, please post it here and I will be extremely grateful. Thank you!!!
BTW, here is my text-based rpg game:
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
//used to maximize screen
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
using namespace std;
int main()
{
//tells screen to maximize
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd,SW_MAXIMIZE);
cout << "********************************************************************************";
cout << "****************************** ***************** *******************************";
cout << "**************************** ******************* ****************************";
cout << "************************* ************************ *************************";
cout << "********************** **************************** **********************";
cout << "******************** ****************************** *******************";
cout << "****************** ******************************** ****************";
cout << "**************** ****** ** * * * ****** **************";
cout << "************** ******* ** * *** * * * * * * ******* ************";
cout << "************* ******* *** * ** * * * * * * ******** ***********";
cout << "************ ******* *** * *** * * * * * * ******** ***********";
cout << "*********** ******* ** * *** * * * * * * ******** **********";
cout << "*********** ****** ** * *** * * * ******* **********";
cout << "*********** * ********************************** * **********";
cout << "*********** ** * ****************************** * ** ***********";
cout << "************ ** * ***************************** ** ** ***********";
cout << "************* * *** ** ******************************* ******* * ************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "************************* *************************** *******************";
cout << "**************************** *********************** **********************";
cout << "******************************* ******************** ************************";
cout << "********************************* ****************** **************************";
cout << "******************** ************* **************** ************* **************";
cout << "********************* ********** ************** ********** ***************";
cout << "********************* ******* ************ ******* ***************";
cout << "******************** ********** ********** ********** **************";
cout << "******************** ****** **** ******** ***** ****** **************";
cout << "********************* **** *************** **** ***************";
cout << "*********************** ************* ******************";
cout << "************************************ ********** ******************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "******************************* ********************** *************************";
cout << "********************************* ****************** ****** ********************";
cout << "************************** ******* **************** ******** *******************";
cout << "************************* *** **** ************** ***** *** ******************";
cout << "**************************** ********************* *********************";
cout << "****************************** ******************* ***********************";
cout << "****************** ************ ***************** *************************";
cout << "***************** * ************ ***************** ************ *************";
cout << "************** * *** ************* *************** ************* * * **********";
cout << "*************** ***** ***** ********************************** *** **********";
cout << "*************** ******* *** * ********************* ********** **** ***********";
cout << "************************ * *** ******************* ********* *****************";
cout << "************************* ***** ************ **** * ******* ******************";
cout << "************************* ******* ********** * ** *** ***** *******************";
cout << "************************* ******** ***** ** *** ***** *** ********************";
cout << "*********************************** *** * **** ******** * *********************";
cout << "************************************ * * *************** **********************";
cout << "************************************* *** **************************************";
cout << "************************************* ******************************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
cout << "********************************************************************************";
Beep(300,100);
Beep(100,100);
Beep(300,100);
Beep(100,300);
Beep(300,100);
Beep(150,100);
Beep(300,100);
Beep(100,100);
Beep(300,100);
Beep(150,300);
Beep(350,100);
Beep(200,100);
Beep(250,100);
Beep(150,100);
Beep(350,100);
Beep(200,300);
Beep(300,100);
Beep(200,100);
Beep(300,100);
Beep(150,100);
Beep(300,100);
Beep(120,300);
Beep(300,100);
Beep(190,100);
Beep(300,100);
Beep(140,100);
Beep(300,100);
Beep(170,300);
Beep(360,100);
Beep(130,100);
Beep(300,100);
Beep(120,100);
Beep(300,100);
Beep(190,300);
Beep(300,100);
Beep(150,100);
Beep(300,100);
Beep(150,100);
Beep(300,100);
Beep(100,300);
Beep(150,200);
Beep(200,200);
Beep(250,300);
system("cls");
int random3, random4, random5;
srand ((unsigned)time(0));
random3 = (rand() % 4) + 1;
random4 = (rand() % 4) + 1;
random5 = (rand() % 4) + 1;
int person, opponent, atk, asuccess, msuccess, game = 1, counter1=1, level = 1, atr, a, b, c = 0, d;
//opponent
int attackop, defenseop, speedop, healthop = 100, opac;
//user
int magicus, attackus, defenseus, speedus, healthus = 100;
//names
string nameus, nameop;
//classes
int healus = 0;
do{
cout << "(1)\n***************\nThe Wizard:\n attack - 30\n defense - 40\n magic - 60\n speed - 60\n***************" << endl << endl;
cout << "(2)\n***************\nThe Knight:\n attack - 50\n defense - 75\n magic - 40\n speed - 30\n***************" << endl << endl;
cout << "(3)\n***************\nThe Berzerker:\n attack - 60\n defense - 50\n magic - 30\n speed - 50\n***************" << endl << endl;
cout << "(4)\n***************\nThe Banshee:\n attack - 40\n defense - 40\n magic - 50\n speed - 65\n***************" << endl << endl;
cout << "(5)\n***************\nThe Goblin:\n attack - 60\n defense - 65\n magic - 30\n speed - 40\n***************" << endl << endl;
cout << "(6)\n***************\nThe Demon:\n attack - 65\n defense - 70\n magic - 25\n speed - 30\n***************" << endl << endl;
cout << "Which Class would you like to be?: ";
cin >> person;
if((person > 6)&&(person != 666))
{
system("cls");
cout << "You must enter an integer between 1 and 6!!!!\n\n";
system("pause");
system("cls");
}
if(person == 666)
{
system("cls");
cout << "Muahahahaha!! You have unleashed Satan!!!";
cout << "\n***************\nSatan:\n attack - 100\n defense - 100\n magic - 100\n speed - 100\n***************" << endl << endl;
Beep(300,200);
Sleep(100);
Beep(200,200);
Sleep(100);
Beep(100,200);
Sleep(100);
Beep(100,100);
Beep(125,50);
Beep(150,50);
Beep(125,50);
Beep(100,200);
system("pause");
system("cls");
}
}while((person > 6)&&(person != 666));
//information for user
switch(person)
{
case 1:
attackus = 30, defenseus = 40, magicus = 60, speedus = 60, nameus = "Wizard";
break;
case 2:
attackus = 50, defenseus = 60, magicus = 40, speedus = 40, nameus = "Knight";
break;
case 3:
attackus = 60, defenseus = 50, magicus = 30, speedus = 50, nameus = "Berzerker";
break;
case 4:
attackus = 40, defenseus = 40, magicus = 50, speedus = 65, nameus = "Banshee";
break;
case 5:
attackus = 60, defenseus = 65, magicus = 30, speedus = 40, nameus = "Goblin";
break;
case 6:
attackus = 65, defenseus = 70, magicus = 30, speedus = 25, nameus = "Demon";
break;
case 666:
attackus = 900, defenseus = 100, magicus = 100, speedus = 100, nameus = "Satan";
break;
default:
cout << "No One";
}
do{
if(healthop == 0)
healthop = 100;
system("cls");
do{
cout << "Welcome " << nameus << ", which opponent would you like to face?" << endl;
d = (c * -1);
switch(random3)
{
case 1:
if(level <= 1)
{
cout << "(" << d + 1 << ")\n***************\nThe Tree(lvl 1):\n attack - 0\n defense - 20\n speed - 0\n***************\n";
cout << endl;
}
break;
case 2:
if(level <= 1)
{
cout << "(" << d + 1 << ")\n***************\nThe Rock(lvl 1):\n attack - 0\n defense - 30\n speed - 0\n***************\n";
cout << endl;
}
break;
case 3:
if(level <= 1)
{
cout << "(" << d + 1 << ")\n***************\nThe Computer(lvl 1):\n attack - 0\n defense - 10\n speed - 0\n***************\n";
cout << endl;
}
break;
case 4:
if(level <= 1)
{
cout << "(" << d + 1 << ")\n***************\nThe Book(lvl 1):\n attack - 0\n defense - 5\n speed - 0\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
switch(random4)
{
case 1:
if(level <= 2)
{
cout << "(" << d + 2 << ")\n***************\nThe Rat(lvl 2):\n attack - 30\n defense - 20\n speed - 30\n***************\n";
cout << endl;
}
break;
case 2:
if(level <= 2)
{
cout << "(" << d + 2 << ")\n***************\nThe Cat(lvl 2):\n attack - 40\n defense - 20\n speed - 30\n***************\n";
cout << endl;
}
break;
case 3:
if(level <= 2)
{
cout << "(" << d + 2 << ")\n***************\nThe Dog(lvl 2):\n attack - 45\n defense - 25\n speed - 30\n***************\n";
cout << endl;
}
break;
case 4:
if(level <= 2)
{
cout << "(" << d + 2 << ")\n***************\nThe Bat(lvl 2):\n attack - 30\n defense - 20\n speed - 35\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
switch(random5)
{
case 1:
if(level <= 3)
{
cout<< "(" << d + 3 << ")\n***************\nThe Mage(lvl 3):\n attack - 65\n defense - 35\n speed - 45\n***************\n";
cout << endl;
}
break;
case 2:
if(level <= 3)
{
cout<< "(" << d + 3 << ")\n***************\nThe Jackal(lvl 3):\n attack - 60\n defense - 50\n speed - 50\n***************\n";
cout << endl;
}
break;
case 3:
if(level <= 3)
{
cout<< "(" << d + 3 << ")\n***************\nThe Crusader(lvl 3):\n attack - 65\n defense - 55\n speed - 45\n***************\n";
cout << endl;
}
break;
case 4:
if(level <= 3)
{
cout<< "(" << d + 3 << ")\n***************\nThe Wolf(lvl 3):\n attack - 55\n defense - 45\n speed - 55\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
switch(random3)
{
case 1:
if((level <= 4)&&(level >= 2))
{
cout<< "(" << d + 4 << ")\n***************\nThe Assassin(lvl 4):\n attack - 75\n defense - 35\n speed - 55\n***************\n";
cout << endl;
}
break;
case 2:
if((level <= 4)&&(level >= 2))
{
cout<< "(" << d + 4 << ")\n***************\nThe Pacman(lvl 4):\n attack - 65\n defense - 30\n speed - 60\n***************\n";
cout << endl;
}
break;
case 3:
if((level <= 4)&&(level >= 2))
{
cout<< "(" << d + 4 << ")\n***************\nThe Man Eating Bunny(lvl 4):\n attack - 75\n defense - 35\n speed - 55\n***************\n";
cout << endl;
}
break;
case 4:
if((level <= 4)&&(level >= 2))
{
cout<< "(" << d + 4 << ")\n***************\nThe Warlock(lvl 4):\n attack - 70\n defense - 40\n speed - 50\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
switch(random4)
{
case 1:
if((level <= 4)&&(level >= 3))
{
cout<< "(" << d + 5 << ")\n***************\nPoseidon(lvl 5):\n attack - 80\n defense - 45\n speed - 45\n***************\n";
cout << endl;
}
break;
case 2:
if((level <= 4)&&(level >= 3))
{
cout<< "(" << d + 5 << ")\n***************\nMinitaur(lvl 5):\n attack - 65\n defense - 55\n speed - 50\n***************\n";
cout << endl;
}
break;
case 3:
if((level <= 4)&&(level >= 3))
{
cout<< "(" << d + 5 << ")\n***************\nThe Cyclops(lvl 5):\n attack - 75\n defense - 45\n speed - 50\n***************\n";
cout << endl;
}
break;
case 4:
if((level <= 4)&&(level >= 3))
{
cout<< "(" << d + 5 << ")\n***************\nThe Dragon(lvl 5):\n attack - 80\n defense - 55\n speed - 30\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
switch(random4)
{
case 1:
if((level <= 4)&&(level >= 4))
{
cout<< "(" << d + 6 << ")\n***************\nBaldino(lvl 6):\n attack - 85\n defense - 55\n speed - 60\n***************\n";
cout << endl;
}
break;
case 2:
if((level <= 4)&&(level >= 4))
{
cout<< "(" << d + 6 << ")\n***************\nChris(lvl 6):\n attack - 90\n defense - 65\n speed - 55\n***************\n";
cout << endl;
}
break;
case 3:
if((level <= 4)&&(level >= 4))
{
cout<< "(" << d + 6 << ")\n***************\nSteve(lvl 6):\n attack - 75\n defense - 70\n speed - 50\n***************\n";
cout << endl;
}
break;
case 4:
if((level <= 4)&&(level >= 4))
{
cout<< "(" << d + 6 << ")\n***************\nDylan(lvl 6):\n attack - 70\n defense - 60\n speed - 55\n***************\n";
cout << endl;
}
break;
default:
cout << "Can't Happen";
}
if(level == 5)
{
cout<< "(" << d + 7 << ")\n***************\nGod(lvl ?):\n attack - ??\n defense - ??\n speed - ??\n***************\n";
cout << endl;
}
cout << ":";
cin >> opponent;
if(opponent > 3)
{
system("cls");
cout << "You must enter an integer between 1 and 3!!!!\n\n";
system("pause");
system("cls");
}
}while(opponent > 3);
system("cls");
opponent = opponent + c;
switch(opponent)
{
case 1:
switch(random3)
{
case 1:
attackop = 0, defenseop = 20, speedop = 0, nameop = "Tree";
break;
case 2:
attackop = 0, defenseop = 30, speedop = 0, nameop = "Rock";
break;
case 3:
attackop = 0, defenseop = 10, speedop = 0, nameop = "Computer";
break;
case 4:
attackop = 0, defenseop = 5, speedop = 0, nameop = "Book";
break;
}
break;
case 2:
switch(random4)
{
case 1:
attackop = 30, defenseop = 20, speedop = 30, nameop = "Rat";
break;
case 2:
attackop = 40, defenseop = 20, speedop = 30, nameop = "Cat";
break;
case 3:
attackop = 45, defenseop = 25, speedop = 30, nameop = "Dog";
break;
case 4:
attackop = 35, defenseop = 20, speedop = 35, nameop = "Bat";
break;
}
break;
case 3:
switch(random5)
{
case 1:
attackop = 65, defenseop = 35, speedop = 45, nameop = "Mage";
break;
case 2:
attackop = 60, defenseop = 50, speedop = 50, nameop = "Jackel";
break;
case 3:
attackop = 65, defenseop = 55, speedop = 45, nameop = "Crusader";
break;
case 4:
attackop = 55, defenseop = 45, speedop = 55, nameop = "Wolf";
break;
}
break;
case 4:
switch(random3)
{
case 1:
attackop = 75, defenseop = 35, speedop = 55, nameop = "Assassin";
break;
case 2:
attackop = 65, defenseop = 30, speedop = 60, nameop = "Pacman";
break;
case 3:
attackop = 75, defenseop = 35, speedop = 55, nameop = "Man Eating Bunny";
break;
case 4:
attackop = 70, defenseop = 40, speedop = 50, nameop = "Warlock";
break;
}
break;
case 5:
switch(random4)
{
case 1:
attackop = 80, defenseop = 45, speedop = 45, nameop = "Poseidon";
break;
case 2:
attackop = 65, defenseop = 55, speedop = 50, nameop = "Minitaur";
break;
case 3:
attackop = 75, defenseop = 45, speedop = 50, nameop = "Cyclops";
break;
case 4:
attackop = 80, defenseop = 55, speedop = 30, nameop = "Dragon";
break;
}
break;
case 6:
switch(random5)
{
case 1:
attackop = 85, defenseop = 55, speedop = 60, nameop = "Baldino";
break;
case 2:
attackop = 90, defenseop = 65, speedop = 55, nameop = "Chris";
break;
case 3:
attackop = 75, defenseop = 70, speedop = 50, nameop = "Steve";
break;
case 4:
attackop = 70, defenseop = 60, speedop = 55, nameop = "Dylan";
break;
}
break;
case 7:
attackop = 90, defenseop = 70, speedop = 60, nameop = "God";
break;
default:
cout << "No One";
}
//success rate
asuccess = speedus - defenseop + 50;
msuccess = speedus - defenseop + 50;
cout << "First Round is: " << nameus << " vs. " << nameop << "!!!";
if(opponent != 6)
Sleep(1000);
if(opponent == 6)
{
Beep(350,200);
Beep(300,300);
Beep(400,200);
Beep(350,250);
Beep(400,400);
Beep(450,600);
}
//amount of damage dealt
a = attackus - defenseop;
b = magicus - defenseop;
opac = 100 - defenseus;
attackop = attackop - defenseus;
if (attackop < 0)
attackop = 0;
else
attackop = attackop;
do{
//Random Number Generator
int random, random2;
random = rand() % 100;
random2 = rand() % 100;
system("CLS");
//limitation
if(asuccess > 100)
asuccess = 100;
else
asuccess = asuccess;
if(msuccess > 100)
msuccess = 100;
else
msuccess = msuccess;
//options
do{
healus = attackop -5;
if(healus < 0)
healus = 0;
cout << "What would you like to use?\n\n"
<< "(1)\n***************\nattack: " << asuccess << "% chance of success\n***************\n\n"
<< "(2)\n***************\nmagic: " << msuccess << "% chance of success\n***************\n\n"
<< "(3)\n***************\nheal + " << healus << "hp\n***************\n\n";
cout << ": ";
cin >> atk;
if(atk > 3)
{
system("cls");
cout << "You MUST enter a number between 1 and 3!!!\n\n";
system("pause");
system("cls");
}
}while(atk > 3);
system("CLS");
cout << "Calculating results";
for(int counter = 0; counter <= 6; counter++)
{
Sleep(00);
cout << ".";
}
system("CLS");
switch(atk)
{
case 1:
if(random<=asuccess)
{
if(random<=10)
{
cout << "CRITICAL!!!!\n\n\a";
a = a * 2;
}
if(a < 0)
a = 5;
cout << "You took away " << a << " health points from the " << nameop << "!\n\n";
healthop = healthop - a;
if(healthop < 0)
healthop = 0;
cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
if(random<=10)
a = a/2;
}
else
{
cout << "You missed!\n\n";
cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
}
break;
case 2:
if(random<=msuccess)
{
if(random<=10)
{
cout << "CRITICAL!!!!\n\n\a";
b = b * 2;
}
if(b < 0)
b = 5;
cout << "You took away " << b << " health points from the " << nameop << "!\n\n";
healthop = healthop - b;
if(healthop < 0)
healthop = 0;
cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
if(random<=10)
b = b/2;
}
else
{
cout << "You missed!\n\n";
cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
}
break;
case 3:
if(healthus < 100)
{
healthus = healthus + healus;
cout << "Your health rose from " << healthus-healus << ", to " << healthus << "!!!" << endl << endl;
}
else
cout << "Your health is already 100%!!!" << endl << endl;
break;
default:
cout << "Attack Not available";
}
system("pause");
system("cls");
if(healthop > 0)
{
cout << "Opponent is now attacking";
for(int counter = 6; counter >= 0; counter--)
{
Sleep(00);
cout << ".";
}
system("cls");
if(opac <= random2)
{
if(random2<=5)
{
cout << "CRITICAL!!!!\n\n\a";
attackop = attackop + 15;
}
if(attackop < 0)
attackop = 5;
cout << "The opponent took away " << attackop << " health points from you!\n\n";
healthus = healthus - attackop;
if(healthus < 0)
healthus = 0;
cout << "Opponent's health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
if(random2<=5)
attackop = attackop - 15;
}
else
{
cout << "The opponent missed!\n\n";
cout << "Opponent's health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
}
system("pause");
}
}while((healthop >= 1)&&(healthus >= 1));
system("cls");
if(healthop >= 1)
{
cout << "You were beat by the " << nameop << "!!! Whhaaaahaahaaaaa\n\n";
Beep(180,500);
Beep(160,500);
Beep(140,500);
Beep(120,500);
Beep(100,800);
}
else if(opponent!=7)
{
level++;
c++;
cout << "Congratulations on your victory! You have graduated to level " << level << "!!!.\n\n";
cout << "Which attribute would you like to increase by 5 points?\n";
cout << endl << "(1)\n*****\nattack\n*****\n\n(2)\n*****\nmagic\n*****\n\n(3)\n*****\nspeed\n*****\n\n(4)\n*****\ndefense\n*****\n:";
cin >> atr;
switch(atr)
{
case 1:
attackus = attackus + 5;
break;
case 2:
magicus = magicus + 5;
break;
case 3:
speedus = speedus + 5;
break;
case 4:
defenseus = defenseus + 5;
break;
default:
defenseus = defenseus;
break;
}
system("cls");
cout << "Your current Stats are:\nattack - " << attackus << endl << "magic - " << magicus << endl << "speed - " << speedus << endl << "defense - " << defenseus << endl << endl;
system("pause");
system("cls");
}
system("pause");
}while((healthus >= 1)&&(opponent!=7));
cout << "OMG!! YOU WON!!! You are better than god...congrats!";
Beep(100,100);
Beep(120,100);
Beep(140,100);
Beep(160,100);
Beep(180,100);
Beep(200,100);
Beep(220,100);
Beep(240,100);
Beep(260,100);
Beep(280,100);
Beep(300,100);
Beep(320,100);
Beep(340,100);
Beep(360,100);
Beep(380,100);
Beep(400,100);
Beep(420,100);
Beep(440,100);
Beep(460,100);
Beep(480,100);
Beep(500,100);
Beep(600,300);
}