Book Image

Corona SDK HOTSHOT

By : Nevin Flanagan
Book Image

Corona SDK HOTSHOT

By: Nevin Flanagan

Overview of this book

<p>If you've used the Corona Software Development Kit to build your very first new mobile app, you already know how easy it makes developing across all the pieces of this fragmented market. This book upgrades your knowledge of Lua and the Corona API with designs, habits and advanced concepts to speed your development and create more exciting apps.</p> <p>Corona SDK Hotshot will show you how to combine advanced Lua features such as coroutines and metatables with Corona's sophisticated tools, including physics and networking, to develop exactly the game or app you or your customers need, quickly and with an eye towards updating your app with improvements in the future.</p> <p>Corona SDK Hotshot will expand your basic knowledge of Corona with an insight into making the most of its event platform, using physics wisely and easily, and moving on to advanced programming tasks like path-finding.</p> <p>You will focus heavily on how to keep your programs understandable as they become more complicated, by using modules and events to divide it up. You'll practice ways to make AI scripts and map files easily understandable to designers and other collaborators, and use networks like GameCenter to publish progress.</p> <p>The last projects will combine the full range of covered material to illustrate how you can produce sophisticated and exciting apps as a Corona Hotshot!</p>
Table of Contents (18 chapters)
Corona SDK HOTSHOT
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Structuring the A* algorithm


We'll lay out the basic structure of the A* search, looking for the point of the current search border likeliest to be closest to the destination, checking to see if any of them offer a faster route to known spaces, and whether or not we have reached our target.

Getting ready

Create a new file, path.lua, and open it for editing.

Getting on with it

We'll start by laying out the generic skeleton of an A* implementation.

Assembling the requirements

In addition to a start position, a goal position, a progress function, and a heuristic function, A* needs to create two things internally to do its job—a list of spaces currently on the border of its search, and the known costs to reach them, and a list of the spaces that the search has determined which are in the best path to any given known space using the following code:

return function(start, goal, neighbors, h)
  local costs = {[start] = 0}
  local parents = {}
end

Selecting the cheapest choice

The costs table holds all...