1 | /* |
---|---|
2 | * Copyright 2006-2009 Parker Coates <coates@kde.org> |
3 | * |
4 | * This file is part of Killbots. |
5 | * |
6 | * Killbots is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * Killbots is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with Killbots. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include "sprite.h" |
21 | |
22 | #include "renderer.h" |
23 | |
24 | #include <QtGui/QPainter> |
25 | |
26 | |
27 | Killbots::Sprite::Sprite() |
28 | : KGameRenderedItem( Renderer::self(), QString() ) |
29 | { |
30 | setShapeMode( QGraphicsPixmapItem::BoundingRectShape ); |
31 | setTransformationMode( Qt::FastTransformation ); |
32 | } |
33 | |
34 | |
35 | Killbots::Sprite::~Sprite() |
36 | { |
37 | } |
38 | |
39 | |
40 | Killbots::SpriteType Killbots::Sprite::spriteType() const |
41 | { |
42 | return m_type; |
43 | } |
44 | |
45 | |
46 | void Killbots::Sprite::setSpriteType( Killbots::SpriteType type ) |
47 | { |
48 | Q_ASSERT( type != NoSprite ); |
49 | |
50 | m_type = type; |
51 | |
52 | switch ( m_type ) |
53 | { |
54 | case Hero : |
55 | setSpriteKey( "hero"); |
56 | break; |
57 | case Robot : |
58 | setSpriteKey( "enemy"); |
59 | break; |
60 | case Fastbot : |
61 | setSpriteKey( "fastenemy"); |
62 | break; |
63 | case Junkheap : |
64 | setSpriteKey( "junkheap"); |
65 | break; |
66 | default : |
67 | break; |
68 | } |
69 | } |
70 | |
71 | |
72 | void Killbots::Sprite::enqueueGridPos( QPoint position ) |
73 | { |
74 | m_gridPositions << position; |
75 | } |
76 | |
77 | |
78 | QPoint Killbots::Sprite::currentGridPos() const |
79 | { |
80 | return m_gridPositions.first(); |
81 | } |
82 | |
83 | |
84 | QPoint Killbots::Sprite::nextGridPos() const |
85 | { |
86 | Q_ASSERT( m_gridPositions.size() > 1 ); |
87 | return m_gridPositions.at( 1 ); |
88 | } |
89 | |
90 | |
91 | QPoint Killbots::Sprite::gridPos() const |
92 | { |
93 | return m_gridPositions.last(); |
94 | } |
95 | |
96 | |
97 | void Killbots::Sprite::advanceGridPosQueue() |
98 | { |
99 | if ( m_gridPositions.size() > 1 ) |
100 | m_gridPositions.removeFirst(); |
101 | } |
102 | |
103 | |
104 | int Killbots::Sprite::type() const |
105 | { |
106 | return Type; |
107 | } |
108 | |
109 | |
110 | void Killbots::Sprite::receivePixmap( const QPixmap & pixmap ) |
111 | { |
112 | KGameRenderedItem::receivePixmap( pixmap ); |
113 | setOffset( -0.5 * QPointF( pixmap.width(), pixmap.height() ) ); |
114 | } |
115 | |
116 |