This commit is contained in:
Jonathan Hirz 2019-11-01 21:42:10 -07:00
parent ae7d1ffffa
commit 7b084e0d2c
4 changed files with 23 additions and 27 deletions

Binary file not shown.

View file

@ -22,7 +22,7 @@ class game is Game {
// game vars
// camera
_camera_scale = 1.5
_camera_scale = 2
_cam_offset_x = (app.width / 2 / _camera_scale)
_cam_offset_y = (app.height / 2 / _camera_scale)
@ -50,66 +50,70 @@ class game is Game {
// NOTES
// z-layers: -1 stars, 0 player ship
// camera stuff: we're moving the ship in the world, based on input. then, moving the camera,
// with lerp, based on where the ship goes. then, moving star_tracker to the camera position,
// with offset. positions and offsets react to _camera_scale
} //ready
tick(delta) {
tick_ship(delta)
tick_camera(delta)
tick_starfield(delta)
something_else()
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
}
app.tick(delta)
} //tick
//////////////
// CREATORS //
//////////////
create_ship() {
something_else() {
//nothing
}
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
create_ui_text() {
_position_text = Entity.create(app.ui)
_mat_font = Assets.material("luxe: material/font")
Transform.create(_position_text)
Transform.set_pos(_position_text, app.width / 2 - 35, app.height - 50)
Text.create(_position_text, _mat_font, 32, "fonts/lato", [1,1,1,1])
} //create_ui_text
create_asteroid(x, y) {
_asteroid = Entity.create(app.world, "asteroid")
Transform.create(_asteroid)
var asteroid_mat = Assets.material("material/asteroid")
Sprite.create(_asteroid, asteroid_mat, 32, 32)
Transform.set_pos(_asteroid, x, y)
} //create_asteroid
create_startracker() {
_star_tracker = Entity.create(app.world, "star_tracker")
Transform.create(_star_tracker)
Transform.set_pos(_star_tracker, Transform.get_pos_x(_ship), Transform.get_pos_y(_ship), Transform.get_pos_z(_ship))
} //create_startracker
create_starfield() {
// sometimes you come back to some code and don't remember exactly how it all works
// that's ok, just trust that past you figured this out, and it works how you want it to
// hopefully you can figure it out later if needed
//
// this makes the starfield background, with randomness applied to the position, size, and set_alpha
// of each star. stars are parented to _star_tracker, which follows the player around
// put a value in the new() call to make the same starfield each time
var rng = Random.new()
@ -131,16 +135,15 @@ class game is Game {
}
// debug red star
// Sprite.set_color(_stars[1], 1, 0, 0, 1)
}
} //create_starfield
//////////////
// UPDATERS //
//////////////
tick_ship(delta) {
var input_vec = [get_axis("horizontal"), get_axis("vertical"), 0]
Math.normalize(input_vec)
var input_vec = [get_axis("horizontal"), get_axis("vertical")]
Math.normalize2D(input_vec)
// 2d movement physics
_ship_acceleration_x = input_vec.x * _ship_speed
@ -163,11 +166,9 @@ class game is Game {
var ship_pos_x_int = Math.floor_around_zero(Transform.get_pos_x(_ship))
var ship_pos_y_int = Math.floor_around_zero(Transform.get_pos_y(_ship))
Text.set_text(_position_text, "[%(ship_pos_x_int), %(ship_pos_y_int)]")
} //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)
@ -177,11 +178,9 @@ class game is Game {
var camera_interp_x = lerp(shipx - _cam_offset_x, camerax, interpolation)
var camera_interp_y = lerp(shipy - _cam_offset_y, cameray, interpolation)
Transform.set_pos(app.camera, camera_interp_x, camera_interp_y)
} //tick_camera
tick_starfield(delta) {
Transform.set_pos(_star_tracker, Transform.get_pos_x(app.camera) + _cam_offset_x, Transform.get_pos_y(app.camera) + _cam_offset_y, -1)
// loop through stars[]
for(star in _stars) {
@ -204,7 +203,6 @@ class game is Game {
Transform.set_pos_y(star, _cam_offset_y * _camera_scale)
}
}
} //tick_starfield
/////////////
@ -212,7 +210,6 @@ class game is Game {
/////////////
get_axis(axis) {
if(axis == "horizontal") {
var xaxis = 0
if(Input.key_state_down(Key.key_a) || Input.key_state_down(Key.left)) {
@ -233,20 +230,15 @@ class game is Game {
}
return yaxis
}
} //get_axis
lerp(a, b, t) {
return a + t * (b - a)
} //lerp
destroy() {
System.print("unready!")
app.destroy()
} //destroy
app { _app }

View file

@ -13,6 +13,10 @@ class Renderer {
}
tick(delta) {
}
render_path(ctx) {
if(ctx.path == "game") {

View file

@ -1,4 +1,4 @@
// luxe 1.0.0-dev.81
// luxe 1.0.0-dev.83
import "luxe: project" for Project