Show Tile.cpp syntax highlighted
/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG *
*Copyright (C) 2006, Tony Sparks *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
#include "StdAfx.h"
#include "Tile.h"
//#include "event.h"
#include "../kernel.h"
extern Kernel* g_kernel;
Tile::Tile(void)
{
m_row = 1;
m_col = 1;
m_x = 0;
m_y = 0;
}
/**
===============================================================================
Tile Def
===============================================================================
*/
int Tile::Init(Image* image)
{
m_image = image;
if ( m_image )
{
m_width = image->width;
m_height = image->height;
// std::cout << m_width << std::endl;
} else return 1;
m_x = 0;
m_y = 0;
return 0;
}
void Tile::Update(long dt)
{
// Do nothing!
}
void Tile::Render( IRender *r )
{
r->DrawSubImage( m_image, m_x, m_y, m_row, m_col );
}
void Tile::AddEvent( MPoint p, MEvent* evnt )
{
std::pair<int, int> pair;
pair.first = p.x;
pair.second = p.y;
m_events[pair] = evnt;
}
//
/** Trigger the event */
void Tile::Trigger( IEntity* triggerer, MPoint p )
{
std::pair<int, int> pair;
pair.first = p.x;
pair.second = p.y;
if ( m_events.find( pair ) != m_events.end() )
{ MEvent* evnt = m_events[pair];
if ( evnt ) {
// g_kernel->GetConsole()->Print( "%3.2f %3.2f", evnt->destination.x,evnt->destination.y);
if ( evnt->destination.Length() )
triggerer->MoveTo( evnt->destination );
if ( evnt->damage )
triggerer->Damage( evnt->damage );
}
}
}
Tile::~Tile(void)
{
}
See more files for this project here