1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| #include <stdlib.h>
#include <stdio.h>
#include "SDL/SDL.h"
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *bleu = NULL;
SDL_Surface *rouge = NULL;
SDL_Surface *bleu_jaune = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *image = NULL;
void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}// dessine une image dans une surface dest2 sur la surface dest
void DrawIMG(SDL_Surface *img, int pos_x, int pos_y, int w, int h, int pos_x2, int pos_y2)
{
SDL_Rect dest;
dest.x = pos_x;
dest.y = pos_y;
SDL_Rect dest2;
dest2.x = pos_x2;
dest2.y = pos_y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);
}
//dessiner une image sur une surface d coordonnées dest
void DessIMG(SDL_Surface *img, int pos_x, int pos_y)
{
SDL_Rect dest;
dest.x = pos_x;
dest.y = pos_y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
/*****************************************************************************/
/***********************Dessine une image en arriere plan*********************/
/*****************************************************************************/
void DrawBG()
{
Slock(screen);
DessIMG(image,0,0);
SDL_Flip(screen);
Sulock(screen);
}
/*****************************************************************************/
/*****Permet d'afficher un caractere en fonction de x et y vec une couleur****/
/*****************************************************************************/
void affiche_caract (char caract,int x,int y,SDL_Surface *couleur)
{
int i=0,test=0;
while ( test==0 )
{
// on n'affiche pas les espaces
if ( caract == (' ') )
return;
if ( caract == ('a'+i) )
{
if (i<15) //de 'a' à 'a'+14 on affichee les lettres à partir de
//x=32+i*32 et y=128 dans le fichier pointé par couleur
{
Slock(screen);
DrawIMG(couleur,x*32,y*32,32,32,32+i*32,128);
SDL_Flip(screen);
Sulock(screen);
test=1;
}
else //au dela de 'a'+14 on affichee les lettres à partir de
//x=0 et y=160 dans le fichier pointé par couleur
{
Slock(screen);
DrawIMG(couleur,x*32,y*32,32,32,(i-15)*32,160);
SDL_Flip(screen);
Sulock(screen);
test=1;
}
}
i++;
}
}
/***************************************************************************/
/*
Cette Fonction Dessine Un Carreau Dans La Scene, Destiné à Récuperer Une
Lettre Tapée Par Le Joueur.
x : abscisse.
y : ordonne.
c : lettre.
color : couleur de fond.
*/
int main( int argc, char* args[] )
{
char c;
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return 1;
}
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
if( screen == NULL )
{
return 1;
}
affiche_caract(c, 32, 32, NULL);
} |
Partager