private void DrawLightPass(Canvas canvas) { Camera mainCam = this.GameObj.ParentScene.FindComponent <Camera>(); SpellScriptEditor spellEditor = Scene.Current.FindComponent <SpellScriptEditor>(); bool spellEditorActive = (spellEditor != null && spellEditor.Active); Vector2 mouseScreenCoord = DualityApp.Mouse.Pos; Vector2 playerScreenCoord = mainCam.GetScreenCoord(this.player.CharacterController.GameObj.Transform.Pos).Xy; if (!spellEditorActive) { canvas.State.SetMaterial(this.cursorLight); canvas.FillRect( mouseScreenCoord.X - this.cursorLightSize, mouseScreenCoord.Y - this.cursorLightSize, this.cursorLightSize * 2, this.cursorLightSize * 2); } canvas.State.SetMaterial(this.playerLight); canvas.FillRect( playerScreenCoord.X - this.playerLightSize, playerScreenCoord.Y - this.playerLightSize, this.playerLightSize * 2, this.playerLightSize * 2); }
void ICmpUpdatable.OnUpdate() { if (this.character == null) { return; } SpellScriptEditor spellEditor = this.GameObj.ParentScene.FindComponent <SpellScriptEditor>(false); bool spellEditorActive = (spellEditor != null && spellEditor.Active); // Character movement if (!spellEditorActive) { Camera mainCam = this.GameObj.ParentScene.FindComponent <Camera>(); Vector2 characterScreenPos = mainCam.GetScreenCoord(this.character.GameObj.Transform.Pos).Xy; Vector2 movement = Vector2.Zero; if (DualityApp.Keyboard[Key.A]) { movement -= Vector2.UnitX; } if (DualityApp.Keyboard[Key.D]) { movement += Vector2.UnitX; } if (DualityApp.Keyboard[Key.W]) { movement -= Vector2.UnitY; } if (DualityApp.Keyboard[Key.S]) { movement += Vector2.UnitY; } if (movement.Length > 1.0f) { movement = movement.Normalized; } this.character.TargetMovement = movement; this.character.TargetLookDir = (DualityApp.Mouse.Pos - characterScreenPos).Angle; } else { this.character.TargetMovement = Vector2.Zero; } // Update existing spells for (int i = this.spells.Count - 1; i >= 0; i--) { Spell spell = this.spells[i]; spell.Update(); if (!spell.IsActive) { if (spell == this.activeSpell) { this.activeSpell = null; } this.spells.RemoveAt(i); } } // Cast Spells if (spellEditor != null && !spellEditorActive) { if (DualityApp.Mouse.ButtonHit(MouseButton.Left)) { if (this.activeSpell == null) { this.activeSpell = Spell.Cast(this.Character, spellEditor.Script); this.spells.Add(this.activeSpell); } } if (!DualityApp.Mouse[MouseButton.Left]) { if (this.activeSpell != null) { this.activeSpell.Release(); this.activeSpell = null; } } } if (DualityApp.Keyboard.KeyHit(Key.P) && spellEditor != null) { spellEditor.Active = !spellEditor.Active; } }
private void DrawOverlayPass(Canvas canvas) { canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White)); Player player = Scene.Current.FindComponent <Player>(); Character character = player != null ? player.Character : null; if (character != null) { canvas.PushState(); canvas.State.ColorTint = ColorRgba.Red * ColorRgba.Grey; canvas.FillRect( canvas.DrawDevice.TargetSize.X - 10 - 30, canvas.DrawDevice.TargetSize.Y - 10 - character.Health, 30, character.Health); canvas.State.ColorTint = ColorRgba.White.WithAlpha(0.5f); canvas.DrawRect( canvas.DrawDevice.TargetSize.X - 10 - 30, canvas.DrawDevice.TargetSize.Y - 10 - 100, 30, 100); canvas.State.ColorTint = ColorRgba.Blue * ColorRgba.Grey; canvas.FillRect( canvas.DrawDevice.TargetSize.X - 10 - 30 - 10 - 30, canvas.DrawDevice.TargetSize.Y - 10 - character.Mana, 30, character.Mana); canvas.State.ColorTint = ColorRgba.White.WithAlpha(0.5f); canvas.DrawRect( canvas.DrawDevice.TargetSize.X - 10 - 30 - 10 - 30, canvas.DrawDevice.TargetSize.Y - 10 - 100, 30, 100); canvas.PopState(); if (character.DamageReaction > 0.005f) { canvas.PushState(); canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Add, ColorRgba.White)); canvas.State.ColorTint = ColorRgba.Red.WithAlpha(character.DamageReaction * 0.5f); canvas.FillRect(0, 0, canvas.Width, canvas.Height); canvas.PopState(); } } SpellScriptEditor spellEditor = Scene.Current.FindComponent <SpellScriptEditor>(); bool spellEditorActive = (spellEditor != null && spellEditor.Active); if (!spellEditorActive) { canvas.DrawText(new string[] { "P: Toggle Spell Editor", "WASD: Move around", "Click: Cast the spell" }, 10, canvas.DrawDevice.TargetSize.Y - 10, 0, Alignment.BottomLeft, true); } else { canvas.DrawText(new string[] { "P: Toggle Spell Editor", "F-Key: Load Spell Preset", "Shift+", "F-Key: Save Spell Preset", "", "Type on the Keyboard to create Glyphs,", "or just use the Mouse Wheel." }, 10, canvas.DrawDevice.TargetSize.Y - 10, 0, Alignment.BottomLeft, true); } canvas.State.ColorTint = ColorRgba.White; canvas.FillCircle(DualityApp.Mouse.X, DualityApp.Mouse.Y, 4); canvas.State.ColorTint = ColorRgba.Black; canvas.FillCircleSegment(DualityApp.Mouse.X, DualityApp.Mouse.Y, 0, 4, 0, MathF.RadAngle360, 1.5f); }