Results 1 to 5 of 5
  1. #1
    nabil is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default want to add BLOCK into snake game

    hello world..
    i've create a simple snake game..
    every level have the same gameplay and the different is only the speed of the snake..
    now i want to try adding a BLOCK into the game,so when the snake crash into the BLOCK it will be game over just as if it crash into the wall..
    do anybody have any idea how can i add it??

    thank you~~

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: want to add BLOCK into snake game

    Create a class called Block, give it the properties and methods it needs and use it in your program.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    nabil is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: want to add BLOCK into snake game

    Quote Originally Posted by Norm View Post
    Create a class called Block, give it the properties and methods it needs and use it in your program.
    ok then..but what should i use to create that block??is it i have to have a picture of the block and call it in the coding??then how to make it game over when the snake crash on it??

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: want to add BLOCK into snake game

    The Block class could show an image or it could just use the fillRect method to make a solid color for its contents.
    Somewhere in your code there would need to be code that detected where the snake and the block were placed to determine when a crash occurred.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Borkpaladin is offline Member
    Join Date
    Mar 2012
    Posts
    8
    Rep Power
    0

    Default Re: want to add BLOCK into snake game

    The block class could have a getBounds method that returns a rectangle, the get the bounds of the snake and use if(snake.intersects(BLOCK.getBounds()){} etc...
    to check if the snake hits the block.

Similar Threads

  1. Snake Game
    By LuluMM in forum New To Java
    Replies: 0
    Last Post: 03-08-2012, 06:48 AM
  2. Snake Game in Java
    By Shyamz1 in forum New To Java
    Replies: 4
    Last Post: 02-10-2011, 02:49 PM
  3. Snake Game Applet
    By Growler in forum Java Applets
    Replies: 6
    Last Post: 07-11-2010, 02:47 PM
  4. Snake game in java
    By freaky in forum New To Java
    Replies: 5
    Last Post: 04-20-2010, 06:34 PM
  5. Snake Game
    By mustachMan in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 10:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •