Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 13th, 2005, 12:55 AM   #1
Dr.Backtick`
Newbie
 
Join Date: Dec 2004
Posts: 16
Rep Power: 0 Dr.Backtick` is on a distinguished road
Help on Game Design (Jezzball Clone)

Hi,

For those of you familiar with Jezzball i'm trying to make a clone of it. For those of you unfamiliar with Jezzball its a game where you start out with 2 balls bouncing off walls with the user's goal is to trap the balls in an enclosed area. You win when you enclose the balls in about 78% of the screen. Each level you get more on the screen.


Well... I currently have a program designed with SDL. The balls bouce off of the edges, the user can move, you can place walls down but the walls are passthrough (I think I need collission detecting). I need it so if I press spacebar the wall will be implemented onto the grid and be unpassable. The ball will need to bouce off of it on either side. I have Googled colission detecting but each thing I come across seems that I must redesign my game.

If it makes it any clearer the code is below:

/*windows copy*/

#include <stdio.h>
#include <stdlib.h>

#include <SDL.h>
#include <SDL_video.h>

SDL_Surface *grid;
SDL_Surface *image,*enemy;
SDL_Surface *screen;
SDL_Surface *takespace;
SDL_Surface *wall;

int xpos=29,ypos=26;
int wallx,wally;
int ex=29,ey=51;
int svx=6,svy=11;//enemy's velocity
int wallgrid[26][23];

int InitImages()
{
  //takespace = SDL_LoadBMP("takespace.bmp");
  grid = SDL_LoadBMP("data/pics/battlegrid.bmp");
  image = SDL_LoadBMP("data/pics/player.bmp");
  enemy = SDL_LoadBMP("data/pics/enemy.bmp");
  wall = SDL_LoadBMP("data/pics/wall.bmp");
  if(!image ||!grid ||!enemy ||!wall)
    {
     fprintf(stderr,"error loading bitmaps\n");
     //exit(1);
    }
  return 0;
}

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 DrawIMG(SDL_Surface *img, int x, int y,SDL_Surface *img2)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, img2, &dest);
}

void DrawBG()
{
  DrawIMG(grid, 0, 0);
}

void DrawScene(int x, int y, SDL_Surface *scrn)
{
  DrawIMG(grid, x-30, y-30, 90, 90, x-30, y-30);
  DrawIMG(scrn, x, y);

  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(800,600,32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE|SDL_ANYFORMAT);
  if ( screen == NULL )
  {
    fprintf(stderr,"Unable to set 800x600 video: %s\n", SDL_GetError());
    exit(1);
  }

  SDL_ShowCursor(0);//cursor is annoying
  InitImages();//call up function InitImages from the global space which loads the images.
  DrawBG();//draw the background

  int done=0;
  
  while(done == 0)
  {
    SDL_Event event;

    while ( SDL_PollEvent(&event) )
    {
   
    switch(event.type)
      {
       case SDL_QUIT:
         done = 1;
	 break;
       
       case SDL_KEYDOWN://|| forward == LOCAL_KEY_ESCAPE
         if ( event.key.keysym.sym == SDLK_ESCAPE  ) { done = 1; }
	 break;
      }
  
      
    }//end while loop
    
    //I would use a case here but switch complains that Uints arent integers and it doesnt work even with the conversion specifier.

    keys = SDL_GetKeyState(NULL);    
    
ex += svx;
ey += svy; 

if(wallgrid[ex][ey]==2)
  {
     svx = -(svx);
     svy = -(svy);
  }

if(ex < 29)
  {
     svx = -(svx); 
  } 

if(ex > 770)
  {  
     svx = -(svx); 
  }
 
if(ey < 26)
  {  
     svy = -(svy); 
  } 

if(ey > 575)
  {
     svy = -(svy); 
  }
         
    if (keys[SDLK_UP] && ypos >30)
      { 
       ypos -= 25;
      }
      
    if (keys[SDLK_DOWN] && ypos <575)
      { 
       ypos += 25;
       
      }
      
    if (keys[SDLK_LEFT] && xpos >30)
      {
       xpos -= 30;
      }
      
    if (keys[SDLK_RIGHT] && xpos <770)
      { 
       xpos += 30;       
      }
      
    if( keys[SDLK_SPACE] )
      {
	wallgrid[ex][ey]=2;
        DrawIMG(wall,xpos,ypos,grid);
      }


    DrawScene(ex,ey,enemy);
    DrawScene(xpos,ypos,image);
    SDL_Delay(100);
  }//end the main while

  return 0;
}

The Linux version isnt much different (just different location of headers).

I have posted a about this on a different forum. So if you wish to see what I said there and what replies I recieved please visit:

http://www.codedread.com/forum/thread-89.html

Thanks in advance,
George

Last edited by Dr.Backtick`; Mar 13th, 2005 at 8:57 AM.
Dr.Backtick` is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC