Changes
This commit is contained in:
parent
4fdf62b6da
commit
1544815447
Binary file not shown.
Before Width: | Height: | Size: 635 KiB After Width: | Height: | Size: 12 KiB |
@ -32,6 +32,8 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="src/Game1.cpp" />
|
||||
<Unit filename="src/Game1.h" />
|
||||
<Unit filename="src/Main.cpp" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
|
@ -2,4 +2,19 @@
|
||||
<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>
|
||||
|
@ -2,39 +2,52 @@
|
||||
#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 += 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<<" "<<r<<" "<<g<<" "<<b;
|
||||
|
||||
|
||||
graphicsDevice->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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user