Poging om een 2D game engine te starten

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

Moderator: anthonio

Poging om een 2D game engine te starten

Berichtdoor Gordon » za dec 27, 2008 4:19 pm

Ik ben gestart met het maken van een soort 2D game engine.
Hier staat mijn poging.
http://www.lbdownloads.com/files/viewtopic.php?t=640

Het lukt nog niet zo goed.

Wie wil meedoen?


Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Re: Poging om een 2D game engine te starten

Berichtdoor Gordon » zo dec 28, 2008 3:26 pm

Ik kreeg van JB gebruikers te horen dat ze de listing niet kunnen gebruiken
(API calls)
Daarom heb ik een functie gemaakt om de API call te vervangen.

Code: Selecteer alles
open "test  Arrow keystates" for graphics as #m

#m "when characterInput [keyed]"
#m "setfocus"

wait

[keyed]
#m "place 50 50"
#m "\ ";GetAsyncKeyState(_VK_UP)
print "yep"
wait

function GetAsyncKeyState(key)
state = 0
    IF LEN(Inkey$) = 2 THEN key=ASC(right$(Inkey$,1)) ELSE key = 0
    SELECT CASE key
        CASE _VK_LEFT  : state = 1
        CASE _VK_UP    : state = 1
        CASE _VK_RIGHT : state = 1
        CASE _VK_DOWN  : state = 1
    END SELECT
GetAsyncKeyState = state

end function



Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Re: Poging om een 2D game engine te starten

Berichtdoor Gordon » di dec 30, 2008 3:00 pm

Hier is de listing.
Om de bewegende beelden te zien moet je eerst minstens de map GFX downloaden uit
http://www.lbdownloads.com/files/viewtopic.php?t=640

De onderstaande listing geeft een spin te zien die je kunt besturen met de pijltjes toetsen.
De linker en rechter pijltoetsen doen het beestje met of tegen de klok in draaien.
De up en down pijltjes toetsen laten het dier in de gegeven richting vooruit
en achteruit lopen en langzamer gaan.
Met de Control toets doet de spin een aanval.
Met de spatiebalk sterft het diertje.

Veel plezier.
Code: Selecteer alles
'Gordon
'LB version walks attacks dies and stays

nomainwin

WindowWidth=800
WindowHeight=600

global BitmapList$

Player1.speedmin=-5
Player1.speedmax=10
Player1.speedinc=1
Player1.angle=0
Player1.sprite = 1

Board.xl=0
Board.xu=WindowWidth
Board.yl=0
Board.yu=WindowHeight


UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
open "Spider attack" for graphics_nsb_nf as #m
#m "trapclose [main.quit]"


call LoadBitmap "bg","gfx\bg.bmp"
#m "background bg"

for i = 0 to 7
  call LoadBitmap "attack1";i+1,"gfx\attack e000";i;".bmp"
AttackBmpList1$=AttackBmpList1$ + " attack1";i+1
  call LoadBitmap "attack7";i+1,"gfx\attack n000";i;".bmp"
AttackBmpList7$=AttackBmpList7$ + " attack7";i+1
  call LoadBitmap "attack8";i+1,"gfx\attack ne000";i;".bmp"
AttackBmpList8$=AttackBmpList8$ + " attack8";i+1
  call LoadBitmap "attack6";i+1,"gfx\attack nw000";i;".bmp"
AttackBmpList6$=AttackBmpList6$ + " attack6";i+1
  call LoadBitmap "attack3";i+1,"gfx\attack s000";i;".bmp"
AttackBmpList3$=AttackBmpList3$ + " attack3";i+1
  call LoadBitmap "attack2";i+1,"gfx\attack se000";i;".bmp"
AttackBmpList2$=AttackBmpList2$ + " attack2";i+1
  call LoadBitmap "attack4";i+1,"gfx\attack sw000";i;".bmp"
AttackBmpList4$=AttackBmpList4$ + " attack4";i+1
  call LoadBitmap "attack5";i+1,"gfx\attack w000";i;".bmp"
AttackBmpList5$=AttackBmpList5$ + " attack5";i+1
next i

for i = 0 to 7
  call LoadBitmap "läuft1";i+1,"gfx\läuft e000";i;".bmp"
LauftBmpList1$=LauftBmpList1$ + " läuft1";i+1
  call LoadBitmap "läuft7";i+1,"gfx\läuft n000";i;".bmp"
LauftBmpList7$=LauftBmpList7$ + " läuft7";i+1
  call LoadBitmap "läuft8";i+1,"gfx\läuft ne000";i;".bmp"
LauftBmpList8$=LauftBmpList8$ + " läuft8";i+1
  call LoadBitmap "läuft6";i+1,"gfx\läuft nw000";i;".bmp"
LauftBmpList6$=LauftBmpList6$ + " läuft6";i+1
  call LoadBitmap "läuft3";i+1,"gfx\läuft s000";i;".bmp"
LauftBmpList3$=LauftBmpList3$ + " läuft3";i+1
  call LoadBitmap "läuft2";i+1,"gfx\läuft se000";i;".bmp"
LauftBmpList2$=LauftBmpList2$ + " läuft2";i+1
  call LoadBitmap "läuft4";i+1,"gfx\läuft sw000";i;".bmp"
LauftBmpList4$=LauftBmpList4$ + " läuft4";i+1
  call LoadBitmap "läuft5";i+1,"gfx\läuft w000";i;".bmp"
LauftBmpList5$=LauftBmpList5$ + " läuft5";i+1
next i

  call LoadBitmap "steht1","gfx\steht e.bmp"
  call LoadBitmap "steht7","gfx\steht n.bmp"
  call LoadBitmap "steht8","gfx\steht ne.bmp"
  call LoadBitmap "steht6","gfx\steht nw.bmp"
  call LoadBitmap "steht3","gfx\steht s.bmp"
  call LoadBitmap "steht2","gfx\steht se.bmp"
  call LoadBitmap "steht4","gfx\steht sw.bmp"
  call LoadBitmap "steht5","gfx\steht w.bmp"
StehtBmpList$ = " steht1 steht2 steht3 steht4 steht5 steht6 steht7 steht8"

for i = 0 to 8
  call LoadBitmap "stirbt";i+1,"gfx\stirbt000";i;".bmp"
StirbtBmpList$ = StirbtBmpList$ + " stirbt";i+1
next i

#m "addsprite PlayerSpiderSteht"+StehtBmpList$ '

#m "addsprite PlayerSpiderLauft1" + LauftBmpList1$
#m "cyclesprite PlayerSpiderLauft1 1"
#m "addsprite PlayerSpiderLauft2" + LauftBmpList2$
#m "cyclesprite PlayerSpiderLauft2 1"
#m "addsprite PlayerSpiderLauft3" + LauftBmpList3$
#m "cyclesprite PlayerSpiderLauft3 1"
#m "addsprite PlayerSpiderLauft4" + LauftBmpList4$
#m "cyclesprite PlayerSpiderLauft4 1"
#m "addsprite PlayerSpiderLauft5" + LauftBmpList5$
#m "cyclesprite PlayerSpiderLauft5 1"
#m "addsprite PlayerSpiderLauft6" + LauftBmpList6$
#m "cyclesprite PlayerSpiderLauft6 1"
#m "addsprite PlayerSpiderLauft7" + LauftBmpList7$
#m "cyclesprite PlayerSpiderLauft7 1"
#m "addsprite PlayerSpiderLauft8" + LauftBmpList8$
#m "cyclesprite PlayerSpiderLauft8 1"

#m "addsprite PlayerSpiderAttack1" + AttackBmpList1$
#m "cyclesprite PlayerSpiderAttack1 1"
#m "addsprite PlayerSpiderAttack2" + AttackBmpList2$
#m "cyclesprite PlayerSpiderAttack2 1"
#m "addsprite PlayerSpiderAttack3" + AttackBmpList3$
#m "cyclesprite PlayerSpiderAttack3 1"
#m "addsprite PlayerSpiderAttack4" + AttackBmpList4$
#m "cyclesprite PlayerSpiderAttack4 1"
#m "addsprite PlayerSpiderAttack5" + AttackBmpList5$
#m "cyclesprite PlayerSpiderAttack5 1"
#m "addsprite PlayerSpiderAttack6" + AttackBmpList6$
#m "cyclesprite PlayerSpiderAttack6 1"
#m "addsprite PlayerSpiderAttack7" + AttackBmpList7$
#m "cyclesprite PlayerSpiderAttack7 1"
#m "addsprite PlayerSpiderAttack8" + AttackBmpList8$
#m "cyclesprite PlayerSpiderAttack8 1"

#m "addsprite PlayerSpiderStirbt" + StirbtBmpList$ '
#m "cyclesprite PlayerSpiderStirbt 1"

Timer.interval=32

#m "when mouseMove [mousemove]"
#m "when leftButtonMove [mousemove]"

timer Timer.interval,[draw]

MouseX=100
MouseY=100
wait

[main.quit]
call UnloadBitmaps
close #m
end

[mousemove]
wait

[draw]
timer 0


    if Player1.speed = 0 then
        up = 0 :at = 0:die = 0
        for i = 1 to 8
        #m "spritevisible PlayerSpiderLauft";i;" off"  'Player1.sprite;" off"
        #m "spritevisible PlayerSpiderAttack";i;" off"
        #m "spritevisible PlayerSpiderStirbt off"
        next i
    end if

  'calldll #kernel32, "Sleep",1 as long,t as void
  if GetAsyncKeyState(_VK_LEFT) then
  Player1.angle=Player1.angle-45:Player1.sprite=Player1.sprite-1
  end if

  if GetAsyncKeyState(_VK_RIGHT) then
  Player1.angle=Player1.angle+45:Player1.sprite=Player1.sprite+1
  end if

  if GetAsyncKeyState(_VK_UP) then
    up = 1
    Player1.speed=Player1.speed+Player1.speedinc
    if Player1.speed>Player1.speedmax then Player1.speed=Player1.speedmax
  else
    if Player1.speed>0 then Player1.speed=Player1.speed-Player1.speedinc
  end if

  if GetAsyncKeyState(_VK_CONTROL) then
    at = 1
  end if

  if GetAsyncKeyState(_VK_SPACE) then
    die = 1
  end if

  if GetAsyncKeyState(_VK_DOWN) then
    up = 1
    Player1.speed=Player1.speed-Player1.speedinc
    if Player1.speed<Player1.speedmin then Player1.speed=Player1.speedmin
  else
    if Player1.speed<0 then Player1.speed=Player1.speed+Player1.speedinc
  end if


  Player1.dx=Player1.speed*cos(deg2rad(Player1.angle))
  Player1.dy=Player1.speed*sin(deg2rad(Player1.angle))

  Player1.x=Player1.x+Player1.dx
  Player1.y=Player1.y+Player1.dy

  if Player1.angle<=0 then
    Player1.angle=360+Player1.angle
    Player1.sprite=8  '32
  end if
  if Player1.angle>=360 then
    Player1.angle=0+(Player1.angle-360)
    Player1.sprite=1
  end if

  if Player1.x<Board.xl then Player1.x=Board.xl:Player1.dx=0
  if Player1.x>Board.xu then Player1.x=Board.xu:Player1.dx=0
  if Player1.y<Board.yl then Player1.y=Board.yl:Player1.dy=0
  if Player1.y>Board.yu then Player1.y=Board.yu:Player1.dy=0

     #m "spritexy PlayerSpiderSteht ";Player1.x;" ";Player1.y
     #m "spriteimage PlayerSpiderSteht steht";Player1.sprite

    if up = 1 then
        #m "spritevisible PlayerSpiderLauft";Player1.sprite;" on"
        #m "spritexy PlayerSpiderLauft";Player1.sprite;" ";Player1.x;" ";Player1.y
     '#m "spriteimage PlayerSpiderLauft";Player1.sprite;" läuft1";Player1.sprite
    end if

    if at = 1 then
        #m "spritevisible PlayerSpiderAttack";Player1.sprite;" on"
        #m "spritexy PlayerSpiderAttack";Player1.sprite;" ";Player1.x;" ";Player1.y
     '#m "spriteimage PlayerSpiderLauft";Player1.sprite;" läuft1";Player1.sprite
    end if

    if die = 1 then

        #m "spritevisible PlayerSpiderSteht off"
        #m "spritevisible PlayerSpiderStirbt on"
        #m "spritexy PlayerSpiderStirbt ";Player1.x;" ";Player1.y

        for t = 0 to 8
        #m "drawsprites"
        for t1 = 1 to 10000 :next t1
        next t
        #m "spriteimage PlayerSpiderStirbt stirbt";Player1.sprite
        wait
     end if

    #m "drawsprites"

timer Timer.interval,[draw]
wait


sub LoadBitmap name$,file$
  loadbmp name$,file$
  BitmapList$=BitmapList$+name$+"-"
end sub
sub UnloadBitmaps
 i=1
 while word$(BitmapList$,i,"-")<>""
   unloadbmp word$(BitmapList$,i,"-")
   i=i+1
 wend
end sub

function GetAsyncKeyState(key)
  calldll #user32, "GetAsyncKeyState",_
    key as long,ret as long
  if ret<>0 then GetAsyncKeyState=1
end function

function rad2deg(num)
    rad2deg = 90 / asn(1) * num
end function

function deg2rad(num)
    deg2rad = asn(1) / 90 * num
end function



Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Re: Poging om een 2D game engine te starten

Berichtdoor bluatigro » ma feb 13, 2012 12:16 pm

bedoel je zoiets :
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
nomainwin
global winx , winy , px , py , pa , frame , pi
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
open "" for graphics as #m
  #m "trapclose [quit]"
  timer 40 , [tmr]
wait
[tmr]
  #m "cls"
  frame = frame + 1
  call pen 0 , 0 ,frame * 2
  call lijn 0 , 0 , 0 , 200 , 10 , "yellow"
  call circle 0 , 0 , 20 , 5 , "blue" , "darkblue"
  call circle 0 , 200 , 20 , 5 , "red" , "darkred"
  call move 0 , 200 , frame * -3
  call circle 0 , 130 , 20 , 5 , "green" , "darkgreen"
  call pen 0,0,frame * 2
  call move 0 , 200 , frame * 3
  call circle 0 , 70 , 20 , 5 , "cyan" , "darkcyan"
wait
sub lijn x1 , y1 , x2 , y2 , t , kl$
  call spot x1 , y1
  call spot x2 , y2
  #m "size " ; t
  #m "color "; kl$
  #m "down"
  #m "line " ; winx / 2 + x1 ; " " ; winy / 2 - y1 _
  ; " " ; winx / 2 + x2 ; " " ; winy / 2 - y2
  #m "up"
end sub
sub circle x , y , r , t , pen$ , brush$
  call spot x , y
  #m "size " ; t
  #m "color " ; pen$
  #m "backcolor " ; brush$
  #m "goto " ; winx / 2 + x ; " " ; winy / 2 - y
  #m "down"
  #m "circlefilled " ; r
  #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
[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