Skip to content

Commit

Permalink
+ starting out on a completely new game :)
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed May 15, 2009
1 parent 9dcde68 commit 9f565ee
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 17 deletions.
19 changes: 9 additions & 10 deletions lib/game_window.rb
Expand Up @@ -47,11 +47,11 @@ def randomly_add type
end

def setup_objects
register Earth.new(self)

7.times { randomly_add Cow }
2.times { randomly_add NukeLauncher }
3.times { randomly_add Gun }
# register Earth.new(self)
#
# 7.times { randomly_add Cow }
# 2.times { randomly_add NukeLauncher }
# 3.times { randomly_add Gun }

add_player1
add_player2
Expand Down Expand Up @@ -186,15 +186,14 @@ def add_player2
# Adds the third player.
#
def add_player3
@player3 = Player.new self
@player3.warp_to SCREEN_WIDTH - 30, 50 # move to the center of the window
# @player2.colorize 0, 255, 0
@player3 = FirstMate.new self
@player3.warp_to 30, 100 # move to the center of the window

@controls << Controls.new(self, @player3,
Gosu::Button::KbLeft => :left,
Gosu::Button::KbRight => :right,
Gosu::Button::KbUp => :away,
Gosu::Button::KbDown => :closer,
Gosu::Button::KbUp => :up,
Gosu::Button::KbDown => :down,
Gosu::Button::KbRightAlt => :shoot,
Gosu::Button::Kb0 => :revive
)
Expand Down
23 changes: 23 additions & 0 deletions lib/horizon_oriented.rb
@@ -0,0 +1,23 @@
module HorizonOriented

def horizontal
CP::Vec2.new(1,0)
end
def vertical
CP::Vec2.new(0,1)
end

def left factor = 0.15
self.speed -= horizontal * factor
end
def right factor = 0.15
self.speed += horizontal * factor
end
def up factor = 0.15
self.speed -= vertical * factor
end
def down factor = 0.15
self.speed += vertical * factor
end

end
18 changes: 18 additions & 0 deletions lib/units/first_mate.rb
@@ -0,0 +1,18 @@
class FirstMate < Player

include HorizonOriented

def initialize window
super window

@image = Gosu::Image.new window, "media/first_mate.png", false
@shape = CP::Shape::Circle.new CP::Body.new(0.1, 0.1), 5.0, CP::Vec2.new(0, 0)

self.shoots Bullet
self.muzzle_position_func { self.position + horizontal * 20 }
self.muzzle_velocity_func { |target| horizontal }
self.muzzle_rotation_func { self.rotation }
self.frequency = 20
end

end
11 changes: 4 additions & 7 deletions lib/units/player.rb
Expand Up @@ -2,7 +2,6 @@
#
class Player < Moveable

include EarthOriented
include Targetable
include Shooter
include Lives
Expand All @@ -16,7 +15,7 @@ def initialize window

@bullet_loaded = true

@image = Gosu::Image::load_tiles window, "media/spaceship.png", 22, 22, false
@image = Gosu::Image.new window, "media/spaceship.png", false

@shape = CP::Shape::Circle.new CP::Body.new(0.1, 0.1), 5.0, CP::Vec2.new(0, 0)

Expand All @@ -32,11 +31,11 @@ def initialize window
# Keep in mind that down the screen is positive y, which means that PI/2 radians,
# which you might consider the top in the traditional Trig unit circle sense is actually
# the bottom; thus 3PI/2 is the top
self.rotation = Math::PI
self.rotation = 0

@shape.collision_type = :ship

self.shoots Ray
self.shoots Bullet
self.muzzle_position_func { self.position + self.direction_to_earth * 20 }
self.muzzle_velocity_func { |target| self.direction_to_earth }
self.muzzle_rotation_func { self.rotation }
Expand All @@ -58,7 +57,6 @@ def colorize red, green, blue
# Wrap to the other side of the screen when we fly off the edge.
#
def validate_position
align_to_earth
if position.x > SCREEN_WIDTH || position.x < 0
@shape.body.v.x = -@shape.body.v.x
end
Expand All @@ -68,7 +66,6 @@ def validate_position
end

def draw
image = @image[Gosu::milliseconds / 100 % @image.size];
image.draw_rot self.position.x, self.position.y, ZOrder::Player, drawing_rotation, 0.5, 0.5, 0.5, 0.5
@image.draw_rot position.x, position.y, ZOrder::Player, drawing_rotation, 1.0, 1.0, 1.0, 1.0
end
end
Binary file added media/RocketJeep.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/admiral.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/captain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/first_mate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/spaceship old.png
Binary file not shown.
2 changes: 2 additions & 0 deletions multiroids.rb
Expand Up @@ -30,6 +30,7 @@
require 'lib/turnable'
require 'lib/accelerateable'
require 'lib/earth_oriented'
require 'lib/horizon_oriented'
require 'lib/targetable'
require 'lib/shooter'
require 'lib/shot'
Expand All @@ -43,6 +44,7 @@
require 'lib/ambient/puff'
require 'lib/ambient/small_explosion'
require 'lib/units/player'
require 'lib/units/first_mate'
require 'lib/units/cow'
require 'lib/units/gun'
require 'lib/units/nuke_launcher'
Expand Down

0 comments on commit 9f565ee

Please sign in to comment.