From 853d153fb6ff756cfbd2d5bdf417348fb411042b Mon Sep 17 00:00:00 2001 From: Ronja Date: Sun, 30 Aug 2020 10:31:57 +0200 Subject: [PATCH] rainbow friends --- Luxe/blocks/human/human.wren | 6 ++-- Luxe/game.wren | 14 ++++---- Luxe/globals.wren | 3 +- Luxe/math/math.wren | 45 ++++++++++++++++++-------- Luxe/math/{repNum.wren => repVal.wren} | 2 +- Luxe/math/util.wren | 4 +-- Luxe/math/vector.wren | 2 +- 7 files changed, 48 insertions(+), 28 deletions(-) rename Luxe/math/{repNum.wren => repVal.wren} (86%) diff --git a/Luxe/blocks/human/human.wren b/Luxe/blocks/human/human.wren index 8c03013..5350967 100644 --- a/Luxe/blocks/human/human.wren +++ b/Luxe/blocks/human/human.wren @@ -27,7 +27,7 @@ class Human { //in the world and respond to them here. class HumanSystem is ModifierSystem { - player_start{[26, 90]} + player_start{[26, 89]} player_size{[10, 12]} construct new() { @@ -59,7 +59,7 @@ class HumanSystem is ModifierSystem { //called usually once every frame. //called when the world that this modifier lives in, is ticked each {|entity, data| - System.print("%(Transform.get_pos(entity))") + } } //tick @@ -73,7 +73,7 @@ class HumanSystem is ModifierSystem { Sprite.destroy(entity) return } - var pos = start + var pos = Vector.new(start) pos.x = pos.x + size.x * i if(!Transform.has(entity)){ Transform.create(entity) diff --git a/Luxe/game.wren b/Luxe/game.wren index 407406c..944ebc5 100644 --- a/Luxe/game.wren +++ b/Luxe/game.wren @@ -11,13 +11,12 @@ import "outline/app" for App import "outline/Renderer" for Renderer import "blocks/ui" for Ui import "blocks/debug" for DrawDebug, Holder -import "globals" for Globals +import "globals" for Globals, RandomInst import "math/vector" for Vector import "math/rect" for AABB import "math/util" for Util import "blocks/tooltip" for Tooltip import "blocks/human/human" for Human -import "random" for Random class game is Game { construct ready() { @@ -39,9 +38,9 @@ class game is Game { tick(delta) { var mouse_pos = Vector.new(Input.mouse_x(), Input.mouse_y()) - var game_mouse = Globals["Renderer"].game_mouse(mouse_pos) + var game_mouse = [0, 0]//Globals["Renderer"].game_mouse(mouse_pos) Globals["GameMouse"] = Camera.screen_point_to_world(app.camera, game_mouse.x, game_mouse.y) - var ui_mouse = Globals["Renderer"].ui_mouse(mouse_pos) + var ui_mouse = [0, 0]//Globals["Renderer"].ui_mouse(mouse_pos) Globals["UiMouse"] = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y) if(Input.key_state_released(Key.escape)) { @@ -58,6 +57,7 @@ class game is Game { _tooltip.tick() app.tick(delta) + } //tick destroy() { @@ -79,15 +79,15 @@ class game is Game { create_human() create_human() + create_human() + create_human() } create_human(){ var human = Entity.create(app.world, "human") var humanMat = Util.material_from_image_path("assets/wip/Human") Human.create(human) - System.print(Util.hsv(Random.new().float(), 1, 1)) - //var rand = Random.new().float() - //Human.set_color(human, Util.hsv(rand, 1, 1)) + Human.set_color(human, Util.hsv(RandomInst.float(), 0.5, 1)) } app { _app } diff --git a/Luxe/globals.wren b/Luxe/globals.wren index b0d7653..f5cc87d 100644 --- a/Luxe/globals.wren +++ b/Luxe/globals.wren @@ -1,3 +1,4 @@ +import "random" for Random - +var RandomInst = Random.new() var Globals = {} \ No newline at end of file diff --git a/Luxe/math/math.wren b/Luxe/math/math.wren index 8cbbe3f..31d242e 100644 --- a/Luxe/math/math.wren +++ b/Luxe/math/math.wren @@ -1,30 +1,49 @@ import "math/vector" for Vector import "luxe: math" for Math -import "math/repNum" for RepNum +import "math/repVal" for RepVal import "math/Util" for Util class M{ - static inv_lerp(from, to, inter){ - return (inter - from) / (to - from) + static inv_lerp(from, to, value){ + //if the range are numbers, we assume the interpolation value is too + if(from is Num && to is Num) return (value - from) / (to - from) + //if only one of the range qualifiers is a sequence, we make the other one a endless sequence of itself + //(will do a union to take the shortest length anyways) + if(from is Sequence != to is Sequence) { + if(from is Sequence){ + to = RepVal.new(to) + } else { + from = RepVal.new(from) + } + } + //if the interpolation value is a number, make it infinite + if(value is Num) value = RepVal.new(value) + + var result = [] + Util.for_all([from, to, value]) { |v| + result.add(lerp(v[0], v[1], v[2])) + } + return result } static lerp(from, to, value){ + //if the range are numbers, we assume the interpolation value is too if(from is Num && to is Num) return from + (to - from) * value + //if only one of the range qualifiers is a sequence, we make the other one a endless sequence of itself + //(will do a union to take the shortest length anyways) if(from is Sequence != to is Sequence) { if(from is Sequence){ - to = RepNum.new(to, from.count) + to = RepVal.new(to) } else { - from = RepNum.new(from, to.count) + from = RepVal.new(from) } } - if(value is Num) value = RepNum.new(value) - - System.print("%(from.toList) %(to.toList)") + //if the interpolation value is a number, make it infinite + if(value is Num) value = RepVal.new(value) var result = [] - Util.for_all([from, to, value]) { |from, to, value| - System.print(from) - result.add(lerp(from, to, value)) + Util.for_all([from, to, value]) { |v| + result.add(lerp(v[0], v[1], v[2])) } return result } @@ -47,8 +66,8 @@ class M{ } if(min is Sequence && max is Sequence){ var result = [] - Util.for_all([value, min, max]) { |value, min, max| - result.add(clamp(value, min, max)) + Util.for_all([value, min, max]) { |v| + result.add(clamp(v[0], v[1], v[2])) } return result } diff --git a/Luxe/math/repNum.wren b/Luxe/math/repVal.wren similarity index 86% rename from Luxe/math/repNum.wren rename to Luxe/math/repVal.wren index b9fc316..4473500 100644 --- a/Luxe/math/repNum.wren +++ b/Luxe/math/repVal.wren @@ -1,5 +1,5 @@ -class RepNum is Sequence{ +class RepVal is Sequence{ static new(value){ return new(value, -1) } diff --git a/Luxe/math/util.wren b/Luxe/math/util.wren index 00fcee2..31cc30b 100644 --- a/Luxe/math/util.wren +++ b/Luxe/math/util.wren @@ -27,7 +27,7 @@ class Util{ var iterators = List.filled(count, null) counter.each{|i| iterators[i] = sequences[i].iterate(iterators[i])} while(iterators.all{|iter| iter}){ - var values = (0...count).map{|i| sequences[i].iteratorValue(iterators[i])} + var values = (0...count).map{|i| sequences[i].iteratorValue(iterators[i])}.toList fn.call(values) counter.each{|i| iterators[i] = sequences[i].iterate(iterators[i])} } @@ -48,6 +48,6 @@ class Util{ //and value col = col.map{|comp| comp * v} - return col.toList + [1] //poor womans add + return col.toList + [1] } } \ No newline at end of file diff --git a/Luxe/math/vector.wren b/Luxe/math/vector.wren index 25037ea..2a38de3 100644 --- a/Luxe/math/vector.wren +++ b/Luxe/math/vector.wren @@ -65,7 +65,7 @@ class Vector is Sequence{ iterate(iter){ if(!iter) return 0 - if(iter > 1) return null + if(iter > 1) return false return iter + 1 }