This commit is contained in:
Jonathan Hirz 2020-09-19 17:37:14 -07:00
parent f82f292cb7
commit 05fceff574
6 changed files with 206 additions and 30 deletions

View file

@ -1,2 +1,2 @@
time = 1600540421
time = 1600562055
version = 2

View file

@ -17,12 +17,20 @@ methods = {
create_ship = true
} //game
Game = {
ready = true
tick = true
destroy = true
lerp = true
tick_camera = true
app = true
create_starfield = true
ready = true
create_ui_text = true
create_startracker = true
tick_starfield = true
get_axis = true
tick_ship = true
create_ship = true
} //Game
} //methods
time = 1600540421
time = 1600562055
version = 1

View file

@ -24,6 +24,7 @@ bytes = [
"_art/laser.ase"
"_art/player_ship.ase"
"_art/star.ase"
"ideas.txt"
] //bytes
particles = [] //particles
unit = [] //unit

178
game.wren
View file

@ -1,11 +1,12 @@
import "luxe: game" for Ready
import "luxe: assets" for Assets
import "luxe: input" for Input, Key
import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera
import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, Text
import "luxe: render" for Material
import "luxe: math" for Math
import "luxe: draw" for Draw
import "luxe: io" for IO
import "random" for Random
import "outline/app" for App
@ -16,21 +17,42 @@ class Game is Ready {
super("ready!")
app = App.new()
app.color = [0,0,0,1]
app.color = [0.12,0,0.12,1]
System.print("render size: %(app.width) x %(app.height) @ %(app.scale)x")
// game vars
// camera
_camera_scale = 3
_cam_offset_x = (app.width / 2 / _camera_scale)
_cam_offset_y = (app.height / 2 / _camera_scale)
Camera.ortho(app.camera, 0, _cam_offset_y * 2, _cam_offset_x * 2, 0, -5, 5)
_camera_scale = 2
_cam_offset_x = (app.width / _camera_scale)
_cam_offset_y = (app.height / _camera_scale)
Camera.ortho(app.camera, 0, _cam_offset_y, _cam_offset_x, 0, -5, 5)
// starfield
_stars = []
// player ship
_input_vec = []
_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
// make things
create_ship()
Transform.set_pos(app.camera, Transform.get_pos_x(_ship) - _cam_offset_x / 2, Transform.get_pos_y(_ship) - _cam_offset_y / 2)
create_ui_text()
create_startracker()
create_starfield()
} //ready
tick(delta) {
tick_ship(delta)
tick_camera(delta)
// tick_starfield(delta)
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
@ -40,14 +62,156 @@ class Game is Ready {
// CREATORS
///////////
create_ship() {
_ship = Entity.create(app.world, "ship")
var ship_mat = Assets.material("material/ship")
Sprite.create(_ship, ship_mat, 16, 32)
Transform.create(_ship)
Transform.set_pos(_ship, app.width/2 / _camera_scale, app.height/2 / _camera_scale)
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, 20)
Text.create(_position_text, _mat_font, 32, "fonts/lato", [1,1,1,1])
} //create_ui_text
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()
var number_of_stars = 50
for(i in 0...number_of_stars) {
var randomness = rng.float(0.5)
var randomness_x = rng.float()
var randomness_y = rng.float()
_star = Entity.create(app.world, "star")
Transform.create(_star)
Transform.set_pos(_star, (app.width * randomness_x) - (app.width / 2), (app.height * randomness_y) - (app.height / 2), -1)
var star_mat = Assets.material("material/star")
Sprite.create(_star, star_mat, 8 * randomness, 8 * randomness)
Sprite.set_alpha(_star, randomness)
// Sprite.set_color(_star, 1, 1, 0, 1)
Transform.link(_star, _star_tracker)
_stars.add(_star)
}
// 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")]
Math.normalize2D(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(270)
Transform.set_euler_world(_ship, 0, 0, _ship_rotation)
}
// move ship
Transform.translate(_ship, _ship_velocity_x, _ship_velocity_y)
// update position text
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)
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 - _cam_offset_x / 2, camerax, interpolation)
var camera_interp_y = lerp(shipy - _cam_offset_y / 2, cameray, interpolation)
Transform.set_pos(app.camera, camera_interp_x, camera_interp_y)
} //tick_camera
tick_starfield(delta) {
//todo: 20191130 - found an interesting bug, where if you (while going super fast) travel out too far, and return to [0,0], the stars will be slightly misaligned. must have something to do with a floating point error while moving the stars around. Went to 25,000 out and saw a slight misalign
// to fix, can make scrolling more accurate somehow, maybe track a stars movement and see where it gets it's error. probably when having them switch sides
// another option is to restrict how far out the player can travel from [0,0], either with a hard limit, or some gameplay thing that makes them stay close to base
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) {
Transform.set_pos_x(star, Transform.get_pos_x(star) + -_ship_velocity_x * (Sprite.get_alpha(star) * 0.5))
Transform.set_pos_y(star, Transform.get_pos_y(star) + -_ship_velocity_y * (Sprite.get_alpha(star) * 0.5))
// x pos reset
if(Transform.get_pos_x(star) > _cam_offset_x * _camera_scale) {
Transform.set_pos_x(star, -_cam_offset_x * _camera_scale)
}
if(Transform.get_pos_x(star) < -_cam_offset_x * _camera_scale) {
Transform.set_pos_x(star, _cam_offset_x * _camera_scale)
}
// y pos reset
if(Transform.get_pos_y(star) > _cam_offset_y * _camera_scale) {
Transform.set_pos_y(star, -_cam_offset_y * _camera_scale)
}
if(Transform.get_pos_y(star) < -_cam_offset_y * _camera_scale) {
Transform.set_pos_y(star, _cam_offset_y * _camera_scale)
}
}
} //tick_starfield
// MISC
///////
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!")

1
ideas.txt Normal file
View file

@ -0,0 +1 @@
new idea for controls. left stick controls which direction you face, triggers used for thrust in that direction (left trig) and weapons (right trig). Have a slow drift/slow down. This allows you to have thrust in one direction, spin around and keep moving in that direction, but shoot behind you/strafe to the side.

42
log.txt
View file

@ -1,4 +1,4 @@
luxe / Engine / Sat Sep 19 11:33:41 2020
luxe / Engine / Sat Sep 19 17:34:15 2020
luxe / Engine / path is `/Users/jonathan/Developer/luxe/space`
luxe / Engine / 2020.3.0
luxe / paths / root / located at `/Users/jonathan/.luxe`
@ -13,7 +13,7 @@ luxe / dev / parcel / adding dependency `luxe` @ `2020.3.0`
luxe / dev / parcel / - adding scripts from `/Users/jonathan/.luxe/modules/luxe/2020.3.0/api`
luxe / dev / parcel / - adding assets from `/Users/jonathan/.luxe/modules/luxe/2020.3.0/assets`
luxe / dev / images / adding unreferenced sources...
luxe / dev / parcel / entry parcel generated in 13.84982001036406ms
luxe / dev / parcel / entry parcel generated in 14.66805406380445ms
luxe / dev / compiler / compiling dev content to `.luxe/` ...
luxe / dev / compiler / luxe runtime `2020.3.0` at path `/Users/jonathan/.luxe/modules/luxe/2020.3.0` ...
+ modifier - 0 found
@ -25,13 +25,14 @@ luxe / dev / compiler / luxe runtime `2020.3.0` at path `/Users/jonathan/.luxe/m
- `.luxe/entry.settings.lx` > `.luxe/.luxe/entry.settings.lx.814a19b5`
+ script - 109 found
- parsing 1 scripts and their imports ...
- parsing `game.wren` - 4.76327ms
- parsing `game.wren` - 24.07203ms
- parsing `random` - 0.00157ms
- compiling 1 scripts ...
- parsing `luxe: input` - 288.53514ms
- parsing `luxe: io` - 5.19695ms
- parsing `luxe/io` - 0.00157ms
- parsing `luxe: assets` - 46.15239ms
- compiled `game.wren` - 352.31519ms
- parsing `luxe: input` - 287.08386ms
- parsing `luxe: io` - 5.22745ms
- parsing `luxe/io` - 0.00143ms
- parsing `luxe: assets` - 46.46948ms
- compiled `game.wren` - 403.50771ms
+ render - 1 found
+ tiles - 0 found
+ font - 2 found
@ -45,17 +46,17 @@ luxe / dev / compiler / luxe runtime `2020.3.0` at path `/Users/jonathan/.luxe/m
+ mesh - 0 found
+ ui - 22 found
luxe / dev / data compile times:
- / material / spent `3.0556ms`
- / shaders / spent `5.32095ms`
- / font / spent `4.19432ms`
- / material_basis / spent `1.2656ms`
- / settings / spent `0.99964ms`
- / script / spent `396.45123ms`
- / image / spent `4.22433ms`
- / input / spent `0.59868ms`
- / render / spent `0.49942ms`
- / ui / spent `2.76114ms`
luxe / dev / compiler / compile complete | `168 assets` | `421.0298489779234ms`
- / material / spent `2.75239ms`
- / shaders / spent `5.65618ms`
- / font / spent `4.29496ms`
- / material_basis / spent `1.50831ms`
- / settings / spent `1.07576ms`
- / script / spent `467.68876ms`
- / image / spent `4.69363ms`
- / input / spent `0.89061ms`
- / render / spent `0.52276ms`
- / ui / spent `2.85538ms`
luxe / dev / compiler / compile complete | `168 assets` | `493.5020689154044ms`
luxe / project / info:
- name: `space`
- version: `0.0.1`
@ -118,6 +119,7 @@ luxe / assets / loading `entry parcel` ...
luxe / assets / loading / bytes `_art/laser.ase`
luxe / assets / loading / bytes `_art/player_ship.ase`
luxe / assets / loading / bytes `_art/star.ase`
luxe / assets / loading / bytes `ideas.txt`
luxe / assets / loading / input `outline/inputs`
luxe / assets / loading / ui `luxe: ui/editor.mini.anim.sprite.key`
luxe / assets / loading / ui `luxe: ui/editor.panel.button`
@ -141,7 +143,7 @@ luxe / assets / loading `entry parcel` ...
luxe / assets / loading / ui `luxe: ui/editor.panel.progress`
luxe / assets / loading / ui `luxe: ui/editor.panel.slider`
luxe / assets / loading / ui `luxe: ui/editor.panel.text`
luxe / assets / loaded `entry parcel` with `65 items` in `28.37803307920694ms`
luxe / assets / loaded `entry parcel` with `66 items` in `28.38667493779212ms`
luxe / runtime / setting log level `info`
luxe / assets / input / loading entry input `outline/inputs`
luxe / render / init renderer script `outline/renderer`