Jump to content
  • Advertisement

dEgle95

Member
  • Content Count

    13
  • Joined

  • Last visited

Everything posted by dEgle95

  1. Hello guys. I was wondering is there any tutorial describing how to make network support in games? Like what should server send and receive and in what order? Clients? I guess best way is to make net_events like in SDL: server should translate incoming packets into events, then handle them, generate events for clients and send them back. Server and clients should have queue of events (like in SDL)...but i'm not sure if it's the best solution.
  2. I meant if it is a right thing to implement:) For example if i send datagram with map data of file parts i will definitely number these packets, so if there is a non stable connection client can ask to resend right packet. In case of lost packets with events...players might be teleporting;-)
  3. I guess it's best idea to reduce traffic when sending events from server to each clients and vice versa:) Will it work if i send events from client to server each frame (if there are any events) and server will send events to clients each frame, so there will be no exact rate? That way I will have to have ping-pong requests to measure latency, disconnected palyers, etc.
  4. dEgle95

    2D Tile Based Lighting

    You can also make multiple "light" blocks inside one tile. Light block can have 3 bytes for color and a byte for light level. To make it faster recalculate only if there are moving lights (like torch in hand). If you use GPU to render fancy lights then you don't need much light blocks. Only for spawning mobs for example... Be creative and you can make your own lighting engine, even more fancy than terraria has!
  5. Actually I'm using UDP, so event can fit in one packet. Thanks anyway:)
  6. dEgle95

    Collision Detection HELP!

    Hello! Here is my function that i use in my projects. It's just a little more compact and 100% working Hope it will help you. int check_collision(SDL_Rect *a , SDL_Rect *b) { if(b->x + b->w < a->x) return 0; //just checking if their if(b->x > a->x + a->w) return 0; //bounding boxes even touch if(b->y + b->h < a->y) return 0; if(b->y > a->y + a->h) return 0; return 1; //bounding boxes intersect }
  7. Hello guys. I'm developing a small game and I've bumped into problem with SDL surfaces. I've written function for creating surfaces: [source lang="cpp"]SDL_Surface *create_surface(int width, int height) { /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order, as expected by OpenGL for textures */ SDL_Surface *surface; Uint32 rmask, gmask, bmask, amask; /* SDL interprets each pixel as a 32-bit number, so our masks must depend on the endianness (byte order) of the machine */ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; } else { rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; } surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); return surface; }[/source] But when i try to do something with it nothing happens: [source lang="cpp"]Uint32 p_color; p_color = SDL_MapRGB(screen->format,255,255,255); SDL_Surface *srf = NULL; srf = create_surface(16,16); SDL_Rect temp; temp.x = 0; temp.y = 0; temp.w = 16; temp.h = 16; SDL_FillRect(srf,&temp,p_color); apply_surface(0,0, srf, screen, NULL); //simple function for blitting one surface to another. [/source] I definitely know that srf and screen are 32bits and function for creating surfaces was copied from SDL docs. apply_surface function works perfectly for any loaded image. Please, help me out with this simple problem
  8. Oops....apparently generating format is not working, but if you take it from screen surface it'll do:) Corrected function for creating surfaces, in case someone needs it: [source lang="cpp"]SDL_Surface *create_surface(int width, int height, SDL_Surface *screen) { /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order, as expected by OpenGL for textures */ SDL_Surface *surface; surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); return surface; }[/source]
  9. dEgle95

    How to Structure a Tile Based Game?

    If your game would be side scrolling then sometimes there would be empty tiles, like air... To save memory and time of calculating you can use resizable array of pointers in current chunk which contains only solid tiles. To delete any tile from this array, for example remove(i); Copy last pointer in your array to i and then resize array. Pretty simple and working
  10. Cortex Command build 27 is finally out!!!! http://t.co/PYHtKT43
  11. Hello guys! I'm having such a problem: i can't figure easiest way to find distance between point and block (as shown on picture) Everything that i tried is not properly working Could you help me please and tell way to find that distance.
  12. dEgle95

    Distance to ray intersection

    Sorry guys for my mistake in he title But still thanks for your concern. I will use your algorithms in other project
  13. dEgle95

    Distance to ray intersection

    Well...it's part of ray class, so my ray has angle, maximum length and point of start. Now how it works: To find distance to each side we make 2 functions: y = kx — function of ray. x = c or y = c — function of side, because they are not rotating. Then we need to find k — it's just tan(angle). Then calculate point where 2 functions are crossing and check if this point lies on side of current block. pretty simple
  14. dEgle95

    Distance to ray intersection

    Thank you guys. I did find another way, it's quite light too: On each line, that presents side of block we find collision point and check if it's really on side of our block: int lx,ly; //temporary point float t_distance[4]; //FIND POINT ON TOP SIDE ly = block->y; lx = (block->y - y) / tan(angle) + x; if( lx >= block->x && lx <= block->x + block->w && ly >= block->y && ly <= block->y + block->h) //find distance to it t_distance[0] = sqrt((float) (x - lx)*(x - lx) + (y - ly)*(y - ly)); //FIND POINT BOTTOM SIDE ly = block->y + block->h; lx = (block->y + block->h - y) /tan(angle) + x; if( lx >= block->x && lx <= block->x + block->w && ly >= block->y && ly <= block->y + block->h) //find distance to it t_distance[1] = sqrt((float) (x - lx)*(x - lx) + (y - ly)*(y - ly)); //FIND POINT ON LEFT SIDE lx = block->x; ly = tan(angle) * (block->x - x) + y; //check if temp point is onside of block if( lx >= block->x && lx <= block->x + block->w && ly >= block->y && ly <= block->y + block->h) //find distance to it t_distance[2] = sqrt((float) (x - lx)*(x - lx) + (y - ly)*(y - ly)); //FIND POINT ON RIGHT SIDE lx = block->x + block->w; ly = tan(angle) * (block->x + block->w - x) + y; if( lx >= block->x && lx <= block->x + block->w && ly >= block->y && ly <= block->y + block->h) //find distance to it t_distance[3] = sqrt((float) (x - lx)*(x - lx) + (y - ly)*(y - ly)); Then just find minimum in t_distance and there u have it! Ohh...and by the way my blocks aren't rotating and are just represented as x,y,width and height
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!