-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
68 lines (61 loc) · 1.8 KB
/
main.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
#include <stdio.h>
#include <SDL.h>
#include <SDL_events.h>
#include <SDL_keyboard.h>
#include <SDL_scancode.h>
#include <SDL_keycode.h>
#include "tk/bitmaps.h"
#include "tk/menu.h"
SDL_Renderer *ren;
int main() {
printf("Hello, World!\n");
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *w = SDL_CreateWindow("Test suite", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 256, 0);
ren = SDL_CreateRenderer(w, 0, 0);
SDL_SetRenderDrawColor(ren, 128, 128, 128, 255);
SDL_RenderSetScale(ren, 4, 4);
uint8_t cont = 1;
draw_menu();
while (cont == 1) {
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_QUIT) {
cont = 0;
}
if (ev.type == SDL_KEYUP) {
if (ev.key.keysym.sym == SDLK_q)
send_msg(MSG_BTN_A);
if (ev.key.keysym.sym == SDLK_w)
send_msg(MSG_BTN_B);
if (ev.key.keysym.sym == SDLK_e)
send_msg(MSG_BTN_C);
if (ev.key.keysym.sym == SDLK_r)
send_msg(MSG_BTN_D);
if (ev.key.keysym.sym == SDLK_k)
send_msg(MSG_LOCK);
if (ev.key.keysym.sym == SDLK_l)
send_msg(MSG_UNLOCK);
}
}
SDL_Delay(1000/120);
}
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}
void update_display() {
SDL_RenderPresent(ren);
}
void set_pixel(int x, int y) {
SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
SDL_RenderDrawPoint(ren, x, y);
}
void clear_pixel(int x, int y) {
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
SDL_RenderDrawPoint(ren, x, y);
}
void clear_display(){
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
SDL_RenderClear(ren);
}