From 9173d3a18f665c6a028d449767acb7dca4197e2e Mon Sep 17 00:00:00 2001 From: Fife Date: Sat, 30 Apr 2016 13:47:44 +0200 Subject: [PATCH] First commit --- GUI.cpp | 73 +++++++++++++++++++ GUI.hpp | 30 ++++++++ Sprite.hpp | 139 ++++++++++++++++++++++++++++++++++++ control.cpp | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++ control.hpp | 27 +++++++ iaghost1.cpp | 123 ++++++++++++++++++++++++++++++++ iaghost1.hpp | 24 +++++++ iaghost2.cpp | 105 +++++++++++++++++++++++++++ iaghost2.hpp | 22 ++++++ pacman.cpp | 152 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 893 insertions(+) create mode 100644 GUI.cpp create mode 100644 GUI.hpp create mode 100644 Sprite.hpp create mode 100644 control.cpp create mode 100644 control.hpp create mode 100644 iaghost1.cpp create mode 100644 iaghost1.hpp create mode 100644 iaghost2.cpp create mode 100644 iaghost2.hpp create mode 100644 pacman.cpp diff --git a/GUI.cpp b/GUI.cpp new file mode 100644 index 0000000..3c01c48 --- /dev/null +++ b/GUI.cpp @@ -0,0 +1,73 @@ + +#include "GUI.hpp" + +extern "C" +{ +#include +} + +void Script_GUI::Start() +{ + + vie = 3; + score = 0; + level = 1; + vulnerability = 0; + +} + +void Script_GUI::UpdateEverySecond() +{ + if(vulnerability > 0)vulnerability --; + else vulnerability = 0; +} + +void Script_GUI::Update() +{ + const unsigned char svie[]={0x6d, 0x93, 0x83, 0x45, 0x29, 0x11, }; + + ML_rectangle(105,0,127,63,1,ML_WHITE,ML_WHITE); + ML_line(104,0,104,63,ML_BLACK); + + PrintMini(107,7,"Score",0); + PrintV(107,15,score); + + if(vie > 0)ML_bmp_or(svie,105,30,7,6); + if(vie > 1)ML_bmp_or(svie,113,30,7,6); + if(vie > 2)ML_bmp_or_cl(svie,121,30,7,6); + + PrintMini(107,47,"Level",0); + PrintV(115,55,level); + +} + + +void Script_GUI::DelVie(int v) +{ + if(v < 0)return; + vie -= v; + + if(vie <= 0) + { + ML_clear_vram(); + PrintXY(25,28,"You Lose",0); + ML_display_vram(); + Sleep(1500); + GetEngine()->StopGame(); + } +} + +void Script_GUI::AddScore(int v) +{ + if(v > 0)score += v; +} + +void Script_GUI::SetVulnerability(int v) +{ + if( v > 0)vulnerability = v; +} + +int Script_GUI::GetVulnerability() +{ + return vulnerability; +} diff --git a/GUI.hpp b/GUI.hpp new file mode 100644 index 0000000..8e16a33 --- /dev/null +++ b/GUI.hpp @@ -0,0 +1,30 @@ +#ifndef GUI +#define GUI + +#include "..\C-Engine\CHeader.hpp" + +class Script_GUI: public Script +{ + public: + + void Start(); + void Update(); + void UpdateEverySecond(); + + void DelVie(int v); + void AddScore(int v); + + void SetVulnerability(int v); + int GetVulnerability(); + + private: + + int score;//Sc: 0 + int vie;//Nb de vie + int level; + int vulnerability; + +}; + + +#endif diff --git a/Sprite.hpp b/Sprite.hpp new file mode 100644 index 0000000..ce66368 --- /dev/null +++ b/Sprite.hpp @@ -0,0 +1,139 @@ + //********Pac Man***********// + + const unsigned char PM_1[]={0x7, 0xc1, 0x18, 0x31, 0x20, 0x9, 0x41, 0x85, 0x41, 0x85, 0x80, 0x3, 0x80, 0x3, 0x81, 0xff, 0x80, 0x3, 0x80, 0x3, 0x40, 0x5, 0x40, 0x5, 0x20, 0x9, 0x18, 0x31, 0x7, 0xc1, }; + const unsigned char PM_2[]={0x7, 0xc1, 0x18, 0x31, 0x20, 0x9, 0x41, 0x85, 0x41, 0x85, 0x80, 0x19, 0x80, 0x61, 0x81, 0x81, 0x80, 0x61, 0x80, 0x19, 0x40, 0x5, 0x40, 0x5, 0x20, 0x9, 0x18, 0x31, 0x7, 0xc1, }; + const unsigned char PM_3[]={0x7, 0xc1, 0x18, 0x31, 0x20, 0x9, 0x41, 0x91, 0x41, 0xa1, 0x80, 0x41, 0x80, 0x81, 0x81, 0x1, 0x80, 0x81, 0x80, 0x41, 0x40, 0x21, 0x40, 0x11, 0x20, 0x9, 0x18, 0x31, 0x7, 0xc1, }; + const unsigned char PM_4[]={0x7, 0x1, 0x19, 0x1, 0x21, 0x1, 0x41, 0x1, 0x41, 0x1, 0x81, 0x1, 0x81, 0x1, 0x81, 0x1, 0x81, 0x1, 0x81, 0x1, 0x41, 0x1, 0x41, 0x1, 0x21, 0x1, 0x19, 0x1, 0x7, 0x1, }; + const unsigned char PM_5[]={0x0, 0x1, 0x0, 0x1, 0x20, 0x1, 0x50, 0x1, 0x48, 0x1, 0x84, 0x1, 0x82, 0x1, 0x81, 0x1, 0x82, 0x1, 0x84, 0x1, 0x48, 0x1, 0x50, 0x1, 0x20, 0x1, 0x0, 0x1, 0x0, 0x1, }; + const unsigned char PM_6[]={0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x60, 0x1, 0x98, 0x1, 0x86, 0x1, 0x81, 0x1, 0x86, 0x1, 0x98, 0x1, 0x60, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, }; + + Sprite S_PacMan_1(PM_1,15,15); S_PacMan_1.CreateReverse(); + Sprite S_PacMan_2(PM_2,15,15); S_PacMan_2.CreateReverse(); + Sprite S_PacMan_3(PM_3,15,15); S_PacMan_3.CreateReverse(); + Sprite S_PacMan_4(PM_4,15,15); S_PacMan_4.CreateReverse(); + Sprite S_PacMan_5(PM_5,15,15); S_PacMan_5.CreateReverse(); + Sprite S_PacMan_6(PM_6,15,15); S_PacMan_6.CreateReverse(); + + Sprite S_PacMan[]={S_PacMan_1,S_PacMan_2,S_PacMan_3,S_PacMan_2}; + Sprite S_PM_Die[]={S_PacMan_1,S_PacMan_2,S_PacMan_3,S_PacMan_4,S_PacMan_5,S_PacMan_6}; + + Animation A_PM(S_PacMan , 4, 200); + Animation A_PM_Die(S_PM_Die , 6, 200); + + Animation A_PacMan[]={A_PM,A_PM_Die}; + + //************Ghost***************// + + const unsigned char G1[]={0xf, 0xe1, 0x1f, 0xf1, 0x3f, 0xf9, 0x7f, 0xfd, 0x6f, 0xbd, 0xef, 0xbf, 0xe3, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x99, 0x9b, 0x99, 0x9b, }; + + const unsigned char Afraid1[]={0xf, 0xe1, 0x1f, 0xf1, 0x3f, 0xf9, 0x7f, 0xfd, 0x73, 0xcd, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd3, 0x97, 0xcc, 0x67, 0xff, 0xff, 0xff, 0xff, 0x99, 0x9b, 0x99, 0x9b, }; + const unsigned char Afraid2[]={0xf, 0xe1, 0x1f, 0xf1, 0x3f, 0xf9, 0x7f, 0xfd, 0x73, 0xcd, 0xf3, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0x67, 0xd3, 0x97, 0xff, 0xff, 0xff, 0xff, 0x99, 0x9b, 0x99, 0x9b, }; + + Sprite S_Ghost(G1,15,15); + Animation A_GhostN(S_Ghost); + + Sprite S_Afraid1(Afraid1,15,15); + Sprite S_Afraid2(Afraid2,15,15); + Sprite S_Afraid[]={S_Afraid1,S_Afraid2}; + Animation A_GhostA(S_Afraid,2,200); + + Animation A_Ghost[]={A_GhostN,A_GhostA}; + + const unsigned char tileset[]={0x1f, 0x1f, 0x1f, 0xbf, 0xbf, 0xbf, 0xff, 0x1f, 0xff, 0x7f, 0x9f, 0xbf, 0xdf, 0x3f, 0xbf, 0xbf, 0x9f, 0x7f, 0xbf, 0x3f, 0xdf, 0x9f, 0x9f, 0x9f, 0x3f, 0x3f, 0x3f, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0x1f, 0x9f, 0x5f, 0x5f, 0x9f, 0x1f, 0x1f, 0x3f, 0x5f, 0x5f, 0x3f, 0x1f, 0x5f, 0xff, 0x5f, 0x7f, 0x9f, 0x9f, 0xdf, 0x3f, 0x3f, 0x9f, 0x9f, 0x7f, 0x3f, 0x3f, 0xdf, }; + + bool tileprop[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; + + unsigned char * level[]={ + "3222222222222222222222222222222222222229999222222222222222222222222222222222222224", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "100\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00700800\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "100\?00=99999999;00\?00=99999999999;00\?00700800\?00=99999999999;00\?00=99999999;00\?001", + "1000007000000008000007000000000008000007008000007000000000008000007000000008000001", + "100@A0700000000800000700000000000800000700800000700000000000800000700000000800@A01", + "100BC0700000000800\?00700000000000800\?00700800\?00700000000000800\?00700000000800BC01", + "1000007000000008000007000000000008000007008000007000000000008000007000000008000001", + "1000007000000008000007000000000008000007008000007000000000008000007000000008000001", + "100\?00>::::::::<00\?00>:::::::::::<00\?00>::<00\?00>:::::::::::<00\?00>::::::::<00\?001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "100\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "100\?00=99999999;00\?00=99;00\?00=99999999999999999999;00\?00=99;00\?00=99999999;00\?001", + "1000007000000008000007008000007000000000000000000008000007008000007000000008000001", + "1000007000000008000007008000007000000000000000000008000007008000007000000008000001", + "100\?00>::::::::<00\?00700800\?00>::::::::0000::::::::<00\?00700800\?00>::::::::<00\?001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "100\?00\?00\?00\?00\?00\?00700800\?00\?00\?00\?00700800\?00\?00\?00\?00700800\?00\?00\?00\?00\?00\?001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "522222222222222400\?00700099999999;00000>::<00000=99999999000800\?003222222222222226", + "0000000000000001000007000000000008000000000000007000000000008000001000000000000000", + "0000000000000001000007000000000008000000000000007000000000008000001000000000000000", + "000000000000000100\?007000::::::::<00000000000000>::::::::000800\?001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "000000000000000100\?00700800000000000000000000000000000000700800\?001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "000000000000000100\?00700800000322222220000002222222400000700800\?001000000000000000", + "0000000000000001000007008000001000000000000000000001000007008000001000000000000000", + "0000000000000001000007008000001000000000000000000001000007008000001000000000000000", + "222222222222222600\?00>::<00000100000000000000000000100000>::<00\?005222222222222222", + "0000000000000000000000000000001000000000000000000001000000000000000000000000000000", + "0000000000000000000000000000001000000000000000000001000000000000000000000000000000", + "000000000000000000\?00000000000100000000000000000000100000000000\?000000000000000000", + "0000000000000000000000000000001000000000000000000001000000000000000000000000000000", + "0000000000000000000000000000001000000000000000000001000000000000000000000000000000", + "222222222222222400\?00=99;00000100000000000000000000100000=99;00\?003222222222222222", + "0000000000000001000007008000001000000000000000000001000007008000001000000000000000", + "0000000000000001000007008000001000000000000000000001000007008000001000000000000000", + "000000000000000100\?00700800000522222222222222222222600000700800\?001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "000000000000000100\?00700800000000000000000000000000000000700800\?001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "0000000000000001000007008000000000000000000000000000000007008000001000000000000000", + "000000000000000100\?00700800000=99999999999999999999;00000700800\?001000000000000000", + "0000000000000001000007008000007000000000000000000008000007008000001000000000000000", + "0000000000000001000007008000007000000000000000000008000007008000001000000000000000", + "322222222222222600\?00>::<00000>::::::::0000::::::::<00000>::<00\?005222222222222224", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "100\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00700800\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "1000000000000000000000000000000000000007008000000000000000000000000000000000000001", + "100\?00=99999999;00\?00=99999999999;00\?00700800\?00=99999999999;00\?00=99999999;00\?001", + "1000007000000008000007000000000008000007008000007000000000008000007000000008000001", + "1000007000000008000007000000000008000007008000007000000000008000007000000008000001", + "100\?00>:::::000800\?00>:::::::::::<00\?00>::<00\?00>:::::::::::<00\?007000:::::<00\?001", + "1000000000007008000000000000000000000000000000000000000000000000007008000000000001", + "1000000000007008000000000000000000000000000000000000000000000000007008000000000001", + "10@A00\?00\?00700800\?00\?00\?00\?00\?00\?00\?00000000\?00\?00\?00\?00\?00\?00\?00700800\?00\?00@A01", + "10BC00000000700800000000000000000000000000000000000000000000000000700800000000BC01", + "1000000000007008000000000000000000000000000000000000000000000000007008000000000001", + "799999;00\?00700800\?00=99;00\?00=99999999999999999999;00\?00=99;00\?00700800\?00=999998", + "7000008000007008000007008000007000000000000000000008000007008000007008000007000008", + "7000008000007008000007008000007000000000000000000008000007008000007008000007000008", + "7:::::<00\?00>::<00\?00700800\?00>::::::::0000::::::::<00\?00700800\?00>::<00\?00>:::::8", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "100\?00\?00\?00\?00\?00\?00700800\?00\?00\?00\?00700800\?00\?00\?00\?00700800\?00\?00\?00\?00\?00\?001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "1000000000000000000007008000000000000007008000000000000007008000000000000000000001", + "100\?00=99999999999999000099999999;00\?00700800\?00=99999999000099999999999999;00\?001", + "1000007000000000000000000000000008000007008000007000000000000000000000000008000001", + "1000007000000000000000000000000008000007008000007000000000000000000000000008000001", + "100\?00>::::::::::::::::::::::::::<00\?00>::<00\?00>::::::::::::::::::::::::::<00\?001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "100\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?00\?001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "1000000000000000000000000000000000000000000000000000000000000000000000000000000001", + "5222222222222222222222222222222222222222222222222222222222222222222222222222222226", +}; + diff --git a/control.cpp b/control.cpp new file mode 100644 index 0000000..ea70360 --- /dev/null +++ b/control.cpp @@ -0,0 +1,198 @@ +#include "..\C-Engine\CHeader.hpp" +#include "control.hpp" + +char *str_remplace ( char *s, unsigned int x, const char *ct) +{ + char *new_s = NULL; + + if (s != NULL && ct != NULL && x >= 0) + { + size_t size = strlen (s); + + new_s = (char*)malloc (sizeof (*new_s) * (size + strlen (ct))); + if (new_s != NULL) + { + memcpy (new_s, s, x); + memcpy (&new_s[x], ct, strlen (ct)); + memcpy (&new_s[x + strlen (ct)], &s[x + 1], size - 1 - x + 1); + } + } + else return s; + + return new_s; +} + +void Control::Initialisation(Script_GUI * v) +{ + SGUI = v ; +} + +void Control::Start() +{ + direction = 0; + directionuser = 0; + objectif = 0; + + for( int i = 0; i < GetEngine()->GetMap()->nbtiles_largeur_monde; i++) + { + for( int j = 0 ; j < GetEngine()->GetMap()->nbtiles_hauteur_monde; j++) + { + + switch(GetEngine()->GetMap()->map[j][i] - '0') + { + case 15: case 16: objectif ++; break; + default: break; + } + } + } +} + +void Control::Update() +{ + + GetObject()->GetRender()->SetIt(0); + + switch(input_dir4()) + { + case 2: directionuser = 3; break; + case 4: directionuser = 4; break; + case 6: directionuser = 2; break; + case 8: directionuser = 1; break; + } + + + if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser; + + + switch(direction) + { + case 1: Move(0,1); GetObject()->GetRender()->SetDirection(90);GetObject()->GetRender()->ReverseRender(false); break; + case 2: Move(1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(false);break; + case 3: Move(0,-1); GetObject()->GetRender()->SetDirection(270); GetObject()->GetRender()->ReverseRender(false);break; + case 4: Move(-1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(true);break; + } + + int x , y; + + x = GetX()/3 + 2; + y = 91 - GetY()/3 - 3; + + switch(GetEngine()->GetMap()->map[y][x] - '0') + { + case 15 : + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); + SGUI->AddScore(200); + objectif--; + break; + case 16: + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x+1 , "0"); + GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x , "0"); + GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x+1 , "0"); + SGUI->AddScore(500); + SGUI->SetVulnerability(8); + objectif--; + break; + case 17: + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x-1 , "0"); + GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x , "0"); + GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x-1 , "0"); + SGUI->AddScore(500); + SGUI->SetVulnerability(8); + objectif--; + break; + case 18: + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x+1 , "0"); + GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x , "0"); + GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x+1 , "0"); + SGUI->AddScore(500); + SGUI->SetVulnerability(8); + objectif--; + break; + case 19: + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); + GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x-1 , "0"); + GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x , "0"); + GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x-1 , "0"); + SGUI->AddScore(500); + SGUI->SetVulnerability(8); + objectif--; + break; + + default: + break; + + } + + if(objectif <= 0) + { + ML_clear_vram(); + PrintXY(30,28,"You Win",0); + ML_display_vram(); + Sleep(1500); + GetEngine()->StopGame(); + } + + Object * Ennemi = GetObject()->CollisionTagO("Ghost"); + + if(Ennemi != NULL) + { + if(SGUI->GetVulnerability() <= 0)Die(); + else Ennemi->GetTransforms()->SetXY(116,131); + } + + if(GetObject()->CollisionTag("TP1")) + { + GetObject()->GetTransforms()->SetXY(229,138); + direction = 4; + } + + if(GetObject()->CollisionTag("TP2")) + { + GetObject()->GetTransforms()->SetXY(2,138); + direction = 2; + } + + if(input_trigger(K_EXIT))GetEngine()->StopGame(); + + GetEngine()->MiddleScreen(GetX() + 18 , GetY() + 8 ,false); +} + +void Control::Die() +{ + bool cinematic = true; + + GetObject()->GetRender()->SetIt(1); + + while(cinematic == true) + { + + ML_clear_vram(); + + GetEngine()->GetMap()->AfficherMap(); + GetObject()->GetRender()->DrawObject(); + + ML_display_vram(); + + if(GetObject()->GetRender()->GetisEnd())cinematic = false; + + Sleep(100); + } + + ML_clear_vram(); + + GetEngine()->GetMap()->AfficherMap(); + + ML_display_vram(); + + Sleep(250); + + GetObject()->GetRender()->SetIt(0); + + GetObject()->GetTransforms()->SetXY(116, 57); + + SGUI->DelVie(1); +} + diff --git a/control.hpp b/control.hpp new file mode 100644 index 0000000..d00aa29 --- /dev/null +++ b/control.hpp @@ -0,0 +1,27 @@ +#ifndef SCRIPTCONTROL +#define SCRIPTCONTROL + +#include"GUI.hpp" + +unsigned char * Modifier (unsigned char * line , int place , char valeur); + +class Control: public Script +{ + public: + + void Start(); + void Update(); + void Initialisation(Script_GUI * v); + void Die(); + + private : + + Script_GUI * SGUI; + + int direction; + int directionuser; + int objectif; +}; + +#endif // SCRIPTCONTROL + diff --git a/iaghost1.cpp b/iaghost1.cpp new file mode 100644 index 0000000..234167c --- /dev/null +++ b/iaghost1.cpp @@ -0,0 +1,123 @@ +#include "..\C-Engine\CHeader.hpp" +#include "GUI.hpp" +#include "iaghost1.hpp" + +void IA1::Start() +{ + + couldown=0; + direction=1; + directionuser=1; +} + +void IA1::UpdateEverySecond() +{ + + if (couldown==5) + { + directionuser = rand_int(4) + 1; + couldown=0; + } + + couldown++; + +} + +void IA1::Initialisation(Script_GUI * v) +{ + SGUI = v ; +} + +void IA1::Update() +{ + int hasard; + + if(SGUI->GetVulnerability() > 0)SetIt(1); + else SetIt(0); + + //Intersection// + + if(!(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) && !GetObject()->GetRigibody()->CollisionDecor(GetX() , GetY() - 1) &&!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) && !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY()))) + { + switch(direction) + { + case 1: + if(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) || !GetObject()->GetRigibody()->CollisionDecor(GetX() , GetY() - 1)) + { + hasard = rand_int(3) + 1; + switch(hasard) + { + case 1: directionuser = 1;break; + case 2: directionuser = 2;break; + case 3: directionuser = 4;break; + } + } + break; + case 2: + if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY())) + { + hasard = rand_int(3) + 1; + switch(hasard) + { + case 1: directionuser = 2;break; + case 2: directionuser = 1;break; + case 3: directionuser = 3;break; + } + } + break; + case 3: + if(!GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() + 1) || !GetObject()->GetRigibody()->CollisionDecor(GetX(), GetY() - 1)) + { + hasard = rand_int(3) + 1; + switch(hasard) + { + case 1: directionuser = 3;break; + case 2: directionuser = 2;break; + case 3: directionuser = 4;break; + } + } + break; + case 4: + if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + 1 , GetY()) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - 1 , GetY())) + { + hasard = rand_int(3) + 1; + switch(hasard) + { + case 1: directionuser = 4;break; + case 2: directionuser = 1;break; + case 3: directionuser = 3;break; + } + } + break; + } + } + + + //***********Deplacement***********// + + if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser; + + + switch(direction) + { + case 1: Move(0,1); break; + case 2: Move(1,0); break; + case 3: Move(0,-1); break; + case 4: Move(-1,0); break; + } + + //************// + + if(GetObject()->CollisionTag("TP1")) + { + GetObject()->GetTransforms()->SetXY(229,138); + direction = 4; + } + + if(GetObject()->CollisionTag("TP2")) + { + GetObject()->GetTransforms()->SetXY(2,138); + direction = 2; + } +} + diff --git a/iaghost1.hpp b/iaghost1.hpp new file mode 100644 index 0000000..478b203 --- /dev/null +++ b/iaghost1.hpp @@ -0,0 +1,24 @@ +#ifndef SCRIPTGHOST1 +#define SCRIPTGHOST1 +#include "GUI.hpp" + +class IA1: public Script +{ + public: + + void Start(); + void Update(); + void UpdateEverySecond(); + void Initialisation(Script_GUI * v); + + private : + + int couldown; + int direction; + int directionuser; + + Script_GUI * SGUI; +}; + +#endif // SCRIPTCONTROL + diff --git a/iaghost2.cpp b/iaghost2.cpp new file mode 100644 index 0000000..1b0815a --- /dev/null +++ b/iaghost2.cpp @@ -0,0 +1,105 @@ +#include "..\C-Engine\CHeader.hpp" +#include "GUI.hpp" +#include "iaghost2.hpp" + +void IA2::Start() +{ + direction=1; + directionuser=1; +} + +void IA2::Initialisation(Script_GUI * v) +{ + SGUI = v ; +} + +void IA2::Update() +{ + + if(SGUI->GetVulnerability() > 0)SetIt(1); + else SetIt(0); + + //Intersection// + + int difx = GetEngine()->GetListeObject()[0]->GetTransforms()->GetX() - GetX(); + int dify = GetEngine()->GetListeObject()[0]->GetTransforms()->GetY() - GetY(); + + if(!GetObject()->GetRigibody()->CollisionDecor(GetX() + (direction%2), GetY() + (!(direction%2))) || !GetObject()->GetRigibody()->CollisionDecor(GetX() - (direction%2), GetY() - (!(direction%2)))) + { + PrintMini(10,10,"Test",0); + + bool possibledirection[4]; + for(int i = 0; i < 4 ; i++)possibledirection[i] = !(GetObject()->GetRigibody()->CollisionDecor(GetX() + (i == 1) - (i == 3), GetY() + (i == 0) - (i == 2))); + + int betterdirection[4]; int best; + if(ABS(difx) > ABS(dify))best = 1; + else best = 2; + + if(difx == 0)best = 2; + if(dify == 0)best = 1; + + if(difx > 0) + { + betterdirection[ (best == 2)] = 2; + betterdirection[ 3 -(best == 2)] = 4; + } + else + { + betterdirection[ (best == 2)] = 4; + betterdirection[ 3 -(best == 2)] = 2; + } + + if(dify > 0) + { + betterdirection[ (best == 1)] = 1; + betterdirection[ 3 -(best == 1)] = 3; + } + else + { + betterdirection[ (best == 1)] = 3; + betterdirection[ 3 -(best == 1)] = 1; + } + + int end = 4; + while(end > 0) + { + if(possibledirection[betterdirection[4 - end] - 1]) + { + directionuser = betterdirection[4 - end]; + end = 0; + } + else end --; + } + } + + + + + //***********Deplacement***********// + + if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser; + + + switch(direction) + { + case 1: Move(0,1); break; + case 2: Move(1,0); break; + case 3: Move(0,-1); break; + case 4: Move(-1,0); break; + } + + //************// + + if(GetObject()->CollisionTag("TP1")) + { + GetObject()->GetTransforms()->SetXY(229,138); + direction = 4; + } + + if(GetObject()->CollisionTag("TP2")) + { + GetObject()->GetTransforms()->SetXY(2,138); + direction = 2; + } +} + diff --git a/iaghost2.hpp b/iaghost2.hpp new file mode 100644 index 0000000..1571eac --- /dev/null +++ b/iaghost2.hpp @@ -0,0 +1,22 @@ +#ifndef SCRIPTGHOST2 +#define SCRIPTGHOST2 +#include "GUI.hpp" + +class IA2: public Script +{ + public: + + void Start(); + void Update(); + void Initialisation(Script_GUI * v); + + private : + + int direction; + int directionuser; + + Script_GUI * SGUI; +}; + +#endif // SCRIPTCONTROL + diff --git a/pacman.cpp b/pacman.cpp new file mode 100644 index 0000000..e95edb2 --- /dev/null +++ b/pacman.cpp @@ -0,0 +1,152 @@ + +#include "..\C-Engine\CHeader.hpp" +#include "control.hpp" +#include "iaghost1.hpp" +#include "iaghost2.hpp" +#include "GUI.hpp" + +void SetDecor( Engine * Game); +int Jeu(); + +void Menu() +{ + const unsigned char smenu[]={0xff, 0x80, 0x20, 0x1, 0xf0, 0x0, 0x10, 0x8, 0x4, 0x2, 0xf, 0x80, 0xc0, 0x20, 0x6, 0xc, 0x0, 0x18, 0x18, 0x4, 0x3, 0x9, 0x80, 0x40, 0x50, 0x8, 0x2, 0x0, 0x14, 0x28, 0xa, 0x2, 0x89, 0x9e, 0x40, 0x50, 0x10, 0x64, 0x0, 0x12, 0x48, 0xa, 0x2, 0x49, 0x92, 0x40, 0x88, 0x10, 0x68, 0x0, 0x11, 0x88, 0x11, 0x2, 0x29, 0x9e, 0x40, 0x88, 0x20, 0x10, 0x0, 0x10, 0x8, 0x11, 0x2, 0x19, 0x80, 0x41, 0x4, 0x20, 0x20, 0x7f, 0x10, 0x8, 0x20, 0x82, 0x1, 0x80, 0xc1, 0x24, 0x20, 0x40, 0x41, 0x10, 0x8, 0x24, 0x82, 0x1, 0x9f, 0x82, 0x52, 0x20, 0x20, 0x7f, 0x10, 0x8, 0x4a, 0x42, 0x1, 0x90, 0x2, 0x72, 0x20, 0x10, 0x0, 0x11, 0x88, 0x4e, 0x42, 0x41, 0x90, 0x4, 0x1, 0x10, 0x8, 0x0, 0x12, 0x48, 0x80, 0x22, 0x61, 0x90, 0x4, 0x1, 0x10, 0x4, 0x0, 0x12, 0x48, 0x80, 0x22, 0x51, 0x90, 0x8, 0x70, 0x88, 0x2, 0x0, 0x12, 0x49, 0xe, 0x12, 0x49, 0x90, 0x8, 0x88, 0x86, 0xc, 0x0, 0x12, 0x49, 0x11, 0x12, 0x49, 0xf0, 0xf, 0x7, 0x81, 0xf0, 0x0, 0x1e, 0x79, 0xe0, 0xf3, 0xcf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf8, 0xf0, 0x0, 0x20, 0x1e, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x8, 0xc, 0x90, 0x0, 0x20, 0x11, 0x44, 0x0, 0x0, 0x0, 0x0, 0x8, 0x4, 0x90, 0x0, 0x50, 0x10, 0x88, 0x0, 0x0, 0x0, 0x0, 0x9, 0xe4, 0x90, 0x0, 0x50, 0x8, 0x88, 0x0, 0x0, 0x0, 0x0, 0x9, 0x24, 0x90, 0x0, 0x88, 0x8, 0x10, 0x0, 0x0, 0x0, 0x0, 0x9, 0xe4, 0x90, 0x0, 0x88, 0x4, 0x10, 0x0, 0x0, 0x0, 0x0, 0x8, 0x4, 0x90, 0x1, 0x4, 0x2, 0x20, 0x0, 0x0, 0x0, 0x0, 0x8, 0xc, 0x90, 0x1, 0x24, 0x2, 0x20, 0x0, 0x0, 0x0, 0x0, 0x9, 0xf8, 0x90, 0x2, 0x52, 0x4, 0x40, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x90, 0x2, 0x72, 0x4, 0x40, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x90, 0x4, 0x1, 0x8, 0x80, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x9f, 0xc4, 0x1, 0x8, 0x80, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x80, 0x48, 0x70, 0x91, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x80, 0x48, 0x88, 0x91, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0xff, 0xcf, 0x7, 0x9e, 0x0, 0x0, 0x0, }; + + while(input_press(K_EXE)){} + + while(!input_press(K_EXIT)) + { + + input_update(); + + ML_clear_vram(); + ML_bmp_or(smenu,20,14,88,36); + ML_display_vram(); + + if(input_trigger(K_SHIFT) || input_trigger(K_EXE))Jeu(); + } + +} + +int Jeu() +{ + #include "Sprite.hpp" // Inclusion des sprites. + + //*****************Creation des objects****************** + + Object * PacMan = new Object; + PacMan->GetTransforms()->SetXY( 116, 57); + PacMan->GetRender()->SetRender(A_PacMan,2); + PacMan->AddRigibody(); + PacMan->AffectTag("PacMan"); + + Control * Script_PacMan = new Control; + PacMan->AffectScript(Script_PacMan); + + + Object * Ghost1 = new Object; + Ghost1->GetTransforms()->SetXY( 99, 129); + Ghost1->GetRender()->SetRender(A_Ghost,2); + Ghost1->AddRigibody(); + Ghost1->AffectTag("Ghost"); + + Object * Ghost2 = new Object; + Ghost2->GetTransforms()->SetXY( 116, 129); + Ghost2->GetRender()->SetRender(A_Ghost,2); + Ghost2->AddRigibody(); + Ghost2->AffectTag("Ghost"); + + Object * Ghost3 = new Object; + Ghost3->GetTransforms()->SetXY( 133, 129); + Ghost3->GetRender()->SetRender(A_Ghost,2); + Ghost3->AddRigibody(); + Ghost3->AffectTag("Ghost"); + + Object * Ghost4 = new Object; + Ghost4->GetTransforms()->SetXY( 116, 156); + Ghost4->GetRender()->SetRender(A_Ghost,2); + Ghost4->AddRigibody(); + Ghost4->AffectTag("Ghost"); + + Object * TP1 = new Object; + TP1->GetTransforms()->SetXY( -14, 140); + TP1->AddRigibody(); + TP1->GetRigibody()->UseFixeBody(15,15); + TP1->AffectTag("TP1"); + + Object * TP2 = new Object; + TP2->GetTransforms()->SetXY( 245, 140); + TP2->AddRigibody(); + TP2->GetRigibody()->UseFixeBody(15,15); + TP2->AffectTag("TP2"); + + /*IA2 * Script_Ghost1 = new IA2; + IA1 * Script_Ghost2 = new IA2; + IA2 * Script_Ghost3 = new IA2;*/ + IA2 * Script_Ghost4 = new IA2; + /* Ghost1->AffectScript(Script_Ghost1); + Ghost2->AffectScript(Script_Ghost2); + Ghost3->AffectScript(Script_Ghost3);*/ + Ghost4->AffectScript(Script_Ghost4); + + //***********Creation de la map*************** + + Map Niveau1; + Niveau1.SetMap(tileset ,level , tileprop , 3 , 3 , 82 ,91); + + + //**************Assignation des objects************ + + Engine Game; + + Game.AddObject( PacMan); + Game.AddObject( Ghost1); + Game.AddObject( Ghost2); + Game.AddObject( Ghost3); + Game.AddObject( Ghost4); + Game.AddObject( TP1); + Game.AddObject( TP2); + + Game.AffectMap( &Niveau1); + + Niveau1.AffectEngine( &Game); + + Script_GUI SGUI; + Game.AffectScript(SGUI); + Script_PacMan->Initialisation(&SGUI); + /*Script_Ghost1->Initialisation(&SGUI); + Script_Ghost2->Initialisation(&SGUI); + Script_Ghost3->Initialisation(&SGUI);*/ + Script_Ghost4->Initialisation(&SGUI); + + Game.SetFpsWish(45); + Game.Game(); + + return 1; + +} + +extern "C" +{ +int AddIn_main(int isAppli, unsigned short OptionNum) +{ + Menu(); + return 1; +} + + +#pragma section _BR_Size +unsigned long BR_Size; +#pragma section + + +#pragma section _TOP + +int InitializeSystem(int isAppli, unsigned short OptionNum) +{ + return INIT_ADDIN_APPLICATION(isAppli, OptionNum); +} + +#pragma section +} +