This commit is contained in:
Rampoina 2023-03-05 14:42:33 +01:00
parent 06646746c6
commit 7ef2e3cd09
1 changed files with 18 additions and 22 deletions

40
arc.bqn
View File

@ -4,11 +4,11 @@
# #
# Arc # Arc
# The level is a 2d matrix of lists (tiles) # The level is a 2d matrix of lists (tiles)
# Each list contains the objects of the game represented as ints # Each list contains the objects of the game represented as numbers
ansi•Import "ansi.bqn" ansi•Import "ansi.bqn"
moves00 # list of moves, each move is a direction, we start without moving moves00 # list of moves, each move is a direction, we start without moving
chars" λ$⊕⭍#/\-|+<>^v" # legal characters chars" λ$⊕⭍#/\-|+<>^v" # legal characters:
floor,player,box,machine,pmachine,wall,lmirror,rmirror,hbeam,vbeam,xbeam,llaser,rlaser,ulaser,dlaserchars floor,player,box,machine,pmachine,wall,lmirror,rmirror,hbeam,vbeam,xbeam,llaser,rlaser,ulaser,dlaserchars
beamshbeamvbeamxbeam beamshbeamvbeamxbeam
mirrorslmirrorrmirror mirrorslmirrorrmirror
@ -19,8 +19,8 @@ empties←floor∾beams # floor and laser beams
colors(chars)<ansi.defaultB # start with all glyphs being the default color colors(chars)<ansi.defaultB # start with all glyphs being the default color
colors ansi.yellow˙(pmachine) colors ansi.yellow˙(pmachine)
colors ansi.cyan¨(lmirrorrmirror) colors ansi.cyan¨(mirrors)
colors ansi.red¨(hbeamvbeamxbeam) colors ansi.red¨(beams)
Colorize{𝕩˜colors˜chars𝕩} # 𝕩: character | Turn character into color+character Colorize{𝕩˜colors˜chars𝕩} # 𝕩: character | Turn character into color+character
lTiles{𝕩movables ? 𝕩floor; 𝕩}¨chars # list of all the possible tiles as lists of numbers lTiles{𝕩movables ? 𝕩floor; 𝕩}¨chars # list of all the possible tiles as lists of numbers
@ -60,7 +60,7 @@ Bounce←{(w‿d)S x:{
Shoot{𝕩 {𝕨Bounce´𝕩} <0¯1,<01,<¯10,<10(˜¨+)¨ FindIdx(¨𝕩)¨ lasers} Shoot{𝕩 {𝕨Bounce´𝕩} <0¯1,<01,<¯10,<10(˜¨+)¨ FindIdx(¨𝕩)¨ lasers}
Step{Push((𝕨 Tiles player FindIdx ¨𝕩))𝕩} # 𝕨 S 𝕩 | 𝕨: direction | 𝕩:level | Step the game Step{Push((𝕨 Tiles player FindIdx ¨𝕩))𝕩} # 𝕨 S 𝕩 | 𝕨: direction | 𝕩:level | Step the game
Draw{´¨<˘Colorize¨chars˜+´¨Shoot 𝕨 Step´ 𝕩} # 𝕨 Draw 𝕩 | 𝕨: levels | 𝕩: moves | Draw the game in ASCII Draw{´¨<˘Colorize¨chars˜+´¨Shoot 𝕨 Step´ 𝕩} # 𝕨 Draw 𝕩 | 𝕨: levels | 𝕩: moves | Draw the game in ASCII
Win{¬´˝3=¨Shoot 𝕩}# W 𝕩 | 𝕩: level | [W]in condition, no unpowered goals after shooting laser Win{¬´˝machine=¨Shoot 𝕩}# W 𝕩 | 𝕩: level | [W]in condition, no unpowered machines after shooting laser
Next{movesmoves<𝕩} Next{movesmoves<𝕩}
Undo{𝕊:moves(-1<)moves} Undo{𝕊:moves(-1<)moves}
@ -73,30 +73,26 @@ e←ansi.e
•Out e"[?25l"e"[2J"e"[H" # Cursor to origin, hide it and clear screen •Out e"[?25l"e"[2J"e"[H" # Cursor to origin, hide it and clear screen
clear"" clear""
{𝕤 # Loop until the user wins {𝕤 # Loop until the user wins
•Out e"[H" # Cursor to origin •Out cleare"[H" # Cursor to origin
clear""
•Out "Level: "•Repr 1+currentLevel •Out "Level: "•Repr 1+currentLevel
•Out e"7" # Save cursor position
•Out ansi.yellow"⭍"ansi.defaultB" Power the machines (⊕) by moving the mirrors ("ansi.cyan"\/"ansi.defaultB") " •Out ansi.yellow"⭍"ansi.defaultB" Power the machines (⊕) by moving the mirrors ("ansi.cyan"\/"ansi.defaultB") "
•Out "Controls: (hjkl or wasd) to move, u to undo, r to reset level, q to quit" •Out "Controls: (hjkl or wasd) to move, u to undo, r to reset level, q to quit"
•Out¨ (currentLevellevels) Draw moves •Out¨ (currentLevellevels) Draw moves
key•term.CharB @
{𝕤Next ("hjkl"=key)/0¯1,10,¯10,01}(key"hjkl")@
{𝕤Next ("aswd"=key)/0¯1,10,¯10,01}(key"aswd")@
{𝕤Undo @}(key='u')@
{𝕤•Out e"[?12l"e"[?25h"•Exit 0}(key='q')@
{𝕤moves00}(key='r')@
{𝕤cleare"[2J"}(((1+>(1+101))¯1+moves)key='u')@
•Out e"8" # Restore cursor position
{𝕤•Out clearansi.yellow"⭍"ansi.defaultB" Power the machines (⊕) by moving the mirrors ("ansi.cyan"\/"ansi.defaultB")"(@+10)"Controls: (hjkl or wasd) to move, u to undo, r to reset level, q to quit"}(key"wasdhjkluqr")@
{𝕤•Out "Invalid key: (hjkl or wasd) to move, u to undo, r to reset level"}(¬key"wasdhjkluqr")@
•Out¨ (currentLevellevels) Draw moves
•Out "Moves: "•Repr ¯1+moves •Out "Moves: "•Repr ¯1+moves
{𝕤 Win (currentLevellevels) Step´moves ?
•Out "Good job!, press any key to continue to the next level" •Out "Good job!, press any key to continue to the next level"
•term.CharB @ key•term.CharB @
•Out e"[H"e"[0J" cleare"[2J"
currentLevelcurrentLevel+1moves00 currentLevelcurrentLevel+1moves00
}(Win (currentLevellevels) Step´moves)@ {𝕤•Out e"[?12l"e"[?25h"•Exit 0}(key='q')@
;
key•term.CharB @
{𝕤Next ("hjklaswd"=key)/˜0¯1,10,¯10,01}(key"hjklaswd")@
{𝕤Undo @}(key='u')@
{𝕤•Out e"[?12l"e"[?25h"•Exit 0}(key='q')@
{𝕤cleare"[2J"moves00}(key='r')@
{𝕤cleare"[2J"}(((1+>(1+101))¯1+moves)key='u')@
}•_While_{𝕤currentLevel<levels}@ }•_While_{𝕤currentLevel<levels}@
•Out "Well played, you win!" •Out "Well played, you win!"
•Out e"[?12l"e"[?25h" •Out e"[?12l"e"[?25h"