Shayel

Members
  • Content count

    27
  • Joined

  • Last visited

Community Reputation

256 Neutral

About Shayel

  • Rank
    Member
  1. Hello Let me start with a simple explanation of my collision system. Every object in my game is just a sprite with a defined vertexes. For example a triangle block is made of 3 vertexes. The collision between a ball (that is my player) and the triangle is done by calculating shortest distance between every edge of the triangle, and every edge is made of 2 vertexes. I am sure you know what  I mean.   Until now everything was fine, but now I want to rotate some of the objects. And here comes the problem: when rotating the sprite, how to calculate new positions for for the vertexes.       Picture as an example. Red dots are the vertexes for calculating collision. Blue dot represents anchor, around which the sprite rotates (so the sprite rotates around its center). (1) is the object without any rotation. After the rotation i want to move the vertexes so they fit the actual display (2), and not stay as they stood before (3). I would appreciate any help   ##EDIT## I was messing around with a piece of paper and probably found a solution. Every vertex <-> center distance is const. Assuming that I increase angle by 5 degrees i can use basic trigonometry (sinus and cosinus) to calculate new X and Y for every vertex.    Correct me if I am wrong. Also I don't know how calculating sin/cos every frame would consume the processing power. I am afraid it would be pretty devastating for the processor (creating a mobile game). Another idea is to keep x/y offsets for every vertex, for every degree, for every type of object. Like a mini-database. But... duh.. i hope there is a better solution..
  2. Hi I want to learn a bit of how multiplayer works in gamedev. To do so I am making a simple platformer game with a coop feature. I don't really know where to start. I was thinking of a client-server architetcture, where first player creates the game and the second one joins it. The only thing client would do is sending input to the server and drawing. So all of the calculations would be done on the server side. But that seems strange to me.. any tips on how to implement networking in a 2D platformer?
  3. Strange memory allocation bug with new[]

    Thank you for replies, especially Samith. But I have checked it and when I created other project, and then created an array of objects using new, the returned value was the same as the pointer value. Olof Hedman - I also tried to overload the new operator, so it returns malloc(), but nothing changed.    The problem is in the allocation itself, because if I do myAlloc(), and right after it _msize(), I get a heap corruption error.
  4. Hi I have ran into a strange problem.. I have this piece of code: template <class T> void my_vect<T>::myAlloc(size_t dim) { try { dat=new T[dim]; } catch(bad_alloc dat) { err::MyErrorHandler.Error(ALLOC_ERROR); } }   Later "dat" is causing the heap corruption, even if it shouldn't. After many many many hours of figuring out why, I found out that the value of my "dat" pointer isn't the same as the value returned by the new[] operator (found it out by stepping into the new operator and looking what it returns). For example new returns 0x...e18, but "dat" is 0x...e1c. The offset is always 4 bytes long. This causes my program to fail when using for example _msize() function.   Why is it happening?    
  5. Using global variables - really so bad?

    Okay, I get why global variables can be bad, but I still don't know how to replace them. In my example it was easy to set correct sound to be played. Now let's say I don;t want to use the global SoundSystem. I could make SoundSystem member of a Game class. But how do I set the correct sounds now, when the "Player" class inside the State, which is already inside the game class, doesn't have access to the SoundSystem. It was easy to check.. if(playerState==state_attacking) g_SoundSystem->PlaySound("swordfling.wav");   Another idea was to pass the m_SoundSystem(member of the game class), to the State->Logic, and then to the Player.Logic() but that makes no sense to me. Well, at least I have never seen a source code/example with such a solution.   Or maybe I don't need anything like SoundSystem? Maybe simple function playing sounds is enough? However I find SoundSystem much more useful, as it can track which sounds are playing so I don't get the "100000 sounds at a time" effect etc.   Any tips from more advanced coders? ;)
  6. Hi Ill give you an example. g_SoundSystem; class Game { sf::RenderWindow screen; State* CurrentState; public: void Start() { CurrentState->Logic(); } }; class Level1 { Player player; public: void Logic() { if(something) g_SoungSystem->Play("shot.wav"); } } CurrentState=new Level1(); I heard that global variables are bad.. but what is the other way to use things like "Soundsystems" etc. g_SoundSystem has to be global so i can use it from any place in the program. I was also thinking about setting flags in certain points but that would also require global access. In other words: Can you help me in understanding how to replace globals?
  7. Hello I am trying to understand the basics of the pathfinding, but I don't understand the main idea. I understand how the algorithms work, for example A* algorithm. The thing that confuses me is how do I actually set the vertices. Let's say I have a tile-based map in a 2D game. Do I set them manually , for example in my level editor, and store the coordinates of the vertices in the array/list/tree/anything? 
  8. Hi When learning to create games I always wonder if my way of thinking is "correct". Yeah, I know that when it comes to programming, everything that works and is free of bugs etc is correct. But I don't like this kind of approach, because I think it limits my self-development. What's more, games seem too complex for me, to allow myself to have this kind of approach. Here is something I was thinking about: Let's say I want to create Tanks game, with the camera from above. Just a basic 2D game. And I want to create, for example, 5 levels, loaded from file. So here is my idea: I can create an array of integers, and save it to the file. Doesn't matter if it is made with an editor or manually (another conclusion: if creating levels the way I see it is correct, I am able to create a level editor, even with my very poor programing experience, hurray :D). So let's say I have the 80x60 array of integers. Then, when the level is reached in the game, the constructor loads the array, and based on the numbers sets proper textures (10x10 px) in the right order. For example, when it finds "0" in the array[0][0], then the upper left corner will be an empty space, where the tank can move. Same with "1" for obstacle, and "2" for destroyable, for example a box. So basically, my level is just a set of 80*60 textures, positioned on the base of the array.    This is just an example, one of the many things that I find complex and confusing. I have talked with my friend, who has created some simple games. He said that his first level editor was just a huge "if/else" program. And this is what I am trying to avoid, learn the game development standards :)
  9. Code Review - Pong clone..

    Wow.. thats.. quite a lot :) I will definitely keep your advices in mind when creating next project. There were some problems, that I couldn't solve other way than doing things such as if(score.AddPoint(ball.Logic(deltaT.asSeconds(), paddle1, paddle2))) Reset(); I admit that it is not the best way, but at this point I couldn't make up any other, working solution. You can probably see that I am not the best in creating object oriented code :) I'm still learning what to make public/private, how to change the private fields etc.. As for putting C in the class names. Well.. it helps me :) I don't think it confuses other people, and if it does just tell me :) Thanks for advices! :)
  10. Code Review - Pong clone..

    Thanks for your feedback As for the SFML advices: I am new to sfml, I have just moved from SDL.. well.. previous bad and ugly pong was written using SDL. But I find SFML much more friendly. Anyway, thanks for advices. In the classes, I prefer to describe the private fields first. It is the core of a class, when I look at it I can see what it really is :) But as you said, it is a matter of preference :)
  11. Code Review - Pong clone..

    Hello For the past few days I have been working on the Pong clone. I have made it before, but I wasn't satisfied with the quality of the code, so I decided to rewrite it. I guess you all are bored, because of the Pong Clones attacking you from every side, but here it is: https://gist.github.com/Shayelxx/5691085 Well.. I think that it may be too big for such a simple game, but I am just starting to learn :)
  12. Simple, game structuring problem

    I was thinking about creating the exit flag, so when user wants to exit(in the event part), the "exit" flag is set to true. Then on the beginning of the logic part, the flag is checked if(exit) return STATE_EXIT; . .//rest of the logic part . .
  13. Simple, game structuring problem

    Thanks for the replies I will change the ChangeState, so it is called outside the Render, Logic and Event functions. But now there is another question. What if the state could be set in both event section (player X'ed out, set to EXIT_STATE) and in the Logic section (player walked through the door, load next room)?
  14. Hello I have my abstract CGameState class, which has 3 virtual functions: Logic, Events and Render. Then I have my CGame class, that contains the CGameState* object, the screen object and methods that change the state. The main loop is like: CurrentState->Events(); CurrentState->Logic(); CurrentState->Render(); Now, if during the application there is a need to change the state, I am using ChangeState method, which basically deletes the old CGameState* and creates the proper new one. For example: void ChangeState(STATE_MENU) { delete CurrentState; CurrentState=new CMenu; }   And the CMenu inherites from the CGameState, to use its own Logic, Events, and Render methods.    Here goes the problem: When there is a need to change the state, I have no access to the (Cgame game) object, because it contains the CurrentState object.. So I cannot use the ChangeState method :/ How can I do it?
  15. Interpolation

    To be honest, I still don't get it :S But I have done something in my project, and it works, so I wanted to ask you guys for opinion + I have some questions.   I have my main loop: while(CurrentID!=STATE_EXIT) { int start=clock(); CurrentState->events(this); CurrentState->logic(this); ChangeState(); CurrentState->render(this); if((clock()-start)/CLOCKS_PER_SEC < one_frame ) { //calculate how much frame time left sf::Time t1=sf::seconds(one_frame-((clock()/-start)/CLOCKS_PER_SEC)); sf::sleep(t1); } }   framerate is set to 60 FPS, fraps shows 58.. I will work on that later, for now let's say everything is fine. Events part does nothing for now, the logic part calculates the next position based on the velocity. If there is an obstacle or something needs to be changed, the velocity is changed. And now comes the render part:   int render_frames=20; while(render_frames--) { game->screen.draw(background); ball.show(game->screen); game->screen.display(); }   The main loop (especially the logic part) calculated next position by calculating the velocity of the ball. So one game loop moves the ball from Originpoint to Originpoint+velocity. The moving part is rendered in (render_frames) number of frames. In this case the ball moves 20 times, everytime velocity/20 is added to its position. At the end of the render part the ball will be on the right position. Render part finished, main loop starts again etc..   But this has some drawbacks. Let's say I have my velocity set to (10,10). Normally, it would travel the 800x600 window in a little more than 1 second, because it would move 600 pixels in one second. But when using the idea above, the ball just slows down, I would say it is a huge slowdown. So I have to set higher velocity, but then the rendering isn't smooth as it would be with lower velocity.. so I make the (render_frames) higher, but this causes the ball to slow down again. Like a loop :/