Fix up examples to no longer use '&'
This commit is contained in:
parent
33f1af8e71
commit
efb7be5bc4
@ -12,7 +12,7 @@ struct Player(pos,prev_pos:Vec2):
|
|||||||
FRICTION := 0.99
|
FRICTION := 0.99
|
||||||
SIZE := Vec2(30, 30)
|
SIZE := Vec2(30, 30)
|
||||||
|
|
||||||
func update(p:&Player):
|
func update(p:@Player):
|
||||||
target_x := inline C:Num {
|
target_x := inline C:Num {
|
||||||
(Num_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0))
|
(Num_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0))
|
||||||
}
|
}
|
||||||
|
@ -38,18 +38,18 @@ func solve_overlap(a_pos:Vec2, a_size:Vec2, b_pos:Vec2, b_size:Vec2 -> Vec2):
|
|||||||
|
|
||||||
return Vec2(0, 0)
|
return Vec2(0, 0)
|
||||||
|
|
||||||
struct World(player:@Player, goal:@Box, boxes:[@Box], dt_accum=0.0, won=no):
|
struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=0.0, won=no):
|
||||||
DT := 1./60.
|
DT := 1./60.
|
||||||
CURRENT := @World(@Player(Vec2(0,0), Vec2(0,0)), @Box(Vec2(0,0), Vec2(0,0), Color.GOAL), [:@Box])
|
CURRENT := @World(@Player(Vec2(0,0), Vec2(0,0)), @Box(Vec2(0,0), Vec2(0,0), Color.GOAL), @[:@Box])
|
||||||
STIFFNESS := 0.3
|
STIFFNESS := 0.3
|
||||||
|
|
||||||
func update(w:&World, dt:Num):
|
func update(w:@World, dt:Num):
|
||||||
w.dt_accum += dt
|
w.dt_accum += dt
|
||||||
while w.dt_accum > 0:
|
while w.dt_accum > 0:
|
||||||
w:update_once()
|
w:update_once()
|
||||||
w.dt_accum -= World.DT
|
w.dt_accum -= World.DT
|
||||||
|
|
||||||
func update_once(w:&World):
|
func update_once(w:@World):
|
||||||
w.player:update()
|
w.player:update()
|
||||||
|
|
||||||
if solve_overlap(w.player.pos, Player.SIZE, w.goal.pos, w.goal.size) != Vec2(0,0):
|
if solve_overlap(w.player.pos, Player.SIZE, w.goal.pos, w.goal.size) != Vec2(0,0):
|
||||||
@ -57,11 +57,11 @@ struct World(player:@Player, goal:@Box, boxes:[@Box], dt_accum=0.0, won=no):
|
|||||||
|
|
||||||
# Resolve player overlapping with any boxes:
|
# Resolve player overlapping with any boxes:
|
||||||
for i in 3:
|
for i in 3:
|
||||||
for b in w.boxes:
|
for b in w.boxes[]:
|
||||||
w.player.pos += STIFFNESS * solve_overlap(w.player.pos, Player.SIZE, b.pos, b.size)
|
w.player.pos += STIFFNESS * solve_overlap(w.player.pos, Player.SIZE, b.pos, b.size)
|
||||||
|
|
||||||
func draw(w:&World):
|
func draw(w:@World):
|
||||||
for b in w.boxes:
|
for b in w.boxes[]:
|
||||||
b:draw()
|
b:draw()
|
||||||
w.goal:draw()
|
w.goal:draw()
|
||||||
w.player:draw()
|
w.player:draw()
|
||||||
@ -71,17 +71,17 @@ struct World(player:@Player, goal:@Box, boxes:[@Box], dt_accum=0.0, won=no):
|
|||||||
DrawText("WINNER", GetScreenWidth()/2-48*3, GetScreenHeight()/2-24, 48, (Color){0,0,0,0xFF});
|
DrawText("WINNER", GetScreenWidth()/2-48*3, GetScreenHeight()/2-24, 48, (Color){0,0,0,0xFF});
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_map(w:&World, map:Text):
|
func load_map(w:@World, map:Text):
|
||||||
if map:has($/[]/):
|
if map:has($/[]/):
|
||||||
map = map:replace_all({$/[]/: "#", $/@{1..}/: "@", $/ /: " "})
|
map = map:replace_all({$/[]/: "#", $/@{1..}/: "@", $/ /: " "})
|
||||||
w.boxes = [:@Box]
|
w.boxes = @[:@Box]
|
||||||
box_size := Vec2(50., 50.)
|
box_size := Vec2(50., 50.)
|
||||||
for y,line in map:lines():
|
for y,line in map:lines():
|
||||||
for x,cell in line:split():
|
for x,cell in line:split():
|
||||||
if cell == "#":
|
if cell == "#":
|
||||||
pos := Vec2((Num(x)-1) * box_size.x, (Num(y)-1) * box_size.y)
|
pos := Vec2((Num(x)-1) * box_size.x, (Num(y)-1) * box_size.y)
|
||||||
box := @Box(pos, size=box_size, color=Color.GRAY)
|
box := @Box(pos, size=box_size, color=Color.GRAY)
|
||||||
(&w.boxes):insert(box)
|
w.boxes:insert(box)
|
||||||
else if cell == "@":
|
else if cell == "@":
|
||||||
pos := Vec2((Num(x)-1) * box_size.x, (Num(y)-1) * box_size.y)
|
pos := Vec2((Num(x)-1) * box_size.x, (Num(y)-1) * box_size.y)
|
||||||
pos += box_size/2. - Player.SIZE/2.
|
pos += box_size/2. - Player.SIZE/2.
|
||||||
|
@ -25,7 +25,7 @@ func _get_file_dependencies(file:Path -> {Dependency}):
|
|||||||
deps:add(Dependency.Module(module_name))
|
deps:add(Dependency.Module(module_name))
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
func _build_dependency_graph(dep:Dependency, dependencies:&{Dependency:{Dependency}}):
|
func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency:{Dependency}}):
|
||||||
return if dependencies:has(dep)
|
return if dependencies:has(dep)
|
||||||
|
|
||||||
dependencies:set(dep, {:Dependency}) # Placeholder
|
dependencies:set(dep, {:Dependency}) # Placeholder
|
||||||
@ -56,8 +56,8 @@ func _build_dependency_graph(dep:Dependency, dependencies:&{Dependency:{Dependen
|
|||||||
_build_dependency_graph(dep2, dependencies)
|
_build_dependency_graph(dep2, dependencies)
|
||||||
|
|
||||||
func get_dependency_graph(dep:Dependency -> {Dependency:{Dependency}}):
|
func get_dependency_graph(dep:Dependency -> {Dependency:{Dependency}}):
|
||||||
graph := {:Dependency:{Dependency}}
|
graph := @{:Dependency:{Dependency}}
|
||||||
_build_dependency_graph(dep, &graph)
|
_build_dependency_graph(dep, graph)
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
func _printable_name(dep:Dependency -> Text):
|
func _printable_name(dep:Dependency -> Text):
|
||||||
@ -70,7 +70,7 @@ func _printable_name(dep:Dependency -> Text):
|
|||||||
else:
|
else:
|
||||||
return "$(\x1b)[31;1m$(f.text_content) (not found)$(\x1b)[m"
|
return "$(\x1b)[31;1m$(f.text_content) (not found)$(\x1b)[m"
|
||||||
|
|
||||||
func _draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}, already_printed:&{Dependency}, prefix="", is_last=yes):
|
func _draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}, already_printed:@{Dependency}, prefix="", is_last=yes):
|
||||||
if already_printed:has(dep):
|
if already_printed:has(dep):
|
||||||
say(prefix ++ (if is_last: "└── " else: "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m")
|
say(prefix ++ (if is_last: "└── " else: "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m")
|
||||||
return
|
return
|
||||||
@ -86,13 +86,13 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}, already_
|
|||||||
_draw_tree(child, dependencies, already_printed, child_prefix, is_child_last)
|
_draw_tree(child, dependencies, already_printed, child_prefix, is_child_last)
|
||||||
|
|
||||||
func draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}):
|
func draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}):
|
||||||
printed := {:Dependency}
|
printed := @{:Dependency}
|
||||||
say(_printable_name(dep))
|
say(_printable_name(dep))
|
||||||
printed:add(dep)
|
printed:add(dep)
|
||||||
deps := dependencies:get(dep) or {:Dependency}
|
deps := dependencies:get(dep) or {:Dependency}
|
||||||
for i,child in deps.items:
|
for i,child in deps.items:
|
||||||
is_child_last := (i == deps.length)
|
is_child_last := (i == deps.length)
|
||||||
_draw_tree(child, dependencies, already_printed=&printed, is_last=is_child_last)
|
_draw_tree(child, dependencies, already_printed=printed, is_last=is_child_last)
|
||||||
|
|
||||||
func main(files:[Text]):
|
func main(files:[Text]):
|
||||||
if files.length == 0:
|
if files.length == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user