81 lines
1.8 KiB
C
81 lines
1.8 KiB
C
#include <stdio.h> //printf and shit
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
const int width = 800;
|
|
const int height = 600;
|
|
|
|
|
|
int main(){
|
|
//legally required print (it broke without it)
|
|
printf("asd");
|
|
|
|
//general setup
|
|
SDL_Init(SDL_INIT_EVERYTHING);
|
|
SDL_Window *window = SDL_CreateWindow("amogus", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
|
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
|
|
|
|
//clear
|
|
//this kinda doesnt work
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
SDL_RenderClear(renderer);
|
|
|
|
int mousex;
|
|
int mousey;
|
|
SDL_Rect rect;
|
|
rect.x = 250;
|
|
rect.y = 150;
|
|
rect.w = 10;
|
|
rect.h = 10;
|
|
|
|
while (1) {
|
|
//update mouse
|
|
SDL_PumpEvents();
|
|
const Uint8 *state = SDL_GetKeyboardState(NULL);
|
|
SDL_GetMouseState(&mousex, &mousey);
|
|
|
|
if (state[SDL_SCANCODE_Q]) {
|
|
goto cleanup;
|
|
}
|
|
if (state[SDL_SCANCODE_W]) {
|
|
rect.y -= 1;
|
|
}
|
|
|
|
if (state[SDL_SCANCODE_A]) {
|
|
rect.x -= 1;
|
|
}
|
|
|
|
if (state[SDL_SCANCODE_S]) {
|
|
rect.y += 1;
|
|
}
|
|
|
|
if (state[SDL_SCANCODE_D]) {
|
|
rect.x += 1;
|
|
}
|
|
|
|
if (state[SDL_SCANCODE_T]) {
|
|
rect.x = 10;
|
|
rect.y = 10;
|
|
}
|
|
SDL_Delay(1);
|
|
|
|
//render loop
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
|
SDL_RenderDrawPoint(renderer, mousex, mousey);
|
|
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
SDL_RenderPresent(renderer);
|
|
}
|
|
SDL_RenderPresent(renderer);
|
|
|
|
cleanup:
|
|
|
|
//CLEANUP
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit;
|
|
return 0;
|
|
}
|