Posts

Showing posts with the label Python Programming

Python Snake Game Basic Codes

Image
import pygame import time import random pygame.init() # Game Window display_width = 800 display_height = 600 gameDisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('Slither') # Colors black = (0,0,0) white = (255,255,255) red = (255,0,0) blue = (0,0,255) # Snake Size block_size = 10 # FPS fps = 15 # Snake Start Position snake_startx = display_width/2 snake_starty = display_height/2 # Change of Snake Direction snake_speed = 0 # Snake List snake_list = [] snake_length = 1 # Random Apple Spawn randAppleX = round(random.randrange(0, display_width - block_size)/10.0)*10.0 randAppleY = round(random.randrange(0, display_height - block_size)/10.0)*10.0 # Game Loop game_over = False game_close = False # Clock clock = pygame.time.Clock() # Message Function def message_to_screen(msg,color):     mesg = font_style.render(msg, True, color)     gameDisplay.blit(mesg, [display_width/2-len(msg)*11/2, display_height/2]) # Game Loop...