Drunk_Snake Game PLEASE HELP!! - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=30) +----- Thread: Drunk_Snake Game PLEASE HELP!! (/showthread.php?tid=820) |
Drunk_Snake Game PLEASE HELP!! - andre2pi - 12-29-2013 Hello everyone! I'm trying to implement a funny version of the snake game posted on youtube by brandonioproduction , and I'm kind of stucked. The idea is to make the snake wobble after eating some fruits ( that in the end will be changed to beers <!-- s --><img src="{SMILIES_PATH}/icon_e_wink.gif" alt="" title="Wink" /><!-- s --> ) so by the move() when the snake is going direction.NORTH for example , the coordinates are (head.x , head.y -1) so it goes straight up. I have to implement something that changes the head.x like this: case Direction.NORTH: newPoint = new Point(head.x -1, head.y - 1); then newPoint = new Point(head.x +1, head.y - 1); then newPoint = new Point(head.x -1, head.y - 1); then newPoint = new Point(head.x +1, head.y - 1); so you get the idea here. The snake would zigzag in x axis when moving vertically. and of course also would zigzag in the y axis when going horizontally. Any Ideas are very welcome !! cheers! Re: Drunk_Snake Game PLEASE HELP!! - andre2pi - 12-29-2013 the link for the source is here: <!-- l --><a class="postlink-local" href="http://bpforums.info/download/file.php?id=195">download/file.php?id=195</a><!-- l --> Re: Drunk_Snake Game PLEASE HELP!! - brandonio21 - 01-05-2014 What you could do is simply have a global variable to keep track of the portion of the zigzag (whether we are going in the positive or negative direction). For example, at the top of the code.. [code2=java]private int xDir = 1;[/code2] And then, every time the snake moves, we simply change this variable, for example... [code2=java]case Direction.NORTH: newPoint = new Point(head.x + xDir, head.y - 1); xDir *= -1; break;[/code2] This would create a wobble effect that works every turn. In order to make this for the y-axis, you would simply need a yDir global variable! |