/
example10_traits_retrofy.rb
81 lines (65 loc) · 1.7 KB
/
example10_traits_retrofy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
require 'rubygems' rescue nil
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), "..", "..", "lib")
require 'chingu'
include Gosu
include Chingu
$stderr.sync = $stdout.sync = true
#
# Testing out a new module-only-super-chain trait system
#
class Game < Chingu::Window
def initialize
super(600,400)
self.caption = "Testing out new module-based traits (SPACE for more spaceships)"
self.input = { :space => :create_thing, :esc => :exit }
retrofy
create_thing(200,200)
end
def update
puts "--- UPDATE ---"
super
end
def draw
puts "--- DRAW ---"
super
end
def create_thing(x=nil, y=nil)
Thing.create(:x => x||rand($window.width), :y => y||rand($window.height), :debug => true)
end
end
class Thing < Chingu::GameObject
trait :effect
trait :velocity
def initialize(options)
super
@image = Image["spaceship.png"]
self.rotation_center(:center)
# Julians ninjahack to get that sweet pixely feeling when zooming :)
# glBindTexture(GL_TEXTURE_2D, @image.gl_tex_info.tex_name)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
#
# The above code has been merged into chingu as @image.retrofy
#
# @image.retrofy
#
# Use Gosu::enable_undocumented_retrofication instead!
self.scale = 8
puts "scale: " + scale.to_i.to_s
self.rotation_rate = 2
self.velocity_x = 2
end
def update
puts "Thing#update"
if outside_window?
@velocity_x = -@velocity_x
self.rotation_rate = -self.rotation_rate
end
end
def draw
puts "Thing#draw"
super
end
end
Game.new.show