bandsasfen.blogg.se

On screen snake game
On screen snake game









on screen snake game
  1. #ON SCREEN SNAKE GAME HOW TO#
  2. #ON SCREEN SNAKE GAME CODE#
  3. #ON SCREEN SNAKE GAME DOWNLOAD#

I just don't know how to get the pellet to actually appear on the screen.

#ON SCREEN SNAKE GAME CODE#

Start_menu = Menu(screen, start_menu_stuff)Īny help or direction would be greatly appreciated, this is my first CS class so the code is very, very basic. #runs options at the start and end of gameįor name, label, (width, height), (pos_x, pos_y) in ems: Pos_y = (self.screen_height / 2) - (lol / 2) + (index * height) Pos_x = (self.screen_width / 2) - (width / 2) Running off the map or into your own vehicle will end the game. #enumerate makes loop clearer, returns an iterator Self.screen_height = screen.get_rect().height Self.screen_width = screen.get_rect().width #determines if snake collides with itselfĭef _init_(self, screen, items, background_color = (bla), font_size = 32, font_color = (whi)): Return + self.speed, current + self.speed]Įlif abs(self.speed) != abs(speed): #sets the position as long as the snake hasn't collided (.pop() removes and then returns)ĭef update(self, speed, pelletCollision = False): Return head_pos_x self.size - self.bit or head_pos_y self.size - self.bitĭef _init_(self, position, speed = ):

on screen snake game

Return random.randint(-500, 500) * self.bit #return random.randint(bit, max_size / bit) * self.bitĪmount_bits = (self.size / self.bit - 1) #amount_bits = (self.size / self.bit - 1) / Everything is ready for the joke Main features of application: - high quality of graphics and realistic movement of a snake.

#ON SCREEN SNAKE GAME DOWNLOAD#

Neither def randomPosition 's will draw a pellet on the game screen though. Download a free snake screen to your phone. I rewrote it and somehow managed to get that one to not mess up the game display. This following 3 lines of code doesn't work and I want it to. #gives pellet random position and avoids overlap with snake #redraws pellet if appears where snake currently is Self.pellet = Pellet(self.newPelletPosition()) #sets snake in initial position and put pellet in random position import sys, pygame, random, itertools, time I would love any advice on how to fix this problem, or how to improve the game. You can move the snake body around in any direction but the pellet or apple that it is supposed to eat won't draw on the screen. Since all key input would be detected through the UserInterface class, I had to bind all the handler methods so they could be used through the Game class.The following code works to a certain extent.

  • UserInterface, which would handle all i/o, which means the key input, the screen, and rendering anything to the screenīlessed uses "boxes" to represent elements, so I had a gameBox to represent the entire game play area, scoreBox to represent a single line where the score would be set and updated, and gameOverBox to display a game over modal.Īll the pixels that would be drawn to the screen beyond that - in this case, the dot and each segment of snake - go through the draw() method, which is a 1px x 1px box.
  • Game, which would track the state of the snake, dot, and score.
  • I made extensive use of the ES6 JavaScript class keyword, and divided the game into two classes:
  • If the snake runs into the wall or itself, the game resets.
  • If the snake eats the dot, it grows and the score goes up by one.
  • There's a snake that can go up, down, left, or right.
  • I made the game as I remember it from the old Nokia bricks:











    On screen snake game