Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SenseHat] Frogger
#1
So I'm making a game sort of like frogger and this is what I have so far
from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
from signal import pause
from random import randint
from time import sleep

speed = 0.20
x = 5
y = 0 
sense = SenseHat()
randy = randint(1,7)

def clamp(value, min_value=0, max_value=7):
    return min(max_value, max(min_value, value))


def pushed_left(event):
    global x
    if event.action != ACTION_RELEASED:
        x = clamp(x - 1)


def pushed_right(event):
    global x
    if event.action != ACTION_RELEASED:
        x = clamp(x + 1)
        
def obstacle(y):  #tell it to expect y as a variable
  if randy == 1:
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
    sense.set_pixel(randy + 2,y,0,255,0)
    sense.set_pixel(randy + 3,y,0,255,0)
    sense.set_pixel(randy + 4,y,0,255,0)
    sense.set_pixel(randy + 5,y,0,255,0)
    sense.set_pixel(randy + 6,y,0,255,0)
  elif randy == 2:
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
    sense.set_pixel(randy + 2,y,0,255,0)
    sense.set_pixel(randy + 3,y,0,255,0)
    sense.set_pixel(randy + 4,y,0,255,0)
    sense.set_pixel(randy + 5,y,0,255,0)
  elif randy == 3:
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
    sense.set_pixel(randy + 2,y,0,255,0)
    sense.set_pixel(randy + 3,y,0,255,0)
    sense.set_pixel(randy + 4,y,0,255,0)
  elif randy == 4:
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
    sense.set_pixel(randy + 2,y,0,255,0)
    sense.set_pixel(randy + 3,y,0,255,0)
  elif randy == 5:
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
    sense.set_pixel(randy + 2,y,0,255,0)
  elif randy == 6:  
    sense.set_pixel(randy,y,0,255,0)
    sense.set_pixel(randy + 1,y,0,255,0)
  elif randy == 7:
    sense.set_pixel(randy,y,0,255,0)

def refresh():
    sense.clear()
    sense.set_pixel(x, 6, 255, 255, 255)
    obstacle(y)
    sense.stick.direction_left = pushed_left
    sense.stick.direction_right= pushed_right 

while True:
    y = y + 1
    sleep(speed)
    refresh()
    if y == 7:
        y = 0
        randy = randint(1,7)
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right
sense.stick.direction_any = refresh
refresh()

What I just can't figure out is how to add gaps in between the obstacles. Your help is appreciated.
Quote
#2
What's Sense_hat? Why do you import signal if you never use it?
For those of us without a raspberry pi, could you maybe include a screenshot or something? Otherwise we're sort of guessing what might be happening.
metulburr likes this post
It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html
Kevin Flynn is my spirit animal.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)