public void InitObj(ControlledObject obj) { allMyObjects.Add(obj); BaseMountObject mounted = obj as BaseMountObject; if (mounted != null) { allUseableObject.Add(mounted); } obj.Init(this); }
public void Drop() { if (!ControlledObject) { return; } //drop held item ControlledObject.GetComponent <InteractionListener>().OnDrop(this); AllControlledObjects.Remove(ControlledObject); ControlledObject = null; }
public void Play() { bool wasRunning; lock (m_KeyframeLock) { wasRunning = m_Program.IsRunning; ControlledObject.IsMoving = true; m_Program.IsRunning = true; m_KeyframeTimer.Enabled = true; } if (!wasRunning) { ControlledObject.PostEvent(new MovingStartEvent()); } }
public void Grab() { if (ControlledObject) { return; } if (!NearestObject) { return; } //grab nearest object ControlledObject = NearestObject; AllControlledObjects.Add(ControlledObject); ControlledObject.GetComponent <InteractableObject>().OnGrab(this); }
public void Pause() { bool wasRunning; lock (m_KeyframeLock) { ControlledObject.Velocity = Vector3.Zero; ControlledObject.AngularVelocity = Vector3.Zero; wasRunning = m_Program.IsRunning; ControlledObject.IsMoving = false; m_Program.IsRunning = false; m_KeyframeTimer.Enabled = false; } if (!wasRunning) { ControlledObject.PostEvent(new MovingStartEvent()); } }
public void ActivateWayMovement() { MapCurve way = null; { EntityComponent_ForTankDemo component = (EntityComponent_ForTankDemo) ControlledObject.Component_GetFirstWithType(typeof(EntityComponent_ForTankDemo)); if (component != null) { way = component.Way; } } if (way != null) { DoGeneralTask(GeneralTaskTypes.WayMove, way); } }
public void UpdateTransformBeforeCameraPositionCalculation() { if (Instance == this) { if (EntitySystemWorld.Instance.IsClientOnly()) { if (ControlledObject != null) { ControlledObject.Client_UpdatePositionsBySnapshots(true); } } Vec3 turnToPosition; if (GetTurnToPosition(out turnToPosition)) { UpdateTurnToPositionForUnits(turnToPosition); } } }
/** * <summary> * This is the main VirtualWorld procedure, which starts to moving all the required objects * Tries to find the first collision or no collision and animates the objects * </summary> */ public void Animate(float deltaTime) { // Generate movements foreach (var ControlledObject in GetPhysicGameObjects()) { ControlledObject.CalculateDisplacement(deltaTime); } // Generate the fastest collision float fastestCollisionTime = deltaTime; var fastestCollision = CollisionResponser.DoTheFastestCollision( GetCollisableGameObjects().Where(x => !x.CurrentlyStaticYesNo).ToList() ); // commit the first collision // ... // When we have collision, animate only to the first one // and recursively do the same if (fastestCollision != null) { // Commit the movement foreach (var ControlledObject in GetPhysicGameObjects()) { ControlledObject.CommitDisplacementPartially(fastestCollision.CollisionDeltaTime); // TODO: should recalculate displacements for both collisioned objects } Animate(deltaTime - fastestCollision.CollisionDeltaTime); } else // no collision { // Commit the movement foreach (var ControlledObject in GetPhysicGameObjects()) { ControlledObject.CommitDisplacement(); } AnimateGravity(); } }
public void Stop() { bool wasRunning; lock (m_KeyframeLock) { ControlledObject.Velocity = Vector3.Zero; ControlledObject.AngularVelocity = Vector3.Zero; wasRunning = m_Program.IsRunning; ControlledObject.IsMoving = false; m_Program.IsRunning = false; m_KeyframeTimer.Enabled = false; /* reset program */ m_Program.CurrentFrame = -1; } if (wasRunning) { ControlledObject.PostEvent(new MovingEndEvent()); } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SubscribeToTickEvent(); //get activationRegion EntityComponent_ForTankDemo component = (EntityComponent_ForTankDemo) ControlledObject.Component_GetFirstWithType(typeof(EntityComponent_ForTankDemo)); if (component != null) { activationRegion = component.ActivationRegion; } //listen activationRegion if (activationRegion != null) { activationRegion.ObjectIn += ActivationRegion_ObjectIn; } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SubscribeToTickEvent(); MapCurve way = null; { EntityComponent_SSDC component = (EntityComponent_SSDC) ControlledObject.Component_GetFirstWithType(typeof(EntityComponent_SSDC)); if (component != null) { way = component.Way; } } if (way != null) { Task(way); } }
public override void Move(MovementDirection movementDirection, double units) { switch (movementDirection) { case MovementDirection.Right: ControlledObject.Move(units, 0); break; case MovementDirection.UpRight: ControlledObject.Move(units, units * (-1)); break; case MovementDirection.Up: ControlledObject.Move(0, units * (-1)); break; case MovementDirection.UpLeft: ControlledObject.Move(units * (-1), units * (-1)); break; case MovementDirection.Left: ControlledObject.Move(units * (-1), 0); break; case MovementDirection.DownLeft: ControlledObject.Move(units * (-1), units); break; case MovementDirection.Down: ControlledObject.Move(0, units); break; case MovementDirection.DownRight: ControlledObject.Move(units, units); break; default: break; } }
void CheckPacmanCollision(xyLoc ghost, ControlledObject obj) { if (!obj.IsAlive()) { return; } if ((pacmanLoc.x + 4) / 8 == (ghost.x + 4) / 8 && (pacmanLoc.y + 4) / 8 == (ghost.y + 4) / 8) { if (currentGameMode == gameMode.kPowerUpGameMode) { obj.Kill(); GetSound(gameSound.kEatGhost).Play(); } else { currentGameMode = gameMode.kLifeOver; elapsedTime = 0; GetSound(gameSound.kBackgroundSound).Stop(); GetSound(gameSound.kDieSound).Play(); } } }
void ServerOrSingle_RestoreMainControlledUnit() { if (mainNotActiveUnit == null) { return; } if (ControlledObject != null) { ControlledObject.SetIntellect(null, false); ControlledObject.Destroying -= AlternativeUnitAllowPlayerControl_Destroying; } if (!mainNotActiveUnit.IsSetForDeletion) { mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = true; mainNotActiveUnit.Position = mainNotActiveUnitRestorePosition; //find free position for movable player controlled units if (ControlledObject != null) { //Tank, Car specific if (ControlledObject is Tank || ControlledObject is Car) { mainNotActiveUnit.Position = FindFreePositionForUnit( mainNotActiveUnit, ControlledObject.Position); } } mainNotActiveUnit.OldPosition = mainNotActiveUnit.Position; mainNotActiveUnit.Visible = true; UnsubscribeToDeletionEvent(mainNotActiveUnit); //restore contact groups for shapes if (mainNotActiveUnitShapeContactGroups != null) { foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies) { foreach (Shape shape in body.Shapes) { int group; if (mainNotActiveUnitShapeContactGroups.TryGetValue(shape, out group)) { shape.ContactGroup = group; } } } mainNotActiveUnitShapeContactGroups.Clear(); mainNotActiveUnitShapeContactGroups = null; } mainNotActiveUnit.SetIntellect(this, false); ControlledObject = mainNotActiveUnit; } else { ControlledObject = null; } mainNotActiveUnit = null; //send mainNotActiveUnit to clients if (EntitySystemWorld.Instance.IsServer()) { Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds); } }
private void KeyframeTimer(object o, ElapsedEventArgs args) { var scene = ControlledObject.KeyframeScene; if (scene == null || !scene.IsKeyframedMotionEnabled) { return; } lock (m_KeyframeLock) { bool newKeyframe = false; if (m_Program.CurrentFrame == -1) { m_Program.IsRunningReverse = false; m_Program.CurrentTimePosition = 0; m_Program.CurrentFrame = (m_Program.PlayMode == KeyframedMotion.Mode.Reverse) ? m_Program.Count - 1 : 0; newKeyframe = true; } else { m_Program.CurrentTimePosition += KEYFRAME_TIME_STEP; } var curFrame = m_Program[m_Program.CurrentFrame]; var flags = m_Program.Flags; if (curFrame.Duration < m_Program.CurrentTimePosition) { if (m_Program.IsRunningReverse) { if (--m_Program.CurrentFrame < 0) { m_Program.CurrentFrame = Math.Min(1, m_Program.Count); if (m_Program.PlayMode != KeyframedMotion.Mode.Reverse) { m_Program.IsRunningReverse = false; } else { if ((flags & KeyframedMotion.DataFlags.Translation) != 0) { ControlledObject.Velocity = Vector3.Zero; ControlledObject.Position = curFrame.TargetPosition; } if ((flags & KeyframedMotion.DataFlags.Rotation) != 0) { ControlledObject.AngularVelocity = Vector3.Zero; ControlledObject.Rotation = curFrame.TargetRotation; } m_Program.CurrentFrame = -1; ControlledObject.IsMoving = false; m_Program.IsRunning = false; m_KeyframeTimer.Enabled = false; ControlledObject.PostEvent(new MovingEndEvent()); return; } } } else { if (++m_Program.CurrentFrame == m_Program.Count) { switch (m_Program.PlayMode) { case KeyframedMotion.Mode.Forward: if ((flags & KeyframedMotion.DataFlags.Translation) != 0) { ControlledObject.Velocity = Vector3.Zero; ControlledObject.Position = curFrame.TargetPosition; } if ((flags & KeyframedMotion.DataFlags.Rotation) != 0) { ControlledObject.AngularVelocity = Vector3.Zero; ControlledObject.Rotation = curFrame.TargetRotation; } m_Program.CurrentFrame = -1; ControlledObject.IsMoving = false; m_Program.IsRunning = false; m_KeyframeTimer.Enabled = false; ControlledObject.PostEvent(new MovingEndEvent()); return; case KeyframedMotion.Mode.Loop: m_Program.CurrentFrame = 0; break; case KeyframedMotion.Mode.PingPong: if (--m_Program.CurrentFrame < 0) { m_Program.CurrentFrame = 0; } m_Program.IsRunningReverse = true; break; default: break; } } } newKeyframe = true; m_Program.CurrentTimePosition = 0f; } curFrame = m_Program[m_Program.CurrentFrame]; if (newKeyframe) { if ((flags & KeyframedMotion.DataFlags.Translation) != 0) { var distance = curFrame.TargetPosition; ControlledObject.Velocity = distance / curFrame.Duration; } if ((flags & KeyframedMotion.DataFlags.Rotation) != 0) { var angularDistance = (curFrame.TargetRotation / ControlledObject.Rotation).GetAngularDisplacement(); ControlledObject.AngularVelocity = angularDistance / curFrame.Duration; } } else { if ((flags & KeyframedMotion.DataFlags.Translation) != 0) { ControlledObject.Position += ControlledObject.Velocity; } if ((flags & KeyframedMotion.DataFlags.Rotation) != 0) { ControlledObject.Rotation *= Quaternion.CreateFromEulers(ControlledObject.AngularVelocity); } } } }
xyLoc HandleAction(xyLoc currLoc, ControlledObject obj, bool canEat) { GameMaze m = board.GetComponent <BoardController> ().GetMaze(); GameController.direction act = obj.GetAction(m, this, currLoc); switch (act) { case direction.kUp: if (CanMove(currLoc, direction.kUp)) { currLoc.y++; if (canEat) { pacmanLastMove = direction.kUp; } } break; case direction.kDown: if (CanMove(currLoc, direction.kDown)) { currLoc.y--; if (canEat) { pacmanLastMove = direction.kDown; } } break; case direction.kRight: if (CanMove(currLoc, direction.kRight)) { currLoc.x++; if (canEat) { pacmanLastMove = direction.kRight; } } break; case direction.kLeft: if (CanMove(currLoc, direction.kLeft)) { currLoc.x--; if (canEat) { pacmanLastMove = direction.kLeft; } } break; } if (currLoc.x < 0) { currLoc.x = pixelWidth - 9; } if (currLoc.x >= pixelWidth - 8) { currLoc.x = 0; } if (AtGridCenter(currLoc) && canEat) { bool powerUp, dot; eatenDots += board.GetComponent <BoardController> ().ClearCell(currLoc.x / 8, currLoc.y / 8, out dot, out powerUp); if (powerUp) { StartPowerUp(); GetSound(gameSound.kEatPowerup).Play(); } else if (dot) { GetSound(gameSound.kEatDot).Play(); } if (eatenDots == 244) { eatenDots = 0; currentGameMode = gameMode.kLevelComplete; GetSound(gameSound.kBackgroundSound).Stop(); } } return(currLoc); }