115 lines
2.8 KiB
Text
115 lines
2.8 KiB
Text
import "luxe: game" for Ready
|
|
import "luxe: input" for Input, Key
|
|
import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, UI
|
|
import "luxe: math" for Math
|
|
import "luxe: draw" for Draw
|
|
import "luxe: io" for IO
|
|
import "luxe: assets" for Assets
|
|
import "luxe: color" for Color
|
|
|
|
import "outline/app" for App
|
|
import "outline/renderer" for Renderer
|
|
import "blocks/ui/ui" for Ui
|
|
import "blocks/debug" for DrawDebug, Holder
|
|
import "globals" for Globals, RandomInst
|
|
import "math/vector" for Vector
|
|
import "math/rect" for AABB
|
|
import "math/util" for Util
|
|
import "math/observable" for Observable
|
|
import "blocks/tooltip" for Tooltip
|
|
import "blocks/human" for Human
|
|
import "blocks/resources" for Resources
|
|
import "blocks/adventures" for AdventureManager
|
|
import "blocks/narrative/time" for Time
|
|
|
|
class Game is Ready {
|
|
construct ready() {
|
|
super("Cabin Game")
|
|
Globals["Game"] = this
|
|
|
|
_focus = Observable.new()
|
|
_adventures = AdventureManager.new()
|
|
_time = Time.new()
|
|
|
|
app = App.new()
|
|
_resources = Resources.new()
|
|
_tooltip = Tooltip.new(app)
|
|
_ui = Ui.new(app)
|
|
|
|
setup()
|
|
DrawDebug.setup(app.world)
|
|
|
|
Globals["Renderer"].events.listen(Renderer.on_change) { app.update_cam() }
|
|
|
|
} //ready
|
|
|
|
tick(delta: Num) {
|
|
Globals["Delta"] = delta
|
|
|
|
var mouse_pos = Vector.new(Input.mouse_x(), Input.mouse_y())
|
|
var game_mouse = Globals["Renderer"].game_mouse(mouse_pos)
|
|
game_mouse = Camera.screen_point_to_world(app.camera, game_mouse.x, game_mouse.y)
|
|
Globals["GameMouse"] = game_mouse
|
|
var ui_mouse = Globals["Renderer"].ui_mouse(mouse_pos)
|
|
ui_mouse = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y)
|
|
Globals["UiMouse"] = ui_mouse
|
|
|
|
DrawDebug.commit()
|
|
_tooltip.tick()
|
|
_adventures.tick()
|
|
Human.tick()
|
|
|
|
app.tick(delta)
|
|
|
|
if(Input.key_state_released(Key.escape)) {
|
|
IO.shutdown()
|
|
}
|
|
} //tick
|
|
|
|
destroy() {
|
|
Log.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)
|
|
|
|
_resources.add("dog", 2)
|
|
_resources.add("wood", 5)
|
|
_resources.add("tent", 0)
|
|
|
|
create_human()
|
|
create_human()
|
|
create_human()
|
|
create_human()
|
|
create_human()
|
|
create_human()
|
|
}
|
|
|
|
create_human(){
|
|
var human: Human = Human.new()
|
|
human.color = Util.hsv(RandomInst.float(), 0.5, 1)
|
|
var names = Assets.lx("assets/names.lx")
|
|
var name = names[RandomInst.int(0, names.count)]
|
|
human.name = name
|
|
human.active = true
|
|
}
|
|
|
|
time{_time}
|
|
focus{_focus}
|
|
adventures{_adventures}
|
|
resources{_resources}
|
|
|
|
app { _app }
|
|
app=(v) { _app=v }
|
|
|
|
ui{_ui}
|
|
|
|
} //Game
|