repl.it
@OmniShift/

CodeJam4

Python

No description

fork
loading
Files
  • main.py
  • animation
  • keys
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time, os, threading
from keys.reader import set_raw, get_keycodes, read_keys
from animation.ConstantsCollection import *
#cursor positioning info: https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences

#baseLine is the width in characters the game requires to play, allowing for play with screens starting at 720p 
baseLine = "."*140
controlsScreen = [baseLine]
gameScreen = [baseLine]*15
fps = (1/50)
keyPressed = "X"
noKeyPressed = True
baseY = len(controlsScreen) + len(gameScreen) - 3
print("\r\n".join(controlsScreen), end="\r\n")
print("\r\n".join(gameScreen), end="\r\n")
oldFrame = """"""
for i in range(sum(CHARATTACK.frameTimes)):
	oldFrame = CHARATTACK.draw(oldFrame, i, 10)
	time.sleep(fps)

def printGame():
	pos = 0
	while noKeyPressed:
		if pos >= len(baseLine) - 1:
			pos = 1
		else:
			pos += 1
			
		listifiedScreen = list(baseLine)
		listifiedScreen[pos] = keyPressed
		#print("".join(listifiedScreen) + "\r")
		print("\x1b[10;" + str(pos) + "H." + keyPressed)
		time.sleep(fps)

def keyTracker():
	with set_raw():
		for key in read_keys(get_keycodes()):
			global keyPressed
			keyPressed = key
			print("\x1b[11;1HYou pressed: " + keyPressed)
			#global noKeyPressed
			#noKeyPressed = False

print("Please make sure your game window is at least this wide:\r\n")
print("<-" + "-"*(len(baseLine)-4) + "->\r\n")
print()
print("If this is not the case, adjust the console width and press the T key to test again or press S to confirm and start.\r\n")
with set_raw():
	for key in read_keys(get_keycodes()):
		if (key == "t"):
			print("Please make sure your game window is at least this wide:\r\n")
			print("<-" + "-"*(len(baseLine)-4) + "->\r\n")
			print()
			print("If this is not the case, adjust the console width and press the T key to test again or press S to confirm and start.\r\n")
		elif (key == "s"):
			os.system("clear")
			print("\r\n".join(controlsScreen), end="\r\n")
			print("\r\n".join(gameScreen), end="\r\n")
			time.sleep(0.5)
			t1 = threading.Thread(target=printGame)
			t2 = threading.Thread(target=keyTracker)
			t1.start()
			t2.start()
			break
?