Jump to content
  • Advertisement

AneuryPerez

Member
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

166 Neutral

About AneuryPerez

  • Rank
    Member
  1. AneuryPerez

    Glut & opengl only for 2D [Question]

    I will look for it , thank you !! 
  2. AneuryPerez

    Glut & opengl only for 2D [Question]

    it seems I Change SDL2 to glfw But another question is possible make full 2d game using opengl, maybe this question seem a litle bit dummy but now  I want to re-writte my PONG game at this library.. thank you for your answer.
  3. Greeting !!    I have a question , I always look that when we use use opengl or derivate we alwasy rely on SDL or a window manager  but is there any way that I  can use OpenGL or derivate without use other library ,framework or other ?      thank you in advance... !!
  4. AneuryPerez

    need a review of my tilemap code

    thank you for answer  I  Did put the __TIME__ and other stuff because im debugging but it could be fixed.   im understand a lilte bit the other stuff but do you think the other part is ok ?    I know  I need to fix the FrameRate Control function and also would recommend something to check when it collide to a " wall " ? 
  5. Greeting first of all !!      I 'd like to share some part of the code im writting  , im totally beginner i wrote a pong but I decide to make other thing bigger than this and im trying  to make a platform Im follow some tutorial from here , but im really don't know how to make it jump correctly , but first let me show the code is what i learnt in this travel of game development.   #include<SDL2/SDL.h> #include<iostream> #include<vector> #include<map> #include<fstream> #include<sstream> using namespace std; #define GLOBAL_ERROR_FLAG -1 #define UNABLE_LOAD_IMG "The image could not be load" #define LOADED "Image load well" #define UNABLE_TO_LOAD_MAP "Unnable to load that map" #define DEBUG 1 #ifdef DEBUG #define debug() cout <<__FUNCTION__<<" " <<__LINE__<<" "<<__DATE__<<endl; #define Debug(X) cout <<"Function Name : "<<__FUNCTION__<<" , Line no. " <<__LINE__<<" , "<<__DATE__ <<" , "<<__TIME__<<" , VALUE : "<< X <<endl; #else #define debug() #define Debug(X) #endif template<class T,class E> string BuildString(T uno, E dos) { stringstream st; st << uno << " " << dos <<endl; return st.str(); } const char *gTitulo = "TITLE APP "; const int TAMANO_PANTALLA_ANCHO = 640; const int TAMANO_PANTALLA_ALTO = 480; const int TAMANO_MAPA_ANCHO = 2100; const int TAMANO_MAPA_ALTO = 500; const int FPS = 60; const int PL_VEL = 48; SDL_Window *window; SDL_Renderer *render; SDL_Event event; bool run; int gReturn; unsigned int start; unsigned int delay; struct Camara { SDL_Rect _camara; }cam; struct Entidad { SDL_Rect crop; SDL_Rect offset; SDL_Texture *img; unsigned int hp; unsigned int mp; bool EstaSaltando; bool EstaCallendo; }; struct Tile { SDL_Rect crop; SDL_Rect offset; int type; }; struct TileSet { SDL_Texture *res; }TestTileset; Entidad player; vector<Entidad> enemigos; vector<Entidad> objetos; vector<Tile > tile; void Init(); ///done void HandleEvent(); void Render(); int Destroy(); void StartFrame(); void RegulateFrame(); void FixBounds(); void LoadTile(vector<Tile> *ref,const char *fname); void DrawMap(); SDL_Texture *CargarImagen(const char *fname, unsigned int r, unsigned int g, unsigned int b); bool CheckCollison(Entidad *e1, Entidad e2); void CargarRecursos(); bool IsTouchingTheWall(); //void ArgManager(int argc, char **argv); ///void Update(); // int main(int argc, char *argv[]) { Init(); CargarRecursos(); while(run) { StartFrame(); HandleEvent(); Render(); RegulateFrame(); } return Destroy(); } void Init() { Debug("Init") if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { gReturn = GLOBAL_ERROR_FLAG; debug() } if(gReturn != GLOBAL_ERROR_FLAG) { window = SDL_CreateWindow(gTitulo,100,100,TAMANO_PANTALLA_ANCHO,TAMANO_PANTALLA_ALTO, SDL_WINDOW_SHOWN ); render = SDL_CreateRenderer(window , -1 , SDL_RENDERER_ACCELERATED); if(window == NULL|| render == NULL) { gReturn = GLOBAL_ERROR_FLAG; cout << "error Creado la ventana \n"; } else { run = true; } } } void HandleEvent() { //Debug("HandleEvent") while(SDL_PollEvent(&event)) { if(event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_q: run =false; break; case SDLK_UP: player.offset.y -= PL_VEL; break; case SDLK_DOWN: player.offset.y += PL_VEL; break; case SDLK_LEFT: player.offset.x -= PL_VEL; break; case SDLK_RIGHT: player.offset.x += PL_VEL; break; default: break; } } FixBounds(); } } void Render() { // Debug("Render") SDL_RenderClear(render); SDL_SetRenderDrawColor(render, 0,23,34,56); DrawMap(); SDL_RenderCopy(render, player.img,&player.crop,&player.offset); #if 0 for(unsigned int Ei = 0; Ei < enemigos.size(); Ei++) { SDL_RenderCopy(render, enemigos.at(Ei).img,&enemigos.at(Ei).crop,&enemigos.at(Ei).offset); } for(unsigned int Ei = 0; Ei < objetos.size(); Ei++) { SDL_RenderCopy(render, objetos.at(Ei).img,&objetos.at(Ei).crop,&objetos.at(Ei).offset); } #endif SDL_RenderPresent(render); } void StartFrame() { start = SDL_GetTicks(); } void RegulateFrame() { if(1000/FPS < start - SDL_GetTicks()) { delay = 1000/FPS < start - SDL_GetTicks(); SDL_Delay(delay); // Debug(delay) } } bool CheckCollison(Entidad *e1, Entidad *e2) { int l1,r1,t1,b1; int l2,r2,t2,b2; l1 = e1->offset.x; r1 = e1->offset.x + e1->offset.w; t1 = e1->offset.y; b1 = e1->offset.y + e1->offset.h; l2 = e2->offset.x; r2 = e2->offset.x + e2->offset.w; t2 = e2->offset.y; b2 = e2->offset.y + e2->offset.h; if(l1 <= r2) return true; return true; } SDL_Texture *CargarImagen(const char *fname, unsigned int r, unsigned int g, unsigned int b) { SDL_Texture *SRet = NULL; SDL_Surface *temp = SDL_LoadBMP(fname); if(temp == NULL) { Debug("Unable to load") } else { SDL_SetColorKey(temp, SDL_TRUE, SDL_MapRGB(temp->format, r,b,g)); SRet = SDL_CreateTextureFromSurface(render, temp); SDL_FreeSurface(temp); if(SRet == NULL) { Debug( UNABLE_LOAD_IMG ) } } return SRet; } void CargarRecursos() { player.img = CargarImagen("player.bmp", 0, 0, 0); if(player.img == NULL) Debug( UNABLE_LOAD_IMG ) else Debug(LOADED) player.crop.w = 48; player.crop.h = 48; player.crop.x = 0; player.crop.y = 0; player.offset.w = 48; player.offset.h = 48; player.offset.x = 10; player.offset.y = 400; player.EstaCallendo = true; player.EstaSaltando = false; /* map */ LoadTile(&tile,"testmap.map"); TestTileset.res = CargarImagen("tileset.bmp", 0, 0, 0); if(TestTileset.res == NULL) { Debug("the tileset Could not be loaded") } /*enemigos area*/ } void FixBounds() { if(player.offset.x <= 0 ) player.offset.x = TAMANO_PANTALLA_ANCHO + 32; if(player.offset.x >= TAMANO_PANTALLA_ANCHO) player.offset.x -= 32; if(player.offset.y <= 0) player.offset.y = TAMANO_PANTALLA_ALTO + 32; if(player.offset.y >= TAMANO_PANTALLA_ALTO) player.offset.y -= 32; } void LoadTile(vector<Tile> *ref,const char *fname) { ifstream file_(fname); vector<string>mapa; string linea; Tile t; unsigned int x = 0; unsigned int y = 0; int type = 0; const int TILESIZE =48; if(!file_.is_open()) { Debug("the map file could not be open!") } else { while(getline(file_, linea)) { mapa.push_back(linea); Debug(linea); } file_.close(); Debug("file close") for(unsigned int outer = 0; outer < mapa.size(); outer++ ) { for(unsigned int inner = 0 ; inner < mapa[outer].size(); inner++) { if(mapa[outer].at(inner) == '1') { Debug(BuildString("Cargando Terreno 1",mapa[outer].at(inner) )) type = 0; } if(mapa[outer].at(inner) == '4') { Debug(BuildString("Cargando Terreno 4",mapa[outer].at(inner) )) type = 48; } t.crop.x = type; t.crop.y = 0; t.crop.w = TILESIZE; t.crop.h = TILESIZE; t.offset.x = x; t.offset.y = y; t.offset.w = TILESIZE; t.offset.h = TILESIZE; x += 48; if(x >= TAMANO_PANTALLA_ANCHO ) { x = 0; y += TILESIZE; } Debug(BuildString("value of X ", x)) Debug(BuildString("value of Y", y )) ref->push_back(t); } } } } void DrawMap() { Debug("Drawing map") for(unsigned int i= 0; i < tile.size(); i++) { Debug(BuildString("OFFSET X ", tile[i].offset.x)) Debug(BuildString("OFFSET Y ", tile[i].offset.y)) SDL_RenderCopy(render, TestTileset.res, &tile[i].crop, &tile[i].offset); } } bool IsTouchingTheWall() { for(unsigned int in= 0; in < tile.size(); in++) { ///no implemented yet } } int Destroy() { debug() SDL_DestroyWindow(window); SDL_DestroyRenderer(render); SDL_Quit(); return gReturn; } this code only load a " sprite " and draw a map , im really not sure how to implement scroll and if this touching the wall and gravity , i wrotte another code where i can jump the sprite but the gravity is like is in the space  , I would any advice from you thank you .      and apologize my english im learning too...
  6. AneuryPerez

    [Question] map algorithm in sdl is flickerin'

    OK , im going to add as parameter, thank you :)
  7. AneuryPerez

    [Question] map algorithm in sdl is flickerin'

    Servant of the lord I  agreed with you !!! right now im going to put the  all the code...     SyncView after I  Read your answer  I realized that  I Was in a big o giant mistake  I Was showing every single tile  since I load  ,this is a mistake.. thank to all ...    bellow im going to put the code.. #include<SDL2\SDL.h> #include<iostream> using namespace std; #define S_W 400 #define S_H 400 #define MAX_ROW 14 #define MAX_COL 23 #define UNUSED 0X32 void DrawMap(SDL_Renderer *render , SDL_Rect *rect, int x,int y,int size) { SDL_Rect offset; offset.x = x; offset.y = y; offset.h = 32; offset.w = 32; SDL_Texture *text = SDL_CreateTextureFromSurface(render,SDL_LoadBMP("tiles.bmp")); if(text == NULL) { cout <<"Unnable to load a map!!"<<endl; } else { SDL_RenderCopy(render, text, rect, &offset); } } int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window *window = SDL_CreateWindow("titu", SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, S_W,S_H, SDL_WINDOW_SHOWN|SDL_WINDOW_FULLSCREEN); SDL_Renderer *render = SDL_CreateRenderer(window, -1 , SDL_RENDERER_ACCELERATED |SDL_RENDERER_PRESENTVSYNC); SDL_Event ev; bool salir = true; SDL_Rect rect={0,0,32,32}; int arreglo[MAX_ROW][MAX_COL]={ /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 */ {2,2,2,2,2,1,1,1,1,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2}, {2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2} }; for(int i= 0; i < MAX_COL ; i++) { ///cout <<endl; for(int j=0; j < MAX_ROW;j++){ if(arreglo[j][i] == 2) //// correcto. rect.x =32; else if(arreglo[j][i]==1) rect.x = 0; else if(arreglo[j][i]==3) rect.x = 64; ///cout << arreglo[j][i]<<','; DrawMap(render, &rect, i*32,j*32,32); ///copy the render in the screen. } } SDL_RenderPresent(render); while(salir) { while(SDL_PollEvent(&ev)) { if(ev.type == SDL_QUIT || ev.type == SDL_KEYDOWN) { salir = false; } } }
  8. hey everyone here !!! wishing everything is great for everyone !!!      I'm a newbie here and i don't know if this correct but i really to learn how to do something , im trying lo load a map in a screen , and the thing is the map load correctly but every time..i load another image the screen is flickering in addition when I  Get full screen is like a chess board.. I would like a litle help  int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window *window = SDL_CreateWindow("titu", SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, S_W,S_H, SDL_WINDOW_SHOWN/*SDL_WINDOW_FULLSCREEN*/); SDL_Renderer *render = SDL_CreateRenderer(window, -1 , SDL_RENDERER_ACCELERATED |SDL_RENDERER_PRESENTVSYNC); SDL_Event ev; bool salir = true; SDL_Rect rect={0,0,32,32}; int arreglo[MAX_ROW][MAX_COL]={ /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 */ {1,1,1,1,1,1,1,1,1,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2}, {2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}, {2,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2} }; for(int i= 0; i < MAX_COL ; i++) { ///cout <<endl; for(int j=0; j < MAX_ROW;j++){ if(arreglo[j][i] == 2) //// correcto. rect.x =32; else if(arreglo[j][i]==1) rect.x = 0; else if(arreglo[j][i]==3) rect.x = 64; ///cout << arreglo[j][i]<<','; DrawMap(render, &rect, i*32,j*32,32); ///copy the render in the screen. SDL_RenderPresent(render); } } obviously i have a game loop where  I make a litle delay using : 1000/fps -(startime-lastime)        i dont put it because the whole code is at home ... but the idea is clear , is what i believe..       thank you . 
  9. AneuryPerez

    Where to begin

    thank you i consider that you gave a good advise im going to follow it !!
  10. Greeting first of all !!      Im trying to write a engine simple to run all of the game I  trying to writte , im using SDL2  as a base , I can create the window , catch SDL_KEYDOWN and  handler it but everytime I tried to render a surface or a texture the program crash  below im going to leave the code if somebody could advise me please i would be very pleasure...  #include"include.hpp" #include"define.hpp" int main(int argc, char *argv[]) { GameEngine engine("title", 500, 400, false); InputStream is(engine); engine.Init(); //engine.InitWithRenderContext(); while(is.KeyListener()) { starCounter = SDL_GetTicks(); cout <<"\npolling event.\nFPS : "<<wait <<"and the key pressed respond at the next event : "<<is.getKeyEventEngine()<<endl; SDL_UpdateWindowSurface(engine.getWindow()); wait = 1000/FPS - ( starCounter - SDL_GetTicks() ); SDL_Delay(wait); } SDL_Quit(); cin.get(); return 0; } InputStream::InputStream(GameEngine ge):Run(true), EVENT_HANDLER_NO(0),g(ge){} bool InputStream::KeyListener() { SDL_Surface *im = SDL_LoadBMP("sprite1.bmp"); SDL_Rect rect ={10,10,0,0}; SDL_Rect clip ={0,0,100,100}; while(SDL_PollEvent(&this->event)) { if(this->event.type == SDL_QUIT) this->Run = false; if(this->event.type == SDL_KEYDOWN) { switch(this->event.key.keysym.sym) { case SDLK_q: this->EVENT_HANDLER_NO = QUIT; this->Run = false; break; case SDLK_UP: this->EVENT_HANDLER_NO = UP; break; case SDLK_DOWN: this->EVENT_HANDLER_NO =DOWN; break; case SDLK_LEFT: this->EVENT_HANDLER_NO = LEFT; rect.x -=10; SDL_BlitSurface(im, &clip, g.getScreen(), &rect); SDL_UpdateWindowSurface(g.getWindow()); break; case SDLK_RIGHT: rect.x +=10; SDL_BlitSurface(im, &clip, g.getScreen(), &rect); SDL_UpdateWindowSurface(g.getWindow()); this->EVENT_HANDLER_NO =RIGHT; break; case SDLK_f: this->EVENT_HANDLER_NO = FIRE; break; case SDLK_p: case SDLK_KP_ENTER: this->EVENT_HANDLER_NO = PAUSE; break; default: this->EVENT_HANDLER_NO = NONE; break; } } } return this->Run; } EVENT_BUTTON InputStream::getKeyEventEngine() { return this->EVENT_HANDLER_NO; } that 's the code thar result in crashing I know there are more ways but what is wrong with this .?    thank you ...
  11. AneuryPerez

    Where to begin

    greeting to all people ,wishing everything is well .   after that greeting I would like to ask maybe the repeat question !! where should I begin to code ? in fact  Im working as developer but in another area, and now I would like to know as beginner, what is the first step if it is possible a some step for beginner , and is good idea to pinned this post because I know there are plenty of people that is asking the same thing...something else  I followed some tutorial like lazyfoo , SDLtutorial , a old wiki from this site, I mentioned for example but in fact  I need something simpler than this , because  I know how to create a window  , how load a map but i need to read about logic of the game development...     maybe you understand , thank you in advance and apologize Im learning english too.. :)    
  12. Hello everyone here !! Wishing everything is ok here ,     I have a question  I believe I Saw in the forum but  I just cant find rigth now ,  I want to crop some part of a picture and apply to another surface or to a  screen but everytime  I do that  I Just dont get it i watched some tutorial about it on youtube, I read on some forun  I tried everything in my hand but  I dont understand could somebody help me out please.  #include <stdio.h> #include <stdlib.h> #include <string.h> #include <SDL/SDL.h> int main(int argc, char **argv){ if(SDL_Init(SDL_INIT_EVERYTHING) < 0 ) { fprintf(stderr, "error creado"); } SDL_Surface *pantalla =NULL; SDL_Surface *crop =NULL; SDL_Surface *imagen1 =NULL; SDL_Surface *imagen2 =NULL; SDL_Surface *imagen3 =NULL; SDL_Surface *imagen4 =NULL; SDL_Rect offset1; SDL_Rect offset2; SDL_Rect offset3; SDL_Rect offset4; offset1.x = 0; offset1.y = 10; offset1.h = 32; offset1.w = 32; offset2.x = 100; offset2.y = 10; offset2.h = 32; offset2.w = 64; offset3.x = 400; offset3.y = 10; offset3.h = 32; offset3.w = 96; offset4.x = 500; offset4.y = 10; offset4.h = 32; offset4.w = 200; if(((pantalla =SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE ))) == NULL ){ fprintf(stderr, "no se pudo iniciar la pantalla"); } SDL_WM_SetCaption("prueba de pantalla", NULL); crop = SDL_LoadBMP("img.bmp"); if(crop == NULL) { fprintf(stderr, "error cargando la imagen"); } imagen1 = SDL_DisplayFormat(crop); imagen2 = SDL_DisplayFormat(crop); imagen3 = SDL_DisplayFormat(crop); imagen4 = SDL_DisplayFormat(crop); if(imagen1 == NULL || imagen2 == NULL || imagen3 == NULL || imagen4 == NULL) { fprintf(stderr, "Error cargando el recurso."); } SDL_BlitSurface(imagen1, &offset1, pantalla, &offset1); SDL_BlitSurface(imagen2, &offset2, pantalla, &offset2); SDL_BlitSurface(imagen3, &offset3, pantalla, &offset3); SDL_BlitSurface(imagen4, &offset4, pantalla, &offset4); SDL_Flip(pantalla); SDL_Event evento; bool corriendo = true; while(corriendo){ if(SDL_PollEvent(&evento)) { if(evento.type == SDL_QUIT) { corriendo = false; } if(evento.type == SDL_KEYDOWN) { switch(evento.key.keysym.sym){ case SDLK_o: corriendo = false; break; case SDLK_q: offset1.x = 125; offset3.y = 87; offset3.h = 373; offset3.w = 571; SDL_BlitSurface(imagen1, &offset3, pantalla, &offset3); SDL_Flip(pantalla); break; default: break; } } } } SDL_Quit(); return 0; } well I attached the picture of what im getting even if change the offset. thank in advance, have a nice day.
  • 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!