Pagina 1 van 1

rotating sprites

BerichtGeplaatst: vr apr 06, 2012 10:29 am
door bluatigro
dit is n programma voor t maken van rotating sprites

comands :
clear maxx , maxy
lijn x1 , y1 , x2 , y2 , size , kleur$
circle mx , my , d , size , kleur$
tri x1 , y1 , x2 , y2 , x3 , y3 , kleur$
pen x , y , hoek
move x , y , hoek
save sprite$ , no

de code set zal uitgebreid worden
sugesties zijn welom

error :
- tri werkt niet goed
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global sprx , spry , px , py , pa , pi
pi = atn( 1 ) * 4
nomainwin
open "Rotation Sprite Draw" for graphics as #m
  #m "trapclose [quit]"
  for i = 0 to 31
    call clear 100 , 100
    call pen 0,0 , i * 360 / 32
    call lijn 20,30 , -20,30 , 5 , "green"
    call lijn -20,30 , -20,-30 , 5 , "green"
    call lijn -20,-30 , 20,-30 , 5 , "green"
    call lijn 20,-30 , 20,30 , 5 , "green"
    call save "TANK_U" , i
  next i
  for i = 0 to 31
    call clear 100 , 100
    call pen 0,0 , i * 360 / 32
    call circle 0 , 0 , 15 , 5 ,"green"
    call lijn 0,15,0,30,5,"green"
    call save "TANK_GUN" , i
  next i

notice "READY !!"
wait
end
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
sub save sprite$ , no
  #m "getbmp spr 0 0 " ; sprx ; " " ; spry * 2
  bmpsave "spr" , DefaultDir$ + "\BMP\" + sprite$ + nr$( no ) ; ".bmp"
end sub
function rgb$( r , g , b )
  rgb$ = str$( r ) ; " " ; g ; " " ; b
end function
sub clear x , y
  sprx = x
  spry = y
  #m "color white"
  #m "backcolor white"
  #m "goto 0 0"
  #m "down"
  #m "boxfilled ";x;" ";y
  #m "up"
  #m "color black"
  #m "backcolor black"
  #m "goto 0 " ; y
  #m "down"
  #m "boxfilled " ; x ; " " ; y * 2
  #m "up"
end sub
sub circle x , y , d  , t ,  kl$
  call spot x , y
  #m "size " ; t
  #m "goto " ; sprx / 2 + x ; " " ; spry / 2 - y
  #m "down"
  #m "color black"
  #m "backcolor black"
  #m "circlefilled " ; d
  #m "up"
  #m "goto " ; sprx / 2 + x ; " " ; spry + spry / 2 - y
  #m "down"
  #m "color " ; kl$
  #m "backcolor " ; kl$
  #m "circlefilled " ; d
  #m "up"
end sub
sub tri x1 , y1 , x2 , y2 , x3 , y3 , kl$
  call spot x1 , y1
  call spot x2 , y2
  call spot x3 , y3
  if y1 = y2 then y1 = y1 - 1e-10
  if y2 = y3 then y3 = y3 + 1e-10
  if y1 > y3 then
    call swap y1 , y3
    call swap x1 , x3
  end if
  if y1 > y2 then
    call swap y1 , y2
    call swap x1 , x3
  end if
  if y2 > y3 then
    call swap y2 , y3
    call swap x2 , y3
  end if
  for i = y1 to y3
    a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 )
    if i < y2 then
      b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 )
    else
      b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 )
    end if
    call lijn a , i , b , i , 1 , kl$
  next i
end sub
sub swap byref a , byref b
  h = a
  a = b
  b = h
end sub
sub lijn x1 , y1 , x2 , y2 , t , kl$
  call spot x1 , y1
  call spot x2 , y2
  #m "size " ; t
  #m "color black"
  #m "down"
  #m "line " ; sprx/2+x1 ; " " ; spry/2-y1 ; " " ; sprx/2+x2 ; " " ; spry/2-y2
  #m "up"
  #m "color " ; kl$
  #m "down"
  #m "line " ; sprx/2+x1 ; " " ; spry+spry/2-y1 ; " " ; sprx/2+x2 ; " " ; spry+spry/2-y2
  #m "up"
end sub
sub pen x , y , a
  px = x
  py = y
  pa = a
end sub
sub move dx , dy , da
  call rotate dx , dy , pa
  call pen px + dx , py + dy , pa + da
end sub
sub spot byref x , byref y
  call rotate x , y , pa
  x = x + px
  y = y + py
end sub
sub rotate byref k , byref l , deg
  s = sin( deg / 180 * pi )
  c = cos( deg / 180 * pi )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
function rad( x )
  rad = x * pi / 180
end function
[quit]
  close #m
end

Re: rotating sprites

BerichtGeplaatst: ma jul 30, 2012 1:41 pm
door bluatigro
update :
- tri is nu foutloos

comando's :

clear spritex , spritey

pen x , y , hoek
move x , y , hoek
lijn x1 , y1 , x2 , y2 , dik , kl$
circle mx , my , d , dik , penkl$ , brushkl$
tri x1 , y1 , x2 , y2 , x3 , y3 , kl$
kl$ = rgb$( r , g , b )

save spritenaam$ , nummer

meer comando's ? vraag maar

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global sprx , spry , px , py , pa , pi
pi = atn( 1 ) * 4
nomainwin
open "Rotation Sprite Draw" for graphics as #m
  #m "trapclose [quit]"

  for i = 0 to 31
    call clear 100 , 100
    call pen 0 , 0 , i / 32 * 360
    call tri 0,-40 ,  -20,40 , 20,40 , "red"
    call save "tri" , i
  next i

notice "READY !!"
wait
end
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
sub save sprite$ , no
  #m "getbmp spr 0 0 " ; sprx ; " " ; spry * 2
  bmpsave "spr" , DefaultDir$ + "\BMP\" + sprite$ + nr$( no ) ; ".bmp"
end sub
function rgb$( r , g , b )
  rgb$ = str$( r ) ; " " ; g ; " " ; b
end function
sub clear x , y
  sprx = x
  spry = y
  #m "color white"
  #m "backcolor white"
  #m "goto 0 0"
  #m "down"
  #m "boxfilled ";x;" ";y
  #m "up"
  #m "color black"
  #m "backcolor black"
  #m "goto 0 " ; y + 2
  #m "down"
  #m "boxfilled " ; x ; " " ; y * 2
  #m "up"
end sub
sub circle x , y , d  , t ,  pen$ , brush$
  call spot x , y
  #m "size " ; t
  #m "goto " ; sprx / 2 + x ; " " ; spry / 2 - y
  #m "down"
  #m "color black"
  #m "backcolor black"
  #m "circlefilled " ; d
  #m "up"
  #m "goto " ; sprx / 2 + x ; " " ; spry + spry / 2 - y
  #m "down"
  #m "color " ; pen$
  #m "backcolor " ; brush$
  #m "circlefilled " ; d
  #m "up"
end sub
sub tri x1 , y1 , x2 , y2 , x3 , y3 , kl$
  call spot x1 , y1
  call spot x2 , y2
  call spot x3 , y3
  if y1 = y2 then y1 = y1 - 1e-10
  if y2 = y3 then y3 = y3 + 1e-10
  if y1 > y3 then
    call swap y1 , y3
    call swap x1 , x3
  end if
  if y1 > y2 then
    call swap y1 , y2
    call swap x1 , x2
  end if
  if y2 > y3 then
    call swap y2 , y3
    call swap x2 , x3
  end if
  for i = y1 to y3
    a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 )
    if i < y2 then
      b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 )
    else
      b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 )
    end if
    call drawline a , i , b , i , 1 , kl$
  next i
end sub
sub swap byref a , byref b
  h = a
  a = b
  b = h
end sub
sub lijn x1 , y1 , x2 , y2 , t , kl$
  call spot x1 , y1
  call spot x2 , y2
  call drawline x1 , y1 , x2 , y2 , t , kl$
end sub
sub drawline x1 , y1 , x2 , y2 , t , kl$
  #m "size " ; t
  #m "color black"
  #m "down"
  #m "line " ; sprx/2+x1 ; " " ; spry/2-y1 _
  ; " " ; sprx/2+x2 ; " " ; spry/2-y2
  #m "up"
  #m "color " ; kl$
  #m "down"
  #m "line " ; sprx/2+x1 ; " " ; spry+spry/2-y1 _
  ; " " ; sprx/2+x2 ; " " ; spry+spry/2-y2
  #m "up"
end sub
sub pen x , y , a
  px = x
  py = y
  pa = a
end sub
sub move dx , dy , da
  call rotate dx , dy , pa
  call pen px + dx , py + dy , pa + da
end sub
sub spot byref x , byref y
  call rotate x , y , pa
  x = x + px
  y = y + py
end sub
sub rotate byref k , byref l , deg
  s = sin( deg / 180 * pi )
  c = cos( deg / 180 * pi )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
function rad( x )
  rad = x * pi / 180
end function
[quit]
  close #m
end