sprite pixel

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

Moderator: anthonio

sprite pixel

Berichtdoor bluatigro » wo jul 25, 2012 10:22 am

dit is n 2D engine
t gebruikt sprites als pixels
nu kan je makkelijker n game bouwen
dat is gebaseerd op blokjes

the pit en drop zone zijn voorbeelden wat je met dit kan doen
Code: Selecteer alles
dim p( 40 , 30 )
global hx , hy , stonest , winx , winy , stonex , stoney , sec
global black , red , green , yellow , blue , pink , cyan , white
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
winx = WindowWidth
winy = WindowHeight
black = 0
red = 1
green = 2
yellow = 3
blue = 4
pink = 5
cyan = 6
white = 7
nomainwin
faling = not( 0 )
open "sprite pixel" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp bmp 0 0 1 1"
  #m "background bmp"
  #m "getbmp black 0 0 20 40"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 20 20"
  #m "up"
  #m "goto 0 20"
  #m "backcolor red"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp red 0 0 20 40"
  #m "backcolor green"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp green 0 0 20 40"
  #m "backcolor yellow"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp yellow 0 0 20 40"
  #m "backcolor blue"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp blue 0 0 20 40"
  #m "backcolor pink"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp pink 0 0 20 40"
  #m "backcolor cyan"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp cyan 0 0 20 40"
  #m "backcolor white"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp white 0 0 20 40"
  #m "backcolor lightgray"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp gray 0 0 20 40"
  for x = 0 to 40
    for y = 0 to 30
      #m "addsprite " ; p$( x , y ) _
      ; " black red green blue yellow pink cyan white"
      #m "spritexy " ; p$( x , y ) _
      ; " " ; winx / 2 - 400 + x * 20 _
      ; " " ; winy / 2 - 300 + y * 20
    next y
  next x
  #m "addsprite human gray"
  #m "when characterInput [key]"
  #m "setfocus"
  call restart
  call drawpit
 '' timer 250 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
  sec = sec + .25

''TODO : game logic here

  lastkey$ = ""
  call drawpit
wait
function p$( x , y )
  p$ = "p" ; x ; "_" ; y
end function
sub restart

''TODO : create spritepixelgrid and player and enemy's start postions

''this is a spritepixel example
''feel free to change
  for x = 0 to 40
    for y = 0 to 30
      p( x , y ) = int( rnd( 0 ) * 7 + 1 )
    next y
  next x
  hx = 20
  hy = 15
  sec = 0
end sub
sub drawpit
  for x = 0 to 40
    for y = 0 to 30
      select case p( x , y )
        case black
          #m "spriteimage " ; p$( x , y ) ; " black"
        case red
          #m "spriteimage " ; p$( x , y ) ; " red"
        case green
          #m "spriteimage " ; p$( x , y ) ; " green"
        case yellow
          #m "spriteimage " ; p$( x , y ) ; " yellow"
        case blue
          #m "spriteimage " ; p$( x , y ) ; " blue"
        case pink
          #m "spriteimage " ; p$( x , y ) ; " pink"
        case cyan
          #m "spriteimage " ; p$( x , y ) ; " cyan"
        case else
          #m "spriteimage " ; p$( x , y ) ; " white"
      end select
    next y
  next x
  #m "spritexy human " _
  ; winx / 2 - 400 + hx * 20 ; " " _
  ; winy / 2 - 300 + hy * 20
  #m "drawsprites"
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