2011-01-16 15:53:14 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2011-01-16 16:29:00 +00:00
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2011-01-16 15:53:14 +00:00
|
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
|
|
<head>
|
2011-01-16 16:29:00 +00:00
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
|
|
<title>HardonCollider - A collision detection library</title>
|
2011-01-18 14:35:55 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
2011-01-16 18:28:07 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="highlight.css" />
|
|
|
|
<script type="text/javascript" src="highlight.pack.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.onload = function() {
|
|
|
|
var examples = document.getElementsByTagName("code");
|
|
|
|
for (i = 0; i < examples.length; ++i) {
|
|
|
|
if (examples[i].className == "lua")
|
|
|
|
hljs.highlightBlock(examples[i], " ");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
2011-01-16 15:53:14 +00:00
|
|
|
</head>
|
|
|
|
|
2011-01-16 16:29:00 +00:00
|
|
|
<body><a name="top"></a>
|
2011-02-02 21:20:27 +00:00
|
|
|
<!--<a href="http://github.com/vrld/HardonCollider"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>-->
|
2011-01-16 16:29:00 +00:00
|
|
|
|
|
|
|
<div id="header">
|
|
|
|
<h1>Hardon Collider <span class="small">Collision detection for <a href="http://www.love2d.org/">LÖVE</a></span></h1>
|
2011-01-24 19:36:04 +00:00
|
|
|
<ul id="main-nav">
|
|
|
|
<li><a href="index.html">Home</a></li>
|
|
|
|
<li><a href="tutorial.html">Tutorial</a></li>
|
|
|
|
<li><a href="reference.html">Reference</a></li>
|
2011-01-16 16:29:00 +00:00
|
|
|
</ul>
|
2011-01-24 19:36:04 +00:00
|
|
|
<h2>Home</h2>
|
2011-01-16 16:29:00 +00:00
|
|
|
</div>
|
|
|
|
|
2011-01-18 19:25:29 +00:00
|
|
|
<a name="hardoncollider"></a>
|
2011-02-17 15:03:00 +00:00
|
|
|
<div id="hardoncollider" class="outer-block">
|
|
|
|
<h3>HardonCollider<a class="top" href="#top">^ top</a></h3>
|
2011-01-16 16:29:00 +00:00
|
|
|
<div class="preamble">
|
2011-01-24 19:36:04 +00:00
|
|
|
<p>HardonCollider is a Lua module to simplify one important aspect in
|
|
|
|
computer games: Collision detection.</p>
|
|
|
|
<p>It can detect collisions between arbitrary positioned and rotated shapes.
|
|
|
|
Those shapes can either be circles or polygons. Any non-intersecting polygons
|
|
|
|
are supported, even concave ones.</p>
|
|
|
|
<p>The main interface is simple:
|
|
|
|
<ul>
|
|
|
|
<li>Define collision callbacks,</li>
|
|
|
|
<li>Add shapes to the scene and</li>
|
|
|
|
<li>Update HardonCollider every frame.</li>
|
|
|
|
</ul>
|
|
|
|
</p>
|
2011-01-16 16:29:00 +00:00
|
|
|
</div>
|
|
|
|
|
2011-02-17 15:03:00 +00:00
|
|
|
<div class="text-block">
|
|
|
|
<h4>Download</h4>
|
2011-02-16 18:02:52 +00:00
|
|
|
<p>You can download the latest packaged version as <a href="http://github.com/vrld/HardonCollider/zipball/master">zip</a>-
|
2011-01-24 19:36:04 +00:00
|
|
|
or <a href="http://github.com/vrld/HardonCollider/tarball/master">tar</a>-archive directly from
|
2011-02-16 18:02:52 +00:00
|
|
|
<a href="http://github.com/">github</a>. In that archive there will be a directory called
|
2011-02-16 18:05:15 +00:00
|
|
|
<code>vrld-HardonCollider-<numbers></code> - you probably want to rename that to something
|
|
|
|
shorter (<code>hardoncollider</code> comes to mind).</p>
|
2011-02-16 18:02:52 +00:00
|
|
|
<p>You can also have a look at the sourcecode online <a href="http://github.com/vrld/HardonCollider">here</a>.</p>
|
2011-01-24 19:36:04 +00:00
|
|
|
<p>If you use the <a href="http://git-scm.com">Git</a> command line client, you can clone
|
|
|
|
the repository by running:</p>
|
|
|
|
<pre>git clone git://github.com/vrld/HardonCollider.git</pre>
|
|
|
|
<p>Once done, you can check for updates by running:</p>
|
|
|
|
<pre>git pull</pre>
|
|
|
|
<p>from inside the directory.</p>
|
2011-01-16 16:29:00 +00:00
|
|
|
</div>
|
|
|
|
|
2011-02-17 15:03:00 +00:00
|
|
|
<div class="text-block">
|
|
|
|
<h4>First steps</h4>
|
2011-01-24 19:36:04 +00:00
|
|
|
<p>This is an example on how to use HardonCollider.
|
|
|
|
One shape will stick to the mouse position, while the other will stay in the same place:</p>
|
2011-12-09 23:10:50 +00:00
|
|
|
<pre><code class="lua">HC = require 'hardoncollider'
|
2011-01-24 19:36:04 +00:00
|
|
|
|
|
|
|
-- array to hold collision messages
|
|
|
|
local text = {}
|
|
|
|
|
2011-06-04 15:03:23 +00:00
|
|
|
-- this is called when two shapes collide
|
|
|
|
function on_collision(dt, shape_a, shape_b, mtv_x, mtv_y)
|
|
|
|
text[#text+1] = string.format("Colliding. mtv = (%s,%s)",
|
2011-01-24 19:36:04 +00:00
|
|
|
mtv_x, mtv_y)
|
2011-01-16 16:29:00 +00:00
|
|
|
end
|
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- this is called when two shapes stop colliding
|
|
|
|
function collision_stop(dt, shape_a, shape_b)
|
|
|
|
text[#text+1] = "Stopped colliding"
|
2011-01-16 16:29:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.load()
|
2011-01-24 19:36:04 +00:00
|
|
|
-- initialize library
|
2011-12-09 23:10:50 +00:00
|
|
|
Collider = HC(100, on_collision, collision_stop)
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- add a rectangle to the scene
|
2011-12-09 23:10:50 +00:00
|
|
|
rect = Collider:addRectangle(200,400,400,20)
|
2011-01-16 19:41:15 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- add a circle to the scene
|
2011-12-09 23:10:50 +00:00
|
|
|
mouse = Collider:addCircle(400,300,20)
|
2011-01-24 19:36:04 +00:00
|
|
|
mouse:moveTo(love.mouse.getPosition())
|
|
|
|
end
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
function love.update(dt)
|
|
|
|
-- move circle to mouse position
|
|
|
|
mouse:moveTo(love.mouse.getPosition())
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- rotate rectangle
|
|
|
|
rect:rotate(dt)
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- check for collisions
|
2011-12-09 23:10:50 +00:00
|
|
|
Collider:update(dt)
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
while #text > 40 do
|
|
|
|
table.remove(text, 1)
|
|
|
|
end
|
|
|
|
end
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-16 19:41:15 +00:00
|
|
|
function love.draw()
|
2011-01-24 19:36:04 +00:00
|
|
|
-- print messages
|
|
|
|
for i = 1,#text do
|
|
|
|
love.graphics.setColor(255,255,255, 255 - (i-1) * 6)
|
|
|
|
love.graphics.print(text[#text - (i-1)], 10, i * 15)
|
2011-01-16 19:41:15 +00:00
|
|
|
end
|
2011-01-16 16:29:00 +00:00
|
|
|
|
2011-01-24 19:36:04 +00:00
|
|
|
-- shapes can be drawn to the screen
|
|
|
|
love.graphics.setColor(255,255,255)
|
|
|
|
rect:draw('fill')
|
|
|
|
mouse:draw('fill')
|
|
|
|
end</code></pre>
|
2011-01-16 16:29:00 +00:00
|
|
|
</div>
|
|
|
|
|
2011-02-17 15:03:00 +00:00
|
|
|
<div class="text-block">
|
|
|
|
<h4>License</h4>
|
2011-01-24 19:36:04 +00:00
|
|
|
<blockquote id="license">
|
|
|
|
<p>Copyright (c) 2010-2011 Matthias Richter</p>
|
|
|
|
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:</p>
|
|
|
|
|
|
|
|
<p>The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.</p>
|
|
|
|
|
|
|
|
<p>Except as contained in this notice, the name(s) of the above copyright holders
|
|
|
|
shall not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
other dealings in this Software without prior written authorization.</p>
|
|
|
|
|
|
|
|
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.</p>
|
|
|
|
</blockquote>
|
2011-01-16 16:29:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2011-01-16 15:53:14 +00:00
|
|
|
|
2011-01-16 18:28:07 +00:00
|
|
|
</html>
|