make compass work as intended
This commit is contained in:
parent
ee46e22899
commit
e3b4d27602
4 changed files with 45 additions and 2 deletions
|
|
@ -31,11 +31,18 @@ class Adventure{
|
||||||
adventurers{_adventurers}
|
adventurers{_adventurers}
|
||||||
resources{_resources}
|
resources{_resources}
|
||||||
data{_data}
|
data{_data}
|
||||||
|
direction{_direction}
|
||||||
|
direction=(dir){_direction = dir}
|
||||||
|
distance{_distance}
|
||||||
|
distance=(dist){_distance = dist}
|
||||||
|
|
||||||
construct new(){
|
construct new(){
|
||||||
_adventurers = []
|
_adventurers = []
|
||||||
_resources = []
|
_resources = []
|
||||||
_data = {}
|
_data = {}
|
||||||
|
|
||||||
|
_direction = 0
|
||||||
|
_distance = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
add_adventurer(adventurer){
|
add_adventurer(adventurer){
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import "math/observable" for Observable
|
||||||
import "blocks/ui/simple_text" for UISimpleText
|
import "blocks/ui/simple_text" for UISimpleText
|
||||||
import "blocks/ui/ui" for Ui
|
import "blocks/ui/ui" for Ui
|
||||||
import "blocks/ui/compass" for UiCompass
|
import "blocks/ui/compass" for UiCompass
|
||||||
|
import "math/math" for M
|
||||||
|
|
||||||
class UiAdventure{
|
class UiAdventure{
|
||||||
root{_root}
|
root{_root}
|
||||||
|
|
@ -85,9 +86,37 @@ class UiAdventure{
|
||||||
var compass = UiCompass.create(_ent)
|
var compass = UiCompass.create(_ent)
|
||||||
Control.child_add(page, compass)
|
Control.child_add(page, compass)
|
||||||
Control.set_size(compass, 32, 32)
|
Control.set_size(compass, 32, 32)
|
||||||
|
var steps = 16 //compass steps
|
||||||
|
var step_names = ["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
|
||||||
|
var full_step_names = step_names.map{|short|
|
||||||
|
var shorts = "NESW"
|
||||||
|
var base_directions = ["north","east","south","west"]
|
||||||
|
if(short.count == 1){
|
||||||
|
return base_directions[shorts.indexOf(short)]
|
||||||
|
} else if(short.count == 2) {
|
||||||
|
return base_directions[shorts.indexOf(short[0])] +
|
||||||
|
base_directions[shorts.indexOf(short[1])]
|
||||||
|
} else { //assume 3
|
||||||
|
return base_directions[shorts.indexOf(short[0])] + "-" +
|
||||||
|
base_directions[shorts.indexOf(short[1])] +
|
||||||
|
base_directions[shorts.indexOf(short[2])]
|
||||||
|
}
|
||||||
|
}.toList
|
||||||
|
|
||||||
|
_game.adventures.planning.on_change(true){|val|
|
||||||
|
if(val == null) return
|
||||||
|
var angle = val.direction * 360 / steps
|
||||||
|
UiCompass.set_angle(compass, angle)
|
||||||
|
}
|
||||||
|
|
||||||
Control.set_events(compass){|event|
|
Control.set_events(compass){|event|
|
||||||
if(event.type == UIEvent.change){
|
if(event.type == UIEvent.change){
|
||||||
System.print(event)
|
var angle = event.change
|
||||||
|
|
||||||
|
var angleIndex = M.repeat((steps * angle / 360).round, steps)
|
||||||
|
var adventure = _game.adventures.planning
|
||||||
|
adventure.value.direction = angleIndex
|
||||||
|
adventure.emit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ class UiCompass{
|
||||||
var center = [x + w/2, y + h/2]
|
var center = [x + w/2, y + h/2]
|
||||||
var diff = [center.x - event.x, center.y - event.y]
|
var diff = [center.x - event.x, center.y - event.y]
|
||||||
var angle = Math.atan2(diff.x, diff.y)
|
var angle = Math.atan2(diff.x, diff.y)
|
||||||
System.print("change %(Math.degrees(angle).round)")
|
|
||||||
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
|
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ class M{
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static repeat(number, min, max){
|
||||||
|
return min + repeat(number, max - min)
|
||||||
|
}
|
||||||
|
|
||||||
|
static repeat(number, max){
|
||||||
|
return max.sign * ((number % max + max) % max)
|
||||||
|
}
|
||||||
|
|
||||||
static remap(min_in, max_in, min_out, max_out, value){
|
static remap(min_in, max_in, min_out, max_out, value){
|
||||||
var inter = inv_lerp(min_in, max_in, value)
|
var inter = inv_lerp(min_in, max_in, value)
|
||||||
return lerp(min_out, max_out, inter)
|
return lerp(min_out, max_out, inter)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue