public void Update() { for (int i = 0; i < marked_objects.Count(); ++i) { ColToken obj = marked_objects.ElementAt(i); int loc_x = 0, loc_y = 0, width = 0, height = 0; switch (obj.GetLocalType()) { case ColType.PLAYER: Player temp_pl = (Player)obj.GetParent(); loc_x = temp_pl.getX(); loc_y = temp_pl.getY(); width = temp_pl.getWidth(); height = temp_pl.getHeight(); break; case ColType.MONSTER: Enemy temp_em = (Enemy)obj.GetParent(); loc_x = temp_em.getX(); loc_y = temp_em.getY(); width = temp_em.getWidth(); height = temp_em.getHeight(); break; case ColType.BULLET: Bullet temp_bu = (Bullet)obj.GetParent(); loc_x = temp_bu.x; loc_y = temp_bu.y; width = temp_bu.width; height = temp_bu.height; break; } if (check_map_col(loc_x, loc_y, width, height)) { // obj.Collision(new Collision(ColType.MAP, 0)); // REVERTS ITSELF SOME TIMES SO IT SAYS IT'S MARKED obj.Collision(new ColToken(ColType.MAP, this, unique_id++, null)); } for (int j = 0; j < all_objects.Count(); ++j) { ColToken other_obj = all_objects.ElementAt(j); if (obj.getID() == other_obj.getID()) { continue; } int other_loc_x = 0, other_loc_y = 0, other_width = 0, other_height = 0; switch (other_obj.GetLocalType()) { case ColType.PLAYER: Player temp_pl = (Player)other_obj.GetParent(); other_loc_x = temp_pl.getX(); other_loc_y = temp_pl.getY(); other_width = temp_pl.getWidth(); other_height = temp_pl.getHeight(); break; case ColType.MONSTER: Enemy temp_em = (Enemy)other_obj.GetParent(); other_loc_x = temp_em.getX(); other_loc_y = temp_em.getY(); other_width = temp_em.getWidth(); other_height = temp_em.getHeight(); break; case ColType.BULLET: Bullet temp_bu = (Bullet)other_obj.GetParent(); other_loc_x = temp_bu.x; other_loc_y = temp_bu.y; other_width = temp_bu.width; other_height = temp_bu.height; break; } //Check col /* * if (obj.GetLocalType() == ColType.BULLET && other_obj.GetLocalType() == ColType.MONSTER) * { * //HELP * continue; * } * */ if (check_col(loc_x, loc_y, other_loc_x, other_loc_y, width, height, other_width, other_height)) { // obj.Collision(new Collision(other_obj.GetLocalType(), other_obj.getID())); // other_obj.Collision(new Collision(obj.GetLocalType(), obj.getID())); obj.Collision(other_obj); } } obj.updated_this_frame = false; } marked_objects.Clear(); }
public void Update() { for (int i = 0; i < marked_objects.Count(); ++i) // for every object that has been "marked", or changed/modified via gameplay, check to see if there is collisions { ColToken obj = marked_objects.ElementAt(i); int loc_x = 0, loc_y = 0, width = 0, height = 0; switch (obj.GetLocalType()) { case ColType.PLAYER: Player temp_pl = (Player)obj.GetParent(); loc_x = temp_pl.getX(); loc_y = temp_pl.getY(); width = temp_pl.getWidth(); height = temp_pl.getHeight(); break; case ColType.MONSTER: Enemy temp_em = (Enemy)obj.GetParent(); loc_x = temp_em.getX(); loc_y = temp_em.getY(); width = temp_em.getWidth(); height = temp_em.getHeight(); break; case ColType.BULLET: Bullet temp_bu = (Bullet)obj.GetParent(); loc_x = temp_bu.x; loc_y = temp_bu.y; width = temp_bu.width; height = temp_bu.height; break; } if (check_map_col(loc_x, loc_y, width, height)) { obj.Collision(new ColToken(ColType.MAP, this, unique_id++, null)); } for (int j = 0; j < all_objects.Count(); ++j) // check to see if any object is involved in a collision { ColToken other_obj = all_objects.ElementAt(j); if (obj.getID() == other_obj.getID()) { continue; } int other_loc_x = 0, other_loc_y = 0, other_width = 0, other_height = 0; switch (other_obj.GetLocalType()) { case ColType.PLAYER: Player temp_pl = (Player)other_obj.GetParent(); other_loc_x = temp_pl.getX(); other_loc_y = temp_pl.getY(); other_width = temp_pl.getWidth(); other_height = temp_pl.getHeight(); break; case ColType.MONSTER: Enemy temp_em = (Enemy)other_obj.GetParent(); other_loc_x = temp_em.getX(); other_loc_y = temp_em.getY(); other_width = temp_em.getWidth(); other_height = temp_em.getHeight(); break; case ColType.BULLET: Bullet temp_bu = (Bullet)other_obj.GetParent(); other_loc_x = temp_bu.x; other_loc_y = temp_bu.y; other_width = temp_bu.width; other_height = temp_bu.height; break; } if (check_col(loc_x, loc_y, other_loc_x, other_loc_y, width, height, other_width, other_height)) { obj.Collision(other_obj); } } obj.updated_this_frame = false; } marked_objects.Clear(); // handled all of the modified objects }