Hardware Reference
In-Depth Information
Using Geo-Fencing
to.Charge.Rent
Now you are going to write a new game, called rent.py . This game consists of a field
with a fence around it. Your program will detect when your player is standing in this field
and charge rent all the while the player is in the field. Your player's challenge is to remove
any objects in this field in the fastest time possible, so that rent is as low as possible.
Your welcomeHome.py program used an if statement to check whether the coordi-
nates of your player were the same as the coordinates of your doormat. For this to
work, your player has to be standing exactly on the doormat. You can improve on this
a bit by using a technique called geo-fencing , which you will use in this new game. The
detection of your player's position is improved because it checks to see if your player is
standing in an area of the Minecraft world, not just at a specific coordinate. This allows
you to detect when your player is standing anywhere in a larger region of the world,
and you don't have to be quite so precise when standing on blocks.
Geo-fencing is a general technique that builds a virtual fence around coordinates
on any map. When something enters this virtual fenced region, something happens
as a result. “Something” could mean a player in the Minecraft world, a person in
the real world, or a device like a lawnmower or even an animal in the real world.
In many cases, geo-fencing is used to alert the user when something—such as
cattle, for example, or a vehicle—moves outside of a pre-determined region. You
can find out more about real world uses of geo-fencing at http://en.wikipedia.
org/wiki/Geo-fence and also find out how geo-fencing is being used in real life
to track elephants in the wild here: http://www.cbsnews.com/news/kenya-uses-
text-messages-to-track-elephant/
For geo-fencing to work, you need two things: an object or region to track, and the
allowed coordinates of the “fence” around that object. You're now going to find out
how to do this by building a field with a real Minecraft fence around it and noting
down the coordinates of the corners of the field.
You don't have to build the fence for this program to work but it makes the game a
bit more interesting to play if you do, because you have to jump over the fence or run
a long way round to get to the gap in the fence, to get in and out of the field. Adding
obstacles to games makes them more challenging and exciting. This Minecraft
fence will line up with the coordinates of your virtual geo-fence, and it gives your
program a simple way to answer the question “is the player in the field or not?”
 
Search WWH ::




Custom Search