2D SPACE SIM

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

2D SPACE SIM

Berichtdoor bluatigro » do jan 15, 2015 1:43 pm

error :
- t beweegt niet goed
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi
global camx , camy , camangle , px , py , pangle
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
menu #m , "game" _
        , "new"  , [new] _
        , "info" , [info] _
        , "exit" , [quit]
open "2D space" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
  timer 40 , [tmr]
wait
[new]
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  timer 0
  r$ = chr$( 13 )
  text$ = "Welkome by 2D SPACE ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "  You steer a spaceship trou space ." + r$ _
  + "  You have to dock on th right place ." + r$ _
  + "  Whit low [ rotational ] speed ." + r$ _
  + "Use numpad to steer the ship ."
  notice text$
  timer 40 , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]

  #m "fill black"
  call cam camx , camy , camangle
  call station
  call ship

  camdx = 0
  camdy = 0
  camdangle = 0
  select case val( key$ )
    case 2
      camdy = 1
    case 4
      camdx = -1
    case 6
      camdx = 1
    case 7
      camdangle = 1
    case 8
      camdy = -1
    case 9
      camdangle = -1
    case else
  end select

  x = 50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = -50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = 0
  y = 100
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    if x < 10 and x > -10 and y < 30 and y > 10 _
    and abs( camdangle ) < 2 _
    and abs( camdx ) < 2 _
    and abs( camdy ) < 2 then
      notice "You docked savely ."
    else
      notice "You crased !!"
    end if
    close #m
    end
  end if

  camx = camx + camdx
  camy = camy + camdy
  camangle = camangle + camdangle

wait
sub spot byref x , byref y
  call rotate x , y , pangle
  x = x + px - camx
  y = y + py - camy
  call rotate x , y , 0 - camangle
end sub
sub lokal byref x , byref y
  call rotate x , y , camangle
  x = x - px + camx
  y = y - py + camy
  call rotate x , y , 0 - pangle
end sub
sub pen x , y , angle
  px = x
  py = y
  pangle = angle
end sub
sub cam x , y , angle
  camx = x
  camy = y
  camangle = angle
end sub
sub station
  call pen 0 , 0 , 0
  call lijn  100,  0 , -100,  0 , "green" , 40
  call lijn    0, 10 ,    0, 30 , "blue"  , 40
end sub
sub ship
  call pen camx , camy , camangle
  call lijn -50,-86 , 50,-86 , "green" , 3
  call lijn 50,-86 , 0,100 , "green" , 3
  call lijn 0,100 , -50,-86 , "green" , 3
end sub
sub lijn x1 , y1 , x2 , y2 , kl$ , t
  call spot x1 , y1
  call spot x2 , y2
  #m "color " ; kl$
  #m "size " ; t
  #m "down"
  #m "line ";winx/2+x1;" ";winy/2-y1 _
        ;" ";winx/2+x2;" ";winy/2-y2
  #m "up"
end sub
sub rotate byref k , byref l , deg
  s = sin( deg * pi / 180 )
  c = cos( deg * pi / 180 )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: 2D SPACE SIM

Berichtdoor bluatigro » vr jan 16, 2015 12:44 pm

update :
- acceleratie is nu goed

error :
- t beweegt niet goed

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi
global camx , camy , camangle
global camdx , camdy , camdangle
global px , py , pangle
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
menu #m , "game" _
        , "new"  , [new] _
        , "info" , [info] _
        , "exit" , [quit]
open "2D space" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
  timer 40 , [tmr]
wait
[new]
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  timer 0
  r$ = chr$( 13 )
  text$ = "Welkome by 2D SPACE ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "  You steer a spaceship trou space ." + r$ _
  + "  You have to dock on th right place ." + r$ _
  + "  Whit low [ rotational ] speed ." + r$ _
  + "Use numpad to steer the ship ."
  notice text$
  timer 40 , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]

  #m "fill black"
  call cam camx , camy , camangle
  call station
  call ship

  camax = 0
  camay = 0
  camaangle = 0
  select case val( key$ )
    case 2
      camay = 1
    case 4
      camax = -1
    case 6
      camax = 1
    case 7
      camaangle = 1
    case 8
      camay = -1
    case 9
      camaangle = -1
    case else
  end select
  key$ = ""

  x = 50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = -50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = 0
  y = 100
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 20 then
    timer 0
    if x < 10 and x > -10 and y < 30 and y > 10 _
    and abs( camdangle ) < 2 _
    and abs( camdx ) < 2 _
    and abs( camdy ) < 2 then
      notice "You docked savely ."
    else
      notice "You crased !!"
    end if
    close #m
    end
  end if

  camdx = camdx + camax
  camdy = camdy + camay
  camdangle = camdangle + camaangle

  camx = camx + camdx
  camy = camy + camdy
  camangle = camangle + camdangle

wait
sub spot byref x , byref y
  call rotate x , y , pangle
  x = x + px - camx
  y = y + py - camy
  call rotate x , y , 0 - camangle
end sub
sub lokal byref x , byref y
  call rotate x , y , camangle
  x = x - px + camx
  y = y - py + camy
  call rotate x , y , 0 - pangle
end sub
sub pen x , y , angle
  px = x
  py = y
  pangle = angle
end sub
sub cam x , y , angle
  camx = x
  camy = y
  camangle = angle
end sub
sub station
  call pen 0 , 0 , 0
  call lijn  100,  0 , -100,  0 , "green" , 40
  call lijn    0, 10 ,    0, 30 , "blue"  , 40
end sub
sub ship
  call pen camx , camy , camangle
  call lijn -50,-86 , 50,-86 , "green" , 3
  call lijn 50,-86 , 0,100 , "green" , 3
  call lijn 0,100 , -50,-86 , "green" , 3
end sub
sub lijn x1 , y1 , x2 , y2 , kl$ , t
  call spot x1 , y1
  call spot x2 , y2
  #m "color " ; kl$
  #m "size " ; t
  #m "down"
  #m "line ";winx/2+x1;" ";winy/2-y1 _
        ;" ";winx/2+x2;" ";winy/2-y2
  #m "up"
end sub
sub rotate byref k , byref l , deg
  s = sin( deg * pi / 180 )
  c = cos( deg * pi / 180 )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: 2D SPACE SIM

Berichtdoor bluatigro » za jan 17, 2015 3:11 pm

update :
- t beweegt nu goed

error :
- de botsing controle werk niet goed

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi
global camx , camy , camangle
global camdx , camdy , camdangle
global px , py , pangle
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
menu #m , "game" _
        , "new"  , [new] _
        , "info" , [info] _
        , "exit" , [quit]
open "2D space sim" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
  timer 40 , [tmr]
wait
[new]
  camx = 300
  camy = 0
  camangle = range( 0 , 360 )
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  timer 0
  r$ = chr$( 13 )
  text$ = "Welkome by 2D SPACE ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "  You steer a spaceship trou space ." + r$ _
  + "  You have to dock on th right place ." + r$ _
  + "  Whit low [ rotational ] speed ." + r$ _
  + "Use numpad to steer the ship ."
  notice text$
  timer 40 , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]

  #m "fill black"
  call cam camx , camy , camangle
  call station
  call ship

  camax = 0
  camay = 0
  camaangle = 0
  select case val( key$ )
    case 2
      camay = -1
    case 4
      camax = -1
    case 6
      camax = 1
    case 7
      camaangle = 1
    case 8
      camay = 1
    case 9
      camaangle = -1
    case else
  end select
  key$ = ""

''  call checkdockedorcrased

  call rotate camax , camay , camangle

  camdx = camdx + camax
  camdy = camdy + camay
  camdangle = camdangle + camaangle

  camx = camx + camdx
  camy = camy + camdy
  camangle = camangle + camdangle

wait
sub checkdockedorcrased

  x = 50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 100 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = -50
  y = -86
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 100 then
    timer 0
    notice "You crased !!"
    close #m
    end
  end if
  x = 0
  y = 100
  call lokal x , y
  if abs( x ) < 100 and abs( y ) < 100 then
    timer 0
    if x < 10 and x > -10 and y < 110 and y > 90 _
    and abs( camdangle ) < 2 _
    and abs( camdx ) < 2 _
    and abs( camdy ) < 2 then
      notice "You docked savely ."
    else
      notice "You crased !!"
    end if
    close #m
    end
  end if

end sub
sub spot byref x , byref y
  call rotate x , y , pangle
  x = x + px - camx
  y = y + py - camy
  call rotate x , y , 0 - camangle
end sub
sub lokal byref x , byref y
  call rotate x , y , camangle
  x = x - px + camx
  y = y - py + camy
  call rotate x , y , 0 - pangle
end sub
sub pen x , y , angle
  px = x
  py = y
  pangle = angle
end sub
sub cam x , y , angle
  camx = x
  camy = y
  camangle = angle
end sub
sub station
  call pen 0 , 0 , 0
  call lijn  100 ,   100 , -100 ,  100 , "green" , 5
  call lijn -100 ,   100 , -100 , -100 , "green" , 5
  call lijn -100 ,  -100 ,  100 , -100 , "green" , 5
  call lijn  100 ,  -100 ,  100 ,  100 , "green" , 5
  call lijn    0 ,    90 ,    0 ,  110 , "blue"  , 40
end sub
sub ship
  call pen camx , camy , camangle
  call lijn -50,-86 , 50,-86 , "green" , 3
  call lijn 50,-86 , 0,100 , "green" , 3
  call lijn 0,100 , -50,-86 , "green" , 3
end sub
sub lijn x1 , y1 , x2 , y2 , kl$ , t
  call spot x1 , y1
  call spot x2 , y2
  #m "color " ; kl$
  #m "size " ; t
  #m "down"
  #m "line ";winx/2+x1;" ";winy/2-y1 _
        ;" ";winx/2+x2;" ";winy/2-y2
  #m "up"
end sub
sub rotate byref k , byref l , deg
  s = sin( deg * pi / 180 )
  c = cos( deg * pi / 180 )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Games

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron