Skip to content

Commit

Permalink
+ shooting, explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed May 18, 2009
1 parent eb840c6 commit 71d988c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/ambient/small_explosion.rb
Expand Up @@ -3,20 +3,20 @@ class SmallExplosion < ShortLived
include Hurting

def initialize window
self.lifetime = 15
self.lifetime = 30

super window

@image = Gosu::Image::load_tiles window, "media/small_explosion.png", 20, 20, false
@start = Time.now

@image = Gosu::Image::load_tiles window, "media/small_explosion.png", 16, 16, false
@shape = CP::Shape::Circle.new CP::Body.new(1_000, 1_000), 5.0, CP::Vec2.new(0, 0)

@shape.collision_type = :explosion
end

def draw
image = @image[Gosu::milliseconds / 300 % @image.size];
image.draw_rot self.position.x, self.position.y, ZOrder::Player, drawing_rotation
image = @image[(Time.now - @start)*10 % @image.size];
image.draw_rot self.position.x, self.position.y, ZOrder::Player, drawing_rotation, 0.8, 0.8, 0.8, 0.8
end

end
2 changes: 1 addition & 1 deletion lib/game_window.rb
Expand Up @@ -73,7 +73,7 @@ def setup_collisions
@space.add_collision_func :bullet, :bullet, &nil
@space.add_collision_func :bullet, :gun, &nil
@space.add_collision_func :bullet, :enemy do |bullet_shape, enemy_shape|
small_explosion bullet_shape
@moveables.each { |bullet| bullet.shape == bullet_shape && bullet.destroy }
end
@space.add_collision_func :enemy, :explosion do |enemy_shape, explosion_shape|
@moveables.each { |enemy| enemy.shape == enemy_shape && enemy.lives -= 100 }
Expand Down
2 changes: 1 addition & 1 deletion lib/generator.rb
Expand Up @@ -17,7 +17,7 @@ def generates moveable_class, seconds
module InstanceMethods

def start_generating
threaded 30 do
threaded 5 do
generate
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/thing.rb
Expand Up @@ -5,7 +5,6 @@ class Thing
attr_reader :window, :shape

def initialize window
@running_threads = []
@window = window
end

Expand All @@ -15,7 +14,6 @@ def threaded time, &code

def destroy
@window.unregister self
@running_threads.select { |thread| thread.status == false }.each(&:join)
true
end

Expand Down
13 changes: 12 additions & 1 deletion lib/units/bullet.rb
Expand Up @@ -2,9 +2,11 @@
class Bullet < ShortLived

it_is_a Shot
it_is_a Generator
generates Puff, 0

def initialize window
self.lifetime = 1000
self.lifetime = 400 + rand(700)

super window

Expand All @@ -17,6 +19,15 @@ def initialize window

self.friction = 0.0001
self.velocity = 5 + rand(1)

start_generating
end

def destroy
explosion = SmallExplosion.new window
explosion.warp position
window.register explosion
super
end

def validate_position
Expand Down
2 changes: 1 addition & 1 deletion lib/units/enemy.rb
Expand Up @@ -6,7 +6,7 @@ class Enemy < Moveable
include HorizonOriented
include Targetable

lives 1000
lives 200

def initialize window
super window
Expand Down
4 changes: 2 additions & 2 deletions lib/units/gun.rb
Expand Up @@ -21,8 +21,8 @@ def initialize window
self.muzzle_position_func { self.position }
self.muzzle_velocity_func { |target| (target.position - self.muzzle_position[] + self.random_vector(1/skill)).normalize }
self.muzzle_rotation_func { |target| (target.position - self.muzzle_position[]).to_angle }
self.range = 900
self.frequency = 300
self.range = 700
self.frequency = 100
end

def random_vector strength
Expand Down
Binary file added media/originals/Explosions.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/small_explosion.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 71d988c

Please sign in to comment.