ScummVM API documentation
collisionpuzzle.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NANCY_ACTION_COLLISIONPUZZLE_H
23 #define NANCY_ACTION_COLLISIONPUZZLE_H
24 
25 #include "engines/nancy/action/puzzlerecord.h"
26 
27 namespace Nancy {
28 namespace Action {
29 
30 // Class responsible for two similar puzzle types, both of which have
31 // rectangular tiles on a grid, which can move up/down/left/right until they
32 // hit a wall or another tile
33 // - CollisionPuzzle: Several 1x1 tiles, each of which has a "home" it needs to reach.
34 // The grid contains walls. Tiles move in all directions.
35 // - TileMovePuzzle: Many differently-sized tiles, one of which must reach the exit.
36 // Rectangular tiles can only move in the directions parallel to their longer sides.
37 // Exit is outside of the tile grid.
38 class CollisionPuzzle : public PuzzleRecord {
39 public:
40  enum PuzzleType { kCollision, kTileMove };
41  CollisionPuzzle(PuzzleType type) : PuzzleRecord(7), _puzzleType(type) {}
42  virtual ~CollisionPuzzle() {}
43 
44  void init() override;
45  void registerGraphics() override;
46  void updateGraphics() override;
47 
48  void readData(Common::SeekableReadStream &stream) override;
49  void execute() override;
50  void handleInput(NancyInput &input) override;
51 
52  bool isViewportRelative() const override { return true; }
53 
54 protected:
55  // 0 is an empty cell, positive numbers are home IDs. Wall/block markers use Nancy 11's
56  // values (16-20); earlier games store 6-10 and are remapped to these on load.
57  enum WallType { kWallLeft = 16, kWallUp = 17, kWallDown = 18, kWallRight = 19, kBlock = 20 };
58 
59  class Piece : public RenderObject {
60  public:
61  Piece() : RenderObject(9) {}
62  virtual ~Piece() {}
63 
64  Piece(Piece &&) = default;
65 
66  Common::Point _gridPos;
67  uint _w = 1;
68  uint _h = 1;
69 
70  bool isViewportRelative() const override { return true; }
71  };
72 
73  Common::String getRecordTypeName() const override { return _puzzleType == kCollision ? "CollisionPuzzle" : "TileMovePuzzle"; }
74 
75  Common::Point movePiece(uint pieceID, WallType direction);
76  Common::Rect getScreenPosition(Common::Point gridPos);
77  void drawGrid();
78 
80  Common::Array<Common::Point> _startLocations;
81 
82  Common::Array<Common::Rect> _pieceSrcs;
84 
85  Common::Rect _verticalWallSrc;
86  Common::Rect _horizontalWallSrc;
87  Common::Rect _blockSrc;
88 
89  Common::Point _tileMoveExitPos = Common::Point(-1, -1);
90  uint _tileMoveExitIndex = 0;
91  bool _tileMoveSolveStartsInSlot = false;
92 
93  bool _usesExitButton = false;
94  Common::Rect _exitButtonSrc;
95  Common::Rect _exitButtonDest;
96 
97  Common::Point _gridPos;
98 
99  uint16 _lineWidth = 0;
100  uint16 _framesPerMove = 0;
101 
102  uint32 _timerTime = 0; // in seconds
103  Common::Array<Common::Rect> _timerSrcs;
104  Common::Array<int16> _timerFlagIds;
105  Common::Rect _timerDest;
106 
107  SoundDescription _moveSound;
108  SoundDescription _homeSound;
109  SoundDescription _wallHitSound;
110  SoundDescription _exitButtonSound;
111 
112  Common::Array<Piece> _pieces;
113 
114  int _currentlyAnimating = -1;
115  int _currentAnimFrame = -1;
116  Common::Point _lastPosition = { -1, -1 };
117 
118  uint32 _solveSoundPlayTime = 0;
119  bool _solved = false;
120 
121  uint32 _puzzleStartTime = 0;
122  int _currentTimerGraphic = -1;
123 
124  PuzzleType _puzzleType;
125 };
126 
127 } // End of namespace Action
128 } // End of namespace Nancy
129 
130 #endif // NANCY_ACTION_COLLISIONPUZZLE_H
Definition: str.h:59
Definition: array.h:52
Definition: rect.h:536
Definition: collisionpuzzle.h:38
Definition: stream.h:745
Definition: input.h:41
Definition: renderobject.h:36
Definition: rect.h:144
Definition: puzzlerecord.h:37
Definition: commontypes.h:306
Definition: actionmanager.h:32
Definition: collisionpuzzle.h:59