source: trunk/monsterz/piece.cpp @ 227

Last change on this file since 227 was 227, checked in by sam, 11 years ago

Spawn several pieces in Monsterz now that we can.

File size: 1.3 KB
Line 
1//
2// Monsterz
3//
4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16#include <cmath>
17
18#include "core.h"
19#include "piece.h"
20#include "monsterz.h"
21
22/*
23 * Piece implementation class
24 */
25
26class PieceData
27{
28    friend class Piece;
29
30private:
31    Game *game;
32    int tiler;
33    int i, j, id;
34};
35
36/*
37 * Public Piece class
38 */
39
40Piece::Piece(Game *game, int i, int j, int id)
41{
42    data = new PieceData();
43    data->game = game;
44    Ticker::Ref(game);
45    data->tiler = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
46    data->i = i;
47    data->j = j;
48    data->id = id;
49}
50
51void Piece::TickGame(float deltams)
52{
53    Entity::TickGame(deltams);
54}
55
56void Piece::TickDraw(float deltams)
57{
58    Entity::TickDraw(deltams);
59
60    int id = data->id;
61    int i = data->i;
62    int j = data->j;
63    data->game->GetScene()->AddTile((data->tiler << 16) | id,
64                                    i * 48 + 24, j * 48 + 177, 2, 0);
65}
66
67Piece::~Piece()
68{
69    Ticker::Unref(data->game);
70    Tiler::Deregister(data->tiler);
71    delete data;
72}
73
Note: See TracBrowser for help on using the repository browser.