Static Binding Problem:

J

JoeC

I have kinda complex question. I am writing a game program and I am
trying to derrive things from my graphic library. For starters I want
to derrive the terrain from my graphics so that I can re-use my
graphics for other things like units. My graphic library works fine.
All I changed was graphic * trn to terrain trn[5]. So I am calling it
from a non-pointer array.

Here is some of what I got, if more is needed let me know:

static graphic * g1; <- this is a graphic that displays fine.
static terrain trn[5]; <- this object works but doesn't display
graphics.

g1 = new graphic(pgr); <-creating a graphic with a BYTE type

trn[0].SetAll(255, 255, 255, bits); creating terrain with color
and BYTE type
trn[1].SetAll(0 , 255, 0 , bits);

if(b->GetSpace(y,x)){
num = b->GetSpace(y,x);
SetTextColor(hdc,RGB(trn[num].red(), trn[num].grn(),
trn[num].blu()));
trn[num].display(hwnd,convert(y),convert(x)); <-This
worked as a graphic
but not derrived in terrain

g1->display(hwnd, convert(3),convert(5)); <-This displays find
which I use the same code as the base of the terrain object.

class terrain : public graphic{
float mvcost;
int defence;
int r, g, b;
public:
terrain(): r(0), g(0), b(0){}
terrain(int, int, int);
void SetColor(int rn, int bn, int gn){r = rn; b = bn; g = gn;}
void SetAll(int, int, int, BYTE c[]);
int red(){return r;}
int grn(){return g;}
int blu(){return b;}
float move(){return mvcost;}
};

Basically I don't understand why graphic is not working as base of
terrain.
 
T

Thomas J. Gritzan

JoeC said:
I have kinda complex question. I am writing a game program and I am
trying to derrive things from my graphic library. For starters I want
to derrive the terrain from my graphics so that I can re-use my
graphics for other things like units. My graphic library works fine.
All I changed was graphic * trn to terrain trn[5]. So I am calling it
from a non-pointer array.

Here is some of what I got, if more is needed let me know:

"My car is not working. What should I do?"

We need more. Read the FAQ:

http://www.parashift.com/c++-faq-lite/
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
static graphic * g1; <- this is a graphic that displays fine.
static terrain trn[5]; <- this object works but doesn't display
graphics. [...]
trn[num].display(hwnd,convert(y),convert(x)); <-This
worked as a graphic
but not derrived in terrain

g1->display(hwnd, convert(3),convert(5)); <-This displays find
which I use the same code as the base of the terrain object.

How is it not working? It is green instead of red? Does it display
hexadecimal instead of base64? Did the cat scream when you started the
program? Explain the wrong behaviour and provide a compilable example, when
possible.
if(b->GetSpace(y,x)){
num = b->GetSpace(y,x);

What range is num in? When it is 0<=num<=4, you wasted an array slot. When
it is 1<=num<=5, you should substract one.
 
J

JoeC

Thomas said:
JoeC said:
I have kinda complex question. I am writing a game program and I am
trying to derrive things from my graphic library. For starters I want
to derrive the terrain from my graphics so that I can re-use my
graphics for other things like units. My graphic library works fine.
All I changed was graphic * trn to terrain trn[5]. So I am calling it
from a non-pointer array.

Here is some of what I got, if more is needed let me know:

"My car is not working. What should I do?"

We need more. Read the FAQ:

http://www.parashift.com/c++-faq-lite/
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
static graphic * g1; <- this is a graphic that displays fine.
static terrain trn[5]; <- this object works but doesn't display
graphics. [...]
trn[num].display(hwnd,convert(y),convert(x)); <-This
worked as a graphic
but not derrived in terrain

g1->display(hwnd, convert(3),convert(5)); <-This displays find
which I use the same code as the base of the terrain object.

How is it not working? It is green instead of red? Does it display
hexadecimal instead of base64? Did the cat scream when you started the
program? Explain the wrong behaviour and provide a compilable example, when
possible.
if(b->GetSpace(y,x)){
num = b->GetSpace(y,x);

What range is num in? When it is 0<=num<=4, you wasted an array slot. When
it is 1<=num<=5, you should substract one.

Thanks, I found the problem: I failed to clear the vector which holds
the data I was appending the new data to the end of the default data.
Now I have to place the units on the map and that may not be too hard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top