public TestLevel(Texture2D texture,string mapname,Vector2 position) { this.mapname = mapname; this.position = position; switch (mapname) { case "map": map = new int[,] { /*items*/ // 1 = blok // 3 = ladder // 5 = item // 7 = schuif obj // 9 = falldoor button // 11 // 2 = steen // 4 = button // 6 = door // 8 = fall door // 10 = pressure plate {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,1,0,1,0,1,0,3,0,0,0,0,0,0,0,1,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,0,0,0,0,0,10,0,10,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,3,0,0,0,6,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,11,0,0,0,1,1,1,1,3,1,1,1,1,1,1,1,0,0,4,0,0,0,1,0,1,1,1,3,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,3,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, }; break; } buttons = new List<Door_button>(); ladders = new List<Ladder>(); stones = new List<Steen>(); Tiles = new List<blok>(); collectibles = new List<CollectItem>(); doors = new List<Door>(); moveObjects = new List<MoveObject>(); Mdoors = new List<MoveDoor>(); Mbuttons = new List<MoveDoorButton>(); plates = new List<PressurePlate>(); CheckRtiles = new List<blok>(); CheckLtiles = new List<blok>(); CheckBtiles = new List<blok>(); this.tiletexture = texture; buttonIndex = 0; ladderIndex = 0; doorIndex = 0; center = new Vector2(this.Width / 2 * 44, this.Heigth / 2*44); SpawnNextlvl = false; for (int x = 0; x < Width; x++) { for (int y = 0; y < Heigth; y++) { //Assets in het Grid genereren int textureIndex = map[y, x]; if (textureIndex == 0) continue; switch (textureIndex) { case 1: blok tile = new blok(tiletexture, new Vector2(position.X + x * 44,position.Y + y * 44)); Tiles.Add(tile); break; case 2: Steen steen = new Steen(Game1.crushstone,13, 1); AnimationClass animate = new AnimationClass(); steen.position = new Vector2(position.X + x * 44, position.Y + y * 44); steen.addAnimation(Game1.crushstone,"idle",1,13, animate.Copy()); steen.Animation = "idle"; stones.Add(steen); break; case 3: Ladder ladder = new Ladder(Game1.laddertextures[ladderIndex], new Vector2(position.X + x * 44, position.Y + y * 44)); ladderIndex++; ladders.Add(ladder); break; case 4: Door_button button = new Door_button(Game1.button_tex, 12, 1, buttonIndex); AnimationClass animate2 = new AnimationClass(); button.position = new Vector2(position.X + x * 44, position.Y + y * 44); button.addAnimation(Game1.button_tex, "idle", 1, 12, animate2.Copy()); button.Animation = "idle"; buttonIndex++; buttons.Add(button); break; case 5: CollectItem item = new CollectItem(Game1.slaktex, 50, 1); AnimationClass animate3 = new AnimationClass(); item.position = new Vector2(position.X + x * 44, position.Y + y * 44); item.addAnimation(Game1.slaktex, "idle", 1, 50, animate3.Copy()); item.Animation = "idle"; collectibles.Add(item); break; case 6: Door door = new Door(Game1.door_tex, new Vector2(position.X + x * 44, position.Y + y * 44), doorIndex); doorIndex++; doors.Add(door); break; case 7: MoveObject obj = new MoveObject(Game1.stonetex,15, 1); AnimationClass animate5 = new AnimationClass(); obj.position = new Vector2(position.X + x * 44, position.Y + y * 44); obj.addAnimation(Game1.stonetex,"idle2",1, 15, animate5.Copy()); obj.Animation = "idle2"; moveObjects.Add(obj); break; case 8: MoveDoor objdoor = new MoveDoor(Game1.fallStone, new Vector2(position.X + x * 44, position.Y + y * 44),moveDoorIndex); moveDoorIndex++; Mdoors.Add(objdoor); break; case 9: MoveDoorButton button2 = new MoveDoorButton(Game1.button_tex,12, 1,moveButtonIndex); AnimationClass animate6 = new AnimationClass(); button2.position = new Vector2(position.X + x * 44, position.Y + y * 44); button2.addAnimation(Game1.button_tex, "idle", 1, 12, animate6.Copy()); button2.Animation = "idle"; moveButtonIndex++; Mbuttons.Add(button2); break; case 10: PressurePlate plate = new PressurePlate(Game1.pressureplate, new Vector2(position.X + x * 44, position.Y + y * 55)); plates.Add(plate); break; case 11: liftobject = new LiftObject(Game1.liftobj, new Vector2(position.X + x * 44, position.Y + y * 44)); break; } } } }
public void Update(GameTime gametime) { KeyboardState kb = Keyboard.GetState(); rectangle = new Rectangle((int)position.X, (int)position.Y,40, 83); //UpdateAnimation(gametime); Center = new Vector2(position.X + width/2, position.Y + height/2); Console.WriteLine(position.Y); if (kb.IsKeyDown(Keys.Left)) { spriteEffects = SpriteEffects.FlipHorizontally; } if (kb.IsKeyDown(Keys.Right)) { spriteEffects = SpriteEffects.None; } for (int i = 0; i < TestLevel.collectibles.Count; i++) { if (rectangle.Intersects(TestLevel.collectibles[i].rectangle)) { points += TestLevel.collectibles[i].value; TestLevel.collectibles[i].pickedUp = true; } } if (rectangle.Intersects(TestLevel.bigRec)) { rectangle.Width = 95; } else { rectangle.Width = 40; } if (status == Status.walking) { Collision(); if (kb.IsKeyDown(Keys.Up) && hasJumped == false) { position.Y -= 20f; velocity.Y = -3f; hasJumped = true; } else if (hasJumped == true) { if (Animation != "jump") { Animation = "jump"; IdleAnimate.Frames = 10; } if (kb.IsKeyDown(Keys.Left)) { position.X += velocity.X; velocity.X = -2f; } if (kb.IsKeyDown(Keys.Right)) { position.X += velocity.X; velocity.X = 2f; } velocity.Y += 0.15f; position.Y += velocity.Y; } else if (kb.IsKeyDown(Keys.Left)) { position.X += velocity.X; velocity.X = -2f; if (Animation != "walk") { Animation = "walk"; IdleAnimate.Frames = 28; } } else if (kb.IsKeyDown(Keys.Right)) { position.X += velocity.X; velocity.X = 2f; if (Animation != "walk") { Animation = "walk"; IdleAnimate.Frames = 28; } } else if (status == Status.pushing) { if (kb.IsKeyDown(Keys.Left)) { position.X += velocity.X; velocity.X = -1f; } if (kb.IsKeyDown(Keys.Right)) { position.X += velocity.X; velocity.X = 1f; } } else if (kb.IsKeyDown(Keys.RightControl)) { if (Animation != "smash") { Animation = "smash"; IdleAnimate.Frames = 24; width = 40; } Attack(TestLevel.stones); } else { if (Animation != "idle") { Animation = "idle"; IdleAnimate.Frames = 12; FramesPerSecond = 17; } } if (gravity) { velocity.Y += gravitypower * (float)gametime.ElapsedGameTime.TotalSeconds; position.Y += velocity.Y; } gravity = true; } if (status == Status.climbing) { if (kb.IsKeyDown(Keys.Up)) { position.Y -= 1; } foreach (Ladder ladder in TestLevel.ladders) { if (!rectangle.Intersects(ladder.rectangle)) { status = Status.walking; } } } for (int i = 0; i < TestLevel.stones.Count; i++) { if(rectangle.Intersects(TestLevel.stones[i].rectangle)) { stonetarget = TestLevel.stones[i]; } else { stonetarget = null; } } foreach (Door_button button in TestLevel.buttons) { button.FrameIndex = 1; button.UpdateAnimation(gametime); if (rectangle.Intersects(button.rectangle)) { if (kb.IsKeyDown(Keys.RightControl)) { for (int h = 0; h < TestLevel.doors.Count; h++) { if (button.indexNumber == TestLevel.doors[h].indexNumber) { TestLevel.doors[h].OpenDoor(); } } } } } foreach (MoveObject obj in TestLevel.moveObjects) { if (isPushing) { obj.UpdateAnimation(gametime); } } foreach (Ladder ladder in TestLevel.ladders) { if (rectangle.Intersects(ladder.rectangle)) { if (kb.IsKeyDown(Keys.Up)) { status = Status.climbing; } } } /* if (rectangle.Intersects(TestLevel.door.rectangle)) { position.X = TestLevel.door.position.X + TestLevel.door.texture.Width; }*/ //TestLevel.door.Update(gametime); //TestLevel.button.ReactToDoor(TestLevel.door, position); }