<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[PunBB Forums - Checkout this Snake Game!]]></title>
	<link rel="self" href="http://punbb.informer.com/forums/feed/atom/topic/20903/"/>
	<updated>2009-09-04T14:30:45Z</updated>
	<generator>PunBB</generator>
	<id>http://punbb.informer.com/forums/topic/20903/checkout-this-snake-game/</id>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/130221/#p130221"/>
			<content type="html"><![CDATA[<p>good game</p>]]></content>
			<author>
				<name><![CDATA[nice4guy1]]></name>
				<uri>http://punbb.informer.com/forums/user/20600/</uri>
			</author>
			<updated>2009-09-04T14:30:45Z</updated>
			<id>http://punbb.informer.com/forums/post/130221/#p130221</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/130187/#p130187"/>
			<content type="html"><![CDATA[<p>Cool...</p>]]></content>
			<author>
				<name><![CDATA[patrikg]]></name>
				<uri>http://punbb.informer.com/forums/user/18045/</uri>
			</author>
			<updated>2009-09-04T06:14:50Z</updated>
			<id>http://punbb.informer.com/forums/post/130187/#p130187</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128499/#p128499"/>
			<content type="html"><![CDATA[<p>Good!</p><p>try it with opera: open any www site, view source, paste code and appy changes! Hooray <img src="http://punbb.informer.com/forums/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></content>
			<author>
				<name><![CDATA[thuankkk]]></name>
				<uri>http://punbb.informer.com/forums/user/14609/</uri>
			</author>
			<updated>2009-06-16T01:05:19Z</updated>
			<id>http://punbb.informer.com/forums/post/128499/#p128499</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128013/#p128013"/>
			<content type="html"><![CDATA[<p>I wrote this game last year. It is mine!</p><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><p>just kidding!</p>]]></content>
			<author>
				<name><![CDATA[esupergood]]></name>
				<uri>http://punbb.informer.com/forums/user/14286/</uri>
			</author>
			<updated>2009-05-28T10:32:44Z</updated>
			<id>http://punbb.informer.com/forums/post/128013/#p128013</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/128012/#p128012"/>
			<content type="html"><![CDATA[<p>It is available on net. This is my game</p>]]></content>
			<author>
				<name><![CDATA[jeffturner]]></name>
				<uri>http://punbb.informer.com/forums/user/15540/</uri>
			</author>
			<updated>2009-05-28T10:31:50Z</updated>
			<id>http://punbb.informer.com/forums/post/128012/#p128012</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/127810/#p127810"/>
			<content type="html"><![CDATA[<p>Is there a live link for this game?&nbsp; Would like to try it, but....</p>]]></content>
			<author>
				<name><![CDATA[tyebone]]></name>
				<uri>http://punbb.informer.com/forums/user/15487/</uri>
			</author>
			<updated>2009-05-19T15:37:59Z</updated>
			<id>http://punbb.informer.com/forums/post/127810/#p127810</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/123105/#p123105"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>Garciat wrote:</cite><blockquote><p>That&#039;s my snake game. Why can&#039;t you just paste a link to it?</p></blockquote></div><p>Fixed.</p>]]></content>
			<author>
				<name><![CDATA[Utchin]]></name>
				<uri>http://punbb.informer.com/forums/user/9648/</uri>
			</author>
			<updated>2009-01-18T01:00:12Z</updated>
			<id>http://punbb.informer.com/forums/post/123105/#p123105</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/123089/#p123089"/>
			<content type="html"><![CDATA[<p>That&#039;s my snake game. Why can&#039;t you just paste a link to it?</p>]]></content>
			<author>
				<name><![CDATA[Garciat]]></name>
				<uri>http://punbb.informer.com/forums/user/12481/</uri>
			</author>
			<updated>2009-01-17T20:15:51Z</updated>
			<id>http://punbb.informer.com/forums/post/123089/#p123089</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Checkout this Snake Game!]]></title>
			<link rel="alternate" href="http://punbb.informer.com/forums/post/123087/#p123087"/>
			<content type="html"><![CDATA[<div class="codebox"><pre><code> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
    &lt;head&gt;
        &lt;title&gt;Snake Game&lt;/title&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
        &lt;meta name=&quot;Description&quot; content=&quot;A JavaScript snake game using canvas HTML tag.&quot; /&gt;
        &lt;meta name=&quot;Keywords&quot; content=&quot;Garciat,Snake,Game,JavaScript,Canvas,HTML&quot; /&gt;
        &lt;meta name=&quot;robots&quot; content=&quot;NOSNIPPET, NOODP, NOARCHIVE&quot; /&gt;
        &lt;style type=&quot;text/css&quot;&gt;
body{
margin: 0;
background: #000;
color: #FFF;
font-family: Arial, Helvetica, sans-serif;
}

#wrap{
width: 450px;
margin: 50px auto;
}

h1{
margin: 0;
font-size: 42pt;
letter-spacing: -4px;
}

#canvas{
margin: 20px auto;
background: #FFF;
}

#start,#stats{
height: 300px;
margin: -320px 0 0 0;
padding: 10px;
color: #000;
display: none;
}

#start{
font-size: 18pt;
font-weight: bold;
text-decoration: underline;
line-height: 280px;
text-align: center;
display: block;
}
#start a{
cursor: pointer;
}

#stats{
color: #444;
}

p{
margin: 0;
}
        &lt;/style&gt;

        &lt;script type=&quot;text/javascript&quot;&gt;
var canvas, ctx, moveTimeout, game=false, paused=false, step, dir, pos=new Array(), snake, used, cookie=new Array(), speed, length, score;
var KEY = { RIGHT:39, UP:38, LEFT:37, DOWN:40, P:80 };

function startGame()
{
    canvas = document.getElementById(&quot;canvas&quot;);
    if(canvas.getContext)
    {
        ctx = canvas.getContext(&quot;2d&quot;);
        game=true; step=1; dir=2; pos[&quot;x&quot;]=15; pos[&quot;y&quot;]=10; snake=new Array(); used=new Array(); length=3; setScore(0); setSpeed(400);
        
        document.getElementById(&quot;start&quot;).style.display = &quot;none&quot;;
        document.getElementById(&quot;stats&quot;).style.display = &quot;block&quot;;
        
        for(x=0;x&lt;30;x++)
        {
            used[x] = new Array();
            for(y=0;y&lt;20;y++)
                used[x][y] = false;
        }
        
        placeCookie(); moveTimeout = setTimeout(move, speed);
    }
    else
        alert(&quot;Your browser cannot run this game. Use Firefox, Safari, or Opera.&quot;);
}

function move()
{
    for(i=1;i&lt;snake.length;i++) snake[i-1] = snake[i];
    
    if(snake[0])
    {
        var lastx = snake[0][&quot;x&quot;]; var lasty = snake[0][&quot;y&quot;];
        ctx.clearRect(lastx*15, lasty*15, 15, 15);
        used[lastx][lasty] = false;
    }
    
    switch(dir)
    {
        case 1: pos[&quot;y&quot;]--; break;
        case 2: pos[&quot;x&quot;]++; break;
        case 3: pos[&quot;y&quot;]++; break;
        case 4: pos[&quot;x&quot;]--; break;
    }
    
    var x = pos[&quot;x&quot;]; var y = pos[&quot;y&quot;];
    
    if((dir==1 &amp;&amp; pos[&quot;y&quot;]&lt;0) || (dir==2 &amp;&amp; pos[&quot;x&quot;]&gt;29) || (dir==3 &amp;&amp; pos[&quot;y&quot;]&gt;19) || (dir==4 &amp;&amp; pos[&quot;x&quot;]&lt;0) || used[x][y])
        return gameOver();
    
    snake[length] = new Array();
    snake[length][&quot;x&quot;] = pos[&quot;x&quot;];
    snake[length][&quot;y&quot;] = pos[&quot;y&quot;];
    
    ctx.fillStyle = &quot;#000&quot;;
    ctx.fillRect(x*15, y*15, 15, 15);
    used[x][y] = true;
    
    if(x==cookie[&quot;x&quot;] &amp;&amp; y==cookie[&quot;y&quot;])
    {
        placeCookie();
        setScore(score+Math.round(1000/speed)*100);
        length++;
        setSpeed(speed-5);
    }
    step = 1;
    setScore(score+1);
    moveTimeout = setTimeout(move, speed);
}

function changeDir(evt)
{
    var code = evt.keyCode;
    if(!game || (paused &amp;&amp; code!=KEY.P) || step==0) return;
    if(code==KEY.UP &amp;&amp; dir!=3)
        dir = 1;
    else if(code==KEY.RIGHT &amp;&amp; dir!=4)
        dir = 2;
    else if(code==KEY.DOWN &amp;&amp; dir!=1)
        dir = 3;
    else if(code==KEY.LEFT &amp;&amp; dir!=2)
        dir = 4;
    else if(code==KEY.P)
        pause();
    else if(code==33)
        setSpeed(speed-20);
    else if(code==34)
        setSpeed(speed+20);
        
    if(code!=KEY.P)
        step = 0;
}

function placeCookie()
{
    while(true)
    {
        x = Math.floor(Math.random()*30);
        y = Math.floor(Math.random()*20);
        if(!used[x][y] &amp;&amp; x!=15 &amp;&amp; y!=10) break;
    }
    
    ctx.fillStyle = &quot;#D00&quot;;
    ctx.fillRect(x*15+5, y*15+5, 5, 5);
    cookie[&quot;x&quot;] = x; cookie[&quot;y&quot;] = y;
}

function pause()
{
    alert(&quot;Game paused.&quot;);
}

function setSpeed(s)
{
    if(s&lt;20 || s&gt;400) return;
    speed = s;
    document.getElementById(&quot;speed&quot;).innerHTML = (420-s);
}

function setScore(s)
{
    score = s;
    document.getElementById(&quot;score&quot;).innerHTML = s;
}

function gameOver()
{
    clearTimeout(moveTimeout);
    alert(&quot;Game over! Length: &quot;+length);
    ctx.clearRect(0, 0, 450, 300);
    document.getElementById(&quot;start&quot;).style.display = &quot;block&quot;;
    game = false;
}
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body onkeydown=&quot;changeDir(event);&quot;&gt;
        &lt;div id=&quot;wrap&quot;&gt;
            &lt;h1&gt;Snake&lt;/h1&gt;
            &lt;canvas id=&quot;canvas&quot; width=&quot;450&quot; height=&quot;300&quot;&gt;Your browser cannot run this game, try using &lt;a href=&quot;http://firefox.com/&quot;&gt;Firefox&lt;/a&gt;, &lt;a href=&quot;http://apple.com/safari/&quot;&gt;Safari&lt;/a&gt;, or &lt;a href=&quot;http://opera.com/&quot;&gt;Opera&lt;/a&gt;.&lt;/canvas&gt;

            &lt;div id=&quot;start&quot;&gt;&lt;a onclick=&quot;startGame();&quot;&gt;Start&lt;/a&gt;&lt;/div&gt;
            &lt;div id=&quot;stats&quot;&gt;&lt;b&gt;Score:&lt;/b&gt; &lt;span id=&quot;score&quot;&gt;&lt;/span&gt; &lt;b style=&quot;margin-left:60px&quot;&gt;Speed:&lt;/b&gt; &lt;span id=&quot;speed&quot;&gt;&lt;/span&gt; &lt;/div&gt;
            &lt;p&gt;Copyright &amp;copy; 2008 &lt;a href=&quot;http://garciat.us.to/&quot;&gt;Garciat&lt;/a&gt;&lt;/p&gt;

        &lt;/div&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google-analytics.com/ga.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
        var pageTracker = _gat._getTracker(&quot;UA-2509211-5&quot;);
        pageTracker._trackPageview();
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt; </code></pre></div><p>Original website: <a href="http://garciat.us.to">Garciat</a></p>]]></content>
			<author>
				<name><![CDATA[Gavin12]]></name>
				<uri>http://punbb.informer.com/forums/user/14703/</uri>
			</author>
			<updated>2009-01-17T19:38:49Z</updated>
			<id>http://punbb.informer.com/forums/post/123087/#p123087</id>
		</entry>
</feed>
