Merge branch 'master' of github.com:E-Almqvist/prog2

master
E. Almqvist 3 years ago
commit ea6eefc385
  1. 29
      prog2/gametest/app.rb

@ -1,11 +1,15 @@
#!/usr/bin/ruby -w
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_reader :width, :height
def initialize(src, xspeed=0, yspeed=0, xaccel=0, yaccel=0.1, ela=-0.5, xpos=0, ypos=0)
super src
def initialize(xspeed=0, yspeed=0, xaccel=0, yaccel=0.1, ela=-0.5, xpos=0, ypos=0)
@x, @y = xpos, ypos
@xspeed, @yspeed = xspeed, yspeed
@xaccel, @yaccel = xaccel, yaccel
@ -27,12 +31,11 @@ class Arch < Gosu::Image
self.x += self.xspeed
self.y += self.yspeed
self.x = self.x.round(1)
self.y = self.y.round(1)
self.xspeed = self.xspeed.round(1)
self.yspeed = self.yspeed.round(1)
puts("#{self.x}, #{self.y} : #{self.xspeed}, #{self.yspeed}")
end
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
@ -55,13 +58,15 @@ class Game < Gosu::Window
def draw
@physobjs.each do |obj|
obj.draw(obj.x, obj.y, 0)
obj.render
end
end
end
@arch = Arch.new("arch.png", 10, 0, 0, 0.1, -0.8)
@arch2 = Arch.new("arch.png", -10, 0, 0, 0.1, -0.8, 164)
physobjs = []
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

Loading…
Cancel
Save