#include <scripted_object.hpp>
Inherits MovingSprite, scripting::ScriptedObject, and ScriptInterface.
Public Member Functions | |
ScriptedObject (const Reader &lisp) | |
virtual void | expose (HSQUIRRELVM vm, SQInteger table_idx) |
virtual void | unexpose (HSQUIRRELVM vm, SQInteger table_idx) |
void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
void | collision_solid (const CollisionHit &hit) |
this function is called when the object collided with something solid | |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
void | set_action (const std::string &animation) |
std::string | get_action () |
void | move (float x, float y) |
void | set_pos (float x, float y) |
float | get_pos_x () |
float | get_pos_y () |
void | set_velocity (float x, float y) |
float | get_velocity_x () |
float | get_velocity_y () |
void | set_visible (bool visible) |
bool | is_visible () |
void | set_solid (bool solid) |
bool | is_solid () |
std::string | get_name () |
Private Attributes | |
Physic | physic |
std::string | name |
a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique | |
bool | solid |
bool | physic_enabled |
bool | visible |
bool | new_vel_set |
Vector | new_vel |
Definition at line 25 of file scripted_object.hpp.
ScriptedObject::ScriptedObject | ( | const Reader & | lisp | ) |
Definition at line 26 of file scripted_object.cpp.
References MovingObject::bbox, COLGROUP_DISABLED, COLGROUP_MOVING_STATIC, lisp::Lisp::get(), MovingSprite::layer, LAYER_OBJECTS, name, physic_enabled, reader_get_layer(), MovingObject::set_group(), Rectf::set_size(), solid, MovingSprite::sprite, and visible.
00026 : 00027 MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING_STATIC), 00028 physic(), 00029 name(), 00030 solid(true), 00031 physic_enabled(true), 00032 visible(true), 00033 new_vel_set(false), 00034 new_vel() 00035 { 00036 lisp.get("name", name); 00037 if(name == "") 00038 throw std::runtime_error("Scripted object must have a name specified"); 00039 00040 // FIXME: do we need this? bbox is already set via .sprite file 00041 float width = sprite->get_width(); 00042 float height = sprite->get_height(); 00043 lisp.get("width", width); 00044 lisp.get("height", height); 00045 bbox.set_size(width, height); 00046 00047 lisp.get("solid", solid); 00048 lisp.get("physic-enabled", physic_enabled); 00049 lisp.get("visible", visible); 00050 layer = reader_get_layer (lisp, /* default = */ LAYER_OBJECTS); 00051 if( solid ){ 00052 set_group( COLGROUP_MOVING_STATIC ); 00053 } else { 00054 set_group( COLGROUP_DISABLED ); 00055 } 00056 }
void ScriptedObject::expose | ( | HSQUIRRELVM | vm, | |
SQInteger | table_idx | |||
) | [virtual] |
Implements ScriptInterface.
Definition at line 59 of file scripted_object.cpp.
References scripting::expose_object(), and name.
00060 { 00061 if (name.empty()) return; 00062 expose_object(vm, table_idx, dynamic_cast<scripting::ScriptedObject *>(this), name, false); 00063 }
void ScriptedObject::unexpose | ( | HSQUIRRELVM | vm, | |
SQInteger | table_idx | |||
) | [virtual] |
Implements ScriptInterface.
Definition at line 66 of file scripted_object.cpp.
References name, and scripting::unexpose_object().
00067 { 00068 if (name.empty()) return; 00069 scripting::unexpose_object(vm, table_idx, name); 00070 }
void ScriptedObject::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Reimplemented from MovingSprite.
Definition at line 165 of file scripted_object.cpp.
References Physic::get_movement(), MovingObject::movement, new_vel, new_vel_set, physic, physic_enabled, Physic::set_velocity(), Vector::x, and Vector::y.
00166 { 00167 if(!physic_enabled) 00168 return; 00169 00170 if(new_vel_set) { 00171 physic.set_velocity(new_vel.x, new_vel.y); 00172 new_vel_set = false; 00173 } 00174 movement = physic.get_movement(elapsed_time); 00175 }
void ScriptedObject::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Reimplemented from MovingSprite.
Definition at line 178 of file scripted_object.cpp.
References MovingObject::get_pos(), MovingSprite::layer, MovingSprite::sprite, and visible.
00179 { 00180 if(!visible) 00181 return; 00182 00183 sprite->draw(context, get_pos(), layer); 00184 }
void ScriptedObject::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
this function is called when the object collided with something solid
Reimplemented from MovingObject.
Definition at line 187 of file scripted_object.cpp.
References CollisionHit::bottom, Physic::get_velocity_y(), CollisionHit::left, physic, physic_enabled, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), and CollisionHit::top.
00188 { 00189 if(!physic_enabled) 00190 return; 00191 00192 if(hit.bottom) { 00193 if(physic.get_velocity_y() > 0) 00194 physic.set_velocity_y(0); 00195 } else if(hit.top) { 00196 physic.set_velocity_y(.1f); 00197 } 00198 00199 if(hit.left || hit.right) { 00200 physic.set_velocity_x(0); 00201 } 00202 }
HitResponse ScriptedObject::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 205 of file scripted_object.cpp.
References FORCE_MOVE.
00206 { 00207 return FORCE_MOVE; 00208 }
void ScriptedObject::set_action | ( | const std::string & | animation | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 147 of file scripted_object.cpp.
References MovingSprite::sprite.
00148 { 00149 sprite->set_action(animation); 00150 }
std::string ScriptedObject::get_action | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 153 of file scripted_object.cpp.
References MovingSprite::sprite.
00154 { 00155 return sprite->get_action(); 00156 }
void ScriptedObject::move | ( | float | x, | |
float | y | |||
) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 73 of file scripted_object.cpp.
References MovingObject::bbox, and Rectf::move().
void ScriptedObject::set_pos | ( | float | x, | |
float | y | |||
) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 79 of file scripted_object.cpp.
References MovingObject::bbox, physic, Physic::reset(), and Rectf::set_pos().
00080 { 00081 printf("SetPos: %f %f\n", x, y); 00082 bbox.set_pos(Vector(x, y)); 00083 physic.reset(); 00084 }
float ScriptedObject::get_pos_x | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 87 of file scripted_object.cpp.
References MovingObject::get_pos(), and Vector::x.
float ScriptedObject::get_pos_y | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 93 of file scripted_object.cpp.
References MovingObject::get_pos(), and Vector::y.
void ScriptedObject::set_velocity | ( | float | x, | |
float | y | |||
) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 99 of file scripted_object.cpp.
References new_vel, and new_vel_set.
00100 { 00101 new_vel = Vector(x, y); 00102 new_vel_set = true; 00103 }
float ScriptedObject::get_velocity_x | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 106 of file scripted_object.cpp.
References Physic::get_velocity_x(), and physic.
00107 { 00108 return physic.get_velocity_x(); 00109 }
float ScriptedObject::get_velocity_y | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 112 of file scripted_object.cpp.
References Physic::get_velocity_y(), and physic.
00113 { 00114 return physic.get_velocity_y(); 00115 }
void ScriptedObject::set_visible | ( | bool | visible | ) | [virtual] |
bool ScriptedObject::is_visible | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 124 of file scripted_object.cpp.
References visible.
00125 { 00126 return visible; 00127 }
void ScriptedObject::set_solid | ( | bool | solid | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 130 of file scripted_object.cpp.
References COLGROUP_DISABLED, COLGROUP_MOVING_STATIC, and MovingObject::set_group().
00131 { 00132 this->solid = solid; 00133 if( solid ){ 00134 set_group( COLGROUP_MOVING_STATIC ); 00135 } else { 00136 set_group( COLGROUP_DISABLED ); 00137 } 00138 }
bool ScriptedObject::is_solid | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 141 of file scripted_object.cpp.
References solid.
00142 { 00143 return solid; 00144 }
std::string ScriptedObject::get_name | ( | ) | [virtual] |
Implements scripting::ScriptedObject.
Definition at line 159 of file scripted_object.cpp.
References name.
00160 { 00161 return name; 00162 }
Physic ScriptedObject::physic [private] |
Definition at line 61 of file scripted_object.hpp.
Referenced by collision_solid(), get_velocity_x(), get_velocity_y(), set_pos(), and update().
std::string ScriptedObject::name [private] |
a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique
Reimplemented from GameObject.
Definition at line 62 of file scripted_object.hpp.
Referenced by expose(), get_name(), ScriptedObject(), and unexpose().
bool ScriptedObject::solid [private] |
bool ScriptedObject::physic_enabled [private] |
Definition at line 64 of file scripted_object.hpp.
Referenced by collision_solid(), ScriptedObject(), and update().
bool ScriptedObject::visible [private] |
Definition at line 65 of file scripted_object.hpp.
Referenced by draw(), is_visible(), and ScriptedObject().
bool ScriptedObject::new_vel_set [private] |
Vector ScriptedObject::new_vel [private] |