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  Piece(Piece &&) = default;
62 
63  Common::Point _gridPos;
64  uint _w = 1;
65  uint _h = 1;
66 
67  protected:
68  bool isViewportRelative() const override { return true; }
69  };
70 
71  Common::String getRecordTypeName() const override { return _puzzleType == kCollision ? "CollisionPuzzle" : "TileMovePuzzle"; }
72  bool isViewportRelative() const override { return true; }
73 
74  Common::Point movePiece(uint pieceID, WallType direction);
75  Common::Rect getScreenPosition(Common::Point gridPos);
76  void drawGrid();
77 
78  Common::Path _imageName;
79 
81  Common::Array<Common::Point> _startLocations;
82 
83  Common::Array<Common::Rect> _pieceSrcs;
85 
86  Common::Rect _verticalWallSrc;
87  Common::Rect _horizontalWallSrc;
88  Common::Rect _blockSrc;
89 
90  Common::Point _tileMoveExitPos = Common::Point(-1, -1);
91  uint _tileMoveExitSize = 0;
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  SceneChangeWithFlag _solveScene;
113  uint16 _solveSoundDelay = 0;
114  SoundDescription _solveSound;
115 
116  SceneChangeWithFlag _exitScene;
117  Common::Rect _exitHotspot;
118 
120  Common::Array<Piece> _pieces;
121 
122  int _currentlyAnimating = -1;
123  int _currentAnimFrame = -1;
124  Common::Point _lastPosition = { -1, -1 };
125 
126  uint32 _solveSoundPlayTime = 0;
127  bool _solved = false;
128 
129  uint32 _puzzleStartTime = 0;
130  int _currentTimerGraphic = -1;
131 
132  PuzzleType _puzzleType;
133 };
134 
135 } // End of namespace Action
136 } // End of namespace Nancy
137 
138 #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:149
Definition: renderobject.h:36
Definition: rect.h:144
Definition: commontypes.h:255
Definition: actionmanager.h:32
Definition: collisionpuzzle.h:56