S
Sylvain Petit
Hello,
I have a few issue using arrays.
I'm working with rubySDL to make a vertical shooting game. I have a
ship, which had a collection of "fired_missile".
The level have a collection of critters on screen.
My main loop is :
def main
self.init_lvl
critest = Critters.new(@screen, SCREEN_W,SCREEN_H/2)
@crit<<critest
while(@finished == false)
background = @screen.format.map_rgb(0, 0, 0)
@screen.fill_rect(0,0,@screen.w,@screen.h,background)
self.event_poll
@ship.move
@ship.draw
cur_crit = @crit
cur_crit.each { |c|
c.move
c.draw
self.check_firing(c)
}
@screen.update_rect(0,0,@screen.w,@screen.h)
end
end
If I understand my code well, for each critters in @crit collection (or
cur_crit to be more accurate), I move the crit, then draw it, and to
finish I call "check_firing" with the critters in parameter.
Here's the check_firing code :
def check_firing(c)
critemp = []
if(@ship.firelist.length!=0)
@ship.firelist.each { |f|
if(f.collide_with?(c))
else
critemp<<c
end
@crit = critemp
}
end
end
The amusing part is that all work well if I fire only one missile. When
I fire more, it becomes unclear : the critters won't disappear, and
(surprisingly) it goes faster.
I used the cur_crit temporary array in the main function because
modifying the @crit array while looping on it was kind of hazardous.
If someone have an idea, it will be greatly appreciated
Thanks.
I have a few issue using arrays.
I'm working with rubySDL to make a vertical shooting game. I have a
ship, which had a collection of "fired_missile".
The level have a collection of critters on screen.
My main loop is :
def main
self.init_lvl
critest = Critters.new(@screen, SCREEN_W,SCREEN_H/2)
@crit<<critest
while(@finished == false)
background = @screen.format.map_rgb(0, 0, 0)
@screen.fill_rect(0,0,@screen.w,@screen.h,background)
self.event_poll
@ship.move
@ship.draw
cur_crit = @crit
cur_crit.each { |c|
c.move
c.draw
self.check_firing(c)
}
@screen.update_rect(0,0,@screen.w,@screen.h)
end
end
If I understand my code well, for each critters in @crit collection (or
cur_crit to be more accurate), I move the crit, then draw it, and to
finish I call "check_firing" with the critters in parameter.
Here's the check_firing code :
def check_firing(c)
critemp = []
if(@ship.firelist.length!=0)
@ship.firelist.each { |f|
if(f.collide_with?(c))
else
critemp<<c
end
@crit = critemp
}
end
end
The amusing part is that all work well if I fire only one missile. When
I fire more, it becomes unclear : the critters won't disappear, and
(surprisingly) it goes faster.
I used the cur_crit temporary array in the main function because
modifying the @crit array while looping on it was kind of hazardous.
If someone have an idea, it will be greatly appreciated
Thanks.