private void CheckPhotos() { //store players location for easy access in distance calculations var playerLocation = new MapLocation(gpsLocationService.Longitude, gpsLocationService.Latitude); //get the current Epoch time in seconds var now = Epoch.Now; foreach (Photo p in photos) { var d = MathG.Distance(p.location, playerLocation); if (MathG.Distance(p.location, playerLocation) < photoSeeDistance) { p.lastSeenTimestamp = now; if (p.gameObject == null) { print("Monster seen, distance " + d + " started at " + p.spawnTimestamp); SpawnPhoto(p); } else { p.gameObject.SetActive(true); //make sure the monster is visible } continue; } //hide monsters that can't be seen if (p.gameObject != null) { p.gameObject.SetActive(false); } } }
private void CheckMonsters() { if (Random.value > monsterSpawnRate) { var mlat = gpsLocationService.Latitude + Random.Range(-latitudeSpawnOffset, latitudeSpawnOffset); var mlon = gpsLocationService.Longitude + Random.Range(-longitudeSpawnOffset, longitudeSpawnOffset); var monster = new Monster { location = new MapLocation(mlon, mlat), spawnTimestamp = gpsLocationService.PlayerTimestamp }; monsters.Add(monster); } //store players location for easy access in distance calculations var playerLocation = new MapLocation(gpsLocationService.Longitude, gpsLocationService.Latitude); //get the current Epoch time in seconds var now = Epoch.Now; foreach (Monster m in monsters) { var d = MathG.Distance(m.location, playerLocation); if (MathG.Distance(m.location, playerLocation) < monsterSeeDistance) { m.lastSeenTimestamp = now; m.footstepRange = 4; if (m.gameObject == null) { print("Monster seen, distance " + d + " started at " + m.spawnTimestamp); SpawnMonster(m); } else { m.gameObject.SetActive(true); //make sure the monster is visible } continue; } if (MathG.Distance(m.location, playerLocation) < monsterHearDistance) { m.lastHeardTimestamp = now; var footsteps = CalculateFootstepRange(d); m.footstepRange = footsteps; print("Monster heard, footsteps " + footsteps); } //hide monsters that can't be seen if (m.gameObject != null) { m.gameObject.SetActive(false); } } }
// Update is called once per frame void Update() { if (gpsLocationService != null && gpsLocationService.IsServiceStarted && gpsLocationService.PlayerTimestamp > lastTimestamp) { lastTimestamp = gpsLocationService.PlayerTimestamp; //test code var s = MathG.Distance(gpsLocationService.Longitude, gpsLocationService.Latitude, gpsLocationService.mapCenter.Longitude, gpsLocationService.mapCenter.Latitude); print("Player Distance from map tile center = " + s); //update the photos around the player CheckPhotos(); } }