protected override bool CheckActvationEvent(GameTime gameTime, Rectangle playerBoundingBox, int timeLeft, Quadtree quadtree, SGame stateGame) { camera = stateGame.Camera; playerPos = new Vector2(playerBoundingBox.Center.X, playerBoundingBox.Center.Y); bool activation = Enabled; List<Tile> killtiles = quadtree.GetCollision(playerBoundingBox); foreach (Tile tile in killtiles) { if (tile.TileType == TileType.Spike) { Rectangle rect = tile.get_rect; rect.Y += 12; rect.Height -= 12; if (playerBoundingBox.Intersects(rect)) { activation = true; if (!traceEffect.Enabled) { ActivateEffect(); } break; } } } return activation; }
protected override bool CheckActvationEvent(GameTime gameTime, Rectangle playerBoundingBox, int timeLeft, Quadtree quadtree, SGame stateGame) { bool activation; if (Enabled == false) { if (playerBoundingBox.Intersects(exit)) { activation = true; backcolor = new Color(0, 0, 0, 0); } else { activation = false; } } else { activation = Enabled; } return activation; }
private void AICollision(Quadtree quadtree, float elapsed, int numThread) { canJump = false; Vector2 newpos = new Vector2(); newpos = pos + speed * elapsed; Rectangle collisionrect = new Rectangle( orgcollisionrect.X + (int)pos.X + orgcollisionrect.Width/2, orgcollisionrect.Y + (int)pos.Y+ orgcollisionrect.Height / 2, orgcollisionrect.Width - orgcollisionrect.Width / 2, orgcollisionrect.Height - orgcollisionrect.Height / 2); Rectangle newcollisionrect = new Rectangle( orgcollisionrect.X + (int)newpos.X, orgcollisionrect.Y + (int)newpos.Y, orgcollisionrect.Width, orgcollisionrect.Height); List<Tile> leveltiles; leveltiles = quadtree.GetEnemyCollision(newcollisionrect, numThread); foreach (Tile tile in leveltiles) { if (tile.TileColission_Type != TileCollision.Event) { //newpos = pos + speed * elapsed; //BottomCollision if (collisionrect.Bottom <= tile.get_rect.Y && newcollisionrect.Bottom >= tile.get_rect.Y) { if (newcollisionrect.Right >= tile.get_rect.X && (int)(newcollisionrect.Left) <= tile.get_rect.Right) { animations.CurrentAnimation = Anims.Walk; newpos.Y -= speed.Y * elapsed; speed.Y = 0; gravity = new Vector2(); jumping = false; jumpSpeed = new Vector2(); canJump = true; break; } } if (tile.TileColission_Type == TileCollision.Impassable) { //RightCollision if (tile.get_rect.X >= collisionrect.Right && newcollisionrect.Right > tile.get_rect.X) { if (newcollisionrect.Bottom > tile.get_rect.Y && newcollisionrect.Top < tile.get_rect.Bottom) { if (!pathfound) rundirection = StandardDirection.Left; speed.X = 0; //continue; } } //LeftCollision else if (collisionrect.Left > tile.get_rect.Right && newcollisionrect.Left <= tile.get_rect.Right) { if (newcollisionrect.Bottom >= tile.get_rect.Y && newcollisionrect.Top <= tile.get_rect.Bottom) { if (!pathfound) rundirection = StandardDirection.Right; speed.X = 0; //continue; } } //UpCollision else if (collisionrect.Y >= tile.get_rect.Bottom && newcollisionrect.Top < tile.get_rect.Bottom) { if (newcollisionrect.Right >= tile.get_rect.X && newcollisionrect.Left <= tile.get_rect.Right) { speed.Y *= -1; jumping = false; jumpSpeed = new Vector2(); continue; } } } } } }
private void Collision(Quadtree quadtree,float elapsed,int numThread) { if (usesKI) AICollision(quadtree, elapsed, numThread); else switch (collision) { case EnemyCollision.Normal: NormalCollision(quadtree, elapsed, numThread); break; case EnemyCollision.NoSuicide: NormalCollision(quadtree, elapsed, numThread); break; default: NormalCollision(quadtree, elapsed, numThread); break; } }
public void Update(GameTime gameTime, Quadtree quadtree, Vector2 playerPos,Rectangle playerRect,Tile[,] map,Matrix matrix) { this.map = map; this.gameTime = gameTime; this.quadtree = quadtree; this.playerPos = playerPos; CheckIntersection(playerRect,matrix); ClearEnemies(); for (int i = 0; i < updater.Length;i++) { //thread = new Thread(new ParameterizedThreadStart(UpdateThread)); if (updater[i].ThreadState == ThreadState.Unstarted) updater[i].Start(i); if (updater[i].ThreadState == ThreadState.Suspended) updater[i].Resume(); } }
private void ChecEventActivation(GameTime gameTime, Rectangle playerBoundingBox, Quadtree quadtree, SGame stateGame) { foreach (GameEvent gamevent in events) { gamevent.CheckActivation(gameTime, playerBoundingBox, timeLeft,quadtree,stateGame); } }
public List<EventAction> Update(GameTime gameTime, Rectangle playerBoundingBox, Quadtree quadtree, List<Enemy.Enemy> enemies, SGame stateGame) { List<EventAction> actions = new List<EventAction>(); ChecEventActivation(gameTime, playerBoundingBox,quadtree,stateGame); UpdateEvents(gameTime, playerBoundingBox, ref actions, enemies); return actions; }
protected void UpdateEnemy(GameTime gameTime, Quadtree quadtree,Vector2 playerPos,int numThread,Tile[,] map) { if (!alive) { timeTillDeath += (float)gameTime.ElapsedGameTime.TotalSeconds; if (timeTillDeath > 10) removable = true; //particleManager.Update(gameTime); wave.Update(gameTime, pos); } else { speed = new Vector2(); gravity.Y += GameParameters.Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; UpdateRectangles(pos); speed.Y += gravity.Y; DoEnemyKI(gameTime, quadtree, playerPos, map); if (movementType == MovementType.Normal && !standXStill) { if (rundirection == StandardDirection.Left) speed.X = -maxSpeed; else speed.X = maxSpeed; } speed.Y += jumpSpeed.Y; if (jumping) animations.CurrentAnimation = Anims.Jump; else animations.CurrentAnimation = Anims.Walk; //#TODO : Speed Collision(quadtree, (float)gameTime.ElapsedGameTime.TotalSeconds, numThread); animations.Update(gameTime, !(rundirection == standardirection)); pos += speed * (float)gameTime.ElapsedGameTime.TotalSeconds; UpdateRectangles(pos); } }
public void Update(GameTime gameTime,Quadtree quadtree,Vector2 playerPos,int numThread,Tile[,] map) { //try { UpdateEnemy(gameTime, quadtree,playerPos,numThread,map); } //catch (Exception e) { //errorMessage = ("Couldn't Update Enemy: " + e.Message); } }
/// <summary> /// Initializes the KillAnimation /// </summary> public void Kill(Quadtree quadtree,Matrix matrix) { alive = false; particleManager.SpawnPos = pos; //particleManager.UseTimedAlpha = true; //particleManager.Alpha = 1; DebugManager.AddItem("Enemy #" + myNumber + " killed", this.ToString(), new System.Diagnostics.StackTrace()); particleManager.UseMinSpeed = true; particleManager.MinSpeed = new Vector2(300); if (speed.X < 0) particleManager.MaxSpeed = new Vector2(500, 500); else particleManager.MaxSpeed = new Vector2(-500, 500); Rectangle particlerect = new Rectangle((int)pos.X - 150, (int)pos.Y - 150, (int)pos.X + 300, (int)pos.Y + 300); List<Tile> collisions = quadtree.GetEnemyCollision(particlerect, numThread); Collisions = collisions; foreach (Tile collision in collisions) if (collision.TileColission_Type != TileCollision.Passable && collision.Standable) particleManager.AddCollisionRect(collision.get_rect); particleManager.StartExplosion(); wave.Enabled = true; wave.StartResetEffect(); wave.CenterCoord = Vector2.Transform(pos, matrix); wave.Disortion = 0.1f; wave.DistortionChange = -0.2f; wave.RadiusChange = 0.5f; wave.SizeChange = 0f; wave.MaxRadius = 0.2f; wave.Size = 0.02f; }
/// <summary> /// Initializes a Level /// </summary> /// <param name="daten">The Content of the LevelFile</param> /// <returns>if it was successfull</returns> private bool LoadLevel(string daten) { bool level_loaded = false; //try { Dictionary<string, string> config = new Dictionary<string, string>(); //Split Lines string[] zeilen = daten.Split(new char[] { ';' }); foreach (string zeile in zeilen) { //Splite Key and Value string[] temp = zeile.Split(new char[] { '=' }); if (temp.Length > 1) { string config_name = temp[0]; string value = temp[1]; config_name = config_name.Trim(); value = value.Trim(); config[config_name] = value; } } try { //Load the LevelTiles load_level_tiles(config["Level"]); } catch (Exception ex) { error_messages.Add(ex.Message); } //Load LevelVariables levelvariables = new LevelVariables(daten,tiles); //Old Method für Loading Level (ByChar) #region CharLevel /* string[] temp_level_lines = config["Level"].Split(new char[] { ':' }); level_lines = new string[temp_level_lines.Count()]; for (int i = 0; i < temp_level_lines.Count(); i++) { level_lines[i] = temp_level_lines[i].Trim(); } int max_width = level_lines[0].Length; foreach (string lines in level_lines) { if (lines.Length > max_width) { max_width = lines.Length; } } tiles = new Tile[level_lines.Count(), max_width]; for (int x = 0; x < level_lines.Count(); x++) { for (int y = 0; y < max_width; y++) { tiles[x, y] = new Tile(y, x); if (y >= level_lines[x].Length) { tiles[x, y].load_tile('E'); } else { tiles[x, y].load_tile(level_lines[x][y]); if (tiles[x, y].get_TileType == TileType.Start) { startpos.X = tiles[x, y].get_rect.Location.X + Tile.TILE_SIZE / 2; startpos.Y = tiles[x, y].get_rect.Location.Y + Tile.TILE_SIZE / 2; } } } } */ #endregion quadtree = new Quadtree(tiles, int.Parse(levelvariables.Dictionary[LV.QuadtreeLayerDepth])); level_loaded = true; } //catch (Exception e) { // error_messages.Add(e.Message); } return level_loaded; }
public void CheckActivation(GameTime gameTime, Rectangle playerBoundingBox, int timeLeft, Quadtree quadtree, SGame stateGame) { enabled = CheckActvationEvent(gameTime, playerBoundingBox, timeLeft,quadtree,stateGame); }
protected abstract bool CheckActvationEvent(GameTime gameTime, Rectangle playerBoundingBox, int timeLeft,Quadtree quadtree,SGame stateGame);
private void DoEnemyKI(GameTime gameTime, Quadtree quadtree, Vector2 playerPos,Tile[,] map) { switch (tracking) { case PlayerTracking.NotTracking: break; case PlayerTracking.Tracking: TrackPlayer((float)gameTime.ElapsedGameTime.TotalSeconds,playerPos); CliffJump((float)gameTime.ElapsedGameTime.TotalSeconds, map); break; } }
public List<CollisionType> Update(GameTime gametime,Vector2 new_aim, Quadtree quadtree,List<Input.InputKeys> inputkeys,List<Input.InputKeys> oldinputkeys, Input.RunDirection rundirection,float run_factor,Vector2 applyingForce) { List<CollisionType> cur_collission = new List<CollisionType>(); List<CollisionType> return_collission = new List<CollisionType>() ; prev_pos = pos; new_aim.Y = pos.Y; speed = new_aim - pos; speed += apply_physics(gametime); breath_animation(gametime); update_hand_animation(gametime); speed += apply_jump(gametime, inputkeys,oldinputkeys,run_factor); speed += applyingForce; run_factor = MathHelper.Clamp(run_factor, 1.0f, 1.5f); Vector2 temp_pos = pos; update_positions(gametime, temp_pos); //collission = Collission_Type.NoCollission; if (quadtree.GetCollision(bounding_box) != null) { List<Tile> collisionTiles = quadtree.GetCollision(bounding_box); foreach (Tile tile in collisionTiles) { cur_collission = collision(tile, ref cur_speed, ref temp_pos, rundirection); foreach(CollisionType coltype in cur_collission) { return_collission.Add(coltype); } update_positions(gametime, temp_pos); } } collission = return_collission; if (collission.Contains(CollisionType.StandsOnIt) || is_jumping) physics.Y = 0; cur_speed.X = MathHelper.Clamp(speed.X, -MAX_SPEED, MAX_SPEED); cur_speed.Y = MathHelper.Clamp(speed.Y, - MAX_SPEED, MAX_SPEED); pos.X += speed.X * (float)gametime.ElapsedGameTime.TotalSeconds * 5; pos.Y += speed.Y * (float)gametime.ElapsedGameTime.TotalSeconds * 5; if (collission.Count != 0) { walk_animation(gametime); update_hand_walk_animation(gametime); } difference = pos - prev_pos; return return_collission; }