Skip to content
Snippets Groups Projects
Commit ac70492a authored by Usman Irfan's avatar Usman Irfan
Browse files

updated food

parent 85a29702
No related branches found
No related tags found
No related merge requests found
#standard set up
import pygame
from random import randint
pygame.init()
#setting width and height of window
......@@ -14,11 +15,13 @@ pygame.display.set_caption("My Game")
white = (255,255,255)
black = (0,0,0)
x = randint(40,400)
y = randint(40,400)
width = 20
height = 20
vel = 10
score = 0
x = randint(0,screen_x - width)
y = randint(0, screen_y - height)
speed = 40
# 0 - (- direction) , 1 - (+ direction)
......@@ -26,8 +29,17 @@ direction = 0
# 0 - x-axis , 1 - y-axis
axis = 0
run = True
location = []
food_x = randint(0,screen_x - width)
food_y = randint(0,screen_y - height)
location = [food_x, food_y]
run = True
while run:
pygame.time.delay(speed) #create a delay to prevent any unwanted behaviour
......@@ -71,9 +83,21 @@ while run:
#x = 500 - height
x = 0
win.fill(white)
#all colors are defined in RGB with Pygame
if( abs(x - food_x) < 15 and abs(y - food_y) < 15):
score += 1
food_x = randint(0,screen_x - width)
food_y = randint(0,screen_y - height)
location = [food_x, food_y]
print('score = ', score)
win.fill(white)
pygame.draw.rect(win,(0,0,255), (location[0], location[1], width, height))
pygame.draw.rect(win,(255,0,0), (x,y,width, height))
#we have to update the display to see the drawing of our object. Since it does
#not automatically update
pygame.display.update()
......
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