RPG OOP-style

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

Moderator: anthonio

RPG OOP-style

Berichtdoor bluatigro » wo okt 05, 2011 2:40 pm

dit is een start van n RPG OOP-style
ik heb nog geen vehaalijn
verbeteringen operkingen sugesties uitbrijdingen zijn welkom
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi , player$ , enemy$ , lastkey$ , speed
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
speed = 5
player$ = entity$( winx / 4 , winy / 2 , "healty" )
enemy$ = entity$( winx - winx / 4 , winy / 2 , "idle" )
nomainwin
open "RPG" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  timer 40 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
  select case lastkey$
    case chr$( _VK_UP )
      call moveEntity player$ , 0 , 0-speed
    case chr$( _VK_DOWN )
      call moveEntity player$ , 0 , speed
    case chr$( _VK_LEFT )
      call moveEntity player$ , 0-speed , 0
    case chr$( _VK_RIGHT )
      call moveEntity player$ , speed , 0
    case else
  end select
  lastkey$ = ""
  #m "cls"
  ex = val( word$( enemy$ , 1 ) )
  ey = val( word$( enemy$ , 2 ) )
  px = val( word$( player$ , 1 ) )
  py = val( word$( player$ , 2 ) )
  select case word$( enemy$ , 3 )
    case "angry"
      #m "backcolor red"
      if ex < px then call moveEntity enemy$ , 3 , 0
      if ex > px then call moveEntity enemy$ , -3 , 0
      if ey < py then call moveEntity enemy$ , 0 , 3
      if ey > py then call moveEntity enemy$ , 0 , -3
    case else
      #m "backcolor darkgreen"
      select case int( rnd( 0 ) * 4 )
        case 0
          call moveEntity enemy$ , 2 , 0
        case 1
          call moveEntity enemy$ , -2 , 0
        case 2
          call moveEntity enemy$ , 0 , 2
        case 3
          call moveEntity enemy$ , 0 , -2
        case else
      end select
  end select
  #m "goto " ; spot$( enemy$ )
  #m "down"
  #m "circlefilled 20"
  #m "up"
  select case word$( player$ , 3 )
    case "healty"
      #m "backcolor yellow"
      speed = 6
    case else
      #m "backcolor darkgray"
      speed = 4
  end select
  #m "goto " ; spot$( player$ )
  #m "down"
  #m "circlefilled 20"
  #m "up"
  if diss( enemy$ , player$ ) < 40 then
    call changeState enemy$ , "angry"
    call changeState player$ , "ill"
  end if
wait
[quit]
  close #m
end
end
function diss( a$ , b$ )
  ax = val( word$( a$ , 1 ) )
  ay = val( word$( a$ , 2 ) )
  bx = val( word$( b$ , 1 ) )
  by = val( word$( b$ , 2 ) )
  diss = sqr( (ax-bx)^2 + (ay-by)^2 )
end function
function entity$( x , y , st$ )
''create game entity
  entity$ = x ; " " ; y ; " " ; st$
end function
function spot$( a$ )
''get place of entity
''for sprite
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  spot$ = x ; " " ; y
end function
sub changeState byref a$ , st$
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  a$ = entity$( x , y , st$ )
end sub
sub moveEntity byref a$ , dx , dy
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  st$ = word$( a$ , 3 )
  a$ = entity$( x + dx , y + dy , st$ )
end sub
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: RPG OOP-style

Berichtdoor ForNext » do okt 06, 2011 8:28 pm

Als Hobbit ontferm ik mij over de zielige van koude bibberende Gollum.
Ga ik vlak voor hem staan, dan wijkt hij achteruit.
Raak ik hem aan, dan springt hij mij om de hals.
En daarna raak ik hem niet meer kwijt.
Help!!

Zondermeer knap geprogrammeerd.

m.vr.gr.
Roberto
Cursist LB Amstelveen
ForNext
 
Berichten: 60
Geregistreerd: za okt 27, 2007 9:40 am
Woonplaats: Amstelveen

Re: RPG OOP-style

Berichtdoor bluatigro » vr okt 14, 2011 11:10 am

update :
meer enemy$
alle entity$ hebben een richting nu

r zit nu wel n error in :
de enemy$ zou rood moeten worden als hij geraakt wordt
en
de player$ zou van geel naar grijs moet gaan dan
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi , player$ , lastkey$ , speed , frame , nmimax
nmimax = 4
dim pen( 3 ) , enemy$( nmimax )
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
speed = 5
player$ = entity$( winx / 4 , winy / 2 , 0 , "healty" )
for i = 0 to nmimax
  enemy$( i ) = entity$( rnd(0)*winx , rnd(0)*winy , rnd(0)*360 , "idle" )
next i
nomainwin
open "RPG" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  timer 40 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
frame = frame + 0.2
  select case lastkey$
    case chr$( _VK_UP )
      call moveEntity player$ , 0 , 0-speed , 0
    case chr$( _VK_DOWN )
      call moveEntity player$ , 0 , speed , 0
    case chr$( _VK_LEFT )
      call moveEntity player$ , 0 , 0 , -5
    case chr$( _VK_RIGHT )
      call moveEntity player$ , 0 , 0 , 5
    case else
  end select
  lastkey$ = ""
  #m "cls"
  for i = 0 to nmimax
    ex = val( word$( enemy$( i ) , 1 ) )
    ey = val( word$( enemy$( i ) , 2 ) )
    eangle = val( word$( enemy$( i ) , 3 ) )
    px = val( word$( player$ , 1 ) )
    py = val( word$( player$ , 2 ) )
    pangle = val( word$( player$ , 3 ) )
    epx = px - ex
    epy = py - ey
    call rotate epx , epy , val( word$( enemy$( i ) , 3 ) )
    e$ = enemy$( i )
    select case word$( enemy$(i) , 4 )
      case "angry"
        clr$ = "red"
        if epx < 0 then call moveEntity e$ , 0 , -3 , - 5
        if epx > 0 then call moveEntity e$ , 0 , -3 , 5
      case else
        clr$ = "green"
        select case int( rnd( 0 ) * 3 )
          case 0
            call moveEntity e$ , 0 , -3 , 0
          case 1
            call moveEntity e$ , 0 , 0 , -5
          case 2
            call moveEntity e$ , 0 , 0 , 5
          case else
        end select
    end select
    call drawhuman e$ , clr$
    enemy$( i ) = e$
  next i
  select case word$( player$ , 3 )
    case "healty"
      clr$ = "yellow"
      speed = 6
    case else
      clr$ = "darkgray"
      speed = 4
  end select
  call drawhuman player$ , clr$
  if diss( enemy$ , player$ ) < 40 then
    call changeState enemy$ , "angry"
    call changeState player$ , "ill"
  end if
wait
[quit]
  close #m
end
end
function diss( a$ , b$ )
  ax = val( word$( a$ , 1 ) )
  ay = val( word$( a$ , 2 ) )
  bx = val( word$( b$ , 1 ) )
  by = val( word$( b$ , 2 ) )
  diss = sqr( (ax-bx)^2 + (ay-by)^2 )
end function
function entity$( x , y , a , st$ )
''create game entity
  entity$ = x ; " " ; y ; " " ; a ; " " ; st$
end function
function spot$( a$ )
''get place of entity
''for sprite
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  spot$ = x ; " " ; y
end function
sub changeState byref a$ , st$
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  angle = val( word$( a$ , 3 ) )
  a$ = entity$( x , y , angle , st$ )
end sub
sub moveEntity byref a$ , dx , dy , da
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  angle = val( word$( a$ , 3 ) )
  if x < 0 then x = winx
  if x > winx then x = 0
  if y < 0 then y = winy
  if y > winy then y = 0
  call rotate dx , dy , angle
  st$ = word$( a$ , 3 )
  a$ = entity$( x + dx , y + dy , angle + da , st$ )
end sub
sub drawhuman e$ , clr$
  x = val( word$( e$ , 1 ) )
  y = val( word$( e$ , 2 ) )
  a = val( word$( e$ , 3 ) )
  call setpen x , y , a
  call circle 10,-10 + sin(frame)*10,10,"black"
  call circle -10,-10 - sin(frame)*10,10,"black"
  call circle 0,0,20,clr$
  call circle -20,0,10,clr$
  call circle 20,0,10,clr$
  call circle 0,-20,5,clr$
  call circle 8,-8,7,"white"
  call circle 8,-8,3,"black"
  call circle -8,-8,7,"white"
  call circle -8,-8,3,"black"
end sub
sub circle x , y , d , clr$
  call rotate x , y , pen( 2 )
  x = x + pen( 0 )
  y = y + pen( 1 )
  #m "goto " ; x ; " " ; y
  #m "color " ; clr$
  #m "backcolor " ; clr$
  #m "down"
  #m "circlefilled " ; d
  #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
sub setpen x , y , a
  pen( 0 ) = x
  pen( 1 ) = y
  pen( 2 ) = a
end sub
sub movepen x , y , a
   call rotate x , y , pen( 2 )
   call setpen pen( 0 ) + x , pen( 1 ) + y , pen( 2 ) + a
end sub
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