Screenshots with F9.
[sdlbotor.git] / Object.cpp
blob569c2ed6ad2b49dcb975e5f291235e0712a1b96c
1 #include <iostream>
3 #include "Object.h"
4 #include "Game.h"
5 #include "DTile.h"
6 #include "DAnimation.h"
7 #include "Player.h"
9 namespace botor
12 Tileset Object::OBJECTS_TILESET( "objects.png" );
14 Object::Object( ObjectClass *CLASS, Sint16 X, Sint16 Y ) : MapObject( X, Y )
16 Init( CLASS );
20 Object::Object( ObjectClass *CLASS ) : MapObject( 0, 0 )
22 Init( CLASS );
25 void Object::Init( ObjectClass *CLASS )
27 oclass = CLASS;
29 oLoc = Object::LOC_GROUND;
31 switch( oclass->graphic )
33 case ObjectClass::GRA_TILE:
34 graphic = new DTile( &Object::OBJECTS_TILESET, oclass->tile_id );
35 break;
36 case ObjectClass::GRA_ANIMATION:
37 break;
38 default:
39 break;
44 Object::~Object() {}
47 void Object::OnActivation( Player *p )
49 if( oclass->OnActivation != LUA_REFNIL )
51 lua_rawgeti( Game::LUA, LUA_REGISTRYINDEX, oclass->OnActivation );
52 lua_pushlightuserdata( Game::LUA, this );
53 lua_call( Game::LUA, 1, 0 );
57 void Object::OnPickup( Player *p )
59 if( oclass->OnPickup != LUA_REFNIL )
61 lua_rawgeti( Game::LUA, LUA_REGISTRYINDEX, oclass->OnPickup );
62 lua_pushlightuserdata( Game::LUA, this );
63 lua_call( Game::LUA, 1, 0 );
67 void Object::OnDrop( Player *p )
69 if( oclass->OnDrop != LUA_REFNIL )
71 lua_rawgeti( Game::LUA, LUA_REGISTRYINDEX, oclass->OnDrop );
72 lua_pushlightuserdata( Game::LUA, this );
73 lua_call( Game::LUA, 1, 0 );
77 void Object::OnPlayerOnTile( Player *p )
79 if( oclass->OnPlayerOnTile != LUA_REFNIL )
81 lua_rawgeti( Game::LUA, LUA_REGISTRYINDEX, oclass->OnPlayerOnTile );
82 lua_pushlightuserdata( Game::LUA, this );
83 lua_call( Game::LUA, 1, 0 );
85 else //standard action
87 p->Pickup( this );
91 /* bool Object::checkID( std::string id )
93 return oclass->id == id;
96 std::string & Object::getID( )
98 return oclass->id;
99 }*/