07-10-2023, 04:13 PM
I think i smell robot
this is updated example with robot and hero
but without plants just to test scanning all 360 cells.
this is updated example with robot and hero
but without plants just to test scanning all 360 cells.
Code: (Select All)
'gdi demo aka CrazyRobot
ptr img0,img1,img2,img3
ptr wmKeyDown
var wp,ix,iy,p,ex,ey,run
var lx,ly,bx,by,cell, tmpx,tmpy,tmpCell,robotCell
var moveLeft,moveRight,moveUp,moveDown,moveTemp
wcolor 0,0,0:swap
'LoadImage(0, strRes, imgType, imgW, imgH, cFlag)
LoadImg img0,"grid.bmp" ,0, 770,482, 24
'green blocks
LoadImg img1,"bush.bmp" ,0, 32,32, 24
'print 10,200,img1
LoadImg img2,"hero.bmp",0, 32,32, 24
'print 10,250,img2
LoadImg img3,"robot.bmp",0, 32,32, 24
'print 10,300,img3
'ShowImgT img3,300, 300, 40, 40
info()
bx = 128 : by = bx + 32
updateBush()
'init positions..........................
ex = 32 : ey = 0 : robotCell = 2
run = 1
'main loop
WHILE run = 1
hWparam wp
'vkLEFT -----------------------------------
if wp = 37
if ix > 0 : ix = ix - 32 : endif
endif
'vkRIGHT ?----------------------------------
if wp = 39
if ix < 736 : ix = ix + 32 : endif
endif
'vkUP --------------------------------------
if wp = 38
if iy > 0 : iy = iy - 32 :endif
endif
'vkDOWN --------------------------------------
if wp = 40
if iy < 420 : iy = iy + 32 :endif
endif
updateBack()
updatePlayer()
updatePosition()
updateBush()
updateRobot()
'testCollision()
swap
' tiny delay for game loop
p=1 : while p < 800 : p=p+0.1 : wend
WEND
func updatePosition()
fcolor 80,80,100 : rect 524,512,68,24
fcolor 100,160,220 : print 530,514,ix
fcolor 80,80,100 : rect 610,512,68,24
fcolor 100,160,220 : print 612,514,iy
'calculate player cell position using sprite upper/left pixel pos
tmpx = int((ix + 32) / 32)
'tmpy = int((iy + 32) / 32)
tmpy = int(iy/32) + 1
'calc temp cell
'tmpCell = tmpx + tmpy
tmpCell = int(iy/32)*24 + int(ix/32) + 1
fcolor 180,100,50 : rect 306,512,68,24 : print 310,514, tmpx
fcolor 180,100,50 : rect 406,512,68,24 : print 410,514, tmpy
'show cell number
fcolor 50,170,100 : rect 206,512,68,24 : print 210,514, tmpCell
updateBush()
endfn
'----------------------------------------
func updateBack()
ShowImgT img0,0,0,770,482
endFn
'----------------------------------------
func updatePlayer()
ShowImgT img2,ix,iy,32,32
endFn
'-----------------------------------------
func updateRobot()
if robotCell = 360 : robotCell = 2 : ex = 32 : ey = 0 : endif
if robotCell < 361
'calc x,y position to cell
ex = (ex + 32)
cell = (robotCell % 24)*24
if cell = robotCell : ey = ey + 32 : ex = 0 : endif
robotCell = robotCell + 1
cell = 0
endif
'show robot
ShowImgT img3, ex, ey, 32, 32
endfn
'----------------------------------
func updateBush()
ShowImgT img1,bx,by,32,32
endFn
'*********************************************
'*** I N F O ******************************
'*********************************************
func info()
'clear screen
fcolor 0,0,0 : rect 6,518,200,32 :
fcolor 200,180,100: print 10,520,"GDI_Robot by Aurel"
'swap
endfn
func LoadCells()
grid()
endFn
func grid()
'clear screen
fcolor 0,0,0 : rect 0,0,800,512 :
'draw shadows
ly=0
While ly < 480
'draw by X
lx=0
While lx < 768
fcolor 60,80,60 : rect lx,ly,32,32
cell = cell + 1 : fcolor 60,60,60: print lx,ly,cell : swap
lx = lx + 32
Wend
ly = ly + 32
Wend
swap
endfn
micro(A)developer
http://basic4us.epizy.com/forum/index.php
http://basic4us.epizy.com/forum/index.php