Fire a bullet with jQuery/Javascript
<p>I'm having a problem with making a fire-a-bullet-function in JavaScript/jQuery. The idea is, when im pressing the space-button a fire will be shot to the right. But I don't know how I can make this possible. </p>

<p>Here is working example: <a href="http://jsfiddle.net/DuCFV/1/" rel="nofollow">http://jsfiddle.net/DuCFV/1/</a> (You control the player with WASD)</p>

<p>Here is the code: </p>

<pre><code> &lt;!DOCTYPE &gt;
 &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script src="http://code.jquery.com/jquery-1.6.4.min.js"&gt;&lt;/script&gt;
    &lt;style&gt;
        body {
            margin: 0px;
            padding: 0px;
            margin-top: 200px;
        }
        #gameField {
            width: 750px;
            height: 400px;
            border: 5px solid #ccffff;
            margin: auto;

        }
        #block {
            position: absolute;
            border: 5px solid #FFB2FF;
            left: 48%;
            right: 0px;
            top: 50%;
            bottom: 0px;
            width: 46px;
            height: 46px;
            margin: 0;
            border-radius: 90px;

        }
        .bullet {
            background-color: red;
            width: 20px;
            height: 20px;
            border-radius: 20px;
        }
    &lt;/style&gt;
    &lt;script&gt;
        $(document).ready(function() {
            playerX = 750;
            playerY = 400;
            bulletX = 0;
            bulletY = 0;


            function gameLoop() {
                $('#block').css({
                    'top' : playerY,
                    'left' : playerX
                });

                $('.bullet').css({
                    'top' : bulletY,
                    'left' : bulletX
                });

                setTimeout(gameLoop, 60);
            }

            gameLoop();
        });



        $(document).keydown(function(event) {
            switch(event.keyCode) {

                case 65:
                    playerX = playerX - 10 // MOVE LEFT
                    break;
                case 87:
                    playerY = playerY - 10 // MOVE UP
                    break;
                case 68:
                    playerX = playerX + 15 // MOVE RIGHT
                    break;
                case 83:
                    playerY = playerY + 10 // MOVE DOWN
                    break;
                case 32:    // FIRE BULLET WITH SPACE-BUTTON.           
                    $('#block').append('&lt;div class="bullet"&gt;&lt;/div&gt;');
                    bulletX = bulletX + 10
                    break   
      });

    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id="gameField"&gt;
        &lt;div id="block"&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;
</code></pre>

<p></p>
