public Trigger(Vector2 npos,Block b) { //Setze Position und Collisionsbox b.block = false; this.b = b; position = npos; cbox.X = (int)position.X; cbox.Y = (int)position.Y; active = false; activeTime = 0; checkpushed = pushed; checkactive = active; checktyp = typ; checkblock = b.block; }
public void Reset(List<Block> list, List<Enemy> elist) { if (checktyp != 0) { if (checktyp == 1) { if (checkactive) { //Baue Wand komplett auf Rectangle cboxnew = triggerend; for (int i = 0; i < 20; i++) { cboxnew.Y -= 48; bool end = false; bool collide = false; for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if(block.type == "triggerend"&&block.cbox.Intersects(cboxnew)) { wallposition = block.position; end = true; break; } else if (block.cbox.Intersects(cboxnew) && block.block) { collide = true; } } if (end) break; else if(!collide) { Block block = new Block(new Vector2(cboxnew.X, cboxnew.Y), "underground_earth"); list.Add(block); blocks.Add(block); } } } else { //Zerstöre alle Blöcke for (int i = 0; i < blocks.Count(); ++i) { Block block = blocks.ElementAt(i); list.Remove(block); } blocks.Clear(); } } else if (checktyp == 2) { if (checkactive) { //Zerstöre alle Blöcke Rectangle cboxnew = triggerend; for (int i = 0; i < 20; i++) { cboxnew.Y += 48; for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if (block.cbox.Intersects(cboxnew) && block.type == "triggerdoor") { list.Remove(block); } } } } else { //Baue die Wand komplett auf Rectangle cboxnew = triggerend; for (int i = 0; i < 20; i++) { cboxnew.Y += 48; bool collide = false; for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if (block.cbox.Intersects(cboxnew) && block.block) { collide = true; } } if (!collide) { Block blockn = new Block(new Vector2(cboxnew.X, cboxnew.Y), "triggerdoor"); list.Add(blockn); } } } } } else { //Wurden schonmal gedrückt aber nicht gesavet if (typ == 1) { //Zerstöre Wand for (int i = 0; i < blocks.Count(); ++i) { Block block = blocks.ElementAt(i); list.Remove(block); } blocks.Clear(); } //Typ 2 wird automatisch aufgebaut } active = checkactive; pushed = checkpushed; time = checkTime; activeTime = checkactiveTime; typ = checktyp; b.block = checkblock; }
public void Update(GameTime gameTime, List<Block> list,List<Enemy> elist,Rectangle sbox,Rectangle hbox) { int speed = 4; if (pushed) { if (typ == 2) { if (doorframe != 20) { doorframe += 1; } if (doorframe == 20) { Rectangle cboxnew = doorstart; //Wenn es keine Blöcke existieren for (int i = 0; i < 20; i++) { for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if (block.cbox.Intersects(cboxnew) && block.type == "triggerdoor") { //Füge existierenden zur Liste hinzu list.Remove(block); } } cboxnew.Y = cboxnew.Y - 48; } if (Game1.level == 4) { Rectangle dposition = doorstart; dposition.X = (int)position.X; dposition.Y = (int)position.Y+48; bool collide = false; for (int i = 0; i < 20; i++) { collide = false; for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if (block.cbox.Intersects(dposition)) { //Füge existierenden zur Liste hinzu collide = true; } } if (!collide) { Block block2 = new Block(new Vector2(dposition.X, dposition.Y), "triggerdoor"); list.Add(block2); } dposition.X = dposition.X + 48; } } pushed = false; time = 0; activeTime = Convert.ToInt32((double)Game1.luaInstance["triggerTimeDoor"]); cboxnew.Y = doorstart.Y - 48; for (int a = 0; a < 10; a++) { cboxnew.X = cboxnew.X + 48; for (int j = 0; j < elist.Count(); ++j) { Enemy enemy = elist.ElementAt(j); if (cboxnew.Intersects(enemy.cbox.box) && enemy.type == 2) { enemy.moving = true; enemy.mover = false; Sound.Play("skullmonkey_freed"); } } } } } else if (typ == 1) { bool ende = false; bool collide = false; Rectangle cboxnew = triggerend; cboxnew.Y = triggerend.Y + 48; bool wallmoved = false; for (int j = 0; j < blocks.Count(); ++j) { Block block = blocks.ElementAt(j); block.cbox.Y -= speed; block.position.Y -= speed; if (!wallmoved) { wallposition = block.position; wallY += speed; if (wallY > 672) wallY = 672; wallmoved = true; } for (int a = 0; a < list.Count(); ++a) { Block blocka = list.ElementAt(a); if (block.cbox.Intersects(blocka.cbox)&& !block.cbox.Intersects(triggerend)&&blocka.type == "triggerend") { ende = true; block.cbox.Y += speed; block.position.Y += speed; break; } if (block.cbox.Intersects(cboxnew)) { collide = true; break; } } if (ende || collide) break; } if (!collide && !ende) { Block block = new Block(new Vector2(triggerend.X, triggerend.Y + 48), "underground_earth"); list.Add(block); blocks.Add(block); } else if (ende) { pushed = false; time = 0; activeTime = Convert.ToInt32((double)Game1.luaInstance["triggerTimeWall"]); } } } else if(active&&!sbox.Intersects(b.cbox)&&Game1.level != 4) { time += gameTime.ElapsedGameTime.TotalSeconds; if (time > activeTime) { if (typ == 2) { Rectangle cboxnew = doorstart; bool geht = true; if (cboxnew.Intersects(sbox) || cboxnew.Intersects(hbox)) { geht = false; } else { for (int i = 0; i < 20; i++) { for (int a = 0; a < elist.Count(); ++a) { Enemy enemy = elist.ElementAt(a); if (enemy.cbox.box.Intersects(cboxnew)) { geht = false; break; } } if (!geht) break; cboxnew.Y = cboxnew.Y - 48; } cboxnew.Y = doorstart.Y - 48; for (int a = 0; a < 10; a++) { cboxnew.X = cboxnew.X + 48; if (sbox.Intersects(cboxnew)||hbox.Intersects(cboxnew)) geht = false; for (int j = 0; j < elist.Count(); ++j) { Enemy enemy = elist.ElementAt(j); if (cboxnew.Intersects(enemy.cbox.box)) { geht = false; } if (!geht) break; } if (!geht) break; } } if (geht) { if(doorframe == 0) { bool collide = false; if (Game1.level == 4) { Rectangle dposition = doorstart; dposition.X = (int)position.X; dposition.Y = (int)position.Y + 48; for (int i = 0; i < 20; i++) { for (int j = 0; j < list.Count(); ++j) { Block block = list.ElementAt(j); if (block.cbox.Intersects(dposition)&&block.type == "triggerdoor") { list.Remove(block); } } dposition.X = dposition.X + 48; } } cboxnew = doorstart; cboxnew.Y = doorstart.Y + 48; for (int j = 0; j < 10; j++) { collide = false; for (int a = 0; a < list.Count(); ++a) { Block blocka = list.ElementAt(a); if (blocka.cbox.Intersects(cboxnew)) { collide = true; break; } } if (!collide) { Block block = new Block(new Vector2(cboxnew.X, cboxnew.Y), "triggerdoor"); list.Add(block); } cboxnew.Y -= 48; } active = false; time = 0; } else { doorframe -= 1; } } } if (typ == 1) { Rectangle cboxnew = triggerend; cboxnew.Y = cboxnew.Y + 96; bool wallmoved = false; for (int i = 0; i < blocks.Count(); ++i) { //Bewege sie einfach nach oben Block block = blocks.ElementAt(i); block.cbox.Y += speed; block.position.Y += speed; if (!wallmoved) { wallposition = block.position; wallY -= speed; if (wallY < 0) wallY = 0; wallmoved = true; } if (block.cbox.Intersects(cboxnew)) { blocks.Remove(block); list.Remove(block); } } if (blocks.Count() == 0) { blocks.Clear(); active = false; time = 0; } } } } }
public void Generate(Player spieler,Hero hero) { //generiere Das Level (erzeuge neue Objekte in der List) anhand der Levelmap int moving_last = 0; int break_x_last = 0; int break_x_anzahl = 0; int break_y_last = 0; int break_y_anzahl = 0; int moving_anzahl = 0; for (int i = 0; i < levelMap.Width; i++) { for (int t = 0; t < levelMap.Height; t++) { string type = ""; if (pixelRGBA[i, t, 3] == 0) { } else { String color = pixelRGBA[i, t, 0] + "," + pixelRGBA[i, t, 1] + "," + pixelRGBA[i, t, 2]; if (pixelRGBA[i, t, 1] == 255 && pixelRGBA[i, t, 2] == 255) { kipoints.Add(new KIPoint(new Vector2(i * 48, t * 48), pixelRGBA[i, t, 0])); } switch (color) { case "255,100,255": spieler.spine.skeleton.X = i*48; spieler.spine.skeleton.Y = t * 48; spieler.position.Y = spieler.spine.skeleton.Y; spieler.position.X = spieler.spine.skeleton.X; spieler.cbox.Update(spieler.position); spieler.checkpoint = spieler.position; break; case "255,115,255": hero.spine.skeleton.X = i * 48; hero.spine.skeleton.Y = t * 48; hero.position.Y = hero.spine.skeleton.Y; hero.position.X = hero.spine.skeleton.X; hero.cbox.Update(hero.position); hero.checkpoint = hero.position; break; case "147,17,126": type = "checkpoint"; checkpoints.Add(new Checkpoint(i * 48, false)); break; case "39,118,33": type = "moving"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); if (moving_last + 1 != i) { moving_anzahl++; } moving_last = i; break; case "119,0,255": type = "breakable"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); if (break_x_last + 1 != i) { break_x_anzahl++; } break_x_last = i; break; case "119,20,255": type = "breakable_verticale"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); if (break_y_last + 1 != t) { break_y_anzahl++; } break_y_last = t; break; case "180,165,0": type = "movingend"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; case "104,60,17": type = "underground_earth"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; case "0,255,0": type = "ground_grass"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; case "0,0,255": type = "water"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; case "0,0,0": type = "hase"; enemies.Add(new Bunny(new Vector2(i * 48, t * 48), 1,true)); break; case "255,255,0": type = "zeit"; items.Add(new Item(new Vector2(i * 48, t * 48 -96 +48), type)); break; case "180,150,140": type = "bag"; items.Add(new Item(new Vector2(i * 48, t * 48 -96+48), type)); break; case "171,140,188": type = "herz"; items.Add(new Item(new Vector2(i * 48, t * 48 - 96 + 48), type)); break; case "255,200,200": type = "monkey"; items.Add(new Item(new Vector2(i * 48, t * 48 - 96 + 48), type)); break; case "50,50,50": type = "monkey"; enemies.Add(new Monkey(new Vector2(i * 48, t * 48), 2, true)); break; case "255,255,100": type = "banana"; items.Add(new Item(new Vector2(i * 48, t * 48 - 96 + 48), type)); break; case "255,0,0": type = "trigger"; Block b = new Block(new Vector2(i * 48, t * 48), type); blocks.Add(b); triggers.Add(new Trigger(new Vector2(i * 48, t * 48),b)); break; case "153,0,0": type = "triggerend"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; case "155,0,0": type = "triggerdoor"; blocks.Add(new Block(new Vector2(i * 48, t * 48), type)); break; } } } } for (int i = 0; i < moving_anzahl; i++) { mblocks.Add(new MovingBlock(blocks)); } int id = 0; for (int i = 0; i < break_x_anzahl; i++) { breakblocks.Add(new Breakable(blocks,false,id)); id++; } for (int i = 0; i < break_y_anzahl; i++) { breakblocks.Add(new Breakable(blocks, true, id)); id++; } checkpoints.Add(new Checkpoint((int)size.X - 100, true)); //Ende for (int i = 0; i < triggers.Count(); ++i) { Trigger trigger = triggers.ElementAt(i); trigger.Check(blocks); } Save(); }