File indexing completed on 2024-06-16 03:55:50

0001 /*
0002     This file is part of Killbots.
0003 
0004     SPDX-FileCopyrightText: 2006-2009 Parker Coates <coates@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "sprite.h"
0010 
0011 #include "renderer.h"
0012 
0013 
0014 Killbots::Sprite::Sprite()
0015     : KGameRenderedItem(Renderer::self(), QString())
0016 {
0017     setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
0018     setTransformationMode(Qt::FastTransformation);
0019 }
0020 
0021 Killbots::Sprite::~Sprite()
0022 {
0023 }
0024 
0025 Killbots::SpriteType Killbots::Sprite::spriteType() const
0026 {
0027     return m_type;
0028 }
0029 
0030 void Killbots::Sprite::setSpriteType(Killbots::SpriteType type)
0031 {
0032     Q_ASSERT(type != NoSprite);
0033 
0034     m_type = type;
0035 
0036     switch (m_type) {
0037     case Hero :
0038         setSpriteKey(QStringLiteral("hero"));
0039         break;
0040     case Robot :
0041         setSpriteKey(QStringLiteral("enemy"));
0042         break;
0043     case Fastbot :
0044         setSpriteKey(QStringLiteral("fastenemy"));
0045         break;
0046     case Junkheap :
0047         setSpriteKey(QStringLiteral("junkheap"));
0048         break;
0049     default :
0050         break;
0051     }
0052 }
0053 
0054 void Killbots::Sprite::enqueueGridPos(QPoint position)
0055 {
0056     m_gridPositions << position;
0057 }
0058 
0059 QPoint Killbots::Sprite::currentGridPos() const
0060 {
0061     return m_gridPositions.first();
0062 }
0063 
0064 QPoint Killbots::Sprite::nextGridPos() const
0065 {
0066     Q_ASSERT(m_gridPositions.size() > 1);
0067     return m_gridPositions.at(1);
0068 }
0069 
0070 QPoint Killbots::Sprite::gridPos() const
0071 {
0072     return m_gridPositions.last();
0073 }
0074 
0075 void Killbots::Sprite::advanceGridPosQueue()
0076 {
0077     if (m_gridPositions.size() > 1) {
0078         m_gridPositions.removeFirst();
0079     }
0080 }
0081 
0082 int Killbots::Sprite::type() const
0083 {
0084     return Type;
0085 }
0086 
0087 void Killbots::Sprite::receivePixmap(const QPixmap &pixmap)
0088 {
0089     KGameRenderedItem::receivePixmap(pixmap);
0090     setOffset(-0.5 * QPointF(pixmap.width(), pixmap.height()));
0091 }
0092