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 protected:
53  // numbers 1-5 are home IDs, 0 is empty cell
54  enum WallType { kWallLeft = 6, kWallUp = 7, kWallDown = 8, kWallRight = 9, kBlock = 10 };
55 
56  class Piece : public RenderObject {
57  public:
58  Piece() : RenderObject(9) {}
59  virtual ~Piece() {}
60 
61  Common::Point _gridPos;
62  uint _w = 1;
63  uint _h = 1;
64 
65  protected:
66  bool isViewportRelative() const override { return true; }
67  };
68 
69  Common::String getRecordTypeName() const override { return _puzzleType == kCollision ? "CollisionPuzzle" : "TileMovePuzzle"; };
70  bool isViewportRelative() const override { return true; }
71 
72  Common::Point movePiece(uint pieceID, WallType direction);
73  Common::Rect getScreenPosition(Common::Point gridPos);
74  void drawGrid();
75 
76  Common::Path _imageName;
77 
79  Common::Array<Common::Point> _startLocations;
80 
81  Common::Array<Common::Rect> _pieceSrcs;
83 
84  Common::Rect _verticalWallSrc;
85  Common::Rect _horizontalWallSrc;
86  Common::Rect _blockSrc;
87 
88  Common::Point _tileMoveExitPos = Common::Point(-1, -1);
89  uint _tileMoveExitSize = 0;
90 
91  bool _usesExitButton = false;
92  Common::Rect _exitButtonSrc;
93  Common::Rect _exitButtonDest;
94 
95  Common::Point _gridPos;
96 
97  uint16 _lineWidth = 0;
98  uint16 _framesPerMove = 0;
99 
100  uint32 _timerTime = 0; // in seconds
101  Common::Array<Common::Rect> _timerSrcs;
102  Common::Array<int16> _timerFlagIds;
103  Common::Rect _timerDest;
104 
105  SoundDescription _moveSound;
106  SoundDescription _homeSound;
107  SoundDescription _wallHitSound;
108  SoundDescription _exitButtonSound;
109 
110  SceneChangeWithFlag _solveScene;
111  uint16 _solveSoundDelay = 0;
112  SoundDescription _solveSound;
113 
114  SceneChangeWithFlag _exitScene;
115  Common::Rect _exitHotspot;
116 
118  Common::Array<Piece> _pieces;
119 
120  int _currentlyAnimating = -1;
121  int _currentAnimFrame = -1;
122  Common::Point _lastPosition = { -1, -1 };
123 
124  uint32 _solveSoundPlayTime = 0;
125  bool _solved = false;
126 
127  uint32 _puzzleStartTime = 0;
128  int _currentTimerGraphic = -1;
129 
130  PuzzleType _puzzleType;
131 };
132 
133 } // End of namespace Action
134 } // End of namespace Nancy
135 
136 #endif // NANCY_ACTION_COLLISIONPUZZLE_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: array.h:52
Definition: rect.h:144
Definition: path.h:52
Definition: collisionpuzzle.h:38
Definition: stream.h:745
Definition: input.h:41
Definition: commontypes.h:171
Definition: actionrecord.h:149
Definition: renderobject.h:36
Definition: rect.h:45
Definition: commontypes.h:254
Definition: actionmanager.h:32
Definition: collisionpuzzle.h:56