Skip to content

Commit

Permalink
split out into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Nov 14, 2010
1 parent c95c5f2 commit 1a4f7b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
19 changes: 19 additions & 0 deletions lib/enemy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Enemy
def initialize(window)
@window = window
@image = Gosu::Image.new(window, "media/enemy.png", false)
@x = @y = @vel_x = @vel_y = @angle = 0.0
end

def update
@x += 1
@y += 1
if @x > @window.width || @y > @window.height
@window.enemies.delete(self)
end
end

def draw
@image.draw_rot(@x, @y, 1, @angle, 0.5, 0.5, 0.25, 0.25)
end
end
37 changes: 2 additions & 35 deletions lib/game.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'rubygems'
require 'gosu'
require 'enemy'
require 'tower'

class GameWindow < Gosu::Window
attr_reader :enemies
Expand Down Expand Up @@ -31,41 +33,6 @@ def button_down(id)
end
end

class Enemy
def initialize(window)
@window = window
@image = Gosu::Image.new(window, "media/enemy.png", false)
@x = @y = @vel_x = @vel_y = @angle = 0.0
end

def update
@x += 1
@y += 1
if @x > @window.width || @y > @window.height
@window.enemies.delete(self)
end
end

def draw
@image.draw_rot(@x, @y, 1, @angle, 0.5, 0.5, 0.25, 0.25)
end
end

class Tower
# damage

def initialize(window)
@window = window
@image = Gosu::Image.new(window, "media/tower.png", false)
@x = rand(@window.width - 20) + 10
@y = @window.height - 60
end

def draw
@image.draw_rot(@x, @y, 1, 0)
end
end

# class Board
# end

Expand Down
14 changes: 14 additions & 0 deletions lib/tower.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Tower
# damage

def initialize(window)
@window = window
@image = Gosu::Image.new(window, "media/tower.png", false)
@x = rand(@window.width - 20) + 10
@y = @window.height - 60
end

def draw
@image.draw_rot(@x, @y, 1, 0)
end
end

0 comments on commit 1a4f7b4

Please sign in to comment.