Making a Simple Snake Flash Game - part1

Posted by Boros Csaba on 2013/08/04 with 0 comments
Everyone played snake, it`s a very simple but fun to play little classic game. The player is controlling the head of the snake and the snake`s tail follows. The goal is to help the snake growing by collecting food and other items without hitting it`s own tail or the walls. As the snake grows and the game speed is increasing it can get really difficult.

For this tutorial I will use FlashDevelop and ActionScript3. To keep things organized I will use multiple classes and I recommend you to do the same.

First we will create a snake piece object: snake_square (extends Sprite) This object will contain the image of a square of the snake, it`s position on the screen (default for Sprite) and a reference to the next piece of the snake, the last square of the snake will have a null reference.
public class snake_square extends Sprite
 {
  
  
  
  private const snake_square_size:int = 20;
  
  
  
  public  var next_square:snake_square = null;
  
  
  
  public function snake_square() 
  {
   
   this.graphics.beginFill(0x464749);
   this.graphics.drawRoundRect(0, 
          0, 
          snake_square_size, 
          snake_square_size, 
          10, 
          10);
   this.graphics.endFill();
   
  }
  
  
  
 }
In the main class I`we defined the following function to start the game:
public function new_game():void {
   
 snake = new snake_square();
 addChild(snake);
   
}
After calling the new_game() function we will see the "head" of the snake on the upper left corner of the screen (I`we set the background color to #BFE0CF) snake game

Now the movement. For the movement of the snake we will create a game_loop function with an Event.ENTER_FRAME event listener, but we will move the snake only after skipping n frames. Later by lower the number of skipped frames we can increase the speed of the game.

The snake will be able to go in 4 different directions, but we will need to limits it movement to a maximum 90 degree turn in a single step. For this purpose we will store the actual direction and the next direction separately.

Test post for the new template

Posted by Boros Csaba on 2013/08/03 with 0 comments
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.

Labels: