Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1544815447 | |||
4fdf62b6da |
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal file
@ -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)
|
BIN
Content/player.png
Normal file
BIN
Content/player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
40
demo-game-cna.cbp
Normal file
40
demo-game-cna.cbp
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="demo-game-cna" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/demo-game-cna" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/demo-game-cna" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="src/Game1.cpp" />
|
||||
<Unit filename="src/Game1.h" />
|
||||
<Unit filename="src/Main.cpp" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
20
demo-game-cna.layout
Normal file
20
demo-game-cna.layout
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="src/Game1.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="586" topLine="4" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/Game1.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1552" topLine="39" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/Main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
84
src/Game1.cpp
Normal file
84
src/Game1.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include "Game1.h"
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
Game1::Game1() {
|
||||
graphicsDevice = new CNA::GraphicsDevice();
|
||||
spriteBatch = new CNA::SpriteBatch(graphicsDevice);
|
||||
|
||||
|
||||
r = ((float)randint(255))/255.0f;
|
||||
g = ((float)(randint(255)))/255.0f;
|
||||
b = ((float)(randint(255)))/255.0f;
|
||||
}
|
||||
|
||||
int Game1::randint() {return rand();}
|
||||
int Game1::randint(int max) {return randint()%max;}
|
||||
|
||||
Game1::~Game1() {
|
||||
delete spriteBatch;
|
||||
delete graphicsDevice;
|
||||
}
|
||||
void Game1::LoadContent() {
|
||||
playerTexture = LoadTexture("Content/player.png");
|
||||
if (playerTexture == nullptr) {
|
||||
std::cerr << "Unable to create texture: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
playerX = 100;
|
||||
playerY = 100;
|
||||
}
|
||||
|
||||
void Game1::Update(float deltaTime) {
|
||||
playerX += xs * 100 * deltaTime; // Player's move
|
||||
playerY += ys * 100 * deltaTime; // Player's move
|
||||
if(playerX<0 || playerX > 800)xs=xs*(-1);
|
||||
if(playerY<0 || playerY > 600)ys=ys*(-1);
|
||||
}
|
||||
|
||||
void Game1::Draw() {
|
||||
spriteBatch->Begin(); // Starts rendering
|
||||
/*
|
||||
float r_ = ((float)(rand()%10)) /255.0f ;
|
||||
float g_ = ((float)(rand()%10)) /255.0f ;
|
||||
float b_ = ((float)(rand()%10)) /255.0f ;
|
||||
|
||||
bool rs = (rand() % 100) > 50;
|
||||
bool gs = (rand() % 100) > 50;
|
||||
bool 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>1.0f)r=1.0f;
|
||||
if(g>1.0f)g=1.0f;
|
||||
if(b>1.0f)b=1.0f;
|
||||
*/
|
||||
/*
|
||||
if(randint(1000)>990){r=1.0f;g=0.0f;b=0.0f;}
|
||||
if(randint(1000)>990){g=0.0f;g=1.0f;b=0.0f;}
|
||||
if(randint(1000)>990){b=0.0f;g=0.0f;b=1.0f;}
|
||||
*/
|
||||
|
||||
std::cout<<" "<<r<<" "<<g<<" "<<b;
|
||||
|
||||
|
||||
graphicsDevice->Clear(r,g,b,0.5f);
|
||||
//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());
|
||||
}
|
||||
|
40
src/Game1.h
Normal file
40
src/Game1.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef GAME1_H
|
||||
#define GAME1_H
|
||||
|
||||
#include "CNA/Game.h"
|
||||
#include "CNA/Texture2D.h"
|
||||
#include "CNA/GraphicsDevice.h"
|
||||
#include "CNA/SpriteBatch.h"
|
||||
#include <string>
|
||||
|
||||
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:
|
||||
|
||||
int randint();
|
||||
int randint(int max);
|
||||
//CNA::Texture2D* playerTexture;
|
||||
SDL_Texture* playerTexture;
|
||||
float playerX;
|
||||
float playerY;
|
||||
int xs=1;
|
||||
int ys=1;
|
||||
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
|
||||
protected:
|
||||
CNA::GraphicsDevice* graphicsDevice;
|
||||
CNA::SpriteBatch* spriteBatch;
|
||||
};
|
||||
|
||||
#endif // GAME1_H
|
9
src/Main.cpp
Normal file
9
src/Main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "Game1.h"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::cout<<"Starting game" <<std::endl;
|
||||
Game1 game;
|
||||
game.Run(); // Launching of the game.
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user