Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

sdl wont blit

This topic is 5395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how come this dosnt work
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <libiberty.h>
#include "SDL.h"
#include "Worm.h"
#include "Block.h"
/* The screen surface */
SDL_Surface *screen = NULL;

int Grid[10][10] =
{
    {6,6,6,6,6,6,6,6,6,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,5,5,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,0,0,0,0,0,0,0,0,6},
    {6,6,6,6,6,6,6,6,6,6}
};
       
/* This function draws to the screen; replace this with your own code! */
static void
draw ()
{
   SDL_Surface *block_src;
   SDL_Surface *apple_src;
   SDL_Surface *wall_src;
   block_src = SDL_LoadBMP("block.bmp"); 
   wall_src = SDL_LoadBMP("wall.bmp");
   apple_src = SDL_LoadBMP("apple.bmp");
    
   Worm *worm = new Worm;
   switch(Grid[100][100])
   {
   worm->ReadMap(Grid,block_src,wall_src,apple_src,screen);
   };   
   worm->Update(Grid,block_src,screen);
   SDL_Flip(screen);
   
}


int
main (int argc, char *argv[])
{
    char *msg;
    int done;

    /* Initialize SDL */
    if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
        asprintf (&msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit (1);
    }
    atexit (SDL_Quit);

    /* Set 640x480 16-bits video mode */
    screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        asprintf (&msg, "Couldn't set 640x480x16 video mode: %s\n",
          SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit (2);
    }
    SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);

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

        /* Check for events */
        while (SDL_PollEvent (&event))
        {
            switch (event.type)
            {
            case SDL_KEYDOWN:
                break;
            case SDL_QUIT:
                done = 1;
                break;
            default:
                break;
            }
        }

        /* Draw to screen */
        draw ();
    }

    return 0;
}
and heres the declerations
#include "Worm.h"
void Worm::Eating(int Grid[10][10])
{
    block i; 
    block End = Worm_Blocks.back();
    if(eating == true)
    {
        Worm_Blocks.push_back(i);        
        if(End.velocityY=5 && End.block_tileY-1 != filled)
        {  
            i.block_tileX = End.block_tileX;
            i.block_tileY = End.block_tileY - 1;
        };
         if(End.velocityY=-5 && End.block_tileY+1 != filled)
        {  
            i.block_tileX = End.block_tileX;
            i.block_tileY = End.block_tileY + 1;
        };
         if(End.velocityX=5 && End.block_tileX -1 != filled)
        {  
            i.block_tileX = End.block_tileX - 1;
            i.block_tileY = End.block_tileY;
        };
         if(End.velocityY=5 && End.block_tileX-1 != filled)
        {  
            i.block_tileX = End.block_tileX + 1;
            i.block_tileY = End.block_tileY;
        };
         Grid[i.block_tileX][i.block_tileY] = filled;
         End = Worm_Blocks.back();
         return;
        
    };
    return;
}; 

void Worm::Update(int Grid[10][10],SDL_Surface *src, SDL_Surface *dst)
{
    for(int i = 0; i < Worm_Blocks.size(); i++)
    {
        block End = Worm_Blocks.back();    
        if(End.velocityX = 5)
        {
           Grid[End.block_tileX - 1][End.block_tileY] = MT;
        };  
         if(End.velocityX = -5)
        {
           Grid[End.block_tileX + 1][End.block_tileY] = MT;
        };      
         if(End.velocityY = 5)
        {
           Grid[End.block_tileX][End.block_tileY - 1] = MT;
        };      
         if(End.velocityY = 5)
        {
           Grid[End.block_tileX][End.block_tileY + 1] = MT;
        };   
        Worm_Blocks.Move(Grid);    
    };            
};

void Worm::ReadMap(int Grid[10][10],SDL_Surface *block_src,SDL_Surface *wall_src,SDL_Surface *apple_src, SDL_Surface *dst)
{
    SDL_Rect *XYrect;
    int N = 1;
      for(int i = 0; i > 10; i++)
     {
         for(int j = 0; j < 10; j++)
         {
    Worm_Blocks.resize(2);
    switch(Grid[10][10])
    {
         XYrect->x = i * 10;
         XYrect->y = j * 10;                    
            case MT:
                {
                }
            case filled:
                {                 
                    SDL_BlitSurface(block_src, NULL, dst, XYrect);
                    Worm_Blocks[N].block_tileX = XYrect->x;
                    Worm_Blocks[N].block_tileY = XYrect->y;
                    N++;
                }
            case wall:
                {
                    SDL_BlitSurface(wall_src, NULL, dst, XYrect);
                };
            case apple:
                {
                    SDL_BlitSurface(apple_src, NULL, dst, XYrect);
                };
            };
        };                
                    
    };    
};
                

thanks for your help! [smile] [Edited by - raptorstrike on October 11, 2004 4:30:47 PM]

Share this post


Link to post
Share on other sites
Advertisement
Your question is a little vague. The title explains a little more clearly, but I'm not sure what you want. Are there any compiler errors? Is anything being blitted to the screen? If so, is it in the wrong place?

I tried pasting the source into a compiler to see for myself, but I noticed that Worm.h is missing. I suggest you either clarify or post the full source. Otherwise, most people don't want to read all of that to find one problem.

Share this post


Link to post
Share on other sites
It might be because of the flags you set with SDL_SetVideoMode().

You set SDL_SWSURFACE and SDL_DOUBLEBUF...so if i can remember correectly, you need to flip the buffer for it to show..its blitting to the back buffer and it hasnt actually been blitted to the screen until you call SDL_Flip()..

I could be wrong..

Share this post


Link to post
Share on other sites
First of all check if the SDL_Surfaces are NULL or not, are they actualy loaded!?

Also, here's a MAJOR bug switch(Grid[10][10]) it should be switch(Grid[j]), now it's actuly taking a value that's outside the array's boundry.

And DO NOT LOAD THE SURFACES EVERY TIME YOU DRAW!!

Actualy, there's TONS OF ERRORS IN THAT!!


EDIT:

WTF!?


switch(Grid[100][100])
{
worm->ReadMap(Grid,block_src,wall_src,apple_src,screen);
};


What exactly are you trying to do with the switch!?

And this:


for(int i = 0; i > 10; i++)
{
for(int j = 0; j < 10; j++)
{


you loop while i > 10 - it should be while i < 10

Do you have any idea what you're doing here!? Maybe start with something simpler, eh!? Somehow I get the feeling you wrote that code from some book and had no idea what it did.



/MindWipe

Share this post


Link to post
Share on other sites
Yeah the switch statement is faulty...its not actually getting to your blitting routine. Try Grid[j] instead of Grid[10][10].


Memory leaks all over the place too...

Share this post


Link to post
Share on other sites
AND WHAT THE HELL!??!


char *msg;
asprintf (&msg, "Couldn't set 640x480x16 video mode: %s\n",
MessageBox (0, msg, "Error", MB_ICONHAND);
free (msg);


That will probably crash you game when built as a release build.

Do yourself a favor and code something simple you understand. Okey?! Read a book about C++, learn what a pointer is. Okey!?

/MindWipe

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!