Dateien nach "jetris" hochladen

main
Justus Jan Nico Wolff 2024-03-01 13:17:12 +01:00
parent 23af3316f7
commit f10a3495ea
3 changed files with 252 additions and 0 deletions

View File

@ -0,0 +1,6 @@
class pathfinder():
def __init__(self, UPDS, JS):
self.MPU = (1/UPDS)/0.1
self.JMPU = (1/JS)/0.1
self.PMPBM = self.MPU/self.JMPU

15
jetris/info.txt 100644
View File

@ -0,0 +1,15 @@
{
"name": "Jetris-Classic",
"cover": [
"",
"",
"",
"100101",
"110111",
"111111",
"111111",
"111111",
]}

231
jetris/main.py 100644
View File

@ -0,0 +1,231 @@
import random
import musicplayer
def calcpos(piece):
for y in range(8):
for i in piece:
if inplacedbypos([i.pos[0], y]) != False:
return [i, y-1]
return [random.choice(piece), 7]
bot = False
if selectoption("Mode", ["Normal", "Auto"]) == 1:
bot = True
placed = []
# pos = [x, y]
def inplacedbypos(pos):
for i in placed:
if i.pos == pos:
return i
return False
def intempbypos(pos):
#for i in temp:
#if i.pos == pos:
#return i
return False
def scanindirection(pos, direction):
# 1, up, 2, right, 3, down, 4, left
if direction == 1:
for i in range(pos[1], -1, -1):
if inplacedbypos([pos[0], i]) == False and intempbypos([pos[0], i]) == False:
return False
if direction == 2:
for i in range(pos[0], 16):
if inplacedbypos([i, pos[1]]) == False and intempbypos([i, pos[1]]) == False:
return False
if direction == 3:
for i in range(pos[1], 8):
if inplacedbypos([pos[0], i]) == False and intempbypos([pos[0], i]) == False:
return False
if direction == 4:
for i in range(pos[0], -1, -1):
if inplacedbypos([i, pos[1]]) == False and intempbypos([i, pos[1]]) == False:
return False
return True
def checkcollision(pos):
if inplacedbypos(pos) == False and intempbypos(pos) == False:
return False
else:
return True
class tile():
def __init__(self, startpos):
self.pos = startpos.copy()
def update(self):
if inplacedbypos([self.pos[0], self.pos[1]+1]) != False:
return False
else:
self.pos[1] += 1
def joystickupd(self, inp):
if inp == -1:
if self.pos[0] != 0 and not checkcollision([self.pos[0]-1, self.pos[1]]):
self.pos[0] -= 1
return True
else:
return False
if inp == 1:
if self.pos[0] != 15 and not checkcollision([self.pos[0]+1, self.pos[1]]):
self.pos[0] += 1
return True
else:
return False
return True
def gentiles(pos):
out = []
for i in pos:
out.append(tile(i))
bag.remove(pos)
return out
skip = False
tiles = [
[[7,1], [8,0], [7,0], [8,1]],
[[7,1], [7,0]],
[[7,0], [8,0], [9,0]],
[[7,2], [7,1], [7,0], [8,2]],
[[7,2], [8,1], [8,2], [8,0]],
[[8,1], [8,0], [9,0], [7,0]]
]
bag = tiles.copy()
temp = gentiles(random.choice(bag))
joystickspeed = 5
speed = 1
score = 0
upd = 0
jupd = 0
inp = 0
lcd.putstr("Score: 0")
song = "0 E6 4 43;4 B5 2 43;6 C6 2 43;8 D6 4 43;12 C6 2 43;14 B5 2 43;16 A5 4 43;20 A5 2 43;22 C6 2 43;24 E6 4 43;28 D6 2 43;30 C6 2 43;32 B5 4 43;36 B5 2 43;38 C6 2 43;40 D6 4 43;44 E6 4 43;56 A5 8 43;52 A5 4 43;48 C6 4 43;64 D6 4 43;68 F6 4 43;72 A6 4 43;76 G6 2 43;78 F6 2 43;80 E6 6 43;86 C6 2 43;88 E6 4 43;92 D6 2 43;94 C6 2 43;96 B5 4 43;102 C6 2 43;104 D6 4 43;108 E6 4 43;112 C6 4 43;100 B5 2 43;120 A5 8 43;116 A5 4 43;128 E6 4 43;132 B5 2 43;134 C6 2 43;136 D6 4 43;140 C6 2 43;142 B5 2 43;144 A5 4 43;148 A5 2 43;150 C6 2 43;152 E6 4 43;156 D6 2 43;158 C6 2 43;160 B5 4 43;164 B5 2 43;166 C6 2 43;168 D6 4 43;172 E6 4 43;184 A5 8 43;180 A5 4 43;176 C6 4 43;192 D6 4 43;196 F6 4 43;200 A6 4 43;204 G6 2 43;206 F6 2 43;208 E6 6 43;214 C6 2 43;216 E6 4 43;220 D6 2 43;222 C6 2 43;224 B5 4 43;230 C6 2 43;232 D6 4 43;236 E6 4 43;240 C6 4 43;228 B5 2 43;248 A5 8 43;244 A5 4 43;256 E6 8 43;264 C6 8 43;272 D6 8 43;280 B5 8 43;288 C6 8 43;296 A5 8 43;304 G#5 8 43;312 B5 8 43;320 E6 8 43;328 C6 8 43;336 D6 8 43;344 B5 8 43;352 C6 4 43;356 F6 4 43;360 A6 8 43;368 G#6 16 43;0 E3 8 43;8 G#3 8 43;16 A3 8 43;24 C4 8 43;32 B3 8 43;40 E3 8 43;48 A3 8 43;64 D3 8 43;56 A3 8 43;72 F3 8 43;80 A3 8 43;88 A3 8 43;96 E3 8 43;104 G#3 8 43;112 A3 8 43;120 A3 8 43;128 E3 8 43;136 G#3 8 43;144 A3 8 43;152 C4 8 43;160 B3 8 43;168 E3 8 43;176 A3 8 43;192 D3 8 43;184 A3 8 43;200 F3 8 43;208 A3 8 43;216 A3 8 43;224 E3 8 43;232 G#3 8 43;240 A3 8 43;248 A3 8 43;256 A3 16 43;288 A3 16 43;272 G#3 16 43;304 G#3 16 43;320 A3 16 43;336 G#3 16 43;352 A3 16 43;368 G#3 16 43"
Song = musicplayer.music(song, pins=[Pin(15)])
while True:
try:
lastpositions = []
jupd += 0.1
if bot == True:
#left; inp=-1, right;inp=1
botalgo.test()
else:
if jupd > 1/joystickspeed:
inp = joystick.gethorizontal()
jupd = 0
else:
inp = 0
hardfly = joystick.getsel()
#hardfly yes; 1
#hardfly no; 0
for i in temp:
lastpositions.append(i.pos.copy())
reset = False
for i in temp:
if i.joystickupd(inp) == False:
reset = True
if reset:
for i in range(len(temp)):
temp[i].pos = lastpositions[i]
if hardfly and not skip:
skip = True
lastspeed = speed
speed = 100
display.fill(0)
for i in temp:
display.pixel(i.pos[0], i.pos[1], 1)
for i in placed:
display.pixel(i.pos[0], i.pos[1], 1)
display.show()
upd += 0.1
if upd >= 1/speed:
if len(bag) == 0:
bag = tiles.copy()
upd = 0
for i in temp:
lastpositions.append(i.pos.copy())
place = True
for i in temp:
if i.update() == False:
place = False
for i in range(len(temp)):
temp[i].pos = lastpositions[i]
break
new = False
for i in temp:
if i.pos[1] == 7 or place == False:
new = True
break
if new == True:
if skip:
speed = lastspeed
skip = False
for i in temp:
placed.append(i)
temp = gentiles(random.choice(bag))
#row check
tochange = 0
for y in range(7, -1, -1):
for i in placed:
display.pixel(i.pos[0], i.pos[1], 1)
display.show()
count = 0
for x in range(16):
if checkcollision([x, y]):
count += 1
if count == 16:
Song.stop()
for x in range(16):
display.pixel(x, y, 0)
display.show()
time.sleep(0.3)
for x in range(16):
display.pixel(x, y, 1)
display.show()
time.sleep(0.3)
for x in range(16):
placed.remove(inplacedbypos([x,y]))
tochange += 1
speed += 0.1
score += 1
lcd.clear()
lcd.putstr("Score: {}".format(score))
Song.resume()
else:
for x in range(16):
if inplacedbypos([x,y]) != False:
inplacedbypos([x,y]).pos[1] += tochange
for x in range(16):
if inplacedbypos([x, 0]) != False:
lcd.clear()
lcd.putstr("You lose!")
Song.stop()
for y in range(7, -1, -1):
for x in range(15, -1, -1):
display.pixel(x, y, 1)
display.show()
time.sleep(0.1)
for y in range(8):
for x in range(16):
display.pixel(x, y, 0)
display.show()
time.sleep(0.1)
temp = gentiles(random.choice(bag))
speed = 1
score = 0
upd = 0
skip = False
lcd.clear()
lcd.putstr("Score: 0")
placed = []
Song.restart()
Song.tick()
time.sleep(0.04)
except KeyboardInterrupt:
playmusic = False
time.sleep(1)
print("EXIT JETRIS-CLASSIC")
break