DXOpal demo


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX