void Player::OnCollideFuel(FuelCell* f) { // New behaviour: // Increment food count, if less than daily limit; make food invis. // Else: attach food to player, drag around. Give to other player we intersect. Ve1Object* owner = f->GetOwner(); bool weAreHungry = GetLocalPlayerFuelCount() <= DailyFoodCount(); if (owner == this) { // We are already carrying this food return; } else if (owner && !weAreHungry) { // Another player is carrying this food. // We are not hungry, so we don't take the food. return; } else if (owner && weAreHungry) { // Another player is carrying this food. // We are hungry, so we eat it. // The other player should get some reward for feeding us. EatFood(f); } else if (!owner && weAreHungry) { // Noone is carrying the food. // We are hungry, so we eat it. EatFood(f); } else if (!owner && !weAreHungry) { // Noone is carrying the food. // We are not hungry, so we pick up the food. LurkMsg lm("You picked up some food!", LURK_FG, LURK_BG, AMJU_CENTRE); TheLurker::Instance()->Queue(lm); f->SetOwner(this); } else { Assert(0); } static GSMain* gsm = TheGSMain::Instance(); gsm->SetFuelCells(GetLocalPlayerFuelCount()); }
void Snake::Move(Food& food, int dif) { TestBorderCollision(); if (gameover) { return; } for (int i = 0; i < s_parts.size(); i++) { standard_field.EraseAtMap(s_parts[i].GetX(), s_parts[i].GetY()); switch (s_parts[i].GetDirection()) { case UP: s_parts[i].SetY(s_parts[i].GetY() - 1); break; case RIGHT: s_parts[i].SetX(s_parts[i].GetX() + 1); break; case DOWN: s_parts[i].SetY(s_parts[i].GetY() + 1); break; case LEFT: s_parts[i].SetX(s_parts[i].GetX() - 1); break; } standard_field.AddToMap(s_parts[i].GetX(), s_parts[i].GetY(), SNAKE_PART); } if (s_parts[0].GetX() == food.GetX() && s_parts[0].GetY() == food.GetY()) { EatFood(food, dif); food.Generate(); } for (int i = s_parts.size() - 1; i > 0; i--) { if (s_parts[i].GetDirection() != s_parts[i - 1].GetDirection()) { s_parts[i].SetDirection(s_parts[i - 1].GetDirection()); } } TestSelfCollision(); }