From c1413464930fa82073800a6c58334099bbef370b Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 7 Apr 2011 00:02:36 +0200 Subject: adding normal points --- pacman-c++/actor.cpp | 3 +-- pacman-c++/bonuspoint.cpp | 1 - pacman-c++/constants.h | 14 ++++++++------ pacman-c++/mainwidget.cpp | 17 +++++++++++++++-- pacman-c++/pacman.pro | 6 ++++-- pacman-c++/pics/points.png | Bin 175 -> 181 bytes pacman-c++/point.cpp | 17 +++++++++++++++++ pacman-c++/point.h | 14 ++++++++++++++ 8 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 pacman-c++/point.cpp create mode 100644 pacman-c++/point.h (limited to 'pacman-c++') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 1796091..b6de49c 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -76,6 +76,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); move->setDuration(Constants::tick); + move->setEndValue(QPoint(0, 0)); } return eating; @@ -138,12 +139,10 @@ void Actor::move(Actor::Movement direction) break; } - qDebug() << __FILE__ << "Move from" << pos() - endpos << "to" << (pos()) << "(" << endpos << ")"; for(int i = 0; i < m_moving->animationCount(); ++i) { QPropertyAnimation *move = dynamic_cast(m_moving->animationAt(i)); move->setStartValue(QPoint(0, 0) - endpos); - move->setEndValue(QPoint(0, 0)); } setPos(pos() + endpos); diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 0517c64..eedb796 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp @@ -1,6 +1,5 @@ #include "bonuspoint.h" #include "constants.h" -#include #define BONUSPOINTS_NUM_SPRITES 4 diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index f0e7903..3d78d1d 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h @@ -34,15 +34,17 @@ namespace Transmission typedef unsigned int field_t; typedef unsigned int mask_t; + const field_t none = 0; const field_t block = (1 << 3); - const field_t bonuspoint = (1 << 4); - const field_t pacman = (1 << 5); + const field_t point = (1 << 4); + const field_t bonuspoint = (1 << 5); + const field_t pacman = (1 << 6); const field_t direction_none = 0; - const field_t direction_left = (1 << 6); - const field_t direction_right = (1 << 7); - const field_t direction_up = (1 << 8); - const field_t direction_down = (1 << 9); + const field_t direction_left = (1 << 7); + const field_t direction_right = (1 << 8); + const field_t direction_up = (1 << 9); + const field_t direction_down = (1 << 10); const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green; const mask_t type_mask = block | bonuspoint; diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 6ee7b7a..d0b2ad7 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -3,6 +3,7 @@ #include "actor.h" #include "block.h" #include "bonuspoint.h" +#include "point.h" #include "constants.h" // temporary @@ -18,7 +19,7 @@ Transmission::map_t createDummyMap() for (unsigned int y = 0; y < Constants::map_size.height; ++y) { Transmission::field_t &cur = map[x][y]; - cur = 0; + cur = Transmission::none; } } @@ -189,6 +190,16 @@ Transmission::map_t createDummyMap() map[17][15] |= Transmission::pacman; map[17][15] |= Transmission::direction_left; + for (unsigned int x = 0; x < Constants::map_size.width; ++x) + { + for (unsigned int y = 0; y < Constants::map_size.height; ++y) + { + Transmission::field_t &cur = map[x][y]; + if (cur == Transmission::none) + cur |= Transmission::point; + } + } + return map; } @@ -275,7 +286,7 @@ void MainWidget::updateMap(const Transmission::map_t& map) for (unsigned int y = 0; y < Constants::map_size.height; ++y) { const Transmission::field_t &cur = map[x][y]; - if (cur == 0) + if (cur == Transmission::none) continue; //qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; @@ -302,6 +313,8 @@ void MainWidget::updateMap(const Transmission::map_t& map) } else if (cur & Transmission::bonuspoint) item = new BonusPoint(); + else if (cur & Transmission::point) + item = new Point(); else if (cur & Transmission::pacman) { Actor *actor = m_actors.value(color, NULL); diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index 6282c5d..68d1be9 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro @@ -5,7 +5,8 @@ SOURCES += pixmapitem.cpp \ block.cpp \ client.cpp \ bonuspoint.cpp \ - mainwidget.cpp + mainwidget.cpp \ + point.cpp HEADERS += pixmapitem.h \ actor.h \ animationmanager.h \ @@ -13,7 +14,8 @@ HEADERS += pixmapitem.h \ client.h \ bonuspoint.h \ mainwidget.h \ - constants.h + constants.h \ + point.h RESOURCES += pacman.qrc OBJECTS_DIR = .obj diff --git a/pacman-c++/pics/points.png b/pacman-c++/pics/points.png index 7fff18d..8883588 100644 Binary files a/pacman-c++/pics/points.png and b/pacman-c++/pics/points.png differ diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp new file mode 100644 index 0000000..8837bba --- /dev/null +++ b/pacman-c++/point.cpp @@ -0,0 +1,17 @@ +#include "point.h" +#include "constants.h" + +namespace +{ + QPixmap *pixmap = NULL; +} + +Point::Point(QGraphicsItem *parent) + : PixmapItem(parent) +{ + if (pixmap == NULL) + pixmap = new QPixmap(":/points"); + setPixmap(*pixmap); + + //setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); +} diff --git a/pacman-c++/point.h b/pacman-c++/point.h new file mode 100644 index 0000000..847daed --- /dev/null +++ b/pacman-c++/point.h @@ -0,0 +1,14 @@ +#ifndef POINT_H +#define SPOINT_H + +#include "pixmapitem.h" + +class Point + : public PixmapItem +{ +public: + Point(QGraphicsItem *parent=0); + virtual ~Point() {}; +}; + +#endif // POINT_H -- cgit v1.2.3