diff --git a/Content/player.png b/Content/player.png index 370a878..3199bf8 100644 Binary files a/Content/player.png and b/Content/player.png differ diff --git a/demo-game-cna.cbp b/demo-game-cna.cbp index 901a474..03614d0 100644 --- a/demo-game-cna.cbp +++ b/demo-game-cna.cbp @@ -32,6 +32,8 @@ + + diff --git a/demo-game-cna.layout b/demo-game-cna.layout index 593c06e..70ac774 100644 --- a/demo-game-cna.layout +++ b/demo-game-cna.layout @@ -2,4 +2,19 @@ + + + + + + + + + + + + + + + diff --git a/src/Game1.cpp b/src/Game1.cpp index 454a8df..3f7d5a4 100644 --- a/src/Game1.cpp +++ b/src/Game1.cpp @@ -2,39 +2,52 @@ #include #include +#include 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 += 100 * deltaTime; // Player's move + 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); } - 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()%10)) /255.0f ; + float g_ = ((float)(rand()%10)) /255.0f ; + float b_ = ((float)(rand()%10)) /255.0f ; - 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; + 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); @@ -45,13 +58,21 @@ void Game1::Draw() { 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; + 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<<" "<Clear(r,g,b,120.0f); - graphicsDevice->Present(); + graphicsDevice->Clear(r,g,b,0.5f); + //graphicsDevice->Present(); spriteBatch->Draw(playerTexture, playerX, playerY); spriteBatch->End(); // Stops rendering diff --git a/src/Game1.h b/src/Game1.h index 06de91f..d19e206 100644 --- a/src/Game1.h +++ b/src/Game1.h @@ -18,10 +18,19 @@ public: 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;