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

endless11111

Members
  • Content count

    25
  • Joined

  • Last visited

Community Reputation

151 Neutral

About endless11111

  • Rank
    Member
  1. I think the reason why the player is going halfway into the rectangle before being pushed out is because of when you handle the collision detection. Let's try stepping through the code one at a time, lets say you start to the left of the rectangle and you press and hold the right key.   At the beginning of the code you gave us you do the collision handling. Because you're not intersecting with the rectangle right now, the collision handling section is skipped because there is no collision.   Next you have your keystates. The game detects that you are holding the right key so it moves your player to the right, then it draws the player in this position. Now this is important to note that the player is drawn right after he moved, meaning the collision detection has not happened yet.   Next you go back to the beginning of the loop and here you run the collision handling because, this time, your player is inside the rectangle. After the collision handling is finished the player is no longer in the rectangle.   But once you reach the input handling you move the player back inside the rectangle and then when you draw the player, he is drawn inside the rectangle because you won't handle collision until the next frame.   If you let go of the right key, then the collision handling will occur like always, but this time the player won't move because you are no longer handling any input. The player is drawn outside the rectangle because you haven't moved him.   So in short the player is drawn right after he moves, before the collision handling can occur so he is drawn inside the rectangle and his position isn't corrected until the next frame. But even if his position is corrected the next frame, if you are still holding down the right key he moves into the rectangle again so in the end you're still in the rectangle.   if you restructure your code so the collision handling occurs after the player actually moves then your problem with the player going inside the rectangle should be fixed.       As for the problem with things moving too fast you'll have to find a way to deal with it yourself. For the most part you can just limit the speed of everything so they can't go through objects, but if thats not possible there are other methods. Since you're using axis-aligned rectangles (non rotated rectangles) you could check out http://www.gamedev.net/page/resources/_/technical/game-programming/swept-aabb-collision-detection-and-response-r3084 to learn about swept AABB collision detection. This is basically where you predict where the player traveled during the frame and check if the course he traveled through intersects with any objects and handle collision accordingly. I think that limiting the speed of the objects are good enough if you're just starting out with game development, but if you want you can always implement more advance techniques if your game needs it.
  2. When you're checking which side of the player is intersecting with the rectangle the first part will always evaluate to true because if the player is at the right side of the rectangle then  his position will always be greater than the rectangle's position. So when you check for collision it always executes the first half of your if statement. if (PlayerRectangle.Intersects(BoxRectangle)) { if (Position.X + 32 >= BoxRectangle.X ) //this part will always be true because if the player is at the right side of the rectangle //then his position is already greater than the box's position so this is the only part that executes Position.X = BoxRectangle.X - 32; else if (Position.X <= BoxRectangle.X + BoxRectangle.Width) //this part won't execute because the first statement is always true if there is an intersection. Position.X = BoxRectangle.X + BoxRectangle.Width; }   Alternatively if you switch the two statements and run the second test first then the collision will only work from the right side of the box. If there is ever a collision between the box and the player then both of those statements will always be true, whichever one is checked first is the one that's executed. You checked the collision from the left side of the box first so only the left side is executed. when you try to collide from the right side of the rectangle you get pushed to the left.     Instead of doing the above, an easy way to decide where to move the player is to calculate the smallest distance required to move the player in order for the two rectangles to stop intersecting.   I don't know XNA so i don't know if the functions abs and min are available to you. //calculate the smallest distance required to move the player in order to escape collision //good to have named constants so you know what the numbers refer to const int playerWidth = 32; //distance from the right edge of the player to the left edge of the rectangle float rightEdgeDistance = BoxRectangle.x - (Position.x + playerWidth); //distance from the left edge of the player to the right edge of the rectangle float leftEdgeDistance = BoxRectangle.x + BoxRectangle.Width - Position.x; //figure out the smaller distance, use the absolute values of both calculations because //the distance might be negative due to the calculations float smallerDistance = min(abs(rightEdgeDistance), abs(leftEdgeDistance)); //move the player towards the edge of the rectangle that requires the smallest distance to move if(smallerDistance == abs(leftEdgeDistance)) { //distance from right edge of rectangle to the left edge of player is the smallest Position.X = BoxRectangle.X + BoxRectangle.Width; } else if(smallerDistance == abs(rightEdgeDistance)) { //distance from left edge of rectangle to right edge of player is smallest Position.X = BoxRectangle.X - playerWidth; } This usually works if your character is moving in small increments that way when you collide with something only a small portion of the player is actually intersecting with the other object. if your character moves too fast then he risks teleporting to the other side of the rectangle. 
  3. I handle collisions pretty easily, first i calculate the distance it traveled in the x axis only, then i check if it collides with anything not passable, like a block. if i collides with anything, i reduce the distance it traveled in this frame and move it back to its previous position, and then i do the same for the y axis.   so for psuedocode it would look like this, actually its closer to c++ code than psudocode, but it's pretty self explanatory:    //so add the distance traveled this frame, distance = velocity * time //save the distance traveled so i can subtract it later and move back to previous position in case of collision float distance_Traveled = x_Velocity * delta_Time;   x_Position += distance_Traveled;   if(check for collision with any entity) {      x_Position -= distance_Traveled; }   then i just repeat that for the y axis, and the object will move to the last position it existed on before it had a collision. note there are some problems, for example if there is a collision before and after it moves, like the bounding box is located inside a block before it moves, and inside a block after it moves, it will move back to its previous position even if its still colliding with something. another problem is if it travels too far within a single frame, and crosses a huge gap at once and collides with something, it will move back to its original position even if the distance is enormous.   lets say the square bracket is the player, and the 0 is a wall []                    0 if its that far, and in one frame the square bracket moves inside the 0                       [(]) then it wil move all the way back to its last position []                      0 and not take into account the entire gap in between.   another problem has more to do with collision detection than handling, if an entity moves from one side of a block to another in a single frame without touching it, it wont count as a collision and he will pass through the block.   ex:   frame 1: []          0   frame 2:              0     []   no collision, so it will keep moving just fine.   anyways this simple way to handle collision works fine until it starts lagging or objects move at high velocities. also if it looks like the player is floating over a block then just make the bounding boxes of the player / block smaller than the image, that way it looks a little bit better. and one last thing, if you move one axis at a time, handling slopes will be easy because you just handle slope on the x axis and you can easily use something like y=mx + b to determien the position.     here is a final guide that you can look over to help you understand how to implement platformers, i really suggest you read it, its great.    http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/ its on gamedev.net too but my computer lags too badly to search for it so i just used the first link i found. Good luck
  4. Alright thanks for the help guys.
  5. Thank you for the reply, but im still confused about how i would implement the search algorithm. First of all how would i make the search algorithm take into account gravity and jumping. also how would i make the algorithm go from one solid node to another and take into account the gaps in between and the distances for jumping. lastly would i implement a search algorithm in the AI itself or just a generic search algorithm that anything can use. thanks for the help so far and sorry i couldnt grasp how i would implement it.
  6. I am currently working on a 2D platformer game and i was hoping to have AI that could follow the player instead of mindlessly moving side to side in the map. I looked into astar pathfinding and i managed to make a simple pathfinding system for an overhead game. The thing i am having trouble with is getting the AI to follow the path in a 2D platformer. I can make simple AI follow paths on overhead games, but i have no idea how to do this in 2D. how do i make the pathfinding itself calculate gravity, jumpheight, pitfalls and all of the other 2D obstacles? also how would i make the AI even follow a path like this? i would like to make an AI like the one in this video http://www.youtube.com/watch?v=Bc7tu-KwfoU . if it makes a difference i use c++.
  7. [quote name='DaShwimp' timestamp='1344663544' post='4968341'] Wow Im sorry xD I cant believe I didnt think of it before. Thank you! I downloaded your media and source for that tutorial and right there was the .ttf to put in xP Thanks again. Hopefully I wont need to post super often xP [/quote] no problem, i also had the same problem when i was first learning SDL(although im still learning).
  8. [quote name='DaShwimp' timestamp='1344649976' post='4968284'] Hello again I now have another problem xP with my C++ and SDL. Im now learning to use the ttf library and Ive linked all the libraries together, and theirs no issues with the compiler trying to find the functions or anything, but when I try to load a font, the ttf_openfont command cant find "lazy.ttf" and returns null, so I end up with the message that the program returned 4, meaning the font failed to load. Any help as to why the program cant find the font? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Thanks! [/quote] do you have the font file in the save directory as the project file? by font file i mean the actual lazy.ttf file, not the dll's. if the error is due to the program being unable to load the font file it means the compiler cant find the lazy.ttf file. just make sure the lazy.ttf file is in the same directory as your compiler's project file if you are running the program through the compiler. if you run it using the .exe file put the lazy.ttf file in the same directory as the .exe.
  9. how do games such as RPG games show the characters wearing different equipment? do they have a separate image for a character wearing all the different combinations of equipment or is the equipment just an overlay that's stuck on to the character and moves along with him?
  10. [quote name='Servant of the Lord' timestamp='1341779569' post='4957014'] Well, I haven't used std::ifstream::ignore() before, but it seems from [url="http://www.cplusplus.com/reference/iostream/istream/ignore/"]the documentation[/url] that you might be using it wrong. The way you are currently using it, it'll ignore only one single character. The problem, however, is that on Windows each line ends with two characters (The 'carriage return' character ([color=#FF0000][b]\r[/b][/color]) and then the 'newline' character ([color=#FF0000][b]\n[/b][/color])). (You can paste code between [ code] and [ /code] tags) Try this: [code]#include <fstream> //For std::ofstream and std::ifstream, to read and write to files. #include <sstream> //For std::stringstream, used by our StringToInt() function. //Converts a std::string to an int. int StringToInt(std::string str) { std::stringstream stream(str); int value; stream >> value; return value; } BlockBox Load(std::string filepath) { std::ifstream file(filepath.c_str()); //Check to see if the file loaded correctly. This is important! You shouldn't ignore checking for errors. if(!file) { //If the file didn't load correctly, report an error and return. std::cout << "Error! The file, \"" << filepath << "\" failed to load." << std::endl; return BlockBox(); //Return an empty BlockBox. } std::string myBuffer; BlockBox blockBox; //Keep looping until we hit the end of the file. while(file.eof() == false) { //Read a line of text into our buffer. Stop at the first space we find. getline(file, myBuffer, ' '); //Convert the text into a number. int x = StringToInt(myBuffer); //Read the next line of text into our buffer. Stop at the next space we find. getline(file, myBuffer, ' '); //Convert the text into a number. int y = StringToInt(myBuffer); //Read the last line of text into our buffer. Stop at the first end-of-line we find. getline(file, myBuffer, '\n'); //Convert the text into a number. int typeOfBlock = StringToInt(myBuffer); //Create the new block. Block block(x, y, typeOfBlock); blockBox.push_back(block); } //Return the level. return blockBox; }[/code] [/quote] Thanks for all the help so far, but i have two questions. Why do you use stringstream instead of atoi? also when you use getline() to read the y location, does it start reading from the space between the x and y location or does it start after the space?
  11. [quote name='SimonForsman' timestamp='1341523269' post='4956108'] If you're just starting out a plain text format will probably be the easiest to handle, just decide on a way to represent the level as text and push it to a file using ofstream. If you want to move to a binary representation instead just change things so that you represent your level as a series of numbers instead. [/quote] i tried to do it the way you two described it. for now i use a class called blocks for each platform, and to save a level i save each block's location onto a txt file. i cant seem to upload my code for some reason, it always gets cut off. void save() { ofstream file("level.txt"); //write the location of each block onto a text file for(vector<blocks>::iterator size = blockbox.begin(); size != blockbox.end(); size++) { //while saving add the with of the blocks to make up for the constructor's width and height subtraction file << size->box.x + 8 << " " << size->box.y + 8<< "\n"; } //close the file file.close(); } void load() { ifstream file("level.txt"); string s; while(file >> s) { //convert to int and create the x location int x = atoi(s.c_str()); //move on to y location then move to the next line file.ignore(); file >> s; //convert to int and create the y location int y = atoi(s.c_str()); //move on to next line file.ignore(); //create the block blocks block1(x,y); blockbox.push_back(block1); } //close the file file.close(); }
  12. I am fairly new at programming games, and so far i have programmed basic games like pong. right now i was working on a small platformer game. right now i use a basic level creator that i made to create a level on the fly, and it's really annoying to recreate a level every time i compile my game. could anyone please teach me how to save my levels and load them so i dont have to recreate a level over and over again?
  13. you should not implement it into your engine until you have a firm grasp of it in case you encounter numerous bugs which you wont know how to fix because you haven`t experienced them before. although i am not experienced in multithreading, i have read numerous times to split the threads as logic, rendering, file input or output, events, and audio. basically to start just create a simple program to test out multithreading and create just 2 threads splitting logic and rendering to get a basis of what multithreading can do, then work on making a harder project like a basic game, then try and implement it into your engine. or you could just try to split logic, rendering, input, and opening files into different threads in your engine right away, but that`s not a good idea until you have the hang of it.
  14. You should go to Lazy foos site, he has tutorials on how to set up and start sdl on code blocks and set up extensions. Here is how to set up sdl -- [url="http://lazyfoo.net/SDL_tutorials/lesson01/windows/index.php"]http://lazyfoo.net/SDL_tutorials/lesson01/windows/index.php[/url] and extensions, this is for SDL_image but it works for all the other extensions. -- [url="http://lazyfoo.net/SDL_tutorials/lesson03/windows/index.php"]http://lazyfoo.net/SDL_tutorials/lesson03/windows/index.php[/url]
  15. the image might not be loading up because you don't have the image file in the same folder as the project file. if you are compiling a program, all the files accosiated with the program must be in the same folder as the .cpp files, and if you are running the .exe file, all the files accosiated with the program must be in the same folder as the .exe file. and i am not really familiar with text intput and output in sdl using cin and cout, but as far as i know, you can't use cin or cout like you would with a console application, you can't just output text or input text directly using cin and cout.