From 7600d281b8ec93944dae992eaa50eca34ed7193d Mon Sep 17 00:00:00 2001 From: Jonathan Hirz Date: Sat, 19 Jan 2019 22:50:00 -0800 Subject: [PATCH] init --- .gitignore | 9 ++ .luxeignore | 1 + _art/player_ship.ase | Bin 0 -> 1082 bytes _art/star.ase | Bin 0 -> 562 bytes empty.outline.lx | 3 + game.scene/game.layer | 3 + game.wren | 187 +++++++++++++++++++++++++++++++++++ image/ship.image.lx | 3 + image/ship.png | Bin 0 -> 375 bytes material/ship.material | 4 + outline/app.wren | 74 ++++++++++++++ outline/inputs.input.lx | 6 ++ outline/renderer.wren | 47 +++++++++ outline/settings.settings.lx | 16 +++ project.luxe | 16 +++ 15 files changed, 369 insertions(+) create mode 100644 .gitignore create mode 100644 .luxeignore create mode 100644 _art/player_ship.ase create mode 100644 _art/star.ase create mode 100644 empty.outline.lx create mode 100644 game.scene/game.layer create mode 100644 game.wren create mode 100644 image/ship.image.lx create mode 100644 image/ship.png create mode 100644 material/ship.material create mode 100644 outline/app.wren create mode 100644 outline/inputs.input.lx create mode 100644 outline/renderer.wren create mode 100644 outline/settings.settings.lx create mode 100644 project.luxe 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 0000000000000000000000000000000000000000..936802fe5d1c210a6d4ef1ba681c4af2174b3d10 GIT binary patch literal 1082 zcmcJNeN4=89LK-q=wYloS<2G=QpjUn9xw4*Hz{g6+SD2f$+@gc=Mr>;ExbZx?^8V|V%Oq}aCT8_k+MH|-)-wtgM+r73h*g(W>LAwT4-Bv~n% zx9?nf$|0kvyKEs{DV^;vrY|K1b`Bpen_->QX|U9Wt*jBMzr;7PT)F3co+WFpXELh# z&#ChLFQZ!P0zXOpDr8|QCt74Es7aN`*RlIKRfQT!+`UmZOuF6gOx-Jt&TeUs^rCT! z);X;%0%LLBaOP!W>=zF0Dmf^OALD`b4C^g^|B;UWSeMh!b+u6JOiA7~1K&NF<-N*b zhfHvi-H^2;|Ll{AIjZ8`wRwf5bs8%=BgaB(FDD;2*I6qZs~3#9#gV^-bksTR}u(W3y?d&7gRs$+Mj5atqDc z-8!PyF_Q|Lw7l~PAJq<(sdKGw3iZ7{Z+a>;MVeGQ>}$1PBH)MFNH@Gmx4_~~0zRH@!uRJ6xbZLuof89g zuBBiw*#^VGW@uUgXxr1!h%UjA)E$iHH5|LRhv(NHP%|R=!(+I-umY2g1BWAFIMbVf z2c`*&LveUHUx3+MKg>)T+F>tV_YJ$7V-xIveA)@8nq+#3rIbt>38aoRx`?8P9JfVl zDoDVO95Y&+2(h8^xh7Q(zlQ{=l2B}JVoLdKE-F;%k>>N4#{B_ix8l*BMb;mXSY?B3 YTcO&~nnKt9`s(Xhp)O}h<4bz?6H9-V-v9sr literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..1246241781788ac975ec58220c7ceaa805d3b61c GIT binary patch literal 375 zcmV--0f_#IP)1pw7==HFq<6?9LN5@oXJ4R@p_J^QCrE~l84O-J_y#3&pwz_B-FUVkbD#uGxkDCp zv5nP8B7;MgJ`ntRJiY(vw+wEmdRgJQ4wq#KKoA60?Vu@q-*rHF=)%x>&S(k9wN3*^JNe zx90wGdIB)=S(a%Atx*@#=@fwdes4Xi%~cAabrn*2E?zT`La6ckv*vz! z`vSnkHzpVFU^Gt{&6A6$HvaxEQG*mhowrMM-Y!*la5ldG1WmWUU0i(s3I1^h`~u}= Vh}aj{VPgOQ002ovPDHLkV1o8eq^$q| literal 0 HcmV?d00001 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