init
This commit is contained in:
commit
7600d281b8
15 changed files with 369 additions and 0 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*/.DS_Store
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
*/thumbs.db
|
||||
thumbs.db
|
||||
.thumbs.db?
|
||||
_luxe.data/
|
||||
_luxe.deploy/
|
||||
screenshots/
|
||||
1
.luxeignore
Normal file
1
.luxeignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
screenshots/*
|
||||
BIN
_art/player_ship.ase
Normal file
BIN
_art/player_ship.ase
Normal file
Binary file not shown.
BIN
_art/star.ase
Normal file
BIN
_art/star.ase
Normal file
Binary file not shown.
3
empty.outline.lx
Normal file
3
empty.outline.lx
Normal file
|
|
@ -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"]
|
||||
3
game.scene/game.layer
Normal file
3
game.scene/game.layer
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
layer = {
|
||||
elements = {} //elements
|
||||
} //layer
|
||||
187
game.wren
Normal file
187
game.wren
Normal file
|
|
@ -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
|
||||
3
image/ship.image.lx
Normal file
3
image/ship.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "image/ship.png"
|
||||
}
|
||||
BIN
image/ship.png
Normal file
BIN
image/ship.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 375 B |
4
material/ship.material
Normal file
4
material/ship.material
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
material = {
|
||||
basis = "luxe: material_basis/sprite_pixelated"
|
||||
samplers = { 0 = "image/ship" }
|
||||
}
|
||||
74
outline/app.wren
Normal file
74
outline/app.wren
Normal file
|
|
@ -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
|
||||
|
||||
} //
|
||||
6
outline/inputs.input.lx
Normal file
6
outline/inputs.input.lx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
input = {
|
||||
nodes = [
|
||||
{ name = "ui" where = "front" channels = ["c01"] }
|
||||
{ name = "game" where = "after: ui" channels = ["c02"] }
|
||||
]
|
||||
}
|
||||
47
outline/renderer.wren
Normal file
47
outline/renderer.wren
Normal file
|
|
@ -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
|
||||
16
outline/settings.settings.lx
Normal file
16
outline/settings.settings.lx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
engine = {
|
||||
runtime = {
|
||||
window = {
|
||||
width = 960
|
||||
height = 640
|
||||
resizable = false
|
||||
fullscreen = false
|
||||
}
|
||||
}
|
||||
|
||||
render = {
|
||||
antialiasing = 2
|
||||
stencil = 8
|
||||
depth = 24
|
||||
}
|
||||
}
|
||||
16
project.luxe
Normal file
16
project.luxe
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue