I am Doing my Movement Engine, and I must say that it is going pretty well... But I am having a problem...
I am using a modified version of F0tz pixelmovement script(modified by me), And I need to chekc if certain pixels are passable.The normal way would be
So I create a Method In game player to detect colisions, here it is:
But I am having a problem, it doesn't detect colisions right, some times when I detect the colision below the player( and i am pretty sure that it is passable) it returns true(true means that there is a colision). the angle is always 0...
These are the methods used in Game_Map to check passability:
Hope you can Help, thanx for reading!
I am using a modified version of F0tz pixelmovement script(modified by me), And I need to chekc if certain pixels are passable.The normal way would be
Code:
$game_map.pixel_passable(x,y,slef.direction,nil,"tileset")
So I create a Method In game player to detect colisions, here it is:
Code:
#=========================
#*Player colision right
#=========================
def player_collision_right(x,y,angle)
if $game_map.pixel_passable?((x + Math.cos(angle) * 11) ,(y - Math.sin(angle) * 11),self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Player colision left
#=========================
def player_collision_left(x,y,angle)
if $game_map.pixel_passable?((x - Math.cos(angle) * 11),(y + Math.sin(angle) * 11),self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Player colision top
#=========================
def player_collision_top(x,y,angle)
if $game_map.pixel_passable?((x - Math.sin(angle) * 11) ,(y - Math.cos(angle) * 11) ,self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Player colision bottom
#=========================
def player_collision_bottom(x,y,angle)
if $game_map.pixel_passable?((x + Math.sin(angle) * 1) ,(y + Math.cos(angle) * 1) ,self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Player left Edge
#=========================
def player_collision_left_edge(x,y,angle)
if $game_map.pixel_passable?((x - Math.cos(angle) * 8 +Math.sin(angle) * 11) ,(y + Math.sin(angle) * 8 +Math.cos(angle) * 11),self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Player right Edge
#=========================
def player_collision_right_edge(x,y,angle)
if $game_map.pixel_passable?((x + Math.cos(angle) * 8 + Math.sin(angle) * 11) ,(y - Math.sin(angle) * 8 + Math.cos(angle) * 11),self.direction, nil,"Tileset")
return false
else $game_map.pixel_passable?((x + Math.cos(angle) * 8 + Math.sin(angle) * 11) ,(y - Math.sin(angle) * 8 + Math.cos(angle) * 11),self.direction, nil,"Tileset") == false
return true
end
end
#=========================
#*Player Colision main
#=========================
def player_collision_main(x,y)
if $game_map.pixel_passable?(x.round,y.round,self.direction, nil,"Tileset")
return false
else
return true
end
end
#=========================
#*Slope colision detector
#=========================
def player_collision_slope(x,y,angle)
if $game_map.pixel_passable?((x + Math.sin(angle) * 23),(y + Math.cos(angle) * 23),self.direction, nil,"Tileset")
return false
else
return true
end
end
But I am having a problem, it doesn't detect colisions right, some times when I detect the colision below the player( and i am pretty sure that it is passable) it returns true(true means that there is a colision). the angle is always 0...
These are the methods used in Game_Map to check passability:
Code:
# checks if passable, initialises pixel to be checked
def pixel_passable?(x,y,d,event,type)
if event == nil
x_size = y_size = 0
else
#edite sizes here
x_size = 32
y_size = 32
end
x = x.round+16
y = y.round+30
counter = 0
# checks pixel on collision map
case d
when 2
for i in (x-x_size/2)..(x+x_size/2)
if i % 2 == 0 and ((type == 'Map' and self.pass_map(i,y)) or
( type == 'Tileset' and self.pass_tileset(i,y)))
counter += 1
end
end
return true if counter > ((x+x_size/2)-(x-x_size/2))/2
when 4
for i in (y-y_size)..(y)
if i % 2 == 0 and ((type == 'Map' and self.pass_map(x-x_size/2,i)) or
( type == 'Tileset' and self.pass_tileset(x-x_size/2,i)))
counter += 1
end
end
return true if counter > ((y)-(y-y_size))/2
when 6
for i in (y-y_size)..(y)
if i % 2 == 0 and ((type == 'Map' and self.pass_map(x+x_size/2,i)) or
( type == 'Tileset' and self.pass_tileset(x+x_size/2,i)))
counter += 1
end
end
return true if counter > ((y)-(y-y_size))/2
when 8
for i in (x-x_size/2)..(x+x_size/2)
if i % 2 == 0 and ((type == 'Map' and self.pass_map(i,y-y_size)) or
( type == 'Tileset' and self.pass_tileset(i,y-y_size)))
counter += 1
end
end
return true if counter > ((x+x_size/2)-(x-x_size/2))/2
end
return false
end
# Checks passability if a Tileset Collision-Map is used
def pass_tileset(x,y)
layer=0
passed = []
empty = 0
type=0
x_s = x
y_s = y
while layer <= 2
pruefe = true
x=x_s
y=y_s
pos = self.data[x/32,y/32,layer]
pos = 0 if pos == nil
if pos >= 384
pos -= 384
sy = (pos / 8)*32
sx = (pos % 8)*32
x = sx + x%32
y = sy + y%32
type=0
elsif pos >= 48
type = pos / 48
pos = pos % 48
sy = (pos / 8)*32
sx = (pos % 8)*32
x = sx + x%32
y = sy + y%32
else
passed[layer] = 1
empty += 1
pruefe = false
end
if pruefe
table = RPG::Cache.read_table(@collision_map[type],x,y)
if table == 2
passed[layer] = 1
elsif table == 1
passed[layer] = 0
else
if @collision_map[type].get_pixel(x, y) != Color.new(0, 0, 0)
passed[layer] = 1
RPG::Cache.write_table(@collision_map[type],x,y,2)
else
passed[layer] = 0
RPG::Cache.write_table(@collision_map[type],x,y,1)
end
end
end
layer+=1
end
# 'Bridges' or free space = true
return ((passed[0] == 1 and passed[1] == 1 and passed[2] == 1) or
(passed[0] == 0 and passed[1] == 1 and passed[2] == 1 and
((data[x_s/32, y_s/32, 1] != 0 and @priorities[data[x_s/32, y_s/32, 1]] == 0) or
(data[x_s/32, y_s/32, 2] != 0 and @priorities[data[x_s/32, y_s/32, 2]] == 0)) and empty < 2))
end
Hope you can Help, thanx for reading!