|
Post by bluatigro on Oct 17, 2020 15:50:25 GMT
error : i do not see my planes
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winw , winh , cam.x , cam.y , cam.a , pi
global nmy.x , nmy.y , nmy.a
winw = WindowWidth
winh = WindowHeight
cam.x = 0
cam.y = 0
cam.a = 0
nmy.x = winw / 4
nmy.y = 0
nmy.a = 0
pi = atn( 1 ) * 4
nomainwin
open "fly game 1.0" for graphics as #m
#m "trapclose [quit]"
#m "fill black"
call drawplane cam.x , cam.y , cam.a , rgb( 255 , 255 , 0 )
call drawplane nmy.x , nmy.y , nmy.a , rgb( 0 , 255 , 255 )
wait
[quit]
close #m
end
sub drawplane x , y , a , kl
x1=0:y1=30
x2=-10:y2=-30
x3=10:y3=-30
call rotate x1 , y1 , a
call rotate x2 , y2 , a
call rotate x3 , y3 , a
call lino x+x1,y+y1,x+x2,y+y2,kl,5
call lino x+x3,y+y3,x+x2,y+y2,kl,5
call lino x+x1,y+y1,x+x3,y+y3,kl,5
end sub
sub lino x1,y1,x2,y2,kl,size
call rotate x1 , y1 , 0 - cam.a
x1 = x1 - cam.x
y1 = y1 - cam.y
x2 = x2 - cam.x
y2 = y2 - cam.y
#m "size ";size
r = int( kl ) and 255
g = int( kl / 256 ) and 255
b = int( kl / 256^2 ) and 255
#m "color ";r;" ";g;" ";b
#m "line ";x1+winw/2;" ";y1+winh/2;" ";x2+winw/2;" ";y2+winh/2
end sub
function rgb( r , g , b )
rgb = r + g * 256 + b * 256 ^ 2
end function
function rad( deg )
rad = deg * pi / 180
end function
sub rotate byref k , byref l , deg
s = sin( rad( deg ) )
c = cos( rad( deg ) )
hk = s * k - c * l
hl = c * k + s * l
k = hk
l = hl
end sub
[time.tick]
wait
|
|
|
Post by bluatigro on Oct 18, 2020 13:22:34 GMT
update : ai added planes viable
i get a 'syntaks error' in a case line
what is not good there ?
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , cam.x , cam.y , cam.a , pi global nmy.x , nmy.y , nmy.a , key$ global fly , flyleft , flyright dim mem( 3600 ) winw = WindowWidth winh = WindowHeight cam.x = 0 cam.y = 0 cam.a = 0 nmy.x = 50 nmy.y = 0 nmy.a = 90 pi = atn( 1 ) * 4 fly = 0 flyleft = 1 flyright = 2 nomainwin open "fly game 1.0" for graphics as #m #m "trapclose [quit]" #m "when characterInput [key]" wait [timer.tick] #m "fill black" ''player control human = fly select case key$ case chr$( VK_LEFT ) cam.a = cam.a + 3 human = flyleft case chr$( VK_RIGHT ) cam.a = cam.a - 3 human = flyright case else end select mem( in( nmy.x - cam.x , nmy.y - cam.y _ , nmy.a - cam.a ) ) = human select case mem( in( cam.x - nmy.x _ , cam.y - nmy.y , cam.a - nmy.a ) ) case flyleft nmy.a = nmy.a + 3 case flyright nmy.a = nmy.a - 3 case else end select dx=0 dy=3 call rotate dx,dy,cam.a cam.x=cam.x+dx cam.y=cam.y+dy dx=0 dy=3 call rotate dx,dy,nmy.a nmy.x=nmy.x+dx nmy.y=nmy.y+dy if cam.x > winh then cam.x = 0 if cam.x < 0 then cam.x = winh if cam.y > winh then cam.y = 0 if cam.y < 0 then cam.y = winh if nmy.x > winh then nmy.x = 0 if nmy.x < 0 then nmy.x = winh if nmy.y > winh then nmy.y = 0 if nmy.y < 0 then nmy.y = winh call drawplane cam.x , cam.y , cam.a , rgb( 255 , 255 , 0 ) call drawplane nmy.x , nmy.y , nmy.a , rgb( 0 , 255 , 255 ) wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( VK_ESCAPE ) then wait [quit] close #m end function in( x , y , a ) call rotate x , y , a x = ( int( x / winx * 20 ) + 10 ) mod 10 y = ( int( y / winh * 20 ) + 10 ) mod 10 a = ( int( a / 10 ) + 36 ) mod 36 in = ( x * 10 + y ) * 36 + a end if sub drawplane x , y , a , kl x1=0:y1=30 x2=-10:y2=-30 x3=10:y3=-30 call rotate x1 , y1 , a call rotate x2 , y2 , a call rotate x3 , y3 , a call lino x+x1,y+y1,x+x2,y+y2,kl,5 call lino x+x3,y+y3,x+x2,y+y2,kl,5 call lino x+x1,y+y1,x+x3,y+y3,kl,5 end sub sub lino x1,y1,x2,y2,kl,size x1 = x1 - cam.x y1 = y1 - cam.y x2 = x2 - cam.x y2 = y2 - cam.y call rotate x1 , y1 , 0 - cam.a call rotate x2 , y2 , 0 - cam.a #m "size ";size r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256^2 ) and 255 #m "color ";r;" ";g;" ";b #m "down" #m "line ";x1+winw/2;" ";y1+winh/2;" ";x2+winw/2;" ";y2+winh/2 #m "up" end sub function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function rad( deg ) rad = deg * pi / 180 end function sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = s * k - c * l hl = c * k + s * l k = hk l = hl end sub
|
|
|
Post by bluatigro on Oct 18, 2020 13:46:51 GMT
update : added forest
error : my forest act strange
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , cam.x , cam.y , cam.a , pi global nmy.x , nmy.y , nmy.a , key$ global fly , flyleft , flyright dim mem( 3600 ) winw = WindowWidth winh = WindowHeight cam.x = 0 cam.y = 0 cam.a = 0 nmy.x = 50 nmy.y = 0 nmy.a = 90 pi = atn( 1 ) * 4 fly = 0 flyleft = 1 flyright = 2 nomainwin open "fly game 1.0" for graphics as #m #m "trapclose [quit]" #m "when characterInput [key]" timer 40 , [timer.tick] wait [timer.tick] #m "fill black" ''player control human = fly '' select case key$ '' case chr$( VK_LEFT ) '' cam.a = cam.a + 3 '' human = flyleft '' case chr$( VK_RIGHT ) '' cam.a = cam.a - 3 '' human = flyright '' case else '' end select mem( in( nmy.x - cam.x , nmy.y - cam.y _ , nmy.a - cam.a ) ) = human select case mem( in( cam.x - nmy.x _ , cam.y - nmy.y , cam.a - nmy.a ) ) case flyleft nmy.a = nmy.a + 3 case flyright nmy.a = nmy.a - 3 case else end select dx=0 dy=3 call rotate dx,dy,cam.a cam.x=cam.x+dx cam.y=cam.y+dy dx=0 dy=3 call rotate dx,dy,nmy.a nmy.x=nmy.x+dx nmy.y=nmy.y+dy if cam.x > winh then cam.x = 0 if cam.x < 0 then cam.x = winh if cam.y > winh then cam.y = 0 if cam.y < 0 then cam.y = winh if nmy.x > winh then nmy.x = 0 if nmy.x < 0 then nmy.x = winh if nmy.y > winh then nmy.y = 0 if nmy.y < 0 then nmy.y = winh call drawplane cam.x , cam.y , cam.a , rgb( 255 , 255 , 0 ) call drawplane nmy.x , nmy.y , nmy.a , rgb( 0 , 255 , 255 ) for x=-300 to 300 step 100 for y=-300 to 300 step 100 call lino x-20,y,x+20,y,rgb(0,255,0),1 call lino x,y-20,x,y+20,rgb(0,255,0),1 next y next x wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] close #m end function in( x , y , a ) call rotate x , y , a x = ( int( x / winw * 20 ) + 10 ) mod 10 y = ( int( y / winh * 20 ) + 10 ) mod 10 a = ( int( a / 10 ) + 36 ) mod 36 in = ( x * 10 + y ) * 36 + a end function sub drawplane x , y , a , kl x1=0:y1=30 x2=-10:y2=-30 x3=10:y3=-30 call rotate x1 , y1 , a call rotate x2 , y2 , a call rotate x3 , y3 , a call lino x+x1,y+y1,x+x2,y+y2,kl,5 call lino x+x3,y+y3,x+x2,y+y2,kl,5 call lino x+x1,y+y1,x+x3,y+y3,kl,5 end sub sub lino x1,y1,x2,y2,kl,size x1 = x1 - cam.x y1 = y1 - cam.y x2 = x2 - cam.x y2 = y2 - cam.y call rotate x1 , y1 , 0 - cam.a call rotate x2 , y2 , 0 - cam.a #m "size ";size r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256^2 ) and 255 #m "color ";r;" ";g;" ";b #m "down" #m "line ";x1+winw/2;" ";y1+winh/2;" ";x2+winw/2;" ";y2+winh/2 #m "up" end sub function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function rad( deg ) rad = deg * pi / 180 end function sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = s * k - c * l hl = c * k + s * l k = hk l = hl end sub
|
|
|
Post by bluatigro on Oct 18, 2020 13:56:12 GMT
update : vk error fount
error : cam plane does not react on key's
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , cam.x , cam.y , cam.a , pi global nmy.x , nmy.y , nmy.a , key$ global fly , flyleft , flyright dim mem( 3600 ) winw = WindowWidth winh = WindowHeight cam.x = 0 cam.y = 0 cam.a = 0 nmy.x = 50 nmy.y = 0 nmy.a = 90 pi = atn( 1 ) * 4 fly = 0 flyleft = 1 flyright = 2 nomainwin open "fly game 1.0" for graphics as #m #m "trapclose [quit]" #m "when characterInput [key]" timer 40 , [timer.tick] wait [timer.tick] scan #m "fill black" ''player control human = fly select case key$ case chr$( _VK_LEFT ) cam.a = cam.a + 3 human = flyleft case chr$( _VK_RIGHT ) cam.a = cam.a - 3 human = flyright case else end select mem( in( nmy.x - cam.x , nmy.y - cam.y _ , nmy.a - cam.a ) ) = human ''ai select case mem( in( cam.x - nmy.x _ , cam.y - nmy.y , cam.a - nmy.a ) ) case flyleft nmy.a = nmy.a + 3 case flyright nmy.a = nmy.a - 3 case else end select dx=0 dy=3 call rotate dx,dy,cam.a cam.x=cam.x+dx cam.y=cam.y+dy dx=0 dy=3 call rotate dx,dy,nmy.a nmy.x=nmy.x+dx nmy.y=nmy.y+dy if cam.x > winh then cam.x = 0 if cam.x < 0 then cam.x = winh if cam.y > winh then cam.y = 0 if cam.y < 0 then cam.y = winh if nmy.x > winh then nmy.x = 0 if nmy.x < 0 then nmy.x = winh if nmy.y > winh then nmy.y = 0 if nmy.y < 0 then nmy.y = winh call drawplane cam.x , cam.y , cam.a , rgb( 255 , 255 , 0 ) call drawplane nmy.x , nmy.y , nmy.a , rgb( 0 , 255 , 255 ) for x=-300 to 300 step 100 for y=-300 to 300 step 100 call lino x-20,y,x+20,y,rgb(0,255,0),1 call lino x,y-20,x,y+20,rgb(0,255,0),1 next y next x wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( _VK_ESCAPE ) then wait [quit] close #m end function in( x , y , a ) call rotate x , y , a x = ( int( x / winw * 20 ) + 10 ) mod 10 y = ( int( y / winh * 20 ) + 10 ) mod 10 a = ( int( a / 10 ) + 36 ) mod 36 in = ( x * 10 + y ) * 36 + a end function sub drawplane x , y , a , kl x1=0:y1=30 x2=-10:y2=-30 x3=10:y3=-30 call rotate x1 , y1 , a call rotate x2 , y2 , a call rotate x3 , y3 , a call lino x+x1,y+y1,x+x2,y+y2,kl,5 call lino x+x3,y+y3,x+x2,y+y2,kl,5 call lino x+x1,y+y1,x+x3,y+y3,kl,5 end sub sub lino x1,y1,x2,y2,kl,size x1 = x1 - cam.x y1 = y1 - cam.y x2 = x2 - cam.x y2 = y2 - cam.y call rotate x1 , y1 , 0 - cam.a call rotate x2 , y2 , 0 - cam.a #m "size ";size r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256^2 ) and 255 #m "color ";r;" ";g;" ";b #m "down" #m "line ";x1+winw/2;" ";y1+winh/2;" ";x2+winw/2;" ";y2+winh/2 #m "up" end sub function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function rad( deg ) rad = deg * pi / 180 end function sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = s * k - c * l hl = c * k + s * l k = hk l = hl end sub
|
|
|
Post by Rod on Oct 18, 2020 14:13:34 GMT
InKey$ returns two characters for the arrow keys. So you need to parse InKey$ and use the right most character to compare against the Virtual Key code.
key$=right$(InKey$,1)
|
|
|
Post by Rod on Oct 19, 2020 9:57:22 GMT
You need to #m "setfocus" when the window is opened. That sets it up ready to read the keyboard. You need to lose the scan in your timer loop. You also need to lengthen the delay as there is not enough time in 40ms to do all the processing so your keystrokes get lost in backed up drawing code. Set the delay to 150 and you will see the keyboard is read. There are other errors.
|
|
|
Post by bluatigro on Oct 21, 2020 9:49:24 GMT
update : got the error's out
please test this gamer's
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , cam.x , cam.y , cam.a , pi global nmy.x , nmy.y , nmy.a , key$ global fly , flyleft , flyright dim mem( 3600 ) , v( 3 ) winw = WindowWidth winh = WindowHeight cam.x = winw / 2 cam.y = winh / 2 cam.a = 0 nmy.x = winw / 2 + 50 nmy.y = winh / 2 nmy.a = 0 pi = atn( 1 ) * 4 fly = 0 flyleft = 1 flyright = 2 nomainwin open "fly game 2.0" for graphics as #m #m "trapclose [quit]" #m "when characterInput [key]" #m "setfocus" timer 150 , [timer.tick] wait [timer.tick] scan #m "fill black" ''player control human = fly select case key$ case chr$( _VK_LEFT ) cam.a = cam.a + 3 human = flyleft case chr$( _VK_RIGHT ) cam.a = cam.a - 3 human = flyright case else end select mem( in( nmy.x - cam.x , nmy.y - cam.y _ , nmy.a - cam.a ) ) = human ''ai select case mem( in( cam.x - nmy.x _ , cam.y - nmy.y , cam.a - nmy.a ) ) case flyleft nmy.a = nmy.a + 3 case flyright nmy.a = nmy.a - 3 case else end select dx=0 dy=3 call rotate dx,dy,cam.a cam.x=cam.x+dx cam.y=cam.y+dy dx=0 dy=3 call rotate dx,dy,nmy.a nmy.x=nmy.x+dx nmy.y=nmy.y+dy if cam.x > winh then cam.x = 0 if cam.x < 0 then cam.x = winh if cam.y > winh then cam.y = 0 if cam.y < 0 then cam.y = winh if nmy.x > winh then nmy.x = 0 if nmy.x < 0 then nmy.x = winh if nmy.y > winh then nmy.y = 0 if nmy.y < 0 then nmy.y = winh call link cam.x , cam.y , cam.a call drawplane rgb( 255 , 255 , 0 ) call link nmy.x , nmy.y , nmy.a call drawplane rgb( 0 , 255 , 255 ) for x = -300 to 300 step 200 for y = -300 to 300 step 200 call link x , y , 0 call lino -20,0,20,0,rgb(0,255,0),1 call lino 0,-20,0,20,rgb(0,255,0),1 next y next x key$ = "" wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( _VK_ESCAPE ) then wait [quit] close #m end sub link x , y , a v( 0 ) = x v( 1 ) = y v( 2 ) = a end sub sub spot byref x , byref y call rotate x , y , v( 2 ) x = x + v( 0 ) y = y + v( 1 ) x = x - cam.x y = y - cam.y call rotate x , y , 0-cam.a x = x + winw/2 y = y + winh/2 end sub function in( x , y , a ) call rotate x , y , a x = ( int( x / winw * 10 ) + 10 ) mod 10 y = ( int( y / winw * 10 ) + 10 ) mod 10 a = ( int( a / 10 ) + 36 ) mod 36 in = ( x * 10 + y ) * 36 + a end function sub drawplane kl x1=0:y1=30 x2=-10:y2=-30 x3=10:y3=-30
call lino x1,y1,x2,y2,kl,5 call lino x3,y3,x2,y2,kl,5 call lino x1,y1,x3,y3,kl,5 end sub sub lino x1,y1,x2,y2,kl,size call spot x1 , y1 call spot x2 , y2 #m "size ";size r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256^2 ) and 255 #m "color ";r;" ";g;" ";b #m "down" #m "line ";x1;" ";y1;" ";x2;" ";y2 #m "up" end sub function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function rad( deg ) rad = deg * pi / 180 end function sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = s * k - c * l hl = c * k + s * l k = hk l = hl end sub
|
|