Thread: The great mystery

  1. #16
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    All these guesses are way off except for one, and I don't know how you knew this.

    ...serial bedwetter...
    When I was about 24 or so I had a lot of alcohol to drink and I wet my bed. I ........ed myself, and now I wear diapers. lol.
    I compile code with:
    Visual Studio.NET beta2

  2. #17
    Registered User rick barclay's Avatar
    Join Date
    Aug 2001
    Posts
    835
    >All these guesses are way off except for one, and I don't know how you knew this.<

    I know a secret. I was watching you through an
    obscure portal on the old board. Why do you
    have a heart with Mother written on it tattooed
    to your butt?

    rick barclay
    No. Wait. Don't hang up!

    This is America calling!

  3. #18
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >-Dean is a robot, that was hacked by Microsoft programmers- and reprogrammed with pro-Microsoft stuff

    haha funny Microsoft couldn't Hack there way out of a wet paper bag...

    i think/Hope Sunlight will return someday so i can finally end the OpenGL vs. Direct-X debate once and for all...

    cause i could...

    BTW: im pro OpenGL.

  4. #19
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    I know a secret. I was watching you through an
    obscure portal on the old board. Why do you
    have a heart with Mother written on it tattooed
    to your butt?
    I don't know but I just noticed that, you're right! I remember once I had a teen girlfriend, I was about 20 at the time, anyway, she convinced me to dye my hair straw blonde. I wouldn't normally do these kinds of things but she got her tounge pierced and did all kinds of stuff, she was also into witch craft and some goth stuff. Anyway I guess it somehow made me a rebel now.
    I compile code with:
    Visual Studio.NET beta2

  5. #20
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    >> 1. Must press key for input (no holding it down)






    I'm little confused but if I interpret correct, I had to do something

    similar to this to create a sliding motion with the mouse.


    Because

    you can detect when a key goes down and when it comes back

    up you set a state variable perhaps the objects velocity etc.

    Once the key goes up you can set it to 0 or whatever.








    Code:
    
    
    
    
    
    SDL_Event event;
    
    
    
    
    
    
    unsigned char key_state;
    
    
    
    
    
    
    
    
    
    
    
    
    
    enum {
    
    
    
    
    
    
        RIGHT_KEY_PRESSED = 0x0001,
    
    
    
    
    
    
        LEFT_KEY_PRESSED    = 0x0002,
    
    
    
    
    
    
        UP_KEY_PRESSED       = 0x0004,
    
    
    
    
    
    
        DOWN_KEY_PRESSED  = 0x0008
    
    
    
    
    
    
    };
    
    
    
    
    
    
    
    
    
    
    
    
    
    /* ... */
    
    
    
    
    
    
    
    
    
    
    
    
    
    while(SDL_Poll(&event))
    
    
    
    
    
    
    {
    
    
    
    
    
    
        switch(event.type) {
    
    
    
    
    
    
        case SDL_KEYDOWN:
    
    
    
    
    
    
                  switch(event.key.keysym.sym) {
    
    
    
    
    
    
                   case SDLK_RIGHT:
    
    
    
    
    
    
                             key_state |= RIGHT_KEY_PRESSED;
    
    
    
    
    
    
                             break;
    
    
    
    
    
    
                  case SDLK_UP:
    
    
    
    
    
    
                             key_state |= UP_KEY_PRESSED;
    
                             break;
    
                   case SDLK_LEFT:
    
                             key_state |= LEFT_KEY_PRESSED;
    
                             break;
    
                    case SDLK_DOWN:
    
                              key_state |= DOWN_KEY_PRESSED;
    
                              break;
    
                    }            
    
                    break;
    
         case SDL_MOUSEMOTION:
    
    
                   printf("mouse's x motion: %d\n", event.motion.x);
    
    
                   printf("mouse's y motion: %d\n", event.motion.y);
    
    
                   break;
    
    
         }
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    if (key_state & RIGHT_KEY_PRESSED) {
    
    
    
    
           /* do something */
    
    
    
    
    }










    If this doesn't solve it a related article is this one

    http://sdldoc.csn.ul.ie/guideinputkeyboard.php#AEN363

    Under "proper game movement"



    I don't know about game pads though SDL supports

    joysticks. I don't have a joy stick or game pad so it's

    hard to test it out.

  6. #21
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Not sure why the code as so many spaces.
    Anyways you should look at SDL_Event.h it's well commented.

  7. #22
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    It's obvious to me look at the disclaimer on Sunlight's website

    right


    under copyright.





    "I do not answer questions on C, C++, Java, Windows programming, electronics, mathematics or any other topic."

  8. #23
    .
    Join Date
    Aug 2001
    Posts
    598
    >If this doesn't solve it a related article is this one
    http://sdldoc.csn.ul.ie/guideinputkeyboard.php#AEN363
    Under "proper game movement" <

    I've tried that already, and the object does not move till you relese the key.


    Thanks for the mouse movment, I spent an hour or so tring to figure out how to asign player1.yTop the y postion of the mouse.

    >you wish you can be as smart as me but sorry you can't <

    Me, as smart as collageGirl nah. I'd rather be smarter, being dummer would be to much work
    To Err Is To Be Human. To Game Is Divine!"

  9. #24
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Well, gamegod3001, for one thing you didn't quote her properly. Maybe you should take a double dose of your medicine today.
    I compile code with:
    Visual Studio.NET beta2

  10. #25
    Registered User rick barclay's Avatar
    Join Date
    Aug 2001
    Posts
    835
    >anyway, she convinced me to dye my hair straw blonde. I wouldn't normally do these kinds of things but she got her tounge pierced and did all kinds of stuff, she was also into witch craft and some goth stuff. Anyway I guess it somehow made me a rebel now.<

    My number two son fits this description, sort of.
    He and his friends, both sexes, died their hair all
    kinds of weird colors. A friend of his ate with us
    the other night, she had so many pins and stuff
    stuck through her eyebrows, I couldn't look at
    her. They're weird but they're nice people, too.
    The differences between my four children are profound.
    None of them comes close to resembling any other;
    yet, they all have physical and character traits
    identical to one of their parents. Very strange.

    rick barclay
    No. Wait. Don't hang up!

    This is America calling!

  11. #26
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    LOL
    I compile code with:
    Visual Studio.NET beta2

  12. #27
    .
    Join Date
    Aug 2001
    Posts
    598
    >Well, gamegod3001, for one thing you didn't quote her properly. Maybe you should take a double dose of your medicine today.<
    What do I have to use the quote tags?

    >Me to, lets pick on dean/witch_craft.
    I wrote this before I saw his comment, I must be good.
    To Err Is To Be Human. To Game Is Divine!"

  13. #28
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    No, I don't mean useing quote tags. I mean reading more carefully and not inserting words into statements and calling them quotes.
    I compile code with:
    Visual Studio.NET beta2

  14. #29
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I'll code some stuft with a scarry box that you move around.

  15. #30
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Ok here it is, your code is probably not working
    because your missing a break statement in the switch
    statement where your handling input.

    Code:
    #include <SDL/SDL.h>
    #include <memory.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    struct Box {
        int x, y;
        int w, h;
        int xvel, yvel;
        int xaccel, yaccel;
        Uint32 color;
    };
    
    typedef struct Box Box;
    
    SDL_Surface* global_screen;
    Box global_my_box;
    
    
    void init_box(Box* box, int x, int y, int w, int h,
                  int xvel, int yvel, Uint32 color);
    
    void draw_box(Box* box);
    void erase_box(Box* box);
    void update_box(Box* box);
    void quit_box_game(void);
    void handle_events(void);
    
    
    int main(void)
    {
        Uint32 video_flags;
        Uint32 color_blue;
    
        video_flags = SDL_DOUBLEBUF | SDL_FULLSCREEN;
    
        if (SDL_Init(SDL_INIT_VIDEO) < 0) {
            fprintf(stderr, "Error initializing SDL: %s\n", SDL_GetError());
            return EXIT_FAILURE;
        }
        atexit(SDL_Quit);
    
        global_screen = SDL_SetVideoMode(800, 600, 16, video_flags);
        if (global_screen == NULL) {
            fprintf(stderr, "Error setting video mode: %s\n", SDL_GetError());
            return EXIT_FAILURE;
        }
    
        color_blue = SDL_MapRGB(global_screen->format, 0, 0, 255);
        init_box(&global_my_box, 30, 30, 100, 100, 1, 2, color_blue);
    
        for(;;) {
            handle_events();
            erase_box(&global_my_box);
            update_box(&global_my_box);
            draw_box(&global_my_box);
            SDL_Flip(global_screen);
        }
    
        return 0;
    }
    
    void init_box(Box* box, int x, int y, int w, int h,
                  int xvel, int yvel, Uint32 color)
    {
        box->x = x;
        box->y = y;
        box->w = w;
        box->h = h;
        box->xvel= xvel;
        box->yvel = yvel;
        box->color = color;
    }
    
    
    /* very crude probably slow way of drawing a box 
       assumes screen is setup to 32 bits
     */
    void draw_box(Box* box)
    {
        Uint16 pitch;
        Uint16* p;
        int i, j;
    
        pitch = global_screen->pitch;
        SDL_LockSurface(global_screen);
    
        p = global_screen->pixels;
    
        for (i = box->y; i < box->y + box->h; ++i) {
            for (j = box->x; j < box->x + box->w; ++j) {
                p[i * (pitch/2) + j] = box->color;
            }
        }
    
        SDL_UnlockSurface(global_screen);
    }
    
    
    void erase_box(Box* box)
    {
        Uint16 pitch;
        Uint16* p;
        int i, j;
    
        pitch = global_screen->pitch;
        SDL_LockSurface(global_screen);
    
        p = global_screen->pixels;
    
        for (i = box->y; i < box->y + box->h; ++i) {
            for (j = box->x; j < box->x + box->w; ++j) {
                p[i * (pitch/2) + j] = 0;
            }
        }
    
        SDL_UnlockSurface(global_screen);
    }
    
    void update_box(Box* box)
    {
        box->xvel += box->xaccel;
        box->yvel += box->yaccel;
    
        if (box->xvel > 30) box->xvel = 20;
        if (box->yvel > 30) box->yvel = 20;
    
        box->x += box->xvel;
        box->y += box->yvel;
    
        if (box->y < 0) {
            box->y = 0;
            box->yvel = -box->yvel;
            box->yaccel = 0;
        }
        if (box->y + box->h >= global_screen->h) {
            box->y = global_screen->h - box->h - 1;
            box->yvel = -box->yvel;
            box->yaccel = 0;
        }
    
        if (box->x < 0) {
            box->x = 0;
            box->xvel = -box->xvel;
            box->xaccel = 0;
        }
        if (box->x + box->w >= global_screen->w) {
            box->x = global_screen->w - box->w - 1;
            box->xvel = -box->xvel;
            box->xaccel = 0;
        }
    }
    
    
    void handle_events()
    {
        SDL_Event event;
    
        while(SDL_PollEvent(&event)) {
            switch(event.type) {
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym) {
                case SDLK_RIGHT:
                    global_my_box.xaccel = 2;
                    break;
                case SDLK_LEFT:
                    global_my_box.xaccel = -2;
                    break;
                case SDLK_UP:
                    global_my_box.yaccel = -2;
                    break;
                case SDLK_DOWN:
                    global_my_box.yaccel = 2;
                    break;
                case SDLK_ESCAPE:
                    quit_box_game();
                    break;
                default:
                    break;
                }
                break;
            case SDL_KEYUP:
                switch(event.key.keysym.sym) {
                case SDLK_RIGHT:     /* fall through */
                case SDLK_LEFT:
                    global_my_box.xaccel = 0;
                    break;
                case SDLK_UP:       /* fall through */
                case SDLK_DOWN:
                    global_my_box.yaccel = 0;
                    break;
                default:
                    break;
                }
                break;
            case SDL_QUIT:
                quit_box_game();
                break;
            default:
                break;
            }
        }
    }
    
    
    void quit_box_game(void)
    {
        exit(EXIT_SUCCESS);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  2. Great Teacher..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-03-2003, 06:40 AM
  3. programming was great until c came along
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-04-2002, 07:37 PM
  4. What's so great about C++?
    By InFeStEd-ArCh0n in forum C++ Programming
    Replies: 32
    Last Post: 05-07-2002, 09:49 PM
  5. Mystery.
    By Nutshell in forum C Programming
    Replies: 1
    Last Post: 01-27-2002, 01:41 AM