mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 14:14:59 +00:00
Yet more script rearranging
This commit is contained in:
391
Data/Scripts/017_Minigames/001_Minigame_Duel.rb
Normal file
391
Data/Scripts/017_Minigames/001_Minigame_Duel.rb
Normal file
@@ -0,0 +1,391 @@
|
||||
#===============================================================================
|
||||
# "Duel" mini-game
|
||||
# Based on the Duel minigame by Alael
|
||||
#===============================================================================
|
||||
class DuelWindow < Window_AdvancedTextPokemon
|
||||
attr_reader :hp
|
||||
attr_reader :name
|
||||
attr_reader :is_enemy
|
||||
|
||||
def initialize(name, is_enemy)
|
||||
@hp = 10
|
||||
@name = name
|
||||
@is_enemy = is_enemy
|
||||
super()
|
||||
self.width = 160
|
||||
self.height = 96
|
||||
duel_refresh
|
||||
end
|
||||
|
||||
def hp=(value)
|
||||
@hp = value
|
||||
duel_refresh
|
||||
end
|
||||
|
||||
def name=(value)
|
||||
@name = value
|
||||
duel_refresh
|
||||
end
|
||||
|
||||
def is_enemy=(value)
|
||||
@is_enemy = value
|
||||
duel_refresh
|
||||
end
|
||||
|
||||
def duel_refresh
|
||||
name_color = @is_enemy ? "<ar><c3=E00808,F8B870>" : "<c3=3050C8,A0C0F0>"
|
||||
hp_color = "<c3=209808,90F090>"
|
||||
self.text = _INTL("{1}{2}\r\n{3}HP: {4}", name_color, fmtescape(@name), hp_color, @hp)
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PokemonDuel
|
||||
def pbStartDuel(opponent, event)
|
||||
@event = event
|
||||
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
||||
@viewport.z = 99999
|
||||
@sprites = {}
|
||||
@sprites["player"] = IconSprite.new(-128 - 32, 96, @viewport)
|
||||
@sprites["player"].setBitmap(GameData::TrainerType.front_sprite_filename($Trainer.trainer_type))
|
||||
@sprites["opponent"] = IconSprite.new(Graphics.width + 32, 96, @viewport)
|
||||
@sprites["opponent"].setBitmap(GameData::TrainerType.front_sprite_filename(opponent.trainer_type))
|
||||
@sprites["playerwindow"] = DuelWindow.new($Trainer.name, false)
|
||||
@sprites["playerwindow"].x = -@sprites["playerwindow"].width
|
||||
@sprites["playerwindow"].viewport = @viewport
|
||||
@sprites["opponentwindow"] = DuelWindow.new(opponent.name, true)
|
||||
@sprites["opponentwindow"].x = Graphics.width
|
||||
@sprites["opponentwindow"].viewport = @viewport
|
||||
pbWait(Graphics.frame_rate / 2)
|
||||
distance_per_frame = 8 * 20 / Graphics.frame_rate
|
||||
while @sprites["player"].x < 0
|
||||
@sprites["player"].x += distance_per_frame
|
||||
@sprites["playerwindow"].x += distance_per_frame
|
||||
@sprites["opponent"].x -= distance_per_frame
|
||||
@sprites["opponentwindow"].x -= distance_per_frame
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
@oldmovespeed = $game_player.move_speed
|
||||
@oldeventspeed = event.move_speed
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::DirectionFixOn])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::DirectionFixOn])
|
||||
pbWait(Graphics.frame_rate * 3 / 4)
|
||||
end
|
||||
|
||||
def pbDuel(opponent, event, speeches)
|
||||
pbStartDuel(opponent, event)
|
||||
@hp = [10, 10]
|
||||
@special = [false, false]
|
||||
decision = nil
|
||||
loop do
|
||||
@hp[0] = 0 if @hp[0] < 0
|
||||
@hp[1] = 0 if @hp[1] < 0
|
||||
pbRefresh
|
||||
if @hp[0] <= 0
|
||||
decision = false
|
||||
break
|
||||
elsif @hp[1] <= 0
|
||||
decision = true
|
||||
break
|
||||
end
|
||||
action = 0
|
||||
scores = [3, 4, 4, 2]
|
||||
choices = (@special[1]) ? 3 : 4
|
||||
scores[3] = 0 if @special[1]
|
||||
total = scores[0] + scores[1] + scores[2] + scores[3]
|
||||
if total <= 0
|
||||
action = rand(choices)
|
||||
else
|
||||
num = rand(total)
|
||||
cumtotal = 0
|
||||
for i in 0...4
|
||||
cumtotal += scores[i]
|
||||
if num < cumtotal
|
||||
action = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
@special[1] = true if action == 3
|
||||
pbMessage(_INTL("{1}: {2}", opponent.name, speeches[action * 3 + rand(3)]))
|
||||
list = [
|
||||
_INTL("DEFEND"),
|
||||
_INTL("PRECISE ATTACK"),
|
||||
_INTL("FIERCE ATTACK")
|
||||
]
|
||||
list.push(_INTL("SPECIAL ATTACK")) if !@special[0]
|
||||
command = pbMessage(_INTL("Choose a command."), list, 0)
|
||||
@special[0] = true if command == 3
|
||||
if action == 0 && command == 0
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ScriptAsync, "moveRight90",
|
||||
PBMoveRoute::ScriptAsync, "moveLeft90",
|
||||
PBMoveRoute::ScriptAsync, "moveLeft90",
|
||||
PBMoveRoute::ScriptAsync, "moveRight90"])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ScriptAsync, "moveLeft90",
|
||||
PBMoveRoute::ScriptAsync, "moveRight90",
|
||||
PBMoveRoute::ScriptAsync, "moveRight90",
|
||||
PBMoveRoute::ScriptAsync, "moveLeft90"])
|
||||
pbWait(Graphics.frame_rate / 2)
|
||||
pbMessage(_INTL("You study each other's movements..."))
|
||||
elsif action == 0 && command == 1
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 4 / 10)
|
||||
pbShake(9, 9, 8)
|
||||
pbFlashScreens(false, true)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
@hp[1] -= 1
|
||||
pbMessage(_INTL("Your attack was not blocked!"))
|
||||
elsif action == 0 && command == 2
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Backward])
|
||||
pbWait(Graphics.frame_rate)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Forward])
|
||||
pbMessage(_INTL("Your attack was evaded!"))
|
||||
elsif (action == 0 || action == 1 || action == 2) && command == 3
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbWait(Graphics.frame_rate * 4 / 10)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 5,
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbWait(Graphics.frame_rate / 2)
|
||||
pbShake(9, 9, 8)
|
||||
pbFlashScreens(false, true)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Forward])
|
||||
@hp[1] -= 3
|
||||
pbMessage(_INTL("You pierce through the opponent's defenses!"))
|
||||
elsif action == 1 && command == 0
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 4 / 10)
|
||||
pbShake(9, 9, 8)
|
||||
pbFlashScreens(true, false)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
@hp[0] -= 1
|
||||
pbMessage(_INTL("You fail to block the opponent's attack!"))
|
||||
elsif action == 1 && command == 1
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 6 / 10)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 6 / 10)
|
||||
pbMoveRoute(event, [PBMoveRoute::Backward])
|
||||
pbMoveRoute($game_player, [PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 6 / 10)
|
||||
pbMoveRoute($game_player, [PBMoveRoute::Backward])
|
||||
pbMessage(_INTL("You cross blades with the opponent!"))
|
||||
elsif (action == 1 && command == 2) ||
|
||||
(action == 2 && command == 1) ||
|
||||
(action == 2 && command == 2)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbWait(Graphics.frame_rate * 8 / 10)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Forward])
|
||||
pbWait(Graphics.frame_rate * 9 / 10)
|
||||
pbShake(9, 9, 8)
|
||||
pbFlashScreens(true, true)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbWait(Graphics.frame_rate)
|
||||
pbMoveRoute(event, [PBMoveRoute::Forward])
|
||||
pbMoveRoute($game_player, [PBMoveRoute::Forward])
|
||||
@hp[0] -= action # Enemy action
|
||||
@hp[1] -= command # Player command
|
||||
pbMessage(_INTL("You hit each other!"))
|
||||
elsif action == 2 && command == 0
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::Forward])
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpBackward"])
|
||||
pbWait(Graphics.frame_rate)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Forward])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
pbMessage(_INTL("You evade the opponent's attack!"))
|
||||
elsif action == 3 && (command == 0 || command == 1 || command == 2)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbWait(Graphics.frame_rate * 4 / 10)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 5,
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbWait(Graphics.frame_rate / 2)
|
||||
pbShake(9, 9, 8)
|
||||
pbFlashScreens(true, false)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Forward])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 2,
|
||||
PBMoveRoute::Backward])
|
||||
@hp[0] -= 3
|
||||
pbMessage(_INTL("The opponent pierces through your defenses!"))
|
||||
elsif action == 3 && command == 3
|
||||
pbMoveRoute($game_player, [PBMoveRoute::Backward])
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::Wait, 15,
|
||||
PBMoveRoute::ChangeSpeed, 4,
|
||||
PBMoveRoute::ScriptAsync, "jumpForward"])
|
||||
pbWait(Graphics.frame_rate)
|
||||
pbMoveRoute(event, [
|
||||
PBMoveRoute::ChangeSpeed, 5,
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::ChangeSpeed, 5,
|
||||
PBMoveRoute::Backward,
|
||||
PBMoveRoute::ChangeSpeed, 2])
|
||||
pbShake(9, 9, 8)
|
||||
pbFlash(Color.new(255, 255, 255, 255), 20)
|
||||
pbFlashScreens(true, true)
|
||||
pbMoveRoute($game_player, [PBMoveRoute::Forward])
|
||||
@hp[0] -= 4
|
||||
@hp[1] -= 4
|
||||
pbMessage(_INTL("Your special attacks collide!"))
|
||||
end
|
||||
end
|
||||
pbEndDuel
|
||||
return decision
|
||||
end
|
||||
|
||||
def pbEndDuel
|
||||
pbWait(Graphics.frame_rate * 3 / 4)
|
||||
pbMoveRoute($game_player, [
|
||||
PBMoveRoute::DirectionFixOff,
|
||||
PBMoveRoute::ChangeSpeed, @oldmovespeed])
|
||||
pbMoveRoute(@event, [
|
||||
PBMoveRoute::DirectionFixOff,
|
||||
PBMoveRoute::ChangeSpeed, @oldeventspeed])
|
||||
fade_time = Graphics.frame_rate * 4 / 10
|
||||
alpha_diff = (255.0 / fade_time).ceil
|
||||
fade_time.times do
|
||||
@sprites["player"].opacity -= alpha_diff
|
||||
@sprites["opponent"].opacity -= alpha_diff
|
||||
@sprites["playerwindow"].contents_opacity -= alpha_diff
|
||||
@sprites["opponentwindow"].contents_opacity -= alpha_diff
|
||||
@sprites["playerwindow"].opacity -= alpha_diff
|
||||
@sprites["opponentwindow"].opacity -= alpha_diff
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@viewport.dispose
|
||||
end
|
||||
|
||||
def pbFlashScreens(player, opponent)
|
||||
i = 0
|
||||
flash_time = Graphics.frame_rate * 2 / 10
|
||||
alpha_diff = (2 * 255.0 / flash_time).ceil
|
||||
flash_time.times do
|
||||
i += 1
|
||||
if player
|
||||
@sprites["player"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
@sprites["playerwindow"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
end
|
||||
if opponent
|
||||
@sprites["opponent"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
@sprites["opponentwindow"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
end
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
flash_time.times do
|
||||
i -= 1
|
||||
if player
|
||||
@sprites["player"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
@sprites["playerwindow"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
end
|
||||
if opponent
|
||||
@sprites["opponent"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
@sprites["opponentwindow"].color = Color.new(255, 255, 255, i * alpha_diff)
|
||||
end
|
||||
Graphics.update
|
||||
Input.update
|
||||
pbUpdateSceneMap
|
||||
end
|
||||
pbWait(Graphics.frame_rate * 4 / 10) if !player || !opponent
|
||||
end
|
||||
|
||||
def pbRefresh
|
||||
@sprites["playerwindow"].hp = @hp[0]
|
||||
@sprites["opponentwindow"].hp = @hp[1]
|
||||
pbWait(Graphics.frame_rate / 4)
|
||||
end
|
||||
end
|
||||
|
||||
# Starts a duel.
|
||||
# trainer_id - ID or symbol of the opponent's trainer type.
|
||||
# trainer_name - Name of the opponent
|
||||
# event - Game_Event object for the character's event
|
||||
# speeches - Array of 12 speeches
|
||||
def pbDuel(trainer_id, trainer_name, event, speeches)
|
||||
trainer_id = GameData::TrainerType.get(trainer_id).id
|
||||
duel = PokemonDuel.new
|
||||
opponent = NPCTrainer.new(
|
||||
pbGetMessageFromHash(MessageTypes::TrainerNames,trainer_name), trainer_id)
|
||||
speech_texts = []
|
||||
for i in 0...12
|
||||
speech_texts.push(_I(speeches[i]))
|
||||
end
|
||||
duel.pbDuel(opponent, event, speech_texts)
|
||||
end
|
||||
1302
Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb
Normal file
1302
Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb
Normal file
File diff suppressed because it is too large
Load Diff
404
Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb
Normal file
404
Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb
Normal file
@@ -0,0 +1,404 @@
|
||||
################################################################################
|
||||
# "Slot Machine" mini-game
|
||||
# By Maruno
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run with: pbSlotMachine(1)
|
||||
# - The number is either 0 (easy), 1 (default) or 2 (hard).
|
||||
################################################################################
|
||||
class SlotMachineReel < BitmapSprite
|
||||
attr_accessor :reel
|
||||
attr_accessor :toppos
|
||||
attr_accessor :spinning
|
||||
attr_accessor :stopping
|
||||
attr_accessor :slipping
|
||||
SCROLLSPEED = 16 # Must be a divisor of 48
|
||||
ICONSPOOL = [[0,0,0,0,1,1,2,2,3,3,3,4,4,4,5,5,6,6,7], # 0 - Easy
|
||||
[0,0,0,0,1,1,1,2,2,2,3,3,4,4,5,6,7], # 1 - Medium (default)
|
||||
[0,0,1,1,1,2,2,2,3,3,4,4,5,6,7] # 2 - Hard
|
||||
]
|
||||
SLIPPING = [0,0,0,0,0,0,1,1,1,2,2,3]
|
||||
|
||||
def initialize(x,y,difficulty=1)
|
||||
@viewport=Viewport.new(x,y,64,144)
|
||||
@viewport.z=99999
|
||||
super(64,144,@viewport)
|
||||
@reel=[]
|
||||
for i in 0...ICONSPOOL[difficulty].length
|
||||
@reel.push(ICONSPOOL[difficulty][i])
|
||||
end
|
||||
@reel.shuffle!
|
||||
@toppos=0
|
||||
@spinning=false
|
||||
@stopping=false
|
||||
@slipping=0
|
||||
@index=rand(@reel.length)
|
||||
@images=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/images"))
|
||||
@shading=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/ReelOverlay"))
|
||||
update
|
||||
end
|
||||
|
||||
def startSpinning
|
||||
@spinning=true
|
||||
end
|
||||
|
||||
def stopSpinning(noslipping=false)
|
||||
@stopping=true
|
||||
@slipping=SLIPPING[rand(SLIPPING.length)]
|
||||
@slipping=0 if noslipping
|
||||
end
|
||||
|
||||
def showing
|
||||
array=[]
|
||||
for i in 0...3
|
||||
num=@index-i
|
||||
num+=@reel.length if num<0
|
||||
array.push(@reel[num])
|
||||
end
|
||||
return array # [0] = top, [1] = middle, [2] = bottom
|
||||
end
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
if @toppos==0 && @stopping && @slipping==0
|
||||
@spinning=@stopping=false
|
||||
end
|
||||
if @spinning
|
||||
@toppos+=SCROLLSPEED
|
||||
if @toppos>0
|
||||
@toppos-=48
|
||||
@index=(@index+1)%@reel.length
|
||||
@slipping-=1 if @slipping>0
|
||||
end
|
||||
end
|
||||
for i in 0...4
|
||||
num=@index-i
|
||||
num+=@reel.length if num<0
|
||||
self.bitmap.blt(0,@toppos+i*48,@images.bitmap,Rect.new(@reel[num]*64,0,64,48))
|
||||
end
|
||||
self.bitmap.blt(0,0,@shading.bitmap,Rect.new(0,0,64,144))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class SlotMachineScore < BitmapSprite
|
||||
attr_reader :score
|
||||
|
||||
def initialize(x,y,score=0)
|
||||
@viewport=Viewport.new(x,y,70,22)
|
||||
@viewport.z=99999
|
||||
super(70,22,@viewport)
|
||||
@numbers=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/numbers"))
|
||||
self.score=score
|
||||
end
|
||||
|
||||
def score=(value)
|
||||
@score = value
|
||||
@score = Settings::MAX_COINS if @score > Settings::MAX_COINS
|
||||
refresh
|
||||
end
|
||||
|
||||
def refresh
|
||||
self.bitmap.clear
|
||||
for i in 0...5
|
||||
digit=(@score/(10**i))%10 # Least significant digit first
|
||||
self.bitmap.blt(14*(4-i),0,@numbers.bitmap,Rect.new(digit*14,0,14,22))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class SlotMachineScene
|
||||
attr_accessor :gameRunning
|
||||
attr_accessor :gameEnd
|
||||
attr_accessor :wager
|
||||
attr_accessor :replay
|
||||
|
||||
def update
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
end
|
||||
|
||||
def pbPayout
|
||||
@replay=false
|
||||
payout=0
|
||||
bonus=0
|
||||
wonRow=[]
|
||||
# Get reel pictures
|
||||
reel1=@sprites["reel1"].showing
|
||||
reel2=@sprites["reel2"].showing
|
||||
reel3=@sprites["reel3"].showing
|
||||
combinations=[[reel1[1],reel2[1],reel3[1]], # Centre row
|
||||
[reel1[0],reel2[0],reel3[0]], # Top row
|
||||
[reel1[2],reel2[2],reel3[2]], # Bottom row
|
||||
[reel1[0],reel2[1],reel3[2]], # Diagonal top left -> bottom right
|
||||
[reel1[2],reel2[1],reel3[0]], # Diagonal bottom left -> top right
|
||||
]
|
||||
for i in 0...combinations.length
|
||||
break if i>=1 && @wager<=1 # One coin = centre row only
|
||||
break if i>=3 && @wager<=2 # Two coins = three rows only
|
||||
wonRow[i]=true
|
||||
case combinations[i]
|
||||
when [1,1,1] # Three Magnemites
|
||||
payout += 8
|
||||
when [2,2,2] # Three Shellders
|
||||
payout += 8
|
||||
when [3,3,3] # Three Pikachus
|
||||
payout += 15
|
||||
when [4,4,4] # Three Psyducks
|
||||
payout += 15
|
||||
when [5,5,6], [5,6,5], [6,5,5], [6,6,5], [6,5,6], [5,6,6] # 777 multi-colored
|
||||
payout += 90
|
||||
bonus = 1 if bonus<1
|
||||
when [5,5,5], [6,6,6] # Red 777, blue 777
|
||||
payout += 300
|
||||
bonus = 2 if bonus<2
|
||||
when [7,7,7] # Three replays
|
||||
@replay = true
|
||||
else
|
||||
if combinations[i][0]==0 # Left cherry
|
||||
if combinations[i][1]==0 # Centre cherry as well
|
||||
payout+=4
|
||||
else
|
||||
payout+=2
|
||||
end
|
||||
else
|
||||
wonRow[i]=false
|
||||
end
|
||||
end
|
||||
end
|
||||
@sprites["payout"].score=payout
|
||||
frame=0
|
||||
if payout>0 || @replay
|
||||
if bonus>0
|
||||
pbMEPlay("Slots big win")
|
||||
else
|
||||
pbMEPlay("Slots win")
|
||||
end
|
||||
# Show winning animation
|
||||
timePerFrame = Graphics.frame_rate/8
|
||||
until frame==Graphics.frame_rate*3
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
@sprites["window2"].bitmap.clear if @sprites["window2"].bitmap
|
||||
@sprites["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/win"))
|
||||
@sprites["window1"].src_rect.set(152*((frame/timePerFrame)%4),0,152,208)
|
||||
if bonus>0
|
||||
@sprites["window2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/bonus"))
|
||||
@sprites["window2"].src_rect.set(152*(bonus-1),0,152,208)
|
||||
end
|
||||
@sprites["light1"].visible=true
|
||||
@sprites["light1"].src_rect.set(0,26*((frame/timePerFrame)%4),96,26)
|
||||
@sprites["light2"].visible=true
|
||||
@sprites["light2"].src_rect.set(0,26*((frame/timePerFrame)%4),96,26)
|
||||
for i in 1..5
|
||||
if wonRow[i-1]
|
||||
@sprites["row#{i}"].visible = ((frame/timePerFrame)%2)==0
|
||||
else
|
||||
@sprites["row#{i}"].visible = false
|
||||
end
|
||||
end
|
||||
frame += 1
|
||||
end
|
||||
@sprites["light1"].visible=false
|
||||
@sprites["light2"].visible=false
|
||||
@sprites["window1"].src_rect.set(0,0,152,208)
|
||||
# Pay out
|
||||
loop do
|
||||
break if @sprites["payout"].score<=0
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
@sprites["payout"].score -= 1
|
||||
@sprites["credit"].score += 1
|
||||
if Input.trigger?(Input::USE) || @sprites["credit"].score == Settings::MAX_COINS
|
||||
@sprites["credit"].score += @sprites["payout"].score
|
||||
@sprites["payout"].score = 0
|
||||
end
|
||||
end
|
||||
(Graphics.frame_rate/2).times do
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
end
|
||||
else
|
||||
# Show losing animation
|
||||
timePerFrame = Graphics.frame_rate/4
|
||||
until frame==Graphics.frame_rate*2
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
@sprites["window2"].bitmap.clear if @sprites["window2"].bitmap
|
||||
@sprites["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lose"))
|
||||
@sprites["window1"].src_rect.set(152*((frame/timePerFrame)%2),0,152,208)
|
||||
frame += 1
|
||||
end
|
||||
end
|
||||
@wager = 0
|
||||
end
|
||||
|
||||
def pbStartScene(difficulty)
|
||||
@sprites={}
|
||||
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z=99999
|
||||
addBackgroundPlane(@sprites,"bg","Slot Machine/bg",@viewport)
|
||||
@sprites["reel1"]=SlotMachineReel.new(64,112,difficulty)
|
||||
@sprites["reel2"]=SlotMachineReel.new(144,112,difficulty)
|
||||
@sprites["reel3"]=SlotMachineReel.new(224,112,difficulty)
|
||||
for i in 1..3
|
||||
@sprites["button#{i}"]=IconSprite.new(68+80*(i-1),260,@viewport)
|
||||
@sprites["button#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/button"))
|
||||
@sprites["button#{i}"].visible=false
|
||||
end
|
||||
for i in 1..5
|
||||
y=[170,122,218,82,82][i-1]
|
||||
@sprites["row#{i}"]=IconSprite.new(2,y,@viewport)
|
||||
@sprites["row#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/line%1d%s",
|
||||
1+i/2,(i>=4) ? ((i==4) ? "a" : "b") : ""))
|
||||
@sprites["row#{i}"].visible=false
|
||||
end
|
||||
@sprites["light1"]=IconSprite.new(16,32,@viewport)
|
||||
@sprites["light1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lights"))
|
||||
@sprites["light1"].visible=false
|
||||
@sprites["light2"]=IconSprite.new(240,32,@viewport)
|
||||
@sprites["light2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lights"))
|
||||
@sprites["light2"].mirror=true
|
||||
@sprites["light2"].visible=false
|
||||
@sprites["window1"]=IconSprite.new(358,96,@viewport)
|
||||
@sprites["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/insert"))
|
||||
@sprites["window1"].src_rect.set(0,0,152,208)
|
||||
@sprites["window2"]=IconSprite.new(358,96,@viewport)
|
||||
@sprites["credit"]=SlotMachineScore.new(360,66,$Trainer.coins)
|
||||
@sprites["payout"]=SlotMachineScore.new(438,66,0)
|
||||
@wager=0
|
||||
update
|
||||
pbFadeInAndShow(@sprites)
|
||||
end
|
||||
|
||||
def pbMain
|
||||
frame=0
|
||||
spinFrameTime = Graphics.frame_rate/4
|
||||
insertFrameTime = Graphics.frame_rate*4/10
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
@sprites["window1"].bitmap.clear if @sprites["window1"].bitmap
|
||||
@sprites["window2"].bitmap.clear if @sprites["window2"].bitmap
|
||||
if @sprites["credit"].score == Settings::MAX_COINS
|
||||
pbMessage(_INTL("You've got {1} Coins.", Settings::MAX_COINS.to_s_formatted))
|
||||
break
|
||||
elsif $Trainer.coins==0
|
||||
pbMessage(_INTL("You've run out of Coins.\nGame over!"))
|
||||
break
|
||||
elsif @gameRunning # Reels are spinning
|
||||
@sprites["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/stop"))
|
||||
@sprites["window1"].src_rect.set(152*((frame/spinFrameTime)%4),0,152,208)
|
||||
if Input.trigger?(Input::USE)
|
||||
pbSEPlay("Slots stop")
|
||||
if @sprites["reel1"].spinning
|
||||
@sprites["reel1"].stopSpinning(@replay)
|
||||
@sprites["button1"].visible=true
|
||||
elsif @sprites["reel2"].spinning
|
||||
@sprites["reel2"].stopSpinning(@replay)
|
||||
@sprites["button2"].visible=true
|
||||
elsif @sprites["reel3"].spinning
|
||||
@sprites["reel3"].stopSpinning(@replay)
|
||||
@sprites["button3"].visible=true
|
||||
end
|
||||
end
|
||||
if !@sprites["reel3"].spinning
|
||||
@gameEnd=true
|
||||
@gameRunning=false
|
||||
end
|
||||
elsif @gameEnd # Reels have been stopped
|
||||
pbPayout
|
||||
# Reset graphics
|
||||
@sprites["button1"].visible=false
|
||||
@sprites["button2"].visible=false
|
||||
@sprites["button3"].visible=false
|
||||
for i in 1..5
|
||||
@sprites["row#{i}"].visible=false
|
||||
end
|
||||
@gameEnd=false
|
||||
else # Awaiting coins for the next spin
|
||||
@sprites["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/insert"))
|
||||
@sprites["window1"].src_rect.set(152*((frame/insertFrameTime)%2),0,152,208)
|
||||
if @wager>0
|
||||
@sprites["window2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/press"))
|
||||
@sprites["window2"].src_rect.set(152*((frame/insertFrameTime)%2),0,152,208)
|
||||
end
|
||||
if Input.trigger?(Input::DOWN) && @wager<3 && @sprites["credit"].score>0
|
||||
pbSEPlay("Slots coin")
|
||||
@wager+=1
|
||||
@sprites["credit"].score-=1
|
||||
if @wager>=3
|
||||
@sprites["row5"].visible=true
|
||||
@sprites["row4"].visible=true
|
||||
elsif @wager>=2
|
||||
@sprites["row3"].visible=true
|
||||
@sprites["row2"].visible=true
|
||||
elsif @wager>=1
|
||||
@sprites["row1"].visible=true
|
||||
end
|
||||
elsif @wager>=3 || (@wager>0 && @sprites["credit"].score==0) ||
|
||||
(Input.trigger?(Input::USE) && @wager>0) || @replay
|
||||
if @replay
|
||||
@wager=3
|
||||
for i in 1..5
|
||||
@sprites["row#{i}"].visible=true
|
||||
end
|
||||
end
|
||||
@sprites["reel1"].startSpinning
|
||||
@sprites["reel2"].startSpinning
|
||||
@sprites["reel3"].startSpinning
|
||||
frame=0
|
||||
@gameRunning=true
|
||||
elsif Input.trigger?(Input::BACK) && @wager==0
|
||||
break
|
||||
end
|
||||
end
|
||||
frame = (frame+1)%(Graphics.frame_rate*4)
|
||||
end
|
||||
$Trainer.coins = @sprites["credit"].score
|
||||
end
|
||||
|
||||
def pbEndScene
|
||||
pbFadeOutAndHide(@sprites)
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@viewport.dispose
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class SlotMachine
|
||||
def initialize(scene)
|
||||
@scene=scene
|
||||
end
|
||||
|
||||
def pbStartScreen(difficulty)
|
||||
@scene.pbStartScene(difficulty)
|
||||
@scene.pbMain
|
||||
@scene.pbEndScene
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbSlotMachine(difficulty=1)
|
||||
if GameData::Item.exists?(:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE)
|
||||
pbMessage(_INTL("It's a Slot Machine."))
|
||||
elsif $Trainer.coins == 0
|
||||
pbMessage(_INTL("You don't have any Coins to play!"))
|
||||
elsif $Trainer.coins == Settings::MAX_COINS
|
||||
pbMessage(_INTL("Your Coin Case is full!"))
|
||||
else
|
||||
pbFadeOutIn {
|
||||
scene = SlotMachineScene.new
|
||||
screen = SlotMachine.new(scene)
|
||||
screen.pbStartScreen(difficulty)
|
||||
}
|
||||
end
|
||||
end
|
||||
626
Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb
Normal file
626
Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb
Normal file
@@ -0,0 +1,626 @@
|
||||
################################################################################
|
||||
# "Voltorb Flip" mini-game
|
||||
# By KitsuneKouta
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run with: pbVoltorbFlip
|
||||
################################################################################
|
||||
class VoltorbFlip
|
||||
def update
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
end
|
||||
|
||||
def pbStart
|
||||
# Set initial level
|
||||
@level=1
|
||||
# Maximum and minimum total point values for each level
|
||||
@levelRanges=[[ 20, 50],[ 50, 100],[ 100, 200],[ 200, 350],
|
||||
[350,600],[600,1000],[1000,2000],[2000,3500]]
|
||||
@firstRound=true
|
||||
pbNewGame
|
||||
end
|
||||
|
||||
def pbNewGame
|
||||
# Initialize variables
|
||||
@sprites={}
|
||||
@cursor=[]
|
||||
@marks=[]
|
||||
@coins=[]
|
||||
@numbers=[]
|
||||
@voltorbNumbers=[]
|
||||
@points=0
|
||||
@index=[0,0]
|
||||
# [x,y,points,selected]
|
||||
@squares=[0,0,0,false]
|
||||
@directory="Graphics/Pictures/Voltorb Flip/"
|
||||
squareValues=[]
|
||||
total=1
|
||||
voltorbs=0
|
||||
for i in 0...25
|
||||
# Sets the value to 1 by default
|
||||
squareValues[i]=1
|
||||
# Sets the value to 0 (a voltorb) if # for that level hasn't been reached
|
||||
if voltorbs < 5+@level
|
||||
squareValues[i]=0
|
||||
voltorbs+=1
|
||||
# Sets the value randomly to a 2 or 3 if the total is less than the max
|
||||
elsif total<@levelRanges[@level-1][1]
|
||||
squareValues[i]=rand(2)+2
|
||||
total*=squareValues[i]
|
||||
end
|
||||
if total>(@levelRanges[@level-1][1])
|
||||
# Lowers value of square to 1 if over max
|
||||
total/=squareValues[i]
|
||||
squareValues[i]=1
|
||||
end
|
||||
end
|
||||
# Randomize the values a little
|
||||
for i in 0...25
|
||||
temp=squareValues[i]
|
||||
if squareValues[i]>1
|
||||
if rand(10)>8
|
||||
total/=squareValues[i]
|
||||
squareValues[i]-=1
|
||||
total*=squareValues[i]
|
||||
end
|
||||
end
|
||||
if total<@levelRanges[@level-1][0]
|
||||
if squareValues[i]>0
|
||||
total/=squareValues[i]
|
||||
squareValues[i]=temp
|
||||
total*=squareValues[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
# Populate @squares array
|
||||
for i in 0...25
|
||||
x=i if i%5==0
|
||||
r=rand(squareValues.length)
|
||||
@squares[i]=[(i-x).abs*64+128,(i/5).abs*64,squareValues[r],false]
|
||||
squareValues.delete_at(r)
|
||||
end
|
||||
pbCreateSprites
|
||||
# Display numbers (all zeroes, as no values have been calculated yet)
|
||||
for i in 0...5
|
||||
pbUpdateRowNumbers(0,0,i)
|
||||
pbUpdateColumnNumbers(0,0,i)
|
||||
end
|
||||
pbDrawShadowText(@sprites["text"].bitmap,8,16,118,26,
|
||||
_INTL("Your coins"),Color.new(60,60,60),Color.new(150,190,170),1)
|
||||
pbDrawShadowText(@sprites["text"].bitmap,8,82,118,26,
|
||||
_INTL("Earned coins"),Color.new(60,60,60),Color.new(150,190,170),1)
|
||||
# Draw current level
|
||||
pbDrawShadowText(@sprites["level"].bitmap,8,150,118,28,
|
||||
_INTL("Level {1}",@level.to_s),Color.new(60,60,60),Color.new(150,190,170),1)
|
||||
# Displays total and current coins
|
||||
pbUpdateCoins
|
||||
# Draw curtain effect
|
||||
if @firstRound
|
||||
angleDiff = 10*20/Graphics.frame_rate
|
||||
loop do
|
||||
@sprites["curtainL"].angle -= angleDiff
|
||||
@sprites["curtainR"].angle += angleDiff
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
break if @sprites["curtainL"].angle<=-180
|
||||
end
|
||||
end
|
||||
@sprites["curtainL"].visible=false
|
||||
@sprites["curtainR"].visible=false
|
||||
@sprites["curtain"].opacity=100
|
||||
if $Trainer.coins >= Settings::MAX_COINS
|
||||
pbMessage(_INTL("You've gathered {1} Coins. You cannot gather any more.", Settings::MAX_COINS.to_s_formatted))
|
||||
$Trainer.coins = Settings::MAX_COINS # As a precaution
|
||||
@quit=true
|
||||
# elsif !pbConfirmMessage(_INTL("Play Voltorb Flip Lv. {1}?",@level)) && $Trainer.coins<Settings::MAX_COINS
|
||||
# @quit=true
|
||||
else
|
||||
@sprites["curtain"].opacity=0
|
||||
# Erase 0s to prepare to replace with values
|
||||
@sprites["numbers"].bitmap.clear
|
||||
# Reset arrays to empty
|
||||
@voltorbNumbers=[]
|
||||
@numbers=[]
|
||||
# Draw numbers for each row (precautionary)
|
||||
for i in 0...@squares.length
|
||||
if i%5==0
|
||||
num=0
|
||||
voltorbs=0
|
||||
j=i+5
|
||||
for k in i...j
|
||||
num+=@squares[k][2]
|
||||
if @squares[k][2]==0
|
||||
voltorbs+=1
|
||||
end
|
||||
end
|
||||
end
|
||||
pbUpdateRowNumbers(num,voltorbs,(i/5).abs)
|
||||
end
|
||||
# Reset arrays to empty
|
||||
@voltorbNumbers=[]
|
||||
@numbers=[]
|
||||
# Draw numbers for each column
|
||||
for i in 0...5
|
||||
num=0
|
||||
voltorbs=0
|
||||
for j in 0...5
|
||||
num+=@squares[i+(j*5)][2]
|
||||
if @squares[i+(j*5)][2]==0
|
||||
voltorbs+=1
|
||||
end
|
||||
end
|
||||
pbUpdateColumnNumbers(num,voltorbs,i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbCreateSprites
|
||||
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z=99999
|
||||
@sprites["bg"]=Sprite.new(@viewport)
|
||||
@sprites["bg"].bitmap=RPG::Cache.load_bitmap(@directory,"boardbg")
|
||||
@sprites["text"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
pbSetSystemFont(@sprites["text"].bitmap)
|
||||
@sprites["text"].bitmap.font.size=26
|
||||
@sprites["level"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
pbSetSystemFont(@sprites["level"].bitmap)
|
||||
@sprites["level"].bitmap.font.size=28
|
||||
@sprites["curtain"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["curtain"].z=99999
|
||||
@sprites["curtain"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
|
||||
@sprites["curtain"].opacity=0
|
||||
@sprites["curtainL"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["curtainL"].z=99999
|
||||
@sprites["curtainL"].x=Graphics.width/2
|
||||
@sprites["curtainL"].angle=-90
|
||||
@sprites["curtainL"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
|
||||
@sprites["curtainR"]=BitmapSprite.new(Graphics.width,Graphics.height*2,@viewport)
|
||||
@sprites["curtainR"].z=99999
|
||||
@sprites["curtainR"].x=Graphics.width/2
|
||||
@sprites["curtainR"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height*2,Color.new(0,0,0))
|
||||
@sprites["cursor"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["cursor"].z=99998
|
||||
@sprites["icon"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["icon"].z=99997
|
||||
@sprites["mark"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["memo"]=Sprite.new(@viewport)
|
||||
@sprites["memo"].bitmap=RPG::Cache.load_bitmap(@directory,"memo")
|
||||
@sprites["memo"].x=10
|
||||
@sprites["memo"].y=244
|
||||
@sprites["memo"].visible=false
|
||||
@sprites["numbers"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["totalCoins"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["currentCoins"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["animation"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites["animation"].z=99999
|
||||
for i in 0...6
|
||||
@sprites[i]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@sprites[i].z=99996
|
||||
@sprites[i].visible=false
|
||||
end
|
||||
# Creates images ahead of time for the display-all animation (reduces lag)
|
||||
icons=[]
|
||||
points=0
|
||||
for i in 0...3
|
||||
for j in 0...25
|
||||
points=@squares[j][2] if i==2
|
||||
icons[j]=[@directory+"tiles",@squares[j][0],@squares[j][1],320+(i*64)+(points*64),0,64,64]
|
||||
end
|
||||
icons.compact!
|
||||
pbDrawImagePositions(@sprites[i].bitmap,icons)
|
||||
end
|
||||
icons=[]
|
||||
for i in 0...25
|
||||
icons[i]=[@directory+"tiles",@squares[i][0],@squares[i][1],@squares[i][2]*64,0,64,64]
|
||||
end
|
||||
pbDrawImagePositions(@sprites[5].bitmap,icons)
|
||||
# Default cursor image
|
||||
@cursor[0]=[@directory+"cursor",0+128,0,0,0,64,64]
|
||||
end
|
||||
|
||||
def getInput
|
||||
if Input.trigger?(Input::UP)
|
||||
pbPlayCursorSE
|
||||
if @index[1]>0
|
||||
@index[1]-=1
|
||||
@sprites["cursor"].y-=64
|
||||
else
|
||||
@index[1]=4
|
||||
@sprites["cursor"].y=256
|
||||
end
|
||||
elsif Input.trigger?(Input::DOWN)
|
||||
pbPlayCursorSE
|
||||
if @index[1]<4
|
||||
@index[1]+=1
|
||||
@sprites["cursor"].y+=64
|
||||
else
|
||||
@index[1]=0
|
||||
@sprites["cursor"].y=0
|
||||
end
|
||||
elsif Input.trigger?(Input::LEFT)
|
||||
pbPlayCursorSE
|
||||
if @index[0]>0
|
||||
@index[0]-=1
|
||||
@sprites["cursor"].x-=64
|
||||
else
|
||||
@index[0]=4
|
||||
@sprites["cursor"].x=256
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT)
|
||||
pbPlayCursorSE
|
||||
if @index[0]<4
|
||||
@index[0]+=1
|
||||
@sprites["cursor"].x+=64
|
||||
else
|
||||
@index[0]=0
|
||||
@sprites["cursor"].x=0
|
||||
end
|
||||
elsif Input.trigger?(Input::USE)
|
||||
if @cursor[0][3]==64 # If in mark mode
|
||||
for i in 0...@squares.length
|
||||
if @index[0]*64+128==@squares[i][0] && @index[1]*64==@squares[i][1] && @squares[i][3]==false
|
||||
pbSEPlay("Voltorb Flip mark")
|
||||
end
|
||||
end
|
||||
for i in 0...@marks.length+1
|
||||
if @marks[i]==nil
|
||||
@marks[i]=[@directory+"tiles",@index[0]*64+128,@index[1]*64,256,0,64,64]
|
||||
elsif @marks[i][1]==@index[0]*64+128 && @marks[i][2]==@index[1]*64
|
||||
@marks.delete_at(i)
|
||||
@marks.compact!
|
||||
@sprites["mark"].bitmap.clear
|
||||
break
|
||||
end
|
||||
end
|
||||
pbDrawImagePositions(@sprites["mark"].bitmap,@marks)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
else
|
||||
# Display the tile for the selected spot
|
||||
icons=[]
|
||||
for i in 0...@squares.length
|
||||
if @index[0]*64+128==@squares[i][0] && @index[1]*64==@squares[i][1] && @squares[i][3]==false
|
||||
pbAnimateTile(@index[0]*64+128,@index[1]*64,@squares[i][2])
|
||||
@squares[i][3]=true
|
||||
# If Voltorb (0), display all tiles on the board
|
||||
if @squares[i][2]==0
|
||||
pbSEPlay("Voltorb Flip explosion")
|
||||
# Play explosion animation
|
||||
# Part1
|
||||
animation=[]
|
||||
for j in 0...3
|
||||
animation[0]=icons[0]=[@directory+"tiles",@index[0]*64+128,@index[1]*64,704+(64*j),0,64,64]
|
||||
pbDrawImagePositions(@sprites["animation"].bitmap,animation)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
@sprites["animation"].bitmap.clear
|
||||
end
|
||||
# Part2
|
||||
animation=[]
|
||||
for j in 0...6
|
||||
animation[0]=[@directory+"explosion",@index[0]*64-32+128,@index[1]*64-32,j*128,0,128,128]
|
||||
pbDrawImagePositions(@sprites["animation"].bitmap,animation)
|
||||
pbWait(Graphics.frame_rate/10)
|
||||
@sprites["animation"].bitmap.clear
|
||||
end
|
||||
# Unskippable text block, parameter 2 = wait time (corresponds to ME length)
|
||||
pbMessage(_INTL("\\me[Voltorb Flip game over]Oh no! You get 0 Coins!\\wtnp[50]"))
|
||||
pbShowAndDispose
|
||||
@sprites["mark"].bitmap.clear
|
||||
if @level>1
|
||||
# Determine how many levels to reduce by
|
||||
newLevel=0
|
||||
for j in 0...@squares.length
|
||||
newLevel+=1 if @squares[j][3]==true && @squares[j][2]>1
|
||||
end
|
||||
newLevel=@level if newLevel>@level
|
||||
if @level>newLevel
|
||||
@level=newLevel
|
||||
@level=1 if @level<1
|
||||
pbMessage(_INTL("\\se[Voltorb Flip level down]Dropped to Game Lv. {1}!",@level.to_s))
|
||||
end
|
||||
end
|
||||
# Update level text
|
||||
@sprites["level"].bitmap.clear
|
||||
pbDrawShadowText(@sprites["level"].bitmap,8,150,118,28,"Level "+@level.to_s,Color.new(60,60,60),Color.new(150,190,170),1)
|
||||
@points=0
|
||||
pbUpdateCoins
|
||||
# Revert numbers to 0s
|
||||
@sprites["numbers"].bitmap.clear
|
||||
for i in 0...5
|
||||
pbUpdateRowNumbers(0,0,i)
|
||||
pbUpdateColumnNumbers(0,0,i)
|
||||
end
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@firstRound=false
|
||||
pbNewGame
|
||||
else
|
||||
# Play tile animation
|
||||
animation=[]
|
||||
for j in 0...4
|
||||
animation[0]=[@directory+"flipAnimation",@index[0]*64-14+128,@index[1]*64-16,j*92,0,92,96]
|
||||
pbDrawImagePositions(@sprites["animation"].bitmap,animation)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
@sprites["animation"].bitmap.clear
|
||||
end
|
||||
if @points==0
|
||||
@points+=@squares[i][2]
|
||||
pbSEPlay("Voltorb Flip point")
|
||||
elsif @squares[i][2]>1
|
||||
@points*=@squares[i][2]
|
||||
pbSEPlay("Voltorb Flip point")
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
count=0
|
||||
for i in 0...@squares.length
|
||||
if @squares[i][3]==false && @squares[i][2]>1
|
||||
count+=1
|
||||
end
|
||||
end
|
||||
pbUpdateCoins
|
||||
# Game cleared
|
||||
if count==0
|
||||
@sprites["curtain"].opacity=100
|
||||
pbMessage(_INTL("\\me[Voltorb Flip win]Game clear!\\wtnp[40]"))
|
||||
# pbMessage(_INTL("You've found all of the hidden x2 and x3 cards."))
|
||||
# pbMessage(_INTL("This means you've found all the Coins in this game, so the game is now over."))
|
||||
pbMessage(_INTL("\\se[Voltorb Flip gain coins]{1} received {2} Coins!",$Trainer.name,@points.to_s_formatted))
|
||||
# Update level text
|
||||
@sprites["level"].bitmap.clear
|
||||
pbDrawShadowText(@sprites["level"].bitmap,8,150,118,28,_INTL("Level {1}",@level.to_s),Color.new(60,60,60),Color.new(150,190,170),1)
|
||||
$Trainer.coins+=@points
|
||||
@points=0
|
||||
pbUpdateCoins
|
||||
@sprites["curtain"].opacity=0
|
||||
pbShowAndDispose
|
||||
# Revert numbers to 0s
|
||||
@sprites["numbers"].bitmap.clear
|
||||
for i in 0...5
|
||||
pbUpdateRowNumbers(0,0,i)
|
||||
pbUpdateColumnNumbers(0,0,i)
|
||||
end
|
||||
@sprites["curtain"].opacity=100
|
||||
if @level<8
|
||||
@level+=1
|
||||
pbMessage(_INTL("\\se[Voltorb Flip level up]Advanced to Game Lv. {1}!",@level.to_s))
|
||||
# if @firstRound
|
||||
# pbMessage(_INTL("Congratulations!"))
|
||||
# pbMessage(_INTL("You can receive even more Coins in the next game!"))
|
||||
@firstRound=false
|
||||
# end
|
||||
end
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
pbNewGame
|
||||
end
|
||||
elsif Input.trigger?(Input::ACTION)
|
||||
pbPlayDecisionSE
|
||||
@sprites["cursor"].bitmap.clear
|
||||
if @cursor[0][3]==0 # If in normal mode
|
||||
@cursor[0]=[@directory+"cursor",128,0,64,0,64,64]
|
||||
@sprites["memo"].visible=true
|
||||
else # Mark mode
|
||||
@cursor[0]=[@directory+"cursor",128,0,0,0,64,64]
|
||||
@sprites["memo"].visible=false
|
||||
end
|
||||
elsif Input.trigger?(Input::BACK)
|
||||
@sprites["curtain"].opacity=100
|
||||
if @points==0
|
||||
if pbConfirmMessage("You haven't found any Coins! Are you sure you want to quit?")
|
||||
@sprites["curtain"].opacity=0
|
||||
pbShowAndDispose
|
||||
@quit=true
|
||||
end
|
||||
elsif pbConfirmMessage(_INTL("If you quit now, you will recieve {1} Coin(s). Will you quit?",@points.to_s_formatted))
|
||||
pbMessage(_INTL("{1} received {2} Coin(s)!",$Trainer.name,@points.to_s_formatted))
|
||||
$Trainer.coins+=@points
|
||||
@points=0
|
||||
pbUpdateCoins
|
||||
@sprites["curtain"].opacity=0
|
||||
pbShowAndDispose
|
||||
@quit=true
|
||||
end
|
||||
@sprites["curtain"].opacity=0
|
||||
end
|
||||
# Draw cursor
|
||||
pbDrawImagePositions(@sprites["cursor"].bitmap,@cursor)
|
||||
end
|
||||
|
||||
def pbUpdateRowNumbers(num,voltorbs,i)
|
||||
# Create and split a string for the number, with padded 0s
|
||||
zeroes=2-num.to_s.length
|
||||
numText=""
|
||||
zeroes.times do
|
||||
numText+="0"
|
||||
end
|
||||
numText+=num.to_s
|
||||
numImages=numText.split(//)[0...2]
|
||||
for j in 0...2
|
||||
@numbers[j]=[@directory+"numbersSmall",472+j*16,i*64+8,numImages[j].to_i*16,0,16,16]
|
||||
end
|
||||
@voltorbNumbers[i]=[@directory+"numbersSmall",488,i*64+34,voltorbs*16,0,16,16]
|
||||
# Display the numbers
|
||||
pbDrawImagePositions(@sprites["numbers"].bitmap,@numbers)
|
||||
pbDrawImagePositions(@sprites["numbers"].bitmap,@voltorbNumbers)
|
||||
end
|
||||
|
||||
def pbUpdateColumnNumbers(num,voltorbs,i)
|
||||
# Create and split a string for the number, with padded 0s
|
||||
zeroes=2-num.to_s.length
|
||||
numText=""
|
||||
zeroes.times do
|
||||
numText+="0"
|
||||
end
|
||||
numText+=num.to_s
|
||||
numImages=numText.split(//)[0...2]
|
||||
for j in 0...2
|
||||
@numbers[j]=[@directory+"numbersSmall",(i*64)+152+j*16,328,numImages[j].to_i*16,0,16,16]
|
||||
end
|
||||
@voltorbNumbers[i]=[@directory+"numbersSmall",(i*64)+168,354,voltorbs*16,0,16,16]
|
||||
# Display the numbers
|
||||
pbDrawImagePositions(@sprites["numbers"].bitmap,@numbers)
|
||||
pbDrawImagePositions(@sprites["numbers"].bitmap,@voltorbNumbers)
|
||||
end
|
||||
|
||||
def pbCreateCoins(source,y)
|
||||
zeroes=5-source.to_s.length
|
||||
coinText=""
|
||||
zeroes.times do
|
||||
coinText+="0"
|
||||
end
|
||||
coinText+=source.to_s
|
||||
coinImages=coinText.split(//)[0...5]
|
||||
for i in 0...5
|
||||
@coins[i]=[@directory+"numbersScore",6+i*24,y,coinImages[i].to_i*24,0,24,38]
|
||||
end
|
||||
end
|
||||
|
||||
def pbUpdateCoins
|
||||
# Update coins display
|
||||
@sprites["totalCoins"].bitmap.clear
|
||||
pbCreateCoins($Trainer.coins,44)
|
||||
pbDrawImagePositions(@sprites["totalCoins"].bitmap,@coins)
|
||||
# Update points display
|
||||
@sprites["currentCoins"].bitmap.clear
|
||||
pbCreateCoins(@points,110)
|
||||
pbDrawImagePositions(@sprites["currentCoins"].bitmap,@coins)
|
||||
end
|
||||
|
||||
def pbAnimateTile(x,y,tile)
|
||||
icons=[]
|
||||
points=0
|
||||
for i in 0...3
|
||||
points=tile if i==2
|
||||
icons[i]=[@directory+"tiles",x,y,320+(i*64)+(points*64),0,64,64]
|
||||
pbDrawImagePositions(@sprites["icon"].bitmap,icons)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
end
|
||||
icons[3]=[@directory+"tiles",x,y,tile*64,0,64,64]
|
||||
pbDrawImagePositions(@sprites["icon"].bitmap,icons)
|
||||
pbSEPlay("Voltorb Flip tile")
|
||||
end
|
||||
|
||||
def pbShowAndDispose
|
||||
# Make pre-rendered sprites visible (this approach reduces lag)
|
||||
for i in 0...5
|
||||
@sprites[i].visible=true
|
||||
pbWait(Graphics.frame_rate/20) if i<3
|
||||
@sprites[i].bitmap.clear
|
||||
@sprites[i].z=99997
|
||||
end
|
||||
pbSEPlay("Voltorb Flip tile")
|
||||
@sprites[5].visible=true
|
||||
@sprites["mark"].bitmap.clear
|
||||
pbWait(Graphics.frame_rate/10)
|
||||
# Wait for user input to continue
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
end
|
||||
# "Dispose" of tiles by column
|
||||
for i in 0...5
|
||||
icons=[]
|
||||
pbSEPlay("Voltorb Flip tile")
|
||||
for j in 0...5
|
||||
icons[j]=[@directory+"tiles",@squares[i+(j*5)][0],@squares[i+(j*5)][1],448+(@squares[i+(j*5)][2]*64),0,64,64]
|
||||
end
|
||||
pbDrawImagePositions(@sprites[i].bitmap,icons)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
for j in 0...5
|
||||
icons[j]=[@directory+"tiles",@squares[i+(j*5)][0],@squares[i+(j*5)][1],384,0,64,64]
|
||||
end
|
||||
pbDrawImagePositions(@sprites[i].bitmap,icons)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
for j in 0...5
|
||||
icons[j]=[@directory+"tiles",@squares[i+(j*5)][0],@squares[i+(j*5)][1],320,0,64,64]
|
||||
end
|
||||
pbDrawImagePositions(@sprites[i].bitmap,icons)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
for j in 0...5
|
||||
icons[j]=[@directory+"tiles",@squares[i+(j*5)][0],@squares[i+(j*5)][1],896,0,64,64]
|
||||
end
|
||||
pbDrawImagePositions(@sprites[i].bitmap,icons)
|
||||
pbWait(Graphics.frame_rate/20)
|
||||
end
|
||||
@sprites["icon"].bitmap.clear
|
||||
for i in 0...6
|
||||
@sprites[i].bitmap.clear
|
||||
end
|
||||
@sprites["cursor"].bitmap.clear
|
||||
end
|
||||
|
||||
# def pbWaitText(msg,frames)
|
||||
# msgwindow=pbCreateMessageWindow
|
||||
# pbMessageDisplay(msgwindow,msg)
|
||||
# frames.times do
|
||||
# pbWait(1)
|
||||
# end
|
||||
# pbDisposeMessageWindow(msgwindow)
|
||||
# end
|
||||
|
||||
def pbEndScene
|
||||
@sprites["curtainL"].angle=-180
|
||||
@sprites["curtainR"].angle=90
|
||||
# Draw curtain effect
|
||||
@sprites["curtainL"].visible=true
|
||||
@sprites["curtainR"].visible=true
|
||||
angleDiff = 18*20/Graphics.frame_rate
|
||||
loop do
|
||||
@sprites["curtainL"].angle += angleDiff
|
||||
@sprites["curtainR"].angle -= angleDiff
|
||||
# Fixes a minor graphical bug
|
||||
@sprites["curtainL"].y-=2 if @sprites["curtainL"].angle>=-90
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
if @sprites["curtainL"].angle>=-90
|
||||
break
|
||||
end
|
||||
end
|
||||
pbFadeOutAndHide(@sprites) {update}
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@viewport.dispose
|
||||
end
|
||||
|
||||
def pbScene
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
getInput
|
||||
break if @quit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class VoltorbFlipScreen
|
||||
def initialize(scene)
|
||||
@scene=scene
|
||||
end
|
||||
|
||||
def pbStartScreen
|
||||
@scene.pbStart
|
||||
@scene.pbScene
|
||||
@scene.pbEndScene
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbVoltorbFlip
|
||||
if GameData::Item.exists?(:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE)
|
||||
pbMessage(_INTL("You can't play unless you have a Coin Case."))
|
||||
elsif $Trainer.coins == Settings::MAX_COINS
|
||||
pbMessage(_INTL("Your Coin Case is full!"))
|
||||
else
|
||||
scene=VoltorbFlip.new
|
||||
screen=VoltorbFlipScreen.new(scene)
|
||||
screen.pbStartScreen
|
||||
end
|
||||
end
|
||||
54
Data/Scripts/017_Minigames/005_Minigame_Lottery.rb
Normal file
54
Data/Scripts/017_Minigames/005_Minigame_Lottery.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
################################################################################
|
||||
# "Lottery" mini-game
|
||||
# By Maruno
|
||||
################################################################################
|
||||
def pbSetLotteryNumber(variable=1)
|
||||
t = pbGetTimeNow
|
||||
hash = t.day + (t.month << 5) + (t.year << 9)
|
||||
srand(hash) # seed RNG with fixed value depending on date
|
||||
lottery = rand(65536) # get a number
|
||||
srand # reseed RNG
|
||||
pbSet(variable,sprintf("%05d",lottery))
|
||||
end
|
||||
|
||||
def pbLottery(winnum,nameVar=2,positionVar=3,matchedVar=4)
|
||||
winnum=winnum.to_i
|
||||
winpoke=nil
|
||||
winpos=0
|
||||
winmatched=0
|
||||
for i in $Trainer.party
|
||||
thismatched=0
|
||||
id=i.owner.public_id
|
||||
for j in 0...5
|
||||
if (id/(10**j))%10 == (winnum/(10**j))%10
|
||||
thismatched+=1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
if thismatched>winmatched
|
||||
winpoke=i.name
|
||||
winpos=1 # Party
|
||||
winmatched=thismatched
|
||||
end
|
||||
end
|
||||
pbEachPokemon { |poke,_box|
|
||||
thismatched=0
|
||||
id=poke.owner.public_id
|
||||
for j in 0...5
|
||||
if (id/(10**j))%10 == (winnum/(10**j))%10
|
||||
thismatched+=1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
if thismatched>winmatched
|
||||
winpoke=poke.name
|
||||
winpos=2 # Storage
|
||||
winmatched=thismatched
|
||||
end
|
||||
}
|
||||
$game_variables[nameVar]=winpoke
|
||||
$game_variables[positionVar]=winpos
|
||||
$game_variables[matchedVar]=winmatched
|
||||
end
|
||||
622
Data/Scripts/017_Minigames/006_Minigame_Mining.rb
Normal file
622
Data/Scripts/017_Minigames/006_Minigame_Mining.rb
Normal file
@@ -0,0 +1,622 @@
|
||||
################################################################################
|
||||
# "Mining" mini-game
|
||||
# By Maruno
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run with: pbMiningGame
|
||||
################################################################################
|
||||
class MiningGameCounter < BitmapSprite
|
||||
attr_accessor :hits
|
||||
|
||||
def initialize(x,y)
|
||||
@viewport=Viewport.new(x,y,416,60)
|
||||
@viewport.z=99999
|
||||
super(416,60,@viewport)
|
||||
@hits=0
|
||||
@image=AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/cracks"))
|
||||
update
|
||||
end
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
value=@hits
|
||||
startx=416-48
|
||||
while value>6
|
||||
self.bitmap.blt(startx,0,@image.bitmap,Rect.new(0,0,48,52))
|
||||
startx-=48
|
||||
value-=6
|
||||
end
|
||||
startx-=48
|
||||
if value>0
|
||||
self.bitmap.blt(startx,0,@image.bitmap,Rect.new(0,value*52,96,52))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class MiningGameTile < BitmapSprite
|
||||
attr_reader :layer
|
||||
|
||||
def initialize(x,y)
|
||||
@viewport=Viewport.new(x,y,32,32)
|
||||
@viewport.z=99999
|
||||
super(32,32,@viewport)
|
||||
r = rand(100)
|
||||
if r<10; @layer = 2 # 10%
|
||||
elsif r<25; @layer = 3 # 15%
|
||||
elsif r<60; @layer = 4 # 35%
|
||||
elsif r<85; @layer = 5 # 25%
|
||||
else; @layer = 6 # 15%
|
||||
end
|
||||
@image=AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/tiles"))
|
||||
update
|
||||
end
|
||||
|
||||
def layer=(value)
|
||||
@layer=value
|
||||
@layer=0 if @layer<0
|
||||
end
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
if @layer>0
|
||||
self.bitmap.blt(0,0,@image.bitmap,Rect.new(0,32*(@layer-1),32,32))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class MiningGameCursor < BitmapSprite
|
||||
attr_accessor :mode
|
||||
attr_accessor :position
|
||||
attr_accessor :hit
|
||||
attr_accessor :counter
|
||||
ToolPositions = [[1,0],[1,1],[1,1],[0,0],[0,0],
|
||||
[0,2],[0,2],[0,0],[0,0],[0,2],[0,2]] # Graphic, position
|
||||
|
||||
def initialize(position=0,mode=0) # mode: 0=pick, 1=hammer
|
||||
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z = 99999
|
||||
super(Graphics.width,Graphics.height,@viewport)
|
||||
@position = position
|
||||
@mode = mode
|
||||
@hit = 0 # 0=regular, 1=hit item, 2=hit iron
|
||||
@counter = 0
|
||||
@cursorbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/cursor"))
|
||||
@toolbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/tools"))
|
||||
@hitsbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/hits"))
|
||||
update
|
||||
end
|
||||
|
||||
def isAnimating?
|
||||
return @counter>0
|
||||
end
|
||||
|
||||
def animate(hit)
|
||||
@counter = 22
|
||||
@hit = hit
|
||||
end
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
x = 32*(@position%MiningGameScene::BOARDWIDTH)
|
||||
y = 32*(@position/MiningGameScene::BOARDWIDTH)
|
||||
if @counter>0
|
||||
@counter -= 1
|
||||
toolx = x; tooly = y
|
||||
i = 10-(@counter/2).floor
|
||||
if ToolPositions[i][1]==1
|
||||
toolx -= 8; tooly += 8
|
||||
elsif ToolPositions[i][1]==2
|
||||
toolx += 6
|
||||
end
|
||||
self.bitmap.blt(toolx,tooly,@toolbitmap.bitmap,
|
||||
Rect.new(96*ToolPositions[i][0],96*@mode,96,96))
|
||||
if i<5 && i%2==0
|
||||
if @hit==2
|
||||
self.bitmap.blt(x-64,y,@hitsbitmap.bitmap,Rect.new(160*2,0,160,160))
|
||||
else
|
||||
self.bitmap.blt(x-64,y,@hitsbitmap.bitmap,Rect.new(160*@mode,0,160,160))
|
||||
end
|
||||
end
|
||||
if @hit==1 && i<3
|
||||
self.bitmap.blt(x-64,y,@hitsbitmap.bitmap,Rect.new(160*i,160,160,160))
|
||||
end
|
||||
else
|
||||
self.bitmap.blt(x,y+64,@cursorbitmap.bitmap,Rect.new(32*@mode,0,32,32))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class MiningGameScene
|
||||
BOARDWIDTH = 13
|
||||
BOARDHEIGHT = 10
|
||||
ITEMS = [ # Item, probability, graphic x, graphic y, width, height, pattern
|
||||
[:DOMEFOSSIL,20, 0,3, 5,4,[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0]],
|
||||
[:HELIXFOSSIL,5, 5,3, 4,4,[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]],
|
||||
[:HELIXFOSSIL,5, 9,3, 4,4,[1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1]],
|
||||
[:HELIXFOSSIL,5, 13,3, 4,4,[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]],
|
||||
[:HELIXFOSSIL,5, 17,3, 4,4,[1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1]],
|
||||
[:OLDAMBER,10, 21,3, 4,4,[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]],
|
||||
[:OLDAMBER,10, 25,3, 4,4,[1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1]],
|
||||
[:ROOTFOSSIL,5, 0,7, 5,5,[1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0]],
|
||||
[:ROOTFOSSIL,5, 5,7, 5,5,[0,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1,0,1,1,1,0]],
|
||||
[:ROOTFOSSIL,5, 10,7, 5,5,[0,1,1,0,0,1,1,0,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1]],
|
||||
[:ROOTFOSSIL,5, 15,7, 5,5,[0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,0]],
|
||||
[:SKULLFOSSIL,20, 20,7, 4,4,[1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0]],
|
||||
[:ARMORFOSSIL,20, 24,7, 5,4,[0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0]],
|
||||
[:CLAWFOSSIL,5, 0,12, 4,5,[0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,0,0]],
|
||||
[:CLAWFOSSIL,5, 4,12, 5,4,[1,1,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1]],
|
||||
[:CLAWFOSSIL,5, 9,12, 4,5,[0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,0,0]],
|
||||
[:CLAWFOSSIL,5, 13,12, 5,4,[1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1]],
|
||||
[:FIRESTONE,20, 20,11, 3,3,[1,1,1,1,1,1,1,1,1]],
|
||||
[:WATERSTONE,20, 23,11, 3,3,[1,1,1,1,1,1,1,1,0]],
|
||||
[:THUNDERSTONE,20, 26,11, 3,3,[0,1,1,1,1,1,1,1,0]],
|
||||
[:LEAFSTONE,10, 18,14, 3,4,[0,1,0,1,1,1,1,1,1,0,1,0]],
|
||||
[:LEAFSTONE,10, 21,14, 4,3,[0,1,1,0,1,1,1,1,0,1,1,0]],
|
||||
[:MOONSTONE,10, 25,14, 4,2,[0,1,1,1,1,1,1,0]],
|
||||
[:MOONSTONE,10, 27,16, 2,4,[1,0,1,1,1,1,0,1]],
|
||||
[:SUNSTONE,20, 21,17, 3,3,[0,1,0,1,1,1,1,1,1]],
|
||||
[:OVALSTONE,150, 24,17, 3,3,[1,1,1,1,1,1,1,1,1]],
|
||||
[:EVERSTONE,150, 21,20, 4,2,[1,1,1,1,1,1,1,1]],
|
||||
[:STARPIECE,100, 0,17, 3,3,[0,1,0,1,1,1,0,1,0]],
|
||||
[:REVIVE,100, 0,20, 3,3,[0,1,0,1,1,1,0,1,0]],
|
||||
[:MAXREVIVE,50, 0,23, 3,3,[1,1,1,1,1,1,1,1,1]],
|
||||
[:RAREBONE,50, 3,17, 6,3,[1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1]],
|
||||
[:RAREBONE,50, 3,20, 3,6,[1,1,1,0,1,0,0,1,0,0,1,0,0,1,0,1,1,1]],
|
||||
[:LIGHTCLAY,100, 6,20, 4,4,[1,0,1,0,1,1,1,0,1,1,1,1,0,1,0,1]],
|
||||
[:HARDSTONE,200, 6,24, 2,2,[1,1,1,1]],
|
||||
[:HEARTSCALE,200, 8,24, 2,2,[1,0,1,1]],
|
||||
[:IRONBALL,100, 9,17, 3,3,[1,1,1,1,1,1,1,1,1]],
|
||||
[:ODDKEYSTONE,100, 10,20, 4,4,[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:HEATROCK,50, 12,17, 4,3,[1,0,1,0,1,1,1,1,1,1,1,1]],
|
||||
[:DAMPROCK,50, 14,20, 3,3,[1,1,1,1,1,1,1,0,1]],
|
||||
[:SMOOTHROCK,50, 17,18, 4,4,[0,0,1,0,1,1,1,0,0,1,1,1,0,1,0,0]],
|
||||
[:ICYROCK,50, 17,22, 4,4,[0,1,1,0,1,1,1,1,1,1,1,1,1,0,0,1]],
|
||||
[:REDSHARD,100, 21,22, 3,3,[1,1,1,1,1,0,1,1,1]],
|
||||
[:GREENSHARD,100, 25,20, 4,3,[1,1,1,1,1,1,1,1,1,1,0,1]],
|
||||
[:YELLOWSHARD,100, 25,23, 4,3,[1,0,1,0,1,1,1,0,1,1,1,1]],
|
||||
[:BLUESHARD,100, 26,26, 3,3,[1,1,1,1,1,1,1,1,0]],
|
||||
[:INSECTPLATE,10, 0,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:DREADPLATE,10, 4,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:DRACOPLATE,10, 8,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:ZAPPLATE,10, 12,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:FISTPLATE,10, 16,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:FLAMEPLATE,10, 20,26, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:MEADOWPLATE,10, 0,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:EARTHPLATE,10, 4,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:ICICLEPLATE,10, 8,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:TOXICPLATE,10, 12,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:MINDPLATE,10, 16,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:STONEPLATE,10, 20,29, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:SKYPLATE,10, 0,32, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:SPOOKYPLATE,10, 4,32, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:IRONPLATE,10, 8,32, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]],
|
||||
[:SPLASHPLATE,10, 12,32, 4,3,[1,1,1,1,1,1,1,1,1,1,1,1]]
|
||||
]
|
||||
IRON = [ # Graphic x, graphic y, width, height, pattern
|
||||
[0,0, 1,4,[1,1,1,1]],
|
||||
[1,0, 2,4,[1,1,1,1,1,1,1,1]],
|
||||
[3,0, 4,2,[1,1,1,1,1,1,1,1]],
|
||||
[3,2, 4,1,[1,1,1,1]],
|
||||
[7,0, 3,3,[1,1,1,1,1,1,1,1,1]],
|
||||
[0,5, 3,2,[1,1,0,0,1,1]],
|
||||
[0,7, 3,2,[0,1,0,1,1,1]],
|
||||
[3,5, 3,2,[0,1,1,1,1,0]],
|
||||
[3,7, 3,2,[1,1,1,0,1,0]],
|
||||
[6,3, 2,3,[1,0,1,1,0,1]],
|
||||
[8,3, 2,3,[0,1,1,1,1,0]],
|
||||
[6,6, 2,3,[1,0,1,1,1,0]],
|
||||
[8,6, 2,3,[0,1,1,1,0,1]]
|
||||
]
|
||||
|
||||
def update
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
end
|
||||
|
||||
def pbStartScene
|
||||
@sprites={}
|
||||
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z=99999
|
||||
addBackgroundPlane(@sprites,"bg","Mining/miningbg",@viewport)
|
||||
@sprites["itemlayer"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
@itembitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/items"))
|
||||
@ironbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/irons"))
|
||||
@items=[]
|
||||
@itemswon=[]
|
||||
@iron=[]
|
||||
pbDistributeItems
|
||||
pbDistributeIron
|
||||
for i in 0...BOARDHEIGHT
|
||||
for j in 0...BOARDWIDTH
|
||||
@sprites["tile#{j+i*BOARDWIDTH}"]=MiningGameTile.new(32*j,64+32*i)
|
||||
end
|
||||
end
|
||||
@sprites["crack"]=MiningGameCounter.new(0,4)
|
||||
@sprites["cursor"]=MiningGameCursor.new(58,0) # central position, pick
|
||||
@sprites["tool"]=IconSprite.new(434,254,@viewport)
|
||||
@sprites["tool"].setBitmap(sprintf("Graphics/Pictures/Mining/toolicons"))
|
||||
@sprites["tool"].src_rect.set(0,0,68,100)
|
||||
update
|
||||
pbFadeInAndShow(@sprites)
|
||||
end
|
||||
|
||||
def pbDistributeItems
|
||||
# Set items to be buried (index in ITEMS, x coord, y coord)
|
||||
ptotal=0
|
||||
for i in ITEMS
|
||||
ptotal+=i[1]
|
||||
end
|
||||
numitems=2+rand(3)
|
||||
tries = 0
|
||||
while numitems>0
|
||||
rnd=rand(ptotal)
|
||||
added=false
|
||||
for i in 0...ITEMS.length
|
||||
rnd-=ITEMS[i][1]
|
||||
if rnd<0
|
||||
if pbNoDuplicateItems(ITEMS[i][0])
|
||||
while !added
|
||||
provx=rand(BOARDWIDTH-ITEMS[i][4]+1)
|
||||
provy=rand(BOARDHEIGHT-ITEMS[i][5]+1)
|
||||
if pbCheckOverlaps(false,provx,provy,ITEMS[i][4],ITEMS[i][5],ITEMS[i][6])
|
||||
@items.push([i,provx,provy])
|
||||
numitems-=1
|
||||
added=true
|
||||
end
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
break if added
|
||||
end
|
||||
tries += 1
|
||||
break if tries>=500
|
||||
end
|
||||
# Draw items on item layer
|
||||
layer=@sprites["itemlayer"].bitmap
|
||||
for i in @items
|
||||
ox=ITEMS[i[0]][2]
|
||||
oy=ITEMS[i[0]][3]
|
||||
rectx=ITEMS[i[0]][4]
|
||||
recty=ITEMS[i[0]][5]
|
||||
layer.blt(32*i[1],64+32*i[2],@itembitmap.bitmap,Rect.new(32*ox,32*oy,32*rectx,32*recty))
|
||||
end
|
||||
end
|
||||
|
||||
def pbDistributeIron
|
||||
# Set iron to be buried (index in IRON, x coord, y coord)
|
||||
numitems=4+rand(3)
|
||||
tries = 0
|
||||
while numitems>0
|
||||
rnd=rand(IRON.length)
|
||||
provx=rand(BOARDWIDTH-IRON[rnd][2]+1)
|
||||
provy=rand(BOARDHEIGHT-IRON[rnd][3]+1)
|
||||
if pbCheckOverlaps(true,provx,provy,IRON[rnd][2],IRON[rnd][3],IRON[rnd][4])
|
||||
@iron.push([rnd,provx,provy])
|
||||
numitems-=1
|
||||
end
|
||||
tries += 1
|
||||
break if tries>=500
|
||||
end
|
||||
# Draw items on item layer
|
||||
layer=@sprites["itemlayer"].bitmap
|
||||
for i in @iron
|
||||
ox=IRON[i[0]][0]
|
||||
oy=IRON[i[0]][1]
|
||||
rectx=IRON[i[0]][2]
|
||||
recty=IRON[i[0]][3]
|
||||
layer.blt(32*i[1],64+32*i[2],@ironbitmap.bitmap,Rect.new(32*ox,32*oy,32*rectx,32*recty))
|
||||
end
|
||||
end
|
||||
|
||||
def pbNoDuplicateItems(newitem)
|
||||
return true if newitem==:HEARTSCALE # Allow multiple Heart Scales
|
||||
fossils=[:DOMEFOSSIL,:HELIXFOSSIL,:OLDAMBER,:ROOTFOSSIL,
|
||||
:SKULLFOSSIL,:ARMORFOSSIL,:CLAWFOSSIL]
|
||||
plates=[:INSECTPLATE,:DREADPLATE,:DRACOPLATE,:ZAPPLATE,:FISTPLATE,
|
||||
:FLAMEPLATE,:MEADOWPLATE,:EARTHPLATE,:ICICLEPLATE,:TOXICPLATE,
|
||||
:MINDPLATE,:STONEPLATE,:SKYPLATE,:SPOOKYPLATE,:IRONPLATE,:SPLASHPLATE]
|
||||
for i in @items
|
||||
preitem=ITEMS[i[0]][0]
|
||||
return false if preitem==newitem # No duplicate items
|
||||
return false if fossils.include?(preitem) && fossils.include?(newitem)
|
||||
return false if plates.include?(preitem) && plates.include?(newitem)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbCheckOverlaps(checkiron,provx,provy,provwidth,provheight,provpattern)
|
||||
for i in @items
|
||||
prex=i[1]
|
||||
prey=i[2]
|
||||
prewidth=ITEMS[i[0]][4]
|
||||
preheight=ITEMS[i[0]][5]
|
||||
prepattern=ITEMS[i[0]][6]
|
||||
next if provx+provwidth<=prex || provx>=prex+prewidth ||
|
||||
provy+provheight<=prey || provy>=prey+preheight
|
||||
for j in 0...prepattern.length
|
||||
next if prepattern[j]==0
|
||||
xco=prex+(j%prewidth)
|
||||
yco=prey+(j/prewidth).floor
|
||||
next if provx+provwidth<=xco || provx>xco ||
|
||||
provy+provheight<=yco || provy>yco
|
||||
return false if provpattern[xco-provx+(yco-provy)*provwidth]==1
|
||||
end
|
||||
end
|
||||
if checkiron # Check other irons as well
|
||||
for i in @iron
|
||||
prex=i[1]
|
||||
prey=i[2]
|
||||
prewidth=IRON[i[0]][2]
|
||||
preheight=IRON[i[0]][3]
|
||||
prepattern=IRON[i[0]][4]
|
||||
next if provx+provwidth<=prex || provx>=prex+prewidth ||
|
||||
provy+provheight<=prey || provy>=prey+preheight
|
||||
for j in 0...prepattern.length
|
||||
next if prepattern[j]==0
|
||||
xco=prex+(j%prewidth)
|
||||
yco=prey+(j/prewidth).floor
|
||||
next if provx+provwidth<=xco || provx>xco ||
|
||||
provy+provheight<=yco || provy>yco
|
||||
return false if provpattern[xco-provx+(yco-provy)*provwidth]==1
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbHit
|
||||
hittype=0
|
||||
position=@sprites["cursor"].position
|
||||
if @sprites["cursor"].mode==1 # Hammer
|
||||
pattern=[1,2,1,
|
||||
2,2,2,
|
||||
1,2,1]
|
||||
@sprites["crack"].hits+=2 if !($DEBUG && Input.press?(Input::CTRL))
|
||||
else # Pick
|
||||
pattern=[0,1,0,
|
||||
1,2,1,
|
||||
0,1,0]
|
||||
@sprites["crack"].hits+=1 if !($DEBUG && Input.press?(Input::CTRL))
|
||||
end
|
||||
if @sprites["tile#{position}"].layer<=pattern[4] && pbIsIronThere?(position)
|
||||
@sprites["tile#{position}"].layer-=pattern[4]
|
||||
pbSEPlay("Mining iron")
|
||||
hittype=2
|
||||
else
|
||||
for i in 0..2
|
||||
ytile=i-1+position/BOARDWIDTH
|
||||
next if ytile<0 || ytile>=BOARDHEIGHT
|
||||
for j in 0..2
|
||||
xtile=j-1+position%BOARDWIDTH
|
||||
next if xtile<0 || xtile>=BOARDWIDTH
|
||||
@sprites["tile#{xtile+ytile*BOARDWIDTH}"].layer-=pattern[j+i*3]
|
||||
end
|
||||
end
|
||||
if @sprites["cursor"].mode==1 # Hammer
|
||||
pbSEPlay("Mining hammer")
|
||||
else
|
||||
pbSEPlay("Mining pick")
|
||||
end
|
||||
end
|
||||
update
|
||||
Graphics.update
|
||||
hititem=(@sprites["tile#{position}"].layer==0 && pbIsItemThere?(position))
|
||||
hittype=1 if hititem
|
||||
@sprites["cursor"].animate(hittype)
|
||||
revealed=pbCheckRevealed
|
||||
if revealed.length>0
|
||||
pbSEPlay("Mining reveal full")
|
||||
pbFlashItems(revealed)
|
||||
elsif hititem
|
||||
pbSEPlay("Mining reveal")
|
||||
end
|
||||
end
|
||||
|
||||
def pbIsItemThere?(position)
|
||||
posx=position%BOARDWIDTH
|
||||
posy=position/BOARDWIDTH
|
||||
for i in @items
|
||||
index=i[0]
|
||||
width=ITEMS[index][4]
|
||||
height=ITEMS[index][5]
|
||||
pattern=ITEMS[index][6]
|
||||
next if posx<i[1] || posx>=(i[1]+width)
|
||||
next if posy<i[2] || posy>=(i[2]+height)
|
||||
dx=posx-i[1]
|
||||
dy=posy-i[2]
|
||||
return true if pattern[dx+dy*width]>0
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def pbIsIronThere?(position)
|
||||
posx=position%BOARDWIDTH
|
||||
posy=position/BOARDWIDTH
|
||||
for i in @iron
|
||||
index=i[0]
|
||||
width=IRON[index][2]
|
||||
height=IRON[index][3]
|
||||
pattern=IRON[index][4]
|
||||
next if posx<i[1] || posx>=(i[1]+width)
|
||||
next if posy<i[2] || posy>=(i[2]+height)
|
||||
dx=posx-i[1]
|
||||
dy=posy-i[2]
|
||||
return true if pattern[dx+dy*width]>0
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def pbCheckRevealed
|
||||
ret=[]
|
||||
for i in 0...@items.length
|
||||
next if @items[i][3]
|
||||
revealed=true
|
||||
index=@items[i][0]
|
||||
width=ITEMS[index][4]
|
||||
height=ITEMS[index][5]
|
||||
pattern=ITEMS[index][6]
|
||||
for j in 0...height
|
||||
for k in 0...width
|
||||
layer=@sprites["tile#{@items[i][1]+k+(@items[i][2]+j)*BOARDWIDTH}"].layer
|
||||
revealed=false if layer>0 && pattern[k+j*width]>0
|
||||
break if !revealed
|
||||
end
|
||||
break if !revealed
|
||||
end
|
||||
ret.push(i) if revealed
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbFlashItems(revealed)
|
||||
return if revealed.length<=0
|
||||
revealeditems = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
|
||||
halfFlashTime = Graphics.frame_rate/8
|
||||
alphaDiff = (255.0/halfFlashTime).ceil
|
||||
for i in 1..halfFlashTime*2
|
||||
for index in revealed
|
||||
burieditem=@items[index]
|
||||
revealeditems.bitmap.blt(32*burieditem[1],64+32*burieditem[2],
|
||||
@itembitmap.bitmap,
|
||||
Rect.new(32*ITEMS[burieditem[0]][2],32*ITEMS[burieditem[0]][3],
|
||||
32*ITEMS[burieditem[0]][4],32*ITEMS[burieditem[0]][5]))
|
||||
if i>halfFlashTime
|
||||
revealeditems.color = Color.new(255,255,255,(halfFlashTime*2-i)*alphaDiff)
|
||||
else
|
||||
revealeditems.color = Color.new(255,255,255,i*alphaDiff)
|
||||
end
|
||||
end
|
||||
update
|
||||
Graphics.update
|
||||
end
|
||||
revealeditems.dispose
|
||||
for index in revealed
|
||||
@items[index][3]=true
|
||||
item=ITEMS[@items[index][0]][0]
|
||||
@itemswon.push(item)
|
||||
end
|
||||
end
|
||||
|
||||
def pbMain
|
||||
pbSEPlay("Mining ping")
|
||||
pbMessage(_INTL("Something pinged in the wall!\n{1} confirmed!",@items.length))
|
||||
loop do
|
||||
update
|
||||
Graphics.update
|
||||
Input.update
|
||||
next if @sprites["cursor"].isAnimating?
|
||||
# Check end conditions
|
||||
if @sprites["crack"].hits>=49
|
||||
@sprites["cursor"].visible=false
|
||||
pbSEPlay("Mining collapse")
|
||||
collapseviewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
collapseviewport.z=99999
|
||||
@sprites["collapse"]=BitmapSprite.new(Graphics.width,Graphics.height,collapseviewport)
|
||||
collapseTime = Graphics.frame_rate*8/10
|
||||
collapseFraction = (Graphics.height.to_f/collapseTime).ceil
|
||||
for i in 1..collapseTime
|
||||
@sprites["collapse"].bitmap.fill_rect(0,collapseFraction*(i-1),
|
||||
Graphics.width,collapseFraction*i,Color.new(0,0,0))
|
||||
Graphics.update
|
||||
end
|
||||
pbMessage(_INTL("The wall collapsed!"))
|
||||
break
|
||||
end
|
||||
foundall=true
|
||||
for i in @items
|
||||
foundall=false if !i[3]
|
||||
break if !foundall
|
||||
end
|
||||
if foundall
|
||||
@sprites["cursor"].visible=false
|
||||
pbWait(Graphics.frame_rate*3/4)
|
||||
pbSEPlay("Mining found all")
|
||||
pbMessage(_INTL("Everything was dug up!"))
|
||||
break
|
||||
end
|
||||
# Input
|
||||
if Input.trigger?(Input::UP) || Input.repeat?(Input::UP)
|
||||
if @sprites["cursor"].position>=BOARDWIDTH
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position-=BOARDWIDTH
|
||||
end
|
||||
elsif Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
|
||||
if @sprites["cursor"].position<(BOARDWIDTH*(BOARDHEIGHT-1))
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position+=BOARDWIDTH
|
||||
end
|
||||
elsif Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
|
||||
if @sprites["cursor"].position%BOARDWIDTH>0
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position-=1
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
|
||||
if @sprites["cursor"].position%BOARDWIDTH<(BOARDWIDTH-1)
|
||||
pbSEPlay("Mining cursor")
|
||||
@sprites["cursor"].position+=1
|
||||
end
|
||||
elsif Input.trigger?(Input::ACTION) # Change tool mode
|
||||
pbSEPlay("Mining tool change")
|
||||
newmode=(@sprites["cursor"].mode+1)%2
|
||||
@sprites["cursor"].mode=newmode
|
||||
@sprites["tool"].src_rect.set(newmode*68,0,68,100)
|
||||
@sprites["tool"].y=254-144*newmode
|
||||
elsif Input.trigger?(Input::USE) # Hit
|
||||
pbHit
|
||||
elsif Input.trigger?(Input::BACK) # Quit
|
||||
break if pbConfirmMessage(_INTL("Are you sure you want to give up?"))
|
||||
end
|
||||
end
|
||||
pbGiveItems
|
||||
end
|
||||
|
||||
def pbGiveItems
|
||||
if @itemswon.length>0
|
||||
for i in @itemswon
|
||||
if $PokemonBag.pbStoreItem(i)
|
||||
pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]",
|
||||
GameData::Item.get(i).name))
|
||||
else
|
||||
pbMessage(_INTL("One {1} was found, but you have no room for it.",
|
||||
GameData::Item.get(i).name))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbEndScene
|
||||
pbFadeOutAndHide(@sprites)
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@viewport.dispose
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class MiningGame
|
||||
def initialize(scene)
|
||||
@scene=scene
|
||||
end
|
||||
|
||||
def pbStartScreen
|
||||
@scene.pbStartScene
|
||||
@scene.pbMain
|
||||
@scene.pbEndScene
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbMiningGame
|
||||
pbFadeOutIn {
|
||||
scene = MiningGameScene.new
|
||||
screen = MiningGame.new(scene)
|
||||
screen.pbStartScreen
|
||||
}
|
||||
end
|
||||
582
Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb
Normal file
582
Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb
Normal file
@@ -0,0 +1,582 @@
|
||||
################################################################################
|
||||
# "Tile Puzzle" mini-games
|
||||
# By Maruno
|
||||
# Graphics by the__end
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run with: pbTilePuzzle(game,board,width,height)
|
||||
# game = 1 (Ruins of Alph puzzle),
|
||||
# 2 (Ruins of Alph puzzle plus tile rotations),
|
||||
# 3 (Mystic Square),
|
||||
# 4 (swap two adjacent tiles),
|
||||
# 5 (swap two adjacent tiles plus tile rotations),
|
||||
# 6 (Rubik's square),
|
||||
# 7 (rotate selected tile plus adjacent tiles at once).
|
||||
# board = The name/number of the graphics to be used.
|
||||
# width,height = Optional, the number of tiles wide/high the puzzle is (0 for
|
||||
# the default value of 4).
|
||||
################################################################################
|
||||
class TilePuzzleCursor < BitmapSprite
|
||||
attr_accessor :game
|
||||
attr_accessor :position
|
||||
attr_accessor :arrows
|
||||
attr_accessor :selected
|
||||
attr_accessor :holding
|
||||
|
||||
def initialize(game,position,tilewidth,tileheight,boardwidth,boardheight)
|
||||
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z=99999
|
||||
super(Graphics.width,Graphics.height,@viewport)
|
||||
@game=game
|
||||
@position=position
|
||||
@tilewidth=tilewidth
|
||||
@tileheight=tileheight
|
||||
@boardwidth=boardwidth
|
||||
@boardheight=boardheight
|
||||
@arrows=[]
|
||||
@selected=false
|
||||
@holding=false
|
||||
@cursorbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Tile Puzzle/cursor"))
|
||||
update
|
||||
end
|
||||
|
||||
def update
|
||||
self.bitmap.clear
|
||||
x=(Graphics.width-(@tilewidth*@boardwidth))/2
|
||||
if @position>=@boardwidth*@boardheight
|
||||
x=(x-(@tilewidth*(@boardwidth/2).ceil))/2-10
|
||||
if (@position%@boardwidth)>=(@boardwidth/2).ceil
|
||||
x=Graphics.width-x-@tilewidth*@boardwidth
|
||||
end
|
||||
end
|
||||
x+=@tilewidth*(@position%@boardwidth)
|
||||
y=(Graphics.height-(@tileheight*@boardheight))/2-32
|
||||
y+=@tileheight*((@position%(@boardwidth*@boardheight))/@boardwidth)
|
||||
self.tone=Tone.new(0,(@holding ? 64 : 0),(@holding ? 64 : 0),0)
|
||||
# Cursor
|
||||
if @game!=3
|
||||
expand=(@holding) ? 0 : 4
|
||||
for i in 0...4
|
||||
self.bitmap.blt(x+(i%2)*(@tilewidth-@cursorbitmap.width/4)+expand*(((i%2)*2)-1),
|
||||
y+(i/2)*(@tileheight-@cursorbitmap.height/2)+expand*(((i/2)*2)-1),
|
||||
@cursorbitmap.bitmap,Rect.new(
|
||||
(i%2)*@cursorbitmap.width/4,(i/2)*@cursorbitmap.height/2,
|
||||
@cursorbitmap.width/4,@cursorbitmap.height/2))
|
||||
end
|
||||
end
|
||||
# Arrows
|
||||
if @selected || @game==3
|
||||
expand=(@game==3) ? 0 : 4
|
||||
xin=[(@tilewidth-@cursorbitmap.width/4)/2,-expand,
|
||||
@tilewidth-@cursorbitmap.width/4+expand,(@tilewidth-@cursorbitmap.width/4)/2]
|
||||
yin=[@tileheight-@cursorbitmap.height/2+expand,(@tileheight-@cursorbitmap.height/2)/2,
|
||||
(@tileheight-@cursorbitmap.height/2)/2,-expand]
|
||||
for i in 0...4
|
||||
if @arrows[i]
|
||||
self.bitmap.blt(x+xin[i],y+yin[i],@cursorbitmap.bitmap,Rect.new(
|
||||
@cursorbitmap.width/2+(i%2)*(@cursorbitmap.width/4),
|
||||
(i/2)*(@cursorbitmap.height/2),
|
||||
@cursorbitmap.width/4,@cursorbitmap.height/2))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class TilePuzzleScene
|
||||
def initialize(game,board,width,height)
|
||||
@game=game
|
||||
@board=board
|
||||
@boardwidth=(width>0) ? width : 4
|
||||
@boardheight=(height>0) ? height : 4
|
||||
end
|
||||
|
||||
def update
|
||||
xtop=(Graphics.width-(@tilewidth*@boardwidth))/2
|
||||
ytop=(Graphics.height-(@tileheight*@boardheight))/2+@tileheight/2-32
|
||||
for i in 0...@boardwidth*@boardheight
|
||||
pos=-1
|
||||
for j in 0...@tiles.length
|
||||
pos=j if @tiles[j]==i
|
||||
end
|
||||
@sprites["tile#{i}"].z=0
|
||||
@sprites["tile#{i}"].tone=Tone.new(0,0,0,0)
|
||||
if @heldtile==i
|
||||
pos=@sprites["cursor"].position
|
||||
@sprites["tile#{i}"].z=1
|
||||
@sprites["tile#{i}"].tone=Tone.new(64,0,0,0) if @tiles[pos]>=0
|
||||
end
|
||||
thisx=xtop
|
||||
if pos>=0
|
||||
if pos>=@boardwidth*@boardheight
|
||||
thisx=(xtop-(@tilewidth*(@boardwidth/2).ceil))/2-10
|
||||
if (pos%@boardwidth)>=(@boardwidth/2).ceil
|
||||
thisx=Graphics.width-thisx-@tilewidth*@boardwidth
|
||||
end
|
||||
end
|
||||
@sprites["tile#{i}"].x=thisx+@tilewidth*(pos%@boardwidth)+@tilewidth/2
|
||||
@sprites["tile#{i}"].y=ytop+@tileheight*((pos%(@boardwidth*@boardheight))/@boardwidth)
|
||||
next if @game==3
|
||||
rotatebitmaps=[@tilebitmap,@tilebitmap1,@tilebitmap2,@tilebitmap3]
|
||||
@sprites["tile#{i}"].bitmap.clear
|
||||
if rotatebitmaps[@angles[i]]
|
||||
@sprites["tile#{i}"].bitmap.blt(0,0,rotatebitmaps[@angles[i]].bitmap,
|
||||
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
|
||||
@sprites["tile#{i}"].angle=0
|
||||
else
|
||||
@sprites["tile#{i}"].bitmap.blt(0,0,@tilebitmap.bitmap,
|
||||
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
|
||||
@sprites["tile#{i}"].angle=@angles[i]*90
|
||||
end
|
||||
end
|
||||
end
|
||||
updateCursor
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
end
|
||||
|
||||
def updateCursor
|
||||
arrows=[]
|
||||
for i in 0...4
|
||||
arrows.push(pbCanMoveInDir?(@sprites["cursor"].position,(i+1)*2,@game==6))
|
||||
end
|
||||
@sprites["cursor"].arrows=arrows
|
||||
end
|
||||
|
||||
def pbStartScene
|
||||
@sprites={}
|
||||
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
|
||||
@viewport.z=99999
|
||||
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/bg#{@board}")
|
||||
addBackgroundPlane(@sprites,"bg","Tile Puzzle/bg#{@board}",@viewport)
|
||||
else
|
||||
addBackgroundPlane(@sprites,"bg","Tile Puzzle/bg",@viewport)
|
||||
end
|
||||
@tilebitmap=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}")
|
||||
@tilebitmap1=nil; @tilebitmap2=nil; @tilebitmap3=nil
|
||||
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_1")
|
||||
@tilebitmap1=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_1")
|
||||
end
|
||||
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_2")
|
||||
@tilebitmap2=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_2")
|
||||
end
|
||||
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_3")
|
||||
@tilebitmap3=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_3")
|
||||
end
|
||||
@tilewidth=@tilebitmap.width/@boardwidth
|
||||
@tileheight=@tilebitmap.height/@boardheight
|
||||
for i in 0...@boardwidth*@boardheight
|
||||
@sprites["tile#{i}"]=BitmapSprite.new(@tilewidth,@tileheight,@viewport)
|
||||
@sprites["tile#{i}"].ox=@tilewidth/2
|
||||
@sprites["tile#{i}"].oy=@tileheight/2
|
||||
break if @game==3 && i>=@boardwidth*@boardheight-1
|
||||
@sprites["tile#{i}"].bitmap.blt(0,0,@tilebitmap.bitmap,
|
||||
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
|
||||
end
|
||||
@heldtile=-1
|
||||
@angles=[]
|
||||
@tiles=pbShuffleTiles
|
||||
@sprites["cursor"]=TilePuzzleCursor.new(@game,pbDefaultCursorPosition,
|
||||
@tilewidth,@tileheight,@boardwidth,@boardheight)
|
||||
update
|
||||
pbFadeInAndShow(@sprites)
|
||||
end
|
||||
|
||||
def pbShuffleTiles
|
||||
ret=[]
|
||||
for i in 0...@boardwidth*@boardheight; ret.push(i); @angles.push(0); end
|
||||
if @game==6
|
||||
@tiles=ret
|
||||
5.times do
|
||||
pbShiftLine([2,4,6,8][rand(4)],rand(@boardwidth*@boardheight),false)
|
||||
end
|
||||
return @tiles
|
||||
elsif @game==7
|
||||
@tiles=ret
|
||||
5.times do
|
||||
pbRotateTile(rand(@boardwidth*@boardheight),false)
|
||||
end
|
||||
else
|
||||
ret.shuffle!
|
||||
if @game==3 # Make sure only solvable Mystic Squares are allowed.
|
||||
num=0; blank=-1
|
||||
for i in 0...ret.length-1
|
||||
blank=i if ret[i]==@boardwidth*@boardheight-1
|
||||
for j in i...ret.length
|
||||
num+=1 if ret[j]<ret[i] && ret[i]!=@boardwidth*@boardheight-1 &&
|
||||
ret[j]!=@boardwidth*@boardheight-1
|
||||
end
|
||||
end
|
||||
if @boardwidth%2==1
|
||||
ret=pbShuffleTiles if num%2==1
|
||||
else
|
||||
ret=pbShuffleTiles if !((num%2==0 && (@boardheight-(blank/@boardwidth))%2==1) ||
|
||||
(num%2==1 && (@boardheight-(blank/@boardwidth))%2==0))
|
||||
end
|
||||
end
|
||||
if @game==1 || @game==2
|
||||
ret2=[]
|
||||
for i in 0...@boardwidth*@boardheight; ret2.push(-1); end
|
||||
ret=ret2+ret
|
||||
end
|
||||
if @game==2 || @game==5
|
||||
for i in 0...@angles.length; @angles[i]=rand(4); end
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbDefaultCursorPosition
|
||||
if @game==3
|
||||
for i in 0...@boardwidth*@boardheight
|
||||
return i if @tiles[i]==@boardwidth*@boardheight-1
|
||||
end
|
||||
return 0
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
def pbMoveCursor(pos,dir)
|
||||
if dir==2
|
||||
pos+=@boardwidth
|
||||
elsif dir==4
|
||||
if pos>=@boardwidth*@boardheight
|
||||
if pos%@boardwidth==(@boardwidth/2).ceil
|
||||
pos=((pos%(@boardwidth*@boardheight))/@boardwidth)*@boardwidth+@boardwidth-1
|
||||
else
|
||||
pos-=1
|
||||
end
|
||||
else
|
||||
if (pos%@boardwidth)==0
|
||||
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil-1
|
||||
else
|
||||
pos-=1
|
||||
end
|
||||
end
|
||||
elsif dir==6
|
||||
if pos>=@boardwidth*@boardheight
|
||||
if pos%@boardwidth==(@boardwidth/2).ceil-1
|
||||
pos=((pos%(@boardwidth*@boardheight))/@boardwidth)*@boardwidth
|
||||
else
|
||||
pos+=1
|
||||
end
|
||||
else
|
||||
if pos%@boardwidth>=@boardwidth-1
|
||||
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil
|
||||
else
|
||||
pos+=1
|
||||
end
|
||||
end
|
||||
elsif dir==8
|
||||
pos-=@boardwidth
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
def pbCanMoveInDir?(pos,dir,swapping)
|
||||
return true if @game==6 && swapping
|
||||
if dir==2
|
||||
return false if (pos/@boardwidth)%@boardheight>=@boardheight-1
|
||||
elsif dir==4
|
||||
if @game==1 || @game==2
|
||||
return false if pos>=@boardwidth*@boardheight && pos%@boardwidth==0
|
||||
else
|
||||
return false if pos%@boardwidth==0
|
||||
end
|
||||
elsif dir==6
|
||||
if @game==1 || @game==2
|
||||
return false if pos>=@boardwidth*@boardheight && pos%@boardwidth>=@boardwidth-1
|
||||
else
|
||||
return false if pos%@boardwidth>=@boardwidth-1
|
||||
end
|
||||
elsif dir==8
|
||||
return false if (pos/@boardwidth)%@boardheight==0
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbRotateTile(pos,anim=true)
|
||||
if @heldtile>=0
|
||||
if anim
|
||||
@sprites["cursor"].visible=false
|
||||
@sprites["tile#{@heldtile}"].z = 1
|
||||
oldAngle = @sprites["tile#{@heldtile}"].angle
|
||||
rotateTime = Graphics.frame_rate/4
|
||||
angleDiff = 90.0/rotateTime
|
||||
rotateTime.times do
|
||||
@sprites["tile#{@heldtile}"].angle -= angleDiff
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
@sprites["tile#{@heldtile}"].z = 0
|
||||
@sprites["tile#{@heldtile}"].angle = oldAngle-90
|
||||
@sprites["cursor"].visible=true if !pbCheckWin
|
||||
end
|
||||
@angles[@heldtile]-=1
|
||||
@angles[@heldtile]+=4 if @angles[@heldtile]<0
|
||||
else
|
||||
return if @tiles[pos]<0
|
||||
group=pbGetNearTiles(pos)
|
||||
if anim
|
||||
@sprites["cursor"].visible=false
|
||||
oldAngles = []
|
||||
for i in group
|
||||
@sprites["tile#{@tiles[i]}"].z = 1
|
||||
oldAngles[i] = @sprites["tile#{@tiles[i]}"].angle
|
||||
end
|
||||
rotateTime = Graphics.frame_rate/4
|
||||
angleDiff = 90.0/rotateTime
|
||||
rotateTime.times do
|
||||
for i in group
|
||||
@sprites["tile#{@tiles[i]}"].angle -= angleDiff
|
||||
end
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
for i in group
|
||||
@sprites["tile#{@tiles[i]}"].z = 0
|
||||
@sprites["tile#{@tiles[i]}"].angle = oldAngles[i]-90
|
||||
end
|
||||
@sprites["cursor"].visible=true if !pbCheckWin
|
||||
end
|
||||
for i in group
|
||||
tile=@tiles[i]
|
||||
@angles[tile]-=1
|
||||
@angles[tile]+=4 if @angles[tile]<0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbGetNearTiles(pos)
|
||||
ret=[pos]
|
||||
if @game==7
|
||||
for i in [2,4,6,8]
|
||||
ret.push(pbMoveCursor(pos,i)) if pbCanMoveInDir?(pos,i,true)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbSwapTiles(dir)
|
||||
cursor=@sprites["cursor"].position
|
||||
return pbShiftLine(dir,cursor) if @game==6
|
||||
movetile=pbMoveCursor(cursor,dir)
|
||||
@sprites["cursor"].visible=false
|
||||
@sprites["tile#{@tiles[cursor]}"].z=1
|
||||
if dir==2 || dir==8 # Swap vertically
|
||||
swapTime = Graphics.frame_rate*3/10
|
||||
distancePerFrame = (@tileheight.to_f/swapTime).ceil
|
||||
dist = (dir/4).floor-1
|
||||
swapTime.times do
|
||||
@sprites["tile#{@tiles[movetile]}"].y += dist*distancePerFrame
|
||||
@sprites["tile#{@tiles[cursor]}"].y -= dist*distancePerFrame
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
else # Swap horizontally
|
||||
swapTime = Graphics.frame_rate*3/10
|
||||
distancePerFrame = (@tilewidth.to_f/swapTime).ceil
|
||||
dist = dir-5
|
||||
swapTime.times do
|
||||
@sprites["tile#{@tiles[movetile]}"].x -= dist*distancePerFrame
|
||||
@sprites["tile#{@tiles[cursor]}"].x += dist*distancePerFrame
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
end
|
||||
@tiles[cursor], @tiles[movetile]=@tiles[movetile], @tiles[cursor]
|
||||
@sprites["tile#{@tiles[cursor]}"].z=0
|
||||
@sprites["cursor"].position=movetile
|
||||
@sprites["cursor"].selected=false
|
||||
@sprites["cursor"].visible=true if !pbCheckWin
|
||||
return true
|
||||
end
|
||||
|
||||
def pbShiftLine(dir,cursor,anim=true)
|
||||
# Get tiles involved
|
||||
tiles=[]; dist=0
|
||||
if dir==2 || dir==8
|
||||
dist=(dir/4).floor-1
|
||||
while (dist>0 && cursor<(@boardwidth-1)*@boardheight) ||
|
||||
(dist<0 && cursor>=@boardwidth)
|
||||
cursor+=(@boardwidth*dist)
|
||||
end
|
||||
for i in 0...@boardheight
|
||||
tiles.push(cursor-i*dist*@boardwidth)
|
||||
end
|
||||
else
|
||||
dist=dir-5
|
||||
while (dist>0 && cursor%@boardwidth>0) ||
|
||||
(dist<0 && cursor%@boardwidth<@boardwidth-1)
|
||||
cursor-=dist
|
||||
end
|
||||
for i in 0...@boardwidth
|
||||
tiles.push(cursor+i*dist)
|
||||
end
|
||||
end
|
||||
# Shift tiles
|
||||
fadeTime = Graphics.frame_rate*4/10
|
||||
fadeDiff = (255.0/fadeTime).ceil
|
||||
if anim
|
||||
@sprites["cursor"].visible=false
|
||||
fadeTime.times do
|
||||
@sprites["tile#{@tiles[tiles[tiles.length-1]]}"].opacity-=fadeDiff
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
shiftTime = Graphics.frame_rate*3/10
|
||||
if dir==2 || dir==8
|
||||
distancePerFrame = (@tileheight.to_f/shiftTime).ceil
|
||||
shiftTime.times do
|
||||
for i in tiles
|
||||
@sprites["tile#{@tiles[i]}"].y -= dist*distancePerFrame
|
||||
end
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
else
|
||||
distancePerFrame = (@tilewidth.to_f/shiftTime).ceil
|
||||
shiftTime.times do
|
||||
for i in tiles
|
||||
@sprites["tile#{@tiles[i]}"].x += dist*distancePerFrame
|
||||
end
|
||||
pbUpdateSpriteHash(@sprites)
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
end
|
||||
end
|
||||
temp=[]
|
||||
for i in tiles; temp.push(@tiles[i]); end
|
||||
for i in 0...temp.length
|
||||
@tiles[tiles[(i+1)%(temp.length)]]=temp[i]
|
||||
end
|
||||
if anim
|
||||
update
|
||||
fadeTime.times do
|
||||
@sprites["tile#{@tiles[tiles[0]]}"].opacity+=fadeDiff
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
@sprites["cursor"].selected=false
|
||||
@sprites["cursor"].visible=true if !pbCheckWin
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbGrabTile(pos)
|
||||
@heldtile, @tiles[pos] = @tiles[pos], @heldtile
|
||||
@sprites["cursor"].holding=(@heldtile>=0)
|
||||
@sprites["cursor"].visible=false if pbCheckWin
|
||||
end
|
||||
|
||||
def pbCheckWin
|
||||
for i in 0...@boardwidth*@boardheight
|
||||
return false if @tiles[i]!=i
|
||||
return false if @angles[i]!=0
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbMain
|
||||
loop do
|
||||
update
|
||||
Graphics.update
|
||||
Input.update
|
||||
# Check end conditions
|
||||
if pbCheckWin
|
||||
@sprites["cursor"].visible=false
|
||||
if @game==3
|
||||
extratile=@sprites["tile#{@boardwidth*@boardheight-1}"]
|
||||
extratile.bitmap.clear
|
||||
extratile.bitmap.blt(0,0,@tilebitmap.bitmap,
|
||||
Rect.new(@tilewidth*(@boardwidth-1),@tileheight*(@boardheight-1),
|
||||
@tilewidth,@tileheight))
|
||||
extratile.opacity=0
|
||||
appearTime = Graphics.frame_rate*8/10
|
||||
opacityDiff = (255.0/appearTime).ceil
|
||||
appearTime.times do
|
||||
extratile.opacity += opacityDiff
|
||||
Graphics.update
|
||||
Input.update
|
||||
end
|
||||
else
|
||||
pbWait(Graphics.frame_rate/2)
|
||||
end
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
break if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
|
||||
end
|
||||
return true
|
||||
end
|
||||
# Input
|
||||
@sprites["cursor"].selected=(Input.press?(Input::USE) && @game>=3 && @game<=6)
|
||||
dir=0
|
||||
dir=2 if Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
|
||||
dir=4 if Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
|
||||
dir=6 if Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
|
||||
dir=8 if Input.trigger?(Input::UP) || Input.repeat?(Input::UP)
|
||||
if dir>0
|
||||
if @game==3 || (@game!=3 && @sprites["cursor"].selected)
|
||||
if pbCanMoveInDir?(@sprites["cursor"].position,dir,true)
|
||||
pbSEPlay("Tile Game cursor")
|
||||
pbSwapTiles(dir)
|
||||
end
|
||||
else
|
||||
if pbCanMoveInDir?(@sprites["cursor"].position,dir,false)
|
||||
pbSEPlay("Tile Game cursor")
|
||||
@sprites["cursor"].position=pbMoveCursor(@sprites["cursor"].position,dir)
|
||||
end
|
||||
end
|
||||
elsif (@game==1 || @game==2) && Input.trigger?(Input::USE)
|
||||
pbGrabTile(@sprites["cursor"].position)
|
||||
elsif (@game==2 && Input.trigger?(Input::ACTION)) ||
|
||||
(@game==5 && Input.trigger?(Input::ACTION)) ||
|
||||
(@game==7 && Input.trigger?(Input::USE))
|
||||
pbRotateTile(@sprites["cursor"].position)
|
||||
elsif Input.trigger?(Input::BACK)
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbEndScene
|
||||
pbFadeOutAndHide(@sprites)
|
||||
pbDisposeSpriteHash(@sprites)
|
||||
@viewport.dispose
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class TilePuzzle
|
||||
def initialize(scene)
|
||||
@scene=scene
|
||||
end
|
||||
|
||||
def pbStartScreen
|
||||
@scene.pbStartScene
|
||||
ret=@scene.pbMain
|
||||
@scene.pbEndScene
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def pbTilePuzzle(game,board,width=0,height=0)
|
||||
ret = false
|
||||
pbFadeOutIn {
|
||||
scene = TilePuzzleScene.new(game,board,width,height)
|
||||
screen = TilePuzzle.new(scene)
|
||||
ret = screen.pbStartScreen
|
||||
}
|
||||
return ret
|
||||
end
|
||||
Reference in New Issue
Block a user