コード例 #1
0
ファイル: Creature.cs プロジェクト: maroussil/dwarfcorp
        public void DrawIndicator(IndicatorManager.StandardIndicators indicator)
        {
            if(!((DateTime.Now - LastIndicatorTime).TotalSeconds >= IndicatorRateLimit))
            {
                return;
            }

            IndicatorManager.DrawIndicator(indicator, AI.Position + new Vector3(0, 0.5f, 0), 1, 2, new Vector2(16, -16));
            LastIndicatorTime = DateTime.Now;
        }
コード例 #2
0
ファイル: WorldManager.cs プロジェクト: johan74/dwarfcorp
        /// <summary>
        /// Called every frame
        /// </summary>
        /// <param name="gameTime">The current time</param>
        public void Update(DwarfTime gameTime)
        {
            foreach (var func in LazyActions)
            {
                if (func != null)
                {
                    func.Invoke();
                }
            }
            LazyActions.Clear();

            if (FastForwardToDay)
            {
                if (Time.IsDay())
                {
                    FastForwardToDay = false;
                    foreach (CreatureAI minion in Master.Faction.Minions)
                    {
                        minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue;
                    }
                    //Master.ToolBar.SpeedButton.SetSpeed(1);
                    Time.Speed = 100;
                }
                else
                {
                    //Master.ToolBar.SpeedButton.SetSpecialSpeed(3);
                    Time.Speed = 1000;
                }
            }
            //ParticleManager.Trigger("dice", CursorLightPos + Vector3.Up, Color.White, 1);

            FillClosestLights(gameTime);
            IndicatorManager.Update(gameTime);
            AspectRatio        = GraphicsDevice.Viewport.AspectRatio;
            Camera.AspectRatio = AspectRatio;

            Camera.Update(gameTime, ChunkManager);
            HandleAmbientSound();

            Master.Update(Game, gameTime);
            GoalManager.Update(this);
            Time.Update(gameTime);
            if (LastWorldPopup != null)
            {
                List <uint> removals = new List <uint>();
                foreach (var popup in LastWorldPopup)
                {
                    popup.Value.Update(gameTime, Camera, GraphicsDevice.Viewport);
                    if (popup.Value.Widget == null || !Gui.RootItem.Children.Contains(popup.Value.Widget) ||
                        popup.Value.BodyToTrack == null || popup.Value.BodyToTrack.IsDead)
                    {
                        removals.Add(popup.Key);
                    }
                }

                foreach (var removal in removals)
                {
                    if (LastWorldPopup[removal].Widget != null && Gui.RootItem.Children.Contains(LastWorldPopup[removal].Widget))
                    {
                        Gui.DestroyWidget(LastWorldPopup[removal].Widget);
                    }
                    LastWorldPopup.Remove(removal);
                }
            }

            if (Paused)
            {
                ComponentManager.UpdatePaused();
                TutorialManager.Update(Gui);
            }
            // If not paused, we want to just update the rest of the game.
            else
            {
                ParticleManager.Update(gameTime, this);
                TutorialManager.Update(Gui);

                Diplomacy.Update(gameTime, Time.CurrentDate, this);
                Factions.Update(gameTime);
                ComponentManager.Update(gameTime, ChunkManager, Camera);
                Sky.TimeOfDay           = Time.GetSkyLightness();
                Sky.CosTime             = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f);
                DefaultShader.TimeOfDay = Sky.TimeOfDay;
                MonsterSpawner.Update(gameTime);
                bool allAsleep = Master.AreAllEmployeesAsleep();

#if !UPTIME_TEST
                if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight())
                {
                    SleepPrompt = new QueuedAnnouncement()
                    {
                        Text        = "All your employees are asleep. Click here to skip to day.",
                        ClickAction = (sender, args) =>
                        {
                            FastForwardToDay = true;
                            SleepPrompt      = null;
                        },
                        ShouldKeep = () =>
                        {
                            return(FastForwardToDay == false && Time.IsNight() && Master.AreAllEmployeesAsleep());
                        }
                    };
                    MakeAnnouncement(SleepPrompt);
                }
                else if (!allAsleep)
                {
                    Time.Speed       = 100;
                    FastForwardToDay = false;
                    SleepPrompt      = null;
                }
#endif
            }

            // These things are updated even when the game is paused

            Splasher.Splash(gameTime, ChunkManager.Water.GetSplashQueue());

            ChunkManager.Update(gameTime, Camera, GraphicsDevice);
            ChunkRenderer.Update(gameTime, Camera, GraphicsDevice);
            SoundManager.Update(gameTime, Camera, Time);
            Weather.Update(this.Time.CurrentDate, this);

            if (gameFile != null)
            {
                // Cleanup game file.
                gameFile = null;
            }
        }
コード例 #3
0
ファイル: WorldManager.cs プロジェクト: johan74/dwarfcorp
        /// <summary>
        /// Called when a frame is to be drawn to the screen
        /// </summary>
        /// <param name="gameTime">The current time</param>
        public void Render(DwarfTime gameTime)
        {
            if (!ShowingWorld)
            {
                return;
            }

            var frustum     = Camera.GetDrawFrustum();
            var renderables = EnumerateIntersectingObjects(frustum)
                              .Where(r => r.IsVisible && !ChunkManager.IsAboveCullPlane(r.GetBoundingBox()));

            // Controls the sky fog
            float x = (1.0f - Sky.TimeOfDay);

            x = x * x;
            DefaultShader.FogColor       = new Color(0.32f * x, 0.58f * x, 0.9f * x);
            DefaultShader.LightPositions = LightPositions;

            CompositeLibrary.Render(GraphicsDevice);
            CompositeLibrary.Update();

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;

            // Computes the water height.
            float wHeight = WaterRenderer.GetVisibleWaterHeight(ChunkManager, Camera, GraphicsDevice.Viewport,
                                                                lastWaterHeight);

            lastWaterHeight = wHeight;

            // Draw reflection/refraction images
            WaterRenderer.DrawReflectionMap(renderables, gameTime, this, wHeight - 0.1f,
                                            GetReflectedCameraMatrix(wHeight),
                                            DefaultShader, GraphicsDevice);


            #region Draw Selection Buffer.

            if (SelectionBuffer == null)
            {
                SelectionBuffer = new SelectionBuffer(8, GraphicsDevice);
            }

            GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;

            Plane slicePlane = WaterRenderer.CreatePlane(SlicePlane, new Vector3(0, -1, 0), Camera.ViewMatrix, false);

            if (SelectionBuffer.Begin(GraphicsDevice))
            {
                // Draw the whole world, and make sure to handle slicing
                DefaultShader.ClipPlane       = new Vector4(slicePlane.Normal, slicePlane.D);
                DefaultShader.ClippingEnabled = true;
                DefaultShader.View            = Camera.ViewMatrix;
                DefaultShader.Projection      = Camera.ProjectionMatrix;
                DefaultShader.World           = Matrix.Identity;

                //GamePerformance.Instance.StartTrackPerformance("Render - Selection Buffer - Chunks");
                ChunkRenderer.RenderSelectionBuffer(DefaultShader, GraphicsDevice, Camera.ViewMatrix);
                //GamePerformance.Instance.StopTrackPerformance("Render - Selection Buffer - Chunks");

                //GamePerformance.Instance.StartTrackPerformance("Render - Selection Buffer - Components");
                ComponentRenderer.RenderSelectionBuffer(renderables, gameTime, ChunkManager, Camera,
                                                        DwarfGame.SpriteBatch, GraphicsDevice, DefaultShader);
                //GamePerformance.Instance.StopTrackPerformance("Render - Selection Buffer - Components");

                //GamePerformance.Instance.StartTrackPerformance("Render - Selection Buffer - Instances");
                InstanceRenderer.Flush(GraphicsDevice, DefaultShader, Camera,
                                       InstanceRenderMode.SelectionBuffer);
                //GamePerformance.Instance.StopTrackPerformance("Render - Selection Buffer - Instances");

                SelectionBuffer.End(GraphicsDevice);
            }


            #endregion



            // Start drawing the bloom effect
            if (GameSettings.Default.EnableGlow)
            {
                bloom.BeginDraw();
            }

            // Draw the sky
            GraphicsDevice.Clear(DefaultShader.FogColor);
            DrawSky(gameTime, Camera.ViewMatrix, 1.0f, DefaultShader.FogColor);

            // Defines the current slice for the GPU
            float level = ChunkManager.World.Master.MaxViewingLevel + 0.25f;
            if (level > VoxelConstants.ChunkSizeY)
            {
                level = 1000;
            }

            SlicePlane = level;

            DefaultShader.WindDirection = Weather.CurrentWind;
            DefaultShader.WindForce     = 0.0005f * (1.0f + (float)Math.Sin(Time.GetTotalSeconds() * 0.001f));
            // Draw the whole world, and make sure to handle slicing
            DefaultShader.ClipPlane       = new Vector4(slicePlane.Normal, slicePlane.D);
            DefaultShader.ClippingEnabled = true;
            //Blue ghost effect above the current slice.
            DefaultShader.GhostClippingEnabled = true;
            Draw3DThings(gameTime, DefaultShader, Camera.ViewMatrix);

            // Now we want to draw the water on top of everything else
            DefaultShader.ClippingEnabled      = true;
            DefaultShader.GhostClippingEnabled = false;

            //ComponentManager.CollisionManager.DebugDraw();

            DefaultShader.View                 = Camera.ViewMatrix;
            DefaultShader.Projection           = Camera.ProjectionMatrix;
            DefaultShader.GhostClippingEnabled = true;
            // Now draw all of the entities in the game
            DefaultShader.ClipPlane       = new Vector4(slicePlane.Normal, slicePlane.D);
            DefaultShader.ClippingEnabled = true;

            if (Debugger.Switches.DrawOcttree)
            {
                foreach (var box in OctTree.EnumerateBounds(frustum))
                {
                    Drawer3D.DrawBox(box.Item2, Color.Yellow, 1.0f / (float)(box.Item1 + 1), false);
                }
            }

            // Render simple geometry (boxes, etc.)
            Drawer3D.Render(GraphicsDevice, DefaultShader, Camera, DesignationDrawer, PlayerFaction.Designations, this);

            DefaultShader.EnableShadows = false;

            DefaultShader.View = Camera.ViewMatrix;

            ComponentRenderer.Render(renderables, gameTime, ChunkManager,
                                     Camera,
                                     DwarfGame.SpriteBatch, GraphicsDevice, DefaultShader,
                                     ComponentRenderer.WaterRenderType.None, lastWaterHeight);
            InstanceRenderer.Flush(GraphicsDevice, DefaultShader, Camera, InstanceRenderMode.Normal);

            if (Master.CurrentToolMode == GameMaster.ToolMode.BuildZone ||
                Master.CurrentToolMode == GameMaster.ToolMode.BuildWall ||
                Master.CurrentToolMode == GameMaster.ToolMode.BuildObject)
            {
                DefaultShader.View       = Camera.ViewMatrix;
                DefaultShader.Projection = Camera.ProjectionMatrix;
                DefaultShader.SetTexturedTechnique();
                GraphicsDevice.BlendState = BlendState.NonPremultiplied;
            }

            WaterRenderer.DrawWater(
                GraphicsDevice,
                (float)gameTime.TotalGameTime.TotalSeconds,
                DefaultShader,
                Camera.ViewMatrix,
                GetReflectedCameraMatrix(wHeight),
                Camera.ProjectionMatrix,
                new Vector3(0.1f, 0.0f, 0.1f),
                Camera,
                ChunkManager);
            ParticleManager.Render(this, GraphicsDevice);
            DefaultShader.ClippingEnabled = false;

            if (GameSettings.Default.EnableGlow)
            {
                bloom.DrawTarget = UseFXAA ? fxaa.RenderTarget : null;

                if (UseFXAA)
                {
                    fxaa.Begin(DwarfTime.LastTime);
                }
                bloom.Draw(gameTime.ToRealTime());
                if (UseFXAA)
                {
                    fxaa.End(DwarfTime.LastTime);
                }
            }
            else if (UseFXAA)
            {
                fxaa.End(DwarfTime.LastTime);
            }

            RasterizerState rasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true
            };


            if (Debugger.Switches.DrawSelectionBuffer)
            {
                SelectionBuffer.DebugDraw(GraphicsDevice.Viewport.Bounds);
            }

            try
            {
                DwarfGame.SafeSpriteBatchBegin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, Drawer2D.PointMagLinearMin,
                                               null, rasterizerState, null, Matrix.Identity);
                //DwarfGame.SpriteBatch.Draw(Shadows.ShadowTexture, Vector2.Zero, Color.White);
                if (IsCameraUnderwater())
                {
                    Drawer2D.FillRect(DwarfGame.SpriteBatch, GraphicsDevice.Viewport.Bounds, new Color(10, 40, 60, 200));
                }

                Drawer2D.Render(DwarfGame.SpriteBatch, Camera, GraphicsDevice.Viewport);

                IndicatorManager.Render(gameTime);
            }
            finally
            {
                DwarfGame.SpriteBatch.End();
            }

            if (Debugger.Switches.DrawComposites)
            {
                Vector2 offset = Vector2.Zero;
                foreach (var composite in CompositeLibrary.Composites)
                {
                    offset = composite.Value.DebugDraw(DwarfGame.SpriteBatch, (int)offset.X, (int)offset.Y);
                }
            }


            Master.Render(Game, gameTime, GraphicsDevice);

            DwarfGame.SpriteBatch.GraphicsDevice.ScissorRectangle =
                DwarfGame.SpriteBatch.GraphicsDevice.Viewport.Bounds;


            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;

            lock (ScreenshotLock)
            {
                foreach (Screenshot shot in Screenshots)
                {
                    TakeScreenshot(shot.FileName, shot.Resolution);
                }

                Screenshots.Clear();
            }
        }
コード例 #4
0
ファイル: Attack.cs プロジェクト: KingMoo1213/dwarfcorp
        public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (performer.Sprite.CurrentAnimation == null ||
                    performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                {
                    return(false);
                }
                break;
            }
            switch (Mode)
            {
            case AttackMode.Melee:
            {
                Health health = other.GetRootComponent().GetChildrenOfType <Health>(true).FirstOrDefault();
                if (health != null)
                {
                    health.Damage(DamageAmount + bonus);
                }

                PlayNoise(other.LocalTransform.Translation);
                if (HitParticles != "")
                {
                    PlayState.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5);
                }

                if (HitAnimation != null)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation, other.BoundingBox.Center(), 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }

                Physics physics = other as Physics;

                if (physics != null)
                {
                    Vector3 force = other.Position - pos;
                    force.Normalize();
                    physics.ApplyForce(force * Knockback, 1.0f);
                }

                break;
            }

            case AttackMode.Ranged:
            {
                PlayNoise(other.LocalTransform.Translation);
                LaunchProjectile(pos, other.Position, other);
                break;
            }
            }

            return(true);
        }