require 'dxopal'
class Enemy < Sprite
SIZE = 40
def initialize
x = rand(Window.width)
y = 0
@img_normal = Image.new(SIZE, SIZE)
@img_normal.triangle_fill(0, 0, SIZE-1, 10, 10, SIZE-1, C_WHITE)
super(x, y, @img_normal)
@img_hit = Image.new(SIZE, SIZE)
@img_hit.triangle_fill(0, 0, SIZE-1, 10, 10, SIZE-1, C_RED)
self.collision = [0, 0, SIZE-1, 10, 10, SIZE-1]
@dy = rand(6) + 1
@drot = rand(8) + 1
@hit = false
end
def hit(other)
@hit = true
end
def update
self.y += @dy
if self.y >= Window.height
self.y = 0
end
self.angle = (self.angle + @drot) % 360
self.image = @hit ? @img_hit : @img_normal
@hit = false
end
end
class Bullet < Sprite
SIZE = 10
def initialize(px, py)
x = px
y = py
@img_normal = Image.new(SIZE, SIZE)
@img_normal.circle_fill(SIZE/2, SIZE/2, (SIZE/2)-1, C_YELLOW)
super(x, y, @img_normal)
self.collision = [SIZE/2, SIZE/2, (SIZE/2)-1]
@dx = rand(8) - 4
@dy = -rand(3) - 3