Alright! Back to programming with my exams now gone! Here I coded this stuff:
screen _newimage(800,600,32)
dim shared x as integer
dim shared y as integer
dim shared oldx as integer
dim shared oldy as integer
x = 100
y = 200
color , _rgb32(50,200,0)
cls
do
cls
open "blocks.txt" for input as #1
while not eof(1)
input #1, x1,y1,x2,y2,r,g,b
makeobs x1,y1,x2,y2,r,g,b
wend
close #1
IF _KEYDOWN(CVI(CHR$(0) + "P")) THEN y = y - 5 '_KEYDOWN(20480)
IF _KEYDOWN(CVI(CHR$(0) + "H")) THEN y = y + 5 '_KEYDOWN(18432)
IF _KEYDOWN(CVI(CHR$(0) + "K")) THEN x = x + 5 '_KEYDOWN(19200)
IF _KEYDOWN(CVI(CHR$(0) + "M")) THEN x = x - 5 '_KEYDOWN(19712)
'The sprites will be 20x20 pixels, I believe...
line (_width/2,_height/2)-step(20,20),_rgb32(255,200,100),BF
_printstring(0,0),str$(x) + " " + str$(y)
_limit 100
_Display
loop
FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
collision% = 0
ELSE
collision% = 1
END IF
END FUNCTION
sub makeobs (x1,y1,w,h,r,g,b)
line(x + x1, y + y1)-step(w,h),_rgb32(r,g,b),BF
Line(x + x1, y + y1)-step(w,h),_Rgb32(255,255,255),B
'200, 200 - 220, 220
if collision%(_width/2,_height/2,20,20,x + x1, y + y1,w,h) then
y = oldy
x = oldx
else
oldy = y
oldx = x
end if
end sub
And here's "blocks.txt"
200,100,100,100,100,200,255
200,300,100,100,100,200,255
100,200,100,100,100,200,255
300,200,100,100,100,200,255
Ok. For some reason, the character's only being blocked by the first obstacle? WHY??
-Prithak