File indexing completed on 2024-02-18 04:04:55

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "spritefactory.h"
0008 
0009 
0010 #include "ship.h"
0011 #include "sprite.h"
0012 
0013 SpriteFactory::SpriteFactory(KBSRenderer* renderer)
0014 : m_renderer(renderer)
0015 {
0016 }
0017 
0018 Sprite* SpriteFactory::createShip(Ship* ship)
0019 {
0020     int x;
0021     int y;
0022     if (ship->direction() == Ship::LEFT_TO_RIGHT) {
0023         x = ship->size();
0024         y = 1;
0025     }
0026     else {
0027         x = 1;
0028         y = ship->size();
0029     }
0030 
0031     const QString name = QLatin1String("ship") + QString::number(ship->size()) + QLatin1String("-view");
0032 
0033     return new Sprite(m_renderer, Coord(x, y), name, ship->direction() == Ship::TOP_DOWN);
0034 }
0035 
0036 Sprite* SpriteFactory::createSimpleSprite(const QString& name)
0037 {
0038     return new Sprite(m_renderer, Coord(1, 1), name, false);
0039 }
0040 
0041 Sprite* SpriteFactory::createHit()
0042 {
0043     return createSimpleSprite(QStringLiteral("hit"));
0044 }
0045 
0046 Sprite* SpriteFactory::createMiss()
0047 {
0048     return createSimpleSprite(QStringLiteral("water"));
0049 }
0050 
0051 Sprite* SpriteFactory::createImpact()
0052 {
0053     return createSimpleSprite(QStringLiteral("water-impact"));
0054 }
0055 
0056