fix compass rotation

This commit is contained in:
Ronja 2020-10-06 22:26:22 +02:00
parent 7f062de6e6
commit cbb2a4c405
3 changed files with 20 additions and 16 deletions

View file

@ -3,21 +3,24 @@
//make groups based on origin culture / meaning
//probably better to do when I have a procgen text engine
"Bob"
"Steve"
"Ronja"
"Amelia"
"Bob"
"Bug"
"Chloe"
"Lauren"
"Claus"
"Ida"
"Innes"
"Rami"
"Richard"
"Jules"
"Mercedes"
"Karl"
"Lara"
"Bug"
"Sandra"
"Claus"
"Lauren"
"Levi"
"Mercedes"
"Niels"
"Rami"
"Richard"
"Ronja"
"Sandra"
"Simon"
"Steve"
]

View file

@ -112,15 +112,14 @@ class UiAdventure{
_game.adventures.planning.on_change(true){|val|
if(val == null) return
var angle = val.direction * 360 / steps
var angle = -val.direction * 360 / steps
UiCompass.set_angle(compass, angle)
}
Control.set_events(compass){|event|
if(event.type == UIEvent.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
adventure.value.direction = angleIndex
adventure.emit()

View file

@ -9,6 +9,7 @@ import "globals" for Globals
import "math/rect" for AABB
import "math/math" for M
import "blocks/debug" for DrawDebug
import "luxe: io" for IO
class UiCompass{
static font{"assets/fonts/BabyBlocks"}
@ -27,9 +28,10 @@ class UiCompass{
var image = Assets.image("assets/wip/Needle")
var ratio = Image.get_width(image) / Image.get_height(image)
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_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|
if(event.control != control) return
@ -46,8 +48,8 @@ class UiCompass{
UI.uncapture(control)
} else if(event.type == UIEvent.move && state["pressed"]){
var center = [x + w/2, y + h/2]
var diff = [center.x - event.x, center.y - event.y]
var angle = Math.atan2(diff.x, diff.y)
var diff = [event.x - center.x, event.y - center.y]
var angle = Math.atan2(-diff.y, diff.x) - Num.tau / 4
UI.events_emit(control, UIEvent.change, Math.degrees(angle))
}
}