コード例 #1
0
ファイル: main.cpp プロジェクト: andyfriesen/ika
// This sucks.  It uses static varaibles, so it's not useful at all for any entity other than the player, among other things. 
void Engine::TestActivate(const Entity* player) {
    CDEBUG("testactivate");
    Sprite* sprite = player->sprite;

    int tx = (player->x + sprite->nHotw / 2) / tiles->Width();
    int ty = (player->y + sprite->nHoth / 2) / tiles->Height();

    if (player->isMoving) {
        Map::Layer::Zone* zone = TestZoneCollision(player);
        if (zone) {
            if (map.zones.count(zone->label)) {
                Map::Zone& bluePrint = map.zones[zone->label];
                if (!bluePrint.scriptName.empty()) {
                    script.CallScript(bluePrint.scriptName);
                    SyncTime();
                }
            }
            else {
                Log::Write("No blueprint %s exists!", zone->label.c_str());
            }
        }
    }

    // adjacent activation
    bool b = the<Input>()->enter->Pressed();
    if (!b) return; // Don't check the rest unless enter was pressed.

    tx = player->x; ty = player->y;
    // entity activation
    switch(player->direction) {
        case face_up:        ty -= sprite->nHoth;    break;
        case face_down:      ty += sprite->nHoth;    break;
        case face_left:      tx -= sprite->nHotw;    break;
        case face_right:     tx += sprite->nHotw;    break;

        case face_upleft:    tx -= sprite->nHotw;    ty -= sprite->nHoth;    break;
        case face_upright:   tx += sprite->nHotw;    ty -= sprite->nHoth;    break;
        case face_downleft:  tx -= sprite->nHotw;    ty += sprite->nHoth;    break;
        case face_downright: tx += sprite->nHotw;    ty += sprite->nHoth;    break;
		default: break;// do nothing
    }

    Entity* ent = DetectEntityCollision(0 , tx, ty, sprite->nHotw, sprite->nHoth, player->layerIndex);
    if (ent) {
        if (ent->activateScript) {
            the<Input>()->Unpress();
            script.ExecObject(ent->activateScript);
            the<Input>()->Flush();
            SyncTime();
            return;
        }
    }
}
コード例 #2
0
void CVanaTime::setCustomOffset(int32 offset)
{
	m_customOffset = offset;

	SyncTime();

	if (m_vHour >= 20)      m_TimeType = TIME_NIGHT;
	else if (m_vHour >= 18) m_TimeType = TIME_EVENING;
	else if (m_vHour >= 17) m_TimeType = TIME_DUSK;
	else if (m_vHour >=  7) m_TimeType = TIME_DAY;
	else if (m_vHour >=  6) m_TimeType = TIME_DAWN;
	else if (m_vHour >=  4) m_TimeType = TIME_NEWDAY;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: andyfriesen/ika
void Engine::CheckKeyBindings() {
    // The "queue" is only one element big.  Unless someone hit two buttons in the same instant,
    // nobody will notice. (hopefully)

    if (ScriptObject* func = the<Input>()->GetQueuedEvent()) {
        // The key that triggered the event would be initially pressed if not for this.
        // This is not useful behaviour.
        the<Input>()->Unpress();
        script.ExecObject(*func);
        the<Input>()->Flush();
        SyncTime();
    }
}
コード例 #4
0
ファイル: main.cpp プロジェクト: andyfriesen/ika
void Engine::MainLoop() {
    CDEBUG("mainloop");
    // static int numframes, t = 0, fps = 0;                           // frame counter stuff (Why do these need to be static?)

    ScopedPtr<Ika::Font> font;
    try {
        font = new Ika::Font("system.fnt", video);
    } catch (Ika::FontException) {
        font = 0;
        _showFramerate = false;
    }

    int now = GetTime();
    SyncTime();

    for (;;) {
        CheckMessages();

        int skipcount = 0;

        while (
            (_oldTime < now) && 
            (skipcount <= _frameSkip)) {
            GameTick();
            _oldTime++;
            skipcount++;
        }

        _oldTime = now;
        now = GetTime();

        Render();

        if (_showFramerate) {
            font->PrintString(0, 0, va("Fps: %i", video->GetFrameRate()));
        }

        video->ShowPage();
    }
}
コード例 #5
0
ファイル: vana_time.cpp プロジェクト: Vanion-/darkstar
void CVanaTime::setCustomOffset(int32 offset)
{
	m_customOffset = offset;
	m_TimeType = SyncTime();
}
コード例 #6
0
ファイル: main.cpp プロジェクト: andyfriesen/ika
// Most of the work involved here is storing the various parts of the v2-style map into memory under the new structure. 
void Engine::LoadMap(const std::string& filename) {
    CDEBUG("loadmap");

    std::string mapPath = IkaPath::_map;
    std::string mapName = IkaPath::_map + filename;
    std::string fullPath = IkaPath::_game + mapName;

    try {
        Log::Write("Loading map \"%s\"", mapName.c_str());

        std::string oldTilesetName = mapPath + map.tilesetName;

        bool result = map.Load(fullPath);

        if (!result) {
            throw std::runtime_error("LoadMap(\"%s\") failed: invalid map file?");
        }

        // Reset the default render list.
        renderList.clear();
        for (uint i = 0; i < map.NumLayers(); i++) {
            renderList.push_back(i);
        }

        // Only load the tileset if it's different
        if (mapPath + map.tilesetName != oldTilesetName) {
            delete tiles;                                               // nuke the old tileset
            tiles = new Tileset(mapPath + map.tilesetName, video);               // load up them tiles
        }

        script.ClearEntityList();

        std::map<const Map::Entity*, Entity*> entMap;                   // used so we know which is related to which, so we can properly gather objects from the map script. (once it's loaded)

        // for each layer, create entities
        for (uint curLayer = 0; curLayer < map.NumLayers(); curLayer++) {
            const Map::Layer* lay = map.GetLayer(curLayer);
            const std::vector<Map::Entity>& ents = lay->entities;

            for (uint curEnt = 0; curEnt < ents.size(); curEnt++) {
                Entity* ent = new Entity(this, ents[curEnt], curLayer);
                entities.push_back(ent);
                ent->sprite = sprite.Load(ent->spriteName, video);
                script.AddEntityToList(ent);

                entMap[&ents[curEnt]] = ent;
            }
        }

        xwin = ywin = 0;                                                // just in case
        _isMapLoaded = true;

        if (!script.LoadMapScripts(mapName)) {
            Script_Error();
        }

        // Now that the scripts have been loaded, it's time to get the movement and activation scripts for the entities
        for (std::map<const Map::Entity*, Entity*>::iterator
            iter = entMap.begin();
            iter != entMap.end();
            iter++
        ) {
            // if they're already nonzero, they changed in the init code, so we shouldn't change them.

            if (!iter->second->moveScript) {
                iter->second->moveScript = script.GetObjectFromMapScript(iter->first->moveScript);
            }

            if (!iter->second->activateScript) {
                iter->second->activateScript = script.GetObjectFromMapScript(iter->first->activateScript);
            }

            if (!iter->second->adjActivateScript) {
                iter->second->adjActivateScript = script.GetObjectFromMapScript(iter->first->adjActivateScript);
            }
        }

        SyncTime();
    } catch (std::runtime_error err) {   
        Sys_Error(va("LoadMap(\"%s\"): %s", filename.c_str(), err.what())); 
    } catch (TilesetException) {
        Sys_Error(va("Unable to load tileset %s", map.tilesetName.c_str())); 

#if 0 // pending removal    
    } catch (const char* msg) {
        Sys_Error(va("Failed to load %s", msg));                            
    } catch (const std::string& msg)  {   
        Sys_Error(va("Failed to load %s", msg.c_str()));                    
#endif

    }
}