lunar_lander 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+
2
+ - Isolate particles movement
@@ -5,16 +5,15 @@ module LunarLander
5
5
 
6
6
  attr_accessor :fuel
7
7
 
8
- def initialize(options={})
9
- super(options.merge(:image => Gosu::Image["player.png"]))
10
- end
11
-
12
8
  def setup
13
- @engine_sound = Gosu::Sound["fierce_wind.wav"].play(1,1,true)
9
+ @x = $window.width / 2
10
+ @y = $window.height / 2
11
+ self.image = Gosu::Image["player.png"]
12
+ @engine_sound = Gosu::Sound["fierce_wind.wav"].play(1, 1, true)
14
13
  @engine_sound.pause
15
14
  self.acceleration_y = 0.01
16
15
  self.velocity_y = 1
17
- @particle_animation = Chingu::Animation.new(:file => "particle.png", :size => [32,32])
16
+ @particle_animation = Chingu::Animation.new(:file => "particle.png", :size => [32, 32])
18
17
  @fuel = 100.0
19
18
  end
20
19
 
@@ -22,18 +21,18 @@ module LunarLander
22
21
  @angle -= 0.5
23
22
 
24
23
  Chingu::Particle.create(
25
- :x => @x + Gosu::offset_x(@angle + 60, 20),
26
- :y => @y + Gosu::offset_y(@angle + 60, 20),
24
+ :x => @x + Gosu::offset_x(@angle + 60, 20 * @factor),
25
+ :y => @y + Gosu::offset_y(@angle + 60, 20 * @factor),
27
26
  :animation => @particle_animation,
28
27
  :scale_rate => -0.03,
29
28
  :fade_rate => -35,
30
29
  :rotation_rate => +1,
31
30
  :mode => :default,
32
- :factor => 0.5
31
+ :factor => @factor / 2
33
32
  )
34
33
  Chingu::Particle.each { |particle|
35
- particle.y -= Gosu::offset_y(@angle-90, 2)
36
- particle.x -= Gosu::offset_x(@angle-90, 2)
34
+ particle.x -= Gosu::offset_x(@angle-90, 2 * @factor)
35
+ particle.y -= Gosu::offset_y(@angle-90, 2 * @factor)
37
36
  }
38
37
  end
39
38
 
@@ -41,18 +40,18 @@ module LunarLander
41
40
  @angle += 0.5
42
41
 
43
42
  Chingu::Particle.create(
44
- :x => @x + Gosu::offset_x(@angle - 60, 20),
45
- :y => @y + Gosu::offset_y(@angle - 60, 20),
43
+ :x => @x + Gosu::offset_x(@angle - 60, 20 * @factor),
44
+ :y => @y + Gosu::offset_y(@angle - 60, 20 * @factor),
46
45
  :animation => @particle_animation,
47
46
  :scale_rate => -0.03,
48
47
  :fade_rate => -35,
49
48
  :rotation_rate => +1,
50
49
  :mode => :default,
51
- :factor => 0.5
50
+ :factor => @factor / 2
52
51
  )
53
52
  Chingu::Particle.each { |particle|
54
- particle.y -= Gosu::offset_y(@angle+90, 2)
55
- particle.x -= Gosu::offset_x(@angle+90, 2)
53
+ particle.x -= Gosu::offset_x(@angle+90, 2 * @factor)
54
+ particle.y -= Gosu::offset_y(@angle+90, 2 * @factor)
56
55
  }
57
56
  end
58
57
 
@@ -62,17 +61,19 @@ module LunarLander
62
61
  self.velocity_y += Gosu::offset_y(@angle, 0.05)
63
62
 
64
63
  Chingu::Particle.create(
65
- :x => @x - Gosu::offset_x(@angle, 20),
66
- :y => @y - Gosu::offset_y(@angle, 20),
64
+ :x => @x - Gosu::offset_x(@angle, 20 * @factor),
65
+ :y => @y - Gosu::offset_y(@angle, 20 * @factor),
67
66
  :animation => @particle_animation,
68
67
  :scale_rate => -0.03,
69
68
  :fade_rate => -35,
70
69
  :rotation_rate => +1,
71
- :mode => :default
70
+ :mode => :default,
71
+ :factor => @factor
72
72
  )
73
+
73
74
  Chingu::Particle.each { |particle|
74
- particle.y -= Gosu::offset_y(@angle, 10 + rand(4))
75
- particle.x -= Gosu::offset_x(@angle, 10 + rand(4))
75
+ particle.x -= Gosu::offset_x(@angle, 10 * @factor + rand(4))
76
+ particle.y -= Gosu::offset_y(@angle, 10 * @factor + rand(4))
76
77
  }
77
78
  @engine_sound.resume unless @engine_sound.playing?
78
79
 
@@ -100,7 +101,6 @@ module LunarLander
100
101
 
101
102
  def update
102
103
  super
103
- @x %= $window.width
104
104
  @engine_sound.stop if @fuel == 0
105
105
  end
106
106
  end
@@ -1,30 +1,75 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module LunarLander
3
+
3
4
  class Play < Chingu::GameState
5
+ trait :timer
6
+
4
7
  def setup
5
- self.input = { :p => LunarLander::Pause }
8
+ self.input = { :p => LunarLander::Pause, :holding_z => :zoom_in, :holding_x => :zoom_out, :c => :cinema_zoom, :holding_d => :camera_right, :holding_a => :camera_left }
6
9
 
7
- @player = Player.create({ :x => $window.width/2, :y => $window.height/2})
10
+ @player = Player.new
8
11
  @player.input = {:holding_left => :rotate_left, :holding_right => :rotate_right, :holding_up => :thrust, :released_up => :stop_engine}
9
12
 
10
- @background = Gosu::Image["moon.png"]
11
- @surface = Chingu::Rect.new(0, $window.height-50, 800, 50)
13
+ @background = Gosu::Image["earth.png"]
14
+
15
+ @moon = Gosu::Image["moon.png"]
16
+ @parallax = Chingu::Parallax.create(:x => 0, :y => $window.height - @moon.height, :rotation_center => :top_left, :zorder => 1)
17
+ @parallax << { :image => @moon, :repeat_x => true, :repeat_y => false}
18
+
19
+ @surface = Chingu::Rect.new(0, $window.height-@moon.height + 60, $window.width, @moon.height - 60)
12
20
 
13
21
  setup_hud
22
+ @factor = 1
14
23
  end
15
24
 
16
- def update
17
- super
18
-
19
- game_objects.destroy_if { |object|
25
+ def camera_left
26
+ @parallax.camera_x -= 2
27
+ end
28
+
29
+ def camera_right
30
+ @parallax.camera_x += 2
31
+ end
32
+
33
+ def adjust_parallax_viewport
34
+ @parallax.camera_x += @player.velocity_x if @player.x > $window.width * 0.8 or @player.x < $window.width * 0.2
35
+ @parallax.camera_y += @player.velocity_y if @player.y < $window.height * 0.2 or (@player.y > $window.height * 0.2 and @parallax.camera_y < -($window.height - @moon.height))
36
+ end
37
+
38
+ def cinema_zoom
39
+ during(3000) do
40
+ zoom_in
41
+ end
42
+ end
43
+
44
+ def zoom_in
45
+ @factor += 0.001
46
+ zoom_by_factor
47
+ end
48
+
49
+ def zoom_out
50
+ @factor -= 0.001
51
+ zoom_by_factor
52
+ end
53
+
54
+ def zoom_by_factor
55
+ game_objects.each do |game_object|
56
+ next if game_object.kind_of? Chingu::Text
57
+ game_object.factor = @factor
58
+ if game_object.kind_of? Chingu::Parallax
59
+ game_object.layers.each do |p| p.factor = @factor end
60
+ game_object.y = $window.height - (@moon.height * game_object.factor)
61
+ end
62
+ end
63
+ @player.factor = @factor
64
+ Chingu::Particle.all.each do |p| p.factor = @factor end
65
+ end
66
+
67
+ def destroy_particles
68
+ game_objects.destroy_if do |object|
20
69
  if object.kind_of? Chingu::Particle
21
70
  object.outside_window? || object.color.alpha == 0
22
71
  end
23
- }
24
-
25
- test_colision
26
-
27
- update_hud
72
+ end
28
73
  end
29
74
 
30
75
  def setup_hud
@@ -59,11 +104,51 @@ module LunarLander
59
104
  end
60
105
  end
61
106
 
107
+ def restrict_player_movement
108
+ if @player.x > $window.width * 0.8
109
+ @player.x = $window.width * 0.8
110
+ elsif @player.x < $window.width * 0.2
111
+ @player.x = $window.width * 0.2
112
+ end
113
+ if @player.y > $window.height * 0.2 and @parallax.camera_y < -($window.height - @moon.height)
114
+ @player.y = $window.height * 0.2
115
+ elsif @player.y < $window.height * 0.2
116
+ @player.y = $window.height * 0.2
117
+ end
118
+ end
62
119
 
120
+ def update
121
+ super
122
+ @player.update_trait
123
+ @player.update
124
+ destroy_particles
125
+ test_colision
126
+ update_hud
127
+ adjust_parallax_viewport
128
+ restrict_player_movement
129
+ end
130
+
63
131
  def draw
64
132
  super
65
- @background.draw(0,0,0)
133
+ @background.draw(($window.width / 2) - (@background.width * 0.5)/2, ($window.height / 2) - (@background.height * 0.5) / 2, 0, 0.5, 0.5)
134
+
135
+ offset_x = 0
136
+ if @player.x > $window.width * 0.8
137
+ offset_x = -(@player.x - $window.width * 0.8)
138
+ elsif @player.x < $window.width * 0.2
139
+ offset_x = -(@player.x - $window.width * 0.2)
140
+ end
141
+
142
+ offset_y = 0
143
+ if @player.y > $window.height * 0.2 and @parallax.camera_y < -($window.height - @moon.height)
144
+ offset_y = -(@player.y - $window.height * 0.2)
145
+ elsif @player.y < $window.height * 0.2
146
+ offset_y = -(@player.y - $window.height * 0.2)
147
+ end
66
148
 
149
+ $window.translate(offset_x, offset_y) do
150
+ @player.draw
151
+ end
67
152
  end
68
153
  end
69
154
  end
@@ -1,3 +1,3 @@
1
1
  module LunarLander
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunar_lander
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Roxo Mundim
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-05 00:00:00 -03:00
19
+ date: 2011-03-11 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ files:
51
51
  - Gemfile
52
52
  - README.rdoc
53
53
  - Rakefile
54
+ - TODO
54
55
  - bin/lunar_lander
55
56
  - lib/lunar_lander.rb
56
57
  - lib/lunar_lander/game.rb
@@ -60,6 +61,7 @@ files:
60
61
  - lib/lunar_lander/game_states/pause.rb
61
62
  - lib/lunar_lander/game_states/play.rb
62
63
  - lib/lunar_lander/version.rb
64
+ - lib/media/earth.png
63
65
  - lib/media/explosion.wav
64
66
  - lib/media/fierce_wind.wav
65
67
  - lib/media/moon.png