• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

MoBaT

Members
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

115 Neutral

About MoBaT

  • Rank
    Member
  1. I understood the code you gave me and it worked fine with displaying the map around the character but what I meant was this: Now the code you gave me displays the map around the character but the character dosent stay on my screen and can move out of the bounds becuase of the map loading around the character.    When I add this code: offset2.x = (x - startX) * TileZoom; offset2.y =(y - startY) * TileZoom; offset2.w = TileZoom; offset2.h = TileZoom;   The map stays within my 800 x 600 screen but the character can venture off and it's not in the middle.   Will I have to do some calculations for the player so it can stay in the middle of my screen? Let me just show my whole code instead of a partial bit.   void Map::OnRender(SDL_Surface* Surf_Display, int MapX, int MapY) { //Rectangles SDL_Rect offset; SDL_Rect offset2; // Loop through laters for (int i = 0; i < map->GetNumLayers(); ++i) { const Tmx::Layer *layer = map->GetLayer(i); const int maxX = map->GetHeight(); const int maxY = map->GetHeight(); const int showWidth = 15; const int showHeight = 13; //Starting point of tiles. int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2)); if (startX <= 0) startX = 0; int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2); if (startY <= 0) startY = 0; //Keep camera in bounds of the map. if(startX < 0) startX = 0; if((startX + showWidth) > maxX) startX = (maxX - showWidth); if(startY < 0) startX = 0; if((startY + showWidth) > maxY) startY = (maxY - showWidth); //Ending point of tiles. int endX = (startX + showWidth); int endY = (startY + showHeight); for (int y = startY; y < endY; ++y) { for (int x = startX; x < endX; ++x) { // Get tileID int TileID = layer->GetTileId(x, y); if (TileID != 0) { int tilesetID = map->GetLayer(i)->GetTileTilesetIndex(x, y); int margin = map->GetTileset(tilesetID)->GetMargin() * ZOOMSCALE; int spacing = map->GetTileset(tilesetID)->GetSpacing() * ZOOMSCALE; int TileZoom = (TILE_SIZE * ZOOMSCALE); int TilesWidth = tileSet[tilesetID]->w / TileZoom; int tileRow = TileID % TilesWidth; int tileColumn = ((TileID - tileRow) / TilesWidth); // Set tileset tile X, Y offset.x = ((tileRow * TileZoom) + tileRow * margin) + spacing; offset.y = ((tileColumn * TileZoom) + tileColumn * margin) + spacing; offset.w = TileZoom; offset.h = TileZoom; //Where to draw on gamemap offset2.x = (x - startX) * TileZoom; offset2.y =(y - startY) * TileZoom; offset2.w = TileZoom; offset2.h = TileZoom; //Blitz. SDL_BlitSurface(tileSet[tilesetID], &offset, Surf_Display, &offset2); } } } } }
  2. Accidently posted twice.
  3. Finally, I tried doing something similar but probably failed at it. I got it working with this code. Thanks for your hard work, I appreciate it. I have one more questions involving the camera. Since the code now works and draws the map around the character, how would I got by implementing the camera so the player stays on the middle of the screen at all times in my 800 x 600 windows. I thought of just going to my player render code and subtracting the offset the character was at it can stay in the middle, but that sounds like a dirty way.   const int minX = 0; const int maxX = map->GetHeight(); const int minY = 0; const int maxY = map->GetHeight(); const int showWidth = 15; const int showHeight = 13; //Starting point of tiles. int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2)); if (startX <= 0) startX = 0; int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2); if (startY <= 0) startY = 0; //Keep camera in bounds of the map. if(startX < minX) startX = minX; if((startX + showWidth) > maxX) startX = (maxX - showWidth); if(startY < minY) startX = minY; if((startY + showWidth) > maxY) startY = (maxY - showWidth); //Ending point of tiles. int endX = (startX + showWidth); int endY = (startY + showHeight);        I can keep the map on my screen by replacing the offset in my loop from:      offset2.x = x * TileZoom; offset2.y =y * TileZoom; offset2.w = TileZoom; offset2.h = TileZoom; to offset2.x = (x - startX) * TileZoom; offset2.y =(y - startY) * TileZoom; offset2.w = TileZoom; offset2.h = TileZoom;
  4. Sorry I'm not being that clear. I mean I want to draw the map around my player similar to what you showed above in the images but using the code I have provided above. That's what my two for loops were above in my second post. I tried getting the characters position and then loading 10 tiles before him and 10 tiles after him. Same thing for the y axis.
  5. So basically you have map files from like 1 - 100 let's say and each file is 20 x 20 tiles. Then you load the maps depending on the area they're at.  What I tried doing was something like:   for (int y = playerYTILE - 10; y < playerYTILE + 20; ++y) { for (int x = playerYTILE - 10; x < playerYTILE + 10; ++x) { //CODE } }   But when I was walking, my character was moving faster than the map loading itself, which does not make sense to me since it uses the tile it's on. I could implement a chunk system, but spent some time trying to get this method working.
  6. I cannot grasp the concept of the map loading all around the player. For example if the map loads 10 to the left of the player, 10 right, 10 up, and 10 down, I cannot think of a way to incorporate that into my code. I'm having a brain fart.   int xcoord = player->xcoord; // Players x coord will be the original coord * (TILE_SIZE * zoom) int ycoord = player->ycoord; // Players x coord will be the original coord * (TILE_SIZE * zoom) //Rectangles SDL_Rect offset; SDL_Rect offset2; // Loop through laters for (int i = 0; i < map->GetNumLayers(); ++i) { const Tmx::Layer *layer = map->GetLayer(i); // TILE_SIZE = 32, ZOOM = 2.0; // Loop through tile number in layers. Tile #(2, 1) on the map would be 2 * (TILE_SIZE * ZOOMSCALE) down the x and 1 * (TILE_SIZE * ZOOMSCALE) down the y; // 0 1 2 3 4 // 1 // 2 // 3 // 4 // Loop through tiles from tile (0, 0) to (20, 20); for (int y = 0; y < 20; ++y) { for (int x = 0; x < 20; ++x) { // Get tileID int TileID = layer->GetTileId(x, y); if (TileID != 0) { int tilesetID = map->GetLayer(i)->GetTileTilesetIndex(x, y); int margin = map->GetTileset(tilesetID)->GetMargin() * ZOOMSCALE; int spacing = map->GetTileset(tilesetID)->GetSpacing() * ZOOMSCALE; int TileZoom = (TILE_SIZE * ZOOMSCALE); int TilesWidth = tileSet[tilesetID]->w / TileZoom; int tileRow = TileID % TilesWidth; int tileColumn = ((TileID - tileRow) / TilesWidth); // Set tileset tile X, Y offset.x = ((tileRow * TileZoom) + tileRow * margin) + spacing; offset.y = ((tileColumn * TileZoom) + tileColumn * margin) + spacing; offset.w = TileZoom; offset.h = TileZoom; //Where to draw on gamemap offset2.x = x * TileZoom; offset2.y = y * TileZoom; offset2.w = TileZoom; offset2.h = TileZoom; //Blitz. SDL_BlitSurface(tileSet[tilesetID], &offset, Surf_Display, &offset2); } } } }  
  7. I got another question relating to this. How would I make it where I can use my Sprite class and use it in the loops? My loop loops through the different tiles and each of those tiles has a tileID from my bmp file. If the getTileID returns 23, it means it's the 23rd block in my bmp so I have to change my Surface for the new rectangle. I tried doing it but kept on getting the lagging problem because I frequently change the sprite for the different tiles.
  8.   Worked perfectly. Thank you, I should've known.
  9. I'm using tmx files for my map and finally got a tmx loader to work. The map drawing code is lagging my game because of the CPU usage. To draw my map, im using code which is:   for (int i = 0; i < map->GetNumLayers(); ++i) { // Get a layer. const Tmx::Layer *layer = map->GetLayer(i); for (int y = 0; y < 20; ++y) { for (int x = 0; x < 20; ++x) { // Get a test tile which is 32 x 32. Sprite* Suf2 = new Sprite(Surf_Tileset->getRect(TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE), 1, 0); // Draw tile to position on map Suf2->draw(Surf_Display, x * TILE_SIZE, y * TILE_SIZE); } } }   So this code is on my Map::OnRender(SDL_Surface* Display). What can I do to keep my cpu from maxing?
  10. I got a question for how should I be creating my tilemap. Should I make it where I just draw the map myself and then specify the spots where different collisions are like what this guy did: http://a248.e.akamai.net/camo.github.com/28e1bb15d28335f2d7763576debf5543cf6a255b/687474703a2f2f6b656e2d736f66742e636f6d2f696d616765732f7a656c64612f7a656c6461392e706e67   Or should I make it where I just draw the map based on: 1:0 1:1 0:1 0:1   Where the first part is the map tile id and the second is if it's a certain item like a hole, water, solid etc.
  11. I have a problem with the SDL Events. I have a code which looks like: while (SDL_PollEvent(&Event)){ OnEvent(&Event); }   then the OnEvent processes the event and directs it to the proper virtual function. So If I were to hold down the right key button, it would go here.   void Engine::OnKeyDown(SDLKey sym){ switch(sym) { case SDLK_RIGHT: x1 += 1; break; } }   The problem is that when I am holding the right button key, it is only running one time. The queue does not stack and keep processing the keydown button. What could be the problem?