Collision ScriptTrigger::hitBy(Collidable* other) { Collision c; c = GameObject::hitBy(other); if(!script()->isRunning()) { if(c.collided()) { // Call onHit via the script engine. script()->callFunction(*this, (char*)"onHit", "o", (ScriptableObject*)other); } } // No collision if script is running return c; }
void State::updateObject(dur elapsedTime) { // Store current map in case of switch GameMap* current_map = m_map; if(!enabled) { return; } assert(engine() != NULL); // Process input controller if(engine()->hardware()) { processInput(); } if(!frameCounter) { return; } else { if(frameCounter > 0) { frameCounter--; } } // Run scripts if(script()->isRunning()) { script()->framestep(); } // Update map if(current_map != NULL) { // Make the cameraman work if(cameraman) { cameraman->update(elapsedTime); current_map->setPosition(cameraman->getCameraPosition()); } // Center map if(camTarget) { int targetX; int targetY; int camX; int camY; int curX; int curY; int localMaxCamSpeed = maxCamSpeed * elapsedTime; // Compute actual target coordinates if(camSecondaryTarget) { targetX = (camTarget->getX() + camSecondaryTarget->getX()) / 2; targetY = (camTarget->getY() + camSecondaryTarget->getY()) / 2; } else { targetX = camTarget->getX(); targetY = camTarget->getY(); } // Smooth object switching if(camSwitching) { camX = (-current_map->getX() * 3 + targetX) / 4; camY = (-current_map->getY() * 3 + targetY) / 4; curX = current_map->getX(); curY = current_map->getY(); } else { camX = targetX; camY = targetY; curX = camX; curY = camY; } // Limit camera speed if(camX + current_map->getX() > localMaxCamSpeed) { camX = -current_map->getX() + localMaxCamSpeed; } else if(-current_map->getX() - camX > localMaxCamSpeed) { camX = -current_map->getX() - localMaxCamSpeed; } if(camY + current_map->getY() > localMaxCamSpeed) { camY = -current_map->getY() + localMaxCamSpeed; } else if(-current_map->getY() - camY > localMaxCamSpeed) { camY = -current_map->getY() - localMaxCamSpeed; } // set camera position current_map->setPosition(-camX, -camY); // test if object switching is finished if(camSwitching) { if(abs(camX - targetX) < 5 && abs(camY - targetY) < 5) { camSwitching = false; } else if((curX == current_map->getX()) && (curY == current_map->getY())) { camSwitching = false; } } } // Update map current_map->update(elapsedTime); // Update mouse cursor #ifdef MOUSE_SUPPORT if(mouseCursor) { Collidable* current_mouse = mouseCursor; current_mouse->update(elapsedTime); Collision c = current_mouse->hitBy(current_map); if(c.collided()) { current_map->signal(current_mouse, MOUSE_MOVE, 0); } if(m_hud) { c = current_mouse->hitBy(m_hud); if(c.collided()) { m_hud->signal(current_mouse, MOUSE_MOVE, 0); } } } #endif } // Update hud if(m_hud != NULL) { m_hud->update(elapsedTime); } }