starting camera/star work
This commit is contained in:
parent
df976707ca
commit
79fd47c342
4 changed files with 40 additions and 53 deletions
86
game.wren
86
game.wren
|
|
@ -3,7 +3,7 @@ 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: draw" for Draw, PathStyle
|
||||
import "luxe: io" for IO
|
||||
import "random" for Random
|
||||
// import "luxe: array" for Lists
|
||||
|
|
@ -22,14 +22,14 @@ class game is Game {
|
|||
|
||||
// game vars
|
||||
// camera
|
||||
_camera_scale = 1.5
|
||||
_camera_scale = 1
|
||||
|
||||
// starfield
|
||||
_star_scale = 2
|
||||
_stars = []
|
||||
_stars2 = []
|
||||
|
||||
// player ship
|
||||
_input_vec = []
|
||||
_ship_rotation = 0
|
||||
_ship_speed = 40
|
||||
_ship_acceleration_x = 0
|
||||
|
|
@ -41,8 +41,9 @@ class game is Game {
|
|||
Camera.ortho(app.camera, 0, 0, app.width / _camera_scale, app.height / _camera_scale, -5, 5)
|
||||
|
||||
create_ship()
|
||||
create_asteroid(5, 10)
|
||||
create_startracker()
|
||||
draw_starfield_2()
|
||||
draw_starfield()
|
||||
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))
|
||||
|
||||
// NOTES
|
||||
|
|
@ -78,6 +79,16 @@ class game is Game {
|
|||
|
||||
} //create_ship
|
||||
|
||||
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")
|
||||
|
|
@ -86,57 +97,26 @@ class game is Game {
|
|||
|
||||
} //create_startracker
|
||||
|
||||
// draw_starfield() {
|
||||
draw_starfield() {
|
||||
|
||||
// //todo: understand this starfield, expand it, make it move.
|
||||
// //todo: for now, just generate a very large starfield. Do something at the "edge of space"]
|
||||
// var rng = Random.new(25)
|
||||
// var ctx = Draw.create(World.render_set(app.world))
|
||||
// var color = [1,1,1,1]
|
||||
// for(i in 0 ... 100000) {
|
||||
// var x = rng.int(-app.width / _star_scale * 10, app.width / _star_scale * 10)
|
||||
// var y = rng.int(-app.height / _star_scale * 10, app.height / _star_scale * 10)
|
||||
// var z = -1
|
||||
// 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
|
||||
|
||||
draw_starfield_2() {
|
||||
|
||||
//try to do this again, making sprites/entities for each star, and attach to player ship transform
|
||||
//Transform.set_pos(x, y, -1)
|
||||
var rng = Random.new()
|
||||
var number_of_stars = 1000
|
||||
var star_spread = 1000
|
||||
|
||||
|
||||
for(i in 0 ... 1000) {
|
||||
for(i in 0...number_of_stars) {
|
||||
var randomness = rng.float()
|
||||
var randomness_x = rng.float()
|
||||
var randomness_y = rng.float()
|
||||
_star = Entity.create(app.world, "star")
|
||||
Transform.create(_star)
|
||||
Transform.set_pos(_star, rng.int(-star_spread, star_spread), rng.int(-star_spread, star_spread), -1)
|
||||
Transform.set_pos(_star, (star_spread * randomness_x) - (star_spread / 2), (star_spread * randomness_y) - (star_spread / 2), -1)
|
||||
var star_mat = Assets.material("material/star")
|
||||
Sprite.create(_star, star_mat, 8, 8)
|
||||
Sprite.create(_star, star_mat, 8 * randomness, 8 * randomness)
|
||||
Sprite.set_alpha(_star, randomness * 0.8)
|
||||
Transform.link(_star, _star_tracker)
|
||||
_stars.add(_star)
|
||||
}
|
||||
|
||||
for(i in 0 ... 1000) {
|
||||
_star = Entity.create(app.world, "star")
|
||||
Transform.create(_star)
|
||||
Transform.set_pos(_star, rng.int(-star_spread, star_spread), rng.int(-star_spread, star_spread), -1)
|
||||
var star_mat = Assets.material("material/star")
|
||||
Sprite.create(_star, star_mat, 4, 4)
|
||||
Transform.link(_star, _star_tracker)
|
||||
_stars2.add(_star)
|
||||
}
|
||||
|
||||
} //draw_starfield_2
|
||||
}
|
||||
|
||||
//////////////
|
||||
// UPDATERS //
|
||||
|
|
@ -163,7 +143,6 @@ class game is Game {
|
|||
|
||||
// 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
|
||||
|
||||
|
|
@ -183,14 +162,15 @@ class game is Game {
|
|||
|
||||
tick_starfield(delta) {
|
||||
|
||||
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(app.camera), Transform.get_pos_y(app.camera), -1)
|
||||
for(star in _stars) {
|
||||
Transform.set_pos_x(star, Transform.get_pos_x(star) + -_ship_velocity_x)
|
||||
Transform.set_pos_y(star, Transform.get_pos_y(star) + -_ship_velocity_y)
|
||||
}
|
||||
for(star in _stars2) {
|
||||
Transform.set_pos_x(star, Transform.get_pos_x(star) + -_ship_velocity_x * 0.9)
|
||||
Transform.set_pos_y(star, Transform.get_pos_y(star) + -_ship_velocity_y * 0.9)
|
||||
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
|
||||
if(Transform.get_pos_x(star) > Transform.get_pos_x(_star_tracker) + (app.width / 2 / _camera_scale)) {
|
||||
// Transform.set_pos_x(star, Transform.get_pos_x(_star_tracker) - (app.width / 2 / _camera_scale))
|
||||
}
|
||||
}
|
||||
|
||||
} //tick_starfield
|
||||
|
|
|
|||
3
image/asteroid.image.lx
Normal file
3
image/asteroid.image.lx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
image = {
|
||||
source = "image/asteroid.png"
|
||||
}
|
||||
BIN
image/asteroid.png
Normal file
BIN
image/asteroid.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 111 B |
4
material/asteroid.material
Normal file
4
material/asteroid.material
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
material = {
|
||||
basis = "luxe: material_basis/sprite_pixelated"
|
||||
samplers = { 0 = "image/asteroid" }
|
||||
}
|
||||
Loading…
Reference in a new issue