added position text
This commit is contained in:
parent
376331fe37
commit
ae7d1ffffa
2 changed files with 24 additions and 6 deletions
28
game.wren
28
game.wren
|
|
@ -1,7 +1,7 @@
|
|||
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: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, Text
|
||||
import "luxe: math" for Math
|
||||
import "luxe: draw" for Draw, PathStyle
|
||||
import "luxe: io" for IO
|
||||
|
|
@ -22,7 +22,7 @@ class game is Game {
|
|||
|
||||
// game vars
|
||||
// camera
|
||||
_camera_scale = 1
|
||||
_camera_scale = 1.5
|
||||
_cam_offset_x = (app.width / 2 / _camera_scale)
|
||||
_cam_offset_y = (app.height / 2 / _camera_scale)
|
||||
|
||||
|
|
@ -42,9 +42,10 @@ class game is Game {
|
|||
Camera.ortho(app.camera, 0, 0, app.width / _camera_scale, app.height / _camera_scale, -5, 5)
|
||||
|
||||
create_ship()
|
||||
create_ui_text()
|
||||
create_asteroid(5, 10)
|
||||
create_startracker()
|
||||
draw_starfield()
|
||||
create_starfield()
|
||||
Transform.set_pos(app.camera, Transform.get_pos_x(_ship) - _cam_offset_x, Transform.get_pos_y(_ship) - _cam_offset_y)
|
||||
|
||||
// NOTES
|
||||
|
|
@ -80,6 +81,16 @@ class game is Game {
|
|||
|
||||
} //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")
|
||||
|
|
@ -98,10 +109,11 @@ class game is Game {
|
|||
|
||||
} //create_startracker
|
||||
|
||||
draw_starfield() {
|
||||
create_starfield() {
|
||||
|
||||
// put a value in the new() call to make the same starfield each time
|
||||
var rng = Random.new()
|
||||
var number_of_stars = 1000
|
||||
var number_of_stars = 500
|
||||
|
||||
for(i in 0...number_of_stars) {
|
||||
var randomness = rng.float(0.5)
|
||||
|
|
@ -113,6 +125,7 @@ class game is Game {
|
|||
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)
|
||||
}
|
||||
|
|
@ -146,6 +159,11 @@ class game is Game {
|
|||
// 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) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// luxe 1.0.0-dev.80
|
||||
// luxe 1.0.0-dev.81
|
||||
|
||||
import "luxe: project" for Project
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue