Skip to content

Commit

Permalink
growl notifs for battle
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodspeed committed Oct 13, 2010
1 parent 4ac1a65 commit dfbf816
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions spike.rb
Expand Up @@ -969,10 +969,11 @@ def json_params
end

class Notification
attr_reader :message, :time_to_live
def initialize(msg, ttl)
attr_reader :message, :time_to_live, :location
def initialize(msg, ttl, location)
@message = msg
@time_to_live = ttl
@location = location
end

def displayed
Expand All @@ -984,6 +985,17 @@ def dead?
end
end

class WorldScreenNotification < Notification
def initialize(msg)
super(msg,@@TICKS_TO_DISPLAY_NOTIFICATIONS, [@@NOTIFICATION_LAYER_INSET_X,@@NOTIFICATION_LAYER_INSET_Y ])
end
end
class BattleScreenNotification < Notification
def initialize(msg)
super(msg,@@TICKS_TO_DISPLAY_NOTIFICATIONS, [@@NOTIFICATION_LAYER_INSET_X,@@NOTIFICATION_LAYER_INSET_Y/3 ])
end
end

class AbstractLayer
include FontLoader #TODO unify resource loading
attr_accessor :active
Expand Down Expand Up @@ -1019,14 +1031,18 @@ def add_notification(notification)
def draw
@layer.fill(:black)
@notifications.each do |notif|
@text_rendering_helper.render_lines_to_layer( notif.message, @config)
@text_rendering_helper.render_lines_to_layer( notif.message, @config) #TODO this is where the ugly pop text is formatted
notif.displayed
end

@notifications.delete_if do |notif|
notif.dead?
end
@layer.blit(@screen, [@@NOTIFICATION_LAYER_INSET_X, @@NOTIFICATION_LAYER_INSET_Y])

unless @notifications.empty?
@layer.blit(@screen, @notifications[0].location)
end

@active = false if @notifications.empty?
end
end
Expand Down Expand Up @@ -1120,7 +1136,6 @@ def update( event )
end
def start_battle(game, universe, player, monster)
@active = true
puts "starting battle, bound field value is #{self.active?}"
@battle = Battle.new(game, universe, player, monster, self)
sections = player.party.collect {|hero| HeroMenuSection.new(hero, [AttackAction.new("Attack", self), ItemAction.new("Item")])}
@menu_helper = BattleMenuHelper.new(@battle, @screen, @layer, @text_rendering_helper, sections, @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
Expand Down Expand Up @@ -1160,7 +1175,6 @@ def draw()
end

def enter_current_cursor_location(game)
puts "weird: game is #{game}" if @battle.nil?
if @battle.over?
@end_of_battle_menu_helper.enter_current_cursor_location(game)
else
Expand Down Expand Up @@ -1240,8 +1254,9 @@ def activate(party_member_index, game, submenu_idx)
hero = battle.player.party.members[party_member_index]
battle.monster.take_damage(hero.damage)
hero.consume_readiness(@action_cost)
puts "hero #{hero} hit #{battle.monster} for #{hero.damage}"
puts "hero #{hero} killed #{battle.monster}" if battle.monster.dead?
msg = "attacked for #{hero.damage} damage"
# msg += "hero #{hero} killed #{battle.monster}" if battle.monster.dead?
game.add_notification(BattleScreenNotification.new("Attacked for #{}"))
end
end
class ItemAction < MenuAction
Expand Down Expand Up @@ -1280,7 +1295,7 @@ def activate(menu_idx, game, submenu_idx)
puts "player was at #{game.player.px} and #{game.player.py} at save time"
puts "save action believes the menu layer to be active? #{game.universe.menu_layer.active}"
game.toggle_menu
game.add_notification(Notification.new("Saved to #{slot}", @@TICKS_TO_DISPLAY_NOTIFICATIONS))
game.add_notification(WorldScreenNotification.new("Saved to #{slot}"))
end
end

Expand Down Expand Up @@ -1328,7 +1343,7 @@ def activate(menu_idx, game, submenu_idx)
rebuilt = JSON.parse(data.join(" "))
puts "got rebuilt: #{rebuilt.class} "
ReloaderHelper.new.replace(game, rebuilt)
game.add_notification(Notification.new("Loaded from #{slot}", @@TICKS_TO_DISPLAY_NOTIFICATIONS))
game.add_notification(WorldScreenNotification.new("Loaded from #{slot}"))
end
end

Expand Down

0 comments on commit dfbf816

Please sign in to comment.