#pragma warning( disable : 4996 )
#include <cstdlib>
#include <vector>
#include <iostream>
#include <string>
#include "G2D.h"
using namespace std;
struct _Heros
{
string texture =
"[RRR ]"
"[RRWR ]"
"[RRR ]"
"[YY ]"
"[YYY ]"
"[YY YG]"
"[GG ]"
"[CC ]"
"[CC ]"
"[C C ]"
"[C C ]";
V2 Size;
int IdTex;
V2 Pos = V2(0,0);
void hero_deplacement()
{
//if (G2D::IsKeyPressed(Key::LEFT)) G.Heros.Pos.x--;
if (G2D::IsKeyPressed(Key::RIGHT)) G.Heros.Pos.x++;
if (G2D::IsKeyPressed(Key::UP)) G.Heros.Pos.y++;
//if (G2D::IsKeyPressed(Key::DOWN)) G.Heros.Pos.y--;
//if (G.Mur(G.Heros.Pos.x , G.Heros.Pos.y ) == true)
if(G.Heros.Pos.y*40<60)
{
if (G2D::IsKeyPressed(Key::LEFT)) G.Heros.Pos.x--;
if (G2D::IsKeyPressed(Key::RIGHT)) G.Heros.Pos.x++;
if (G2D::IsKeyPressed(Key::DOWN)) G.Heros.Pos.y--;
};
struct _Key
{
string texture =
"[ ]"
"[ W W WWWW ]"
"[ W W W W]"
"[ WWWWWWWWWWWWWW W]"
"[ W W]"
"[ WWWW ]";
V2 Size;
int IdTex;
V2 Pos = V2(440, 450);
};
struct GameData
{
string Map =
"MMMMMMMMMMMMMMM"
"M M M"
"M M M MMM MMM M"
"M M M M"
"MMM M M MMM M M"
"M M M M M"
"M MMM MMM MMMMM"
"M M M M"
"M M M M M MM M"
"M M M M M M M"
"M M M MM M MMMM"
"M M M M M"
"M M M MMMMMMM M"
"M M M M"
"MMMMMMMMMMMMMMM";
// indique la présence d'un mur à la case (x,y)
bool Mur(int x, int y) { return Map[(15 - y - 1)*15+x] == 'M'; }
int Lpix = 40; // largeur en pixels des cases du labyrinthe
_Heros Heros; // data du héros
_Key Key;
GameData() {}
};
GameData G;
void render()
{
G2D::ClearScreen(Color::Black);
for (int x = 0; x < 15; x++)
for (int y = 0; y < 15; y++)
{
int xx = x * G.Lpix;
int yy = y * G.Lpix;
if ( G.Mur(x,y))
G2D::DrawRectangle(V2(xx, yy), V2(G.Lpix, G.Lpix),
Color::Blue, true);
}
// affichage du héro avec boite englobante et zoom x 2
G2D::DrawRectangle(G.Heros.Pos, G.Heros.Size, Color::Red );
G2D::DrawRectWithTexture(G.Heros.IdTex, G.Heros.Pos, G.Heros.Size);
// affichage de la clef
G2D::DrawRectWithTexture(G.Key.IdTex, G.Key.Pos, G.Key.Size);
G2D::Show();
}
void Logic()
{
G.Heros.hero_deplacement();
void AssetsInit()
{
// Size passé en ref et texture en param
G.Heros.IdTex = G2D::InitTextureFromString(G.Heros.Size, G.Heros.texture);
G.Heros.Size = G.Heros.Size * 2; // on peut zoomer la taille du sprite
G.Key.IdTex = G2D::InitTextureFromString(G.Key.Size, G.Key.texture);
G.Key.Size = G.Key.Size * 1.5; // on peut zoomer la taille du sprite
int main(int argc, char* argv[])
{
G2D::InitWindow(argc,argv,V2(G.Lpix * 15, G.Lpix * 15), V2(200,200),
string("Labyrinthe"));
AssetsInit();
G2D::Run(Logic,render);