ello
This commit is contained in:
parent
ae7d1ffffa
commit
7b084e0d2c
4 changed files with 23 additions and 27 deletions
Binary file not shown.
44
game.wren
44
game.wren
|
|
@ -22,7 +22,7 @@ class game is Game {
|
||||||
|
|
||||||
// game vars
|
// game vars
|
||||||
// camera
|
// camera
|
||||||
_camera_scale = 1.5
|
_camera_scale = 2
|
||||||
_cam_offset_x = (app.width / 2 / _camera_scale)
|
_cam_offset_x = (app.width / 2 / _camera_scale)
|
||||||
_cam_offset_y = (app.height / 2 / _camera_scale)
|
_cam_offset_y = (app.height / 2 / _camera_scale)
|
||||||
|
|
||||||
|
|
@ -50,66 +50,70 @@ class game is Game {
|
||||||
|
|
||||||
// NOTES
|
// NOTES
|
||||||
// z-layers: -1 stars, 0 player ship
|
// 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
|
} //ready
|
||||||
|
|
||||||
tick(delta) {
|
tick(delta) {
|
||||||
|
|
||||||
tick_ship(delta)
|
tick_ship(delta)
|
||||||
tick_camera(delta)
|
tick_camera(delta)
|
||||||
tick_starfield(delta)
|
tick_starfield(delta)
|
||||||
|
something_else()
|
||||||
|
|
||||||
if(Input.key_state_released(Key.escape)) {
|
if(Input.key_state_released(Key.escape)) {
|
||||||
IO.shutdown()
|
IO.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
app.tick(delta)
|
app.tick(delta)
|
||||||
|
|
||||||
} //tick
|
} //tick
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// CREATORS //
|
// CREATORS //
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
create_ship() {
|
something_else() {
|
||||||
|
//nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
create_ship() {
|
||||||
_ship = Entity.create(app.world, "ship")
|
_ship = Entity.create(app.world, "ship")
|
||||||
Transform.create(_ship)
|
Transform.create(_ship)
|
||||||
var ship_mat = Assets.material("material/ship")
|
var ship_mat = Assets.material("material/ship")
|
||||||
Sprite.create(_ship, ship_mat, 16, 32)
|
Sprite.create(_ship, ship_mat, 16, 32)
|
||||||
Transform.set_pos(_ship, 0, 0)
|
Transform.set_pos(_ship, 0, 0)
|
||||||
|
|
||||||
} //create_ship
|
} //create_ship
|
||||||
|
|
||||||
create_ui_text() {
|
create_ui_text() {
|
||||||
|
|
||||||
_position_text = Entity.create(app.ui)
|
_position_text = Entity.create(app.ui)
|
||||||
_mat_font = Assets.material("luxe: material/font")
|
_mat_font = Assets.material("luxe: material/font")
|
||||||
Transform.create(_position_text)
|
Transform.create(_position_text)
|
||||||
Transform.set_pos(_position_text, app.width / 2 - 35, app.height - 50)
|
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])
|
Text.create(_position_text, _mat_font, 32, "fonts/lato", [1,1,1,1])
|
||||||
|
|
||||||
} //create_ui_text
|
} //create_ui_text
|
||||||
|
|
||||||
create_asteroid(x, y) {
|
create_asteroid(x, y) {
|
||||||
|
|
||||||
_asteroid = Entity.create(app.world, "asteroid")
|
_asteroid = Entity.create(app.world, "asteroid")
|
||||||
Transform.create(_asteroid)
|
Transform.create(_asteroid)
|
||||||
var asteroid_mat = Assets.material("material/asteroid")
|
var asteroid_mat = Assets.material("material/asteroid")
|
||||||
Sprite.create(_asteroid, asteroid_mat, 32, 32)
|
Sprite.create(_asteroid, asteroid_mat, 32, 32)
|
||||||
Transform.set_pos(_asteroid, x, y)
|
Transform.set_pos(_asteroid, x, y)
|
||||||
|
|
||||||
} //create_asteroid
|
} //create_asteroid
|
||||||
|
|
||||||
create_startracker() {
|
create_startracker() {
|
||||||
|
|
||||||
_star_tracker = Entity.create(app.world, "star_tracker")
|
_star_tracker = Entity.create(app.world, "star_tracker")
|
||||||
Transform.create(_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))
|
Transform.set_pos(_star_tracker, Transform.get_pos_x(_ship), Transform.get_pos_y(_ship), Transform.get_pos_z(_ship))
|
||||||
|
|
||||||
} //create_startracker
|
} //create_startracker
|
||||||
|
|
||||||
create_starfield() {
|
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
|
// put a value in the new() call to make the same starfield each time
|
||||||
var rng = Random.new()
|
var rng = Random.new()
|
||||||
|
|
@ -131,16 +135,15 @@ class game is Game {
|
||||||
}
|
}
|
||||||
// debug red star
|
// debug red star
|
||||||
// Sprite.set_color(_stars[1], 1, 0, 0, 1)
|
// Sprite.set_color(_stars[1], 1, 0, 0, 1)
|
||||||
}
|
} //create_starfield
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// UPDATERS //
|
// UPDATERS //
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
tick_ship(delta) {
|
tick_ship(delta) {
|
||||||
|
var input_vec = [get_axis("horizontal"), get_axis("vertical")]
|
||||||
var input_vec = [get_axis("horizontal"), get_axis("vertical"), 0]
|
Math.normalize2D(input_vec)
|
||||||
Math.normalize(input_vec)
|
|
||||||
|
|
||||||
// 2d movement physics
|
// 2d movement physics
|
||||||
_ship_acceleration_x = input_vec.x * _ship_speed
|
_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_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))
|
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)]")
|
Text.set_text(_position_text, "[%(ship_pos_x_int), %(ship_pos_y_int)]")
|
||||||
|
|
||||||
} //tick_ship
|
} //tick_ship
|
||||||
|
|
||||||
tick_camera(delta) {
|
tick_camera(delta) {
|
||||||
|
|
||||||
// move the camera, with some lerp delay, along with the ship
|
// move the camera, with some lerp delay, along with the ship
|
||||||
var shipx = Transform.get_pos_x(_ship)
|
var shipx = Transform.get_pos_x(_ship)
|
||||||
var shipy = Transform.get_pos_y(_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_x = lerp(shipx - _cam_offset_x, camerax, interpolation)
|
||||||
var camera_interp_y = lerp(shipy - _cam_offset_y, cameray, interpolation)
|
var camera_interp_y = lerp(shipy - _cam_offset_y, cameray, interpolation)
|
||||||
Transform.set_pos(app.camera, camera_interp_x, camera_interp_y)
|
Transform.set_pos(app.camera, camera_interp_x, camera_interp_y)
|
||||||
|
|
||||||
} //tick_camera
|
} //tick_camera
|
||||||
|
|
||||||
tick_starfield(delta) {
|
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)
|
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[]
|
// loop through stars[]
|
||||||
for(star in _stars) {
|
for(star in _stars) {
|
||||||
|
|
@ -204,7 +203,6 @@ class game is Game {
|
||||||
Transform.set_pos_y(star, _cam_offset_y * _camera_scale)
|
Transform.set_pos_y(star, _cam_offset_y * _camera_scale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} //tick_starfield
|
} //tick_starfield
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
|
|
@ -212,7 +210,6 @@ class game is Game {
|
||||||
/////////////
|
/////////////
|
||||||
|
|
||||||
get_axis(axis) {
|
get_axis(axis) {
|
||||||
|
|
||||||
if(axis == "horizontal") {
|
if(axis == "horizontal") {
|
||||||
var xaxis = 0
|
var xaxis = 0
|
||||||
if(Input.key_state_down(Key.key_a) || Input.key_state_down(Key.left)) {
|
if(Input.key_state_down(Key.key_a) || Input.key_state_down(Key.left)) {
|
||||||
|
|
@ -233,20 +230,15 @@ class game is Game {
|
||||||
}
|
}
|
||||||
return yaxis
|
return yaxis
|
||||||
}
|
}
|
||||||
|
|
||||||
} //get_axis
|
} //get_axis
|
||||||
|
|
||||||
lerp(a, b, t) {
|
lerp(a, b, t) {
|
||||||
|
|
||||||
return a + t * (b - a)
|
return a + t * (b - a)
|
||||||
|
|
||||||
} //lerp
|
} //lerp
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
|
||||||
System.print("unready!")
|
System.print("unready!")
|
||||||
app.destroy()
|
app.destroy()
|
||||||
|
|
||||||
} //destroy
|
} //destroy
|
||||||
|
|
||||||
app { _app }
|
app { _app }
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ class Renderer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tick(delta) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render_path(ctx) {
|
render_path(ctx) {
|
||||||
|
|
||||||
if(ctx.path == "game") {
|
if(ctx.path == "game") {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// luxe 1.0.0-dev.81
|
// luxe 1.0.0-dev.83
|
||||||
|
|
||||||
import "luxe: project" for Project
|
import "luxe: project" for Project
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue