collapse collapse

* Who's Online

  • Dot Guests: 136
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: C++ (Game Programming)  (Read 2104 times)

0 Members and 1 Guest are viewing this topic.

CplusJ

  • Guest
C++ (Game Programming)
« on: January 17, 2009, 04:37:51 am »
Hello...
I am in the process of creating a basic text RPG based game using C++.  I have not had much experience in C++ and using it for games. 
My question is, if i want to add a EXP counter or a Curency counter what would be a example of a function i could call throughout the entire program when needed.
I was leaning more twards the line of a constant but the function is where i am having the trouble.

If you have any advice and please E-Mail me at justinam1989@yahoo.com or reply to the this fourm.

Thank you

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: C++ (Game Programming)
« Reply #1 on: January 17, 2009, 09:59:04 am »
Hello...
I am in the process of creating a basic text RPG based game using C++.  I have not had much experience in C++ and using it for games. 
My question is, if i want to add a EXP counter or a Curency counter what would be a example of a function i could call throughout the entire program when needed.
I was leaning more twards the line of a constant but the function is where i am having the trouble.

If you have any advice and please E-Mail me at justinam1989@yahoo.com or reply to the this fourm.

Thank you
Experience is kinda complicated, in most RPG games you just don't get the same amount of EXP every battle so you are going to have to figure out how you want your game to work. And although you really don't need a currency or exp counter as a function, what I would do is use a class:
Code: [Select]
#include <iostream>
#include <string>

using namespace std;

class CPlayer {
private:
int money;
int exp;
public:
CPlayer()
{
this->money = 0;
this->exp = 0;
}
int getMoney()
{
return this->money;
}
void adjustcurrency(int val)
{
this->money += val;
}
void addEXP(int val)
{
this->exp += val;
}
};

int main()
{
CPlayer p1;
p1.adjustcurrency(55);
cout << p1.getMoney() << endl;
system("pause");
return 0;
}

Look at different libraries for game devlopment like SDL, OpenGL, and IrrLib.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: C++ (Game Programming)
« Reply #2 on: January 17, 2009, 12:39:46 pm »
Hello...
I am in the process of creating a basic text RPG based game using C++.  I have not had much experience in C++ and using it for games. 
My question is, if i want to add a EXP counter or a Curency counter what would be a example of a function i could call throughout the entire program when needed.
I was leaning more twards the line of a constant but the function is where i am having the trouble.

If you have any advice and please E-Mail me at justinam1989@yahoo.com or reply to the this fourm.

Thank you
Also as a side note, using a constant for values that you intend to change is a no no. You use constants when you want the data to remain the same, not when you want it to change it.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]