CabinGame/Luxe/game.wren

99 lines
2.4 KiB
Text
Raw Normal View History

2020-08-16 13:59:43 +00:00
import "luxe: game" for Game
import "luxe: assets" for Assets
import "luxe: input" for Input, Key
import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera
import "luxe: math" for Math
import "luxe: draw" for Draw
import "luxe: io" for IO
import "luxe: color" for Color
2020-08-16 13:59:43 +00:00
import "outline/app" for App
2020-08-18 21:16:04 +00:00
import "outline/Renderer" for Renderer
2020-08-16 13:59:43 +00:00
import "blocks/ui" for Ui
import "blocks/debug" for DrawDebug, Holder
2020-08-30 08:31:57 +00:00
import "globals" for Globals, RandomInst
2020-08-16 13:59:43 +00:00
import "math/vector" for Vector
import "math/rect" for AABB
import "math/util" for Util
import "blocks/tooltip" for Tooltip
2020-08-29 19:25:16 +00:00
import "blocks/human/human" for Human
2020-08-16 13:59:43 +00:00
class game is Game {
construct ready() {
2020-08-29 19:25:16 +00:00
//simple example... in theory (should print `0, 1, a` and `1, 2, b` cause thats the union)
//Util.for_all([[0, 1, 2], [1, 2], ["a", "b", "c", "d"]]){|a, b, c|System.print("%(a), %(b), %(c)")}
2020-08-16 13:59:43 +00:00
2020-08-29 06:14:01 +00:00
Globals["Game"] = this
2020-08-16 13:59:43 +00:00
app = App.new()
_ui = Ui.new(app)
_tooltip = Tooltip.new(app)
2020-08-16 13:59:43 +00:00
setup()
2020-08-16 13:59:43 +00:00
DrawDebug.setup(app.world)
Globals["Renderer"].events.listen(Renderer.on_change) { app.update_cam() }
2020-08-18 21:16:04 +00:00
2020-08-16 13:59:43 +00:00
} //ready
tick(delta) {
var mouse_pos = Vector.new(Input.mouse_x(), Input.mouse_y())
2020-08-30 08:31:57 +00:00
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)
2020-08-30 08:31:57 +00:00
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)
2020-08-16 13:59:43 +00:00
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
}
if(Input.key_state_pressed(Key.key_q)) {
_tooltip.cycle_size()
}
2020-08-16 13:59:43 +00:00
_ui.test()
2020-08-16 13:59:43 +00:00
DrawDebug.commit()
_tooltip.tick()
2020-08-16 13:59:43 +00:00
app.tick(delta)
2020-08-30 08:31:57 +00:00
2020-08-16 13:59:43 +00:00
} //tick
destroy() {
System.print("unready!")
app.destroy()
} //destroy
setup(){
var game_rect = Globals["GameRect"]
var bg = Entity.create(app.world, "background")
Transform.create(bg)
Transform.set_pos(bg, 64, 64, -10)
var material = Util.material_from_image_path("assets/wip/Room")
Sprite.create(bg, material, 128, 128)
2020-08-29 19:25:16 +00:00
create_human()
create_human()
2020-08-30 08:31:57 +00:00
create_human()
create_human()
2020-08-29 19:25:16 +00:00
}
create_human(){
var human = Entity.create(app.world, "human")
var humanMat = Util.material_from_image_path("assets/wip/Human")
Human.create(human)
2020-08-30 08:31:57 +00:00
Human.set_color(human, Util.hsv(RandomInst.float(), 0.5, 1))
}
2020-08-16 13:59:43 +00:00
app { _app }
app=(v) { _app=v }
2020-08-29 06:14:01 +00:00
ui{_ui}
2020-08-16 13:59:43 +00:00
} //Game