Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

125 Neutral

About starfruit64

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. starfruit64

    Problem With Room Generation For Rougelike Game

    I appreciate your help, but I don't think this is the issue. if(check_walls(cell, &cur_x, &cur_y) == false is actually satisfied. Whenever i run the program, in fact, it seems always returns false. The check_walls function is used to test if there are any available neighbors of the current cell. If there are it changes cur_x and cur_y. If there are none, it is supposed to iterate through vector until it wither finds a cell that returns true when passed into check_walls, or until it runs out of cells. if (upblock == true && leftblock == true && downblock == true && rightblock == true) { *x = ori_x; *y = ori_y; std::cout << "Checkwalls returns false" << std::endl; return false; } I don't understand why you say this can't be satisfied. If all four of the cells surrounding the current cell are blocked, it should set all four of those bools to true and return false.
  2. starfruit64

    Problem With Room Generation For Rougelike Game

    Thanks for replying Rutin! Here is the github repository for the project: https://github.com/Starfruit64/Paladin Im not 100% if this is what you were asking for, so if it's not just say. And no, I'm not using Visual Studio, I'm using Eclipse. (p.s I'll keep what you said about initializing variables in mind)
  3. Hello, I'm programming a simple rougelike video game for fun. I'm running into a very difficult problem with my room generation code, specifically the part that deals with the maze-like hallway to connect the randomly placed rooms inside a dungeon, using the depth-first search method. The code I've written is kinda long and probably hard to read, but I seriously cannot figure out what is causing the issue so try to bear with me please. Below is the header file for the Floor class, which generates the floor of the dungeon. #ifndef FLOOR_H_ #define FLOOR_H_ #include <iostream> #include <vector> #include <algorithm> #include "Cell.h" class Floor { private: int attempts; //Amount of attempts it tries to place a room before giving up. More attempts = more cramped. int maxdoor; //Maximum amount of doors on each room int maxroom; //Maximum number of rooms. 0 for 999. int maxheight, minheight; int maxwidth, minwidth; int maxbigroom; std::vector<std::vector<Cell> > region; //A collection of regions. A region is a collection of cells (rooms & hallway) std::vector<Cell> temp_region; //Used to fill the region. std::vector<Cell> temp_maze; std::vector<Cell> maze; public: Floor(); void init(int attempts, int maxdoor, int maxroom, int maxwidth, int minwidth, int maxheight, int minheight, int maxbigroom); void gen(Cell cell[120][60], SDL_Texture* tex); bool check_walls(Cell cell[120][60], int* x, int* y); }; #endif The main thing that is important in this header is the temp_maze vector, which is used to keep track of the current section of the maze that has been carved out, so that when the maze hits a dead end it can back track. is the Cell is a class that represents a cell in the 2D grid that the player can move on. For the issue of this post, just think of each Cell as having an X integer, a Y integer, and a Bool to keep track of whether or not the cell is opened up. Below is the part of the gen function that deals with the hallway generation. //Hallway Generation int cur_x, cur_y; //Current cell being tested bool time_to_break; for (int i = 1; i < 119; i++) { for (int j = 1; j < 59; j++) { if (cell[i][j].return_blockade() == true && cell[i + 1][j].return_blockade() == true && cell[i][j + 1].return_blockade() == true && cell[i - 1][j].return_blockade() == true && cell[i][j - 1].return_blockade() == true) { //Start of a path cur_x = i; cur_y = j; while (true) { cell[cur_x][cur_y].set_bloc(false); //Opens up cell cell[cur_x][cur_y].set_tex(tex); cell[cur_x][cur_y].set_default_tex(tex); temp_maze.push_back(cell[cur_x][cur_y]); if (check_walls(cell, &cur_x, &cur_y) == false) { std::cout << "Entering nospace" << std::endl; std::cout << "Size of k: " << temp_maze.size() << std::endl; for (int k = temp_maze.size() - 1; k > -1; k--) { int xte = temp_maze[k].return_rect().x / 15; int yte = temp_maze[k].return_rect().y / 15; std::cout << "k: " << k << std::endl; std::cout << "rect_x: "<< temp_maze[k].return_rect().x<< " rect_y : "<< temp_maze[k].return_rect().y<< std::endl; std::cout << "x_te: " << xte << " y_te: " << yte << std::endl; if (check_walls(cell, &xte, &yte) == true) { cur_x = xte; cur_y = yte; std::cout << "Exiting nospace via newblock" << std::endl; break; } if (k == 0) { time_to_break = true; std::cout << "Exiting nospace via noviableblock" << std::endl; break; } } } if (time_to_break == true) { time_to_break = false; temp_maze.clear(); break; } } } } } The broad idea is that, starting from the top-left cell, we scroll through them until we find a cell that is not blocked, nor has any neighbors that are blocked. Than we open that cell up, add it to the temp_maze vector, and check whether it has any viable neighbors. If it does, it moves cur_y and cur_x to that new cell and repeats. If it doesn't have any viable neighbors, than it goes through the temp_maze vector until either it finds a cell that has viable neighbors, or it reaches the end of the vector. This is accomplished with the check_walls function. bool Floor::check_walls(Cell cell[120][60], int* x, int* y) { int ori_x = *x; int ori_y = *y; std::cout << "Entering checkwalls with x: " << ori_x << " y: " << ori_y << std::endl; if (cell[ori_x][ori_y].return_blockade() == true) { std::cout << "Checkwalls returns false due to being blocked" << std::endl; return false; } while (true) { *x = ori_x; *y = ori_y; bool upblock, rightblock, downblock, leftblock; int sidecount = 0; int dir = rand() % 4; if (dir == 0) { *y = (*y) - 1; } else if (dir == 1) { *x = (*x) - 1; } else if (dir == 2) { *y = (*y) + 1; } else if (dir == 3) { *x = (*x) + 1; } if (*x <= 0 || *y <= 0) { sidecount = 8; dir = 5; *x = ori_x; *y = ori_y; } if (cell[*x + 1][*y].return_blockade() == false) { sidecount++; } if (cell[*x - 1][*y].return_blockade() == false) { sidecount++; } if (cell[*x][*y + 1].return_blockade() == false) { sidecount++; } if (cell[*x][*y - 1].return_blockade() == false) { sidecount++; } if (sidecount <= 1) { std::cout << "Checkwalls returns true" << std::endl; return true; } else { if (dir == 0) { upblock = true; } else if (dir == 1) { leftblock = true; } else if (dir == 2) { downblock = true; } else if (dir == 3) { rightblock = true; } } if (upblock == true && leftblock == true && downblock == true && rightblock == true) { *x = ori_x; *y = ori_y; std::cout << "Checkwalls returns false" << std::endl; return false; } } } The basic idea here is that if one of the neighbors are available, than it moves x & y to that cell and return true, and if there are none, than return false. The problem is that when I run this the temp_maze function seems to get filled with the same cell, and time_to_break never gets set to true, as the vector seems to never end. Once again I understand this is kind of a lot but I have looked at this for a couple days now and have no idea what i am doing wrong, so any help would be very much appreciated.
  4. starfruit64

    Tetris Clone Code Review Request

    About events: should I remove the Input class and have all events handles in Main in a function? Or should I have multiple times where I poll for events, one time for input, one time for window events, etc.?
  5. Hello! I have made a clone of Tetris using SDL libraries for C++. I would love to get some input as to what I have done right and wrong. Also please tell me if im using Github correctly, it confuses me greatly. (I tried to add a new commit to remove the misplaced header file "DungeonCrawlV4.o" but it doesn't seem to have taken place.) https://github.com/Starfruit64/Tetris-Clone
  6. I've heard from many places (including this website) a really helpful thing you can do as a beginner is have someone review your game code, and to go back and update it using peoples suggestions. Are there any good websites for this that is open to beginners? 
  7. starfruit64

    SDL rotate rect evenly?

    Even when i convert the degrees to radians the laser is still off. I think this is because you though that x and y were the center of the bullet rect, but it is actually the upper left-hand corner. I tried adding 1/2 ship_width to the offset x but this doesnt help. How should I adjust my code? Thanks.
  8. starfruit64

    SDL rotate rect evenly?

      When I try this code it only amplifies the problem. The bullet is very far off from the ship, and when the player rotates the ship the bullet sporadically moves close and away from the ship. I don't understand why multiplying the width of the ship divided by two by the angle would help at all to be honest. 
  9. starfruit64

    SDL rotate rect evenly?

    I am making a basic "space shooter" game to test myself. I am using SDL external library in c++ to make it. I have a class called "Bullet" and a vector of Bullet objects. I als o have a class called "Ship", which is the player. When the player shoots, one of the Bullet objects is teleported to the player and given the angle of the player. The problem is that when the player is to the side the bullet is off-center. Can anybody help me? Here is my code for my class: void Bullet::shoot(float ship_x, float ship_y, float ship_angle, int ship_width){ x = ship_x + (ship_width/2) - (width/2); y = ship_y; angle = ship_angle; } When the ship is pointing up (0 degree angle) or down (180 degree angle) than the bullet spawns perfectly. But the more away it gets from those the more off kilter it gets. Any thought?
  10. I am trying to make a top down space shooter thing in SDL. I am trying to move the ships rect so that it goes forward at the angle the ship is at. From what I have read, in order to do this would do something like: rect.y -= sin( angle*( PI/180 ) ) * speed; rect.x -= cos( angle*( PI/180 ) ) * speed; Is this what I should do? Because when I add this to my loop, the ship moves in the opposite direction, and the movement is usually curved, not straight. And if the angle is set to 0, the ship moves sideways. Any help is appreciated.
  11. Hello, I am making a simple little text-based RPG/Dungeon Crawler game to help me practice C++. But I have come across an odd bug. I have narrowed it down to this bit of code: ...more code cout << "A " << name << " attacks!" << endl; //Checks who attacks first int initiative = rand() % 2; if(initiative == 0){ cout << "The " << name << " strikes first!" << endl; int damage = (rand() % max + min); hp =- damage; cout << endl; cout << "The " << name << " dealt " << damage << " points of damage!" << endl; } string bin; cout << "Press any key to continue > " << flush; cin >> bin; system("cls"); //Combat loop while(true){      ...more code   If initiative = 1, than the program works like its supposed to: the enemy doesn't attack first and after the user inputs something after "Press any key to continue" the game continues on. But if initiative = 0 than it gets weird. It displays the "Enemy struck first...enemy dealt x damage" etc. but when the user enters input after it prompts  "Press any key to continue" the program just enters an infinite loop  with no text on screen. Any ideas as to why this could be happening?
  12. starfruit64

    SDL_TTF crashes c++ program?

    Alright you and everyone else has been super helpful. This fixed the crash but now when I run the program and update the screen, the text isn't there. My code is this:  #include <iostream> #include <fstream> #include <SDL.h> #include "SDL_ttf.h" #include "Input.h" #include "Screen.h" using namespace std; Screen screen; Input input; SDL_Renderer *renderer; int main(int argc, char* argv[]) { screen.init(); screen.test_text(); screen.update(); while (true) { string event = input.check_event(); if(event == "1"){ break; } } TTF_Quit(); SDL_Quit(); return 0; }   screen.init(); does this: bool Screen::init() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { return false; } if(TTF_Init()==-1) { printf("TTF_Init: %s\n", TTF_GetError()); exit(2); } window = SDL_CreateWindow("Particle Simulation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HIGHT, SDL_WINDOW_SHOWN); if (window == NULL) { return false; } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); if (renderer == NULL) { return false; SDL_DestroyWindow(window); SDL_Quit(); } texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, WIDTH, HIGHT); if (texture == NULL) { return false; SDL_DestroyWindow(window); SDL_DestroyRenderer(renderer); SDL_Quit(); } buffer = new Uint32[WIDTH * HIGHT]; return true; }  screen.test_text(); does this: void Screen::test_text(){ TTF_Font* font = TTF_OpenFont("C:\\Users\\KP7\\Desktop\\C++2\\Hero\\Debug\\block.ttf", 24); SDL_Color color = {255, 255, 255}; SDL_Surface* surfaceMessage = TTF_RenderText_Solid(font, "Hello World!", color); SDL_Texture* message = SDL_CreateTextureFromSurface(renderer, surfaceMessage); SDL_Rect message_rect; message_rect.x = 0; message_rect.y = 0; message_rect.w = 100; message_rect.h = 100; SDL_RenderCopy(renderer, message, NULL, &message_rect); }  and screen.update(); does this: void Screen::update() { SDL_UpdateTexture(texture, NULL, buffer, WIDTH * sizeof(Uint32)); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); }  This just displays a black screen for me. Does anyone know why?
  13. starfruit64

    SDL_TTF crashes c++ program?

    How can I check this? I think you are right in that i dont have Sans.ttf in the current working directory, but how can i find out what that directory is?
  • 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!