public virtual bool Pixel_Collision(Game_Object go) { Color[] data_a = new Color[tex.Width * tex.Height]; tex.GetData(data_a); Color[] data_b = new Color[go.tex.Width * go.tex.Height]; go.tex.GetData(data_b); int top = Math.Max(hit_box.Top, go.hit_box.Top); int bottom = Math.Min(hit_box.Bottom, go.hit_box.Bottom); int left = Math.Max(hit_box.Left, go.hit_box.Left); int right = Math.Min(hit_box.Right, go.hit_box.Right); for (int y = top; y < bottom; y++) { for (int x = left; x < right; x++) { Color color_a = data_a[(x - hit_box.Left) + (y - hit_box.Top) * hit_box.Width]; Color color_b = data_b[(x - go.hit_box.Left) + (y - go.hit_box.Top) * go.hit_box.Width]; if (color_a.A != 0 && color_b.A != 0) { return(true); } } } return(false); }
public virtual void Handle_shooting(Game_Object go, Texture2D tex) { projectiles.Add(new Power_Up(go.pos, tex)); foreach (Power_Up p in projectiles) { p.speed.X = 7; } powered_player = false; }
public virtual void Handle_collision(Platform p, Game_Object go) { Rectangle inter = Rectangle.Intersect(go.hit_box, p.hit_box); Vector2 nor_velocity = new Vector2(go.speed.X, go.speed.Y); nor_velocity.Normalize(); if (inter.Height - 4 > inter.Width) { if (go.pos.X < p.hit_box.X) { go.speed.X = 0; go.pos.X -= inter.Width; } else { go.pos.X += inter.Width; } } else { if (go.pos.Y < p.hit_box.Y) { go.speed.Y = 0; go.pos.Y -= inter.Height; go.is_on_ground = true; } else { go.pos.Y += inter.Height; } } }
public virtual bool Hits_object(Game_Object go) { return(hit_box.Intersects(go.hit_box)); }
public virtual void Handle_climbing(Platform p, Game_Object go) { speed.Y = -2; }
public virtual void Handle_trampoline(Game_Object go) { go.speed.Y = -10; }