init
This commit is contained in:
commit
580526df63
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
cmake-build*
|
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.27)
|
||||||
|
project(tunellerbutworse)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
|
||||||
|
add_executable(tunellerbutworse main.cpp
|
||||||
|
Game.cpp
|
||||||
|
Game.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(tunellerbutworse PRIVATE SDL2::SDL2)
|
107
Game.cpp
Normal file
107
Game.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
//
|
||||||
|
// Created by bruno on 27.10.2023.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Game.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
unsigned int Game::logicalWidth = 160;
|
||||||
|
unsigned int Game::logicalHeight = 100;
|
||||||
|
unsigned int Game::renderWidth = 1280;
|
||||||
|
unsigned int Game::renderHeight = 800;
|
||||||
|
|
||||||
|
bool Game::isRunning = true;
|
||||||
|
|
||||||
|
SDL_Event Game::event;
|
||||||
|
SDL_Window* Game::window;
|
||||||
|
SDL_Renderer* Game::renderer;
|
||||||
|
|
||||||
|
|
||||||
|
int Game::init(){
|
||||||
|
// Initialize SDL
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||||
|
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the SDL window and renderer
|
||||||
|
window = SDL_CreateWindow("Pixel Art Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, renderWidth, renderHeight, SDL_WINDOW_RESIZABLE);
|
||||||
|
if (!window) {
|
||||||
|
SDL_Log("Unable to create window: %s", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
if (!renderer) {
|
||||||
|
SDL_Log("Unable to create renderer: %s", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the logical scaling
|
||||||
|
SDL_RenderSetLogicalSize(renderer, logicalWidth, logicalHeight);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Game::processInput(){
|
||||||
|
event;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Game::render(){
|
||||||
|
// Render the checkerboard pattern
|
||||||
|
for (int x = 0; x < logicalWidth; x++) {
|
||||||
|
for (int y = 0; y < logicalHeight; y++) {
|
||||||
|
if ((x + y) % 2 == 0) {
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // Black
|
||||||
|
} else {
|
||||||
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // White
|
||||||
|
}
|
||||||
|
SDL_RenderDrawPoint(renderer, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Game::update(){
|
||||||
|
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
if (event.type == SDL_QUIT) {
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||||
|
renderWidth = event.window.data1;
|
||||||
|
renderHeight = event.window.data2;
|
||||||
|
SDL_RenderSetLogicalSize(renderer, logicalWidth, logicalHeight);
|
||||||
|
}
|
||||||
|
else if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP){
|
||||||
|
processInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the renderer
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
// Your game rendering code goes here, using the logical resolution
|
||||||
|
|
||||||
|
this->render();
|
||||||
|
|
||||||
|
// Present the renderer
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Game::run(){
|
||||||
|
this->init();
|
||||||
|
|
||||||
|
while (isRunning) {
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup and exit
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
return 0;
|
||||||
|
}
|
41
Game.h
Normal file
41
Game.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// Created by bruno on 27.10.2023.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TUNELLERBUTWORSE_GAME_H
|
||||||
|
#define TUNELLERBUTWORSE_GAME_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Game {
|
||||||
|
public:
|
||||||
|
static SDL_Window* window;
|
||||||
|
static SDL_Renderer* renderer;
|
||||||
|
|
||||||
|
// Logical resolution
|
||||||
|
static unsigned int logicalWidth;
|
||||||
|
static unsigned int logicalHeight;
|
||||||
|
|
||||||
|
// Rendering resolution (initial window size)
|
||||||
|
static unsigned int renderWidth;
|
||||||
|
static unsigned int renderHeight;
|
||||||
|
|
||||||
|
static bool isRunning;
|
||||||
|
|
||||||
|
static SDL_Event event;
|
||||||
|
|
||||||
|
int run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int init();
|
||||||
|
int processInput();
|
||||||
|
int render();
|
||||||
|
int update();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TUNELLERBUTWORSE_GAME_H
|
6
main.cpp
Normal file
6
main.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "Game.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Game game;
|
||||||
|
return game.run();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user