Skip to content
Snippets Groups Projects
Commit 91440a2a authored by 's avatar
Browse files
parents 4d9578c2 6eff3f9a
No related branches found
No related tags found
No related merge requests found
## Author: Usman Irfan, Andy Hameed
# This module will be used to control snake body movements and gameplay
## @file Snake_2.o.py
# @author Andy Hameed, Usman Irfan
# @brief implements gameplay and connects the different components of the game
# @date 11/09/2018
import pygame
from random import randint
#initializing PyGame and setting game window dimensions
pygame.init()
#setting width and size of window to screenSize
screenSize = 500
win = pygame.display.set_mode((screenSize,screenSize))
pygame.display.set_caption("My Game")
pygame.display.set_caption("Snake 2.o")
#Define color constants
white = (255,255,255)
......@@ -18,27 +18,26 @@ red = (255,0,0)
blue = (0,0,255)
black = (0,0,0)
#width1, size1 correspond to constant width and size for the food block
#width and size change over time as the snake consumes food
width, width1 = 20,20 # can replace with size - one number
size, size1 = 20,20
size = 20 # One size for all block created for snake
# One size for all blocks created for snake
size = 20
#velocity and score
vel = 10
score = 0
x = randint(0,screenSize - size)
y = randint(0, screenSize - size)
#initial x and y coordinates of the snake
x_init = randint(0,screenSize - size)
y_init = randint(0, screenSize - size)
speed = 40
# 0 gives (- direction)
# 1 gives (+ direction)
direction = 0
# 0 - x-axis , 1 - y-axis
axis = 0
location = []
food_x = randint(0,screenSize - size)
......@@ -96,8 +95,8 @@ while run:
#consumption of food block
if( abs(x - food_x) < 15 and abs(y - food_y) < 15):
score += 1
food_x = randint(0,screenSize - size1)
food_y = randint(0,screenSize - size1)
food_x = randint(0,screenSize - size)
food_y = randint(0,screenSize - size)
location = [food_x, food_y]
## --------------------------DELETE --------------------------
......@@ -106,15 +105,16 @@ while run:
size += 20
else:
size += 20
print('score = ', score)
##---------------------------DELETE----------------------------
print('score = ', score)
win.fill(white)
#Draw food item
pygame.draw.rect(win,blue, (location[0], location[1], size1, size1))
pygame.draw.rect(win,blue, (location[0], location[1], size, size))
#Draw snake
pygame.draw.rect(win, red , (x,y,size, size))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment