commit 7600d281b8ec93944dae992eaa50eca34ed7193d Author: Jonathan Hirz Date: Sat Jan 19 22:50:00 2019 -0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dce4b32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*/.DS_Store +.DS_Store +.DS_Store? +*/thumbs.db +thumbs.db +.thumbs.db? +_luxe.data/ +_luxe.deploy/ +screenshots/ \ No newline at end of file diff --git a/.luxeignore b/.luxeignore new file mode 100644 index 0000000..04ddc8b --- /dev/null +++ b/.luxeignore @@ -0,0 +1 @@ +screenshots/* \ No newline at end of file diff --git a/_art/player_ship.ase b/_art/player_ship.ase new file mode 100644 index 0000000..936802f Binary files /dev/null and b/_art/player_ship.ase differ diff --git a/_art/star.ase b/_art/star.ase new file mode 100644 index 0000000..f47ca09 Binary files /dev/null and b/_art/star.ase differ diff --git a/empty.outline.lx b/empty.outline.lx new file mode 100644 index 0000000..3c4ad30 --- /dev/null +++ b/empty.outline.lx @@ -0,0 +1,3 @@ +name = "empty" +description = "An empty project, with a game world and a ui world.\nDefaults to 2D cameras mapped to window size,\nand handles basic rendering and updating." +keywords = ["empty", "blank", "2D"] \ No newline at end of file diff --git a/game.scene/game.layer b/game.scene/game.layer new file mode 100644 index 0000000..66bb535 --- /dev/null +++ b/game.scene/game.layer @@ -0,0 +1,3 @@ +layer = { + elements = {} //elements +} //layer diff --git a/game.wren b/game.wren new file mode 100644 index 0000000..858f9c5 --- /dev/null +++ b/game.wren @@ -0,0 +1,187 @@ +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 "random" for Random + +import "outline/app" for App + +class game is Game { + + construct ready() { + + System.print("ready!") + + app = App.new() + app.color = [0,0,0,1] + System.print("render size: %(app.width) x %(app.height) @ %(app.scale)x") + + // game vars + // camera + _camera_scale = 1.5 + + // starfield + _star_scale = 2 + + // player ship + _ship_rotation = 0 + _ship_speed = 40 + _ship_acceleration_x = 0 + _ship_acceleration_y = 0 + _ship_velocity_x = 0 + _ship_velocity_y = 0 + _ship_dampening = 0.85 + + Camera.ortho(app.camera, 0, 0, app.width / _camera_scale, app.height / _camera_scale, -1, 1) + + draw_starfield() + create_ship() + Transform.set_pos(app.camera, Transform.get_pos_x(_ship) - (app.width / 2 / _camera_scale), Transform.get_pos_y(_ship) - (app.height / 2 / _camera_scale)) + + } //ready + + tick(delta) { + + tick_ship(delta) + tick_camera(delta) + tick_starfield(delta) + + if(Input.key_state_released(Key.escape)) { + IO.shutdown() + } + + app.tick(delta) + + } //tick + + ////////////// + // CREATORS // + ////////////// + + draw_starfield() { + + //todo: understand this starfield, expand it, make it move. + var rng = Random.new(25) + var ctx = Draw.create(World.render_set(app.world)) + var color = [1,1,1,1] + for(i in 0 ... 1000) { + var x = rng.int(-app.width / _star_scale, app.width / _star_scale) + var y = rng.int(-app.height / _star_scale, app.height / _star_scale) + var z = 0 + var w = rng.int(1, 4) + // var h = rng.int(1, 3) + var h = w + var a = 0 + color.a = 0.1 * w + Draw.quad(ctx, x, y, z, w, h, a, color) + } + Draw.commit(ctx) + + } //draw_starfield + + create_ship() { + + _ship = Entity.create(app.world, "ship") + Transform.create(_ship) + var ship_mat = Assets.material("material/ship") + Sprite.create(_ship, ship_mat, 16, 32) + Transform.set_pos(_ship, 0, 0) + + } //create_ship + + ////////////// + // UPDATERS // + ////////////// + + tick_ship(delta) { + + var input_vec = [get_axis("horizontal"), get_axis("vertical"), 0] + Math.normalize(input_vec) + + // 2d movement physics + _ship_acceleration_x = input_vec.x * _ship_speed + _ship_acceleration_y = input_vec.y * _ship_speed + _ship_velocity_x = _ship_velocity_x + (_ship_acceleration_x * delta) + _ship_velocity_y = _ship_velocity_y + (_ship_acceleration_y * delta) + _ship_velocity_x = _ship_velocity_x * _ship_dampening + _ship_velocity_y = _ship_velocity_y * _ship_dampening + + // rotate ship in direction of movement, if input is detected (solves snap at vel=0) + if(input_vec.x != 0 || input_vec.y != 0) { + _ship_rotation = Math.atan2(_ship_velocity_y, _ship_velocity_x) + Math.radians(90) + Transform.set_euler_world(_ship, 0, 0, _ship_rotation) + } + + // move ship + Transform.translate(_ship, _ship_velocity_x, _ship_velocity_y) + System.print("[%(Transform.get_pos_x(_ship)), %(Transform.get_pos_y(_ship))]") + + } //tick_ship + + tick_camera(delta) { + + // move the camera, with some lerp delay, along with the ship + var shipx = Transform.get_pos_x(_ship) + var shipy = Transform.get_pos_y(_ship) + var camerax = Transform.get_pos_x(app.camera) + var cameray = Transform.get_pos_y(app.camera) + var interpolation = 0.8 + var camera_interp_x = lerp(shipx - (app.width / 2 / _camera_scale), camerax, interpolation) + var camera_interp_y = lerp(shipy - (app.height / 2 / _camera_scale), cameray, interpolation) + Transform.set_pos(app.camera, camera_interp_x, camera_interp_y) + + } //tick_camera + + tick_starfield(delta) { + + } //tick_starfield + + ///////////// + // HELPERS // + ///////////// + + get_axis(axis) { + + if(axis == "horizontal") { + var xaxis = 0 + if(Input.key_state_down(Key.key_a) || Input.key_state_down(Key.left)) { + xaxis = xaxis - 1 + } + if(Input.key_state_down(Key.key_d) || Input.key_state_down(Key.right)) { + xaxis = xaxis + 1 + } + return xaxis + } + if(axis == "vertical") { + var yaxis = 0 + if(Input.key_state_down(Key.key_w) || Input.key_state_down(Key.up)) { + yaxis = yaxis - 1 + } + if(Input.key_state_down(Key.key_s) || Input.key_state_down(Key.down)) { + yaxis = yaxis + 1 + } + return yaxis + } + + } //get_axis + + lerp(a, b, t) { + + return a + t * (b - a) + + } //lerp + + destroy() { + + System.print("unready!") + app.destroy() + + } //destroy + + app { _app } + app=(v) { _app=v } + +} //Game diff --git a/image/ship.image.lx b/image/ship.image.lx new file mode 100644 index 0000000..21ef3b6 --- /dev/null +++ b/image/ship.image.lx @@ -0,0 +1,3 @@ +image = { + source = "image/ship.png" +} \ No newline at end of file diff --git a/image/ship.png b/image/ship.png new file mode 100644 index 0000000..1246241 Binary files /dev/null and b/image/ship.png differ diff --git a/material/ship.material b/material/ship.material new file mode 100644 index 0000000..766d3b0 --- /dev/null +++ b/material/ship.material @@ -0,0 +1,4 @@ +material = { + basis = "luxe: material_basis/sprite_pixelated" + samplers = { 0 = "image/ship" } +} \ No newline at end of file diff --git a/outline/app.wren b/outline/app.wren new file mode 100644 index 0000000..e03e222 --- /dev/null +++ b/outline/app.wren @@ -0,0 +1,74 @@ +import "luxe: world" for World, Camera, Entity, Transform +import "luxe: render" for Render + +class App { + + world { _world } + ui { _ui_world } + + camera { _camera } + ui_camera { _ui_camera } + + color { _color } + color=(v) { _color = v } + + width { Render.window_w() } + height { Render.window_h() } + scale { Render.drawable_ratio() } + + construct new() { + + _color = [1,1,1,1] + + //create worlds + + _world = World.create("game") + _ui_world = World.create("ui") + + //create cameras + + _camera = Entity.create(_world, "app.camera") + Transform.create(_camera) + Camera.create(_camera) + + _ui_camera = Entity.create(_ui_world, "app.ui_camera") + Transform.create(_ui_camera) + Camera.create(_ui_camera) + + } //new + + destroy() { + + //destroy cameras + + Camera.destroy(_camera) + Camera.destroy(_ui_camera) + + Entity.destroy(_camera) + Entity.destroy(_ui_camera) + + //destroy worlds + + World.destroy(_ui_world) + World.destroy(_world) + + } //destroy + + tick(delta) { + + //update worlds + + World.tick_systems(_world, delta) + World.tick_systems(_ui_world, delta) + + World.tick_world(_world, delta) + World.tick_world(_ui_world, delta) + + //render worlds + + World.render(_world, _camera, "game", {"clear_color":_color}) + World.render(_ui_world, _ui_camera, "ui") + + } //tick + +} // diff --git a/outline/inputs.input.lx b/outline/inputs.input.lx new file mode 100644 index 0000000..e5b5f9d --- /dev/null +++ b/outline/inputs.input.lx @@ -0,0 +1,6 @@ +input = { + nodes = [ + { name = "ui" where = "front" channels = ["c01"] } + { name = "game" where = "after: ui" channels = ["c02"] } + ] +} diff --git a/outline/renderer.wren b/outline/renderer.wren new file mode 100644 index 0000000..d6aac6c --- /dev/null +++ b/outline/renderer.wren @@ -0,0 +1,47 @@ +import "luxe: render" for Render, RenderLayerDesc, PassLayerDesc, LoadAction +import "luxe: render" for SortType, ImageDesc, ImageType, PixelFormat + +class Renderer { + + construct new() { + + System.print("game / render / init / ok") + + } //new + + ready() { + + } + + render_path(ctx) { + + if(ctx.path == "game") { + game_render_path(ctx) + } else if(ctx.path == "ui") { + ui_render_path(ctx) + } + + } //render_path + + game_render_path(ctx) { + + var layer = RenderLayerDesc.new() + layer.dest.color[0].clear_color = ctx.get("clear_color", [1,1,1,1]) + layer.dest.color[0].load_action = LoadAction.clear + layer.dest.depth.load_action = LoadAction.clear + + ctx.layer_render("default", layer) + + } //game_render_path + + ui_render_path(ctx) { + + var layer = RenderLayerDesc.new() + layer.dest.color[0].load_action = LoadAction.dont_care + layer.dest.depth.load_action = LoadAction.clear + + ctx.layer_render("default", layer) + + } //ui_render_path + +} //Renderer \ No newline at end of file diff --git a/outline/settings.settings.lx b/outline/settings.settings.lx new file mode 100644 index 0000000..3ce2436 --- /dev/null +++ b/outline/settings.settings.lx @@ -0,0 +1,16 @@ +engine = { + runtime = { + window = { + width = 960 + height = 640 + resizable = false + fullscreen = false + } + } + + render = { + antialiasing = 2 + stencil = 8 + depth = 24 + } +} \ No newline at end of file diff --git a/project.luxe b/project.luxe new file mode 100644 index 0000000..495be76 --- /dev/null +++ b/project.luxe @@ -0,0 +1,16 @@ +// luxe 1.0.0-dev.80 + +import "luxe: project" for Project + +class project is Project { + + construct new(target) { + + name = "space" + version = "0.0.1" + renderer = "outline/renderer" + settings = "outline/settings" + + } //new + +} //Project \ No newline at end of file