1
0
Fork 0

auts: draw some tile

This commit is contained in:
coaljoe 2020-08-20 21:16:10 +03:00
parent c8fd05407c
commit a475def9f8
9 changed files with 126 additions and 16 deletions

8
isotest/cell.v Normal file
View File

@ -0,0 +1,8 @@
module main
struct Cell {
mut:
z int
tile_id int
}

View File

@ -53,7 +53,9 @@ fn (mut d Drawer) draw_image() {
fn (mut d Drawer) draw_tex(tex voidptr, px, py int) {
if isnil(tex) {
return
println("tex is nil")
pp(2)
//return
}
texw := 0
texh := 0

View File

@ -5,11 +5,17 @@ mut:
w int
h int
cells [][]Cell
view &FieldView
ctx &Context
}
fn new_field() &Field {
fn new_field(mut ctx Context) &Field {
println("new_field()")
f := &Field{}
f := &Field{
view: &FieldView(0),
ctx: ctx,
}
return f
}
@ -30,11 +36,7 @@ fn (mut f Field) generate(w, h int) {
}
}
//
// Cell
//
struct Cell {
mut:
z int
}
fn (mut f Field) spawn() {
f.view = new_fieldview(f)
f.view.spawn()
}

79
isotest/fieldview.v Normal file
View File

@ -0,0 +1,79 @@
module main
import os
struct FieldView {
mut:
m &Field
tiles map[string]voidptr
}
fn new_fieldview(m &Field) &FieldView {
v := &FieldView{
m: m,
}
return v
}
fn (mut v FieldView) load() {
println("fieldview load()")
path := "res/images/tiles/test1"
for f in os.walk_ext(path, ".png") {
println("f: $f")
//mut name := os.file_name(f).trim_right(".png")
mut name := os.file_name(f).all_before_last(".png")
//println("z: $name")
if name.count("_") != 1 {
//idx := name.index_after(5)
name = name.all_before_last("_")
}
println("name: $name")
tex := v.m.ctx.drawer.load_image_tex(f)
v.tiles[name] = tex
//pp(2)
}
//pp(2)
}
fn (mut v FieldView) spawn() {
println("fiedview spawn()")
v.load()
}
fn (mut v FieldView) draw() {
println("fieldview draw()")
c_tile_w := 32
c_tile_h := 16
for y in 0 .. v.m.h {
for x in 0 .. v.m.w {
c := v.m.cells[x][y]
name := "tile_${c.tile_id}"
println("name: $name")
tex := v.tiles[name]
if isnil(tex) {
println("tex is nil")
pp(2)
}
px := c_tile_w * x
py := c_tile_h * y
//v.m.ctx.drawer.draw_tex(px, py, tex)
v.m.ctx.drawer.draw_tex(tex, px, py)
}
}
}

5
isotest/info.txt Normal file
View File

@ -0,0 +1,5 @@
1u h = 20px
archer h = ~40px = ~2m
wall h = ~3 archer h = ~6m
wall w = ~2 tiles

View File

@ -5,22 +5,26 @@ import time
fn main() {
println("main()")
mut f := new_field()
mut ctx := new_context()
mut f := new_field(mut ctx)
f.generate(4, 4)
f.cells[1][1].z = 100
println("z 0 0: ${f.cells[0][0].z}")
println("z 1 1: ${f.cells[1][1].z}")
println("z 1 1: ${f.cells[1][1].z}")
mut ctx := new_context()
f.cells[1][1].tile_id = 1
f.cells[2][2].tile_id = 2
mut app := new_app(mut ctx)
app.init(800, 600, "auts")
f.spawn()
//d := new_drawer(mut ctx)
mut d := ctx.drawer
@ -31,7 +35,8 @@ fn main() {
d.clear()
d.draw_tex(tex, 0, 0)
f.view.draw()
//d.draw_tex(tex, 0, 0)
app.flip()

BIN
isotest/res/images/tiles/test1/tile_0_green.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/images/tiles/test1/tile_1_red.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/images/tiles/test1/tile_2_blue.png (Stored with Git LFS) Normal file

Binary file not shown.