diff --git a/.gitignore b/.gitignore index d9dc9db..2241471 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ thumbs.db .luxe/ _luxe.data/ _luxe.deploy/ -log.txt \ No newline at end of file +log.txt +*.png~ diff --git a/field.wren b/field.wren index 656bcb9..13160c7 100644 --- a/field.wren +++ b/field.wren @@ -1,12 +1,18 @@ -import "luxe: world" for Prototype, Entity +import "luxe: world" for Prototype, Entity, Transform +import "utils/vec" for Vec var Slots = [ - [-1, +3, -2], [ 0, +2, -2], [ 1, +1, -2], [ 2, +0, -2], [ 3, -1, -2], - [-2, +3, -1], [-1, +2, -1], [ 0, +1, -1], [ 1, +0, -1], [ 2, -1, -1], [ 3, -2, -1], - [-3, +3, +0], [-2, +2, +0], [-1, +1, +0], [ 0, +0, +0], [ 1, -1, +0], [ 2, -2, +0], [ 3, -3, 0], - [-3, +2, +1], [-2, +1, +1], [-1, +0, +1], [ 0, -1, +1], [ 1, -2, +1], [ 2, -3, +1], - [-3, +1, +2], [-2, +0, +2], [-1, -1, +2], [ 0, -2, +2], [ 1, -3, +2] + [-1, 3, -2], [ 0, 2, -2], [ 1, 1, -2], [ 2, 0, -2], [ 3, -1, -2], + [-2, 3, -1], [-1, 2, -1], [ 0, 1, -1], [ 1, 0, -1], [ 2, -1, -1], [ 3, -2, -1], + [-3, 3, 0], [-2, 2, 0], [-1, 1, 0], [ 0, 0, 0], [ 1, -1, 0], [ 2, -2, 0], [ 3, -3, 0], + [-3, 2, 1], [-2, 1, 1], [-1, 0, 1], [ 0, -1, 1], [ 1, -2, 1], [ 2, -3, 1], + [-3, 1, 2], [-2, 0, 2], [-1, -1, 2], [ 0, -2, 2], [ 1, -3, 2] +] + +var Hand = [ + [-1, 2, -1], [ 0, 1, -1], [ 1, 0, -1], [ 2, -1, -1], + [-2, 2, 0], [-1, 1, 0], [ 0, 0, 0], [ 1, -1, 0], [ 2, -2, 0] ] var x_angle = 1 * Num.tau / 12 @@ -18,14 +24,20 @@ var Z_Dir = [z_angle.cos, z_angle.sin, 0] class Field{ + root{_root} + construct new(world){ _world = world _root = Entity.create(world) + Transform.create(_root) _slots = [] } add_slot(slot: List /*of Num*/){ - Prototype.create(_world, "prototype/card", "card(%(slot.x), %(slot.y), %(slot.z))", [0, 0, 0], [0,0,0], [2,2,2]) + var pos = Vec.add(Vec.add(Vec.mul(slot.x, X_Dir), Vec.mul(slot.y, Y_Dir)), Vec.mul(slot.z, Z_Dir)) + pos = Vec.mul(pos, 66) + var new_instance = Prototype.create(_world, "prototype/card", "card(%(slot.x), %(slot.y), %(slot.z))", pos, [0,0,0], [2,2,2]) + Transform.link(new_instance, _root) } add_slots(slots: List /*of List of Num*/){ diff --git a/game.wren b/game.wren index 8fe6fb3..b2f4181 100644 --- a/game.wren +++ b/game.wren @@ -6,7 +6,7 @@ import "luxe: math" for Math import "luxe: draw" for Draw import "luxe: io" for IO import "luxe: lx" for LX -import "field" for Field, Slots +import "field" for Field, Slots, Hand import "outline/app" for App @@ -23,17 +23,25 @@ class Game is Ready { _logo = Entity.create(app.world, "sprite") Transform.create(_logo) - Transform.set_pos(_logo, app.width/2, app.height/2, 0) + Transform.set_pos(_logo, app.width/2, app.height/2, 100) Text.create(_logo, Assets.material("luxe: material/font"), 42, "luxe: fonts/lato", [1,1,1,1]) Text.set_text(_logo, "Lorem Ipsum dolor sit amet") _playField = Field.new(app.world) + Transform.set_pos(_playField.root, app.width/2, app.height/2 + 100, 0) + Transform.set_scale(_playField.root, 0.8, 0.8, 0.8) + _playField.add_slots(Slots) + + _hand = Field.new(app.world) + Transform.set_pos(_hand.root, app.width/2, 50, 0) + Transform.set_scale(_hand.root, 0.8, 0.8, 0.8) + _hand.add_slots(Hand) } //ready tick(delta) { var pos = Camera.screen_point_to_world(app.camera, Input.mouse_x(), Input.mouse_y()) - Transform.set_pos(_logo, pos.x, pos.y, 0) + Transform.set_pos(_logo, pos.x, pos.y, 100) if(Input.key_state_released(Key.escape)) { IO.shutdown() diff --git a/utils/vec.wren b/utils/vec.wren new file mode 100644 index 0000000..7622c91 --- /dev/null +++ b/utils/vec.wren @@ -0,0 +1,42 @@ + + +class Vec{ + static add(first: List, second: List){ + var count = first.count.min(second.count) + var result = [] + for(i in 0...count){ + result.add(first[i] + second[i]) + } + return result + } + + static sub(first: List, second: List){ + var count = first.count.min(second.count) + var result = [] + for(i in 0...count){ + result.add(first[i] - second[i]) + } + return result + } + + static mul(first: List, second: Any){ + if(first is Num && second is List) return mul(second, first) + var secondNum = second is Num + var count = secondNum ? first.count : (first.count.min(second.count)) + var result = [] + for(i in 0...count){ + result.add(first[i] * (secondNum?second:second[i])) + } + return result + } + + static div(first: List, second: Any){ + var secondNum = second is Num + var count = secondNum ? first.count : first.count.min(second.count) + var result = [] + for(i in 0...count){ + result.add(first[i] / secondNum?second:second[i]) + } + return result + } +} \ No newline at end of file