diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7b1d33f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.10) +project(DEMOGAMECNA) + +set(CMAKE_CXX_STANDARD 17) + +add_subdirectory(../cna CNA) +include_directories(../cna/include CNA) + +add_executable(DEMOGAMECNA + src/Main.cpp + src/Game1.cpp +) + +find_package(SDL3 REQUIRED) +find_package(SDL3_image REQUIRED) + +target_link_libraries(DEMOGAMECNA PRIVATE CNA SDL3::SDL3) diff --git a/Content/player.png b/Content/player.png new file mode 100644 index 0000000..370a878 Binary files /dev/null and b/Content/player.png differ diff --git a/demo-game-cna.cbp b/demo-game-cna.cbp new file mode 100644 index 0000000..901a474 --- /dev/null +++ b/demo-game-cna.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/demo-game-cna.layout b/demo-game-cna.layout new file mode 100644 index 0000000..593c06e --- /dev/null +++ b/demo-game-cna.layout @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Game1.cpp b/src/Game1.cpp new file mode 100644 index 0000000..454a8df --- /dev/null +++ b/src/Game1.cpp @@ -0,0 +1,63 @@ +#include "Game1.h" +#include + +#include + +Game1::Game1() { + graphicsDevice = new CNA::GraphicsDevice(); + spriteBatch = new CNA::SpriteBatch(graphicsDevice); + } + +Game1::~Game1() { + delete spriteBatch; + delete graphicsDevice; +} +void Game1::LoadContent() { + playerTexture = LoadTexture("Content/player.png"); + playerX = 100; + playerY = 100; +} + +void Game1::Update(float deltaTime) { + playerX += 100 * deltaTime; // Player's move +} + + private float r = ((float)(rand()%255)) /255.0f ; + private float g = ((float)(rand()%255)) /255.0f ; + private float b = ((float)(rand()%255)) /255.0f ; +void Game1::Draw() { + spriteBatch->Begin(); // Starts rendering + + float r_ = ((float)(rand()%255)) /32.0f ; + float g_ = ((float)(rand()%255)) /32.0f ; + float b_ = ((float)(rand()%255)) /32.0f ; + + boolean rs = ()rand() % 100) > 50; + boolean gs = ()rand() % 100) > 50; + boolean bs = ()rand() % 100) > 50; + if(rs)r_=r_*(-1); + if(rs)g_=g_*(-1); + if(rs)b_=b_*(-1); + r=r+r_; + g=g+g_; + b=b+b_; + + if(r<0.0f)r=0.0f; + if(g<0.0f)g=0.0f; + if(b<0.0f)b=0.0f; + if(r>0.0f)r=1.0f; + if(g>0.0f)g=1.0f; + if(b>0.0f)b=1.0f; + + + graphicsDevice->Clear(r,g,b,120.0f); + graphicsDevice->Present(); + spriteBatch->Draw(playerTexture, playerX, playerY); + + spriteBatch->End(); // Stops rendering +} + +SDL_Texture* Game1::LoadTexture(const std::string& path) { + return IMG_LoadTexture(graphicsDevice->GetRenderer(), path.c_str()); +} + diff --git a/src/Game1.h b/src/Game1.h new file mode 100644 index 0000000..06de91f --- /dev/null +++ b/src/Game1.h @@ -0,0 +1,31 @@ +#ifndef GAME1_H +#define GAME1_H + +#include "CNA/Game.h" +#include "CNA/Texture2D.h" +#include "CNA/GraphicsDevice.h" +#include "CNA/SpriteBatch.h" +#include + +class Game1 : public CNA::Game { +public: + Game1(); + virtual ~Game1(); + void LoadContent() override; + void Update(float deltaTime) override; + void Draw() override; + + SDL_Texture* LoadTexture(const std::string& path); + +private: + //CNA::Texture2D* playerTexture; + SDL_Texture* playerTexture; + float playerX; + float playerY; + +protected: + CNA::GraphicsDevice* graphicsDevice; + CNA::SpriteBatch* spriteBatch; +}; + +#endif // GAME1_H diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..65e8020 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,9 @@ +#include "Game1.h" +#include + +int main(int argc, char* argv[]) { + std::cout<<"Starting game" <