master
E. Almqvist 3 years ago
parent 1ed130326a
commit 4672f78f02
  1. 29
      prog2/gametest/app.rb

@ -1,11 +1,15 @@
#!/usr/bin/ruby -w #!/usr/bin/ruby -w
require "gosu" require "gosu"
class Arch < Gosu::Image RED = Gosu::Color.argb(0xff_ff0000)
GREEN = Gosu::Color.argb(0xff_00ff00)
BLUE = Gosu::Color.argb(0xff_0000ff)
WHITE = Gosu::Color.argb(0xff_ffffff)
class PhysObj
attr_accessor :xspeed, :yspeed, :xaccel, :yaccel, :ela, :x, :y attr_accessor :xspeed, :yspeed, :xaccel, :yaccel, :ela, :x, :y
attr_reader :width, :height attr_reader :width, :height
def initialize(src, xspeed=0, yspeed=0, xaccel=0, yaccel=0.1, ela=-0.5, xpos=0, ypos=0) def initialize(xspeed=0, yspeed=0, xaccel=0, yaccel=0.1, ela=-0.5, xpos=0, ypos=0)
super src
@x, @y = xpos, ypos @x, @y = xpos, ypos
@xspeed, @yspeed = xspeed, yspeed @xspeed, @yspeed = xspeed, yspeed
@xaccel, @yaccel = xaccel, yaccel @xaccel, @yaccel = xaccel, yaccel
@ -27,12 +31,11 @@ class Arch < Gosu::Image
self.x += self.xspeed self.x += self.xspeed
self.y += self.yspeed self.y += self.yspeed
self.x = self.x.round(1) puts("#{self.x}, #{self.y} : #{self.xspeed}, #{self.yspeed}")
self.y = self.y.round(1) end
self.xspeed = self.xspeed.round(1)
self.yspeed = self.yspeed.round(1)
def render
Gosu.draw_quad(self.x, self.y, RED, self.x + self.width, self.y, GREEN, self.x, self.y + self.height, BLUE, self.x + self.width, self.y + self.height, WHITE)
end end
end end
@ -55,13 +58,15 @@ class Game < Gosu::Window
def draw def draw
@physobjs.each do |obj| @physobjs.each do |obj|
obj.draw(obj.x, obj.y, 0) obj.render
end end
end end
end end
@arch = Arch.new("arch.png", 10, 0, 0, 0.1, -0.8) physobjs = []
@arch2 = Arch.new("arch.png", -10, 0, 0, 0.1, -0.8, 164) for i in 0...1 do
physobjs << PhysObj.new(4, 0, 0, 0.1, -0.8, i, 0)
end
game = Game.new(640, 480, [@arch, @arch2]) game = Game.new(640, 480, physobjs)
game.show game.show

Loading…
Cancel
Save