#===========================================================================
# ** Spriteset_CardBattle
#===========================================================================
class Spriteset_CardBattle
#------------------------------------------------------------------------
# * Virtual Readers
#------------------------------------------------------------------------
def plyr_crds ; $game_tripletriad_battle.player_cards ; end
def opnt_crds ; $game_tripletriad_battle.opponent_cards ; end
def vis_plry_crds ; $game_tripletriad_battle.visible_player_cards ; end
def vis_opnt_crds ; $game_tripletriad_battle.visible_opponent_cards ; end
def plyr_moves ; $game_tripletriad_battle.player_panel_selections ; end
def opnt_moves ; $game_tripletriad_battle.opponent_panel_selections ; end
def plry_index ; $game_tripletriad_battle.player_select_index ; end
def opnt_index ; $game_tripletriad_battle.opponent_select_index ; end #
def dummy_card ; $game_tripletriad_battle.dummy_card ; end
def dummy_index ; $game_tripletriad_battle.dummy_index ; end
def boardpanels ; $game_tripletriad_battle.boardpanels ; end
def plyr_score ; $game_tripletriad_battle.player_score ; end
def opnt_score ; $game_tripletriad_battle.opponent_score ; end
#------------------------------------------------------------------------
# * Object Initialization
#------------------------------------------------------------------------
def initialize
# Creates Background Image
@background = Sprite.new
@background.bitmap = RPG::Cache.triple_triad('')
# Dummy Card
@dummy_card = Sprite.new
@dummy_card.z = 200
# Creates Player & Opponent Cards
@player_cards = []
@opponent_cards = []
for i in 0..4
@player_cards << Sprite.new
@opponent_cards << Sprite.new
@player_cards[i].x, @opponent_cards[i].x = 505, 35
@player_cards[i].y, @opponent_cards[i].y = 480, 480 + i * 96
end
# Creates Board Panel Sprites
@board_panels = [ [], [], [] ]
for i in 0..2
3.times {@board_panels[i] << Sprite.new}
end
for i in 0..2
for j in 0..2
@board_panels[i][j].x = 170 + 100 * i
@board_panels[i][j].y = 83 + 127 * j
end
end
# Score Sprites
@player_score = Sprite.new
@player_score.bitmap = Bitmap.new(100, 32)
@player_score.bitmap.font.size = 32
@player_score.x, @player_score.y = 505, 430
@opponent_score = Sprite.new
@opponent_score.bitmap = Bitmap.new(100, 32)
@opponent_score.bitmap.font.size = 32
@opponent_score.x, @opponent_score.y = 35, 430
# Update Graphics
update
# Refresh Graphics
refresh_dummy_card
refresh_player_cards
refresh_opponent_cards
refresh_board_panels
refresh_score
end
#------------------------------------------------------------------------
# * Frame Update
#------------------------------------------------------------------------
def update
# If Game Player
if $scene.phase.nil? || $scene.phase < 7
# If Card Selection
if $scene.phase == 1 && dummy_card != nil
# Set Bitmap
deck = $data_tripletriad_decks[dummy_card[0]]
card = deck.cards[dummy_card[1]][dummy_card[2]]
bitmap = RPG::Cache.triple_triad("Cards/#{deck.name}/#{card.name}")
bitmap.font.size = 24
bitmap.font.name = "Calibri"
bitmap.draw_text(15,5,24,24,card.np.to_s)
bitmap.draw_text(5,25,24,24,card.wp.to_s)
bitmap.draw_text(25,25,24,24,card.ep.to_s)
bitmap.draw_text(15,45,24,24,card.sp.to_s)
@dummy_card.bitmap = bitmap
# Handel X & Y Location
@dummy_card.x = 386
@dummy_card.y = 100
end
# Passes Through Card List
for i in 0..4
# If No Card Is Selected
unless plyr_crds[i].nil?
@player_cards[i].y -= 12 if @player_cards[i].y > 96 + i * 48
end
# If No Card Is Selected
unless opnt_crds[i].nil?
@opponent_cards[i].y -= 12 if @opponent_cards[i].y > 96 + i * 48
end
# Alter X & Z
if plry_index == i
@player_cards[i].x = 515
@player_cards[i].z = 250
else
@player_cards[i].x = 505
@player_cards[i].z = 100 + i
end
# Alter X & Z
if opnt_index == i
@opponent_cards[i].x = 45
@opponent_cards[i].z = 250
else
@opponent_cards[i].x = 35
@opponent_cards[i].z = 100 + i
end
end
else
for i in 0..4
@opponent_cards[i].y = i == dummy_index ? 310 : 300
@player_cards[i].visible = vis_plry_crds[i]
@opponent_cards[i].visible = vis_opnt_crds[i]
end
end
end
#------------------------------------------------------------------------
# * Refresh : Dummy Card
#------------------------------------------------------------------------
def refresh_dummy_card
# If No Card
if dummy_card.nil?
# Dispose Bitmap
unless @dummy_card.bitmap.nil?
@dummy_card.bitmap.dispose
@dummy_card.bitmap = nil
end
else
# Handel X & Y Location
@dummy_card.x = dummy_index % 3 * 100 + 170
@dummy_card.y = dummy_index / 3 * 127 + 83
# Handels Bitmap
deckname = $data_tripletriad_decks[dummy_card[0]].name
cardname = dummy_card[1].name
bitmap = RPG::Cache.triple_triad("Cards/#{deckname}/#{cardname}")
card = dummy_card[1]
$bpcard = card
bitmap.font.size = 24
bitmap.font.name = "Calibri"
bitmap.draw_text(15,5,24,24,card.np.to_s)
bitmap.draw_text(5,25,24,24,card.wp.to_s)
bitmap.draw_text(25,25,24,24,card.ep.to_s)
bitmap.draw_text(15,45,24,24,card.sp.to_s)
@dummy_card.bitmap = bitmap
end
end
#------------------------------------------------------------------------
# * Refresh : Player Cards
#------------------------------------------------------------------------
def refresh_player_cards
# Passes Through Card List
for i in 0..4
# If No Card Is Selected
if plyr_crds[i].nil?
# If Bitmap Exist
unless @player_cards[i].bitmap.nil?
# Dispose Bitmap & Move Off Screen
@player_cards[i].bitmap.dispose
@player_cards[i].bitmap = nil
@player_cards[i].y = 480
end
# If Card Is Selected
else
# Checks Player Card
deck_name = $data_tripletriad_decks[plyr_crds[i][0]].name
card_name = plyr_crds[i][3].name
# Gets Filename
filename = "Cards/#{deck_name}/#{card_name}"
# Sets Bitmap To Sprite
@player_cards[i].bitmap = RPG::Cache.triple_triad(filename)
card = plyr_crds[i][3]
@player_cards[i].bitmap.font.size = 24
@player_cards[i].bitmap.font.name = "Calibri"
@player_cards[i].bitmap.draw_text(15,5,24,24,card.np.to_s)
@player_cards[i].bitmap.draw_text(5,25,24,24,card.wp.to_s)
@player_cards[i].bitmap.draw_text(25,25,24,24,card.ep.to_s)
@player_cards[i].bitmap.draw_text(15,45,24,24,card.sp.to_s)
# Move Card Up
end
# Alters Visibility
@player_cards[i].visible = vis_plry_crds[i]
end
end
#------------------------------------------------------------------------
# * Refresh : Opponent Cards
#------------------------------------------------------------------------
def refresh_opponent_cards
# Passes Through Card List
for i in 0..4
# If No Card Is Selected
if opnt_crds[i].nil?
# If Bitmap Exist
unless @opponent_cards[i].bitmap.nil?
# Dispose Bitmap & Move Off Screen
@opponent_cards[i].bitmap.dispose
@opponent_cards[i].bitmap = nil
@opponent_cards[i].y = 480 + i * 96
end
# If Card Is Selected
else
# If Open Rule
if $game_tripletriad.game_rules[0]
# Checks Player Card
deck_name = $data_tripletriad_decks[opnt_crds[i][0]].name
card_name = opnt_crds[i][3].name
# Gets Filename
filename = "Cards/#{deck_name}/#{card_name} - r"
else
filename = "Cards/Blank Cards/Panel_0"
end
# Sets Bitmap To Sprite
@opponent_cards[i].bitmap = RPG::Cache.triple_triad(filename)
end
# Alters Visibility
@opponent_cards[i].visible = vis_opnt_crds[i]
end
end
#------------------------------------------------------------------------
# * Refresh : Board Panels
#------------------------------------------------------------------------
def refresh_board_panels
# Passes Through 3 Rows
for i in 0..2
# Passes Through 3 Columns
for j in 0..2
# Set Bitmap
@board_panels[i][j].bitmap = boardpanels[i][j].bitmap
end
end
end
#------------------------------------------------------------------------
# * Refresh : Score
#------------------------------------------------------------------------
def refresh_score
# Updates Scores
if $scene.phase.nil? || $scene.phase < 3
@player_score.visible = false
@opponent_score.visible = false
else
@player_score.visible = true
@opponent_score.visible = true
end
@player_score.bitmap.clear
@opponent_score.bitmap.clear
@player_score.bitmap.draw_text(0, 0, 100, 32, plyr_score.to_s, 1)
@opponent_score.bitmap.draw_text(0, 0, 100, 32, opnt_score.to_s, 1)
end
#------------------------------------------------------------------------
# * Refresh : Card Results
#------------------------------------------------------------------------
def refresh_card_results
# Passes Through All Player & Opponent Cards
for i in 0..4
# ~ Player Cards
# Sets Bitmap To Sprite
deck_name = $data_tripletriad_decks[plyr_crds[i][0]].name
card_name = plyr_crds[i][3].name
filename = "Cards/#{deck_name}/#{card_name}"
# Checks Panel Possession
if plyr_moves.has_key?(i)
x, y = plyr_moves[i] % 3, plyr_moves[i] / 3
filename += ' - r' unless boardpanels[x][y].players
end
card = plyr_crds[i][3]
@player_cards[i].bitmap = RPG::Cache.triple_triad(filename)
@player_cards[i].bitmap.font.size = 24
@player_cards[i].bitmap.font.name = "Calibri"
@player_cards[i].bitmap.draw_text(15,5,24,24,card.np.to_s)
@player_cards[i].bitmap.draw_text(5,25,24,24,card.wp.to_s)
@player_cards[i].bitmap.draw_text(25,25,24,24,card.ep.to_s)
@player_cards[i].bitmap.draw_text(15,45,24,24,card.sp.to_s)
# ~ Opponent Cards
# Sets Bitmap To Sprite
deck_name = $data_tripletriad_decks[opnt_crds[i][0]].name
card_name = opnt_crds[i][3].name
filename = "Cards/#{deck_name}/#{card_name} - r"
# Checks Panel Possession
if opnt_moves.has_key?(i)
x, y = opnt_moves[i] % 3, opnt_moves[i] / 3
if boardpanels[x][y].players
4.times {filename.pop}
end
end
card = opnt_crds[i][3]
@opponent_cards[i].bitmap = RPG::Cache.triple_triad(filename)
@opponent_cards[i].bitmap.font.size = 24
@opponent_cards[i].bitmap.font.name = "Calibri"
@opponent_cards[i].bitmap.draw_text(15,5,24,24,card.np.to_s)
@opponent_cards[i].bitmap.draw_text(5,25,24,24,card.wp.to_s)
@opponent_cards[i].bitmap.draw_text(25,25,24,24,card.ep.to_s)
@opponent_cards[i].bitmap.draw_text(15,45,24,24,card.sp.to_s)
# Turns Cards On & Moves To Coordinates
@player_cards[i].visible = true
@opponent_cards[i].visible = true
@player_cards[i].y = 100
@opponent_cards[i].y = 300
@player_cards[i].x = 70 + i * 100
@opponent_cards[i].x = 70 + i * 100
# Turns Visibility On
$game_tripletriad_battle.visible_player_cards[i] = true
$game_tripletriad_battle.visible_opponent_cards[i] = true
end
# Clears Panels
for i in 0..2
@board_panels[i].each {|panel| panel.visible = false}
end
end
#------------------------------------------------------------------------
# * Dispose
#------------------------------------------------------------------------
def dispose
# Dispose Background
@background.dispose
# Dispose Player & Opponent Cards
@player_cards.each {|card| card.dispose}
@opponent_cards.each {|card| card.dispose}
# Dispose Board Panel Sprites
for i in 0..2
@board_panels[i].each {|panel| panel.dispose}
end
# Dipsose Scores
@player_score.dispose
@opponent_score.dispose
end
end