|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using Microsoft.Xna.Framework; |
| 5 | +using DotRPG.Objects; |
| 6 | +using DotRPG.Objects.Dynamics; |
| 7 | +using DotRPG.Scripting; |
| 8 | +using Microsoft.Xna.Framework.Graphics; |
| 9 | + |
| 10 | +namespace DotRPG._Example |
| 11 | +{ |
| 12 | + class ScriptTest : Frame |
| 13 | + { |
| 14 | + LuaModule DialogTest1; |
| 15 | + TextObject DialogForm; |
| 16 | + SceneSwitchSet SceneSwitches = new SceneSwitchSet(); |
| 17 | + PlayerObject Player; |
| 18 | + DynamicRectObject dro; |
| 19 | + Boolean[] lastInputCollection = new bool[8]; |
| 20 | + Boolean ShowingText; |
| 21 | + |
| 22 | + public override int FrameID |
| 23 | + { |
| 24 | + get |
| 25 | + { |
| 26 | + return 2; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public ScriptTest(Game owner, ResourceHeap globalGameResources, HashSet<TimedEvent> globalEventSet) : base(owner, globalGameResources, globalEventSet) |
| 31 | + { |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + public override void Initialize() |
| 36 | + { |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Rectangle drawZone) |
| 41 | + { |
| 42 | + Player.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height)); |
| 43 | + dro.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height)); |
| 44 | + if (ShowingText) |
| 45 | + { |
| 46 | + DialogForm.Draw(spriteBatch, Owner.Window); |
| 47 | + } |
| 48 | +#if DEBUG |
| 49 | + spriteBatch.DrawString(FrameResources.Global.Fonts["vcr"], String.Format("Sight: {0}, Z key: {1}", Player.SightArea, lastInputCollection[4]), new Vector2(0, 12), Color.White); |
| 50 | +#endif |
| 51 | + } |
| 52 | + |
| 53 | + public override void Update(GameTime gameTime, bool[] controls) |
| 54 | + { |
| 55 | + Single loco_x = 0.0f; Single loco_y = 0.0f; |
| 56 | + if (controls[0]) { loco_y -= 1.0f; } |
| 57 | + if (controls[1]) { loco_y += 1.0f; } |
| 58 | + if (controls[2]) { loco_x -= 1.0f; } |
| 59 | + if (controls[3]) { loco_x += 1.0f; } |
| 60 | + Vector2 Locomotion = new Vector2(loco_x, loco_y); |
| 61 | + if (controls[0] && !(controls[1] || controls[2] || controls[3])) |
| 62 | + { |
| 63 | + Player.SightDirection = Direction.Up; |
| 64 | + } |
| 65 | + if (controls[1] && !(controls[0] || controls[2] || controls[3])) |
| 66 | + { |
| 67 | + Player.SightDirection = Direction.Down; |
| 68 | + } |
| 69 | + if (controls[2] && !(controls[1] || controls[0] || controls[3])) |
| 70 | + { |
| 71 | + Player.SightDirection = Direction.Left; |
| 72 | + } |
| 73 | + if (controls[3] && !(controls[1] || controls[0] || controls[2])) |
| 74 | + { |
| 75 | + Player.SightDirection = Direction.Right; |
| 76 | + } |
| 77 | + Locomotion /= (Locomotion.Length() != 0 ? Locomotion.Length() : 1.0f); |
| 78 | + Locomotion *= 0.1f; |
| 79 | + if (ShowingText) |
| 80 | + { |
| 81 | + Locomotion = Vector2.Zero; |
| 82 | + } |
| 83 | + Player.Velocity = Locomotion; |
| 84 | + Player.TryCollideWith(dro); |
| 85 | + if (controls[4] && !lastInputCollection[4] || (ShowingText && DialogForm.ReachedEnd && SceneSwitches.AutoScroll)) |
| 86 | + { |
| 87 | + if (Player.SightArea.Intersects(dro.Collider) && !ShowingText) |
| 88 | + { |
| 89 | + SceneSwitches.AutoScroll = false; |
| 90 | + SceneSwitches.ExitDialog = false; |
| 91 | + ShowingText = true; |
| 92 | + DialogTest1.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)gameTime.TotalGameTime.TotalMilliseconds); |
| 93 | + DialogForm.ResetToStart(); |
| 94 | + } |
| 95 | + else if (DialogForm.ReachedEnd) |
| 96 | + { |
| 97 | + if (SceneSwitches.ExitDialog) |
| 98 | + { |
| 99 | + ShowingText = false; |
| 100 | + } |
| 101 | + else |
| 102 | + { |
| 103 | + SceneSwitches.AutoScroll = false; |
| 104 | + SceneSwitches.ExitDialog = false; |
| 105 | + DialogTest1.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)gameTime.TotalGameTime.TotalMilliseconds); |
| 106 | + DialogForm.ResetToStart(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + } |
| 111 | + if (ShowingText) |
| 112 | + { |
| 113 | + DialogForm.Update(gameTime); |
| 114 | + } |
| 115 | + Player.Update(gameTime); |
| 116 | + base.Update(gameTime, controls); |
| 117 | + for (int i = 0; i < Math.Min(lastInputCollection.Length, controls.Length); i++) |
| 118 | + { |
| 119 | + lastInputCollection[i] = controls[i]; |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + public override void SetPlayerPosition(object sender, EventArgs e, GameTime gameTime) |
| 124 | + { |
| 125 | + throw new NotImplementedException(); |
| 126 | + } |
| 127 | + |
| 128 | + public override void LoadContent() |
| 129 | + { |
| 130 | + DialogForm = new TextObject(FrameResources.Global.Fonts["vcr_large"], "...", 0.01f, 0.80f, Color.White, AlignMode.TopLeft, 1080, scrollPerTick: 1, scrollDelay: 0.04f); |
| 131 | + DialogTest1 = new LuaModule(System.IO.File.ReadAllText(System.IO.Path.Join(Owner.Content.RootDirectory, "Scripts/dialog.lua"))); |
| 132 | + DialogTest1.Runtime["dialog"] = DialogForm; |
| 133 | + DialogTest1.Runtime["scene"] = SceneSwitches; |
| 134 | + Player = new PlayerObject(new Point(32, 32), new Point(32, 32), 20.0f, new Point(32, 8)); |
| 135 | + dro = new DynamicRectObject(new Point(32, 128), new Point(32, 32), 30.0f, true); |
| 136 | + FrameResources.Textures.Add("cube-p", Owner.Content.Load<Texture2D>("Texture2D/cube-p")); |
| 137 | + Player.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-p"]); |
| 138 | + FrameResources.Textures.Add("cube-o", Owner.Content.Load<Texture2D>("Texture2D/cube-o")); |
| 139 | + dro.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-o"]); |
| 140 | + } |
| 141 | + |
| 142 | + public override void UnloadContent() |
| 143 | + { |
| 144 | + DialogForm = null; |
| 145 | + FrameResources.Dispose(); |
| 146 | + } |
| 147 | + } |
| 148 | +} |
0 commit comments