penguins  1.0.0
tileset.cc
Go to the documentation of this file.
1 #include "gui/tileset.hh"
2 #include "gui/canvas.hh"
3 #include "resources_tileset_png.h"
4 #include <wx/debug.h>
5 #include <wx/defs.h>
6 #include <wx/gdicmn.h>
7 #include <wx/image.h>
8 #include <wx/mstream.h>
9 
10 TilesetHelper::TilesetHelper() : scaling(CanvasPanel::TILE_SIZE / TilesetHelper::TILE_SIZE) {}
11 
13  wxMemoryInputStream stream(resources_tileset_png, resources_tileset_png_size);
14  this->image.LoadFile(stream, wxBITMAP_TYPE_PNG);
15  wxASSERT(this->image.IsOk());
16  wxSize image_size = this->image.GetSize();
17  this->image.Rescale(image_size.x * scaling, image_size.y * scaling, wxIMAGE_QUALITY_NEAREST);
18 
19  this->transparent_tile = get_tile(4, 1);
20  for (int i = 0; i < int(WXSIZEOF(this->ice_tiles)); i++) {
21  this->ice_tiles[i] = get_tile(0 + i % 3, 0 + i / 3);
22  }
23  for (int i = 0; i < int(WXSIZEOF(this->water_tiles)); i++) {
24  this->water_tiles[i] = get_tile(0 + i % 3, 2 + i / 3);
25  }
26  this->tile_edges[EDGE_TOP] = get_tile(4, 2);
27  this->tile_edges[EDGE_RIGHT] = get_tile(3, 1);
28  this->tile_edges[EDGE_BOTTOM] = get_tile(4, 0);
29  this->tile_edges[EDGE_LEFT] = get_tile(5, 1);
38  this->blocked_tile = get_tile(7, 0);
39  this->grid_tile = get_tile(6, 0);
40  for (int i = 0; i < int(WXSIZEOF(this->fish_sprites)); i++) {
41  this->fish_sprites[i] = get_tile(5 + i, 3);
42  }
43  for (int i = 0; i < int(WXSIZEOF(this->penguin_sprites)); i++) {
44  auto tile = get_tile(0 + i, 3);
45  this->penguin_sprites[i] = tile;
46  this->penguin_sprites_flipped[i] = tile.Mirror(/* horizontally */ true);
47  }
48  this->current_penguin_overlay = get_tile(1, 4);
49 }
Responsible for drawing the board and painting the UI overlays.
Definition: canvas.hh:17
wxBitmap tile_edges[EDGE_MAX]
Definition: tileset.hh:55
wxBitmap water_tiles[3]
Definition: tileset.hh:53
wxBitmap ice_tiles[6]
Definition: tileset.hh:54
wxBitmap grid_tile
Definition: tileset.hh:59
const int scaling
Definition: tileset.hh:49
wxBitmap penguin_sprites[5]
Definition: tileset.hh:61
wxBitmap tile_concave_corners[CORNER_MAX]
Definition: tileset.hh:57
wxBitmap fish_sprites[3]
Definition: tileset.hh:60
wxBitmap transparent_tile
Definition: tileset.hh:52
wxBitmap tile_convex_corners[CORNER_MAX]
Definition: tileset.hh:56
wxImage get_tile(const wxPoint &point) const
Definition: tileset.hh:40
wxBitmap current_penguin_overlay
Definition: tileset.hh:63
wxBitmap blocked_tile
Definition: tileset.hh:58
void load()
Definition: tileset.cc:12
wxImage image
Definition: tileset.hh:50
wxBitmap penguin_sprites_flipped[WXSIZEOF(penguin_sprites)]
Definition: tileset.hh:62
wxImage & Rescale(int width, int height, wxImageResizeQuality quality=wxIMAGE_QUALITY_NORMAL)
wxSize GetSize() const
virtual bool LoadFile(wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
bool IsOk() const
wxBITMAP_TYPE_PNG
#define wxASSERT(condition)
wxIMAGE_QUALITY_NEAREST
@ EDGE_RIGHT
Definition: tileset.hh:10
@ EDGE_BOTTOM
Definition: tileset.hh:11
@ EDGE_TOP
Definition: tileset.hh:9
@ EDGE_LEFT
Definition: tileset.hh:12
@ CORNER_TOP_RIGHT
Definition: tileset.hh:17
@ CORNER_BOTTOM_LEFT
Definition: tileset.hh:19
@ CORNER_TOP_LEFT
Definition: tileset.hh:20
@ CORNER_BOTTOM_RIGHT
Definition: tileset.hh:18