This is the code for flappy bird for the nibble! I used the code for the bit and modified it! Also, I have a suggestion, circuitmess. I think you should add the “push screen” block for the nibble like the bit has. It would improve the annoying screen flickering and make coding a whole lot easier.
from Nibble import *
import random
import time
sprite_bird = bytearray(b'\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\xAD\x55\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x40\x00\x40\x00\x40\x00\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\xAD\x55\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\xAD\x55\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x40\x00\x40\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xA0\xFF\xA0\xFF\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\xAD\x55\xFF\xFF\xFF\xFF\xFF\xFF\xAD\x55\x00\x00\xFF\xA0\xFF\xA0\x00\x00\xC9\x86\xC9\x86\xC9\x86\xC9\x86\xC9\x86\xC9\x86\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAD\x20\xAD\x20\x00\x00\xC9\x86\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x40\x00\x40\x00\x00\x00\xAD\x20\xAD\x20\xAD\x20\xAD\x20\xAD\x20\xAD\x20\x00\x00\xC9\x86\xC9\x86\xC9\x86\xC9\x86\xC9\x86\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\xAD\x20\xAD\x20\xAD\x20\xAD\x20\xAD\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00')
sprite_bird_transparent = 16384
jump_velocity = None
jump_strength = None
player_pos_y = None
player_dead = None
jump = None
gravity = None
points = None
jump_lock = None
tubes_pos_x = None
player_pos_x = None
tubes_gap_pos_y = None
tubes_width = None
tubes_speed = None
tubes_gap_height = None
# Describe this function...
def draw_bg():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
display.fill(Display.Color.Cyan)
# Describe this function...
def player_respawn():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
player_pos_y = 30
jump_velocity = 0
jump = False
jump_lock = False
points = 0
tubes_pos_x = 128
# Describe this function...
def draw_overlay():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
display.text(str(points), int(5), int(5), 0)
if player_dead:
for count in range(30):
display.fill(0)
display.text(str('Final score: ' + str(points)), int(2), int(50), Display.Color.White)
display.text(str('Play again?'), int(2), int(65), Display.Color.White)
player_pos_y = 30
jump_velocity = 0
jump = False
jump_lock = False
points = 0
tubes_pos_x = 128
player_dead = False
# Describe this function...
def draw_player():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
if jump and not jump_lock:
jump_lock = True
jump_velocity = jump_strength
if player_pos_y <= 0:
jump_velocity = -gravity
if player_pos_y >= 128:
player_dead = True
else:
player_pos_y = player_pos_y - jump_velocity
display.blit(sprite_bird, int(player_pos_x), int(player_pos_y), 17, 12, sprite_bird_transparent)
jump_velocity = jump_velocity - gravity
# Describe this function...
def draw_tubes():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
if tubes_pos_x <= -20:
tubes_pos_x = 128
tubes_gap_pos_y = (20) + (random.getrandbits(32) % ((118 - tubes_gap_height) - (20) + 1))
else:
tubes_pos_x = tubes_pos_x - tubes_speed
display.rect(int(tubes_pos_x), int(0), int(tubes_width), int(128), Display.Color.Green, True)
display.rect(int(tubes_pos_x), int(tubes_gap_pos_y), int(tubes_width), int(tubes_gap_height), Display.Color.Cyan, True)
# Describe this function...
def collision_detection():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
if not (player_pos_x > tubes_pos_x + tubes_width or player_pos_x + 17 < tubes_pos_x):
if not (player_pos_y + 12 > tubes_gap_pos_y + tubes_gap_height or player_pos_y < tubes_gap_pos_y):
if player_pos_x == tubes_pos_x + tubes_width:
points = points + 1
print(points)
else:
player_dead = True
jump_velocity = 0
jump_strength = 4
gravity = 0.4
player_pos_x = 10
player_pos_y = 30
points = 0
jump = False
jump_lock = False
tubes_pos_x = 128
tubes_gap_pos_y = 50
tubes_gap_height = 55
tubes_speed = 3
tubes_width = 20
player_dead = False
def cb_Yn6nn8Bvn3aJR():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
player_dead = False
player_respawn()
buttons.on_press(Buttons.B, cb_Yn6nn8Bvn3aJR)
def cb_0exwJUUqMExDu():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
jump = True
buttons.on_press(Buttons.A, cb_0exwJUUqMExDu)
def cb_eJYePGM3L4qdO():
global jump_velocity, jump_strength, player_pos_y, player_dead, jump, gravity, points, jump_lock, tubes_pos_x, player_pos_x, tubes_gap_pos_y, tubes_width, tubes_speed, tubes_gap_height
jump = False
jump_lock = False
buttons.on_release(Buttons.A, cb_eJYePGM3L4qdO)
begin(True)
while True:
buttons.scan()
draw_bg()
draw_tubes()
draw_player()
collision_detection()
draw_overlay()
time.sleep_ms(5)