Hey, Long time no see. Anyways,
I was developing a game where I run on a problem IMMEDIATELY xD. And I can't quite figure out what that problem is. Would you look at the code and find it out?
screen _newimage(1280,720,32)
_fullscreen
'Declaring Variables
type vec
x as integer
y as integer
speed as integer
end type
dim shared player as vec
dim shared map as string
dim shared oldx, oldy as integer
player.speed = 3
map = "map1.txt"
player.x = _width / 2
player.y = _height / 2
'Main Loop
do
cls
makeplayer
playerMovement
'Test
'makeObstacle 100,100,200,200,255,200,100
makeMap
'For Experiments: The co-ordinates
_printstring (0,0), str$(player.x) + str$(player.y)
_display
loop until _keyhit = 27
system
'Subs and Functions
sub makeplayer
circle (player.x, player.y), 10, _rgb32(100,200,255)
paint (player.x, player.y), _rgb32(100,200,255), _rgb32(100,200,255)
end sub
sub playerMovement
if _keydown(18432) then player.y = player.y - player.speed
if _keydown(20480) then player.y = player.y + player.speed
if _keydown(19200) then player.x = player.x - player.speed
if _keydown(19712) then player.x = player.x + player.speed
end sub
sub makeObstacle(x1,y1,x2,y2,r,g,b)
line (x1,y1)-(x2,y2),_rgb32(r,g,b), BF
if player.x + 10 >= x1 and player.x - 10 <= x2 and player.y + 10 >= y1 and player.y - 10 <= y2 then
player.x = oldx
player.y = oldy
else
oldx = player.x
oldy = player.y
end if
end sub
sub makeMap
open map for input as #1
while not eof(1)
input #1, cm$,x1,y1,x2,y2,r,g,b
if cm$ = "obs" then
makeObstacle x1,y1,x2,y2,r,g,b
end if
wend
close #1
end sub
Here's the file called "map1.txt"
obs, 0,0,700,50,242,242,242
obs, 800,50,1280,100,242,242,242
Here, the 1st obstacle is blocking the character perfectly, but the second one isn't. Why???
-Prithak