Skip to content
Sign upLog in
← Back to Community
A BIG PROBLEM
Profile icon
astropi7

Hi!I have a problem with a code in python i have to do for a lesson.What i have to do is to make a falling food and a character who catches it. Thats my current program:

from sense_hat import SenseHat
sense = SenseHat()
import random
from time import sleep

l1 = random.randint(0,8)
l2 = random.randint(0,8)
score = 0
y = [255,255,0]
g = [0,255,0]
r = [255,0,0]
c = [255,255,255]

screen = [
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c
]

def falling_food():
for j in range (0,7):
screen[j] = y
sleep(2)
for j in range (8,15):
screen[j] = y
sleep(2)
for j in range (16,23):
screen[j] = y
sleep(2)
for j in range [24,31]:
screen[j] = y
sleep(2)
for j in range [32,39]:
screen[j] = y
sleep(2)
for j in range [40,47]:
screen[j] = y
sleep(2)
for j in range [48,55]:
screen[j] = y
for j in range [56,63]:
if l1 == l2:
screen[j] = g
score = score + 1
else:
screen[j] = y

while True:
sense.set_pixels(screen)
com = input

if com == "a": if l2 != l1 : falling_food() l1 = l1 - 1 falling_food() else: falling_food() if com == "d": if l2 != l1 : falling_food() l1 = l1 + 1 falling_food() else: falling_food() if l2 >= 56 and l2 <= 63: continue

it also must counts score and start a new round when food is at the last row of a sense hat screen in raspberry pi the character is red , the food yellow and if the character cathces the food he must be green .Every help is appreciated :).

Voters
Profile icon
shreyagarg3008
Profile icon
astropi7
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

please show yor repl

Profile icon
astropi7
Profile icon
astropi7