// ALL FACE void NPC::AllFace(int identity, int section, double x) { bool anyID = (identity == -1 ? true : false); bool anySec = (section == -1 ? true : false); NPCMOB* thisnpc; for(int i = 0; i < GM_NPCS_COUNT; i++) { thisnpc = Get(i); if (anyID || thisnpc->id == identity) { if(anySec || GetSection(thisnpc) == section) { if(x < thisnpc->momentum.x) { FaceDirection(thisnpc, -1); } else { FaceDirection(thisnpc, 1); } } } } }
void Enemy::Update(int x_tile, int y_tile, Tilemap* map) { anim.Tick(); time_until_next_step.Update(); offset_from_tile *= 0.9; int player_x, player_y; map->PlayerObject(player_x, player_y); // Check if this enemy actually cares about the player at the moment Vector dist((float)player_x - (float)x_tile, (float)player_y - (float)y_tile); if (dist.X()*dist.X() + dist.Y()*dist.Y() <= radius_of_caring*radius_of_caring) { // I'm pretty sure its quicker to multiply that run a sqare root. Doubt it makes any real difference though FaceDirection(Strategy(Vector(x_tile, y_tile), Vector(player_x, player_y), map)); if (!map->IsMovementBlocked()) { int new_x = x_tile, new_y = y_tile; Vector tile_offset; switch (dir) { case up: new_y = y_tile > 0 ? (int)y_tile - 1 : y_tile; tile_offset = Vector(0.0, tile_dim.Y()); break; case down: new_y = y_tile < 10 ? y_tile + 1 : y_tile; tile_offset = Vector(0.0, -tile_dim.Y()); break; case left: new_x = x_tile > 0 ? (int)x_tile - 1 : x_tile; tile_offset = Vector(tile_dim.X(), 0.0); break; case right: new_x = x_tile < 10 ? x_tile + 1 : x_tile; tile_offset = Vector(-tile_dim.X(), 0.0); break; case nowhere: default: // Stay still break; } if (time_until_next_step) { offset_from_tile = tile_offset; TileObject* obj_swapping_with = map->ObjectAt(new_x, new_y); if (obj_swapping_with != NULL && obj_swapping_with->WhatAmI() == player1) ((Player*)(map->ObjectAt(new_x, new_y)))->CollidedWithEnemy(map); else { owner->SwapObjects(map->GetTile(new_x, new_y)); time_until_next_step.SetTicks(step_time); } } } } }
void Player::CollidedWithEnemy(Tilemap* map) { map->BlockMovement(60); --lives; reward = reward_entered_level_with; ammo = ammo_entered_level_with; map->SetUpMap(generated_tilemap, generated_objectmap, this); FaceDirection(up); offset_from_tile = Vector(0, 32); died = true; }
void Humanoid::MoveInDirection(Vector *vMove) { SetMaxSpeed(vMove->Length()); if(*vMove!=Vector(0.0f, 0.0f, 0.0f)) { if(vInternal.LengthSquared()<GetMaxSpeed()*GetMaxSpeed()) { Vector vForce= *vMove/(GetAcceleration()*Timer::GetElapsedTime()); vInternal+=vForce; } } if(!vMove->IsZeroVector()) FaceDirection(*vMove); }
void Player::Update(int x, int y, Tilemap* map) { map->SetVisibility(x-2, y-1, 50); map->SetVisibility(x-2, y, 50); map->SetVisibility(x-2, y+1, 50); map->SetVisibility(x+2, y-1, 50); map->SetVisibility(x+2, y, 50); map->SetVisibility(x+2, y+1, 50); map->SetVisibility(x-1, y-2, 50); map->SetVisibility(x, y-2, 50); map->SetVisibility(x+1, y-2, 50); map->SetVisibility(x-1, y+2, 50); map->SetVisibility(x, y+2, 50); map->SetVisibility(x+1, y+2, 50); map->SetVisibility(x-1, y-1, 200); map->SetVisibility(x-1, y, 256); map->SetVisibility(x-1, y+1, 200); map->SetVisibility(x, y-1, 256); map->SetVisibility(x, y, 256); map->SetVisibility(x, y+1, 256); map->SetVisibility(x+1, y-1, 200); map->SetVisibility(x+1, y, 256); map->SetVisibility(x+1, y+1, 200); anim.Tick(); time_until_next_step.Update(); can_do_special_ability.Update(); time_until_stop_shot.Update(); bool move_tile = false; Vector which_tile_go_to; offset_from_tile *= 0.8; if (!map->IsMovementBlocked()) { if (key[KEY_UP]) { if (map->GetTile(x, y-1).IsPassable() && time_until_next_step.Finished()) { move_tile = true; which_tile_go_to = Vector(x, y-1); offset_from_tile = Vector(0.0, tile_dim.Y()); } FaceDirection(up); } else if (key[KEY_DOWN]) { if (map->GetTile(x, y+1).IsPassable() && time_until_next_step.Finished()) { move_tile = true; which_tile_go_to = Vector(x, y+1); offset_from_tile = Vector(0.0, -tile_dim.Y()); } FaceDirection(down); } else if (key[KEY_LEFT]) { if (map->GetTile(x-1, y).IsPassable() && time_until_next_step.Finished()) { move_tile = true; which_tile_go_to = Vector(x-1, y); offset_from_tile = Vector(tile_dim.X(), 0.0); } FaceDirection(left); } else if (key[KEY_RIGHT]) { if (map->GetTile(x+1, y).IsPassable() && time_until_next_step.Finished()) { move_tile = true; which_tile_go_to = Vector(x+1, y); offset_from_tile = Vector(-tile_dim.X(), 0.0); } FaceDirection(right); } if (key[KEY_SPACE] && can_do_special_ability && ammo > 0) { TileObject* first_object_found = NULL; int x_tile_stopped_at, y_tile_stopped_at; switch (dir) { case up: { for (int i=y-1; i>=0; --i) { x_tile_stopped_at = x; y_tile_stopped_at = i; first_object_found = map->ObjectAt(x, i); if (first_object_found != NULL || !map->GetTile(x, i).IsPassable()) break; if (i==0) break; } break; } case down: { for (int i=y+1; i<9; ++i) { x_tile_stopped_at = x; y_tile_stopped_at = i; first_object_found = map->ObjectAt(x, i); if (first_object_found != NULL || !map->GetTile(x, i).IsPassable()) break; } break; } case left: { for (int i=x-1; i>=0; --i) { x_tile_stopped_at = i; y_tile_stopped_at = y; first_object_found = map->ObjectAt(i, y); if (first_object_found != NULL || !map->GetTile(i, y).IsPassable()) break; if (i==0) break; } break; } case right: { for (int i=x+1; i<10; ++i) { x_tile_stopped_at = i; y_tile_stopped_at = y; first_object_found = map->ObjectAt(i, y); if (first_object_found != NULL || !map->GetTile(i, y).IsPassable()) break; } break; } case nowhere: default: break; } if (first_object_found != NULL && first_object_found->WhatAmI() == enemy) { map->GetTile(x_tile_stopped_at, y_tile_stopped_at).SetTileType(5); delete (Enemy1*)first_object_found; map->GetTile(x_tile_stopped_at, y_tile_stopped_at).SetObject(NULL); map->GetTile(x_tile_stopped_at, y_tile_stopped_at).SetTileType(GLOBDAT_tile_bloodstainedpath); } time_until_next_step.SetTicks(24); time_until_stop_shot.SetTicks(20); can_do_special_ability.SetTicks(60); where_to_shoot = Vector(x_tile_stopped_at, y_tile_stopped_at); --ammo; } } if (move_tile) { // Check whats on the tile Tile& new_tile = map->GetTile(which_tile_go_to.XInt(), which_tile_go_to.YInt()); TileObject* object_on_new_tile = new_tile.GetObject(); ObjectType obj_type; if (object_on_new_tile == NULL) obj_type = nothing; else obj_type = object_on_new_tile->WhatAmI(); switch (obj_type) { default: case nothing: owner->SwapObjects(map->GetTile(which_tile_go_to.XInt(), which_tile_go_to.YInt())); time_until_next_step.SetTicks(10); break; case civilian1: last_reward_recieved = ((Civilian*)(object_on_new_tile))->GetReward(); reward += last_reward_recieved; new_tile.RemoveObject(); owner->SwapObjects(new_tile); time_until_next_step.SetTicks(10); map->DoCivilianSplash(); break; case enemy: CollidedWithEnemy(map); break; case nextlevel: ++current_level; GenerateTilemap(); map->SetUpMap(generated_tilemap, generated_objectmap, this); map->SetAllVisibilities(1); break; case ammo_stash: ammo += 1+rand() % max_ammo_from_stash-1; delete (AmmoStash*)(new_tile.RemoveObject());; owner->SwapObjects(new_tile); time_until_next_step.SetTicks(10); break; } } }