Eli ajattelin kattoo noit valmiita ohjelmii tuli mieleen miten
tämmönen compiletaan?
opin asian jo...
#include <math.h> #include <SDL.h> #include <SDL_gfxPrimitives.h> #define WINDOW_WIDTH 400 #define WINDOW_HEIGHT 300 int main() { SDL_Surface *screen; SDL_Event event; float p1x= 0, p1y = 0, p2x = 0, p2y = 0, p3x = 0, p3y = 0, p4x = 0, p4y = 0, k=0; int size = 100; /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } atexit(SDL_Quit); /* Set up videomode */ screen = SDL_SetVideoMode (WINDOW_WIDTH, WINDOW_HEIGHT, 16, SDL_SWSURFACE); /* Main loop */ while( SDL_PollEvent(&event) >= 0 ) { p1x = WINDOW_WIDTH / 2 + sin(k) * size; p2x = WINDOW_WIDTH / 2 + sin(k + (3.14/2)) * size; p3x = WINDOW_WIDTH / 2 + sin(k + 3.14) * size; p4x = WINDOW_WIDTH / 2 + sin(k + 3.14 + (3.14/2)) * size; p1y = WINDOW_HEIGHT / 2 + cos(k) * size; p2y = WINDOW_HEIGHT / 2 + cos(k + (3.14/2)) * size; p3y = WINDOW_HEIGHT / 2 + cos(k + 3.14) * size; p4y = WINDOW_HEIGHT / 2 + cos(k + 3.14 + (3.14/2)) * size; k += 0.1; /* Draw rectangle */ lineRGBA(screen, p1x, p1y, p2x, p2y, 255, 255, 0, 255); lineRGBA(screen, p2x, p2y, p3x, p3y, 255, 255, 0, 255); lineRGBA(screen, p3x, p3y, p4x, p4y, 255, 255, 0, 255); lineRGBA(screen, p4x, p4y, p1x, p1y, 255, 255, 0, 255); /* Update screen */ SDL_Flip(screen); /* Clear screen */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); /* Handle keys... */ if (event.type==SDL_QUIT) { printf("Quitting.\n"); exit(0); } else if (event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_LEFT) { size -= 3; } else if (event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_RIGHT) { size += 3; } } return(0); }
tai joku muu vastaava?
Kiitos etukäteen.
Mod. Edit: Kooditagit
Ensin sinun pitää asentaa SDL, mistä voit lukea lisää tästä: https://www.ohjelmointiputka.net/oppaat/opas.
Aihe on jo aika vanha, joten et voi enää vastata siihen.