foxcode

Members
  • Content count

    32
  • Joined

  • Last visited

Community Reputation

299 Neutral

About foxcode

  • Rank
    Member
  1. Thanks everyone, these are excellent responses, I have some reading to do
  2. Hi everyone.   I have been thinking about old 2D racing games and am struggling to visualize how they might be implemented.   Just to be clear on what I'm talking about, here is my favorite example of such a game (or see picture below if you do not trust links :p), might want to turn your speakers down, though nostalgia makes me resist.     I know that you could simply use a 3D engine to replicate this effect, but I want to know how these type of games were made originally.  Are sprites simply stretched to make them appear closer when they approach the bottom of the screen? How do corners works, I am sure they are not all manually drawn, I suspect there is some kind of track segment sprite, which is drawn multiple times and offset in the x axis for corners.   Does anyone have any ideas or articles about how this specific game type was implemented? Google is coming up blank for me  
  3. I would say a memory pool will definitely solve your allocation problem. Creating potentially hundreds of objects per frame is never a good idea, but a memory pool should make it manageable.   This guy has a reasonable explanation http://www.codeproject.com/Articles/27487/Why-to-use-memory-pool-and-how-to-implement-it     As for drawing your objects in an efficient way, that depends on the engine you're using, and is a big topic.   Assuming a modern 3D engine you could... * Just call draw for every bullet, each of which is represented by a polygon - Very crude and slow due to the large number of draw calls, but might give you a place to start from and give you an idea of what kind of performance you can expect   * Each frame get the position and direction of every bullet, pass the data to a shader - I have not yet tried this approach myself, it does mean that you can draw all your bullets with a single call, however depending on your shaders complexity you could be worse off. Ask someone who knows more about it than me, I have been living in html5 land for too long :p   Good luck
  4. Hi rmxhaha   Phaser is probably a safe bet, I have not used it myself but it is very popular and some of the demos I have seen look rather impressive.   Now for some bias :p. I would recommend having a look at WADE. I work for the company that made WADE and having never even done javascript before I started here, found it very easy to use.   Using Node.js for the server code is awesome, I guess you would also need mongodb and socketio, there are a tonne of guides for both out there.   If the engine you end up using supports webgl, you might want to look into using shaders to create the effects you desire, but you have to be careful as switching between shaders too much really hurts performance.   Hope it helps
  5. Game engine basics

    Hi JKAVS   Game loops are actually a pretty complex topic, there are a few ways to do what you want, though my knowledge on this topic is a little limited so hopefully others can give you more detailed answers.   1. You can record the current time in ms just before you update the state. Next time you are about to update the state, you take the time again and find the difference. So if we have an object that moves at 100pixels per second, and our last frame took 25ms to update and render, we know that object needs to move at 2.5 pixels in the next update.   timeTaken/1000 * velocity milliseconds/1000 * pixels per second   25/1000*velocity   2. A cheap option that I do not encourage but can be useful for prototyping things, is to use a constant rate. Say you want your game to run at 40 fps, that is 25ms per frame. If you make the assumption that your hardware will always be faster than that, you can just do sleep(desired frame time - actual frame time) Again I do not recommend this, but for personal projects that only you will use it is okay   I realise I haven't explained this well, please reply if you need clarification. Was a bit rushed in this post as I'm at work supposed to be playing with javascript, the horror..
  6. Match-3 Program Question

    This thread brings back bad memories from 2 months ago. All I can say is don't do it like this var createMatch = function(axis, square, match) { var square2 = !columnsLocked[square.col+axis.x] && board[square.col+axis.x] && board[square.col+axis.x][square.row+axis.y]; square && square2 && square.type == square2.type && !square2.moving && match.push(square2) && createMatch(axis, square2, match); }; var horizontalMatch = []; var verticalMatch = []; createMatch({x:1, y:0}, square, horizontalMatch); createMatch({x:-1, y:0}, square, horizontalMatch); createMatch({x:0, y:1}, square, verticalMatch); createMatch({x:0, y:-1}, square, verticalMatch); horizontalMatch.push(square); verticalMatch.push(square);
  7. Hi, I plan to just haven't got around to it yet. I also need to add the ball changing velocity when it hits a paddle, writing this felt so wrong.
  8. Hi everyone, me and my friend once again had a competition involving the classic Pong. Instead of a severe time restriction, we had to use the fewest lines of code possible with a max line length 80 characters.   This is possibly the biggest little mess I have ever coded, enjoy the GOTO   #include <SFML/Graphics.hpp> #include <windows.h> int scoreReg[4] = {0,0,0,0}; //score 1, score 2, void main() { sf::RenderWindow window(sf::VideoMode(700, 700), "Small Pong Program"); sf::Font font; //Set font font.loadFromFile("arial.ttf"); sf::Text text; //Set text text.setFont(font); text.setColor(sf::Color::Green); text.setCharacterSize(24); text.setPosition(10,10); sf::CircleShape ballShape(5.0f,12); //Ball shape sf::RectangleShape paddleShape; //Paddle shape sf::Vector2f size(100,15); //BEGIN GOTO LABEL BELOW //Top paddle, bottom paddle, ball, ball vel, reg a, reg b begin: float positions[8] = {310,50,310,635,345,342.5,0.5,0.5}; if(scoreReg[0] == 5){text.setString("Top player wins!"); //Top Player wins goto end;} if(scoreReg[1] == 5){text.setString("Bottom player wins!"); //Bottom wins goto end;} paddleShape.setSize(size); ballShape.setPosition(positions[4], positions[5]); ballShape.setFillColor(sf::Color::Red); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) //Event loop for window close if (event.type == sf::Event::Closed) window.close(); //Top player controls if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) positions[0] -= 1; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))positions[0] += 1; //Bottom player controls if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))positions[2] -= 1; if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))positions[2] += 1; if(positions[4] <=0 || positions[4] >=695) //Ball collision with sides positions[6] = positions[6]*-1; //Flip ball x vel if(positions[5] < 5){ //Yes kill me goto scoreReg[1] += 1; goto begin;} //New ball and add 1 point to bottom player else if (positions[5] > 695){ //Yes kill me goto scoreReg[0] += 1; goto begin;} //New ball and add 1 point to top player positions[4] += positions[6]; //Update ball pos x positions[5] += positions[7]; //Update ball pos y ballShape.setPosition(positions[4], positions[5]); //Set ball pos for(int i=0; i<3; i+=2){ //Brilliant idea offset using for loop i if(positions[4]+5 < positions[i]) continue; //x left else if (positions[4] >positions[i] + size.x) continue; //x right if(positions[5]+5 < positions[i+1]) continue; //x left else if (positions[5] >positions[i+1] + size.y) continue; //x right positions[7] = positions[7]*-1;}//Collision occured reverse ball std::string score = std::to_string(scoreReg[0]) + " : " + std::to_string(scoreReg[1]); text.setString(score); paddleShape.setPosition(positions[0], positions[1]); window.draw(paddleShape); //Draw top paddle paddleShape.setPosition(positions[2], positions[3]); window.draw(paddleShape); //Draw bottom paddle window.draw(ballShape); window.draw(text); window.display(); window.clear(); // Clear and then draw everything Sleep(2);} end:; //GOTO END LABEL window.draw(text); window.display(); Sleep(5000);}
  9. Tic Tac Toe need some help

    One other thing you can do, though disliked by many coders is yoda conditions.   This is where instead of i==-1 you write -1==i If you forget an equals, the compiler will show an error because you cannot assign a value to a constant
  10. Tic Tac Toe need some help

    Hello, while I am not sure I fully understand the way you have done this, I have spotted something that looks suspect. GameBoard(); i = checkwin(); } while (i=-1);   the condition in the do while loop, you are assigning i to -1, not checking for equality, are you sure this is not what you want }while (i==-1);     EDIT:   I just compiled this, I was correct, change your while condition to what I have and it will work, though now you have another bug, the incorrect player is credited with the win, happy debugging and don't worry, everyone on this site has made the double equals error, probably more than once, you are doing great!
  11. Every time I look at things like this I feel like I should do some programming, am years away from this...
  12. Sprite Class not working

    Collision can be a pretty complex topic.   There are 2 main parts, collision detection and collision handling.   I recently answered a post that asked a similar question http://www.gamedev.net/topic/655552-searching-for-a-good-tutorial-sfml/#entry5147080 This is fine if all you need to do is compare rectangles that are aligned to x and y. If your rectangles can be rotated however, you need a way to map both rectangles onto an axis to compare them, I believe you can do this using something called the separating axis theorem http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169   One of the easiest types of collision is circular collision. All you need to know here is the position and radius of each circle. You can calculate the distance between them by taking one position from the other and finding the magnitude of the resulting vector. If that distance is greater than the sum of each radius, then collision is impossible.   From this you should be able to figure out what system will work for you, but if you provide more details on the type of game, I might be able to give a better answer.   Good luck
  13. Searching for a good tutorial [SFML]

    The sfml main website has pretty good documentation and even example code you can copy and compile to see how it works. http://www.sfml-dev.org/tutorials/2.1/   I will address 2D collision briefly but it is covered pretty well on gamedev along with everything else you could want to know about making a 2D game   The type of 2D collision you need depends on the style of your platformer, one of the easiest is a tile based world, like the original Mario.   To check collision between 2 tiles or rectangles for example, a rectangle that is the ground and another that is the player, you can do something like this. This is code I have wrote just now as a guide, it only handles collision detection, it does not do anything based on that aka collision handling.  struct Rect { float x; //Position, top left corner x pos float y; //Position, top left corner y pos float w; //Width of rectangle float h; //Height of rectangle }; static bool CheckCollision(Rect _one, Rect _two) { //Check if rectangles overlap on x axis if(_one.x + _one.w < _two.x || //Check if rect one is to the left _one.x > _two.x + _two.w //Check if rect one is to the right { return false; //No overlap on this axis, collision not possible } //Check if rectangles overlap on y axis if(_one.y + _one.h < _two.y || //Check if rect one is above _one.y > _two.y + _two.h //Check if rect one is below { return false; //No overlap on this axis, collision not possible } return true; //Both axis have overlap, collision must have occurred } Hope this helps, gl
  14. I need help with matrices

    Not meaning to hijack the thread, but I suspect using matrices would help me too.   I have a camera class, it has this simple function to apply it. //Some weird shit going on here //Old comment but kept for lols void Camera::ApplyICam() { glRotatef(-m_rotation.m_xValue*180/PI, 1.0, 0.0, 0.0); glRotatef(-m_rotation.m_yValue*180/PI, 0.0, 1.0, 0.0); glRotatef(-m_rotation.m_zValue*180/PI, 0.0, 0.0, 1.0); glTranslatef(-m_position.m_xValue, -m_position.m_yValue, -m_position.m_zValue); }     My object class also stores position and rotation as two 3 dimensional vectors. Using this system I can move my camera and view my objects just fine, the problem comes when I want to rotate the object.   Doing a simple initial rotation is easy, I simply set my m_rotate in object, my question is how to rotate my object after this initial rotation. Say we have an aircraft and I want the plane to bank left aka roll anticlockwise along it's central axis by say 15 degrees. I am unsure how to calculate this rotation given that the plane is no longer aligned along one of our axis, it has its own arbitrary axis. Simply put I cannot figure out how I need to alter my initial rotation.   Here is part of my code showing the order of transformations glLoadIdentity(); cam->ApplyICam(); obj->AddRotation(0.0, 0.025, 0.0); obj->ApplyTransformations(); obj->GetMesh()->DrawMesh(); cam->ApplyICam(); This code correctly draws my object in position, spinning around the y axis by 0.025 per frame. What I want to know is how to make my object bank as described above, no matter how it happens to be rotated at the time.   I am sorry for the poor description, I have always had a hard time visualizing these rotations 
  15. GLSL

    For god sake, why didn't I think of that! Thank you so much, I feel really stupid at times.