game : lander

General FreeBASIC programming questions.
bluatigro
Posts: 597
Joined: Apr 25, 2012 10:35
Location: netherlands

game : lander

Postby bluatigro » Jun 06, 2018 11:17

old idea

error :
trans gives no trasparent black
color of flame is not good

Code: Select all

'' bluatigro 6 jun 2018
'' lander

#include "_sprite.bas"
#include "_color.bas"
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif



screen 20 , 32  , 2
dim as sprite lander( 1 )
lander( 0 ).create 100 , 100
lander( 1 ).create 100 , 100
dim as integer i
line lander( 0 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 0 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 0 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i
line lander( 1 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 1 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 1 ).image , ( 50 , 70 + i / 6 ) , i / 2 _
  , colormix( yellow , i / 40 , blue ) ,,,2, f 
  circle lander( 1 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i

dim as double delta_drop_speed = 0 , fuel = 100
lander( 0 ).posx = 1024 / 2 - 50
lander( 1 ).posx = 1024 / 2 - 50

do
  cls
  line ( 0 , 600 ) - ( 1024 , 800 ) , red , bf
  line ( 25 , 600 ) - step( 25 , -fuel * 5 ) , cyan , bf
  if multikey( sc_up ) and lander( 0 ).posy > 0 then
    lander( 1 ).show
    delta_drop_speed -= 1
    fuel -= 1
    if fuel < 0 then fuel = 0
  else
    lander( 0 ).show
  end if
  delta_drop_speed += .1
  lander( 0 ).speedy += delta_drop_speed
  lander( 1 ).speedy += delta_drop_speed
  lander( 0 ).update
  lander( 1 ).update
  sleep 40
  flip
loop until inkey = chr( 27 ) or lander( 0 ).posy > 600
locate 10 , 20
print "GAME OVER"
locate 20 , 20
if lander( 0 ).speedy > 5 then
  print "Pitty on you : you crased !!"
else
  print "You landed savely !!"
end if
locate 25 , 20
print "[ push return ]"
sleep

Code: Select all

'' bluatigro 6 jun 2018
'' sprite

type sprite
public :
  dim as double posx,posy,speedx,speedy,sizex,sizey
  dim as any ptr image
  declare sub create ( a as double , b as double )
  declare sub show()
  declare sub update()
  declare function hit( q as sprite ) as integer
end type
sub sprite.create( w as double , h as double )
  sizex = w
  sizey = h
  image = imagecreate( sizex , sizey , rgba(0,0,0,0) )
end sub
sub sprite.show()
  put ( posx , posy ) , image , trans
end sub
sub sprite.update()
  posx += speedx
  posy += speedy
end sub
function sprite.hit( q as sprite ) as integer
  if posx + sizex < q.posx then return 0
  if posx > q.posx + q.sizey then return 0
  if posy + sizey < q.posy then return 0
  if posy > q.posy + q.sizey then return 0
  return 1
end function

Code: Select all

'' bluatigro 6 jun 2018
'' color

const as uinteger black   = rgb(   0 ,   0 ,   0 )
const as uinteger red     = rgb( 255 ,   0 ,   0 )
const as uinteger green   = rgb(   0 , 255 ,   0 )
const as uinteger yellow  = rgb( 255 , 255 ,   0 )
const as uinteger blue    = rgb(   0 ,   0 , 255 )
const as uinteger magenta = rgb( 255 ,   0 , 255 )
const as uinteger cyan    = rgb(   0 , 255 , 255 )
const as uinteger white   = rgb( 255 , 255 , 255 )

const as uinteger gray    = rgb( 127 , 127 , 127 )
const as uinteger orange  = rgb( 255 , 127 , 0 )
const as uinteger pink    = rgb( 255 , 127 , 127 )

function colormix( color1 as uinteger _
  , f as double , color2 as uinteger ) as uinteger
  dim as integer r1,g1,b1,r2,g2,b2,r,g,b
  r1 = color1 and 255
  g1 = ( color1 shr 8 ) and 255
  b1 = ( color1 shr 16 ) and 255
  r2 = color2 and 255
  g2 = ( color2 shr 8 ) and 255
  b2 = ( color2 shr 16 ) and 255
  r = r1 + ( r2 - r1 ) * f
  g = g1 + ( g2 - g1 ) * f
  b = b1 + ( b2 - b1 ) * f
  return rgb( r , g , b )
end function
 
bluatigro
Posts: 597
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: game : lander

Postby bluatigro » Jun 06, 2018 11:48

update :
added countdown + fuelnumber %

Code: Select all

'' bluatigro 6 jun 2018
'' lander

#include "_sprite.bas"
#include "_color.bas"
#include "_text.bas"
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif



screen 20 , 32  , 2
dim as sprite lander( 1 )
lander( 0 ).create 100 , 100
lander( 1 ).create 100 , 100
dim as integer i , state = 9 * 25
line lander( 0 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 0 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 0 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i
line lander( 1 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 1 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 1 ).image , ( 50 , 70 + i / 6 ) , i / 2 _
  , colormix( yellow , i / 40 , blue ) ,,,2, f 
  circle lander( 1 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i

dim as double delta_drop_speed = 0 , fuel = 100
lander( 0 ).posx = 1024 / 2 - 50
lander( 1 ).posx = 1024 / 2 - 50

do
  cls
  line ( 0 , 600 ) - ( 1024 , 800 ) , red , bf
  line ( 25 , 600 ) - step( 25 , -fuel * 5 ) , cyan , bf
  text 50 , 50 , str( fuel ) + "%" , 2 , white
  if state > 0 then
    text 200 , 50 , str( int( state / 25 ) ) , 5 , white
    state -= 1
  end if
  if multikey( sc_up ) _
  and lander( 0 ).posy > 0 _
  and state = 0 then
    lander( 1 ).show
    delta_drop_speed -= .3
    fuel -= 1
    if fuel < 0 then fuel = 0
  else
    lander( 0 ).show
  end if
  if state = 0 then delta_drop_speed += .02
  lander( 0 ).speedy += delta_drop_speed
  lander( 1 ).speedy += delta_drop_speed
  lander( 0 ).update
  lander( 1 ).update
  sleep 40
  flip
loop until inkey = chr( 27 ) or lander( 0 ).posy > 600
locate 10 , 20
print "GAME OVER"
locate 20 , 20
if lander( 0 ).speedy > 5 then
  print "Pitty on you : you crased !!"
else
  print "You landed savely !!"
end if
locate 25 , 20
print "[ push return ]"
sleep

Code: Select all

'' bluatirgo 6 jun 2018
'' text
dim shared as integer letterpart( 40 , 7 )
dim as integer j , k
const as string letters = "abcdefghijklmnopqrstuvwxyz0123456789[]=%"
dim as string q
for i as byte = 1 to len( letters )
  for j = 0 to 7
    read q
    for k = 0 to 7
      if mid( q , k + 1 , 1 ) = "1" then
        letterpart( i , j ) = letterpart( i , j ) or 2 ^ k
      end if
    next k
  next j
next i

''a
data "...1...."
data "..111..."
data ".1...1.."
data "1.....1."
data "1111111."
data "1.....1."
data "1.....1."
data "1.....1."
''b
data "1111...."
data "1...1..."
data "1....1.."
data "1....1.."
data "111111.."
data "1.....1."
data "1.....1."
data "111111.."
''c
data "..111..."
data ".1...1.."
data "1.....1."
data "1......."
data "1......."
data "1.....1."
data ".1...1.."
data "..111..."
''d
data "11111..."
data "1....1.."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1....1.."
data "11111..."
''e
data "1111111."
data "1.....1."
data "1......."
data "1......."
data "111111.."
data "1......."
data "1.....1."
data "1111111."
''f
data "1111111."
data "1.....1."
data "1......."
data "1......."
data "111111.."
data "1......."
data "1......."
data "1......."
''g
data "..111..."
data ".1...1.."
data "1.....1."
data "1......."
data "1...111."
data "1.....1."
data ".1...1.."
data "..111..."
''h
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1111111."
data "1.....1."
data "1.....1."
data "1.....1."
''i
data "..111..."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "..111..."
''j
data "..111..."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "1..1...."
data "1..1...."
data ".11...."
''k
data "1......."
data "1.....1."
data "1....1.."
data "1...1..."
data "1111...."
data "1...1..."
data "1....1.."
data "1.....1."
''l
data "1......."
data "1......."
data "1......."
data "1......."
data "1......."
data "1......."
data "1......."
data "1111111."
''m
data "1.....1."
data "11...11."
data "1.1.1.1."
data "1..1..1."
data "1..1..1."
data "1.....1."
data "1.....1."
data "1.....1."
''n
data "1.....1."
data "11....1."
data "1.1...1."
data "1..1..1."
data "1..1..1."
data "1...1.1."
data "1....11."
data "1.....1."
''o
data "..111..."
data ".1...1.."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data ".1...1.."
data "..111..."
''p
data "11111..."
data "1....1.."
data "1.....1."
data "1....1.."
data "11111..."
data "1.....,."
data "1......."
data "1......."
''q
data "..111..."
data ".1...1.."
data "1.....1."
data "1.....1."
data "1..1..1."
data "1...1.1."
data ".1...1.."
data "..111.1."
''r
data "11111..."
data "1....1.."
data "1.....1."
data "1....1.."
data "111111.."
data "1...1..."
data "1....1.."
data "1.....1."
''s
data "..111..."
data ".1...1.."
data "1.....1."
data "1......."
data ".11111.."
data "......1."
data "1.....1."
data ".11111.."
''t
data "1111111."
data "1..1..1."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "...1...."
data "..111..."
''u
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data ".11111.."
''v
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data ".1...1.."
data "..1.1..."
data "...1...."
''w
data "1.....1."
data "1.....1."
data "1.....1."
data "1.....1."
data "1..1..1."
data "1.1.1.1."
data "11...11."
data "1.....1."
''x
data "1.....1."
data ".1...1.."
data "..1.1.."
data "...1...."
data "...1...."
data "..1.1..."
data ".1...1.."
data "1.....1."
''y
data "1.....1."
data ".1...1.."
data "..1.1.."
data "...1...."
data "...1...."
data "..1....."
data ".1......"
data "1......."
''z
data "1111111."
data ".....1.."
data "....1..."
data "...1...."
data "...1...."
data "..1....."
data ".1......"
data "1111111."
''0
data ".11111.."
data "1.....1."
data "1.....1."
data "1.....1."
data "........"
data "1.....1."
data "1.....1."
data ".11111.."
''1
data "........"
data "......1."
data "......1."
data "......1."
data "........"
data "......1."
data "......1."
data "........"
''2
data ".11111.."
data "......1."
data "......1."
data "......1."
data ".11111.."
data "1......."
data "1......."
data ".11111.."
''3
data ".11111.."
data "......1."
data "......1."
data "......1."
data ".11111.."
data "......1."
data "......1."
data ".11111.."
''4
data "........"
data "1.....1."
data "1.....1."
data "1.....1."
data ".11111.."
data "......1."
data "......1."
data "........"
''5
data ".11111.."
data "1......."
data "1......."
data "1......."
data ".11111.."
data "......1."
data "......1."
data ".11111.."
''6
data ".11111.."
data "1......."
data "1......."
data "1......."
data ".11111.."
data "1.....1."
data "1.....1."
data ".11111.."
''7
data ".11111.."
data "......1."
data "......1."
data "......1."
data "........"
data "......1."
data "......1."
data "........"
''8
data ".11111.."
data "1.....1."
data "1.....1."
data "1.....1."
data ".11111.."
data "1.....1."
data "1.....1."
data ".11111.."
''9
data ".11111.."
data "1.....1."
data "1.....1."
data "1.....1."
data ".11111.."
data "......1."
data "......1."
data ".11111.."
''[
data "..1111.."
data "..1....."
data "..1....."
data "..1....."
data "..1....."
data "..1....."
data "..1....."
data "..1111.."
'']
data "..1111..."
data ".....1.."
data ".....1.."
data ".....1.."
data ".....1.."
data ".....1.."
data ".....1.."
data "..1111.."
''=
data "........"
data "........"
data "..1111.."
data "........"
data "........"
data "..1111.."
data "........"
data "........"

data "111....1"
data "1.1...1."
data "111..1.."
data "....1..."
data "...1...."
data "..1..111"
data ".1...1.1"
data "1....111"

sub digit( x as integer , y as integer , b as integer , d as double , kl as ulong )
  dim as integer i , j
  for i = 0 to 7
    for j = 0 to 7
      if ( letterpart( b , i ) and 2 ^ j ) <> 0 then
        circle ( x + j * d - 3 * d , y + i * d - 3 * d ) , d / 2 , kl ,,,, f
      end if
    next j
  next i
end sub
const as ulong transparent = &h1000000
sub text( x as integer , y as integer _
  , t as string , d as double _
  , kl as ulong , bkl as ulong = transparent )
  dim as integer i , l = len( t )
  if bkl < transparent then
    line ( x - l * 4 * d + d * 4 , y - 4 * d ) _
    - step ( l * 8 * d + d * 4 , 9 * d ) , bkl , bf
  end if
  for i = 1 to l
    digit x + i * 8 * d - l * 4 * d , y _
    , instr( letters , lcase( mid( t , i , 1 ) ) ) , d , kl
  next i
end sub
dodicat
Posts: 5945
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: game : lander

Postby dodicat » Jun 06, 2018 12:39

Transparent is
imagecreate( sizex , sizey , rgb(255,0,255) )
or simply
imagecreate( sizex , sizey )
because rgb(255,0,255) is the 32 bit default image colour (transparent)
bluatigro
Posts: 597
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: game : lander

Postby bluatigro » Jun 09, 2018 9:52

@ dodicat
thans for that it helped

update :
sprite back is transparent now
last version of big chars added in game

error :
the ship flies somtimes away

Code: Select all

'' bluatigro 9 jun 2018
'' lander

#include "_sprite.bas"
#include "_color.bas"
#include "_big_chars.bas"
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif

dim as sprite lander( 1 )
lander( 0 ).create 100 , 100
lander( 1 ).create 100 , 100
dim as integer i , state = 9 * 25
line lander( 0 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 0 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 0 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i
line lander( 1 ).image , ( 25 , 25 ) - ( 30 , 100 ) , gray , bf
line lander( 1 ).image , ( 75 , 25 ) - ( 70 , 100 ) , gray , bf
for i = 40 to 1 step -1
  circle lander( 1 ).image , ( 50 , 70 + i / 6 ) , i / 2 _
  , colormix( yellow , i / 40 , blue ) ,,,2, f 
  circle lander( 1 ).image , ( 50 , 25 + i / 3 ) , i _
  , colormix( white , i / 40 , gray ) ,,,.5, f
next i

dim as double delta_drop_speed = 0 , fuel = 100
lander( 0 ).posx = 1024 / 2 - 50
lander( 1 ).posx = 1024 / 2 - 50

do
  cls
  line ( 0 , 600 ) - ( 1024 , 800 ) , red , bf
  line ( 25 , 600 ) - step( 25 , -fuel * 5 ) , cyan , bf
  text 100 , 50 , str( fuel ) + "%" , 3 , white
  if state > 0 then
    text 200 , 50 , str( int( state / 25 ) ) , 7 , white
    state -= 1
  end if
  if multikey( sc_up ) _
  and lander( 0 ).posy > 0 _
  and state = 0 then
    lander( 1 ).show
    delta_drop_speed -= .3
    fuel -= 1
    if fuel < 0 then fuel = 0
  else
    lander( 0 ).show
  end if
  if state = 0 then delta_drop_speed += .02
  lander( 0 ).speedy += delta_drop_speed
  lander( 1 ).speedy += delta_drop_speed
  lander( 0 ).update
  lander( 1 ).update
  sleep 40
  flip
loop until inkey = chr( 27 ) or lander( 0 ).posy > 600

text winx / 2 , winy / 4 , "GAME OVER" , 7 , white
if lander( 0 ).speedy > 5 then
  text winx / 2 , winy / 2 _
  , "Pitty on you : you crased !!" , 5 , red
else
  text winx / 2 , winy / 2 _
  , "You landed savely !!" , 5 , white
end if
text winx / 2 , winy * 3 / 4 _
, "[ push return ]" , 5 , cyan
sleep

Code: Select all

'' bluatigro 9 jun 2018
'' automatic big chars

dim shared as integer letterpart( 255 , 8 )
dim as integer char , ix , iy

#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
  Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif

DIM shared AS INTEGER winx, winy, bitdepth , nu
SCREENINFO winx , winy , bitdepth
SCREENRES winx , winy , 32 , 2 , FB.GFX_FULLSCREEN

for char = 30 to 255
  cls
  print chr( char )
  for ix = 0 to 8
    for iy = 0 to 8
      if point( ix , iy ) <> -16777216 then
        letterpart( char , iy ) += 2 ^ ix
      end if
    next iy
  next ix
next char

sub digit( a as double , b as double _
  , q as double , d as double  , kl as ulong )
  dim as double x , y
  for x = 0 to 8
    for y = 0 to 8
      if letterpart( q , y ) and 2 ^ x then
        circle( a + ( x - 4 ) * d , b + ( y - 4 ) * d ) _
        , d / 2 , kl ,,,, f
      end if
    next y
  next x
end sub

sub text( a as double , b as double , txt as string _
  , d as double , kl as ulong )
  dim as double l = len( txt ) , x
  for x = 1 to l
    digit a + ( x - l / 2 - 1 ) * d * 8 , b _
    , asc( mid( txt , x , 1 ) ) , d , kl
  next x
end sub

       
       
       
       
       

Code: Select all

'' bluatigro 9 jun 2018
'' sprite

type sprite
public :
  dim as double posx,posy,speedx,speedy,sizex,sizey
  dim as any ptr image
  declare sub create ( a as double , b as double )
  declare sub show()
  declare sub update()
  declare function hit( q as sprite ) as integer
end type
sub sprite.create( w as double , h as double )
  sizex = w
  sizey = h
  image = imagecreate( sizex , sizey , rgb(255,0,255) )
end sub
sub sprite.show()
  put ( posx , posy ) , image , trans
end sub
sub sprite.update()
  posx += speedx
  posy += speedy
end sub
function sprite.hit( q as sprite ) as integer
  if posx + sizex < q.posx then return 0
  if posx > q.posx + q.sizey then return 0
  if posy + sizey < q.posy then return 0
  if posy > q.posy + q.sizey then return 0
  return 1
end function


Code: Select all

'' bluatigro 6 jun 2018
'' color

const as uinteger black   = rgb(   0 ,   0 ,   0 )
const as uinteger red     = rgb( 255 ,   0 ,   0 )
const as uinteger green   = rgb(   0 , 255 ,   0 )
const as uinteger yellow  = rgb( 255 , 255 ,   0 )
const as uinteger blue    = rgb(   0 ,   0 , 255 )
const as uinteger magenta = rgb( 255 ,   0 , 255 )
const as uinteger cyan    = rgb(   0 , 255 , 255 )
const as uinteger white   = rgb( 255 , 255 , 255 )

const as uinteger gray    = rgb( 127 , 127 , 127 )
const as uinteger orange  = rgb( 255 , 127 , 0 )
const as uinteger pink    = rgb( 255 , 127 , 127 )

function colormix( color1 as uinteger _
  , f as double , color2 as uinteger ) as uinteger
  dim as integer r1,g1,b1,r2,g2,b2,r,g,b
  r1 = color1 and 255
  g1 = ( color1 shr 8 ) and 255
  b1 = ( color1 shr 16 ) and 255
  r2 = color2 and 255
  g2 = ( color2 shr 8 ) and 255
  b2 = ( color2 shr 16 ) and 255
  r = r1 + ( r2 - r1 ) * f
  g = g1 + ( g2 - g1 ) * f
  b = b1 + ( b2 - b1 ) * f
  return rgb( r , g , b )
end function
 

Return to “General”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 49 guests