1
0
Fork 0

auts: sprite rendering test

This commit is contained in:
coaljoe 2020-08-22 21:29:33 +03:00
parent 9c4a9ade7d
commit 96560a64e1
4 changed files with 89 additions and 0 deletions

View File

@ -56,6 +56,21 @@ fn main() {
tex := d.load_image_sdl_tex("res/images/heightmap.png")
// Sprite test
mut spr1 := new_sprite()
spr1.load("res/objects/walls/wall1/image_0.png")
{
// Position sprite
px := 8
py := 8
// Center at tile
spr1.x = (px * c_cell_w) + c_cell_w / 2
spr1.y = (py * (c_cell_h / 2)) + c_cell_h / 2
}
//ctx.vars.scroll_speed = 0
ctx.vars.mouse_scroll = false
@ -84,6 +99,8 @@ fn main() {
//d.draw_sdl_tex(tex, px, py)
spr1.draw()
app.flip()
//time.sleep_ms(20)

BIN
isotest/res/objects/walls/wall1/image_0.png (Stored with Git LFS) Normal file

Binary file not shown.

65
isotest/sprite.v Normal file
View File

@ -0,0 +1,65 @@
module main
struct Sprite {
mut:
// Pos (world-space)
x int
y int
w int
h int
// Multi-tile
num_tiles_x int
num_tiles_y int
num_tiles int
tile_size int
shift_x int
// yCorr
shift_y int
tex &Texture
spawned bool
}
fn new_sprite() &Sprite {
s := &Sprite{
}
return s
}
fn (mut s Sprite) load(path string) {
s.tex = new_texture()
s.tex.load(path)
s.w, s.h = s.tex.size()
// Calc shift
s.shift_x = s.w / 2 // half tile
//s.shift_y = s.h - (c_cell_h)
s.shift_y = s.h - (c_cell_h / 2)
}
fn (mut s Sprite) spawn() {
}
fn (mut s Sprite) draw() {
println("sprite draw()")
//s.tex.draw_pos(s.x, s.y)
px := s.x - s.shift_x
py := s.y - s.shift_y
s.tex.draw_pos(px, py)
}
fn (mut s Sprite) update(dt f32) {
}

View File

@ -19,6 +19,10 @@ fn new_texture() &Texture {
return t
}
fn (mut t Texture) size() (int, int) {
return t.w, t.h
}
fn (mut t Texture) load(path string) {
println("texture load() path: $path")