First render of the physics
This commit is contained in:
41
Window.cpp
41
Window.cpp
@@ -1,29 +1,38 @@
|
||||
#include "Window.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
void Window::Draw(std::function<bool(Window*)> f){
|
||||
void Window::Draw(std::function<bool(Window*)> setup, std::function<bool(Window*)> draw){
|
||||
setup(this);
|
||||
while(Running){
|
||||
|
||||
Running = f(this);
|
||||
SDL_SetRenderDrawColor(ren, 0x00,0x00,0x00,0xff);
|
||||
SDL_RenderClear(ren);
|
||||
Events(draw);
|
||||
draw(this);
|
||||
SDL_RenderPresent(ren);
|
||||
|
||||
Events();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::Events(){
|
||||
while(SDL_PollEvent(e)){
|
||||
if(e->type == SDL_QUIT){
|
||||
void Window::Events(std::function<bool(Window*)> draw){
|
||||
while(SDL_PollEvent(&e)){
|
||||
if(e.type == SDL_QUIT){
|
||||
Running = false;
|
||||
}
|
||||
if(e->type == SDL_KEYDOWN){
|
||||
switch(e->key.keysym.sym){
|
||||
if(e.type == SDL_KEYDOWN){
|
||||
switch(e.key.keysym.sym){
|
||||
case SDLK_a:
|
||||
Running = false;
|
||||
break;
|
||||
case SDLK_s:
|
||||
step = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,7 +48,7 @@ Window::Window(std::string title, int width, int height)
|
||||
ErrorHandler::send(ErrorType::SDL_ERROR, "SDL_Init");
|
||||
}
|
||||
|
||||
win = SDL_CreateWindow("test", 0,0, width, height, SDL_WINDOW_SHOWN);
|
||||
win = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
if(win == NULL){
|
||||
ErrorHandler::send(ErrorType::SDL_ERROR, "SDL_CreateWindow");
|
||||
}
|
||||
@@ -59,3 +68,17 @@ Window::~Window(){
|
||||
SDL_Renderer* Window::GetRenderer(){
|
||||
return ren;
|
||||
}
|
||||
|
||||
void Window::DrawCircle(SDL_Renderer* ren, int x, int y, int r, bool filled){
|
||||
std::vector<SDL_Point> circle;
|
||||
for(int _x = x - r; _x <= x + r; _x++){
|
||||
for(int _y = y - r; _y <= y + r; _y++){
|
||||
int dx = _x - x;
|
||||
int dy = _y - y;
|
||||
if (dx*dx + dy*dy <= r*r){
|
||||
circle.push_back({_x, _y});
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_RenderDrawPoints(ren, circle.data(), circle.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user