Screensaver hypnotiseur

Description

Bonjour
Un screensaver en SDL pas du tout assez optimisé, je m'en excuse mais sur un pentium 4 il tournera quand même ^^
disons qu'il économise pas beaucoup le processeur

le but du jeu c'est de tenir le plus longtemps possible devant, et/ou trouver comment il fonctionne

Source / Exemple :


#define WW 800
#define HH 600
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <math.h>

static SDL_Surface * init(int w, int h, int bpp);
static void          loop(SDL_Surface * s);
static void          manageEvents(SDL_Surface * s);
static void          draw(SDL_Surface * s);
static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y);

int main(int argc, char ** argv) {
  SDL_Surface * s;
  s = init(WW, HH, 32);
  loop(s);
  return 0;
}

static SDL_Surface * init(int w, int h, int bpp) {
  SDL_Surface * s;
  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    exit(1);
  }
  if ( (s = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWSURFACE |SDL_FULLSCREEN )) == NULL ) {
    exit(1);
  }
  int i; Uint32 *t = s->pixels; for (i=0; i < WW*HH; i++) t[i] = 0xFFFFFFFF;
  atexit(SDL_Quit);
  return s;
}

static void loop(SDL_Surface * s) {
  SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_HWSURFACE, WW*2, HH*2, 32, 0, 0, 0, 0);
  static int i,j;
  Uint32 *t = s2->pixels;
  static int count = 0;
  static int yesorno = 0;
  static double rotation3 = M_PI/2000;
  static SDL_Event event;
  static double rotation2 = 2.1543;
  for (i=0; i < WW*2; i++) for (j=0; j < HH*2; j++) t[j*WW+i] = 0;
  for(;;) {
    if (yesorno) rotation3 /= 1.3;
    else rotation3 *= 1.2;
    if (rotation3 < M_PI/500000) { yesorno = !yesorno; rotation3 = M_PI/500000; }
    if (rotation3 > M_PI/1000) { yesorno = !yesorno; rotation3 = M_PI/1000; }
    rotation2 += rotation3;
    while (rotation2 >= 2*M_PI) rotation2 -= 2*M_PI;
    SDL_Rotate(s2,s,rotation2,WW,HH);
    SDL_UpdateRect(s, 0, 0, WW, HH);
    SDL_Delay(1);
    if(SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) exit(0);
  }
}

static void SDL_Rotate(SDL_Surface *src,SDL_Surface *dst, double rotation, int x, int y) {
    Uint32 *t1 = src->pixels, *t2 = dst->pixels;
    static int i,j,i2,j2,i3,j3;
    static double vi, vj;
    vi = cos(rotation); vj = sin(rotation);
    for (i=0; i < WW*HH; i++) t2[i] = 0xFFFFFFFF;
    for (i=0; i < WW*2; i++)
        for (j=0; j < HH*2; j++) {
            i3 = i - x; j3 = j - y;
            i2 = (double)i3*vi - (double)j3*vj + x - WW/2; j2 = (double)i3*vj + (double)j3*vi + y - HH/2;
            if (i2 >=0 && j2 >= 0 && i2 < WW && j2 < HH)
                t2[j2 * WW + i2] = t1[j * WW + i];
        }
}

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.