C
ChrisKaelin
The code of my raw main loop is below. I'm sure there are better ways
to poll the event queue. Do you have better ideas?
Also I'm not sure about the garbage collect thing at the bottom...
loop {
offset_x = 0
offset_y = 0
if event.poll != 0
case event.type
when SDL::Event::QUIT
break
when SDL::Event::KEYDOWN
case event.keySym
when SDL::Key::ESCAPE
break
when SDL::Key::LEFT
offset_x = -5
when SDL::Key::RIGHT
offset_x = +5
when SDL::Key:
OWN
offset_y = +5
when SDL::Key::UP
offset_y = -5
end
end
end
before = now
now = SDL::getTicks
dt = now-before
# here comes the rendering finally
player.draw(screen)
enemies.each{|i| i.draw(screen)}
screen.fillRect(0,0,640,480,0)
w.to_sdl(screen, offset_x, offset_y)
screen.fillRect(0,0,640,480,0)
ObjectSpace.garbage_collect
screen.flip
}
to poll the event queue. Do you have better ideas?
Also I'm not sure about the garbage collect thing at the bottom...
loop {
offset_x = 0
offset_y = 0
if event.poll != 0
case event.type
when SDL::Event::QUIT
break
when SDL::Event::KEYDOWN
case event.keySym
when SDL::Key::ESCAPE
break
when SDL::Key::LEFT
offset_x = -5
when SDL::Key::RIGHT
offset_x = +5
when SDL::Key:
offset_y = +5
when SDL::Key::UP
offset_y = -5
end
end
end
before = now
now = SDL::getTicks
dt = now-before
# here comes the rendering finally
player.draw(screen)
enemies.each{|i| i.draw(screen)}
screen.fillRect(0,0,640,480,0)
w.to_sdl(screen, offset_x, offset_y)
screen.fillRect(0,0,640,480,0)
ObjectSpace.garbage_collect
screen.flip
}