• 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.


  • Content count

  • Joined

  • Last visited

Community Reputation

108 Neutral

About DanielWilkins

  • Rank
  1. Thank you for the reply. Someone else suggested SDL_gfx which supports blitting semi transparent surfaces to other semitransparent surfaces (RGBA to RGBA). It works perfectly. To recap, the reason I do this is so I build the sprite completely and then ship it off to the renderer without sending them in pieces (8 or 9 render calls per explosion). Cheers!
  2. Bump. And I think I overly confused people. Here is what I am trying to do: I am trying to create a composite surface by blitting to that surface. I need the surface to be initially transparent and I need to blit the image I linked above which has transparency onto it. If need be, I can also color the background of the explosion image I linked pink and use an alpha key if that works with SDL. Any advice?
  3. Hi. I am writing a Bomberman clone and trying to blit parts of an explosion to a surface and then render that surface but have ran into problems. Here is my function: [CODE] SDL_Surface* SpriteManager::buildExplosion(int id, SDL_Surface* image, int size) { // Create the surface that will hold the explosion image SDL_Surface* explosion = SDL_CreateRGBSurface(SDL_SRCALPHA, size * 32 , size * 32, 32, 0, 0, 0, 0 ); // Our source and destination surfaces SDL_Rect srcrect; SDL_Rect dstrect; int parentX = sprites[id].x; int parentY = sprites[id].y; int middle = size / 2; // Create the first image srcrect.x = sprites[id].imgBlockX * 32; // default for now srcrect.y = sprites[id].imgBlockY * 32; // default for now srcrect.w = 32; srcrect.h = 32; // Get the location it should be applied to dstrect.x = middle * 32; dstrect.y = middle * 32; dstrect.w = 32; dstrect.h = 32; // Apply the texture SDL_BlitSurface(image, &srcrect, explosion, &dstrect); return explosion; }[/CODE] As of now, it only blits the 32x32 tile at 0,0 in the image to the middle of the destination tile. I am 99% sure all the code here is correct as my debug output is consistent with where everything should be. What it ends up doing is producing an image that is the correct size BUT only has a 32x32 black tile in the upper left hand corner. I am wondering if there is a problem with the fact I am blitting from an image with an alpha mask. Here is the image: [url="http://i.imgur.com/eKD88.png"][img]http://i.imgur.com/eKD88.png[/img][/url] So to recap: I am blitting the first tile at 0, 0 with size 32x32 to the middle of the surface I have created. What ends up happening is that it only renders a single 32x32 black tile in the upper left hand corner of the created surface (at least I know the surface is rendering in the correct place) [url="http://i.imgur.com/cRzLk.png"][img]http://i.imgur.com/cRzLk.png[/img][/url] In the above picture, the upper left player dropped a bomb and it exploded. It had a power of 2 meaning that the box was 5 tiles in width and height. Let me know if you have any questions. Thank you.
  4. Hi. I am writing a Bomberman clone and would like some advice on the way most 2d engines communication between classes (still preserving object oriented class design). For instance, I wrote an entity manager which contains all of the main classes for the game. It's basically an encapsulation of the game to take it out of the main.cpp file. It handles updating all of the classes (players, bombs, items). Now I have gotten to an interesting point. I had the handleInput() function in my main.cpp file but have since moved it into my class manager. I guess my question is if there is an agreed upon way to have two classes communicate with eachother. For example, if I were to handle input in the player class for each player individually and the player hits space bar, what would be the best way to alert the bomb class to create a new bomb at the location provided by the player. Would some sort of event queue be the way to go. Here is a simple visualization of the classes:[list] [*]--EntityManager [*]-Player [*]-Bombs [/list] I want to keep the EntityManager as abstract as possible for reuse in other games so while updatePlayers() and updateBombs() (functions that invoke the update routine by each class) is fine by me, I want to shy away from things like addBomb() and more really specific stuff which should be in each class. Does anyone have any advice on this matter? Or maybe a good design document to look at? Thanks a bunch!
  5. Thank you both again. Last question as I have the whole thing implemented and working: Does SDL have an accurate enough timer or should I grab a more precise one? Any recommendations? Thanks!
  6. Hi all. Sorry I ducked out for a bit. The first implementation was a bastardization of the main loop on the article: [url="http://gafferongames.com/game-physics/fix-your-timestep/"]http://gafferongames...-your-timestep/[/url] To be honest, the physics and calculus nature of his implementation confused me so although I implemented it, I know it was incorrect. I have since redone the loop using dewitters last game loop (is this also fixed time step), and have gotten good results... Here's the thing. I am not here to make a quick game, I want this to be a solid engine I can produce a game on, extend and reuse. I know physics will eventually be part of the game and although I don't anticipate writing my own physics engine, I would love to know the actual logic behind it. Because I have been less than clear and confused, and you have all been incredibly helpful in providing articles and source, let me break down my understanding of it and I will ask questions. Again, my apologies. I will be basing my questions, understand off of: [url="http://gafferongames.com/game-physics/fix-your-timestep/"]http://gafferongames...-your-timestep/[/url] Please tell me what I have missed. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] -------------------------- [b] Fixed delta time[/b] So the inherent problem here is the rate at which you update your game. You shouldn't just update the game as fast as possible as that will make programs/games run faster on faster computers and slower on slower computers. Not ideal. [b] Variable delta time[/b] The logical solution (what I tried as well) is to measure the time it takes for each frame and record the time change (the delta). Then pass this into the physics simulation. This will provide consistent speed but differing physics results on different framerates. Also for some reason, they are keeping track of the total time represented by t, for some reason. Why is this? It is used in the integrate function which I understand to be an integral from Calculus. [b] Semi-fixed timestep[/b] The solution to this is to ensure the delta time is small and the results will be (nearly) identical every time. If I understand correctly, this loop takes the last frame rate (i think) and then updates the physics continuously, decrementing the frametime until it is zero and finally renders the frame. FINAL SOLUTION The final solution is to have a fixed delta time (time between updates) so that your physics are run at regular intervals BUT at the same time, render independently. Again, I am confused by some of his functions like integrate. I assume this is his physics update, just the same as I would update a player's position. To do this, he caps the delta time which will affect physics at a specific time to avoid the spiral of death. The next part is where I am confused: [CODE] while ( accumulator >= dt ) { previousState = currentState; integrate( currentState, t, dt ); t += dt; accumulator -= dt; } [/CODE] When he integrates, what exactly is he updating? How would that apply to moving a character across the screen rather than a calculus function? Then, when the accumulator is smaller than delta time, he calculates the alpha value which is interpolation? Then, he interpolated the position of the ball (and in my case, a character) by the value alpha (this makes sense) My main question about this last loop is about the code I linked above is what exactly is it doing. What does integrate do? Is it just a general physics function? What would I do instead for a simple bomberman clone during that time. ---------------- Thank you again. It's quite funny. I have pretty much everything else coded and yet, my main loop keeps changing. I really appreciate the time you guys have spent helping me. Sorry that I have learned this a bit slow. I will make sure to pay it forward and help others. Thanks!
  7. Fixed everything with floats. Movement still feels a little bit off. Not sure why... Anyone willing to test and let me know what you feel. Feels a lot smoother now compared to what it used to be but a weird issue seems to involve the character moving faster in the open part of the level. It check collision less there when aligned with the grid but I thought the whole purpose of this kind of loop was to remove temporal antialiasing (which is has) and make it steady rendering throughout. How would I modify my main loop to work at a fixed frame rate?
  8. I have made some progress but am still confused a bit: First of all, I keep track of locations in integers. I do this because I didn't assume you could be between pixels but now I realize when I am using doubles that effect the x and y values, I might have to make the switch. Edit: I definitely have to make the switch. It seems as if it was dropping the precision on the speed. 0.9 became 0 and 1 was way too fast. Here is my revised main loop: [CODE] int main(int argc, char *argv[]) { // Initialize everything if(!init()) { errorLog.writeError("Failed to initialize engine components!"); return 1; } // Time variables double t = 0.0; const double dt = 0.01; double currentTime = SDL_GetTicks(); double accumulator = 0.0; // Run until the user has requested a quit while ( !quit ) { double newTime = SDL_GetTicks(); double frameTime = newTime - currentTime; if ( frameTime > 0.25 ) frameTime = 0.25; currentTime = newTime; accumulator += frameTime; // Loop until we are ready to render, updating as we go while ( accumulator >= dt ) { update( dt ); t += dt; accumulator -= dt; } // Get the time we use for interpolation const double alpha = accumulator / dt; // Interpolate the values player.interpolate(alpha); // Render the scene renderScene(); } return 0; }[/CODE] When I interpolate the values, I do so like this: [CODE] void Player::interpolate(double alpha) { renderXPos = curXPos * alpha + lastXPos * (1.0 - alpha); renderYPos = curYPos * alpha + lastYPos * (1.0 - alpha); }[/CODE] My question is how delta time and time play a role in updating the physics. I have my speed as an integer at 3. It moves about how fast I want it. In the main player update function: [CODE] void Player::update(double dt) { float pSpeed = speed * dt; ... collision handling, etc.. position updating... }[/CODE] Am I using delta time correctly? Should I be applying it to speed or did I miss the point. Thanks to everyone who has helped me understand this so far. Edit: Apologies for the formatting. Not sure why it undoes the formatting I have in my IDE.
  9. Beernuts, so the physics engine has the timestep built in and controls the aspect of updating the players? I am writing a simple Bomberman clone. Would using a robust physics engine be overkill? Even if so, I will use this method if I have something a bit more complicated. Thank you!
  10. [quote name='JTippetts' timestamp='1336434151' post='4938217'] Every object stores its Last position and its current position. In [b]addFrameTime[/b], these values are interpolated and the result is used to set the position of the object's scene node. In [b]UpdateLogic[/b], the Last position is set to Current, and a new Current position is generated based on movement if any movement occurred. For purposes of logic, the object's position is considered to be Current; Last is only stored for the purpose of interpolating to smooth out movement. [/quote] Brilliant! Thank you. And yes BeerNuts, I will have a look at the source thank you.
  11. Thank you. I guess what I am confused about is the whole interpolation and the function addFrameTime. What exactly does it do. I understand that the logic updates until it is larger than the logic step and then when rendering the position values are interpolated. Are these values actually modified? Or are they just interpolated for the rendering (i.e. does the rendering actually modify the values or does it just modify them temporarily for the rendering and then they are permanently changed when the next update() function is run). What exactly does addFrameTime do? And do you pass this value to your rendering call? Is it possible that it can interpolate a value past collision and have something interpolated into a wall for instance? Thank you.
  12. Hi. I am developing a simple Bomberman clone using SDL and C++. Collision detection, movement, animation have all been implemented. The problem is that the character often seems to skip across the screen. I have researched this and found this to be temporal anti aliasing due to the frame rendering between updates. I have found two main solutions and wanted input. This engine code should be as smooth as possible and I want to reuse it so I will put in the effort now to understand it. I have found an article on fixed timestep. I really wish I could implement it but I am very confused about how it applies to a non physics application or maybe just to something simpler like moving a character across the screen. This is the article I am referring to: [url="http://gafferongames.com/game-physics/fix-your-timestep/"]http://gafferongames...-your-timestep/[/url] Is this method a little overboard for a non physics intense game? Can anyone elaborate on what it does and how I would apply it to simple position updates on an x/y plane. There is also another article I found which covers quite a few different main game loops: [url="http://www.koonsolo.com/news/dewitters-gameloop/"]http://www.koonsolo....tters-gameloop/[/url] I tried to implement the last option but found that often I got some unexpected warping where it would interpolate that I would be somewhere and then change its mind. It's possible it was a bug on my part (e.g. not factoring it into collision correctly). Does anyone have a solid 2d main game loop they can break down and explain. I mean, I understand how it works, the components relating to handling input, updating logic and rendering, I am just confused sometimes about how the time is applied to those updates. Thank you for your time. Here is my main loop as it stands: [CODE] int main(int argc, char *argv[]) { const int TICKS_PER_SECOND = 60; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 10; double next_game_tick = timer.getTime(); int loops; // Initialize everything if(!init()) { errorLog.writeError("Failed to initialize engine components!"); return 1; } // While the user hasn't quit while(quit == false) { loops = 0; while( timer.getTime() > next_game_tick && loops < MAX_FRAMESKIP) { update(); next_game_tick += SKIP_TICKS; loops++; } } render.cleanup(); return 0; }[/CODE] Chanz
  13. [quote name='dpadam450' timestamp='1334804251' post='4932672'] [quote]I only end up checking four directions every frame but still, I think there has to be a better way (especially considering 500 lines of code just for collision detection!).[/quote] What directions? When moving up and left is when I can cut through the whole map. All you need to do is check 1 block. If holding up, just check the one block above, if holding up and left, check the upper left block, left block and upper block. Worst case is you are in a corner and hitting 3 blocks max. Also, when holding up and left, these checks should be separate for instance if I hit up and left, and there is collision with the block above, I should still move left while holding both of those. I see you have the halfway check and he will kind of curve/maneuver which I dont really like, but if u just did each collision check separate like (if left && no block left), move.x--; then separately (if up && no block up), move.y++; [/quote] Can you elaborate on what would would do instead of the "curve/maneuver". I thought it worked pretty good for allowing players to move through despite the rigid size. What do you not like about it. I can make it much smaller. Right now it is 15 pixels. What if it was half of that instead? Also, it seems you can only move through when going up and left. Thank you for noticing that. Doesn't make me throw out all the code. Any more opinions?
  14. Sorry about that. The walkspeed is very slow. Here it is but a bit quicker so you can really test.
  15. I am trying to get back into SDL and 2d games by writing a simple Bomberman clone. I have gotten map loading, texture loading and a bunch of the logic worked out. Now I am trying to go about and figure out how to get collision detection working and facilitate easy movement throughout the map. Currently, my collision detection code is about 500 lines. It works with a few hiccups but there must be an easier way to do this. Each block is 32x32 and my player (although his head peaks over) is also 32x32. So for that, I implemented really rigid collision detection. It would simply see if it could move in a specific direction, get the distance to the block if there was one and then move until it hit it. Fair enough. Then I added something I call "nudging" where if the player was at a specific part of the block and tried to move, say, left, and was within a specific threshold, it would move him up or down and then left. Made it a lot better. But still I am getting errors. It seems diagonally, the player can still go through the blocks. I could add more checks against that but I figure I am doing this wrong, or just a way that isn't optimal. There is another error where the collision vector (my data is stored in the vector) will crash the program when the player queries a part that is out of range (when the player travels through the walls. I only end up checking four directions every frame but still, I think there has to be a better way (especially considering 500 lines of code just for collision detection!). What kind of collision detection do you recommend for a game like this? I definitely don't need to be checking all of the squares every frame. Thank you! I attached the program so you can see what I mean.