static NodeSmartReference Entity_parseTokens (Tokeniser& tokeniser, EntityCreator& entityTable, const PrimitiveParser& parser, int index) { NodeSmartReference entity(g_nullNode); KeyValues keyValues; std::string classname = ""; int count_primitives = 0; while (1) { std::string token = tokeniser.getToken(); if (token.empty()) { Tokeniser_unexpectedError(tokeniser, token, "#entity-token"); return g_nullNode; } if (token == "}") { // end entity if (entity == g_nullNode) { // entity does not have brushes entity = Entity_create(entityTable, GlobalEntityClassManager().findOrInsert(classname, false), keyValues); } return entity; } else if (token == "{") { // begin primitive if (entity == g_nullNode) { // entity has brushes entity = Entity_create(entityTable, GlobalEntityClassManager().findOrInsert(classname, true), keyValues); } NodeSmartReference primitive(parser.parsePrimitive(tokeniser)); if (primitive == g_nullNode || !Node_getMapImporter(primitive)->importTokens(tokeniser)) { globalErrorStream() << "brush " << count_primitives << ": parse error\n"; return g_nullNode; } scene::Traversable* traversable = Node_getTraversable(entity); if (Node_getEntity(entity)->isContainer() && traversable != 0) { traversable->insert(primitive); } else { globalErrorStream() << "entity " << index << ": type " << classname << ": discarding brush " << count_primitives << "\n"; } ++count_primitives; } else { // epair const std::string key = token; token = tokeniser.getToken(); if (token.empty()) { Tokeniser_unexpectedError(tokeniser, token, "#epair-value"); return g_nullNode; } keyValues.push_back(KeyValues::value_type(key, token)); if (key == "classname") classname = keyValues.back().second; } } // unreachable code return g_nullNode; }
void Entity_createFromSelection (const std::string& name, const Vector3& origin) { try { bool revert = Entity_create(name, origin); if (revert) { GlobalUndoSystem().undo(); GlobalUndoSystem().clearRedo(); GlobalSceneGraph().sceneChanged(); } } catch (EntityCreationException e) { gtkutil::errorDialog(e.what()); } }
Entity* Missile_create() { Entity *entity = Entity_create(); entity->type = ENTITY_MISSILE; entity->width = 1; entity->height = 1; entity->x = -1; entity->y = -1; entity->think = Missile_think; entity->draw = Missile_draw; return entity; }
Enemy* Enemy_createWhiteKnight(Scene* scene, SDL_Point tilePos) { Enemy* this = malloc(sizeof(Enemy)); AnimatedSprite* sprite = AnimatedSprite_create(Sprite_create(TextureCache_get(scene->engine->textureCache, "images/whiteKnight.png"))); Animation* idleAnimation = Animation_create("idle", true); List_pushBack(idleAnimation->frames, Frame_create(0,0, 32, 32, 200)); List_pushBack(idleAnimation->frames, Frame_create(32,0, 32, 32, 200)); List_pushBack(idleAnimation->frames, Frame_create(64,0, 32, 32, 200)); List_pushBack(idleAnimation->frames, Frame_create(32,0, 32, 32, 200)); List_pushBack(sprite->animations, idleAnimation); Animation* attack1PrepareAnimation = Animation_create(ANIMATION_PREPARE_ATTACK1, false); List_pushBack(attack1PrepareAnimation->frames, Frame_create(0, 32, 32, 32, 60)); List_pushBack(attack1PrepareAnimation->frames, Frame_create(32,32, 32, 32, 60)); List_pushBack(attack1PrepareAnimation->frames, Frame_create(0, 32, 32, 32, 60)); List_pushBack(sprite->animations, attack1PrepareAnimation); Animation* attack1Animation = Animation_create(ANIMATION_ATTACK1, false); List_pushBack(attack1Animation->frames, Frame_create(64,32, 36, 32, 120)); List_pushBack(sprite->animations, attack1Animation); AnimatedSprite_setFrame(sprite, ((Frame*)idleAnimation->frames->first->data)->rect); sprite->progress.animation = idleAnimation; sprite->sprite->flip = false; Entity* entity = Entity_create(this, scene, sprite); entity->draw = Enemy_draw; entity->update = Enemy_update; entity->destroy = Enemy_destroy; entity->physics.bounds.x = tilePos.x * TILE_W * PHYSICS_SCALE; entity->physics.bounds.y = tilePos.y * TILE_H * PHYSICS_SCALE; entity->physics.bounds.w = 15 * PHYSICS_SCALE; // Make sure Mr. Fatty get's though those slim trapdoors entity->physics.bounds.h = 15 * PHYSICS_SCALE; entity->physics.belongsToGroups = COLLISION_GROUP_ENEMY; entity->physics.collidesWithGroupMask = COLLISION_GROUP_TERRAIN | COLLISION_GROUP_PLAYER; entity->offset.x = -10; entity->offset.y = -17; this->entity = entity; return this; }