#include "SDL/SDL.h"
#include "game.h"
/* Implementazione delle funzioni */
// Funzione che crea una palla
Ball* createBall( int x, int y, unsigned short speed ) {
Ball* ball;
// Setto le variabili della palla
ball->surface = SDL_LoadBMP( "ball.bmp" );
ball->dst.x = x;
ball->dst.y = y;
setBallDirection( ball, FALSE, FALSE, FALSE, FALSE );
ball->speed = speed;
return ball;
}
// Funzione che distrugge una palla
void destroyBall( Ball* ball ) {
SDL_FreeSurface( ball->surface );
}
// Funzione che crea un paddle
Paddle* createPaddle( int x, int y, unsigned short speed ) {
Paddle* paddle;
// Setto le variabili del paddle
paddle->surface = SDL_LoadBMP( "paddle.bmp" );
paddle->dst.x = x;
paddle->dst.y = y;
paddle->speed = speed;
return paddle;
}
// Funzione che distrugge un paddle
void destroyPaddle( Paddle* paddle ) {
SDL_FreeSurface( paddle->surface );
}
// Funziona che crea un background
Background* createBackground() {
Background *background;
background->surface = SDL_LoadBMP( "background.bmp" );
return background;
}
// Funzione che distrugge un background
void destroyBackground( Background* background ) {
SDL_FreeSurface( background->surface );
}
// Funzione che setta la direzione di una palla
void setBallDirection( Ball* ball, BOOL right, BOOL left, BOOL up, BOOL down ) {
ball->direction.right = right;
ball->direction.left = left;
ball->direction.up = up;
ball->direction.down = down;
}
// Funzione che muove una palla
void moveBall( Ball* ball ) {
if ( ball->direction.right == TRUE ) {
ball->dst.x += ball->speed;
}
if ( ball->direction.left == TRUE ) {
ball->dst.x -= ball->speed;
}
if ( ball->direction.up == TRUE ) {
ball->dst.y -= ball->speed;
}
if ( ball->direction.down == TRUE ) {
ball->dst.y += ball->speed;
}
}
// Aggiorna la palla sullo schermo
void refreshBall( Ball* ball, SDL_Surface* screen ) {
SDL_BlitSurface( ball->surface, NULL, screen, &ball->dst );
}
// Aggiorna il paddle sullo schermo
void refreshPaddle( Paddle* paddle, SDL_Surface* screen ) {
SDL_BlitSurface( paddle->surface, NULL, screen, &paddle->dst );
}
// Aggiorna lo schermo
void refreshScreen( SDL_Surface* screen ) {
//Aggiorna screen
SDL_UnlockSurface( screen );
SDL_BlitSurface( screen, NULL, NULL, NULL );
SDL_UpdateRect ( screen, 0, 0, 0, 0 ); // Gli zero stanno ad indicare che aggiornerà tutto la dialog
SDL_LockSurface( screen );
}
// Aggiorna il background
void refreshBackground( Background* background, SDL_Surface* screen ) {
// Aggiorna background
SDL_BlitSurface( background->surface, NULL, screen, NULL );
}