fix compass rotation
This commit is contained in:
parent
7f062de6e6
commit
cbb2a4c405
3 changed files with 20 additions and 16 deletions
|
|
@ -3,21 +3,24 @@
|
||||||
//make groups based on origin culture / meaning
|
//make groups based on origin culture / meaning
|
||||||
//probably better to do when I have a procgen text engine
|
//probably better to do when I have a procgen text engine
|
||||||
|
|
||||||
"Bob"
|
|
||||||
"Steve"
|
|
||||||
"Ronja"
|
|
||||||
"Amelia"
|
"Amelia"
|
||||||
|
"Bob"
|
||||||
|
"Bug"
|
||||||
"Chloe"
|
"Chloe"
|
||||||
"Lauren"
|
"Claus"
|
||||||
|
"Ida"
|
||||||
"Innes"
|
"Innes"
|
||||||
"Rami"
|
|
||||||
"Richard"
|
|
||||||
"Jules"
|
"Jules"
|
||||||
"Mercedes"
|
|
||||||
"Karl"
|
"Karl"
|
||||||
"Lara"
|
"Lara"
|
||||||
"Bug"
|
"Lauren"
|
||||||
"Sandra"
|
"Levi"
|
||||||
"Claus"
|
"Mercedes"
|
||||||
"Niels"
|
"Niels"
|
||||||
|
"Rami"
|
||||||
|
"Richard"
|
||||||
|
"Ronja"
|
||||||
|
"Sandra"
|
||||||
|
"Simon"
|
||||||
|
"Steve"
|
||||||
]
|
]
|
||||||
|
|
@ -112,15 +112,14 @@ class UiAdventure{
|
||||||
|
|
||||||
_game.adventures.planning.on_change(true){|val|
|
_game.adventures.planning.on_change(true){|val|
|
||||||
if(val == null) return
|
if(val == null) return
|
||||||
var angle = val.direction * 360 / steps
|
var angle = -val.direction * 360 / steps
|
||||||
UiCompass.set_angle(compass, angle)
|
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){
|
||||||
var angle = event.change
|
var angle = event.change
|
||||||
|
var angleIndex = M.repeat(-(steps * angle / 360).round, steps)
|
||||||
var angleIndex = M.repeat((steps * angle / 360).round, steps)
|
|
||||||
var adventure = _game.adventures.planning
|
var adventure = _game.adventures.planning
|
||||||
adventure.value.direction = angleIndex
|
adventure.value.direction = angleIndex
|
||||||
adventure.emit()
|
adventure.emit()
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import "globals" for Globals
|
||||||
import "math/rect" for AABB
|
import "math/rect" for AABB
|
||||||
import "math/math" for M
|
import "math/math" for M
|
||||||
import "blocks/debug" for DrawDebug
|
import "blocks/debug" for DrawDebug
|
||||||
|
import "luxe: io" for IO
|
||||||
|
|
||||||
class UiCompass{
|
class UiCompass{
|
||||||
static font{"assets/fonts/BabyBlocks"}
|
static font{"assets/fonts/BabyBlocks"}
|
||||||
|
|
@ -27,9 +28,10 @@ class UiCompass{
|
||||||
var image = Assets.image("assets/wip/Needle")
|
var image = Assets.image("assets/wip/Needle")
|
||||||
var ratio = Image.get_width(image) / Image.get_height(image)
|
var ratio = Image.get_width(image) / Image.get_height(image)
|
||||||
var needleSize = [(Math.min(w, h) - 8) * ratio, (Math.min(w, h) - 8)]
|
var needleSize = [(Math.min(w, h) - 8) * ratio, (Math.min(w, h) - 8)]
|
||||||
|
var angle = state["angle"]
|
||||||
UI.draw_ring(control, center.x, center.y, depth, w/2, h/2, 0, 360, 8, state["style"])
|
UI.draw_ring(control, center.x, center.y, depth, w/2, h/2, 0, 360, 8, state["style"])
|
||||||
UI.draw_image(control, center.x - needleSize.x/2, center.y-needleSize.y/2, depth, needleSize.x, needleSize.y,
|
UI.draw_image(control, center.x - needleSize.x/2, center.y-needleSize.y/2, depth, needleSize.x, needleSize.y,
|
||||||
state["angle"], [1,1,1,1], [0, 0, 1, 1], image, true)
|
angle, [1,1,1,1], [0, 0, 1, 1], image, true)
|
||||||
}
|
}
|
||||||
Control.set_process(compass){|control, state, event, x,y,w,h|
|
Control.set_process(compass){|control, state, event, x,y,w,h|
|
||||||
if(event.control != control) return
|
if(event.control != control) return
|
||||||
|
|
@ -46,8 +48,8 @@ class UiCompass{
|
||||||
UI.uncapture(control)
|
UI.uncapture(control)
|
||||||
} else if(event.type == UIEvent.move && state["pressed"]){
|
} else if(event.type == UIEvent.move && state["pressed"]){
|
||||||
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 = [event.x - center.x, event.y - center.y]
|
||||||
var angle = Math.atan2(diff.x, diff.y)
|
var angle = Math.atan2(-diff.y, diff.x) - Num.tau / 4
|
||||||
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
|
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue