Initialize game with parameters (level path, colors and glyphs)

This commit is contained in:
Rampoina 2023-03-05 16:14:24 +01:00
parent 2333c02699
commit 2697bbb950
2 changed files with 9 additions and 10 deletions

View File

@ -12,7 +12,8 @@ e←ansi.e
•term.RawMode 1 # set terminal to raw mode
•Out e"[?25l"e"[2J"e"[H" # Cursor to origin, hide it and clear screen
clear""
gGame "levels"
gGame "levels"" λ$⊕⭍#/\-|+<>^v"ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red
{𝕤 # Loop until the user wins
•Out cleare"[H" # Cursor to origin
clear""

View File

@ -1,11 +1,9 @@
#!/usr/bin/env BQN
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 Rampoina <rampoina@protonmail.com>
ansi•Import "ansi.bqn"
Game{
𝕊 levelPathcharscolors:
moves00 # list of moves, each move is a direction, we start without moving
chars" λ$⊕⭍#/\-|+<>^v" # legal characters:
floor,player,box,machine,pmachine,wall,lmirror,rmirror,hbeam,vbeam,xbeam,llaser,rlaser,ulaser,dlaserchars
beamshbeamvbeamxbeam
mirrorslmirrorrmirror
@ -14,11 +12,11 @@ Game⇐{
opaqueplayerboxmachinewalllasers # non laser reflecting
emptiesfloorbeams # floor and laser beams
colors←(chars)<ansi.defaultB # start with all glyphs being the default color
colors ansi.yellow˙(pmachine)
colors ansi.cyan¨(mirrors)
colors ansi.red¨(beams)
Colorize{𝕩˜colors˜chars𝕩} # 𝕩: character | Turn character into color+character
cols←(chars)<(colors) # start with all glyphs being the default color
cols (1colors)˙(pmachine)
cols (2colors)¨(mirrors)
cols (3colors)¨(beams)
Colorize{𝕩˜cols˜chars𝕩} # 𝕩: character | Turn character into color+character
lTiles{𝕩movables ? 𝕩floor; 𝕩}¨chars # list of all the possible tiles as lists of numbers
# Turns the level from ascii strings into a 2d matrix of lists
@ -66,6 +64,6 @@ Game⇐{
NextLevel{𝕊:currentLevelcurrentLevel+1Reset @}
Over{𝕊:currentLevel<levels}
SplitOnEmpty{𝕩˜(-˜+`׬)0=¨𝕩}
levelsAscii2Matrix¨>¨SplitOnEmpty•FLines 𝕩 # Load file containing levels
levelsAscii2Matrix¨>¨SplitOnEmpty•FLines levelPath # Load file containing levels
currentLevel0
}