1 /*
2     SPDX-FileCopyrightText: 2007-2008 John-Paul Stanford <jp@stanwood.org.uk>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 // own
8 #include "plane.h"
9 
10 // Bomber
11 #include "board.h"
12 
13 /** The speed the plane will fly at */
14 const qreal Plane::DEFAULT_VELOCITY = 0.08;
15 
16 /** This is the planes size relative to the tile */
17 const qreal Plane::PLANE_RELATIVE_SIZE = 1;
18 
19 /** This is the position before the plane goes off the screen */
20 const qreal Plane::PLANE_MAX_POSITION_X = 12;
21 
Plane(KGameRenderer * renderer,BomberBoard * board)22 Plane::Plane(KGameRenderer * renderer, BomberBoard * board)
23     : Explodable(QStringLiteral("plane"), QStringLiteral("plane_explode"), PLANE_RELATIVE_SIZE,
24                  PLANE_RELATIVE_SIZE, renderer, board)
25 {
26     setVelocity(DEFAULT_VELOCITY);
27     resetPosition();
28 }
29 
~Plane()30 Plane::~Plane()
31 {
32 }
33 
resetPosition()34 void Plane::resetPosition()
35 {
36     m_xPos = 0, m_yPos = 0;
37     m_nextBoundingRect.moveTo(m_xPos, m_yPos);
38 }
39 
advanceItem()40 void Plane::advanceItem()
41 {
42     if (state() == State::Moving) {
43         m_xPos += velocity();
44         if (m_xPos > PLANE_MAX_POSITION_X) {
45             m_xPos = 0;
46             ++m_yPos;
47         }
48     }
49     m_nextBoundingRect.moveTo(m_xPos + velocity(), m_yPos);
50 }
51