-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spaceship.rb
64 lines (47 loc) · 1005 Bytes
/
Spaceship.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "gosu"
require 'json'
require './modules'
class Spaceship
include Steerable
include Movable
@@spaceships = []
attr_accessor :angle, :vel, :x, :y
def initialize(window, x=0, y=0)
@window = window
@x = @y = 100.0
@angle = @vel = 0.0
@d_angle = -90.0
@image = Gosu::Image.new(window, "./img/spaceship.png", true)
#@image.rect 0,0, 200,100, color: :white, fill: true, dest_select: :transparent
@@spaceships << self
end
def self.each
@@spaceships.each do |spaceship|
yield spaceship
end
end
def self.spaceships
@@spaceships
end
def fire
Photon.new(@window, @x,@y,@angle)
end
def draw
@image.draw_rot @x, @y, 1, @angle + @d_angle
end
def data
{'vel' => vel, 'angle' => angle}.to_json
end
def data= s_data
resc = false
begin
m_data = JSON.load(s_data)
rescue
resc = true
end
unless resc
@vel = m_data['vel']
@angle = m_data['angle']
end
end
end