1
0
Fork 0

auts: tweaks

This commit is contained in:
coaljoe 2020-08-22 14:43:20 +03:00
parent a82dc6b068
commit 8168aa4c49
3 changed files with 19 additions and 22 deletions

View File

@ -1,9 +1,6 @@
module main
const (
c_tile_w = 32
c_tile_h = 16
c_cell_w = 32
c_cell_h = 16
)

View File

@ -80,11 +80,11 @@ fn (mut v FieldView) draw_tile_cell_pos(tile_id int, cx, cy int) {
mut shx := 0
if y % 2 != 0 {
shx = c_tile_w / 2
shx = c_cell_w / 2
}
mut px := x * c_tile_w + shx
mut py := y * c_tile_h / 2
mut px := x * c_cell_w + shx
mut py := y * c_cell_h / 2
v.draw_tile(tile_id, px, py)
}
@ -102,8 +102,8 @@ fn (mut v FieldView) draw() {
for x in 0 .. v.m.w {
c := v.m.cells[x][y]
//mut px := c_tile_w * x
//mut py := c_tile_h * y
//mut px := c_cell_w * x
//mut py := c_cell_h * y
v.draw_tile_cell_pos(c.tile_id, x, y)
//pp(2)

View File

@ -14,11 +14,11 @@ fn world_to_screen_pos(x, y int) (int, int) {
fn cell_to_screen_pos(cx, cy int) (int, int) {
pan_x := 0
pan_y := 0
tile_size_z := 0
cell_size_z := 0
cz := 0
sx := pan_x + (c_tile_w * cx) + ((cy&1) * (c_tile_w / 2))
sy := pan_y + (c_tile_h * cy / 2) - tile_size_z * cz
sx := pan_x + (c_cell_w * cx) + ((cy&1) * (c_cell_w / 2))
sy := pan_y + (c_cell_h * cy / 2) - cell_size_z * cz
return sx, sy
}
@ -47,10 +47,10 @@ fn cell_to_screen_pos2(cx, cy int) (int, int) {
fn screen_to_cell_pos(sx, sy int) (int, int) {
pan_x := 0
pan_y := 0
tile_size_z := 0
cell_size_z := 0
mut cy := (2 * (sy - pan_y)) / c_tile_h
mut cx := (sx - pan_x - ((cy&1) * (c_tile_w / 2))) / c_tile_w
mut cy := (2 * (sy - pan_y)) / c_cell_h
mut cx := (sx - pan_x - ((cy&1) * (c_cell_w / 2))) / c_cell_w
mut cz := 0
// Correction?
@ -63,15 +63,15 @@ fn screen_to_cell_pos(sx, sy int) (int, int) {
yy = sy - yy
my0 := cy
if xx <= (c_tile_w / 2) {
if yy > xx * c_tile_h/c_tile_w {
if xx <= (c_cell_w / 2) {
if yy > xx * c_cell_h/c_cell_w {
cy++
if int(cy&1) != 0 {
cx--
}
}
} else {
if yy > (c_tile_w - xx) * c_tile_h/c_tile_w {
if yy > (c_cell_w - xx) * c_cell_h/c_cell_w {
cy++
if int(cy&1) == 0 {
cx++
@ -121,7 +121,7 @@ fn screen_to_cell_pos3(sx, sy int) (int, int) {
//mut y := f32(sy) * 2.0 / f32(c_cell_h)
mut x := f32(0.0)
y = (2 * (sy)) / c_tile_h
y = (2 * (sy)) / c_cell_h
if int(y) % 2 == 0 {
x = f32(sx) / f32(c_cell_w)
@ -141,11 +141,11 @@ fn screen_to_cell_pos3(sx, sy int) (int, int) {
fn mouse_to_cell_pos(mx, my int) (int, int) {
// https://gamedev.stackexchange.com/questions/45103/staggered-isometric-map-calculate-map-coordinates-for-point-on-screen
px := f32(mx) - (c_tile_w / 2.0)
py := f32(my) - (c_tile_h / 2.0)
px := f32(mx) - (c_cell_w / 2.0)
py := f32(my) - (c_cell_h / 2.0)
x := math.floor((px + (py - (c_tile_h / 2.0)) * 2.0) / c_tile_w)
y := math.floor((py - (px - (c_tile_w / 2.0)) * 0.5) / c_tile_h)
x := math.floor((px + (py - (c_cell_h / 2.0)) * 2.0) / c_cell_w)
y := math.floor((py - (px - (c_cell_w / 2.0)) * 0.5) / c_cell_h)
tx := math.floor((x - y) / 2.0) + 1.0 //+ this.camera.x;