## maze walk

Game development specific discussions.
bluatigro
Posts: 424
Joined: Apr 25, 2012 10:35
Location: netherlands

### maze walk

opject of the game :
walk trou enless mazes

error :
if you solve the first maze the second is not created

Code: Select all

`''bluatigro 5 jan 2017''maze test#include "color.bas"#include "_maze2d.bas"#include "fbgfx.bi"#if __FB_LANG__ = "fb"  Using FB #endifscreen 20 , 32create_new_maze 0 , 30 , 20maze( mazemaxx - 1 , mazemaxy - 1 ) = 2dim as integer x , y , tel = 1 , px = 1 , py = 1 , dx , dydo  screenlock    cls    for x = 0 to mazemaxx      for y = 0 to mazemaxy        if maze( x , y ) = 1 then          line ( x * 32 , y * 32 ) - step ( 31 , 31 ) , blue , bf        end if        if maze( x , y ) = 2 then          circle ( x * 32 + 16 , y * 32 + 16 ) , 7 , green ,,,, f        end if      next y    next x    circle ( px * 32 + 16 , py * 32 + 16 ) , 10 , yellow ,,,, f  screenunlock  dx = 0  dy = 0  if multikey( sc_up ) then dy = -1  if multikey( sc_down ) then dy = 1  if multikey( sc_left ) then dx = -1  if multikey( sc_right ) then dx = 1  if maze( px + dx , py + dy ) = 1 then    dx = 0    dy = 0  end if  px += dx  py += dy  if px = mazemaxx - 1 _  and py = mazemaxy - 1 then    px = 1    py = 1    create_new_maze tel , 30 , 20    tel += 1  end if  sleep 250loop until inkey = chr( 27 )    `

Code: Select all

`''bluatigro 5 jan 2017''game lib : 2d maze generationtype wall  as integer wallx, wally, roomx, roomyend typedim shared as integer mazemaxx = 10dim shared as integer mazemaxy = 10dim shared as integer maze( mazemaxx , mazemaxy )dim shared as wall walls( mazemaxx * mazemaxy )dim shared as integer maxwallsub create_new_maze( seed as integer , w as integer , h as integer )  mazemaxx = w  mazemaxy = h  redim as integer maze( mazemaxx , mazemaxy )  redim as wall walls( mazemaxx * mazemaxy )  maxwall = 0  dim as integer x , y  for x = 0 to mazemaxx    for y = 0 to mazemaxy      maze( x , y ) = 1    next y  next x    if seed >= 0 then    randomize seed  else    randomize timer  end if  walls( 0 ).roomx = 1  walls( 0 ).roomy = 1  walls( 0 ).wallx = 1  walls( 0 ).wally = 1  do    x = int(rnd * (1 + maxwall))      if walls( x ).roomx >= 0 and walls( x ).roomx <= mazemaxx _    and walls( x ).roomy >= 0 and walls( x ).roomy <= mazemaxy then      if maze( walls( x ).roomx , walls( x ).roomy ) then        maze( walls( x ).roomx , walls( x ).roomy ) = 0        maze( walls( x ).wallx , walls( x ).wally ) = 0              walls( maxwall + 1 ).wallx = walls( x ).roomx - 1        walls( maxwall + 1 ).wally = walls( x ).roomy        walls( maxwall + 1 ).roomx = walls( x ).roomx - 2        walls( maxwall + 1 ).roomy = walls( x ).roomy              walls( maxwall + 2 ).wallx = walls( x ).roomx        walls( maxwall + 2 ).wally = walls( x ).roomy + 1        walls( maxwall + 2 ).roomx = walls( x ).roomx        walls( maxwall + 2 ).roomy = walls( x ).roomy + 2              walls( maxwall + 3 ).wallx = walls( x ).roomx        walls( maxwall + 3 ).wally = walls( x ).roomy - 1        walls( maxwall + 3 ).roomx = walls( x ).roomx        walls( maxwall + 3 ).roomy = walls( x ).roomy - 2              walls( maxwall + 4 ).wallx = walls( x ).roomx + 1        walls( maxwall + 4 ).wally = walls( x ).roomy        walls( maxwall + 4 ).roomx = walls( x ).roomx + 2        walls( maxwall + 4 ).roomy = walls( x ).roomy              maxwall += 4      end if    end if      walls( x ).wallx = walls( maxwall ).wallx    walls( x ).wally = walls( maxwall ).wally    walls( x ).roomx = walls( maxwall ).roomx    walls( x ).roomy = walls( maxwall ).roomy    maxwall -= 1  loop until maxwall = -1end sub`

Code: Select all

`''bluatigro 13 feb 2015''color.bas''some colors consts + functions#ifndef COLOR_H#define COLOR_H#include "math.bas"''primary colorsconst as ulong black      = &hff000000const as ulong red        = &hffff0000const as ulong green      = &hff00ff00const as ulong yellow     = &hffffff00const as ulong blue       = &hff0000ffconst as ulong magenta    = &hffff00ffconst as ulong cyan       = &hff00ffffconst as ulong white      = &hffffffff''mix colorsconst as ulong orange     = &hffff7f00const as ulong gray       = &hff7f7f7fconst as ulong pink       = &hffff7f7fconst as ulong purple     = &hff7f007fconst as ulong darkRed    = &hff7f0000const as ulong darkYellow = &hff7f7f00const as ulong darkGreen  = &hff007f00const as ulong darkBlue   = &hff00007ffunction mix( kla as ulong , f as single , klb as ulong ) as ulong  dim as ulong ra , ga , ba , rb , gb , bb , r , g , b   ra = ( kla shr 16 ) and 255  ga = ( kla shr 8 ) and 255  ba = kla and 255  rb = ( klb shr 16 ) and 255  gb = ( klb shr 8 ) and 255  bb = klb and 255  r = ra + ( rb - ra ) * f  g = ga + ( gb - ga ) * f  b = ba + ( bb - ba ) * f  return rgb( r , g , b )end functionfunction rainbow( x as single ) as ulong  dim as ulong r , g , b  r = sin( rad( x ) ) * 127 + 128  g = sin( rad( x - 120 ) ) * 127 + 128  b = sin( rad( x + 120 ) ) * 127 + 128  return rgb( r , g , b )end function function rndcolor() as ulong  return rgb( rnd * 255 , rnd * 255 , rnd * 255 )end function#endif`

Code: Select all

`''bluatigro 30-dec-2013''game + animation lib : ''some math const[s] + function[s]#ifndef MATH_H#define MATH_Hconst as Single pi    = CSng( atn( 1.0 ) * 4.0 )const as Single golden_ratio = CSng( ( sqr(5.0) - 1.0 ) / 2.0 )function rad( x as single ) as single''help function degrees to radians   return x * pi / 180end functionfunction degrees( x as single ) as single  return x * 180 / piend functionfunction range( l as single , h as single ) as single  return rnd * ( h - l ) + lend function#endif`
bluatigro
Posts: 424
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: maze walk

update :
bigger maze
scroling maze

Code: Select all

`''bluatigro 5 jan 2017''maze test#include "color.bas"#include "_maze2d.bas"#include "fbgfx.bi"#if __FB_LANG__ = "fb"  Using FB #endifscreen 20 , 32create_new_maze 0 , 100 , 100maze( mazemaxx - 1 , mazemaxy - 1 ) = 2dim as integer x , y , tel = 1 , px = 1 , py = 1 , dx , dydo  screenlock    cls    for x = 0 to mazemaxx      for y = 0 to mazemaxy        if maze( x , y ) = 1 then          line ( 1024/2 + x * 32 - px * 32 _          , 768/2 + y * 32 - py * 32 ) - step ( 31 , 31 ) , blue , bf        end if        if maze( x , y ) = 2 then          circle ( 1024/2 + x * 32 - px * 32 + 16 _          , 768/2 + x * 32 - py * 32 + 16 ) , 7 , green ,,,, f        end if      next y    next x    circle ( 1024/2 + 16 , 768/2 + 16 ) , 10 , yellow ,,,, f  screenunlock  dx = 0  dy = 0  if multikey( sc_up ) then dy = -1  if multikey( sc_down ) then dy = 1  if multikey( sc_left ) then dx = -1  if multikey( sc_right ) then dx = 1  if maze( px + dx , py + dy ) = 1 then    dx = 0    dy = 0  end if  px += dx  py += dy  if px = mazemaxx - 1 _  and py = mazemaxy - 1 then    px = 1    py = 1    create_new_maze tel , mazemaxx , mazemaxy    tel += 1  end if  sleep 250loop until inkey = chr( 27 )`
MrSwiss
Posts: 1702
Joined: Jun 02, 2013 9:27
Location: Switzerland

### Re: maze walk

@bluatigro,

seeing your included Math-Stuff (by color.bas), coded as Functions.
This can easily be sped up, by converting them to #Define(s) aka: 'single line' Macro(s).

It is coded as .bi file (Basic Include) instead of .bas (works the same anyway):

Code: Select all

`' GFX_MATH.bi -- mathematics for fbGFX (Singles only) -- 2016, MrSwiss' some math const(s) + macro(s) -- #Define = single line macro#Ifndef __GFX_MATH_BI__#Define __GFX_MATH_BI__Const As Single PI  = Atn( 1f ) * 4fConst As Single GoldenRatio = ( Sqr(5f) - 1f ) / 2fConst As Single DtoR    = pi / 180fConst As Single RtoD    = 180f / pi#Define RAD(d)      ( CSng(d * DtoR) )#Define DEG(r)      ( CSng(r * RtoD) )Randomize(Timer, 3) ' seed for Rnd()#Define RANGE(l, h) ( CSng(Rnd() * (h - l) + l) )#EndIf ' __GFX_MATH_BI__`
Best, if included at the top of *any* code file that uses fbGFX.

Return to “Game Dev”

### Who is online

Users browsing this forum: No registered users and 1 guest