Jump to content
  • Advertisement

Jaydeep Hora

  • Content Count

  • Joined

  • Last visited

Community Reputation

107 Neutral

About Jaydeep Hora

  • Rank
  1. Jaydeep Hora

    Storing breakout bricks in an array SDL

    And can I not initialize the data values of the members of the array using the parameterized constructor?
  2. Jaydeep Hora

    Storing breakout bricks in an array SDL

    Okay Okay! I get it. Thanks! It worked!
  3. Jaydeep Hora

    Storing breakout bricks in an array SDL

    I had to add the default constructor because the compiler wouldn't let me initialize an array otherwise.
  4. Jaydeep Hora

    Storing breakout bricks in an array SDL

    Error : 1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall brick::brick(void)" (??0brick@@QAE@XZ) referenced in function _SDL_main 1>F:\Opengl\Projects\myfirstgame\Debug\myfirstgame.exe : fatal error LNK1120: 1 unresolved externals
  5. Jaydeep Hora

    Storing breakout bricks in an array SDL

    Main.cpp: #include <SDL.h> #include <iostream> #include "player.h" #include "ball.h" #include "brick.h" #include <vector>   using namespace std; SDL_Surface* load_image(const char* c,Uint32 colorkey=0) {         SDL_Surface* tmp=SDL_LoadBMP(c);         if(colorkey!=0)         {                 SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,colorkey);         }         return tmp; }       int main( int argc, char* args[] ) {     //Start SDL      SDL_Surface* screen,*background;      const int width=640;         const int FPS=30;         const int height=480;        screen=SDL_SetVideoMode(width,height,32,SDL_SWSURFACE); SDL_Event event; Uint32 start; player player1(load_image("pappu.bmp"),0,SDL_GetVideoSurface()->clip_rect.h-10,50,10,10); ball ball1(load_image("ball.bmp"),width/2,height/2,15,15,2,2); brick brick1(load_image("brick.bmp"),40,200,40,20); brick bricks[20]; //array declaration   /*for(int i=40,j=0;i<=600 && j<=20;i+=40,j++){ brickv[j].set(load_image("brick.bmp"),i,380,40,20);   } /*background=SDL_LoadBMP("background.bmp"); SDL_Rect camera; camera.x=0; camera.y=0; camera.w=640; camera.h=480; */ bool running=true; int arr[4]={0,0,0,0}; while(running){   start=SDL_GetTicks(); while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_QUIT: running=false; break; case SDL_KEYDOWN: switch(event.key.keysym.sym){ case SDLK_RIGHT: arr[0]=1; break; case SDLK_LEFT: arr[1]=1; break; } break; case SDL_KEYUP: switch(event.key.keysym.sym){ case SDLK_RIGHT: arr[0]=0; break; case SDLK_LEFT: arr[1]=0; break; } break; } } if(arr[0]==1){ player1.moveR();       } if(arr[1]==1){ player1.moveL(); }   SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0xff,0xff,0xff));     player1.show(); ball1.show(); ball1.move(player1.getRect()); ball1.walls(); brick1.show();      SDL_Flip(screen);                 //regulate FPS                 if(1000/FPS>(SDL_GetTicks()-start))                         SDL_Delay(1000/FPS-(SDL_GetTicks()-start));   }         //Quit SDL     SDL_Quit();          return 0;     } brick.h: #include <SDL.h> #ifndef brick_h #define brick_h class brick{ SDL_Rect brik; SDL_Surface* image; public: brick(); brick(SDL_Surface* img,int x,int y,int w,int h); ~brick(); void show(); SDL_Rect* get_Rect(); void Free(); void set(SDL_Surface* img,int x,int y,int w,int h); }; #endif brick.cpp: #include "brick.h" brick::brick(SDL_Surface* img,int x,int y,int w,int h){ image=img; brik.x=x; brik.y=y; brik.w=w; brik.h=h; } brick::~brick(){ SDL_FreeSurface(image); } void brick:: show(){ SDL_BlitSurface(image,NULL,SDL_GetVideoSurface(),&brik); } SDL_Rect* brick::get_Rect(){ return &brik; } void brick::Free(){ SDL_LockSurface(image); }
  6. So I just started game programming and I was working on a game like breakout where there is a paddle and a set of bricks that can be destroyed using the ball.I am using SDL and C++ to make the game. I can't figure how out how to implement the set of bricks in the game.I have a class "Brick" .I use a constructor to initialize the values of the SDL_Rect for the brick and also the surface image for the brick. Also I use a show function to show the brick using the SDL_BlitSurface function. Now I declare an array say "brick a[20];" and even if I don't call no function or constructor , on compiling it fails to compile and gives an error. I am using Visual studio 2010.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!