On screen snake how to#
You learned how to create the game snake in Python along with concepts such as collision detection, image loading and event handling. Self._apple_surf = ( "block.jpg").convert() Self._image_surf = ( "block.jpg").convert() If x1 >= x2 and x1 = y2 and y1 <= y2 + bsize:
If x1 >= x2 and x1 = y2 and y1 self.updateCountMax: We create a new method to do that:ĭef isCollision (self,x1,y1,x2,y2,bsize): This simply means veryfing that the cordinate of the snake are intersecting with the coordinates of the apple. It has gained around 5000 installs so far, with an average rating of 4.0 out of 5 in the play store. To know if the snakes position matches the apples position, we have to do collision detection. Six Snake On Screen Prank is an Android Entertainment app developed by Wellwisher Production and published on the Google play store. Self._apple_surf = ( "apple.png").convert() You can now move the block around the screen with the arrow keys. Self._display_surf.blit(self._image_surf,(,)) Self._image_surf = ( "pygame.png").convert() Self._display_surf = _mode((self.windowWidth,self.windowHeight), pygame.HWSURFACE) The complete code gives us the ability to move the player across the screen: from pygame.locals import * In Pygame we can get non-blocking keyboard input using this code: () In addition we define the actions a Player instance can do (movements): class Player:Ī player object can be created and variables can be modified using the movement methods. We define a class Player which holds the players position on the screen and the speed by which it moves. Getting started: Basic structure and event handling. This is very easy in the early phase of the game but is increasingly more difficult as the length of the snake grows. The goal of the game is to eat as many apples as possible without colliding into yourself. The player is represented as snake, which grows if it eats an apple. The game is an arcade game and it has very simple logic, which is why it is an ideal example to demonstrate how to build games with Pygame. In this tutorial you will learn how to build the game snake.