def wave
top_of_wave = @y_sprite_coordinate - 20
bottom_of_wave =@y_sprite_coordinate + 20
sprite_at_top_of_wave = false
#heres some pseudo code
if sprite_at_top_of_wave is false and @y_sprite_coordinate is greater than top_of_wave
then @y_sprite_coordinate -= 5
else if @y_sprite_coordinate <= top_of_wave
then sprite_at_top_of_wave = true
else if sprite_at_top_of_wave == true and @y_sprite_coordinate is less than bottom_of_wave
then @y_sprite_coordinate += 5
else if @y_sprite_coordinate greater than bottom_of_wave
then sprite_at_top_of_wave = true
end
@y_sprite_coordinate -= 5
I think this is happening because it calls the method during the update phase. So I think its calling the method 60 times a second. If that's the case then the method just keeps resetting the @y_sprite_coordinate
and it goes up and up and up.def button_down(id)
if id == Gosu::GP_BUTTON_1 and Gosu::GP_RIGHT
#do thing
end
end
def button_down(id)
case id
when (Gosu::BUTTON_1 and Gosu::GP_RIGHT)
#do thing
end
end
#thing
only when I press the second button. The buttons don't seem to work together. The one that fulfills the if/then statement or the case statement is the last thing. ie: Gosu::GP_RIGHT
@tiles = Array.new(@width) do |x|
Array.new(@height) do |y|
case lines[y][x, 1]
when '"'
Tiles::Grass
when '#'
Tiles::Earth
when 'x'
@gems.push(CollectibleGem.new(gem_img, x * 50 + 25, y * 50 + 25))
nil
else
nil
end
end
end
def draw
# Very primitive drawing function:
# Draws all the tiles, some off-screen, some on-screen.
@height.times do |y|
@width.times do |x|
tile = @tiles[x][y]
if tile
# Draw the tile with an offset (tile images have some overlap)
# Scrolling is implemented here just as in the game objects.
@tileset[tile].draw(x * 50 - 5, y * 50 - 5, 0)
end
end
end
@gems.each { |c| c.draw }
end
.times
method. We do 'something' @height and @width times. Where height and width are the values taken from the map text file. tile
variable. draw
method. x * 50
-5 & y * 50 -5
decide where the tiles are drawn in the window.(I think.) But I don't understand what the x and y are and why you times them by 50. I mean, I know that x
and y
represent items in the @tiles
array but... I'm confused :)solid?
method returns true/false when it's next to a map tile.solid?
method is only checking for a map tile in one direction right now.@x
and @y
are the x and y coordinates of the tile in the Map class. Sorry. def solid?(x, y)
@x.between?(x, x + 20) and @y.between?(y, y + 20)
end
def solid?(x, y)
x.between?(@x, @x + 20) and y.between(@y, @y + 20)
end
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill