Initialize game with parameters (level path, colors and glyphs)
This commit is contained in:
parent
2333c02699
commit
2697bbb950
3
arc.bqn
3
arc.bqn
|
@ -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←""
|
||||
g←Game "levels"
|
||||
|
||||
g←Game "levels"‿" λ$⊕⭍#/\-|+<>^v"‿⟨ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red⟩
|
||||
{𝕤 # Loop until the user wins
|
||||
•Out clear∾e∾"[H" # Cursor to origin
|
||||
clear↩""
|
||||
|
|
16
logic.bqn
16
logic.bqn
|
@ -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⇐{
|
||||
𝕊 levelPath‿chars‿colors:
|
||||
moves⇐⟨0‿0⟩ # 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,dlaser⟩←↕≠chars
|
||||
beams←hbeam‿vbeam‿xbeam
|
||||
mirrors←lmirror‿rmirror
|
||||
|
@ -14,11 +12,11 @@ Game⇐{
|
|||
opaque←player‿box‿machine‿wall∾lasers # non laser reflecting
|
||||
empties←floor∾beams # 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 (1⊑colors)˙⌾(pmachine⊸⊑)↩
|
||||
cols (2⊑colors)¨⌾(mirrors⊸⊏)↩
|
||||
cols (3⊑colors)¨⌾(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⇐{𝕊:currentLevel↩currentLevel+1⋄Reset @}
|
||||
Over⇐{𝕊:currentLevel<≠levels}
|
||||
SplitOnEmpty←{𝕩⊔˜(⊢-˜+`׬)0=≠¨𝕩}
|
||||
levels←Ascii2Matrix¨>¨SplitOnEmpty•FLines 𝕩 # Load file containing levels
|
||||
levels←Ascii2Matrix¨>¨SplitOnEmpty•FLines levelPath # Load file containing levels
|
||||
currentLevel⇐0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue