# Sunsharior

Member

43

1567 Excellent

• Rank
Member
1. ## What would you be willing to trade to get your ideal job in the gaming industry?

I would sacrifice a lot more things (i've already sacrificed so much), but i wouldn't sacrifice my happiness.

3. ## Creating menus using Codeblocks (C++)

Also, each Menus can be a state inside the engine you are using, making a simple interface with Update, Draw and Clear or what ever fit your need. Consider using one state per menu, unless your design do not need it.   Just plug the current state inside the main game loop and change it when you need it.   We'll be happy to answers more question.
4. ## Creating rectangles with contiguous filled grid cell

I finally figured out the algorithm i needed. Here is my solution, in case some one need it (in C++).   Please note that my solution will scan along the X axis all the way to the end before going to the next row. This is exactly how my game need it, but i feel the need to mention it. The algorithm is not optimized. In my case, it did not need to be optimized. ////////////////////////////////////////////////////////////////////////// // Calculate the rectangles that can exist in a grid. std::vector<SDL_Rect> MapManager::CalculateVoidZones() {     std::vector<SDL_Point> corners;     std::vector<SDL_Point> sizes;     // Retrieve the maximum col and row. note that the col and row are already shrinked by 1.     SDL_Point max = {mInfo->GetCol(), mInfo->GetRow()};     // scan a col. Start from top left.     for(int row = 0; row <= max.y; row++)     {         // remember the current width for consecutive void state.         const short INVALID = -1;         SDL_Point lastcorner = {INVALID, INVALID}; // invalid corner.         int width = 0;         // scan a col. go right.         for(int col = 0; col <= max.x; col++)         {             bool lastcol = (col == mInfo->GetCol() && width > 0);             bool addnewcorner = false, nonvoid = true;             // if the cell is a void.             if(GetTile(row, col)->IsState(STATE_TILE_VOID))             {                 nonvoid = false;                 if(lastcorner.x == INVALID && lastcorner.y == INVALID)                 {                     lastcorner.x = col;                     lastcorner.y = row;                 }                                  bool addwidth = lastcorner.x == (col - width);                 if (addwidth)                     width++;                 if(!addwidth || lastcol)                     addnewcorner = true;             }             if(addnewcorner || (nonvoid && width))             {                 bool fit = false; // do the rectangle fit into a previous one?                 // loop through all existing corners                 for(unsigned int i = 0; i < corners.size(); i++)                 {                     if(corners[i].x == lastcorner.x &&                         corners[i].y == (lastcorner.y - sizes[i].y) &&                         width == sizes[i].x)                     {                         // increase the height                         sizes[i].y++;                         fit = true;                     }                 }                 if(!fit)                 {                     corners.push_back(lastcorner);                     SDL_Point size = SDL_Point();                     size.x = width;                     size.y = 1;                     sizes.push_back(size);                 }                 // reset                 lastcorner.x = INVALID;                 lastcorner.y = INVALID;                 width = 0;             }           }     }     // finally, create the rects     std::vector<SDL_Rect> voidzones;     if(corners.size() && corners.size() == sizes.size())     {         for(int i = corners.size(); i--;)         {             SDL_Point corner = corners[i];             SDL_Point size = sizes[i];                          // mTw and mTh is the width and height of a tile, respectively.             SDL_Rect rect = {corner.x * mTw,                              corner.y * mTh,                              size.x * mTw,                              size.y * mTh};             rects.push_back(rect);         }     } return voidzones;     } Have a good day.

6. ## Creating rectangles with contiguous filled grid cell

Only the rectangles are interesting me.   This means a "star" shape composed of one 3x3 square and 1 filled cell on each side on the middle will be counted as 5 different rectangles. (the 3x3, and 4 1x1s).   0001000 0011100 0111110 0011100 0001000
7. ## Creating rectangles with contiguous filled grid cell

Hi. I'm currently trying to find a solution to a grid filling problem. Unfortunately, i'm having trouble imagining the implementation.   I will explain. In a 2D grid, a cell can be filled or not. I need to retrieve the total number of contiguous rectangles that can be formed by the filled regions. I'm fairly sure what i'm looking after have a name, but it's hard to google it without the proper name. I have attached an image of what i mean at the end of this post.   Currently, i have a double for loop for each rows and each columns. I remember the amount of "widths" of consecutive filled cell of the last row and if the current row have the same "widths" at the same place, i add one to that width height. But this is where i'm stuck, i can't find the rest of the logic. // This function will calculate the number of void zone and store it in mVoidZones void MapManager::CalculateVoidZones() { // array of rectangle (X, Y, W, H). mVoidZones.clear(); std::vector<SDL_Point> lastcorners; std::vector<int> widths; std::vector<int> heights; // scan a col. for(int col = 0; col < mInfo->GetCol(); col++) { // remember the current width a consecutive void state. int width = 0; SDL_Point lastcorner = SDL_Point(); lastcorner.x = -1; lastcorner.y = -1; // scan a row. for(int row = 0; row < mInfo->GetRow(); row++) { // fetch if the cell is "filled" if(GetTile(row, col)->IsState(STATE_TILE_VOID)) { // add a corner if(lastcorner.x == -1 && lastcorner.y == -1) { lastcorner.x = col; lastcorner.y = row; width = 1; } // increment the current width else if (lastcorner.x == col - 1) width++; } // a gap is found. Close the current width. else if(width > 0) { lastcorners.push_back(lastcorner); widths.push_back(width); lastcorner.x = -1; lastcorner.y = -1; width = 0; } } } // TODO this function is incomplete. // It is missing the "corner" comparison, then adding the height // then creating the rectangle and pushing it to mVoidZones. } Take note that the grid can be massively scrambled or even checkered, creating a huge number of small rectangles.   As always, thank you for your time. I will continue searching in the meantime.

9. ## Implementing a quest/achievement system

The observer design pattern is a good idea for decoupled achievements. Here is a link to an article describing it: http://gameprogrammingpatterns.com/observer.html

You are missing the methods "clean" and "update" from the file SDLGameObject.cpp
11. ## How to implement skeletal animation in 2d game?

If you prefer to do thing yourself, i have something for you that you might like. I'll just explain how i did something similar in my game. With more than 250 weapons sprites, it was out of the question to actually draw each sprite. So what i did was creating my own tool to manage the sprite animations and hitboxes. After that, i added "anchors" to each frame of animation to set where the weapon goes. Good thing is, i can even set anchor point for the weapon when it's sheathed. You need two anchors, one to set where it goes and another to set the angle. So basically, i'm not using a complexe bone system but only anchor points to tell my game "that weapon goes there" at that frame. Obviously, this method was very time consuming, but it give you an alternative to Spine.
12. ## Rotating a sprite in SDL2?

With this simple snipet, you will be able to draw a sprite. // for this to work, i will assume you already have a SDL_Renderer and a SDL_Window. SDL_Texture *texture = IMG_LoadTexture(renderer, "image.png"); // if the texture was loaded. if(texture) { SDL_Rect rect = {0, 0, 32, 32}; // the rect is where you wants the texture to be drawn (screen coordinate). SDL_Rect crop = {0, 0, 16, 16}; // the crop is what part of the image we want to display. float angle = 180.0f; // set the angle. SDL_Point center = {8, 8}; // the center where the texture will be rotated. SDL_RendererFlip flip = SDL_FLIP_NONE; // the flip of the texture. // now, try to draw something int result = SDL_RenderCopyEx(renderer, texture, &crop , &rect, angle, &center, flip); if(result!= 0) std::cout << SDL_GetError() << std::endl; } else std::cout << Error << "Couldn't render texture." << std::endl; Using this example, you will draw an image rotated 180 degree. It will be drawn at 0,0 with a width of 32 and a height of 32. The crop is 16x16 and the rotation is 180 that is centered at 8,8.   I hope this help. If you have errors, feel free to post it.
13. ## Text Based RPG help

Like Josh Petrie said, you declared functions in a header file that were never defined elsewhere. I have enclosed 3 of your project's file code with the error fixed.   You will noticed a few things:   1. I have created the Prologue.cpp file and moved the content from Char info.cpp to it. 2. The prologue is now used as a class instead of static. See the modification i did to Main.cpp to notice it's scope remain inaffected. 3. The fonctions and member variables of the class Prologue are no longer static. Prologue.cpp now have the proper definition of thoses fonctions, and a constructor aswell. 4. The file Char info.cpp has been deleted.
14. ## How should i process about embedding a SDL2 game into QT to make a level editor.

Thank you for your reply Dejaime. It helped me do the initial setup.   After fiddling this weekend, and doing additional researches, i've partially solved my problem. I'm not done yet but i've successfully draw something in QT using Sdl2. Now, what i'm missing is just the Inter-process communication between the QT application and my game. I should be able to do that during this week.   So, it's looking good, at the moment :).
15. ## How should i process about embedding a SDL2 game into QT to make a level editor.

Hello everyone.   The video game engine i'm working on is amost complete. Right now i'm working on refactoring part i don't like. One of the part i do not like is the current level editor. It's currently a seperate window that have the basic fonctionality (see screenshot). So i wants to make everything nicer and do a level editor using QT.   I want to make a basic QT Dialog that have embedded inside the game engine. However, i'm very confused about how i should do it. Right now, i'm struggling to make SDL2 work within QT and i'm not even sure if it's the right approche i'm doing. I'm currently able to draw with SDL2 within QT, but i really don't know how to make my game work inside.   Some detail: i'm using QT 5.3.x via Vs2012 (not qteditor). My game engine is an executable that use SDL2 for graphic, sound and key inputs. I've heard i might have problem with graphic rendering and sound, so i'm hesitant on how to proceed. Should i make my game engine a DLL to run within QT or is a .Exe okay? If more information is needed, i will give it.   As always, thank you very much for your time. ps. Sorry for my english.