Multiple Collision Question

B

Bean Bunny

Guest
I'm making a capture the hill style game. I have the game working enough to where if one team member stands on the hill long enough, they can capture it, and another person on another team can reduce the timer and take it away.

Here's two things I would like to get working:

- If the same number of people from team 1 and team 2 are on the hill, it completely stops charging.

- If two people from team 1 and one person from team 2 are on the hill, the hill charges in favor of team 1, but at half the speed. (Or three people from one team and two people from the other team or whatever combination you can come up with from there if that makes sense.)

Every solution I can come up with, the hill object would have to know how many objects are currently colliding with it, and what team each object is on. Each player object currently has a variable that denotes its team, so that information does exist. Does that sound right? What can I do to make this work?
 

YoSniper

Member
I would suggest counting the number from each team using a with statement. This is an example script that would help you achieve your goal.

Script charge()
Code:
//RETURNS 1 if the meter should charge for team #1.
//RETURNS 2 if the meter should charge for team #2.
//RETURNS 0 if the meter should not charge for either team.

//Assumed: all player objects are instances of obj_player, and the distinction between teams is an attribute team_number, which is either 1 or 2.

var count_1, count_2;
count_1 = 0;
count_2 = 0;
with(obj_player) {
    if standing_on_hill {
        if team_number == 1 {
            count_1 += 1;
        } else if team_number == 2 {
            count_2 += 2;
        }
    }
}

if count_1 > count_2 {
    return 1;
}
if count_2 > count_1 {
    return 2;
}

//Catch all
return 0;
 
N

nonodev

Guest
A solution can be:
Code:
///collision_circle_multiple(x,y,rad,obj,prec,notme);
//Gets a list of the instances that collides with the circle
//Returns: Array
var _array;
var _x = argument0;
var _y = argument1;
var _rad = argument2;
var _obj = argument3;
var _prec = argument4;
var _notme = argument5;

var _count = 0;
var _col = collision_circle(_x,_y,_rad,_obj_prec,_notme);
while (_col !=noone) {
   _array[_count] = _col;
   instance_deactivate_object(_col);
   _col = collision_circle(_x,_y,_rad,_obj_prec,_notme);
}
for (var i=0;i<_count;i++) {
   instance_activate_object(_array[_count]);
}

return _array;
Now you should call that script like:
Code:
var _instList = collision_circle_multiple(x,y,rad,obj,prec,notme);
var _redNumber = 0;
var _blueNumber = 0;
for (var i=0;i<array_length_1d(_instList);i++) {
  var _inst = _instList[i];
   if (_inst.team==red) {
      _redNumber++;
   } else if (_inst.team==blue) {
      _blueNumber++;
   }
}
And voila!
 
N

nonodev

Guest
A solution can be:
Code:
///collision_circle_multiple(x,y,rad,obj,prec,notme);
//Gets a list of the instances that collides with the circle
//Returns: Array
var _array;
var _x = argument0;
var _y = argument1;
var _rad = argument2;
var _obj = argument3;
var _prec = argument4;
var _notme = argument5;

var _count = 0;
var _col = collision_circle(_x,_y,_rad,_obj_prec,_notme);
while (_col !=noone) {
   _array[_count] = _col;
   instance_deactivate_object(_col);
   _col = collision_circle(_x,_y,_rad,_obj_prec,_notme);
}
for (var i=0;i<_count;i++) {
   instance_activate_object(_array[_count]);
}

return _array;
Now you should call that script like:
Code:
var _instList = collision_circle_multiple(x,y,rad,obj,prec,notme);
var _redNumber = 0;
var _blueNumber = 0;
for (var i=0;i<array_length_1d(_instList);i++) {
   var _inst = _instList[i];
   if (_inst.team==red) {
      _redNumber++;
   } else if (_inst.team==blue) {
      _blueNumber++;
   }
}
And voila!
 
Top