forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   2D-программирование (http://forum.boolean.name/forumdisplay.php?f=13)
-   -   Вопрос .Сново гексы (http://forum.boolean.name/showthread.php?t=16973)

polopok 26.06.2012 21:05

Вопрос .Сново гексы
 
Чего-то не получается правильно выдать ячейки при наведении мыши.
Правильно выводятся только через один столбец
помогите пожалуйста :''((
код:
Код:

        Local  d      = 40
        Const  tilex  = 4
        Const  tiley  = 4       

Graphics 640,480

;gex = LoadImage ("D:\vitalii\blitz\hex3.png") :MaskImage gex,255,255,255
gex = CreateImage(41,41)
SetBuffer ImageBuffer(gex)
Color 200,50,50
Line 0,20, 10,0
Line 10,0, 30,0
Line 30,0,40,20
Line 40,20 ,30,40
Line 30,40,10,40
Line 10,40,0,20
Color 255,255,255
SetBuffer BackBuffer()

s=h/Cos(30*Pi/180)/2

               
While Not KeyHit(1)
Cls
mx = MouseX() : my = MouseY()
                For j=0 To tiley
                        For i=0 To tilex

                                                        x =  i*d*1.5+(j Mod 2)*30
                                                        y = j*d*0.5
                                                                                       
                                DrawImage gex, x , y
                        Text x+10,y+5,"i= "+i
                        Text x+10,y+15,"j= "+j
;                        Color 50,50,55
;                        Rect x,y,40,40,0
;                        Color 255,255,255
                              Next
                Next
                x2=mx/d/1.5 - (y2 Mod 2)/30  ;Проблема видимо тут
                y2=my/d/0.5;
               
                ;y2=(my-(x2 Mod 2)*s)/h                       
                ;Oval x2-3,y2-3,6,6,1
Text 30 ,200 , "i - "+ x2+ "  j - "+y2
Text 30 ,220 ,"(y2 Mod 2) = "+(my Mod 2)
Flip ; Меняем буфер
Wend
End



Кстати , основывался на эту статью:
http://www.dionaholding.ru/news/arti...g_flash/tbg_25
правда там тоже реализация мыши не ахти

polopok 28.06.2012 20:24

Ответ: Вопрос .Сново гексы
 
Итак , ввиду того , что никто ничего не предложил ...
После долгих мучений и перелопачивания инета ,сваял нечто своё.
Увы у меня так и не получилось точного определения гекса формулами
может кто поможет в правильном определении ?

Код:


Graphics 800,600,32,2
fntArial=LoadFont("Arial",16)
SetFont fntArial

w = 40
h = 40
m = 20
tilex =8
tiley = 6
;gex = LoadImage ("hex3.png") :MaskImage gex,255,255,255
gex = CreateImage(41,41)
SetBuffer ImageBuffer(gex)
Color 200,50,50
Line 0,20, 10,0
Line 10,0, 30,0
Line 30,0,40,20
Line 40,20 ,30,40
Line 30,40,10,40
Line 10,40,0,20
Color 255,255,255

gex_activ=CreateImage(41,41)
SetBuffer ImageBuffer(gex_activ)
L1= 10 :L2= 30
        Color 200,78,0
        For ww= 1 To 20 Step 2
                Line L1,ww,L2,ww
                L1= L1-1 :L2= L2+1
        Next
        For ww= 20 To 40 Step 2
                Line L1,ww,L2,ww
                L1= L1+1 :L2= L2-1
        Next
SetBuffer BackBuffer()

While Not KeyHit(1)
ClsColor 110,110,112
Cls
        If KeyHit(2) Then a = a +1 : a = a Mod 3
mx# = MouseX() : my# = MouseY()
;mxs = MouseXSpeed() : mys = MouseYSpeed()
If KeyDown(200) Then n# = n# + 0.01 ;And  n# < 3
If KeyDown(208) Then n# = n# - 0.01 :If n# <=0.01Then n# = 0.01
                For j=0 To tiley
                        For i=0 To tilex
                                x = i * w/4*3
                                y = j * h +(i Mod 2)*h*0.5
                               
                        If a = 0 Then
                                DrawImage gex, x , y
                                Text x+15 , y+15 ,I+","+j
                                        visual$ = " гексагонами "
                        Else If a = 1
                                Color 100,100,100
                                Rect x , y , w , h , 0
                                Color 255,255,255
                                Text x +5 , y +5 ,I+","+j
                                        visual$ = " квадратами "
                        Else If a = 2
                                Line x , y , x , y + h
                                Line x , y , x +w , y
                                        visual$ = " линиями "
                        End If
                                                               
                              Next
                Next
                sx# = Floor (mx#/w * 4/3) 
                sy# = Floor ( my#/h - (sx Mod 2)/2);/h/0.5
                sxx = Int (sx#)
                syy = Int (sy#)
               
                        xx = sxx * w/4*3
                        yy = syy * h +(sxx Mod 2)*h*0.5

        Color 0,0,255
        Text xx - 5, yy - 5 ,"*"
        DrawImage gex_activ , xx , yy
        Color 255,255,255
       
Text 500 ,185 ," Вычисления :"       
Text 500 ,200 ,mx# +" / "+w+" * "+4/3+" = "+sx+"    :i"
Text 500 ,215 ,my# +" / "+h+" - "+ (sx Mod 2)/2+" = "+sy+"    :j"
Text 400 ,40 ,"Положение мышы в сетке : U : "+sxx+"  V :"+syy
Text 400 ,55 ,"Координаты мышы в сетке : UX : "+xx+"  VY :"+yy
Text 400 ,10 ,"Клавиша 1 меняет виды сетки  "
Text 400 ,25 ,"Вид : "+visual$
Flip ; Меняем буфер
Wend
FreeFont fntArial
End


polopok 29.06.2012 19:26

Ответ: Вопрос .Сново гексы
 
Ура !:wild: свершилось ... чисто случайно нашёл параметр .
Теперь всё работает . Хотя и есть небольшая погрешность ,но ею можно пренебречь ,настолько она незначительна .
Вот код: (нажать offtop) :)
Код:


Graphics 800,600,32,2
fntArial=LoadFont("Arial",16)
SetFont fntArial

w = 40
h = 20
tilex =8
tiley = 6
;gex = LoadImage ("hex3.png") :MaskImage gex,255,255,255
gex = CreateImage(w+1,h+1)
SetBuffer ImageBuffer(gex)
Color 238,118,0
Line 0,h/2                ,w/4,0
Line w/4,0        ,w/4*3,0
Line w/4*3,0        ,w,h/2
Line w,h/2        ,w/4*3,h
Line w/4*3,h        ,w/4,h
Line w/4,h        ,0,h/2
Color 255,255,255

gex_activ = CreateImage(w+1,h+1)
SetBuffer ImageBuffer(gex_activ)
        Color 102,205,0
        Rect (w/4 +0.15) , 0 ,  (w/2 +0.15) , h ,1
SetBuffer BackBuffer()

While Not KeyHit(1)
ClsColor 110,110,112
Cls
        If KeyHit(2) Then a = a +1 : a = a Mod 3
mx# = MouseX() : my# = MouseY()

                For j=0 To tiley
                        For i=0 To tilex
                                x = i * w/4*3
                                y = j * h +(i Mod 2)*h*0.5
                               
                        If a = 0 Then
                                DrawImage gex, x , y
                                Text x+(w/4) , y+(h/2-5) ,I+","+j
                                        visual$ = " гексагонами "
                        Else If a = 1
                                Color 238,118,0
                                Rect x , y , w , h , 0
                                Color 255,255,255
                                Text x +(w/4) , y +(h/2-5) ,I+","+j
                                        visual$ = " квадратами "
                        Else If a = 2
                                Line x , y , x , y + h
                                Line x , y , x +w , y
                                        visual$ = " линиями "
                        End If
                                                               
                              Next
                Next
                sx# =Floor#  (mx#/(w+0.15) * 4/3 - 0.15)  ;
                sy# =Floor#  ( my#/h - (sx# Mod 2)/2 );
                sxx = Int( (sx#))
                syy = Int( (sy#))
       
               
                ssx# =  (mx#/w * 4/3) ;
                ssy# = ( my#/h - (sx# Mod 2)/2);
               
                        xx = sxx * w/4*3
                        yy = syy * h +(sxx Mod 2)*h*0.5       

               
        Color 0,0,255
        ;Text xx - 5, yy - 5 ,"*"
        ;Line xx , yy , xx , yy + (h/2)
        Color 255,255,255
        DrawImage gex_activ , xx , yy

;        Text 300 ,40 ,"Sx : "+ssx#
;        Text 300 ,55 ,"Sy : "+ssy#

        Text 500 ,185 ," Вычисления :"       
        Text 500 ,200 ,mx# +" / "+w+" * "+4/3+" = "+sx+"    :i"
        Text 500 ,215 ,my# +" / "+h+" - "+ (sx Mod 2)/2+" = "+sy+"    :j"
        Text 400 ,40 ,"Положение мышы в сетке : U : "+sxx+"  V :"+syy
        Text 400 ,55 ,"Координаты мышы в сетке : UX : "+xx+"  VY :"+yy
        Text 400 ,10 ,"Клавиша 1 меняет виды сетки  "
        Text 400 ,25 ,"Вид : "+visual$
Flip ; Меняем буфер
Wend
FreeFont fntArial
End


polopok 29.06.2012 21:10

Ответ: Вопрос .Сново гексы
 
Вложений: 2
Гексы в играх ...
Новые герои и Цивилизация 5

SBJoker 29.06.2012 22:27

Ответ: Вопрос .Сново гексы
 
...и скриншот из King's Bounty: Princes in Armor


Часовой пояс GMT +4, время: 13:47.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot