/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. SpriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here MyGraphics.Setup(this); ImageTable = new Dictionary<string, Texture2D>(); foreach (var name in imageNames) { ImageTable[name] = Content.Load<Texture2D>(name); } ImageTable[""] = null; Camera = new Camera(); Camera.Origin = new Vector2(320, 240); this.Components.Add(Camera); Field = new Field(); this.Components.Add(Field); MyProgram1 = new MyProgram(Color.MediumSeaGreen); MyProgram1.Position = new Vector2(10, 20); this.Components.Add(MyProgram1); MyProgram2 = new MyProgram(Color.Red); MyProgram2.Position = new Vector2(10, 200); this.Components.Add(MyProgram2); var posX1 = new CodePosition(CodePosition.PositionType.X); var posX2 = new CodePosition(CodePosition.PositionType.X); var posY3 = new CodePosition(CodePosition.PositionType.Y); var posY4 = new CodePosition(CodePosition.PositionType.Y); var sp1_1 = new CodeSpeed(CodeSpeed.SpeedType.Speed05); var sp1_2 = new CodeSpeed(CodeSpeed.SpeedType.Speed01); var sp1_3 = new CodeSpeed(CodeSpeed.SpeedType.Speed05); var sp1_4 = new CodeSpeed(CodeSpeed.SpeedType.Speed05); var sub1 = new CodeCAO(CodeCAO.CAOType.Sub); var add2 = new CodeCAO(CodeCAO.CAOType.Add); var sub3 = new CodeCAO(CodeCAO.CAOType.Sub); var add4 = new CodeCAO(CodeCAO.CAOType.Add); var left = new CodeEventTrigger(CodeEventTrigger.EventType.LeftKey); var right = new CodeEventTrigger(CodeEventTrigger.EventType.RightKey); var up = new CodeEventTrigger(CodeEventTrigger.EventType.UpKey); var down = new CodeEventTrigger(CodeEventTrigger.EventType.DownKey); this.Components.Add(posX1); this.Components.Add(posX2); this.Components.Add(posY3); this.Components.Add(posY4); this.Components.Add(sp1_1); this.Components.Add(sp1_2); this.Components.Add(sp1_3); this.Components.Add(sp1_4); this.Components.Add(sub1); this.Components.Add(add2); this.Components.Add(sub3); this.Components.Add(add4); this.Components.Add(left); this.Components.Add(right); this.Components.Add(up); this.Components.Add(down); this.FieldCodeList = new List<GameObject>(); Player = new Player(); Player.Position = new Vector2(0, 0); this.Components.Add(Player); this.FieldCodeList.Add(Player); var factoryTable = new Dictionary<int, Func<GameObject>>(); factoryTable[0] = () => new CodeEventTrigger(CodeEventTrigger.EventType.LeftKey); factoryTable[1] = () => new CodeEventTrigger(CodeEventTrigger.EventType.RightKey); factoryTable[2] = () => new CodeEventTrigger(CodeEventTrigger.EventType.UpKey); factoryTable[3] = () => new CodeEventTrigger(CodeEventTrigger.EventType.DownKey); factoryTable[4] = () => new CodeCAO(CodeCAO.CAOType.Add); factoryTable[5] = () => new CodeCAO(CodeCAO.CAOType.Sub); factoryTable[6] = () => new CodePosition(CodePosition.PositionType.X); factoryTable[7] = () => new CodePosition(CodePosition.PositionType.Y); factoryTable[8] = () => new CodeSpeed(CodeSpeed.SpeedType.Speed01); factoryTable[9] = () => new CodeSpeed(CodeSpeed.SpeedType.Speed05); factoryTable[10] = () => new CodeSpeed(CodeSpeed.SpeedType.Speed10); var statementList = new List<CodeStatement>(); var variableList = new List<CodeVariable>(); for (int i = 0; i < 10; i++) { int type = i;// random.Next(factoryTable.Count); var code = factoryTable[type](); code.Position = GetRandomPosition(); this.FieldCodeList.Add(code); this.Components.Add(code); if (type < 6) statementList.Add((CodeStatement)code); else variableList.Add((CodeVariable)code); } this.SnapManager = new SnapManager(this); SnapManager.StatementList = statementList; SnapManager.VariableList = variableList; this.Components.Add(SnapManager); CollisionManager = new CollisionManager(); CollisionManager.Field = Field; CollisionManager.Player = Player; CollisionManager.FieldObjectList = FieldCodeList; this.Components.Add(CollisionManager); GameObject.Setup(this); for (int i = 0; i < Components.Count; i++) { Components[i].Initialize(); } sub1.Left = posX1; sub1.Right = sp1_1; left.Next = sub1; MyProgram1.Add(left); add2.Left = posX2; add2.Right = sp1_2; right.Next = add2; MyProgram2.Add(right); sub3.Left = posY3; sub3.Right = sp1_3; up.Next = sub3; MyProgram1.Add(up); add4.Left = posY4; add4.Right = sp1_4; down.Next = add4; MyProgram1.Add(down); Player.MyProgram = MyProgram2; Player.StatementList = statementList; }
private void CheckFieldPlayerLimit(Player player) { var position = player.Position; var bounding = player.BoundingBox; if (bounding.Min.X < Field.Left) position.X += (Field.Left - bounding.Min.X); if (bounding.Max.X > Field.Right) position.X -= (bounding.Max.X - Field.Right); if (bounding.Min.Y < Field.Top) position.Y += (Field.Top - bounding.Min.Y); if (bounding.Max.Y > Field.Bottom) position.Y -= (bounding.Max.Y - Field.Bottom); player.Position = position; }