[C++]Need help setting up a class -
i'm new c++ , trying create game of mario. have 3 classes working on: stage, image , element. first 1 has own .h , .cpp, , 2 others have .h , .cpp; problem is: in class stage, have variables of type element, can't on world declare no problems. code is: elements.h
#ifndef elements_h #define elements_h #include <stdio.h> #include <conio.h> #include <windows.h> #include "stage.h" hdc * mywindow; stage * stage2; class image{ public: bool ontop; file* entry; int lenght, height; colorref matrix[32][32]; void load(); void print(int x, int y, int orientation, int ratiox, int ratioy); void erase(int x, int y, int orientation, int ratiox, int ratioy); private: }; **strong text** class element{ public: element(); int num, sizex, sizey, orientation, timeofdeath; float vely; int top, left, spent; void print(); void erase(); int bottom(); int right(); int middlex(); int middley(); void initializeelements(hdc * windowptr, stage * stageptr); }; #endif
stage.h
#ifndef stage_h #define stage_h #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #include <wingdi.h> #include <iostream> #using <mscorlib.dll> #include "elements.h" class stage{ //0 = mario, 1 = luigi, 2 = mushroom. 3 = block, 4 = coin, 5 = coinbox, 6 = spentcoinbox, 7 = brick, 8 = bomb public: bool map[1184][600]; colorref colormap[1184][600]; element blocks[600], coins[600], mushrooms[600], coinboxes[600], bricks[600], bombs[600], specialcoins[600]; int blockslen, coinslen, mushroomslen, coinboxeslen, brickslen, bombslen; int level; stage(); void print(); }; #endif
elements.cpp
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> #include <string.h> #include <windows.h> #include <wingdi.h> #include <iostream> #include <math.h> #using <mscorlib.dll> #include "elements.h" #define red rgb(255, 0, 0) #define blue rgb(0, 0, 255) #define black rgb(0, 0, 0) #define white rgb(255, 255, 255) #define none rgb(1, 2, 3) #define brown rgb(43, 17, 0) #define skin rgb(255, 179, 128) #define yellow rgb(255, 255, 0) #define shoe rgb(80, 45, 22) #define sky rgb(101, 156, 239) #define color1 rgb(203, 79, 15) #define color2 rgb(255, 191, 179) #define color3 rgb(248, 216, 30) #define color4 rgb(248, 248, 0) #define color5 rgb(216, 158, 54) #define color6 rgb(255, 210, 67) #define color7 rgb(247, 150, 70) #define color8 rgb(255, 97, 29) #define color9 rgb(0,85,170) #define color0 rgb(131,91,9) #define colorz rgb(246, 182, 4) #define green rgb(40, 170, 85) image images[9]; void image::load(){ char read; (int j = 0; j != height; j++){ (int = 0; != lenght; i++){ fscanf(entry, "%c", &read); if (read == 'r') matrix[i][j] = red; else if (read == 'l') matrix[i][j] = blue; else if (read == 's') matrix[i][j] = skin; else if (read == 'y') matrix[i][j] = yellow; else if (read == 'n') matrix[i][j] = brown; else if (read == 'w') matrix[i][j] = white; else if (read == 'q') matrix[i][j] = shoe; else if (read == 'b') matrix[i][j] = black; else if (read == '1') matrix[i][j] = color1; else if (read == '2') matrix[i][j] = color2; else if (read == '3') matrix[i][j] = color3; else if (read == '4') matrix[i][j] = color4; else if (read == '5') matrix[i][j] = color5; else if (read == '6') matrix[i][j] = color6; else if (read == '7') matrix[i][j] = color7; else if (read == '8') matrix[i][j] = color8; else if (read == '9') matrix[i][j] = color9; else if (read == '0') matrix[i][j] = color0; else if (read == 'z') matrix[i][j] = colorz; else if (read == 'g') matrix[i][j] = green; else matrix[i][j] = none; } fscanf(entry, "%c", &read); } fclose(entry); } void image::print(int x, int y, int orientation, int ratiox, int ratioy){ colorref color; int i; (int j = 0; j < height; j++){ (int k = 0; k < lenght; k++){ if (matrix[i][j] == none) continue; if (orientation == 0) = k; else = 11 - k; (int m = 0; m < ratiox; m++){ (int n = 0; n < ratioy; n++){ if (ontop == 0) stage2.colormap[i][j] = color; setpixelv((*mywindow) , x + ratiox*k + m, y + ratioy*j + n, matrix[i][j]); } } } } } void image::erase(int x, int y, int orientation, int ratiox, int ratioy){ colorref color; int i; (int j = 0; j < height; j++){ (int k = 0; k < lenght; k++){ if (matrix[i][j] == none) continue; if (orientation == 0) = k; else = 11 - k; (int m = 0; m < ratiox; m++){ (int n = 0; n < ratioy; n++){ if (ontop == 1){ setpixelv((*mywindow), x + ratiox*k + m, y + ratioy*j + n, stage2.colormap[i][j]); } else{ setpixelv((*mywindow), x + ratiox*k + m, y + ratioy*j + n, sky); stage2.colormap[i][j] = sky; } } } } } } element::element(){ vely = 0; sizex = 2; sizey = 2; orientation = 0; spent = 0; timeofdeath = 0; } void element::print(){ images[i].print(left, top, orientation, sizex, sizey); } void element::erase(){ images[num].print(left, top, orientation, sizex, sizey); } int element::bottom(){ return (top + images[i].height - 1); } int element::right(){ return (left + images[i].length - 1); } int element::middlex(){ return (left + right())/2; } int element::middley(){ return (top + bottom()) / 2; } void element::initializeelements(hdc * windowptr, stage * stageptr){ mywindow = windowptr; stage2 = stageptr; //it's me, mario! images[0].entry = fopen("c:\\mario\\mario12x16.txt", "r"); images[0].height = 16; images[0].lenght = 12; images[0].ontop = 1; images[0].load(); //it's me, aluisio! images[1].entry = fopen("c:\\mario\\luigi12x16.txt", "r"); images[1].height = 16; images[1].lenght = 12; images[1].ontop = 1; images[1].load(); //mario's hungry. let's make mushroom! images[2].entry = fopen("c:\\mario\\mushroom16x16.txt", "r"); images[2].height = 16; images[2].lenght = 16; images[2].ontop = 0; images[2].load(); //i need walk on! images[3].entry = fopen("c:\\mario\\block32x32.txt", "r"); images[3].height = 32; images[3].lenght = 32; images[3].ontop = 0; images[3].load(); //and money buy peach nice dildo... images[4].entry = fopen("c:\\mario\\coin12x16.txt", "r"); images[4].height = 16; images[4].lenght = 12; images[4].ontop = 0; images[4].load(); // images[5].entry = fopen("c:\\mario\\coinbox16x16.txt", "r"); images[5].height = 16; images[5].lenght = 16; images[5].ontop = 0; images[5].load(); // images[6].entry = fopen("c:\\mario\\spentcoinbox16x16.txt", "r"); images[6].height = 16; images[6].lenght = 16; images[6].ontop = 0; images[6].load(); // images[7].entry = fopen("c:\\mario\\brick16x16.txt", "r"); images[7].height = 16; images[7].lenght = 16; images[7].ontop = 0; images[7].load(); // images[8].entry = fopen("c:\\mario\\bomb29x29.txt", "r"); images[8].height = 29; images[8].lenght = 29; images[8].ontop = 0; images[8].load(); // }
stage.cpp
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> #include <string.h> #include <windows.h> #include <wingdi.h> #include <iostream> #include <math.h> #using <mscorlib.dll> #include "stage.h" //#include "elements.h" //#include "elements.cpp" stage::stage(){ blockslen = 0; coinslen = 0; mushroomslen = 0; coinboxeslen = 0; brickslen = 0; bombslen = 0; (int j = 0; j < 600; j++){ (int = 0; < 1184; i++){ map[i][j] == 0; } } char read; file *entry; if (level == 1) entry = fopen("c:\\mario\\stage1.txt", "r"); (int j = 0; j < 18; j++){ (int = 0; < 37; i++){ fscanf(entry, "%c", &read); if (read == '0'){ blocks[blockslen].num = 3; blocks[blockslen].sizex = 1; blocks[blockslen].sizey = 1; blocks[blockslen].left = 32 * i; blocks[blockslen++].top = 32 * j + 24; (int m = 0; m < 32; m++){ (int n = 0; n < 32; n++){ map[32 * + m][32 * j + n + 24] = 0; } } } if (read == 'c'){ coins[coinslen].num = 4; coins[coinslen].left = 32 * + 4; coins[coinslen++].top = 32 * j + 24; } if (read == 'd'){ coinboxes[coinboxeslen].num = 5; coinboxes[coinboxeslen].left = 32 * i; coinboxes[coinboxeslen++].top = 32 * j + 24; (int m = 0; m < 32; m++){ (int n = 0; n < 32; n++){ map[32 * + m][32 * j + n + 24] = 1; } } } if (read == 'e'){ coinboxes[coinboxeslen].num = 6; coinboxes[coinboxeslen].spent = true; coinboxes[coinboxeslen].left = 32 * i; coinboxes[coinboxeslen++].top = 32 * j + 24; (int m = 0; m < 32; m++){ (int n = 0; n < 32; n++){ map[32 * + m][32 * j + n + 24] = 1; } } } if (read == 'f'){ bricks[brickslen].num = 7; bricks[brickslen].left = 32 * i; bricks[brickslen++].top = 32 * j + 24; (int m = 0; m < 32; m++){ (int n = 0; n < 32; n++){ map[32 * + m][32 * j + n + 24] = 1; } } } if (read == 'm'){ mushrooms[mushroomslen].num = 2; mushrooms[mushroomslen].left = 32 * i; mushrooms[mushroomslen++].top = 32 * j + 24; } } fscanf(entry, "%c", &read); } } void stage::print(){ (int = 0; < 1184; i++) (int j = 0; j < 600; j++) stage.colormap[i][j] = sky; (int = 0; < blockslen; i++){ blocks[i].print(); } (int = 0; < coinslen; i++){ coins[i].print(); } (int = 0; < mushroomslen; i++){ mushrooms[i].print(); } (int = 0; < coinboxeslen; i++){ coinboxes[i].print(); } (int = 0; < brickslen; i++){ bricks[i].print(); } (int = 0; < 1184; i++) (int j = 0; j < 600; j++) if (stage.colormap[i][j] == sky) setpixelv(mywindow, i, j, sky); }
now errors get: image
thank all
either move stage *stage2;
out of elements.h
, or forward declare class stage
in elements.h
without #include "stage.h"
.
what do, error.
Comments
Post a Comment