112 lines
2.8 KiB
Text
112 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
|
|
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" 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/human" for Human
|
|
import "blocks/resources" for Resources
|
|
|
|
class Game is Ready {
|
|
construct ready() {
|
|
super("Cabin Game")
|
|
Globals["Game"] = this
|
|
|
|
_focus = Observable.new()
|
|
_adventure = Observable.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) {
|
|
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
|
|
|
|
if(Input.key_state_released(Key.escape)) {
|
|
IO.shutdown()
|
|
}
|
|
|
|
if(Input.key_state_pressed(Key.key_q)) {
|
|
_tooltip.cycle_size()
|
|
}
|
|
|
|
DrawDebug.commit()
|
|
|
|
app.tick(delta)
|
|
_tooltip.tick() //important to tick after systems to not have a 1 frame lag after setting text
|
|
} //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)
|
|
|
|
_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 = Entity.create(app.world, "human")
|
|
Human.create(human)
|
|
Human.set_color(human, Util.hsv(RandomInst.float(), 0.5, 1))
|
|
|
|
var names = Assets.lx("assets/names.lx")
|
|
var name = names[RandomInst.int(0, names.count)]
|
|
Human.set_name(human, name)
|
|
}
|
|
|
|
Focus{_focus}
|
|
Adventure{_adventure}
|
|
resources{_resources}
|
|
|
|
app { _app }
|
|
app=(v) { _app=v }
|
|
|
|
ui{_ui}
|
|
|
|
} //Game
|