Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intitial program #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Uruguay Potato Vine/P1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from microbit import *
import radio

#player1

delay = 500

radio.on()
radio.config(channel = 24)
block_time = 0
block_disable = 5
block_enable = 4
block_state = True


time = 0

player = 1

while True:

x= accelerometer.get_x()
y = accelerometer.get_y()
z = accelerometer.get_z()
disable1 = radio.receive()
if disable1:
if disable1 == "disable1":
sleep(1000)
pass
else:
if pin0.read_digital() == 1 and block_state == True:
print("block" + str(block_time))
radio.send("Block from player " + str(player))
radio.send("disable2")
sleep(1000)
block_time += 1
if block_time >= block_disable:
block_state = False
elif z > 2000 and accelerometer.is_gesture("up"):
print("fireball " + str(z))
radio.send("Fireball from player " + str(player))
sleep(delay)
elif x > 2000 and not accelerometer.is_gesture("shake"):
print("sideways jab " + str(x))
radio.send("Sideways jab from player " + str(player))
sleep(delay)
elif button_a.was_pressed():
print("Insult")
radio.send("Insult from player " + str(player))
sleep(delay)
elif y > 2000 and accelerometer.is_gesture("face up"):
print("forward punch " + str(y))
radio.send("Forward punch from player " + str(player))
sleep(delay)

if pin0.read_digital() == 0:
if running_time() >= (time + 1000):
block_time -= 1
time = running_time()
if block_time < 0:
block_time = 0
if block_time <= block_enable:
block_state = True





72 changes: 72 additions & 0 deletions Uruguay Potato Vine/P2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from microbit import *
import radio
import music

#player2

delay = 500

radio.on()
radio.config(channel = 24)


time = 0
player = 2

block_time = 0
block_disable = 5
block_enable = 4
block_state = True



while True:
disable2 = radio.receive()

x= accelerometer.get_x()
y = accelerometer.get_y()
z = accelerometer.get_z()

if disable2:
if disable2 == "disable2":
sleep(1000)
pass
else:
if pin0.read_digital() == 1 and block_state == True:
print("block" + str(block_time))
radio.send("Block from player " + str(player))
radio.send("disable1")
sleep(1000)
block_time += 1
if block_time >= block_disable:
block_state = False
elif z > 2000 and accelerometer.is_gesture("up"):
print("fireball " + str(z))
radio.send("Fireball from player " + str(player))
sleep(delay)

elif x > 2000 and not accelerometer.is_gesture("shake"):
print("sideways jab " + str(x))
radio.send("Sideways jab from player " + str(player))
sleep(delay)
elif button_a.was_pressed():
print("Insult")
radio.send("Insult from player " + str(player))
sleep(delay)
elif y > 2000 and accelerometer.is_gesture("face up"):
print("forward punch " + str(y))
radio.send("Forward punch from player " + str(player))
sleep(delay)

if pin0.read_digital() == 0:
if running_time() >= (time + 1000):
block_time -= 1
time = running_time()
if block_time < 0:
block_time = 0
if block_time <= block_enable:
block_state = True




107 changes: 107 additions & 0 deletions Uruguay Potato Vine/Streetfighter, receiving and display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from microbit import *
import radio
radio.config(channel = 24)
import random
import music
radio.on()

health_1 = 1000
health_2 = 1000
punch = -20
sideways_jab = -30
fireball = -40

display.show(Image.HAPPY)


insults= ['Your mother was a hampster and your father smelled of elderberries.',
'His wit\'s as thick as a Tewkesbury mustard.', 'I am sick when I do look on thee.',
'Methink\'st thou art a general offence and every man should beat thee.',
'More of your conversation would infect my brain.',
'The rankest compound of villainous smell that ever offended nostril.',
'You are as a candle, the better burnt out.',
'Thou appeareth nothing to me but a foul and pestilent congregation of vapours.',
]
gameon = True
while gameon == True:
'''if button_a.was_pressed():
music.play(music.ENTERTAINER)
radio.on()
if radio.on:
if button_b.was_pressed():
music.play(music.NYAN)
radio.off()'''

answer = radio.receive()
if answer:
music.stop()
if answer == "Block from player 1" or answer == "Block from player 2":
print('Blocked' + '\n')
#sleep(1000)
else:
if answer == "Forward punch from player 1":
print(answer)
health_2 += punch
print('Player Two Health: ' + str(health_2)+ '\n')
radio.send('player2_health:{}'.format(health_2))
if answer == "Sideways jab from player 1":
print(answer)
health_2 += sideways_jab
print('Player Two Health: ' + str(health_2)+ '\n')
radio.send('player2_health:{}'.format(health_2))
if answer == "Fireball from player 1":
print(answer)
health_2 += fireball
print('Player Two Health: ' + str(health_2) + '\n')
radio.send('player2_health:{}'.format(health_2))
if answer == "Insult from player 1":
choice = random.choice(insults)
radio.send("Player 1 says: " + choice)
ttsChoice = random.randrange(0,7)
radio.send("TTS:" + str(ttsChoice))

print("Player 1 says: " + choice + '\n')
if choice == insults[0]:
music.play(music.PYTHON, wait=False)


if answer == "Forward punch from player 2":
print(answer)
health_1 += punch
print('Player One Health: ' + str(health_1)+ '\n')
radio.send('player1_health:{}'.format(health_1))
if answer == "Sideways jab from player 2":
print(answer)
health_1 += sideways_jab
print('Player One Health: ' + str(health_1)+ '\n')
radio.send('player1_health:{}'.format(health_1))
if answer == "Fireball from player 2":
print(answer)
health_1 += fireball
print('Player One Health: ' + str(health_1)+ '\n')
radio.send('player1_health:{}'.format(health_1))
if answer == "Insult from player 2":
choice = random.choice(insults)
radio.send("Player 2 says: " + choice)
ttsChoice = random.randrange(0,7)
radio.send("TTS:" + str(ttsChoice))
print("Player 2 says: " + choice + '\n')
if choice == insults[0]:
music.play(music.PYTHON, wait=False)

loop = 0
#player 1
if health_2 <= 0:
while loop < 10:
radio.send("player1_win")
loop+=1
sleep(100)
gameon = False
if health_1 <= 0:
while loop < 10:
radio.send("player2_win")
loop+=1
sleep(100)
gameon = False

display.show(Image.SAD)
107 changes: 107 additions & 0 deletions Uruguay Potato Vine/health bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# SPI dotstars
# Authors: Sofia, Owen, Moss

from microbit import *
import radio

radio.on()
radio.config(channel = 24)

increment = 1000-28.57
lights = 35
N_LEDS = 35
health = 1000

"""
global rgb


rgb = [(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0)]
"""


def write_frames(frames):
spi.write(bytes(frames))

def rgb_to_frames(rgb):
frames = [0]*4

for r, g, b in rgb:
frames += [0b11111111, b, g, r]

frames += [0xff]*4

return frames

def main(lights):
spi.init(baudrate=1000000, mosi=pin13, sclk=pin0)

rgb = []

for _ in range(lights):
rgb.append((0, 255, 0))

for _ in range(35 - lights):
rgb.append((255, 0, 0))

frames = rgb_to_frames(rgb)
write_frames(frames)

while True:
msg = radio.receive()
if msg:
try:
if msg.startswith("player1_health:"):
health = int(msg.split(":")[1])
percentage_health = health/1000
lights = int(percentage_health * N_LEDS)
except:
pass

"""
if increment > health:
while increment > health:
increment -= 28.57
lights -= 1
"""

main(lights)
sleep(50)