-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiBK.c
69 lines (61 loc) · 1.89 KB
/
miBK.c
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
#include "SDL.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8
#define FPS 40
int main(int argc, char *argv[]) {
// Main loop
Uint32 waittime = 1000.0f/FPS;
Uint32 framestarttime = 0;
Sint32 delaytime;
SDL_Event event;
SDL_Surface *screen;
Uint8 *p;
int x = 10; //x coordinate of our pixel
int y = 20; //y coordinate of our pixel
/* Initialize SDL */
SDL_Init(SDL_INIT_VIDEO);
/* Initialize the screen / window */
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
/* Make p point to the place we want to draw the pixel */
p = (Uint8 *)screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
/* Draw the pixel! */
*p=0xff;
/* update the screen (aka double buffering) */
SDL_Flip(screen);
while(1){
if (SDL_PollEvent(&event))
{
// Check for the quit message
if (event.type == SDL_QUIT)
{
// Quit the program
break;
}
if (event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym) {
case SDLK_UP:
y++;
break;
case SDLK_DOWN:
y--;
break;
case SDLK_LEFT:
x--;
break;
case SDLK_RIGHT:
x++;
break;
}
p = (Uint8 *)screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
*p=0xff;
}
}
SDL_Flip(screen);
delaytime = waittime - (SDL_GetTicks() - framestarttime);
if(delaytime > 0)
SDL_Delay((Uint32)delaytime);
framestarttime = SDL_GetTicks();
}
}