Added decent spacing to all scripts thanks to Rubocop

This commit is contained in:
Maruno17
2021-12-18 15:25:40 +00:00
parent f7b76ae62e
commit d17fc40a47
207 changed files with 18577 additions and 18587 deletions

View File

@@ -419,7 +419,7 @@ 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)
pbGetMessageFromHash(MessageTypes::TrainerNames, trainer_name), trainer_id)
speech_texts = []
for i in 0...12
speech_texts.push(_I(speeches[i]))

View File

@@ -166,17 +166,17 @@ class TriadScene
@bitmaps = []
@battle = battle
# Allocate viewport
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
addBackgroundPlane(@sprites,"background","triad_bg",@viewport)
addBackgroundPlane(@sprites, "background", "triad_bg", @viewport)
@sprites["helpwindow"] = Window_AdvancedTextPokemon.newWithSize("",
0,Graphics.height-64,Graphics.width,64,@viewport)
for i in 0...@battle.width*@battle.height
0, Graphics.height - 64, Graphics.width, 64, @viewport)
for i in 0...@battle.width * @battle.height
@sprites["sprite#{i}"] = SpriteWrapper.new(@viewport)
@sprites["sprite#{i}"].x = Graphics.width/2 - 118 + (i%3)*78
@sprites["sprite#{i}"].y = 36 + (i/3)*94
@sprites["sprite#{i}"].x = Graphics.width / 2 - 118 + (i % 3) * 78
@sprites["sprite#{i}"].y = 36 + (i / 3) * 94
@sprites["sprite#{i}"].z = 2
bm = TriadCard.createBack(@battle.board[i].type,true)
bm = TriadCard.createBack(@battle.board[i].type, true)
@bitmaps.push(bm)
@sprites["sprite#{i}"].bitmap = bm
end
@@ -188,20 +188,20 @@ class TriadScene
@boardCards = []
for i in 0...@battle.maxCards
@sprites["player#{i}"] = Sprite.new(@viewport)
@sprites["player#{i}"].x = Graphics.width-92
@sprites["player#{i}"].y = 44+44*i
@sprites["player#{i}"].x = Graphics.width - 92
@sprites["player#{i}"].y = 44 + 44 * i
@sprites["player#{i}"].z = 2
@cardIndexes.push(i)
end
@sprites["overlay"] = Sprite.new(@viewport)
@sprites["overlay"].bitmap = BitmapWrapper.new(Graphics.width,Graphics.height)
@sprites["overlay"].bitmap = BitmapWrapper.new(Graphics.width, Graphics.height)
pbSetSystemFont(@sprites["overlay"].bitmap)
pbDrawTextPositions(@sprites["overlay"].bitmap,[
[@battle.opponentName,52,-2,2,Color.new(248,248,248),Color.new(96,96,96)],
[@battle.playerName,Graphics.width-52,-2,2,Color.new(248,248,248),Color.new(96,96,96)]
pbDrawTextPositions(@sprites["overlay"].bitmap, [
[@battle.opponentName, 52, -2, 2, Color.new(248, 248, 248), Color.new(96, 96, 96)],
[@battle.playerName, Graphics.width - 52, -2, 2, Color.new(248, 248, 248), Color.new(96, 96, 96)]
])
@sprites["score"] = Sprite.new(@viewport)
@sprites["score"].bitmap = BitmapWrapper.new(Graphics.width,Graphics.height)
@sprites["score"].bitmap = BitmapWrapper.new(Graphics.width, Graphics.height)
pbSetSystemFont(@sprites["score"].bitmap)
pbBGMPlay("Triple Triad")
# Fade in all sprites
@@ -230,7 +230,7 @@ class TriadScene
def pbDisplayPaused(text)
@sprites["helpwindow"].letterbyletter = true
@sprites["helpwindow"].text = text+"\1"
@sprites["helpwindow"].text = text + "\1"
loop do
Graphics.update
Input.update
@@ -248,7 +248,7 @@ class TriadScene
@sprites["helpwindow"].text = ""
end
def pbNotifyCards(playerCards,opponentCards)
def pbNotifyCards(playerCards, opponentCards)
@playerCards = playerCards
@opponentCards = opponentCards
end
@@ -259,17 +259,17 @@ class TriadScene
for item in cardStorage
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
end
command = Window_CommandPokemonEx.newWithSize(commands,0,0,Graphics.width/2,Graphics.height-64,@viewport)
@sprites["helpwindow"].text = _INTL("Choose {1} cards to use for this duel.",@battle.maxCards)
command = Window_CommandPokemonEx.newWithSize(commands, 0, 0, Graphics.width / 2, Graphics.height - 64, @viewport)
@sprites["helpwindow"].text = _INTL("Choose {1} cards to use for this duel.", @battle.maxCards)
preview = Sprite.new(@viewport)
preview.x = Graphics.width/2 + 20
preview.x = Graphics.width / 2 + 20
preview.y = 60
preview.z = 4
index = -1
for i in 0...@battle.maxCards
@sprites["player#{i}"] = Sprite.new(@viewport)
@sprites["player#{i}"].x = Graphics.width-92
@sprites["player#{i}"].y = 44+44*i
@sprites["player#{i}"].x = Graphics.width - 92
@sprites["player#{i}"].y = 44 + 44 * i
@sprites["player#{i}"].z = 2
end
loop do
@@ -277,18 +277,18 @@ class TriadScene
Input.update
pbUpdate
command.update
if command.index!=index
if command.index != index
preview.bitmap.dispose if preview.bitmap
if command.index<cardStorage.length
if command.index < cardStorage.length
item = cardStorage[command.index]
preview.bitmap = TriadCard.new(item[0]).createBitmap(1)
end
index = command.index
end
if Input.trigger?(Input::BACK)
if chosenCards.length>0
if chosenCards.length > 0
item = chosenCards.pop
@battle.pbAdd(cardStorage,item)
@battle.pbAdd(cardStorage, item)
commands = []
for item in cardStorage
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
@@ -299,9 +299,9 @@ class TriadScene
pbPlayBuzzerSE
end
elsif Input.trigger?(Input::USE)
break if chosenCards.length==@battle.maxCards
break if chosenCards.length == @battle.maxCards
item = cardStorage[command.index]
if !item || @battle.quantity(cardStorage,item[0])==0
if !item || @battle.quantity(cardStorage, item[0]) == 0
pbPlayBuzzerSE
else
pbPlayDecisionSE
@@ -310,27 +310,27 @@ class TriadScene
@cardBitmaps[chosenCards.length] = TriadCard.new(item[0]).createBitmap(1)
sprite.bitmap = @cardBitmaps[chosenCards.length]
chosenCards.push(item[0])
@battle.pbSubtract(cardStorage,item[0])
@battle.pbSubtract(cardStorage, item[0])
commands = []
for item in cardStorage
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
end
command.commands = commands
command.index = commands.length-1 if command.index>=commands.length
command.index = commands.length - 1 if command.index >= commands.length
index = -1
end
end
if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
for i in 0...@battle.maxCards
@sprites["player#{i}"].visible = (i<chosenCards.length)
@sprites["player#{i}"].visible = (i < chosenCards.length)
end
if chosenCards.length==@battle.maxCards
@sprites["helpwindow"].text = _INTL("{1} cards have been chosen.",@battle.maxCards)
if chosenCards.length == @battle.maxCards
@sprites["helpwindow"].text = _INTL("{1} cards have been chosen.", @battle.maxCards)
command.visible = false
command.active = false
preview.visible = false
else
@sprites["helpwindow"].text = _INTL("Choose {1} cards to use for this duel.",@battle.maxCards)
@sprites["helpwindow"].text = _INTL("Choose {1} cards to use for this duel.", @battle.maxCards)
command.visible = true
command.active = true
preview.visible = true
@@ -346,8 +346,8 @@ class TriadScene
def pbShowPlayerCards(cards)
for i in 0...@battle.maxCards
@sprites["player#{i}"] = Sprite.new(@viewport)
@sprites["player#{i}"].x = Graphics.width-92
@sprites["player#{i}"].y = 44+44*i
@sprites["player#{i}"].x = Graphics.width - 92
@sprites["player#{i}"].y = 44 + 44 * i
@sprites["player#{i}"].z = 2
@sprites["player#{i}"].bitmap = TriadCard.new(cards[i]).createBitmap(1)
@cardBitmaps.push(@sprites["player#{i}"].bitmap)
@@ -358,7 +358,7 @@ class TriadScene
for i in 0...@battle.maxCards
@sprites["opponent#{i}"] = Sprite.new(@viewport)
@sprites["opponent#{i}"].x = 12
@sprites["opponent#{i}"].y = 44+44*i
@sprites["opponent#{i}"].y = 44 + 44 * i
@sprites["opponent#{i}"].z = 2
@sprites["opponent#{i}"].bitmap = @battle.openHand ? TriadCard.new(cards[i]).createBitmap(2) : TriadCard.createBack
@opponentCardBitmaps.push(@sprites["opponent#{i}"].bitmap)
@@ -371,29 +371,29 @@ class TriadScene
choice = 0
lastChoice = -1
loop do
if lastChoice!=choice
if lastChoice != choice
y = 44
for i in 0...@opponentCardIndexes.length
@sprites["opponent#{@opponentCardIndexes[i]}"].bitmap = @opponentCardBitmaps[@opponentCardIndexes[i]]
@sprites["opponent#{@opponentCardIndexes[i]}"].x = (i==choice) ? 28 : 12
@sprites["opponent#{@opponentCardIndexes[i]}"].x = (i == choice) ? 28 : 12
@sprites["opponent#{@opponentCardIndexes[i]}"].y = y
@sprites["opponent#{@opponentCardIndexes[i]}"].z = 2
y += 44
end
lastChoice = choice
end
break if choice==-1
break if choice == -1
Graphics.update
Input.update
pbUpdate
if Input.repeat?(Input::DOWN)
pbPlayCursorSE
choice += 1
choice = 0 if choice>=numCards
choice = 0 if choice >= numCards
elsif Input.repeat?(Input::UP)
pbPlayCursorSE
choice -= 1
choice = numCards-1 if choice<0
choice = numCards - 1 if choice < 0
elsif Input.trigger?(Input::BACK)
pbPlayCancelSE
choice = -1
@@ -411,11 +411,11 @@ class TriadScene
choice = 0
lastChoice = -1
loop do
if lastChoice!=choice
if lastChoice != choice
y = 44
for i in 0...@cardIndexes.length
@sprites["player#{@cardIndexes[i]}"].bitmap = @cardBitmaps[@cardIndexes[i]]
@sprites["player#{@cardIndexes[i]}"].x = (i==choice) ? Graphics.width-108 : Graphics.width-92
@sprites["player#{@cardIndexes[i]}"].x = (i == choice) ? Graphics.width - 108 : Graphics.width - 92
@sprites["player#{@cardIndexes[i]}"].y = y
@sprites["player#{@cardIndexes[i]}"].z = 2
y += 44
@@ -428,11 +428,11 @@ class TriadScene
if Input.repeat?(Input::DOWN)
pbPlayCursorSE
choice += 1
choice = 0 if choice>=numCards
choice = 0 if choice >= numCards
elsif Input.repeat?(Input::UP)
pbPlayCursorSE
choice -= 1
choice = numCards-1 if choice<0
choice = numCards - 1 if choice < 0
elsif Input.trigger?(Input::USE)
pbPlayDecisionSE
break
@@ -456,12 +456,12 @@ class TriadScene
if doRefresh
y = 44
for i in 0...@cardIndexes.length
if i==cardIndex # Card being placed
@sprites["player#{@cardIndexes[i]}"].x = Graphics.width/2 - 118 + boardX*78
@sprites["player#{@cardIndexes[i]}"].y = 36 + boardY*94
if i == cardIndex # Card being placed
@sprites["player#{@cardIndexes[i]}"].x = Graphics.width / 2 - 118 + boardX * 78
@sprites["player#{@cardIndexes[i]}"].y = 36 + boardY * 94
@sprites["player#{@cardIndexes[i]}"].z = 4
else # Other cards in hand
@sprites["player#{@cardIndexes[i]}"].x = Graphics.width-92
@sprites["player#{@cardIndexes[i]}"].x = Graphics.width - 92
@sprites["player#{@cardIndexes[i]}"].y = y
@sprites["player#{@cardIndexes[i]}"].z = 2
y += 44
@@ -475,27 +475,27 @@ class TriadScene
if Input.repeat?(Input::DOWN)
pbPlayCursorSE
boardY += 1
boardY = 0 if boardY>=@battle.height
boardY = 0 if boardY >= @battle.height
doRefresh = true
elsif Input.repeat?(Input::UP)
pbPlayCursorSE
boardY -= 1
boardY = @battle.height-1 if boardY<0
boardY = @battle.height - 1 if boardY < 0
doRefresh = true
elsif Input.repeat?(Input::LEFT)
pbPlayCursorSE
boardX -= 1
boardX = @battle.width-1 if boardX<0
boardX = @battle.width - 1 if boardX < 0
doRefresh = true
elsif Input.repeat?(Input::RIGHT)
pbPlayCursorSE
boardX += 1
boardX = 0 if boardX>=@battle.width
boardX = 0 if boardX >= @battle.width
doRefresh = true
elsif Input.trigger?(Input::BACK)
return nil
elsif Input.trigger?(Input::USE)
if @battle.isOccupied?(boardX,boardY)
if @battle.isOccupied?(boardX, boardY)
pbPlayBuzzerSE
else
pbPlayDecisionSE
@@ -504,12 +504,12 @@ class TriadScene
end
end
end
return [boardX,boardY]
return [boardX, boardY]
end
def pbEndPlaceCard(position, cardIndex)
spriteIndex = @cardIndexes[cardIndex]
boardIndex = position[1]*@battle.width+position[0]
boardIndex = position[1] * @battle.width + position[0]
@boardSprites[boardIndex] = @sprites["player#{spriteIndex}"]
@boardCards[boardIndex] = TriadCard.new(@playerCards[spriteIndex])
pbRefresh
@@ -521,12 +521,12 @@ class TriadScene
y = 44
for i in 0...@opponentCardIndexes.length
sprite = @sprites["opponent#{@opponentCardIndexes[i]}"]
if i==cardIndex
if i == cardIndex
@opponentCardBitmaps[@opponentCardIndexes[i]] = triadCard.createBitmap(2)
sprite.bitmap.dispose if sprite.bitmap
sprite.bitmap = @opponentCardBitmaps[@opponentCardIndexes[i]]
sprite.x = Graphics.width/2 - 118 + position[0]*78
sprite.y = 36 + position[1]*94
sprite.x = Graphics.width / 2 - 118 + position[0] * 78
sprite.y = 36 + position[1] * 94
sprite.z = 2
else
sprite.x = 12
@@ -539,7 +539,7 @@ class TriadScene
def pbEndOpponentPlaceCard(position, cardIndex)
spriteIndex = @opponentCardIndexes[cardIndex]
boardIndex = position[1]*@battle.width+position[0]
boardIndex = position[1] * @battle.width + position[0]
@boardSprites[boardIndex] = @sprites["opponent#{spriteIndex}"]
@boardCards[boardIndex] = TriadCard.new(@opponentCards[spriteIndex])
pbRefresh
@@ -548,11 +548,11 @@ class TriadScene
end
def pbRefresh
for i in 0...@battle.width*@battle.height
x = i%@battle.width
y = i/@battle.width
for i in 0...@battle.width * @battle.height
x = i % @battle.width
y = i / @battle.width
if @boardSprites[i]
owner = @battle.getOwner(x,y)
owner = @battle.getOwner(x, y)
@boardSprites[i].bitmap.dispose if @boardSprites[i].bitmap
@boardSprites[i].bitmap = @boardCards[i].createBitmap(owner)
end
@@ -564,18 +564,18 @@ class TriadScene
bitmap.clear
playerscore = 0
oppscore = 0
for i in 0...@battle.width*@battle.height
for i in 0...@battle.width * @battle.height
if @boardSprites[i]
playerscore += 1 if @battle.board[i].owner==1
oppscore += 1 if @battle.board[i].owner==2
playerscore += 1 if @battle.board[i].owner == 1
oppscore += 1 if @battle.board[i].owner == 2
end
end
if @battle.countUnplayedCards
playerscore += @cardIndexes.length
oppscore += @opponentCardIndexes.length
end
pbDrawTextPositions(bitmap,[
[_INTL("{1}-{2}",oppscore,playerscore),Graphics.width/2,-2,2,Color.new(248,248,248),Color.new(96,96,96)]
pbDrawTextPositions(bitmap, [
[_INTL("{1}-{2}", oppscore, playerscore), Graphics.width / 2, -2, 2, Color.new(248, 248, 248), Color.new(96, 96, 96)]
])
end
@@ -610,32 +610,32 @@ class TriadScreen
end
def maxCards
numcards = @width*@height
if numcards%2 == 1
numcards = numcards/2+1
numcards = @width * @height
if numcards % 2 == 1
numcards = numcards / 2 + 1
else
numcards = numcards/2
numcards = numcards / 2
end
return numcards
end
def isOccupied?(x,y)
return @board[y*@width+x].owner!=0
def isOccupied?(x, y)
return @board[y * @width + x].owner != 0
end
def getOwner(x,y)
return @board[y*@width+x].owner
def getOwner(x, y)
return @board[y * @width + x].owner
end
def getPanel(x,y)
return @board[y*@width+x]
def getPanel(x, y)
return @board[y * @width + x]
end
def quantity(items,item)
def quantity(items, item)
return ItemStorageHelper.quantity(items, item)
end
def pbAdd(items,item)
def pbAdd(items, item)
return ItemStorageHelper.add(items, $PokemonGlobal.triads.maxSize,
TriadStorage::MAX_PER_SLOT, item, 1)
end
@@ -644,28 +644,28 @@ class TriadScreen
return ItemStorageHelper.remove(items, item, 1)
end
def flipBoard(x,y,attackerParam = nil,recurse = false)
panels = [x-1,y,x+1,y,x,y-1,x,y+1]
panels[0] = (@wrapAround ? @width-1 : 0) if panels[0]<0 # left
panels[2] = (@wrapAround ? 0 : @width-1) if panels[2]>@width-1 # right
panels[5] = (@wrapAround ? @height-1 : 0) if panels[5]<0 # top
panels[7] = (@wrapAround ? 0 : @height-1) if panels[7]>@height-1 # bottom
attacker = attackerParam!=nil ? attackerParam : @board[y*@width+x]
def flipBoard(x, y, attackerParam = nil, recurse = false)
panels = [x - 1, y, x + 1, y, x, y - 1, x, y + 1]
panels[0] = (@wrapAround ? @width - 1 : 0) if panels[0] < 0 # left
panels[2] = (@wrapAround ? 0 : @width - 1) if panels[2] > @width - 1 # right
panels[5] = (@wrapAround ? @height - 1 : 0) if panels[5] < 0 # top
panels[7] = (@wrapAround ? 0 : @height - 1) if panels[7] > @height - 1 # bottom
attacker = attackerParam != nil ? attackerParam : @board[y * @width + x]
flips = []
return nil if attackerParam!=nil && @board[y*@width+x].owner!=0
return nil if !attacker.card || attacker.owner==0
return nil if attackerParam != nil && @board[y * @width + x].owner != 0
return nil if !attacker.card || attacker.owner == 0
for i in 0...4
defenderX = panels[i*2]
defenderY = panels[i*2+1]
defender = @board[defenderY*@width+defenderX]
defenderX = panels[i * 2]
defenderY = panels[i * 2 + 1]
defender = @board[defenderY * @width + defenderX]
next if !defender.card
if attacker.owner!=defender.owner
if attacker.owner != defender.owner
attack = attacker.attack(i)
defense = defender.defense(i)
if @elements
# If attacker's type matches the tile's element, add
# a bonus of 1 (only for original attacker, not combos)
attack += 1 if !recurse && attacker.type==attacker.card.type
attack += 1 if !recurse && attacker.type == attacker.card.type
else
# Modifier depends on opponent's Pokémon type:
# +1 - Super effective
@@ -673,19 +673,19 @@ class TriadScreen
# -2 - Immune
# attack += attacker.bonus(defender)
end
if attack>defense || (attack==defense && @sameWins)
flips.push([defenderX,defenderY])
if attackerParam==nil
if attack > defense || (attack == defense && @sameWins)
flips.push([defenderX, defenderY])
if attackerParam == nil
defender.owner = attacker.owner
if @sameWins
# Combo with the "sameWins" rule
ret = flipBoard(defenderX,defenderY,nil,true)
ret = flipBoard(defenderX, defenderY, nil, true)
flips.concat(ret) if ret
end
else
if @sameWins
# Combo with the "sameWins" rule
ret = flipBoard(defenderX,defenderY,attackerParam,true)
ret = flipBoard(defenderX, defenderY, attackerParam, true)
flips.concat(ret) if ret
end
end
@@ -697,21 +697,21 @@ class TriadScreen
# If pbStartScreen includes parameters, it should
# pass the parameters to pbStartScene.
def pbStartScreen(opponentName,minLevel,maxLevel,rules = nil,oppdeck = nil,prize = nil)
raise _INTL("Minimum level must be 0 through 9.") if minLevel<0 || minLevel>9
raise _INTL("Maximum level must be 0 through 9.") if maxLevel<0 || maxLevel>9
raise _INTL("Maximum level shouldn't be less than the minimum level.") if maxLevel<minLevel
if rules && rules.is_a?(Array) && rules.length>0
def pbStartScreen(opponentName, minLevel, maxLevel, rules = nil, oppdeck = nil, prize = nil)
raise _INTL("Minimum level must be 0 through 9.") if minLevel < 0 || minLevel > 9
raise _INTL("Maximum level must be 0 through 9.") if maxLevel < 0 || maxLevel > 9
raise _INTL("Maximum level shouldn't be less than the minimum level.") if maxLevel < minLevel
if rules && rules.is_a?(Array) && rules.length > 0
for rule in rules
@sameWins = true if rule=="samewins"
@openHand = true if rule=="openhand"
@wrapAround = true if rule=="wrap"
@elements = true if rule=="elements"
@randomHand = true if rule=="randomhand"
@countUnplayedCards = true if rule=="countunplayed"
@trade = 1 if rule=="direct"
@trade = 2 if rule=="winall"
@trade = 3 if rule=="noprize"
@sameWins = true if rule == "samewins"
@openHand = true if rule == "openhand"
@wrapAround = true if rule == "wrap"
@elements = true if rule == "elements"
@randomHand = true if rule == "randomhand"
@countUnplayedCards = true if rule == "countunplayed"
@trade = 1 if rule == "direct"
@trade = 2 if rule == "winall"
@trade = 3 if rule == "noprize"
end
end
@triadCards = []
@@ -726,7 +726,7 @@ class TriadScreen
@playerName = $player ? $player.name : "Trainer"
@opponentName = opponentName
type_keys = GameData::Type.keys
for i in 0...@width*@height
for i in 0...@width * @height
square = TriadSquare.new
if @elements
loop do
@@ -741,7 +741,7 @@ class TriadScreen
end
@scene.pbStartScene(self) # (param1, param2)
# Check whether there are enough cards.
if count<self.maxCards
if count < self.maxCards
@scene.pbDisplayPaused(_INTL("You don't have enough cards."))
@scene.pbEndScene
return 0
@@ -751,7 +751,7 @@ class TriadScreen
if @randomHand # Determine hand at random
self.maxCards.times do
randCard = @triadCards[rand(@triadCards.length)]
pbSubtract(@triadCards,randCard[0])
pbSubtract(@triadCards, randCard[0])
cards.push(randCard[0])
end
@scene.pbShowPlayerCards(cards)
@@ -759,12 +759,12 @@ class TriadScreen
cards = @scene.pbChooseTriadCard(@triadCards)
end
# Set the opponent's cards.
if oppdeck && oppdeck.is_a?(Array) && oppdeck.length==self.maxCards # Preset
if oppdeck && oppdeck.is_a?(Array) && oppdeck.length == self.maxCards # Preset
opponentCards = []
for i in oppdeck
species_data = GameData::Species.try_get(i)
if !species_data
@scene.pbDisplayPaused(_INTL("Opponent has an illegal card, \"{1}\".",i))
@scene.pbDisplayPaused(_INTL("Opponent has an illegal card, \"{1}\".", i))
@scene.pbEndScene
return 0
end
@@ -787,7 +787,7 @@ class TriadScreen
end
end
# sort by total point count
candidates.sort! { |a,b| a[1] <=> b[1] }
candidates.sort! { |a, b| a[1] <=> b[1] }
opponentCards = []
self.maxCards.times do
# Choose random card from candidates based on trainer's level
@@ -797,13 +797,13 @@ class TriadScreen
end
originalCards = cards.clone
originalOpponentCards = opponentCards.clone
@scene.pbNotifyCards(cards.clone,opponentCards.clone)
@scene.pbNotifyCards(cards.clone, opponentCards.clone)
@scene.pbShowOpponentCards(opponentCards)
@scene.pbDisplay(_INTL("Choosing the starting player..."))
@scene.pbUpdateScore
playerTurn = (rand(2) == 0)
@scene.pbDisplay(_INTL("{1} will go first.", (playerTurn) ? @playerName : @opponentName))
for i in 0...@width*@height
for i in 0...@width * @height
position = nil
triadCard = nil
cardIndex = 0
@@ -816,65 +816,65 @@ class TriadScreen
end
else
# Opponent's turn
@scene.pbDisplay(_INTL("{1} is making a move...",@opponentName))
@scene.pbDisplay(_INTL("{1} is making a move...", @opponentName))
scores = []
for cardIndex in 0...opponentCards.length
square = TriadSquare.new
square.card = TriadCard.new(opponentCards[cardIndex])
square.owner = 2
for i in 0...@width*@height
for i in 0...@width * @height
x = i % @width
y = i / @width
square.type = @board[i].type
flips = flipBoard(x,y,square)
if flips!=nil
scores.push([cardIndex,x,y,flips.length])
flips = flipBoard(x, y, square)
if flips != nil
scores.push([cardIndex, x, y, flips.length])
end
end
end
# Sort by number of flips
scores.sort! { |a,b| (b[3]==a[3]) ? rand(3)-1 : b[3]<=>a[3] }
scores = scores[0,opponentCards.length] # Get the best results
if scores.length==0
@scene.pbDisplay(_INTL("{1} can't move somehow...",@opponentName))
scores.sort! { |a, b| (b[3] == a[3]) ? rand(3) - 1 : b[3] <=> a[3] }
scores = scores[0, opponentCards.length] # Get the best results
if scores.length == 0
@scene.pbDisplay(_INTL("{1} can't move somehow...", @opponentName))
playerTurn = !playerTurn
continue
end
result = scores[rand(scores.length)]
cardIndex = result[0]
triadCard = TriadCard.new(opponentCards[cardIndex])
position = [result[1],result[2]]
@scene.pbOpponentPlaceCard(triadCard,position,cardIndex)
position = [result[1], result[2]]
@scene.pbOpponentPlaceCard(triadCard, position, cardIndex)
end
boardIndex = position[1]*@width+position[0]
boardIndex = position[1] * @width + position[0]
board[boardIndex].card = triadCard
board[boardIndex].owner = playerTurn ? 1 : 2
flipBoard(position[0],position[1])
flipBoard(position[0], position[1])
if playerTurn
cards.delete_at(cardIndex)
@scene.pbEndPlaceCard(position,cardIndex)
@scene.pbEndPlaceCard(position, cardIndex)
else
opponentCards.delete_at(cardIndex)
@scene.pbEndOpponentPlaceCard(position,cardIndex)
@scene.pbEndOpponentPlaceCard(position, cardIndex)
end
playerTurn = !playerTurn
end
# Determine the winner
playerCount = 0
opponentCount = 0
for i in 0...@width*@height
playerCount += 1 if board[i].owner==1
opponentCount += 1 if board[i].owner==2
for i in 0...@width * @height
playerCount += 1 if board[i].owner == 1
opponentCount += 1 if board[i].owner == 2
end
if @countUnplayedCards
playerCount += cards.length
opponentCount += opponentCards.length
end
result = 0
if playerCount==opponentCount
if playerCount == opponentCount
@scene.pbDisplayPaused(_INTL("The game is a draw."))
result = 3
if @trade==1
if @trade == 1
# Keep only cards of your color
for card in originalCards
$PokemonGlobal.triads.remove(card)
@@ -882,16 +882,16 @@ class TriadScreen
for i in cards
$PokemonGlobal.triads.add(i)
end
for i in 0...@width*@height
if board[i].owner==1
for i in 0...@width * @height
if board[i].owner == 1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.add(card)
end
end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color."))
end
elsif playerCount>opponentCount
@scene.pbDisplayPaused(_INTL("{1} won against {2}.",@playerName,@opponentName))
elsif playerCount > opponentCount
@scene.pbDisplayPaused(_INTL("{1} won against {2}.", @playerName, @opponentName))
result = 1
if prize
species_data = GameData::Species.try_get(prize)
@@ -904,7 +904,7 @@ class TriadScreen
card = originalOpponentCards[rand(originalOpponentCards.length)]
if $PokemonGlobal.triads.add(card)
cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.", cardname))
end
when 1 # Keep only cards of your color
for card in originalCards
@@ -913,8 +913,8 @@ class TriadScreen
for i in cards
$PokemonGlobal.triads.add(i)
end
for i in 0...@width*@height
if board[i].owner==1
for i in 0...@width * @height
if board[i].owner == 1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.add(card)
end
@@ -928,14 +928,14 @@ class TriadScreen
end
end
else
@scene.pbDisplayPaused(_INTL("{1} lost against {2}.",@playerName,@opponentName))
@scene.pbDisplayPaused(_INTL("{1} lost against {2}.", @playerName, @opponentName))
result = 2
case @trade
when 0 # Lose 1 random card from your deck
card = originalCards[rand(originalCards.length)]
$PokemonGlobal.triads.remove(card)
cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Opponent won your {1} card.",cardname))
@scene.pbDisplayPaused(_INTL("Opponent won your {1} card.", cardname))
when 1 # Keep only cards of your color
for card in originalCards
$PokemonGlobal.triads.remove(card)
@@ -943,13 +943,13 @@ class TriadScreen
for i in cards
$PokemonGlobal.triads.add(i)
end
for i in 0...@width*@height
if board[i].owner==1
for i in 0...@width * @height
if board[i].owner == 1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.add(card)
end
end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.",cardname))
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.", cardname))
when 2 # Lose all your cards
for card in originalCards
$PokemonGlobal.triads.remove(card)
@@ -967,12 +967,12 @@ end
#===============================================================================
# Start duel
#===============================================================================
def pbTriadDuel(name,minLevel,maxLevel,rules = nil,oppdeck = nil,prize = nil)
def pbTriadDuel(name, minLevel, maxLevel, rules = nil, oppdeck = nil, prize = nil)
ret = 0
pbFadeOutInWithMusic {
scene = TriadScene.new
screen = TriadScreen.new(scene)
ret = screen.pbStartScreen(name,minLevel,maxLevel,rules,oppdeck,prize)
ret = screen.pbStartScreen(name, minLevel, maxLevel, rules, oppdeck, prize)
}
return ret
end
@@ -1072,18 +1072,18 @@ def pbBuyTriads
realcommands.push(command[2])
end
# Scroll right before showing screen
pbScrollMap(4,3,5)
cmdwindow = Window_CommandPokemonEx.newWithSize(realcommands,0,0,Graphics.width/2,Graphics.height)
pbScrollMap(4, 3, 5)
cmdwindow = Window_CommandPokemonEx.newWithSize(realcommands, 0, 0, Graphics.width / 2, Graphics.height)
cmdwindow.z = 99999
goldwindow = Window_UnformattedTextPokemon.newWithSize(
_INTL("Money:\r\n{1}",pbGetGoldString),0,0,32,32)
goldwindow.resizeToFit(goldwindow.text,Graphics.width)
goldwindow.x = Graphics.width-goldwindow.width
_INTL("Money:\r\n{1}", pbGetGoldString), 0, 0, 32, 32)
goldwindow.resizeToFit(goldwindow.text, Graphics.width)
goldwindow.x = Graphics.width - goldwindow.width
goldwindow.y = 0
goldwindow.z = 99999
preview = Sprite.new
preview.x = Graphics.width*3/4-40
preview.y = Graphics.height/2-48
preview.x = Graphics.width * 3 / 4 - 40
preview.y = Graphics.height / 2 - 48
preview.z = 4
preview.bitmap = TriadCard.new(commands[cmdwindow.index][3]).createBitmap(1)
olditem = commands[cmdwindow.index][3]
@@ -1094,7 +1094,7 @@ def pbBuyTriads
cmdwindow.active = true
cmdwindow.update
goldwindow.update
if commands[cmdwindow.index][3]!=olditem
if commands[cmdwindow.index][3] != olditem
preview.bitmap.dispose if preview.bitmap
preview.bitmap = TriadCard.new(commands[cmdwindow.index][3]).createBitmap(1)
olditem = commands[cmdwindow.index][3]
@@ -1107,22 +1107,22 @@ def pbBuyTriads
itemname = commands[cmdwindow.index][1]
cmdwindow.active = false
cmdwindow.update
if $player.money<price
if $player.money < price
pbMessage(_INTL("You don't have enough money."))
next
end
maxafford = (price<=0) ? 99 : $player.money/price
maxafford = 99 if maxafford>99
maxafford = (price <= 0) ? 99 : $player.money / price
maxafford = 99 if maxafford > 99
params = ChooseNumberParams.new
params.setRange(1,maxafford)
params.setRange(1, maxafford)
params.setInitialValue(1)
params.setCancelValue(0)
quantity = pbMessageChooseNumber(
_INTL("The {1} card? Certainly. How many would you like?",itemname),params)
next if quantity<=0
_INTL("The {1} card? Certainly. How many would you like?", itemname), params)
next if quantity <= 0
price *= quantity
next if !pbConfirmMessage(_INTL("{1}, and you want {2}. That will be ${3}. OK?",itemname,quantity,price.to_s_formatted))
if $player.money<price
next if !pbConfirmMessage(_INTL("{1}, and you want {2}. That will be ${3}. OK?", itemname, quantity, price.to_s_formatted))
if $player.money < price
pbMessage(_INTL("You don't have enough money."))
next
end
@@ -1132,7 +1132,7 @@ def pbBuyTriads
end
$PokemonGlobal.triads.add(item, quantity)
$player.money -= price
goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString)
goldwindow.text = _INTL("Money:\r\n{1}", pbGetGoldString)
pbMessage(_INTL("Here you are! Thank you!\\se[Mart buy item]"))
end
end
@@ -1142,7 +1142,7 @@ def pbBuyTriads
preview.dispose
Graphics.frame_reset
# Scroll right before showing screen
pbScrollMap(6,3,5)
pbScrollMap(6, 3, 5)
end
def pbSellTriads
@@ -1153,23 +1153,23 @@ def pbSellTriads
commands.push(_INTL("{1} x{2}", speciesname, item[1]))
end
commands.push(_INTL("CANCEL"))
if commands.length==1
if commands.length == 1
pbMessage(_INTL("You have no cards."))
return
end
# Scroll right before showing screen
pbScrollMap(4,3,5)
cmdwindow = Window_CommandPokemonEx.newWithSize(commands,0,0,Graphics.width/2,Graphics.height)
pbScrollMap(4, 3, 5)
cmdwindow = Window_CommandPokemonEx.newWithSize(commands, 0, 0, Graphics.width / 2, Graphics.height)
cmdwindow.z = 99999
goldwindow = Window_UnformattedTextPokemon.newWithSize(
_INTL("Money:\r\n{1}",pbGetGoldString),0,0,32,32)
goldwindow.resizeToFit(goldwindow.text,Graphics.width)
goldwindow.x = Graphics.width-goldwindow.width
_INTL("Money:\r\n{1}", pbGetGoldString), 0, 0, 32, 32)
goldwindow.resizeToFit(goldwindow.text, Graphics.width)
goldwindow.x = Graphics.width - goldwindow.width
goldwindow.y = 0
goldwindow.z = 99999
preview = Sprite.new
preview.x = Graphics.width*3/4-40
preview.y = Graphics.height/2-48
preview.x = Graphics.width * 3 / 4 - 40
preview.y = Graphics.height / 2 - 48
preview.z = 4
item = $PokemonGlobal.triads.get_item(cmdwindow.index)
preview.bitmap = TriadCard.new(item).createBitmap(1)
@@ -1196,7 +1196,7 @@ def pbSellTriads
break
end
if Input.trigger?(Input::USE)
if cmdwindow.index>=$PokemonGlobal.triads.length
if cmdwindow.index >= $PokemonGlobal.triads.length
done = true
break
end
@@ -1204,33 +1204,33 @@ def pbSellTriads
itemname = GameData::Species.get(item).name
quantity = $PokemonGlobal.triads.quantity(item)
price = TriadCard.new(item).price
if price==0
pbDisplayPaused(_INTL("The {1} card? Oh, no. I can't buy that.",itemname))
if price == 0
pbDisplayPaused(_INTL("The {1} card? Oh, no. I can't buy that.", itemname))
break
end
cmdwindow.active = false
cmdwindow.update
if quantity>1
if quantity > 1
params = ChooseNumberParams.new
params.setRange(1,quantity)
params.setRange(1, quantity)
params.setInitialValue(1)
params.setCancelValue(0)
quantity = pbMessageChooseNumber(
_INTL("The {1} card? How many would you like to sell?",itemname),params)
_INTL("The {1} card? How many would you like to sell?", itemname), params)
end
if quantity>0
if quantity > 0
price /= 4
price *= quantity
if pbConfirmMessage(_INTL("I can pay ${1}. Would that be OK?",price.to_s_formatted))
if pbConfirmMessage(_INTL("I can pay ${1}. Would that be OK?", price.to_s_formatted))
$player.money += price
goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString)
$PokemonGlobal.triads.remove(item,quantity)
pbMessage(_INTL("Turned over the {1} card and received ${2}.\\se[Mart buy item]",itemname,price.to_s_formatted))
goldwindow.text = _INTL("Money:\r\n{1}", pbGetGoldString)
$PokemonGlobal.triads.remove(item, quantity)
pbMessage(_INTL("Turned over the {1} card and received ${2}.\\se[Mart buy item]", itemname, price.to_s_formatted))
commands = []
for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i]
speciesname = GameData::Species.get(item[0]).name
commands.push(_INTL("{1} x{2}",speciesname,item[1]))
commands.push(_INTL("{1} x{2}", speciesname, item[1]))
end
commands.push(_INTL("CANCEL"))
cmdwindow.commands = commands
@@ -1246,7 +1246,7 @@ def pbSellTriads
preview.dispose
Graphics.frame_reset
# Scroll right before showing screen
pbScrollMap(6,3,5)
pbScrollMap(6, 3, 5)
end
def pbTriadList
@@ -1254,17 +1254,17 @@ def pbTriadList
for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i]
speciesname = GameData::Species.get(item[0]).name
commands.push(_INTL("{1} x{2}",speciesname,item[1]))
commands.push(_INTL("{1} x{2}", speciesname, item[1]))
end
commands.push(_INTL("CANCEL"))
if commands.length==1
if commands.length == 1
pbMessage(_INTL("You have no cards."))
return
end
cmdwindow = Window_CommandPokemonEx.newWithSize(commands,0,0,Graphics.width/2,Graphics.height)
cmdwindow = Window_CommandPokemonEx.newWithSize(commands, 0, 0, Graphics.width / 2, Graphics.height)
cmdwindow.z = 99999
sprite = Sprite.new
sprite.x = Graphics.width/2+40
sprite.x = Graphics.width / 2 + 40
sprite.y = 48
sprite.z = 99999
done = false
@@ -1274,9 +1274,9 @@ def pbTriadList
Graphics.update
Input.update
cmdwindow.update
if lastIndex!=cmdwindow.index
if lastIndex != cmdwindow.index
sprite.bitmap.dispose if sprite.bitmap
if cmdwindow.index<$PokemonGlobal.triads.length
if cmdwindow.index < $PokemonGlobal.triads.length
sprite.bitmap = TriadCard.new($PokemonGlobal.triads.get_item(cmdwindow.index)).createBitmap(1)
end
lastIndex = cmdwindow.index
@@ -1286,7 +1286,7 @@ def pbTriadList
break
end
if Input.trigger?(Input::USE)
if cmdwindow.index>=$PokemonGlobal.triads.length
if cmdwindow.index >= $PokemonGlobal.triads.length
done = true
break
end

View File

@@ -13,45 +13,45 @@ class SlotMachineReel < BitmapSprite
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]
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=[]
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"))
@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
@spinning = true
end
def stopSpinning(noslipping = false)
@stopping=true
@slipping=SLIPPING[rand(SLIPPING.length)]
@slipping=0 if noslipping
@stopping = true
@slipping = SLIPPING[rand(SLIPPING.length)]
@slipping = 0 if noslipping
end
def showing
array=[]
array = []
for i in 0...3
num=@index-i
num+=@reel.length if num<0
num = @index - i
num += @reel.length if num < 0
array.push(@reel[num])
end
return array # [0] = top, [1] = middle, [2] = bottom
@@ -59,23 +59,23 @@ class SlotMachineReel < BitmapSprite
def update
self.bitmap.clear
if @toppos==0 && @stopping && @slipping==0
@spinning=@stopping=false
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
@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))
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))
self.bitmap.blt(0, 0, @shading.bitmap, Rect.new(0, 0, 64, 144))
end
end
@@ -84,12 +84,12 @@ 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
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)
@@ -101,8 +101,8 @@ class SlotMachineScore < BitmapSprite
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))
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
@@ -120,92 +120,92 @@ class SlotMachineScene
end
def pbPayout
@replay=false
payout=0
bonus=0
wonRow=[]
@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
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
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
when [1, 1, 1] # Three Magnemites
payout += 8
when [2,2,2] # Three Shellders
when [2, 2, 2] # Three Shellders
payout += 8
when [3,3,3] # Three Pikachus
when [3, 3, 3] # Three Pikachus
payout += 15
when [4,4,4] # Three Psyducks
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
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
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
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
if combinations[i][0] == 0 # Left cherry
if combinations[i][1] == 0 # Centre cherry as well
payout += 4
else
payout+=2
payout += 2
end
else
wonRow[i]=false
wonRow[i] = false
end
end
end
@sprites["payout"].score=payout
frame=0
if payout>0 || @replay
if bonus>0
@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
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["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)
@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)
@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
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)
@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
break if @sprites["payout"].score <= 0
Graphics.update
Input.update
update
@@ -216,21 +216,21 @@ class SlotMachineScene
@sprites["payout"].score = 0
end
end
(Graphics.frame_rate/2).times do
(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
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)
@sprites["window1"].src_rect.set(152 * ((frame / timePerFrame) % 2), 0, 152, 208)
frame += 1
end
end
@@ -238,47 +238,47 @@ class SlotMachineScene
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)
@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}"] = IconSprite.new(68 + 80 * (i - 1), 260, @viewport)
@sprites["button#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/button"))
@sprites["button#{i}"].visible=false
@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)
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
1 + i / 2, (i >= 4) ? ((i == 4) ? "a" : "b") : ""))
@sprites["row#{i}"].visible = false
end
@sprites["light1"]=IconSprite.new(16,32,@viewport)
@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["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["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,$player.coins)
@sprites["payout"]=SlotMachineScore.new(438,66,0)
@wager=0
@sprites["window1"].src_rect.set(0, 0, 152, 208)
@sprites["window2"] = IconSprite.new(358, 96, @viewport)
@sprites["credit"] = SlotMachineScore.new(360, 66, $player.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
frame = 0
spinFrameTime = Graphics.frame_rate / 4
insertFrameTime = Graphics.frame_rate * 4 / 10
loop do
Graphics.update
Input.update
@@ -288,77 +288,77 @@ class SlotMachineScene
if @sprites["credit"].score == Settings::MAX_COINS
pbMessage(_INTL("You've got {1} Coins.", Settings::MAX_COINS.to_s_formatted))
break
elsif $player.coins==0
elsif $player.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)
@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
@sprites["button1"].visible = true
elsif @sprites["reel2"].spinning
@sprites["reel2"].stopSpinning(@replay)
@sprites["button2"].visible=true
@sprites["button2"].visible = true
elsif @sprites["reel3"].spinning
@sprites["reel3"].stopSpinning(@replay)
@sprites["button3"].visible=true
@sprites["button3"].visible = true
end
end
if !@sprites["reel3"].spinning
@gameEnd=true
@gameRunning=false
@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
@sprites["button1"].visible = false
@sprites["button2"].visible = false
@sprites["button3"].visible = false
for i in 1..5
@sprites["row#{i}"].visible=false
@sprites["row#{i}"].visible = false
end
@gameEnd=false
@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["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)
@sprites["window2"].src_rect.set(152 * ((frame / insertFrameTime) % 2), 0, 152, 208)
end
if Input.trigger?(Input::DOWN) && @wager<3 && @sprites["credit"].score>0
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
@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
elsif @wager >= 3 || (@wager > 0 && @sprites["credit"].score == 0) ||
(Input.trigger?(Input::USE) && @wager > 0) || @replay
if @replay
@wager=3
@wager = 3
for i in 1..5
@sprites["row#{i}"].visible=true
@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
frame = 0
@gameRunning = true
elsif Input.trigger?(Input::BACK) && @wager == 0
break
end
end
frame = (frame+1)%(Graphics.frame_rate*4)
frame = (frame + 1) % (Graphics.frame_rate * 4)
end
old_coins = $player.coins
$player.coins = @sprites["credit"].score
@@ -380,7 +380,7 @@ end
class SlotMachine
def initialize(scene)
@scene=scene
@scene = scene
end
def pbStartScreen(difficulty)

View File

@@ -11,341 +11,341 @@ class VoltorbFlip
def pbStart
# Set initial level
@level=1
@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
@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]
@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
@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
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
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]
elsif total < @levelRanges[@level - 1][1]
squareValues[i] = rand(2) + 2
total *= squareValues[i]
end
if total>(@levelRanges[@level-1][1])
if total > (@levelRanges[@level - 1][1])
# Lowers value of square to 1 if over max
total/=squareValues[i]
squareValues[i]=1
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]
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]
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]
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)
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)
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)
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
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
break if @sprites["curtainL"].angle <= -180
end
end
@sprites["curtainL"].visible=false
@sprites["curtainR"].visible=false
@sprites["curtain"].opacity=100
@sprites["curtainL"].visible = false
@sprites["curtainR"].visible = false
@sprites["curtain"].opacity = 100
if $player.coins >= Settings::MAX_COINS
pbMessage(_INTL("You've gathered {1} Coins. You cannot gather any more.", Settings::MAX_COINS.to_s_formatted))
$player.coins = Settings::MAX_COINS # As a precaution
@quit=true
@quit = true
# elsif !pbConfirmMessage(_INTL("Play Voltorb Flip Lv. {1}?",@level)) && $player.coins<Settings::MAX_COINS
# @quit=true
else
@sprites["curtain"].opacity=0
@sprites["curtain"].opacity = 0
# Erase 0s to prepare to replace with values
@sprites["numbers"].bitmap.clear
# Reset arrays to empty
@voltorbNumbers=[]
@numbers=[]
@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
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
num += @squares[k][2]
if @squares[k][2] == 0
voltorbs += 1
end
end
end
pbUpdateRowNumbers(num,voltorbs,(i/5).abs)
pbUpdateRowNumbers(num, voltorbs, (i / 5).abs)
end
# Reset arrays to empty
@voltorbNumbers=[]
@numbers=[]
@voltorbNumbers = []
@numbers = []
# Draw numbers for each column
for i in 0...5
num=0
voltorbs=0
num = 0
voltorbs = 0
for j in 0...5
num+=@squares[i+(j*5)][2]
if @squares[i+(j*5)][2]==0
voltorbs+=1
num += @squares[i + (j * 5)][2]
if @squares[i + (j * 5)][2] == 0
voltorbs += 1
end
end
pbUpdateColumnNumbers(num,voltorbs,i)
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)
@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)
@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
@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
@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
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]
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)
pbDrawImagePositions(@sprites[i].bitmap, icons)
end
icons=[]
icons = []
for i in 0...25
icons[i]=[@directory+"tiles",@squares[i][0],@squares[i][1],@squares[i][2]*64,0,64,64]
icons[i] = [@directory + "tiles", @squares[i][0], @squares[i][1], @squares[i][2] * 64, 0, 64, 64]
end
pbDrawImagePositions(@sprites[5].bitmap,icons)
pbDrawImagePositions(@sprites[5].bitmap, icons)
# Default cursor image
@cursor[0]=[@directory+"cursor",0+128,0,0,0,64,64]
@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
if @index[1] > 0
@index[1] -= 1
@sprites["cursor"].y -= 64
else
@index[1]=4
@sprites["cursor"].y=256
@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
if @index[1] < 4
@index[1] += 1
@sprites["cursor"].y += 64
else
@index[1]=0
@sprites["cursor"].y=0
@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
if @index[0] > 0
@index[0] -= 1
@sprites["cursor"].x -= 64
else
@index[0]=4
@sprites["cursor"].x=256
@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
if @index[0] < 4
@index[0] += 1
@sprites["cursor"].x += 64
else
@index[0]=0
@sprites["cursor"].x=0
@index[0] = 0
@sprites["cursor"].x = 0
end
elsif Input.trigger?(Input::USE)
if @cursor[0][3]==64 # If in mark mode
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
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
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)
pbDrawImagePositions(@sprites["mark"].bitmap, @marks)
pbWait(Graphics.frame_rate / 20)
else
# Display the tile for the selected spot
icons=[]
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 @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
if @squares[i][2] == 0
pbSEPlay("Voltorb Flip explosion")
# Play explosion animation
# Part1
animation=[]
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)
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=[]
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)
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
if @level > 1
# Determine how many levels to reduce by
newLevel=0
newLevel = 0
for j in 0...@squares.length
newLevel+=1 if @squares[j][3]==true && @squares[j][2]>1
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))
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
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)
pbUpdateRowNumbers(0, 0, i)
pbUpdateColumnNumbers(0, 0, i)
end
pbDisposeSpriteHash(@sprites)
@firstRound=false
@firstRound = false
pbNewGame
else
# Play tile animation
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)
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]
if @points == 0
@points += @squares[i][2]
pbSEPlay("Voltorb Flip point")
elsif @squares[i][2]>1
@points*=@squares[i][2]
elsif @squares[i][2] > 1
@points *= @squares[i][2]
pbSEPlay("Voltorb Flip point")
end
break
@@ -353,44 +353,44 @@ class VoltorbFlip
end
end
end
count=0
count = 0
for i in 0...@squares.length
if @squares[i][3]==false && @squares[i][2]>1
count+=1
if @squares[i][3] == false && @squares[i][2] > 1
count += 1
end
end
pbUpdateCoins
# Game cleared
if count==0
@sprites["curtain"].opacity=100
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!",$player.name,@points.to_s_formatted))
pbMessage(_INTL("\\se[Voltorb Flip gain coins]{1} received {2} Coins!", $player.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)
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)
old_coins = $player.coins
$player.coins+=@points
$player.coins += @points
$stats.coins_won += $player.coins - old_coins if $player.coins > old_coins
@points=0
@points = 0
pbUpdateCoins
@sprites["curtain"].opacity=0
@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)
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))
@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
@firstRound = false
# end
end
pbDisposeSpriteHash(@sprites)
@@ -399,124 +399,124 @@ class VoltorbFlip
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
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
@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
@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
@sprites["curtain"].opacity = 0
pbShowAndDispose
@quit=true
@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)!",$player.name,@points.to_s_formatted))
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)!", $player.name, @points.to_s_formatted))
old_coins = $player.coins
$player.coins+=@points
$player.coins += @points
$stats.coins_won += $player.coins - old_coins if $player.coins > old_coins
@points=0
@points = 0
pbUpdateCoins
@sprites["curtain"].opacity=0
@sprites["curtain"].opacity = 0
pbShowAndDispose
@quit=true
@quit = true
end
@sprites["curtain"].opacity=0
@sprites["curtain"].opacity = 0
end
# Draw cursor
pbDrawImagePositions(@sprites["cursor"].bitmap,@cursor)
pbDrawImagePositions(@sprites["cursor"].bitmap, @cursor)
end
def pbUpdateRowNumbers(num,voltorbs,i)
def pbUpdateRowNumbers(num, voltorbs, i)
# Create and split a string for the number, with padded 0s
zeroes=2-num.to_s.length
numText=""
zeroes = 2 - num.to_s.length
numText = ""
zeroes.times do
numText+="0"
numText += "0"
end
numText+=num.to_s
numImages=numText.split(//)[0...2]
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]
@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]
@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)
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
end
def pbUpdateColumnNumbers(num,voltorbs,i)
def pbUpdateColumnNumbers(num, voltorbs, i)
# Create and split a string for the number, with padded 0s
zeroes=2-num.to_s.length
numText=""
zeroes = 2 - num.to_s.length
numText = ""
zeroes.times do
numText+="0"
numText += "0"
end
numText+=num.to_s
numImages=numText.split(//)[0...2]
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]
@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]
@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)
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
end
def pbCreateCoins(source,y)
zeroes=5-source.to_s.length
coinText=""
def pbCreateCoins(source, y)
zeroes = 5 - source.to_s.length
coinText = ""
zeroes.times do
coinText+="0"
coinText += "0"
end
coinText+=source.to_s
coinImages=coinText.split(//)[0...5]
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]
@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($player.coins,44)
pbDrawImagePositions(@sprites["totalCoins"].bitmap,@coins)
pbCreateCoins($player.coins, 44)
pbDrawImagePositions(@sprites["totalCoins"].bitmap, @coins)
# Update points display
@sprites["currentCoins"].bitmap.clear
pbCreateCoins(@points,110)
pbDrawImagePositions(@sprites["currentCoins"].bitmap,@coins)
pbCreateCoins(@points, 110)
pbDrawImagePositions(@sprites["currentCoins"].bitmap, @coins)
end
def pbAnimateTile(x,y,tile)
icons=[]
points=0
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)
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)
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].visible = true
pbWait(Graphics.frame_rate / 20) if i < 3
@sprites[i].bitmap.clear
@sprites[i].z=99997
@sprites[i].z = 99997
end
pbSEPlay("Voltorb Flip tile")
@sprites[5].visible=true
@sprites[5].visible = true
@sprites["mark"].bitmap.clear
pbWait(Graphics.frame_rate/10)
pbWait(Graphics.frame_rate / 10)
# Wait for user input to continue
loop do
Graphics.update
@@ -528,28 +528,28 @@ class VoltorbFlip
end
# "Dispose" of tiles by column
for i in 0...5
icons=[]
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]
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)
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]
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)
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]
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)
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]
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)
pbDrawImagePositions(@sprites[i].bitmap, icons)
pbWait(Graphics.frame_rate / 20)
end
@sprites["icon"].bitmap.clear
for i in 0...6
@@ -568,21 +568,21 @@ class VoltorbFlip
# end
def pbEndScene
@sprites["curtainL"].angle=-180
@sprites["curtainR"].angle=90
@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
@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
@sprites["curtainL"].y -= 2 if @sprites["curtainL"].angle >= -90
Graphics.update
Input.update
update
if @sprites["curtainL"].angle>=-90
if @sprites["curtainL"].angle >= -90
break
end
end
@@ -605,7 +605,7 @@ end
class VoltorbFlipScreen
def initialize(scene)
@scene=scene
@scene = scene
end
def pbStartScreen
@@ -623,8 +623,8 @@ def pbVoltorbFlip
elsif $player.coins == Settings::MAX_COINS
pbMessage(_INTL("Your Coin Case is full!"))
else
scene=VoltorbFlip.new
screen=VoltorbFlipScreen.new(scene)
scene = VoltorbFlip.new
screen = VoltorbFlipScreen.new(scene)
screen.pbStartScreen
end
end

View File

@@ -8,47 +8,47 @@ def pbSetLotteryNumber(variable = 1)
srand(hash) # seed RNG with fixed value depending on date
lottery = rand(65536) # get a number
srand # reseed RNG
pbSet(variable,sprintf("%05d",lottery))
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
def pbLottery(winnum, nameVar = 2, positionVar = 3, matchedVar = 4)
winnum = winnum.to_i
winpoke = nil
winpos = 0
winmatched = 0
for i in $player.party
thismatched=0
id=i.owner.public_id
thismatched = 0
id = i.owner.public_id
for j in 0...5
if (id/(10**j))%10 == (winnum/(10**j))%10
thismatched+=1
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
if thismatched > winmatched
winpoke = i.name
winpos = 1 # Party
winmatched = thismatched
end
end
pbEachPokemon { |poke,_box|
thismatched=0
id=poke.owner.public_id
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
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
if thismatched > winmatched
winpoke = poke.name
winpos = 2 # Storage
winmatched = thismatched
end
}
$game_variables[nameVar]=winpoke
$game_variables[positionVar]=winpos
$game_variables[matchedVar]=winmatched
$game_variables[nameVar] = winpoke
$game_variables[positionVar] = winpos
$game_variables[matchedVar] = winmatched
end

View File

@@ -7,27 +7,27 @@
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"))
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
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))
startx -= 48
if value > 0
self.bitmap.blt(startx, 0, @image.bitmap, Rect.new(0, value * 52, 96, 52))
end
end
end
@@ -37,10 +37,10 @@ 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)
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%
@@ -53,19 +53,19 @@ class MiningGameTile < BitmapSprite
else
@layer = 6 # 15%
end
@image=AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/tiles"))
@image = AnimatedBitmap.new(_INTL("Graphics/Pictures/Mining/tiles"))
update
end
def layer=(value)
@layer=value
@layer=0 if @layer<0
@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))
if @layer > 0
self.bitmap.blt(0, 0, @image.bitmap, Rect.new(0, 32 * (@layer - 1), 32, 32))
end
end
end
@@ -78,13 +78,13 @@ class MiningGameCursor < BitmapSprite
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
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)
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)
super(Graphics.width, Graphics.height, @viewport)
@position = position
@mode = mode
@hit = 0 # 0=regular, 1=hit item, 2=hit iron
@@ -96,7 +96,7 @@ class MiningGameCursor < BitmapSprite
end
def isAnimating?
return @counter>0
return @counter > 0
end
def animate(hit)
@@ -106,33 +106,33 @@ class MiningGameCursor < BitmapSprite
def update
self.bitmap.clear
x = 32*(@position%MiningGameScene::BOARDWIDTH)
y = 32*(@position/MiningGameScene::BOARDWIDTH)
if @counter>0
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
i = 10 - (@counter / 2).floor
if ToolPositions[i][1] == 1
toolx -= 8
tooly += 8
elsif ToolPositions[i][1]==2
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))
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))
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))
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))
self.bitmap.blt(x, y + 64, @cursorbitmap.bitmap, Rect.new(32 * @mode, 0, 32, 32))
end
end
end
@@ -143,82 +143,82 @@ 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]]
[: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]]
[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
@@ -226,54 +226,54 @@ class MiningGameScene
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=[]
@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)
@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["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)
@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
ptotal = 0
for i in ITEMS
ptotal+=i[1]
ptotal += i[1]
end
numitems=2+rand(3)
numitems = 2 + rand(3)
tries = 0
while numitems>0
rnd=rand(ptotal)
added=false
while numitems > 0
rnd = rand(ptotal)
added = false
for i in 0...ITEMS.length
rnd-=ITEMS[i][1]
if rnd<0
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
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
@@ -283,95 +283,95 @@ class MiningGameScene
break if added
end
tries += 1
break if tries>=500
break if tries >= 500
end
# Draw items on item layer
layer=@sprites["itemlayer"].bitmap
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))
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)
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
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
break if tries >= 500
end
# Draw items on item layer
layer=@sprites["itemlayer"].bitmap
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))
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]
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
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)
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
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
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
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
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
@@ -379,34 +379,34 @@ class MiningGameScene
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))
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))
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]
if @sprites["tile#{position}"].layer <= pattern[4] && pbIsIronThere?(position)
@sprites["tile#{position}"].layer -= pattern[4]
pbSEPlay("Mining iron")
hittype=2
hittype = 2
else
for i in 0..2
ytile=i-1+position/BOARDWIDTH
next if ytile<0 || ytile>=BOARDHEIGHT
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]
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
if @sprites["cursor"].mode == 1 # Hammer
pbSEPlay("Mining hammer")
else
pbSEPlay("Mining pick")
@@ -414,11 +414,11 @@ class MiningGameScene
end
update
Graphics.update
hititem=(@sprites["tile#{position}"].layer==0 && pbIsItemThere?(position))
hittype=1 if hititem
hititem = (@sprites["tile#{position}"].layer == 0 && pbIsItemThere?(position))
hittype = 1 if hititem
@sprites["cursor"].animate(hittype)
revealed=pbCheckRevealed
if revealed.length>0
revealed = pbCheckRevealed
if revealed.length > 0
pbSEPlay("Mining reveal full")
pbFlashItems(revealed)
elsif hititem
@@ -427,52 +427,52 @@ class MiningGameScene
end
def pbIsItemThere?(position)
posx=position%BOARDWIDTH
posy=position/BOARDWIDTH
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
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
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
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=[]
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]
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
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
@@ -483,21 +483,21 @@ class MiningGameScene
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
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],
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)
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)
revealeditems.color = Color.new(255, 255, 255, i * alphaDiff)
end
end
update
@@ -505,76 +505,76 @@ class MiningGameScene
end
revealeditems.dispose
for index in revealed
@items[index][3]=true
item=ITEMS[@items[index][0]][0]
@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))
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
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
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))
@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
foundall = true
for i in @items
foundall=false if !i[3]
foundall = false if !i[3]
break if !foundall
end
if foundall
@sprites["cursor"].visible=false
pbWait(Graphics.frame_rate*3/4)
@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
if @sprites["cursor"].position >= BOARDWIDTH
pbSEPlay("Mining cursor")
@sprites["cursor"].position-=BOARDWIDTH
@sprites["cursor"].position -= BOARDWIDTH
end
elsif Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
if @sprites["cursor"].position<(BOARDWIDTH*(BOARDHEIGHT-1))
if @sprites["cursor"].position < (BOARDWIDTH * (BOARDHEIGHT - 1))
pbSEPlay("Mining cursor")
@sprites["cursor"].position+=BOARDWIDTH
@sprites["cursor"].position += BOARDWIDTH
end
elsif Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
if @sprites["cursor"].position%BOARDWIDTH>0
if @sprites["cursor"].position % BOARDWIDTH > 0
pbSEPlay("Mining cursor")
@sprites["cursor"].position-=1
@sprites["cursor"].position -= 1
end
elsif Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
if @sprites["cursor"].position%BOARDWIDTH<(BOARDWIDTH-1)
if @sprites["cursor"].position % BOARDWIDTH < (BOARDWIDTH - 1)
pbSEPlay("Mining cursor")
@sprites["cursor"].position+=1
@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
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
@@ -585,7 +585,7 @@ class MiningGameScene
end
def pbGiveItems
if @itemswon.length>0
if @itemswon.length > 0
for i in @itemswon
if $bag.add(i)
pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]",
@@ -609,7 +609,7 @@ end
class MiningGame
def initialize(scene)
@scene=scene
@scene = scene
end
def pbStartScreen

View File

@@ -22,60 +22,60 @@ class TilePuzzleCursor < BitmapSprite
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"))
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
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)
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
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))
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]
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))
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
@@ -85,49 +85,49 @@ end
class TilePuzzleScene
def initialize(game,board,width,height)
@game=game
@board=board
@boardwidth=(width>0) ? width : 4
@boardheight=(height>0) ? height : 4
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
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
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
@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
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}"].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
@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
@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
@@ -136,100 +136,100 @@ class TilePuzzleScene
end
def updateCursor
arrows=[]
arrows = []
for i in 0...4
arrows.push(pbCanMoveInDir?(@sprites["cursor"].position,(i+1)*2,@game==6))
arrows.push(pbCanMoveInDir?(@sprites["cursor"].position, (i + 1) * 2, @game == 6))
end
@sprites["cursor"].arrows=arrows
@sprites["cursor"].arrows = arrows
end
def pbStartScene
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@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)
addBackgroundPlane(@sprites, "bg", "Tile Puzzle/bg#{@board}", @viewport)
else
addBackgroundPlane(@sprites,"bg","Tile Puzzle/bg",@viewport)
addBackgroundPlane(@sprites, "bg", "Tile Puzzle/bg", @viewport)
end
@tilebitmap=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}")
@tilebitmap1=nil
@tilebitmap2=nil
@tilebitmap3=nil
@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")
@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")
@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")
@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))
@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)
@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 = []
for i in 0...@boardwidth * @boardheight
ret.push(i)
@angles.push(0)
end
if @game==6
@tiles=ret
if @game == 6
@tiles = ret
5.times do
pbShiftLine([2,4,6,8][rand(4)],rand(@boardwidth*@boardheight),false)
pbShiftLine([2, 4, 6, 8][rand(4)], rand(@boardwidth * @boardheight), false)
end
return @tiles
elsif @game==7
@tiles=ret
elsif @game == 7
@tiles = ret
5.times do
pbRotateTile(rand(@boardwidth*@boardheight),false)
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
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
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
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))
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
if @game == 1 || @game == 2
ret2 = []
for i in 0...@boardwidth * @boardheight
ret2.push(-1)
end
ret=ret2+ret
ret = ret2 + ret
end
if @game==2 || @game==5
if @game == 2 || @game == 5
for i in 0...@angles.length
@angles[i]=rand(4)
@angles[i] = rand(4)
end
end
end
@@ -237,9 +237,9 @@ class TilePuzzleScene
end
def pbDefaultCursorPosition
if @game==3
for i in 0...@boardwidth*@boardheight
return i if @tiles[i]==@boardwidth*@boardheight-1
if @game == 3
for i in 0...@boardwidth * @boardheight
return i if @tiles[i] == @boardwidth * @boardheight - 1
end
return 0
else
@@ -247,73 +247,73 @@ class TilePuzzleScene
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
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
pos -= 1
end
else
if (pos%@boardwidth)==0
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil-1
if (pos % @boardwidth) == 0
pos = (((pos / @boardwidth) + @boardheight) * @boardwidth) + (@boardwidth / 2).ceil - 1
else
pos-=1
pos -= 1
end
end
elsif dir==6
if pos>=@boardwidth*@boardheight
if pos%@boardwidth==(@boardwidth/2).ceil-1
pos=((pos%(@boardwidth*@boardheight))/@boardwidth)*@boardwidth
elsif dir == 6
if pos >= @boardwidth * @boardheight
if pos % @boardwidth == (@boardwidth / 2).ceil - 1
pos = ((pos % (@boardwidth * @boardheight)) / @boardwidth) * @boardwidth
else
pos+=1
pos += 1
end
else
if pos%@boardwidth>=@boardwidth-1
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil
if pos % @boardwidth >= @boardwidth - 1
pos = (((pos / @boardwidth) + @boardheight) * @boardwidth) + (@boardwidth / 2).ceil
else
pos+=1
pos += 1
end
end
elsif dir==8
pos-=@boardwidth
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
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
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
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
return false if pos % @boardwidth >= @boardwidth - 1
end
elsif dir==8
return false if (pos/@boardwidth)%@boardheight==0
elsif dir == 8
return false if (pos / @boardwidth) % @boardheight == 0
end
return true
end
def pbRotateTile(pos,anim = true)
if @heldtile>=0
def pbRotateTile(pos, anim = true)
if @heldtile >= 0
if anim
@sprites["cursor"].visible=false
@sprites["cursor"].visible = false
@sprites["tile#{@heldtile}"].z = 1
oldAngle = @sprites["tile#{@heldtile}"].angle
rotateTime = Graphics.frame_rate/4
angleDiff = 90.0/rotateTime
rotateTime = Graphics.frame_rate / 4
angleDiff = 90.0 / rotateTime
rotateTime.times do
@sprites["tile#{@heldtile}"].angle -= angleDiff
pbUpdateSpriteHash(@sprites)
@@ -321,23 +321,23 @@ class TilePuzzleScene
Input.update
end
@sprites["tile#{@heldtile}"].z = 0
@sprites["tile#{@heldtile}"].angle = oldAngle-90
@sprites["cursor"].visible=true if !pbCheckWin
@sprites["tile#{@heldtile}"].angle = oldAngle - 90
@sprites["cursor"].visible = true if !pbCheckWin
end
@angles[@heldtile]-=1
@angles[@heldtile]+=4 if @angles[@heldtile]<0
@angles[@heldtile] -= 1
@angles[@heldtile] += 4 if @angles[@heldtile] < 0
else
return if @tiles[pos]<0
group=pbGetNearTiles(pos)
return if @tiles[pos] < 0
group = pbGetNearTiles(pos)
if anim
@sprites["cursor"].visible=false
@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 = Graphics.frame_rate / 4
angleDiff = 90.0 / rotateTime
rotateTime.times do
for i in group
@sprites["tile#{@tiles[i]}"].angle -= angleDiff
@@ -348,114 +348,114 @@ class TilePuzzleScene
end
for i in group
@sprites["tile#{@tiles[i]}"].z = 0
@sprites["tile#{@tiles[i]}"].angle = oldAngles[i]-90
@sprites["tile#{@tiles[i]}"].angle = oldAngles[i] - 90
end
@sprites["cursor"].visible=true if !pbCheckWin
@sprites["cursor"].visible = true if !pbCheckWin
end
for i in group
tile=@tiles[i]
@angles[tile]-=1
@angles[tile]+=4 if @angles[tile]<0
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)
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
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
@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 = 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
@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
@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)
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)
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)
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
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)
tiles.push(cursor + i * dist)
end
end
# Shift tiles
fadeTime = Graphics.frame_rate*4/10
fadeDiff = (255.0/fadeTime).ceil
fadeTime = Graphics.frame_rate * 4 / 10
fadeDiff = (255.0 / fadeTime).ceil
if anim
@sprites["cursor"].visible=false
@sprites["cursor"].visible = false
fadeTime.times do
@sprites["tile#{@tiles[tiles[tiles.length-1]]}"].opacity-=fadeDiff
@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 = 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
@sprites["tile#{@tiles[i]}"].y -= dist * distancePerFrame
end
pbUpdateSpriteHash(@sprites)
Graphics.update
Input.update
end
else
distancePerFrame = (@tilewidth.to_f/shiftTime).ceil
distancePerFrame = (@tilewidth.to_f / shiftTime).ceil
shiftTime.times do
for i in tiles
@sprites["tile#{@tiles[i]}"].x += dist*distancePerFrame
@sprites["tile#{@tiles[i]}"].x += dist * distancePerFrame
end
pbUpdateSpriteHash(@sprites)
Graphics.update
@@ -463,36 +463,36 @@ class TilePuzzleScene
end
end
end
temp=[]
temp = []
for i in tiles
temp.push(@tiles[i])
end
for i in 0...temp.length
@tiles[tiles[(i+1)%(temp.length)]]=temp[i]
@tiles[tiles[(i + 1) % (temp.length)]] = temp[i]
end
if anim
update
fadeTime.times do
@sprites["tile#{@tiles[tiles[0]]}"].opacity+=fadeDiff
@sprites["tile#{@tiles[tiles[0]]}"].opacity += fadeDiff
Graphics.update
Input.update
end
@sprites["cursor"].selected=false
@sprites["cursor"].visible=true if !pbCheckWin
@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
@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
for i in 0...@boardwidth * @boardheight
return false if @tiles[i] != i
return false if @angles[i] != 0
end
return true
end
@@ -504,23 +504,23 @@ class TilePuzzleScene
Input.update
# Check end conditions
if pbCheckWin
@sprites["cursor"].visible=false
if @game==3
extratile=@sprites["tile#{@boardwidth*@boardheight-1}"]
@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
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)
pbWait(Graphics.frame_rate / 2)
end
loop do
Graphics.update
@@ -530,29 +530,29 @@ class TilePuzzleScene
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)
@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)
if pbCanMoveInDir?(@sprites["cursor"].position, dir, false)
pbSEPlay("Tile Game cursor")
@sprites["cursor"].position=pbMoveCursor(@sprites["cursor"].position,dir)
@sprites["cursor"].position = pbMoveCursor(@sprites["cursor"].position, dir)
end
end
elsif (@game==1 || @game==2) && Input.trigger?(Input::USE)
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))
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
@@ -571,12 +571,12 @@ end
class TilePuzzle
def initialize(scene)
@scene=scene
@scene = scene
end
def pbStartScreen
@scene.pbStartScene
ret=@scene.pbMain
ret = @scene.pbMain
@scene.pbEndScene
return ret
end
@@ -584,10 +584,10 @@ end
def pbTilePuzzle(game,board,width = 0,height = 0)
def pbTilePuzzle(game, board, width = 0, height = 0)
ret = false
pbFadeOutIn {
scene = TilePuzzleScene.new(game,board,width,height)
scene = TilePuzzleScene.new(game, board, width, height)
screen = TilePuzzle.new(scene)
ret = screen.pbStartScreen
}