Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:11:07+00:00 2026-06-06T12:11:07+00:00

So here is my snake script – http://jsfiddle.net/6bKHc/24/ I started to create a snake

  • 0

So here is my snake script –

http://jsfiddle.net/6bKHc/24/

I started to create a snake game, but basically move(top), move(bottom) e.c. is not working. Any ideas why? I understand that I can’t pass the elements to variable like this, so maybe you could show me how to do that correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:11:08+00:00Added an answer on June 6, 2026 at 12:11 pm

    Ok cleared syntax and took a look at errors this should get you started

    $(document).keydown(function(event){
        var move, inter;
        inter = setInterval(move = function() {
            var dir = $(".snake").data('dir');
            var snake = $('.snake');
    
            if(dir == 'top') {
                snake.stop().animate({"top": "+=5px"});
            }
            if(dir == 'bottom') {
                snake.stop().animate({"top": "-=5px"});
            }
            if(dir == 'left') {
                snake.stop().animate({"left": "+=5px"});
            }
            if(dir == 'right') {
                snake.stop().animate({"top": "-=5px"});
            }
        }, 500);
        if(event.which == 40) {
            $(".snake").data('dir','top');
        } else if(event.which == 39) {
            $(".snake").data('dir','left');           
        } else if(event.which == 37) {
            $(".snake").data('dir','right');        
        } else if(event.which == 38) {
           $(".snake").data('dir','bottom');    
        }; });​
    

    fiddle

    Couple of obvious additions to make:

    • boundary checking
    • smoothness of animation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie on Unity 3d.I have started practising with a snake game. I
Demo I am trying to make a snake game in html 5 canvas. But
I'm trying to learn Python, (i have 2.5.4) by writing a snake game, but
Here the total height of all <div> 's are 900 pixels, but the jQuery
Greetings! I'm creating a simple snake game. I want to expand my classes in
I'm not even sure this is possible to do efficiently, but here's my problem:
Here's a strange bug that appears on the iPhone (4S) but not the iPad
For the sake of argument, here's a simple person class public class Person :
Here's my proposed (very simplified to illustrate the problem space) design for a C#
Here is a complete example. I want to forbid using A::set from objects casted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.