From e8b7cf83a5114d21f4e1ff87f835a020b868bc04 Mon Sep 17 00:00:00 2001 From: laiaga Date: Tue, 24 Nov 2015 01:16:32 +0100 Subject: [PATCH] =?utf8?q?3=C3=A8=20it=C3=A9ration?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- PACMAN.pro | 17 +-- PACMAN.pro.user | 207 +------------------------------- engines/box.cpp | 27 ++--- engines/core_kernel.cpp | 44 ++++--- engines/core_kernel.h | 12 +- engines/engine_graphics.cpp | 21 ++-- engines/engine_graphics.h | 13 +- engines/engine_physics.cpp | 23 ++-- engines/engine_physics.h | 5 +- engines/entity.cpp | 76 +++++++----- engines/entity.h | 11 +- engines/frame.cpp | 70 ----------- engines/frame.h | 39 ------ engines/playzone.cpp | 59 +++++++++ engines/playzone.h | 40 ++++++ engines/point.cpp | 64 +++++----- engines/point.h | 20 +-- gameplay/labyrinth.cpp | 35 ++++++ gameplay/labyrinth.h | 21 ++++ gameplay/level.cpp | 55 +++++---- gameplay/level.h | 42 ++++--- gameplay/main.cpp | 8 +- gameplay/{mouvement.cpp => movment.cpp} | 10 +- gameplay/{mouvement.h => movment.h} | 3 +- gameplay/pacman.cpp | 55 ++++----- gameplay/pacman.h | 7 +- gameplay/window.cpp | 5 +- qml.qrc | 26 +++- res.qrc | 6 + 29 files changed, 455 insertions(+), 566 deletions(-) rewrite engines/core_kernel.cpp (90%) rewrite engines/entity.cpp (93%) delete mode 100644 engines/frame.cpp delete mode 100644 engines/frame.h create mode 100644 engines/playzone.cpp create mode 100644 engines/playzone.h rewrite engines/point.cpp (95%) create mode 100644 gameplay/labyrinth.cpp create mode 100644 gameplay/labyrinth.h rewrite gameplay/level.cpp (61%) rewrite gameplay/level.h (72%) rename gameplay/{mouvement.cpp => movment.cpp} (71%) rename gameplay/{mouvement.h => movment.h} (95%) rewrite gameplay/pacman.cpp (94%) create mode 100644 res.qrc diff --git a/PACMAN.pro b/PACMAN.pro index d213e28..1434185 100644 --- a/PACMAN.pro +++ b/PACMAN.pro @@ -13,15 +13,17 @@ SOURCES += \ engines/entity.cpp \ engines/point.cpp \ engines/engine_graphics.cpp \ - engines/frame.cpp \ - gameplay/mouvement.cpp \ gameplay/pacman.cpp \ gameplay/main.cpp \ gameplay/window.cpp \ - gameplay/level.cpp + gameplay/level.cpp \ + gameplay/labyrinth.cpp \ + engines/playzone.cpp \ + gameplay/movment.cpp -RESOURCES += qml.qrc +RESOURCES += \ + res.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = @@ -36,9 +38,10 @@ HEADERS += \ engines/entity.h \ engines/point.h \ engines/engine_graphics.h \ - engines/frame.h \ gameplay/window.h \ gameplay/level.h \ - gameplay/mouvement.h \ - gameplay/pacman.h + gameplay/pacman.h \ + gameplay/labyrinth.h \ + engines/playzone.h \ + gameplay/movment.h diff --git a/PACMAN.pro.user b/PACMAN.pro.user index dee61a1..4a46159 100644 --- a/PACMAN.pro.user +++ b/PACMAN.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -195,207 +195,6 @@ ProjectExplorer.BuildSteps.Deploy 1 - Déployer localement - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - PACMAN - - Qt4ProjectManager.Qt4RunConfiguration:/home/laiaga/Documents/git/PACMAN/PACMAN.pro - - PACMAN.pro - false - false - - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Memcheck - Memcheck - {ae539aa5-d058-47e0-82e5-51e196d7932d} - 0 - 0 - 0 - - /home/laiaga/Documents/git/build-PACMAN-Memcheck-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/laiaga/Documents/git/build-PACMAN-Memcheck-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 2 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 Deploy locally ProjectExplorer.DefaultDeployConfiguration @@ -459,7 +258,7 @@ ProjectExplorer.Project.TargetCount - 2 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/engines/box.cpp b/engines/box.cpp index 847fca0..ba0d6b6 100644 --- a/engines/box.cpp +++ b/engines/box.cpp @@ -1,20 +1,17 @@ #include "box.h" -namespace engine -{ - - Box::Box() : width(0), height(0) - {} - Box::Box(int width, int height) : width(width), height(height) - {} +using namespace engine; - int Box::get_width() - { - return this->width; - } - int Box::get_height() - { - return this->height; - } +Box::Box() : width(0), height(0) +{} +Box::Box(int width, int height) : width(width), height(height) +{} +int Box::get_width() +{ + return this->width; +} +int Box::get_height() +{ + return this->height; } diff --git a/engines/core_kernel.cpp b/engines/core_kernel.cpp dissimilarity index 90% index 6137440..7c05656 100644 --- a/engines/core_kernel.cpp +++ b/engines/core_kernel.cpp @@ -1,23 +1,21 @@ -#include "core_kernel.h" - -namespace engine -{ - - Core_kernel::Core_kernel(int argc, char* argv[]) : QApplication(argc,argv) - { - this->entities_list = vector(); - } - - Core_kernel::Core_kernel(int argc, char* argv[], vector entities) : QApplication(argc,argv) - { - this->entities_list = entities; - } - - void Core_kernel::refresh_frame() - { - for(Entity entity:entities_list) - { - entity.update_entity(); - } - } -} +#include "core_kernel.h" + +using namespace engine; + +Core_kernel::Core_kernel(int &argc, char* argv[]) : QApplication(argc,argv) +{ + this->entities_list = vector(); +} + +void Core_kernel::add_entity(Entity *e) +{ + this->entities_list.push_back(e); +} + +void Core_kernel::main_loop() +{ + for(Entity *entity:entities_list) + { + entity->update_entity(); + } +} diff --git a/engines/core_kernel.h b/engines/core_kernel.h index 6e2e2bf..9cc54e3 100644 --- a/engines/core_kernel.h +++ b/engines/core_kernel.h @@ -3,22 +3,18 @@ #include #include -#include -#include #include "entity.h" -using namespace engine; - namespace engine { class Core_kernel : public QApplication { private: - vector entities_list; + vector entities_list; public: - Core_kernel(int argc, char* argv[]); - Core_kernel(int argc, char* argv[], vector entities); - void refresh_frame(); + Core_kernel(int &argc, char* argv[]); + void add_entity(Entity *e); + void main_loop(); }; } diff --git a/engines/engine_graphics.cpp b/engines/engine_graphics.cpp index 8c3fe44..2aebb02 100644 --- a/engines/engine_graphics.cpp +++ b/engines/engine_graphics.cpp @@ -2,18 +2,18 @@ using namespace engine; - Engine_graphics::Engine_graphics() : QWidget() { - play_zone = new Frame(); + play_zone = new Playzone(); layout = new QGridLayout(); - layout->addWidget(play_zone,1,0,8,8); + layout->addWidget(play_zone,1,0,8,8); labels = new vector(); numbers = new vector(); setLayout(layout); + setForegroundRole(QPalette::Shadow); setWindowTitle("Pac-Man"); resize(WIDTH,HEIGHT); @@ -21,7 +21,7 @@ Engine_graphics::Engine_graphics() : QWidget() Engine_graphics::Engine_graphics(int width, int height) : QWidget() { - play_zone = new Frame(); + play_zone = new Playzone(); layout = new QGridLayout(); layout->addWidget(play_zone,1,0,8,8); @@ -46,19 +46,16 @@ void Engine_graphics::create_label(QString text, int row, int col, int width, in void Engine_graphics::create_number(int initial_value, int nb_digit, int row, int col, int width, int height) { QLCDNumber *n = new QLCDNumber(nb_digit); - n->setSegmentStyle(QLCDNumber::Filled); + n->setSegmentStyle(QLCDNumber::Flat); n->display(initial_value); - //if(alignment) n->setAlignment(alignment); layout->addWidget(n,row,col,width,height); numbers->push_back(n); } -void Engine_graphics::set_background(QString img_path) +void Engine_graphics::set_background(QString background_path) { - QPixmap bkgnd(img_path); - bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio); - QPalette palette; - palette.setBrush(QPalette::Background, bkgnd); - this->setPalette(palette); + play_zone->setBackgroundBrush(QBrush(QImage(background_path))); + std::cout << "test" << std::endl; + play_zone->show(); } diff --git a/engines/engine_graphics.h b/engines/engine_graphics.h index 8278307..606cdeb 100644 --- a/engines/engine_graphics.h +++ b/engines/engine_graphics.h @@ -7,11 +7,10 @@ #include #include #include -#include -#include "frame.h" +#include "playzone.h" -#define WIDTH 512 -#define HEIGHT 512 +#define WIDTH 600 +#define HEIGHT 600 namespace engine { @@ -19,7 +18,7 @@ namespace engine { private: QGridLayout *layout; - engine::Frame *play_zone; + engine::Playzone *play_zone; vector *labels; vector *numbers; @@ -28,8 +27,8 @@ namespace engine Engine_graphics(int width, int height); void create_label(QString text, int row, int col, int width=1, int height=1, Qt::Alignment alignment=0); void create_number(int initial_value, int nb_digit, int row, int col, int width=1, int height=1); - void set_background(QString img_path); - engine::Frame* get_play_zone(){return play_zone;}; + void set_background(QString background_path); + engine::Playzone* get_play_zone(){return play_zone;}; }; } diff --git a/engines/engine_physics.cpp b/engines/engine_physics.cpp index 210898d..8112e72 100644 --- a/engines/engine_physics.cpp +++ b/engines/engine_physics.cpp @@ -1,24 +1,25 @@ #include "engine_physics.h" -namespace engine +using namespace engine; + +bool Engine_physics::is_collision(Entity e1, Entity e2) { - Box Engine_physics::create_box(int width, int height) + if(e1.is_null() || e2.is_null()) { - return Box(width, height); + return false; } - - bool Engine_physics::is_collision(Entity e1, Entity e2) + else { - int dif_pos_w = abs(e1.get_pos().get_pos_x() - e2.get_pos().get_pos_x()); - int dif_pos_h = abs(e1.get_pos().get_pos_y() - e2.get_pos().get_pos_y()); + int dif_pos_w = abs(e1.get_pos().get_x() - e2.get_pos().get_x()); + int dif_pos_h = abs(e1.get_pos().get_y() - e2.get_pos().get_y()); int dif_box_w = abs(e1.get_box().get_width() + e2.get_box().get_width()); int dif_box_h = abs(e1.get_box().get_height() + e2.get_box().get_height()); return (dif_pos_w <= dif_box_w/2 && dif_pos_h <= dif_box_h/2); } +} - void Engine_physics::move_entity(Entity entity, Point to) - { - entity.set_pos(to); - } +void Engine_physics::move_entity(Entity entity, Point to) +{ + entity.set_pos(to); } diff --git a/engines/engine_physics.h b/engines/engine_physics.h index ac1d4d3..70bae18 100644 --- a/engines/engine_physics.h +++ b/engines/engine_physics.h @@ -5,14 +5,11 @@ #include "box.h" #include "entity.h" -using namespace engine; - namespace engine { class Engine_physics { - public: - Box create_box(int width, int height); + public: static bool is_collision(Entity e1, Entity e2); static void move_entity(Entity entity, Point to); }; diff --git a/engines/entity.cpp b/engines/entity.cpp dissimilarity index 93% index dc9b328..b1f9d5c 100644 --- a/engines/entity.cpp +++ b/engines/entity.cpp @@ -1,31 +1,45 @@ -#include "entity.h" - -namespace engine -{ - - Entity::Entity(int x, int y, int width, int height) : position(Point(x, y)), hitbox(Box(width, height)) - {} - Entity::Entity(Point pos, Box box) : position(pos), hitbox(box) - {} - - Point Entity::get_pos() - { - return this->position; - } - Box Entity::get_box() - { - return this->hitbox; - } - - void Entity::set_pos(Point to) - { - this->position = to; - } - - void Entity::update_entity() - { - - } - -} - +#include "entity.h" +#include "core_kernel.h" + +using namespace engine; + +Entity::Entity(int x, int y, int width, int height) : position(Point(x, y)), hitbox(Box(width, height)) +{} + +Entity::Entity(Point pos, Box box) : position(pos), hitbox(box) +{} + +Entity::Entity(int x, int y, int width, int height, Core_kernel *ker) : position(Point(x, y)), hitbox(Box(width, height)) +{ + ker->add_entity(this); +} +Entity::Entity(Point pos, Box box, Core_kernel *ker) : position(pos), hitbox(box) +{ + ker->add_entity(this); +} + +Point Entity::get_pos() +{ + return this->position; +} +Box Entity::get_box() +{ + return this->hitbox; +} + +bool Entity::is_null() +{ + return (this->get_box().get_width() == 0 && this->get_box().get_height() == 0); +} + +void Entity::set_pos(Point to) +{ + this->position = to; +} + +void Entity::update_entity() +{} + + + + diff --git a/engines/entity.h b/engines/entity.h index 0e03cf1..5e86a3b 100644 --- a/engines/entity.h +++ b/engines/entity.h @@ -4,10 +4,10 @@ #include "box.h" #include "point.h" -using namespace engine; - namespace engine { + class Core_kernel;//forward declaration car on ne peut pas inclure directement core_kernel.h => cela créerait une inclusion mutuelle vu que entity.h est inclus dans core_kernel + class Entity { private: @@ -15,12 +15,15 @@ namespace engine Box hitbox; string path_skin; public: - Entity(int x, int y, int width, int weight); + Entity(int x, int y, int width, int height); Entity(Point pos, Box box); + Entity(int x, int y, int width, int height, Core_kernel *ker); + Entity(Point pos, Box box, Core_kernel *ker); Point get_pos(); Box get_box(); + bool is_null(); void set_pos(Point to); - void update_entity(); + virtual void update_entity(); }; } diff --git a/engines/frame.cpp b/engines/frame.cpp deleted file mode 100644 index db5b44a..0000000 --- a/engines/frame.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "frame.h" - -using namespace engine; - -Frame::Frame() : QFrame() -{ - setFrameStyle(QFrame::Panel | QFrame::Sunken); - setFocusPolicy(Qt::StrongFocus); - character = NULL; -} - -void Frame::set_handler_arrows(void (*on_key_up)(), void (*on_key_down)(), void (*on_key_left)(), void (*on_key_right)()) -{ - this->on_key_up = on_key_up; - this->on_key_down = on_key_down; - this->on_key_left = on_key_left; - this->on_key_right = on_key_right; -} - -void Frame::display_character(QString img_path, int x, int y) -{ - character = new QLabel(); - QPixmap pixmap(img_path); - - character->setPixmap(pixmap); - - QGridLayout *layout = new QGridLayout(); - layout->addWidget(character,1,10); - - //QWidget *corner = new QWidget(); - //layout->addWidget(corner,100,100); - - setLayout(layout); - - update(); - -} - -void Frame::display_item(Entity e) -{ - -} - -void Frame::keyPressEvent(QKeyEvent *event) -{ - if(character == NULL) return; - switch (event->key()) - { - case Qt::Key_Up: - this->on_key_up; - break; - case Qt::Key_Down: - this->on_key_down; - break; - case Qt::Key_Left: - this->on_key_left; - break; - case Qt::Key_Right: - this->on_key_right; - break; - default: - QFrame::keyPressEvent(event); - } -} - -void Frame::paintEvent(QPaintEvent *event) -{ - QFrame::paintEvent(event); - -} diff --git a/engines/frame.h b/engines/frame.h deleted file mode 100644 index 2884f1a..0000000 --- a/engines/frame.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef FRAME_H -#define FRAME_H - -#include -#include -#include -#include -#include -#include -#include -#include "entity.h" -#include "point.h" -#include "../gameplay/pacman.h" - -using namespace gameplay; - -namespace engine -{ - class Frame : public QFrame - { - public: - Frame(); - void set_handler_arrows(void (*on_key_left)(), void (*on_key_right)(), void (*on_key_up)(), void (*on_key_down)()); - void display_character(QString img_path, int x, int y); - void display_item(Entity e); - private: - enum { BoardWidth = 19, BoardHeight = 22 }; - QLabel *character; - void (*on_key_left)(); - void (*on_key_right)(); - void (*on_key_up)(); - void (*on_key_down)(); - void keyPressEvent(QKeyEvent *event); - void paintEvent(QPaintEvent *event); - - }; -} - -#endif // FRAME_H diff --git a/engines/playzone.cpp b/engines/playzone.cpp new file mode 100644 index 0000000..91f565f --- /dev/null +++ b/engines/playzone.cpp @@ -0,0 +1,59 @@ +#include "playzone.h" + +using namespace engine; + +Playzone::Playzone(QString background_path) : QGraphicsView() +{ + scene = new QGraphicsScene(); + this->setScene(scene); + setBackgroundBrush(QBrush(QImage(background_path))); + //this->show(); +} + +Playzone::Playzone() : QGraphicsView() +{ + scene = new QGraphicsScene(); + this->setScene(scene); + //this->show(); +} + +//void Playzone::set_handler_arrows(void (*on_key_up)(), void (*on_key_down)(), void (*on_key_left)(), void (*on_key_right)()) +//{ +// this->on_key_up = on_key_up; +// this->on_key_down = on_key_down; +// this->on_key_left = on_key_left; +// this->on_key_right = on_key_right; +//} + +void Playzone::display_character(QString img_path, int x, int y) +{ + + +} + +void Playzone::display_item(Entity e) +{ + +} + +//void Playzone::keyPressEvent(QKeyEvent *event) +//{ +// if(character == NULL) return; +// switch (event->key()) +// { +// case Qt::Key_Up: +// this->on_key_up; +// break; +// case Qt::Key_Down: +// this->on_key_down; +// break; +// case Qt::Key_Left: +// this->on_key_left; +// break; +// case Qt::Key_Right: +// this->on_key_right; +// break; +// default: +// QGraphicsView::keyPressEvent(event); +// } +//} diff --git a/engines/playzone.h b/engines/playzone.h new file mode 100644 index 0000000..87eb34e --- /dev/null +++ b/engines/playzone.h @@ -0,0 +1,40 @@ +#ifndef PLAYZONE_H +#define PLAYZONE_H + +#include +#include +#include +#include +#include +#include +#include "entity.h" +#include "point.h" +#include "../gameplay/pacman.h" + +using namespace gameplay; + +namespace engine +{ + class Playzone : public QGraphicsView + { + public: + Playzone(QString background_path); + Playzone(); +// void set_handler_arrows(void (*on_key_left)(), void (*on_key_right)(), void (*on_key_up)(), void (*on_key_down)()); + void display_character(QString img_path, int x, int y); + void display_item(Entity e); + + private: + QGraphicsScene *scene; + + enum { BoardWidth = 19, BoardHeight = 22 }; +// void (*on_key_left)(); +// void (*on_key_right)(); +// void (*on_key_up)(); +// void (*on_key_down)(); +// void keyPressEvent(QKeyEvent *event); + + }; +} + +#endif // PLAYZONE_H diff --git a/engines/point.cpp b/engines/point.cpp dissimilarity index 95% index 9982958..173e816 100644 --- a/engines/point.cpp +++ b/engines/point.cpp @@ -1,32 +1,32 @@ -#include "point.h" - -namespace engine -{ - Point::Point() : pos_x(0), pos_y(0) - {} - Point::Point(int x, int y) : pos_x(x), pos_y(y) - {} - - int Point::get_pos_x() - { - return this->pos_x; - } - - int Point::get_pos_y() - { - return this->pos_y; - } - - Point& Point::operator+=(const Point& rhs) - { - this->pos_x += rhs.pos_x; - this->pos_y += rhs.pos_y; - return *this; - } - Point& Point::operator-=(const Point& rhs) - { - this->pos_x -= rhs.pos_x; - this->pos_y -= rhs.pos_y; - return *this; - } -} +#include "point.h" + +using namespace engine; + +Point::Point() : x(0), y(0) +{} +Point::Point(int _x, int _y) : x(_x), y(_y) +{} + +int Point::get_x() +{ + return this->x; +} + +int Point::get_y() +{ + return this->y; +} + +Point& Point::operator+=(const Point& rhs) +{ + this->x += rhs.x; + this->y += rhs.y; + return *this; +} +Point& Point::operator-=(const Point& rhs) +{ + this->x -= rhs.x; + this->y -= rhs.y; + return *this; +} + diff --git a/engines/point.h b/engines/point.h index 429c356..956d6d7 100644 --- a/engines/point.h +++ b/engines/point.h @@ -10,26 +10,26 @@ namespace engine class Point { private: - int pos_x; - int pos_y; + int x; + int y; public: Point(); - Point(int x, int y); - int get_pos_x(); - int get_pos_y(); + Point(int _x, int _y); + int get_x(); + int get_y(); Point& operator+=(const Point& rhs); Point& operator-=(const Point& rhs); }; inline bool operator==(Point& lhs, Point& rhs) { - return lhs.get_pos_x() == rhs.get_pos_x() - && lhs.get_pos_y() == rhs.get_pos_y(); + return lhs.get_x() == rhs.get_x() + && lhs.get_y() == rhs.get_y(); } inline bool operator!=(Point& lhs, Point& rhs) { - return lhs.get_pos_x() != rhs.get_pos_x() - || lhs.get_pos_y() != rhs.get_pos_y(); + return lhs.get_x() != rhs.get_x() + || lhs.get_y() != rhs.get_y(); } inline Point operator+(Point lhs, const Point& rhs) @@ -45,7 +45,7 @@ namespace engine inline ostream& operator<<(ostream& stream, Point p) { - stream << "(" << p.get_pos_x() << "," << p.get_pos_y() << ")"; + stream << "(" << p.get_x() << "," << p.get_y() << ")"; return stream; } } diff --git a/gameplay/labyrinth.cpp b/gameplay/labyrinth.cpp new file mode 100644 index 0000000..90b810b --- /dev/null +++ b/gameplay/labyrinth.cpp @@ -0,0 +1,35 @@ +#include "labyrinth.h" + +using namespace gameplay; + +Labyrinth::Labyrinth(char* path_file) +{ + FILE * pFile; + int c; + pFile = fopen(path_file, "r"); + if(pFile == NULL) + { + perror ("Error opening file"); + } + else + { + int i(0); + do + { + int j(0); + while(j < n_max) + { + c = fgetc (pFile); + this->matrix[i][j] = (c == '1'); + j++; + } + } while (c != EOF && i < n_max); + fclose (pFile); + } +} + +engine::Entity Labyrinth::getWall(int x, int y) +{ + if(this->matrix[x][y]) return engine::Entity(x*width_wall, y*width_wall, width_wall, width_wall); + else return engine::Entity(x*width_wall, y*width_wall, 0, 0); +} diff --git a/gameplay/labyrinth.h b/gameplay/labyrinth.h new file mode 100644 index 0000000..e6d28bf --- /dev/null +++ b/gameplay/labyrinth.h @@ -0,0 +1,21 @@ +#ifndef LABYRINTH_H +#define LABYRINTH_H +#define n_max 40 +#define width_wall 15 + +#include +#include "engines/entity.h" + +namespace gameplay +{ + class Labyrinth + { + private: + bool matrix[n_max][n_max]; + public: + Labyrinth(char* path_file); + engine::Entity getWall(int x, int y); + }; +} + +#endif // LABYRINTH_H diff --git a/gameplay/level.cpp b/gameplay/level.cpp dissimilarity index 61% index 0988888..dbb21c2 100644 --- a/gameplay/level.cpp +++ b/gameplay/level.cpp @@ -1,25 +1,30 @@ -#include "level.h" - -using namespace engine; - -Level::Level() -{ - this->pacman = new Pacman(0,0); -} - -void Level::on_key_up() -{ - this->pacman->set_heading(&Mouvement::move_north); -} -void Level::on_key_down() -{ - this->pacman->set_heading(&Mouvement::move_south); -} -void Level::on_key_left() -{ - this->pacman->set_heading(&Mouvement::move_east); -} -void Level::on_key_right() -{ - this->pacman->set_heading(&Mouvement::move_west); -} +#include "level.h" + +using namespace engine; + +Level::Level(Core_kernel *ker) +{ + this->pacman = new Pacman(0,0,ker); +} + +Level::Level(Pacman *pac) +{ + this->pacman = pac; +} + +void Level::on_key_up() +{ + this->pacman->set_heading(&Movment::move_north); +} +void Level::on_key_down() +{ + this->pacman->set_heading(&Movment::move_south); +} +void Level::on_key_left() +{ + this->pacman->set_heading(&Movment::move_east); +} +void Level::on_key_right() +{ + this->pacman->set_heading(&Movment::move_west); +} diff --git a/gameplay/level.h b/gameplay/level.h dissimilarity index 72% index 5342091..1dfad04 100644 --- a/gameplay/level.h +++ b/gameplay/level.h @@ -1,19 +1,23 @@ -#ifndef LEVEL_H -#define LEVEL_H - -#include "engines/frame.h" -#include "pacman.h" - -class Level -{ -private: - Pacman *pacman; - void on_key_up(); - void on_key_down(); - void on_key_left(); - void on_key_right(); -public: - Level(); -}; - -#endif // LEVEL_H +#ifndef LEVEL_H +#define LEVEL_H + +#include "engines/playzone.h" +#include "engines/core_kernel.h" +#include "pacman.h" + +namespace gameplay{ + class Level + { + private: + Pacman *pacman; + void on_key_up(); + void on_key_down(); + void on_key_left(); + void on_key_right(); + public: + Level(Core_kernel *ker); + Level(Pacman *pac); + }; +} + +#endif // LEVEL_H diff --git a/gameplay/main.cpp b/gameplay/main.cpp index 02047e5..13cc5df 100644 --- a/gameplay/main.cpp +++ b/gameplay/main.cpp @@ -9,14 +9,16 @@ int main(int argc, char *argv[]) { //std::cout << "un"<< std::endl; - Core_kernel kernel(argc,argv); + int &tmp = argc; + Core_kernel kernel(tmp,argv); - Window w("ressources/pacman_layout.JPG"); + + Window w("qrc:/ressources/pacman_layout.JPG"); //std::cout << "deux"<< std::endl; - Pacman pacman(0,0,"ressources/pacman.png"); + Pacman pacman(0,0,"qrc:/ressources/pacman.png",&kernel); //std::cout << "trois"<< std::endl; diff --git a/gameplay/mouvement.cpp b/gameplay/movment.cpp similarity index 71% rename from gameplay/mouvement.cpp rename to gameplay/movment.cpp index 995fa54..259ba6b 100644 --- a/gameplay/mouvement.cpp +++ b/gameplay/movment.cpp @@ -1,24 +1,24 @@ -#include "mouvement.h" +#include "movment.h" #include "../engines/engine_physics.h" namespace gameplay { - void Mouvement::move_north(Entity entity) + void Movment::move_north(Entity entity) { Point to = entity.get_pos() + Point(-1, 0); Engine_physics::move_entity(entity, to); } - void Mouvement::move_south(Entity entity) + void Movment::move_south(Entity entity) { Point to = entity.get_pos() + Point(1, 0); Engine_physics::move_entity(entity, to); } - void Mouvement::move_east(Entity entity) + void Movment::move_east(Entity entity) { Point to = entity.get_pos() + Point(0, 1); Engine_physics::move_entity(entity, to); } - void Mouvement::move_west(Entity entity) + void Movment::move_west(Entity entity) { Point to = entity.get_pos() + Point(0, -1); Engine_physics::move_entity(entity, to); diff --git a/gameplay/mouvement.h b/gameplay/movment.h similarity index 95% rename from gameplay/mouvement.h rename to gameplay/movment.h index 95f4408..0afb076 100644 --- a/gameplay/mouvement.h +++ b/gameplay/movment.h @@ -5,9 +5,10 @@ #include "engines/entity.h" using namespace engine; + namespace gameplay { - class Mouvement + class Movment { public: static void move_north(Entity entity); diff --git a/gameplay/pacman.cpp b/gameplay/pacman.cpp dissimilarity index 94% index 45f77e5..5f0902a 100644 --- a/gameplay/pacman.cpp +++ b/gameplay/pacman.cpp @@ -1,29 +1,26 @@ -#include "pacman.h" - -namespace gameplay -{ - - Pacman::Pacman(int x, int y, int width, int height) : Entity(x, y, width, height) - { - } - - Pacman::Pacman(int x, int y, QString img_path, int width, int height) : Entity(x, y, width, height) - { - this->img_path = img_path; - } - - void Pacman::set_heading(void (*head)(Entity)) - { - this->head = *head; - } - - void Pacman::move() - { - head(*this); - } - - void Pacman::update_entity() - { - move(); - } -} +#include "pacman.h" + +using namespace gameplay; + +Pacman::Pacman(int x, int y, Core_kernel *ker, int width, int height) : Entity(x, y, width, height, ker) +{} + +Pacman::Pacman(int x, int y, QString img_path, Core_kernel *ker, int width, int height) : Entity(x, y, width, height, ker) +{ + this->img_path = img_path; +} + +void Pacman::set_heading(void (*head)(engine::Entity)) +{ + this->head = head; +} + +void Pacman::move() +{ + head(*this); +} + +void Pacman::update_entity() +{ + move(); +} diff --git a/gameplay/pacman.h b/gameplay/pacman.h index 9dde185..21eee09 100644 --- a/gameplay/pacman.h +++ b/gameplay/pacman.h @@ -4,7 +4,8 @@ #include #include #include "engines/entity.h" -#include "gameplay/mouvement.h" +#include "gameplay/movment.h" +#include "engines/core_kernel.h" namespace gameplay { @@ -14,8 +15,8 @@ namespace gameplay QString img_path; void (*head)(Entity); public: - Pacman(int x, int y, int width=15, int height=15); - Pacman(int x, int y, QString img_path, int width=15, int height=15); + Pacman(int x, int y, Core_kernel *ker, int width=15, int height=15); + Pacman(int x, int y, QString img_path, Core_kernel *ker, int width=15, int height=15); void set_heading(void (*head)(Entity)); void move(); void update_entity(); diff --git a/gameplay/window.cpp b/gameplay/window.cpp index 2c638d1..5fe1939 100644 --- a/gameplay/window.cpp +++ b/gameplay/window.cpp @@ -6,7 +6,6 @@ Window::Window(QString bg_img_path) { graph = new Engine_graphics(); graph->set_background(bg_img_path); - std::cout << bg_img_path.toStdString() << std::endl; graph->show(); } @@ -19,7 +18,7 @@ void Window::create_life_display() int width=1; int height=1; - graph->create_label("Lives left : ", row, col, width, height, Qt::AlignTop); + graph->create_label("Lives left : ", row, col, width, height, Qt::AlignTop); graph->create_number(initial_lives,nb_digits,row,col+1,width,height); } @@ -32,7 +31,7 @@ void Window::create_score_display() int width=1; int height=1; - graph->create_label("Score : ",row,col,width,height,Qt::AlignBottom); + graph->create_label("Score : ",row,col,width,height,Qt::AlignBottom); graph->create_number(initial_score,nb_digits,row,col+1,width,height); } diff --git a/qml.qrc b/qml.qrc index 0ff3892..e64b139 100644 --- a/qml.qrc +++ b/qml.qrc @@ -1,6 +1,30 @@ main.qml + engines/box.cpp + engines/box.h + engines/core_kernel.cpp + engines/core_kernel.h + engines/engine_graphics.cpp + engines/engine_graphics.h + engines/engine_physics.cpp + engines/engine_physics.h + engines/entity.cpp + engines/entity.h + engines/playzone.cpp + engines/playzone.h + engines/point.cpp + engines/point.h + gameplay/labyrinth.cpp + gameplay/labyrinth.h + gameplay/level.cpp + gameplay/level.h + gameplay/main.cpp + gameplay/movment.cpp + gameplay/movment.h + gameplay/pacman.cpp + gameplay/pacman.h + gameplay/window.cpp + gameplay/window.h - diff --git a/res.qrc b/res.qrc new file mode 100644 index 0000000..1ff420d --- /dev/null +++ b/res.qrc @@ -0,0 +1,6 @@ + + + ressources/pacman_layout.JPG + ressources/pacman.png + + -- 2.11.4.GIT