Skip to content

Commit

Permalink
fixing some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Aug 8, 2012
1 parent c2565db commit e03e86c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 61 deletions.
38 changes: 21 additions & 17 deletions assets/maps/level_3.txt
Expand Up @@ -2,20 +2,24 @@
#........................................................#
#........................................................#
#........................................................#
#.......................................................x#
#""""""""""""""""""""""""""""""""""""""""""""""""""""....#
#........................................................#
#........................................................#
#........................................................#
###......................................................#
#........""..............................................#
#........##..............................................#
#........................................................#
###......................................................#
#........................................................#
#........................................................#
#........................................................#
###......................................................#
#................x.......................................#
#...............###......................................#
#"""""""""""""#######""""""""""""""""""""""""""""""""""""#
#......"."."."."."."......".".".........................x#
#..""""###.#.#.#.#.#""""".#.#.#""""""""""""""""""""""....#
##........"#"#"#"#"#....."#"#"#..........................#
#.........#.#.#.#.#......#.#.#...........................#
#x.#.....................................................#
#........x...............................................#
#x.......""..............................................#
###..#...##........#.....................................#
#......................##................................#
#x.............#................""..x....................#
###.............................##""""..x................#
#.................................####..#..x.............#
#x......................................#..#..x..........#
###.....................................#..#..#..x.......#
#................x.........................#..#..#.......#
#x..............###...........................#..#.x.x.x.#
#""""""""""""".######"""""""""""""""""##"""""""""""""""""#
#..............#.......................#.................#
#............##...xxxxxx......xxxxxx..##.................#
#.................xxxxxx......xxxxxx.###.................#
#""""""""""""""""""""""""""""""""""""""""""""""""""""""""#
11 changes: 7 additions & 4 deletions lib/end_game_screen.rb
Expand Up @@ -5,7 +5,7 @@ def initialize(window)
@window = window
@window.cursor_active = true
@text = Gosu::Font.new(window, Gosu.default_font_name, 30)
@code = "X2D5A3Q"
@code = "X2D5A3Q" #Generate unique code
@end_song = Gosu::Song.new(window, asset_path('end-game.ogg'))
tweet_text = "I%20just%20played%20and%20beat%20%23PCOTM%20http%3A%2F%2Fbit.ly%2FMbZUMo%20%40PhoneCaseOfTheM"
@tweet_url = "https://twitter.com/intent/tweet?#{tweet_text}"
Expand All @@ -15,9 +15,10 @@ def initialize(window)
def draw
@text.draw("CONGRATS!", 100, 80, 3, 1.0, 1.0, 0xff086279)
@text.draw("You completed PCOTM.", 100, 120, 3, 1.0, 1.0, 0xff086279)
@text.draw("Sign up for phonecaseofthemonth.com", 100, 160, 3, 1.0, 1.0, 0xff086279)
@text.draw("and enter #{@code} for a free case!", 100, 190, 3, 1.0, 1.0, 0xff086279)
@text.draw("press enter to get started esc to quit", 100, 350, 3, 1.0, 1.0, 0xff086279)
@text.draw("Sign up for PhoneCaseOfTheMonth.com", 100, 160, 3, 1.0, 1.0, 0xff086279)
#@text.draw("and enter #{@code} for a free case!", 100, 190, 3, 1.0, 1.0, 0xff086279)
@text.draw("press enter to get started, esc to quit,", 100, 350, 3, 1.0, 1.0, 0xff086279)
@text.draw("or tweet this by pressing t", 100, 380, 3, 1.0, 1.0, 0xff086279)
end

def update
Expand All @@ -27,6 +28,8 @@ def update
def keys(id)
if id == Gosu::KbReturn
`open #{@pcotm_url}`
elsif id == Gosu::KbT
`open #{@tweet_url}`
end
end

Expand Down
9 changes: 1 addition & 8 deletions lib/info_screen.rb
Expand Up @@ -29,14 +29,7 @@ def update
end

def keys(id)
case id
when Gosu::KbUp

when Gosu::KbDown

when Gosu::KbReturn
@window.goto(TitleScreen.new(@window))
end
@window.goto(TitleScreen.new(@window))
end

end
10 changes: 5 additions & 5 deletions lib/map.rb
Expand Up @@ -6,12 +6,12 @@ def initialize(window, level)
# Load 60x60 tiles, 5px overlap in all four directions.
@tileset = Gosu::Image.load_tiles(window, asset_path('land-tiles.png'), 60, 60, true)

self.phones = []
@phones = []

lines = File.readlines(filename).map { |line| line.chomp }
self.height = lines.size
self.width = lines[0].size
self.tiles = Array.new(width) do |x|
@height = lines.size
@width = lines[0].size
@tiles = Array.new(width) do |x|
Array.new(height) do |y|
case lines[y][x, 1]
when '"'
Expand All @@ -20,7 +20,7 @@ def initialize(window, level)
Tiles::EARTH
when 'x'
phone_img = Gosu::Image.new(window, asset_path("phone_#{rand(14) + 1}.png"), false)
self.phones << Phone.new(phone_img, x * 50 + 25, y * 50 + 25)
@phones << Phone.new(phone_img, x * 50 + 25, y * 50 + 25)
nil
else
nil
Expand Down
4 changes: 2 additions & 2 deletions lib/monster.rb
Expand Up @@ -10,7 +10,7 @@ def initialize(window, x, y, color = :blue)
@standing, @walk1, @walk2, @jump = *Gosu::Image.load_tiles(window, asset_path("monster_#{color}.png"), 50, 50, false)
@cur_image = @standing
@phones = 0
self.level_phone_count = 0
@level_phone_count = 0
@beep = Gosu::Sample.new(window, asset_path('beep.wav'))
end

Expand Down Expand Up @@ -65,7 +65,7 @@ def collect_phones(phones)
phones.reject! do |phone|
if (phone.x - @x).abs < 50 and (phone.y - @y).abs < 50
@phones += 1
self.level_phone_count += 1
@level_phone_count += 1
@beep.play
true
end
Expand Down
6 changes: 3 additions & 3 deletions lib/timer.rb
Expand Up @@ -7,7 +7,7 @@ def initialize(window)
@seconds = 0
@last_time = Gosu.milliseconds
@font = Gosu::Font.new(window, Gosu.default_font_name, 26)
self.stopped_time = ""
@stopped_time = ""
end

def update
Expand All @@ -25,7 +25,7 @@ def update
end
end

def print(x, y)
def draw(x, y)
@font.draw("Elapsed Time: #{formatted}",x, y, 3, 1.0, 1.0, 0xff6F0000)
end

Expand All @@ -34,7 +34,7 @@ def formatted
end

def reset!
self.stopped_time = formatted
@stopped_time = formatted
@hours = @minutes = @seconds = 0
@last_time = Gosu.milliseconds
end
Expand Down
45 changes: 23 additions & 22 deletions lib/window.rb
@@ -1,26 +1,25 @@
class Window < Gosu::Window
attr_reader :game_song
attr_accessor :map, :game_in_progress, :current_screen, :current_level, :monster, :timer, :cursor_active
attr_accessor :map, :game_in_progress, :current_screen, :current_level, :monster, :timer, :cursor_active, :phones_to_collect

def initialize
super 640, 480, false
self.caption = "Phone Case of the Monster"
self.current_level = 3
self.current_screen = TitleScreen.new(self)
self.cursor_active = false
self.map = Map.new(self, current_level)
@caption = "Phone Case of the Monster"
@current_level = 1
@current_screen = TitleScreen.new(self)
@cursor_active = false
@map = Map.new(self, current_level)
@timer = Timer.new(self)
@sky = Gosu::Image.new(self, asset_path('background.png'), true)
@camera_x = @camera_y = 0
@score_font = Gosu::Font.new(self, Gosu.default_font_name, 26)
@game_in_progress = false

@phones_to_collect = map.total_phones
@game_song = Gosu::Song.new(self, asset_path('game-song.ogg'))
end

def update
if @game_in_progress
@timer.update
move_x = 0
move_x -= 5 if button_down? Gosu::KbLeft
move_x += 5 if button_down? Gosu::KbRight
Expand All @@ -35,6 +34,7 @@ def update
end
@camera_x = [[@monster.x - 320, 0].max, map.width * 50 - 640].min
@camera_y = [[@monster.y - 240, 0].max, map.height * 50 - 480].min
@timer.update
else
current_screen.update
end
Expand All @@ -48,14 +48,14 @@ def draw
@monster.draw
end
translate 10, 10 do
score_text = "Phones Collected: #{@monster.phones} / #{map.total_phones}"
score_text = "Phones Collected: #{@monster.phones} / #{@phones_to_collect}"
score_width = @score_font.text_width(score_text)
draw_quad 0, 0, 0xaa000000,
score_width, 0, 0xaa000000,
0, @score_font.height, 0xaa000000,
score_width, @score_font.height, 0xaa000000
@score_font.draw(score_text, 0, 0, 3, 1.0, 1.0, 0xffffffff)
@timer.print(300, 0)
@timer.draw(300, 0)
end
else
current_screen.draw
Expand All @@ -76,33 +76,34 @@ def game_keys(id)
end

def goto(screen)
self.current_screen = screen
@current_screen = screen
end

def load_new_level
self.game_in_progress = false
self.current_level += 1
self.map = Map.new(self, current_level)
@game_in_progress = false
@current_level += 1
@map = Map.new(self, current_level)
@monster.map = map
@timer.reset!
self.current_screen = ScoreScreen.new(self, @timer)
self.game_song.stop
@current_screen = ScoreScreen.new(self, @timer)
@game_song.stop
@monster.level_phone_count = 0
@camera_x = @camera_y = 0
@monster.x = 100
@monster.y = 50
@phones_to_collect = @map.total_phones + @monster.level_phone_count
end

def start_new_level
self.game_in_progress = true
self.game_song.play(true)
self.timer = Timer.new(self)
@game_in_progress = true
@game_song.play(true)
@timer = Timer.new(self)
end

def load_end_game
self.game_in_progress = false
self.current_screen = EndGameScreen.new(self)
self.game_song.stop
@game_in_progress = false
@current_screen = EndGameScreen.new(self)
@game_song.stop
current_screen.end_song.play(true)
end

Expand Down

0 comments on commit e03e86c

Please sign in to comment.