My first SDL game

Started by
19 comments, last by neon_prannock 19 years, 5 months ago
I'm learning SDL and I've just made this game. It´s very simple: you can control a little smile on the screen, with the arrows, and when the smile colides with the ball bouncering around, the game ends. Please test it and give your opinion! ;-) Download Game
Web site > http://sergiosantos.info
Advertisement
Dead link. Sounds interesting, gimmie a PM or something when it's back up. I'd like to see how your first project is going.
I could download it, so it must be running again...

You should try to expand the game, then it would be fun to play.
Right now I would say it was more or less like an alpha version, but not bad at all...
Killers don't end up in jailThey end up on a high-score!
Copy paste the link dont click because if you click it wont work. Another thing is that the app runs 2x slower once you move the smiley. If you dont everything runs faster.!
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
How could I fix this last problem? Any sugestion?
Web site > http://sergiosantos.info
Nicely done. When can we expect the source release! What resources would you recommend?

Now try to do a pong clone.
Rob Loach [Website] [Projects] [Contact]
Looks too slow while playing....
Here's the source code (without comments)

#include <stdio.h>#include <stdlib.h>#include <SDL/SDL.h>SDL_Surface *back;SDL_Surface *image;SDL_Surface *smile;SDL_Surface *screen;int xpos=25,ypos=20,xx=1,yy=1,apos=25,bpos=300,key;int InitImages(){  back = SDL_LoadBMP("bg.bmp");  image = SDL_LoadBMP("ball.bmp");  SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL ,SDL_MapRGB(image->format,0,0,0) );  smile = SDL_LoadBMP("smile.bmp");  SDL_SetColorKey(smile, SDL_SRCCOLORKEY | SDL_RLEACCEL ,SDL_MapRGB(smile->format,255,255,255) );  return 0;}int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,                        SDL_Surface *dst, SDL_Rect *dstrect);void DrawIMG(SDL_Surface *img, int x, int y){  SDL_Rect dest;  dest.x = x;  dest.y = y;  SDL_BlitSurface(img, NULL, screen, &dest);}void DrawIMG(SDL_Surface *img, int x, int y,int w, int h, int x2, int y2){  SDL_Rect dest;  dest.x = x;  dest.y = y;  SDL_Rect dest2;  dest2.x = x2;  dest2.y = y2;  dest2.w = w;  dest2.h = h;  SDL_BlitSurface(img, &dest2, screen, &dest);}void DrawBG(){  DrawIMG(back, 0, 0);}void DrawScene(){  DrawIMG(back, xpos-1, ypos-1, 51, 51, xpos-1, ypos-1);  DrawIMG(image, xpos, ypos);  SDL_Flip(screen);}void DrawSmile(){  DrawIMG(back, apos-1, bpos-1, 31, 31, apos-1, bpos-1);  DrawIMG(smile,apos,bpos);    SDL_Flip(screen);}     int main(int argc, char *argv[]){  Uint8* keys;      if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )  {    printf("Unable to init SDL: %s\n", SDL_GetError());    exit(1);  }  atexit(SDL_Quit);  screen=SDL_SetVideoMode(700,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF);  if ( screen == NULL )  {    printf("Unable to set 700x400 video: %s\n", SDL_GetError());    exit(1);  }    InitImages();  DrawBG();  DrawSmile();      int done=0;  while(done == 0)  {    SDL_Event event;    while ( SDL_PollEvent(&event) )    {      if ( event.type == SDL_QUIT )  {  done = 1;  }      if ( event.type == SDL_KEYDOWN )      {        if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }      }    }        xpos=xpos+xx;    ypos=ypos+yy;    if ((xpos==644)|(xpos==0))    {        xx=xx*-1;    }    if ((ypos==344)|(ypos==0))    {       yy=yy*-1;    }                  DrawScene();            if (((apos+30>xpos)&&(apos<xpos+50))&&((bpos+30>ypos)&&(bpos<ypos+50)))      {          exit(1);      }                 keys = SDL_GetKeyState(NULL);    if ( (keys[SDLK_UP])&&(bpos!=6) ) { bpos -= 1;key=1; }    if ( (keys[SDLK_DOWN])&&(bpos!=365) ) { bpos += 1;key=1; }    if ( (keys[SDLK_LEFT])&&(apos!=6) ) { apos -= 1;key=1; }    if ( (keys[SDLK_RIGHT])&&(apos!=665) ) { apos += 1;key=1; }      if (key==1)      {          DrawSmile();          key=0;      }      }      return 0;}


And I'm already making an Pong type game. Thanks for the comments! ;-)

Any sugestion on the code, and how to make it faster?
Web site > http://sergiosantos.info
Yes, use a backbuffer. That should do the trick.
Congrats.

Yea,make that pong clone will ya.
______________________________________________________________________________________________________
[AirBash.com]

This topic is closed to new replies.

Advertisement