Slider_SLO

Member
  • Content count

    13
  • Joined

  • Last visited

Community Reputation

136 Neutral

About Slider_SLO

  • Rank
    Member
  1. SDL.net

    ups that was a msitake i did when i was trying out something so just ignore those SDLNet_TCP_Close(client); functions, my original code is without em...
  2. SDL.net

    This is my server app, it starts up SDL makes window etc. and then waits for the incoming data....     #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <SDL/SDL.h> #include <SDL/SDL_net.h> #include <cstring> //SERVER-------------- int main(int argc,char** argv) {         freopen("CON","w",stdout);         int running = 1;         char buffer[512];         SDL_Init(SDL_INIT_EVERYTHING);         SDLNet_Init();         SDL_WM_SetCaption("Server", NULL);         SDL_Surface *screen, *background;         screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);         background = SDL_DisplayFormat(SDL_LoadBMP("background.bmp"));                  IPaddress ip;         SDLNet_ResolveHost(&ip,NULL,1234);         TCPsocket server=SDLNet_TCP_Open(&ip);         TCPsocket client;         SDL_BlitSurface(background, NULL, screen, NULL);         SDL_Flip(screen);                          while(running)         {                 SDL_Event event;                 while(SDL_PollEvent(&event)) {                        switch(event.type) {                                 case SDL_QUIT:                                         running = 2;                                         break;                        }                 }              client=SDLNet_TCP_Accept(server);                 if(client)                 {                         if (SDLNet_TCP_Recv(client, buffer, 512) > 0)                                     {                                        printf("From Client: %s\n", buffer);                                        SDLNet_TCP_Close(client);                                         }                                                                          //SDLNet_TCP_Send(client,text,strlen(text)+1);                         //SDLNet_TCP_Close(client);                        //break;                 }              if (running==2)              {              SDLNet_Quit();              SDL_Quit();                  }             }         SDL_FreeSurface(background);         SDL_FreeSurface(screen);                 SDLNet_TCP_Close(server);         SDLNet_Quit();         SDL_Quit(); }         And this client starts window waits for the input to send string to server...       #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <SDL/SDL.h> #include <SDL/SDL_net.h> #include <cstring> //---------CLIENT---- int main(int argc,char** argv) {         SDL_Init(SDL_INIT_EVERYTHING);         SDLNet_Init();         //init graficne stvari         SDL_Surface *screen, *background;         screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);         background = SDL_DisplayFormat(SDL_LoadBMP("background.bmp"));                  bool b[4] = {0,0,0,0};         bool running = true;         char buffer[512];         char* mesg="aaa aa a aa";         char* mesg2="bbbb bb b";         char* mesg3="cc ccccc c";         char* mesg4="d d dddd d";                  freopen("CON","w",stdout);         IPaddress ip;         SDLNet_ResolveHost(&ip,"127.0.0.1",1234);                  SDL_BlitSurface(background, NULL, screen, NULL);         SDL_Flip(screen);                  TCPsocket client=SDLNet_TCP_Open(&ip);         while(running)         {             SDL_Event event;                     while(SDL_PollEvent(&event)) {                             switch(event.type) {                                 case SDL_QUIT:                                     running = false;                                     SDL_Quit();                                     break;                                 case SDL_KEYDOWN:                                     switch(event.key.keysym.sym)                                     {                                         case SDLK_w:                                                 b[0] = 1;                                                 break;                                         case SDLK_a:                                                 b[1] = 1;                                                 break;                                         case SDLK_s:                                                 b[2] = 1;                                                 break;                                         case SDLK_d:                                                 b[3] = 1;                                                 break;                                     }                                     break;                                 case SDL_KEYUP:                                      switch(event.key.keysym.sym)                                      {                                                 case SDLK_w:                                                         b[0] = 0;                                                         break;                                                         case SDLK_a:                                                         b[1] = 0;                                                         break;                                                 case SDLK_s:                                                         b[2] = 0;                                                         break;                                                 case SDLK_d:                                                         b[3] = 0;                                                         break;                                      }                                                                                                                                }             if(b[0]){             SDLNet_TCP_Send(client,mesg,strlen(mesg)+1);             SDLNet_TCP_Close(client);                 }             if(b[1]){             SDLNet_TCP_Send(client,mesg2,strlen(mesg2)+1);             SDLNet_TCP_Close(client);                 }             if(b[2]){             SDLNet_TCP_Send(client,mesg3,strlen(mesg3)+1);             SDLNet_TCP_Close(client);                 }             if(b[3]){             SDLNet_TCP_Send(client,mesg4,strlen(mesg4)+1);             SDLNet_TCP_Close(client);                 }                                      }                              }     //    char text[10000];                       //while(SDLNet_TCP_Recv(client,text,10000))         //        std::cout << text;                                    SDL_FreeSurface(screen);         SDL_FreeSurface(background);                  SDLNet_TCP_Close(client);         SDLNet_Quit();         SDL_Quit(); }  
  3. SDL.net

    For the moment im not using it since I only created one way communication from client to server. Want to get this done at first before i move on to 2way communicating betwen multiple clients...
  4. SDL.net

    Im using SDLNet_TCP_Recv function in a loop to wait for the incoming string and it prints me out that string that comes in and im using function SDLNet_TCP_Send on the client side to send that string from client to server. After i send my first string from client to server app everything is fine for the first string but for only one string for any other strings I want to send to the server I have to restart my client app.
  5. SDL.net

    I made a mistake im not sending packages only strings and im using TCP, I know the basics of TCP/UDP and how it works... Well my client app waits for the input and to send to the server and i can send the first string without any problems but after that I cant send anything else. It looks like that socket I created locks down after the first sting or something like that.
  6. SDL.net

    Hey I just wanna ask if anyone knows for some SDL.net tutorials for basic/beginners++, i allready went through top tutorials that I could find but still I have some problems... Im having a problem that my client sends only one package to the server and cant send any other date and doesnt want to send same package aswell, its like the client locks down after the first package... Any ideas?
  7. Camera/screen moving

    If I understand you then if I would want to move by one pix like lets say 201,301 then i would need to move all the others objects by one pix and leave my character on 200, 300? If so then isnt that really inefficient to move the world and all its objects instead of the character?
  8. Camera/screen moving

    But why does images that I blit on the surface lets say an image of another object/player etc... they move with my camera/screen the same way as my player,  like they are locked on the surface on those coordinates that i blit them? It would be fun if I would be making the HUD, but I dont want that for my objects should I decrement them in the opposite direction when my player moves? And yes it is for 2d game, thanks for all the help
  9. Camera/screen moving

    I am having some issues with camera or screen and background animations... All of the examples i can find are kinda focused that your screen and character is still while the background is actually moving and that gives you impression that you are the one moving. I would like to script that your background is still and that your screen would be the one moving, like lets say you have dimension of the ''map'' 1920 × 1080 and your screen would be 800 x 640. If you would move the character, camera would be centered on it and he would be constantly changing coordinates while the background coordinates would be always the same... Is that even possible to do something like that or is it always that your background is moving instead of you? Tnx for any info if you can help me :P
  10. Bullet animation

    Thanks guys im going to try em all to see what I get... First just one question from Xaer0 what is that direction.normalize() and how do I use it?
  11. Im just wondering if anyone could help me out a bit... First of all im making topdown 2d shooter with C++ and SDL and iwe got a problem with the bullet animation... Anyone knows what math code should I use that the ''bullet'' would follow the mouse coordinates and then acctually go in a straight line from char coordinates to mouse coordinates? Tnx for any ideas...
  12. beginning C++ game programming

    [quote name='AllEightUp' timestamp='1352352683' post='4998753'] If I had a do over, I'd start with a simple C book in order to learn the basics of the language "before" adding the ++ bit to it. Unfortunately such books are becoming less available as everything is C++ now. Learning C++ requires taking bite sized bits at a time, learning the underlying C language is a great start and even though it has some unnecessary work involved, which C++ removes, the logic is often best learned in a more restrictive language. Unfortunately the due to such early language restrictions you have to "unlearn" a couple items when you transition to C++ properly.. An example of the C versus C++ issue. In C you are required to declare all variables in the current scope, defined or not prior to any code. (Any variable with a definition is considered "code", so has to come after pure declarations: i.e. "int a=0;" is a definition where "int a;" is just a declaration) in C+++ you can define new variables at any point. There are arguments for both cases but I personally prefer to keep declaration, definition and use as close as possible in the text files, so I prefer the C++ standard. As to all the learn XYZ because they are better, more used etc. In certain contexts all such comments are probably true. If I want to program web pages, I'll use Java script, if I want to generate web pages from templates with DB integration, I'd probably use Lua on Rails, Python and Drupal are pretty popular, etc etc etc etc etc..... But for generic everyday no specific target, I will use C/C++ every time. [/quote] I kinda started with C for dummies imo its a great book that teaches you the basics of C, since i had no prior knowledge in any language it did its job and now i went for SDL . Im having some problems with SDL dont really know is it the problem that im just too stupid for SDL or just cant get the right tutorial for me... If anyone knows some easy to understand tutorial for SDL please post... Tnx
  13. SDL mouse

    Hi all im kinda new with SDL and im making game for my self as a practise run really, Iwe been having couple of problems i want it to be top down shooter... Now i have no idea how to make my character follow and turn where the mouse is and bullet animition fire in direction of the mouse. If i could get any tips from you guys i would be really glad i just dont know where to start with this one. Tnx guys