Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 100 lines (81 sloc) 2.315 kB
99fee25 @deps What I have so far
authored
1 require 'rubygems'
2 require 'opengl'
fb07e13 @ippa Droid vs Bullet collision detection, colorcycle 'explosion'. Tidy up …
ippa authored
3 require 'chingu'
4 #require '../chingu/lib/chingu'
99fee25 @deps What I have so far
authored
5 include Gosu
6fd39e3 @ippa include Chingu to get media_path()
ippa authored
6 include Chingu
99fee25 @deps What I have so far
authored
7
8 require_all('models')
9
10 class Game < Chingu::Window
526adf5 @deps Credit screen added.
authored
11 attr_reader :factor, :font, :metalfont
5a76f2e @ippa Droid-class with animations, #walk_towards(x,y), #stop. Spawn some in…
ippa authored
12
99fee25 @deps What I have so far
authored
13 def initialize
14 super
5a76f2e @ippa Droid-class with animations, #walk_towards(x,y), #stop. Spawn some in…
ippa authored
15 @factor = 2.5 # set new objects factor to $window.factor when they initialize, see droid.rb
99fee25 @deps What I have so far
authored
16
419d6eb @deps Moved speech code into Main.rb, and fiddled a bit with the main menu.
authored
17 @sample_queue = []
18 @current_samples = []
19 @current_word = nil
20 @sample_speed = 1.0
21
f7351a2 @ippa Major cleanup of Player and Bullet
ippa authored
22 @metalfont = Chingu::Animation.new(:file => "metalfont.png", :size => [32,32]).retrofy
2ce5d67 @ippa Major cleanup of Player and Bullet
ippa authored
23 @directions_to_xy = { :north => [0, -1], :east => [1, 0], :south => [0, 1], :west => [-1, 0] }
cd8971c @deps Background musics, and fixes in bitmapfont code.
authored
24 @font_letters = ('A'..'Z').to_a + [' ','.'] + ('0'..'9').to_a + ['!','(',')',',','"','?','*','-']
f7351a2 @ippa Major cleanup of Player and Bullet
ippa authored
25
526adf5 @deps Credit screen added.
authored
26 # Normal font used elsewhere
27 @font = Font.new($window, default_font_name, 30)
28
29
6df3753 @deps A "This game is free" warning added, in case somebody tries to sell it.
authored
30 push_game_state( ScamState )
99fee25 @deps What I have so far
authored
31 end
df7197b @deps Score font changed to a bitmap
authored
32
2ce5d67 @ippa Major cleanup of Player and Bullet
ippa authored
33 #
34 # Takes a Hash (e.g. :north => true, :east => true } and returns [x, y]
35 #
7704424 @ippa some smaller fixes here and there
ippa authored
36 def directions_to_xy(directions = nil)
2ce5d67 @ippa Major cleanup of Player and Bullet
ippa authored
37 x, y = 0, 0
7704424 @ippa some smaller fixes here and there
ippa authored
38 return [x,y] unless directions
2bda1fc @deps Fixed bug where it was impossible to fire to the right, and a bug whe…
authored
39 directions.each do |direction, boolean|
40 if boolean
41 x += @directions_to_xy[direction][0]
42 y += @directions_to_xy[direction][1]
43 end
f2efed7 @ippa fixed droid shooting bug
ippa authored
44 end
2ce5d67 @ippa Major cleanup of Player and Bullet
ippa authored
45 return [x,y]
46 end
47
cd8971c @deps Background musics, and fixes in bitmapfont code.
authored
48 # This method turns a string into an array with the corrensponding index values for the
49 # bitmap font inside @metalfont
50 # See PlayState#draw_hud for an example of how to use it
51 def string_to_index(msg)
52 arr = []
53 msg.split("").each do |l|
54 i = @font_letters.index(l)
55 if i
56 arr << i
57 else
58 arr << 42
59 end
60 end
61 arr
62 end
63
99fee25 @deps What I have so far
authored
64 def update
65 super
66 close if current_parent == self
67 end
68
419d6eb @deps Moved speech code into Main.rb, and fiddled a bit with the main menu.
authored
69 def speak( message )
70 words = message.split(" ")
71 samples = []
72 words.each do |w|
73 samples << "word_#{w}.wav"
74 end
75
76 @sample_queue << samples
77 end
78
79 def update_speech
80 if @current_samples.empty? and @current_word == nil
81 return if @sample_queue.length == 0
82 @current_samples = @sample_queue.shift
83 @sample_speed = 0.90 + rand(0.20)
84 end
85
86 if @current_word == nil
87 @current_word = Sound[@current_samples.shift].play(0.3, @sample_speed)
88 else
89 unless @current_word.playing?
90 @current_word = nil
91 end
92 end
93
94 end
95
99fee25 @deps What I have so far
authored
96 end
97
98
99 g = Game.new
100 g.show
Something went wrong with that request. Please try again.