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/actionrecord.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.
39 public:
40  enum PuzzleType { kCollision, kTileMove };
41  CollisionPuzzle(PuzzleType type) : RenderActionRecord(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 
79  Common::Path _imageName;
80 
82  Common::Array<Common::Point> _startLocations;
83 
84  Common::Array<Common::Rect> _pieceSrcs;
86 
87  Common::Rect _verticalWallSrc;
88  Common::Rect _horizontalWallSrc;
89  Common::Rect _blockSrc;
90 
91  Common::Point _tileMoveExitPos = Common::Point(-1, -1);
92  uint _tileMoveExitIndex = 0;
93 
94  bool _usesExitButton = false;
95  Common::Rect _exitButtonSrc;
96  Common::Rect _exitButtonDest;
97 
98  Common::Point _gridPos;
99 
100  uint16 _lineWidth = 0;
101  uint16 _framesPerMove = 0;
102 
103  uint32 _timerTime = 0; // in seconds
104  Common::Array<Common::Rect> _timerSrcs;
105  Common::Array<int16> _timerFlagIds;
106  Common::Rect _timerDest;
107 
108  SoundDescription _moveSound;
109  SoundDescription _homeSound;
110  SoundDescription _wallHitSound;
111  SoundDescription _exitButtonSound;
112 
113  SceneChangeWithFlag _solveScene;
114  uint16 _solveSoundDelay = 0;
115  SoundDescription _solveSound;
116 
117  SceneChangeWithFlag _exitScene;
118  Common::Rect _exitHotspot;
119 
121  Common::Array<Piece> _pieces;
122 
123  int _currentlyAnimating = -1;
124  int _currentAnimFrame = -1;
125  Common::Point _lastPosition = { -1, -1 };
126 
127  uint32 _solveSoundPlayTime = 0;
128  bool _solved = false;
129 
130  uint32 _puzzleStartTime = 0;
131  int _currentTimerGraphic = -1;
132 
133  PuzzleType _puzzleType;
134 };
135 
136 } // End of namespace Action
137 } // End of namespace Nancy
138 
139 #endif // NANCY_ACTION_COLLISIONPUZZLE_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: array.h:52
Definition: rect.h:524
Definition: path.h:52
Definition: collisionpuzzle.h:38
Definition: stream.h:745
Definition: input.h:41
Definition: commontypes.h:172
Definition: actionrecord.h:152
Definition: renderobject.h:36
Definition: rect.h:144
Definition: commontypes.h:255
Definition: actionmanager.h:32
Definition: collisionpuzzle.h:59