position play and hand cards

This commit is contained in:
Ronja 2021-05-23 16:20:37 +02:00
parent c87b31968b
commit 8ce3872527
4 changed files with 74 additions and 11 deletions

3
.gitignore vendored
View file

@ -7,4 +7,5 @@ thumbs.db
.luxe/
_luxe.data/
_luxe.deploy/
log.txt
log.txt
*.png~

View file

@ -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*/){

View file

@ -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()

42
utils/vec.wren Normal file
View file

@ -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
}
}