I am making a version of Flappy Bird in ruby. I can't figure out how to get the tube's/obstacles to appear. I need them to appear at any length, as long as their is a gap of a certain amount of pixels. I am stuck. Here is my code if you have any tips for me? Also having a wierd issue with the velocity where it slows majorily down as it gets close to the bottom or lowers a certain amount of pixels.
require 'gosu'
include Gosu
class GameWindow < Window
def initialize
super(450,900,fullscreen = false,update_interval = 15)
self.caption = "Flappy You"
@background = Image.new("/Users/JackSharkey/Desktop/background.jpg", :tileable => false)
@foreground = Image.new("/Users/JackSharkey/Desktop/foreground.jpg", :tileable => true)
@birdpic = Image.new("/Users/JackSharkey/Desktop/FlappyStraight.png", :tileable => true)
@birdx = 0
@birdy = 300
#@birdypos = 0
@scroll_x = 0
@life = "true"
@birdVel = 0
@pixelTime = 0
@start_time = 0
#@gravity = 100 #This Means that it will go at 100 pixels/ per second
#@jump_speed = 250
#@birdup = Image.new("")
end
def draw
#@background.draw(0, 0, 0)
@foreground.draw(-@scroll_x, 0, 0)
@foreground.draw(-@scroll_x + @foreground.width, 0, 0)
@birdpic.draw(120, @birdy, 0)
end
def button_down(button)
close if button == KbEscape
if button == KbSpace
@start_time = Gosu.milliseconds
@birdVel = 50 #you decide
end
#if button == KbUp
# fall
#end
end
def update
@scroll_x += 3
if @scroll_x > @foreground.width
@scroll_x = 0
end
check
move
#@birdVel += birdVel * (update_interval / 1000)
#@birdy += @birdypos * (update_interval / 1000)
end
def fall
@birdy += 100
end
def check
if Gosu.milliseconds - @start_time > 1000
@birdVel = 0
end
end
def move
#@birdy -= @birdVel - 1
@birdVel -= 2
@birdy = @birdy - 0.5 * @birdVel
if @birdy >= 900
puts "Game Over"
end
if @birdy <= -1
puts "Game Over"
end
puts @birdy
end
def score
end
def obstacles
end
end
window = GameWindow.new
window.show
Aucun commentaire:
Enregistrer un commentaire