public void OnAction(Entity entity) { if ((entity.Mask & MASK) == MASK) { ComponentGeometry geometryComponent = (ComponentGeometry)entity.FindComponent(ComponentTypes.COMPONENT_GEOMETRY); Geometry geometry = geometryComponent.Geometry(); ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); //Vector3 position = transformComponent.Position; //Vector3 scale = transformComponent.Scale; //Vector3 rotation = transformComponent.Rotation; //Matrix4 translateMatrix = Matrix4.CreateTranslation(position); //Matrix4 scaleMatrix = Matrix4.CreateScale(scale); //Matrix4 xRotMatrix = Matrix4.CreateRotationX(rotation.X); //Matrix4 yRotMatrix = Matrix4.CreateRotationY(rotation.Y); //Matrix4 zRotMatrix = Matrix4.CreateRotationZ(rotation.Z); //Matrix4 rotMatrix = xRotMatrix * yRotMatrix * zRotMatrix; //Matrix4 world = rotMatrix * scaleMatrix * translateMatrix; Matrix4 world = transformComponent.Transform; ComponentTexture textureComponent = (ComponentTexture)entity.FindComponent(ComponentTypes.COMPONENT_TEXTURE); int texture = textureComponent.Texture; Draw(world, geometry, texture); } }
/// <summary> /// Game engine gameplay update /// </summary> /// <param name="e"></param> public override void Update(FrameEventArgs e) { float dt = (float)e.Time; // Checks if the game is over and acts accordingly if (Rounds <= 0) { sceneManager.NextScene(); } // Handle AI player turn if (!isPlayer1 && isAI) { AiInputTimer += dt; if (AiInputTimer >= 0.5f) { GenerateAiInput(InputID); AiInputTimer = 0.0f; InputID++; } } // Handles the banana and its animation Handle_BananaTrajectory(dt); SystemAnimator Animator = (SystemAnimator)systemManager.FindSystem("SystemAnimator"); Animator.UpdateDeltaTime(dt); // Handles the hitting sun effect where its texture gets changed if (hasHitSun) { sunHitTimer += dt; if (sunHitTimer >= 2.0f) { ComponentTexture texture = (ComponentTexture)entityManager.FindEntity("SunFace").FindComponent(ComponentTypes.COMPONENT_TEXTURE); texture.Texture = ResourceManager.LoadTexture("Textures/sun_1.png"); sunHitTimer = 0.0f; hasHitSun = false; } } }
/// <summary> /// Handles the projectile entity movement and collision triggers /// </summary> /// <param name="pCollide">The system collider being used</param> /// <param name="pTrajectory">Trajectory values calculated</param> private void HandleBananaMovement(ref SystemColliderXY pCollide, Vector2 pTrajectory) { // Used to time out banana if trajectory takes it out of camera view float MaxTravelTime = 6.0f; // Updates the bananas position with next increment of the trajectory calculation ComponentPosition pos = (ComponentPosition)entityManager.FindEntity("Banana").FindComponent(ComponentTypes.COMPONENT_POSITION); pos.Position = new Vector3(pTrajectory.X, pTrajectory.Y, pos.Position.Z); // Updates the collision system with new position for checks pCollide.UpdatePosition(pos.Position); // Used to determine whether collision happened bool hasCollided = false; // If collision system has found a trigger then take action if (pCollide.GetEntityCollisionTrigger() != null && pCollide.GetEntityCollisionTrigger() != "") { if (pCollide.GetEntityCollisionTrigger().Contains("Gorilla")) { SoundEffects[2].UpdateEmitterPosition(sceneManager.camera.Position); SoundEffects[2].PlayAudio(); EndRound(pCollide.GetEntityCollisionTrigger()); pCollide.ClearLastDestructable(); } else if (pCollide.GetEntityCollisionTrigger().Contains("Sun")) { ComponentTexture texture = (ComponentTexture)entityManager.FindEntity("SunFace").FindComponent(ComponentTypes.COMPONENT_TEXTURE); texture.Texture = ResourceManager.LoadTexture("Textures/sun_2.png"); hasHitSun = true; pCollide.ClearLastTrigger(); } else { SoundEffects[1].UpdateEmitterPosition(pos.Position); SoundEffects[1].VolumeOfAudio = 0.4f; SoundEffects[1].PlayAudio(); // Remove all building blocks around hit point DestroySkyline(pCollide.GetEntityCollisionTrigger()); // Clear collision system ready for next collision detection pCollide.ClearLastDestructable(); // Updates the collision system with new banana position pos.Position = new Vector3(0.0f, -50.0f, pos.Position.Z); pCollide.UpdatePosition(pos.Position); // Sets collision to true so game can progress to next player hasCollided = true; } } // If the banana has flown too long, fallen too low or has collided then progress to next player if (ProjectileTime >= MaxTravelTime || pTrajectory.Y < -5.0f || hasCollided) { // Used to determine which input is being entered (set to zero as current player is done) InputID = 0; // Readies time value for next trajectory ProjectileTime = 0.0f; // Switches which player is active if (isPlayer1) { isPlayer1 = false; } else { isPlayer1 = true; } } }
private static XmlNode SaveComponentTexture(XmlDocument file, ComponentTexture component) { return(null); }
public void ItemCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, Entity item, ComponentAudio faudioComponent, ComponentTexture ftextureComponent) { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1 && ftextureComponent.Texture != 0) { faudioComponent.Start(); ftextureComponent.remove(); fpositionComponent.Position = offscreen; } }