This commit is contained in:
plane000
2018-09-30 15:59:36 +01:00
parent 24b195e1da
commit 32e44a9018
7 changed files with 42 additions and 5 deletions

View File

@@ -127,6 +127,7 @@
<ItemGroup>
<ClCompile Include="entity.cpp" />
<ClCompile Include="game.cpp" />
<ClCompile Include="logger.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="mathHelper.cpp" />
<ClCompile Include="renderer.cpp" />
@@ -135,6 +136,7 @@
<ItemGroup>
<ClInclude Include="entity.h" />
<ClInclude Include="game.h" />
<ClInclude Include="logger.h" />
<ClInclude Include="mathHelper.h" />
<ClInclude Include="renderer.h" />
<ClInclude Include="sprite.h" />

View File

@@ -7,6 +7,7 @@
<ClCompile Include="game.cpp" />
<ClCompile Include="mathHelper.cpp" />
<ClCompile Include="sprite.cpp" />
<ClCompile Include="logger.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="headers">
@@ -32,5 +33,6 @@
<ClInclude Include="timer.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="logger.h" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
#include "logger.h"
Logger::Logger() {
}
Logger::~Logger() {
}

8
crumpet-engine/logger.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
class Logger {
public:
Logger();
virtual ~Logger();
};

View File

@@ -6,12 +6,25 @@
#define SCREEN_HEIGHT 600
int main(int argc, char** argv) {
Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1000 / 60);
Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 1, 1000 / 60);
Timer timer;
Entity mario("mario", game.SDLRenderer);
mario.LoadTexture("/resources/mario.png");
Entity box("box", game.SDLRenderer, PolyDrawType::DRAW_FILLED_RECT);
box.SetDrawColour(Vec4(144, 022, 111, 255));
box.SetRect(Vec2(0, 0), Vec2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
Entity boxOutline("box", game.SDLRenderer, PolyDrawType::DRAW_OUTLINE_RECT);
boxOutline.SetDrawColour(Vec4(144, 111, 111, 255));
boxOutline.SetRect(Vec2(100, 100), Vec2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
Entity mesh("mesh", game.SDLRenderer, PolyDrawType::DRAW_LINES);
mesh.SetDrawColour(Vec4(255, 244, 111, 255));
mesh.AddVecPoint(Vec4(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
mesh.AddVecPoint(Vec4(SCREEN_WIDTH, 0, 0, SCREEN_HEIGHT));
Sprite sans("sans", game.SDLRenderer, SpriteType::SPRITE_ANIMATED);
@@ -19,7 +32,6 @@ int main(int argc, char** argv) {
game.PollEvents();
if (timer.GetTimeElapsed() >= game.TargetMsPerUpdate) {
std::cout << timer.GetTimeElapsed() << std::endl;
// game logic
@@ -28,6 +40,9 @@ int main(int argc, char** argv) {
game.RenderClear();
game.RenderEntity(&mario);
game.RenderEntity(&box);
game.RenderEntity(&mesh);
game.RenderEntity(&boxOutline);
game.RenderUpdate();
}

View File

@@ -1 +0,0 @@
#include "mathHelper.h"

View File

@@ -2,12 +2,14 @@
#include "entity.h"
Renderer::Renderer(std::string title, int width, int height, int targetFramerate) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << "SDL could not initialize, SDL ERROR: " << SDL_GetError() << std::endl;
}
std::cout << "SDL initialized" << std::endl;
m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
std::cout << "SDL window created" << std::endl;
if (targetFramerate == 0)
SDLRenderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED);
if (targetFramerate == 1)