Skip to content
Snippets Groups Projects
Commit c8613276 authored by JOLY Clement's avatar JOLY Clement
Browse files

Nouvelles modifications de quelques parties

parent 5f41c0e9
Branches
Tags
No related merge requests found
assets/Double Jump (32x32).png

1.82 KiB

assets/Hit (32x32).png

1.59 KiB

assets/Wall Jump (32x32).png

902 B

...@@ -31,9 +31,6 @@ private: ...@@ -31,9 +31,6 @@ private:
float m_JumpTime; float m_JumpTime;
float m_JumpForce; float m_JumpForce;
//int m_Row, m_Frame, m_FrameCount;
//int m_AnimSpeed;
Animation* m_Animation; Animation* m_Animation;
RigidBody* m_RigidBody; RigidBody* m_RigidBody;
Vector2D m_LastSafePosition; Vector2D m_LastSafePosition;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "Character.h" #include "Character.h"
#include "Animation.h" #include "Animation.h"
//#include "RigidBody.h"
#include "Collider.h" #include "Collider.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "SDL.h" #include "SDL.h"
...@@ -36,4 +35,4 @@ private: ...@@ -36,4 +35,4 @@ private:
}; };
#endif // !WATER_H #endif // !WATER_H
\ No newline at end of file
#pragma warning (disable: 26812) //This warning is not important #pragma warning (disable: 26812)
#pragma warning (disable: 6282) //This warning is not important #pragma warning (disable: 6282)
#include "Engine.h" #include "Engine.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "TextureManager.h" #include "TextureManager.h"
//#include "Vector2D.h"
#include "Transform.h" #include "Transform.h"
#include "Warrior.h" #include "Warrior.h"
#include "Input.h" #include "Input.h"
...@@ -19,17 +18,17 @@ ...@@ -19,17 +18,17 @@
Warrior* player = nullptr; Warrior* player = nullptr;
Water* water = nullptr; Water* water = nullptr;
Engine* Engine::s_Instance = nullptr; Engine* Engine::s_Instance = nullptr;
std::string fileDirAssetsTree = "../assets/tree.png"; //Here you will put the directory where the "assets" folder is located std::string fileDirAssetsTree = "../assets/tree.png";
std::string fileDirAssetsPlayer = "../assets/Idle (32x32).png"; //Here you will put the directory where the "assets" folder is located std::string fileDirAssetsPlayer = "../assets/Idle (32x32).png";
std::string fileDirAssetsPlayerRun = "../assets/Run (32x32).png"; //Here you will put the directory where the "assets" folder is located std::string fileDirAssetsPlayerRun = "../assets/Run (32x32).png";
std::string fileDirAssetsPlayerJump = "../assets/Jump (32x32).png"; //Here you will put the directory where the "assets" folder is located std::string fileDirAssetsPlayerJump = "../assets/Jump (32x32).png";
std::string fileDirAssetsWater = "../assets/water.png"; //Here you will put the directory where the "assets" folder is located std::string fileDirAssetsWater = "../assets/water.png";
std::string bg = "../assets/Images/bg.jpg"; //Here you will put the directory where the "assets" folder is located std::string bg = "../assets/Images/bg.jpg";
const char* font = "../assets/Fonts/arial.ttf"; //Here you will put the directory where the "assets" folder is located const char* font = "../assets/Fonts/arial.ttf";
//Window name can be changed here
const char* window_Name = "SDL_GAME"; // This variable const char contains a pointer to convert char 'a' to string "a"; const char* window_Name = "SDL_GAME";
//The function SDL_CreateWindow need the const char* value in the first parameter
int frameCount, timerFPS, lastFrame, fps; int frameCount, timerFPS, lastFrame, fps;
...@@ -42,8 +41,7 @@ bool Engine::Init() ...@@ -42,8 +41,7 @@ bool Engine::Init()
SDL_Log("Failed to initialize SDL: %s", SDL_GetError()); SDL_Log("Failed to initialize SDL: %s", SDL_GetError());
return false; return false;
} }
//The "flag" in a window will tell you whether or not it is activated.
///Window name in first parameter in function SDL_CreateWindow(windowName, WindowPositionX, WindowPositionY, ScreenWidht, ScreenHeight, flag);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
m_Window = SDL_CreateWindow(window_Name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, window_flags); m_Window = SDL_CreateWindow(window_Name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, window_flags);
if (m_Window == nullptr) if (m_Window == nullptr)
...@@ -51,9 +49,7 @@ bool Engine::Init() ...@@ -51,9 +49,7 @@ bool Engine::Init()
SDL_Log("Failed to create Window: %s", SDL_GetError()); SDL_Log("Failed to create Window: %s", SDL_GetError());
return false; return false;
} }
///The SDL_CreateRenderer function needs a variable of type SDL_Window *window,
///an index so that the system can give instructions to the gpu of what should be drawn and a variable of type Uint32,
///this variable will set how the gpu should render the content
m_Renderer = SDL_CreateRenderer(m_Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); m_Renderer = SDL_CreateRenderer(m_Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (m_Renderer == nullptr) if (m_Renderer == nullptr)
...@@ -73,22 +69,14 @@ bool Engine::Init() ...@@ -73,22 +69,14 @@ bool Engine::Init()
return false; return false;
} }
//Vector2D v1(1, 1), v2(1, 1), v3;
//v3 = v1 + v2;
//v3.Log("V3: ");
//tf.Log();
if (!MapParser::GetInstance()->Load()) if (!MapParser::GetInstance()->Load())
{ {
std::cout << "Failed to Load map" << std::endl; std::cout << "Failed to Load map" << std::endl;
} }
m_LevelMap = MapParser::GetInstance()->GetMap("map"); m_LevelMap = MapParser::GetInstance()->GetMap("map");
//m_LevelMap1 = MapParser::GetInstance()->GetMap("map1");
//TextureManager::GetInstance()->Load("tree", fileDirAssetsTree);
///Load assets ///Load assets
TextureManager::GetInstance()->Load("player", fileDirAssetsPlayer); TextureManager::GetInstance()->Load("player", fileDirAssetsPlayer);
...@@ -129,8 +117,6 @@ void Engine::Quit() ...@@ -129,8 +117,6 @@ void Engine::Quit()
m_IsRunning = false; m_IsRunning = false;
} }
//The GetKeyDown() function receives as a parameter a variable of the SDL_Scancode type,
//all keyboard keys are already defined in the "Definitions.h" file, just pass the desired key in the parameter and that's it
void Engine::Update() void Engine::Update()
...@@ -160,7 +146,7 @@ void Engine::Update() ...@@ -160,7 +146,7 @@ void Engine::Update()
float initialposX = 50; float initialposX = 50;
float initialposY = 388; float initialposY = 388;
float nextPosX = 2580; float nextPosX = 2580;
//DebugInputs();
//Update the objects //Update the objects
water->Update(0); water->Update(0);
...@@ -168,7 +154,6 @@ void Engine::Update() ...@@ -168,7 +154,6 @@ void Engine::Update()
player->Update(dt); player->Update(dt);
//player->IntersectsWith(water->box);
//Clear console //Clear console
if (Input::GetInstance()->GetKeyDown(DEL)) if (Input::GetInstance()->GetKeyDown(DEL))
...@@ -183,10 +168,6 @@ void Engine::Update() ...@@ -183,10 +168,6 @@ void Engine::Update()
if (player->Reset) if (player->Reset)
{ {
player = new Warrior(new Properties("player", initialposX, initialposY, 32, 60)); player = new Warrior(new Properties("player", initialposX, initialposY, 32, 60));
//player->positionRect.x = 2530;
//player->positionRect.y = 388;
//player->Update(dt);
//player->Draw();
Camera::GetInstance()->SetTarget(player->GetOrigin()); Camera::GetInstance()->SetTarget(player->GetOrigin());
} }
...@@ -194,16 +175,9 @@ void Engine::Update() ...@@ -194,16 +175,9 @@ void Engine::Update()
if (player->Next) if (player->Next)
{ {
player = new Warrior(new Properties("player", nextPosX, initialposY, 32, 60)); player = new Warrior(new Properties("player", nextPosX, initialposY, 32, 60));
//player->positionRect.x = 2530;
//player->positionRect.y = 388;
//player->Update(dt);
//player->Draw();
Camera::GetInstance()->SetTarget(player->GetOrigin()); Camera::GetInstance()->SetTarget(player->GetOrigin());
} }
//SDL_Log("Update is Called now !!!");
//SDL_Log("%f", Timer::GetInstance()->GetDeltaTime());
Camera::GetInstance()->Update(dt); Camera::GetInstance()->Update(dt);
} }
...@@ -320,9 +294,8 @@ void Engine::Render() ...@@ -320,9 +294,8 @@ void Engine::Render()
{ {
//Render //Render
setColor(Color::Cian); setColor(Color::Cian);
SDL_RenderClear(m_Renderer); //Here the buffers will be updated before the new color is redrawn, SDL_RenderClear(m_Renderer);
//if the buffers are not updated gpu will just render black which is the primary null color,
//as it has not received instructions from the processor to update the buffer
TextureManager::GetInstance()->Draw("bg", 0, -100, 3840, 2400); TextureManager::GetInstance()->Draw("bg", 0, -100, 3840, 2400);
frameCount++; frameCount++;
...@@ -334,7 +307,6 @@ void Engine::Render() ...@@ -334,7 +307,6 @@ void Engine::Render()
SDL_RenderCopy(m_Renderer, text, NULL, &localText); SDL_RenderCopy(m_Renderer, text, NULL, &localText);
//TextureManager::GetInstance()->Draw("tree", 10, 80, 347, 465);
m_LevelMap->Render(); m_LevelMap->Render();
water->Draw(); water->Draw();
player->Draw(); player->Draw();
......
...@@ -3,20 +3,16 @@ ...@@ -3,20 +3,16 @@
MapParser* MapParser::s_Instance = nullptr; MapParser* MapParser::s_Instance = nullptr;
//std::string fileDir = "/home/tarek/Documents/jeu/assets/Maps/map.tmx"; //Here you will put the directory where the "assets/Maps" folder is located
bool MapParser::Load() bool MapParser::Load()
{ {
//if (!Parse("level1", "D:/C++BGAME/Game/GameSDL/assets/Maps/map.tmx")){ return false; } return true;
return Parse("map", "../assets/Maps/map.tmx"); return Parse("map", "../assets/Maps/map.tmx");
} }
bool MapParser::Load1() bool MapParser::Load1()
{ {
//if (!Parse("level1", "D:/C++BGAME/Game/GameSDL/assets/Maps/map.tmx")){ return false; } return true;
return Parse("map1", "../assets/Maps/map1.tmx"); return Parse("map1", "../assets/Maps/map1.tmx");
} }
......
#pragma warning (disable: 26812) //This warning is not important #pragma warning (disable: 26812)
#pragma warning (disable: 4838) //This warning is not important #pragma warning (disable: 4838)
#pragma warning (disable: 4244) //This warning is not important #pragma warning (disable: 4244)
#include "TextureManager.h" #include "TextureManager.h"
#include "Engine.h" #include "Engine.h"
#include "Camera.h" #include "Camera.h"
......
...@@ -3,20 +3,11 @@ ...@@ -3,20 +3,11 @@
#include "TextureManager.h" #include "TextureManager.h"
/// ATTEND THE DIRECTORY ///
TileLayer::TileLayer(int tilesize, int rowcount, int colcount, TileMap tilemap, TilesetList tilesets) : m_TileSize(tilesize), m_ColCount(colcount), TileLayer::TileLayer(int tilesize, int rowcount, int colcount, TileMap tilemap, TilesetList tilesets) : m_TileSize(tilesize), m_ColCount(colcount),
m_RowCount(rowcount), m_Tilemap(tilemap), m_Tilesets(tilesets) m_RowCount(rowcount), m_Tilemap(tilemap), m_Tilesets(tilesets)
{ {
//m_Tilesets = tilesets;
//m_RowCount = rowcount;
//m_ColCount = colcount;
//m_Tilemap = tilemap;
//m_Tilesets = tilesets;
for ( int i = 0; i < m_Tilesets.size(); i++) for ( int i = 0; i < m_Tilesets.size(); i++)
{ // {
TextureManager::GetInstance()->Load(m_Tilesets[i].Name, "../assets/Maps/" + m_Tilesets[i].Source); TextureManager::GetInstance()->Load(m_Tilesets[i].Name, "../assets/Maps/" + m_Tilesets[i].Source);
} }
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "Camera.h" #include "Camera.h"
#include "Water.h" #include "Water.h"
#include <iostream> #include <iostream>
//#include "Input.h"
SDL_RendererFlip flipNone = SDL_FLIP_NONE; SDL_RendererFlip flipNone = SDL_FLIP_NONE;
SDL_RendererFlip flipVertical = SDL_FLIP_VERTICAL; SDL_RendererFlip flipVertical = SDL_FLIP_VERTICAL;
...@@ -20,10 +19,6 @@ Water* water0 = nullptr; ...@@ -20,10 +19,6 @@ Water* water0 = nullptr;
//Set the properties of player //Set the properties of player
Warrior::Warrior(Properties* props) : Character(props) Warrior::Warrior(Properties* props) : Character(props)
{ {
//m_Row = 1;
//m_FrameCount = 9;
//m_AnimSpeed = 65;
m_JumpTime = JUMP_TIME; m_JumpTime = JUMP_TIME;
m_JumpForce = JUMP_FORCE; m_JumpForce = JUMP_FORCE;
...@@ -55,8 +50,6 @@ void Warrior::Draw() ...@@ -55,8 +50,6 @@ void Warrior::Draw()
void Warrior::Update(float dt) void Warrior::Update(float dt)
{ {
//m_Frame = (SDL_GetTicks() / m_AnimSpeed) % m_FrameCount;
m_Animation->SetProps("player", 1, 11, 40, flipNone); m_Animation->SetProps("player", 1, 11, 40, flipNone);
m_RigidBody->UnSetForce(); m_RigidBody->UnSetForce();
...@@ -95,12 +88,9 @@ void Warrior::Update(float dt) ...@@ -95,12 +88,9 @@ void Warrior::Update(float dt)
//Move on X axis //Move on X axis
//SDL_Log("%f",dt);
m_RigidBody->Update(dt); m_RigidBody->Update(dt);
m_LastSafePosition.X = m_Transform->X; m_LastSafePosition.X = m_Transform->X;
m_Transform->X += m_RigidBody->Position().X; m_Transform->X += m_RigidBody->Position().X;
//m_Transform->TranslateX(m_RigidBody->Position().X);
//m_Transform->TranslateY(m_RigidBody->Position().Y);
m_Collider->Set(m_Transform->X, m_Transform->Y, 30, 50); m_Collider->Set(m_Transform->X, m_Transform->Y, 30, 50);
if (CollisionHandler::GetIstance()->MapCollision(m_Collider->Get())) if (CollisionHandler::GetIstance()->MapCollision(m_Collider->Get()))
......
...@@ -50,8 +50,6 @@ void Water::Draw() ...@@ -50,8 +50,6 @@ void Water::Draw()
box = m_Collider->Get(); box = m_Collider->Get();
box.x -= cam.X; box.x -= cam.X;
box.y -= cam.Y; box.y -= cam.Y;
//SDL_RenderDrawRect(Engine::GetInstance()->GetRenderer(), &box);
} }
bool Water::IntersectsWith(SDL_Rect a) bool Water::IntersectsWith(SDL_Rect a)
...@@ -90,21 +88,4 @@ bool Water::IntersectsWith0(SDL_Rect a) ...@@ -90,21 +88,4 @@ bool Water::IntersectsWith0(SDL_Rect a)
void Water::Clean() void Water::Clean()
{ {
TextureManager::GetInstance()->Drop(m_TextureID); TextureManager::GetInstance()->Drop(m_TextureID);
} }
\ No newline at end of file
/*
*
* if (m_Collider->Get().x + X < a.x || m_Collider->Get().x > a.x + a.w || m_Collider->Get().y + Y < a.y ||
m_Collider->Get().y > a.y + a.h)
{
return true;
}
else
{
return false;
}
m_Collider->Get().y + Y < a.y || m_Collider->Get().y > a.y + a.h
m_Collider->Get().x + X < a.x || m_Collider->Get().x > a.x + a.w
*
*/
\ No newline at end of file
//This is where the magic happens
#include "Engine.h" #include "Engine.h"
#include "Timer.h" #include "Timer.h"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#undef main #undef main
#include <iostream> #include <iostream>
//don't do this, this is just an example
SDL_Renderer* renderer; SDL_Renderer* renderer;
SDL_Window* window; SDL_Window* window;
bool isRunning; bool isRunning;
...@@ -71,7 +70,6 @@ void setColor(int color) ...@@ -71,7 +70,6 @@ void setColor(int color)
} }
} }
//please don't put all your code in main like I did.
int aux() { int aux() {
fullscreen = false; fullscreen = false;
int flags = 0; int flags = 0;
...@@ -103,18 +101,15 @@ int aux() { ...@@ -103,18 +101,15 @@ int aux() {
render(); render();
} }
//frees memory associated with renderer and window
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); //error here SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }
//handles any events that SDL noticed.
void handleEvents() { void handleEvents() {
//the only event we'll check is the SDL_QUIT event.
SDL_Event event; SDL_Event event;
SDL_PollEvent(&event); SDL_PollEvent(&event);
...@@ -128,16 +123,14 @@ void handleEvents() { ...@@ -128,16 +123,14 @@ void handleEvents() {
} }
} }
//simple render function
void render() { void render() {
setColor(color::Red); setColor(color::Red);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
//your stuff to render would typically go here.
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
//simple update function
void update() { void update() {
//if things could update the code would go in here.
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment