All pastes #557843 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-11 03:59 UTC
rendered paste body
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <iostream>
using namespace std;

SDL_Surface *Screen = NULL;
SDL_Surface *Backdrop = NULL, *Gift = NULL;
SDL_Rect Offset;
int XAccel = 2, YAccel = 2;

SDL_Surface *Load( char* Name ){

  SDL_Surface *TempIMG = NULL;
  TempIMG = IMG_Load( Name );    
  return SDL_DisplayFormatAlpha( TempIMG );;
}

int Init(){

  SDL_Init( SDL_INIT_EVERYTHING );
  Screen = SDL_SetVideoMode( 800, 600, 32, SDL_SWSURFACE );
  SDL_WM_SetCaption( "Happy Birthday Pato!", "Birthday" );
  Backdrop = Load( "Backdrop.png" );
  Gift = Load( "Gift.png" );
  Offset.x = Offset.y = 0;
  return 0;
}

int Kill(){

  SDL_FreeSurface( Screen );
  SDL_FreeSurface( Backdrop );
  SDL_FreeSurface( Gift );
  SDL_Quit();
  return 0;
}

void Process(){

  while( SDL_GetTicks() < 10000 ){
    
    if( Offset.x >= 720 || Offset.x <= 0 )
      XAccel *= -1;
    
    if( Offset.y >= 530 || Offset.y <= 0 )
      YAccel *= -1;
      
    Offset.x += XAccel;
    Offset.y += YAccel;
    SDL_BlitSurface( Backdrop, NULL, Screen, NULL );
    SDL_BlitSurface( Gift, NULL, Screen, &Offset );
    SDL_Flip( Screen );
    SDL_PumpEvents();
  }
  return;
}

int main(){

  Init();
  Process();
  Kill();
  return 0;
}