mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-07 21:24:59 +00:00
Minor fixes to Voltorb Flip
This commit is contained in:
@@ -1,20 +1,26 @@
|
|||||||
################################################################################
|
#===============================================================================
|
||||||
# "Voltorb Flip" mini-game
|
# "Voltorb Flip" mini-game
|
||||||
# By KitsuneKouta
|
# By KitsuneKouta
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Run with: pbVoltorbFlip
|
# Run with: pbVoltorbFlip
|
||||||
################################################################################
|
#===============================================================================
|
||||||
class VoltorbFlip
|
class VoltorbFlip
|
||||||
|
# Ranges of total coins available in each level.
|
||||||
|
LEVEL_RANGES = [[20, 50],
|
||||||
|
[50, 100],
|
||||||
|
[100, 200],
|
||||||
|
[200, 350],
|
||||||
|
[350, 600],
|
||||||
|
[600, 1000],
|
||||||
|
[1000, 2000],
|
||||||
|
[2000, 3500]]
|
||||||
|
|
||||||
def update
|
def update
|
||||||
pbUpdateSpriteHash(@sprites)
|
pbUpdateSpriteHash(@sprites)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pbStart
|
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
|
@firstRound = true
|
||||||
pbNewGame
|
pbNewGame
|
||||||
end
|
end
|
||||||
@@ -43,11 +49,11 @@ class VoltorbFlip
|
|||||||
squareValues[i] = 0
|
squareValues[i] = 0
|
||||||
voltorbs += 1
|
voltorbs += 1
|
||||||
# Sets the value randomly to a 2 or 3 if the total is less than the max
|
# Sets the value randomly to a 2 or 3 if the total is less than the max
|
||||||
elsif total < @levelRanges[@level - 1][1]
|
elsif total < LEVEL_RANGES[@level - 1][1]
|
||||||
squareValues[i] = rand(2..3)
|
squareValues[i] = rand(2..3)
|
||||||
total *= squareValues[i]
|
total *= squareValues[i]
|
||||||
end
|
end
|
||||||
if total > (@levelRanges[@level - 1][1])
|
if total > LEVEL_RANGES[@level - 1][1]
|
||||||
# Lowers value of square to 1 if over max
|
# Lowers value of square to 1 if over max
|
||||||
total /= squareValues[i]
|
total /= squareValues[i]
|
||||||
squareValues[i] = 1
|
squareValues[i] = 1
|
||||||
@@ -61,7 +67,7 @@ class VoltorbFlip
|
|||||||
squareValues[i] -= 1
|
squareValues[i] -= 1
|
||||||
total *= squareValues[i]
|
total *= squareValues[i]
|
||||||
end
|
end
|
||||||
if total < @levelRanges[@level - 1][0] && squareValues[i] > 0
|
if total < LEVEL_RANGES[@level - 1][0] && squareValues[i] > 0
|
||||||
total /= squareValues[i]
|
total /= squareValues[i]
|
||||||
squareValues[i] = temp
|
squareValues[i] = temp
|
||||||
total *= squareValues[i]
|
total *= squareValues[i]
|
||||||
@@ -69,9 +75,8 @@ class VoltorbFlip
|
|||||||
end
|
end
|
||||||
# Populate @squares array
|
# Populate @squares array
|
||||||
25.times do |i|
|
25.times do |i|
|
||||||
x = i if i % 5 == 0
|
|
||||||
r = rand(squareValues.length)
|
r = rand(squareValues.length)
|
||||||
@squares[i] = [((i - x).abs * 64) + 128, (i / 5).abs * 64, squareValues[r], false]
|
@squares[i] = [((i % 5) * 64) + 128, (i / 5).abs * 64, squareValues[r], false]
|
||||||
squareValues.delete_at(r)
|
squareValues.delete_at(r)
|
||||||
end
|
end
|
||||||
pbCreateSprites
|
pbCreateSprites
|
||||||
@@ -83,9 +88,9 @@ class VoltorbFlip
|
|||||||
pbDrawShadowText(@sprites["text"].bitmap, 8, 16, 118, 26,
|
pbDrawShadowText(@sprites["text"].bitmap, 8, 16, 118, 26,
|
||||||
_INTL("Your coins"), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
_INTL("Your coins"), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
||||||
pbDrawShadowText(@sprites["text"].bitmap, 8, 82, 118, 26,
|
pbDrawShadowText(@sprites["text"].bitmap, 8, 82, 118, 26,
|
||||||
_INTL("Earned coins"), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
_INTL("Prize coins"), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
||||||
# Draw current level
|
# Draw current level
|
||||||
pbDrawShadowText(@sprites["level"].bitmap, 8, 150, 118, 28,
|
pbDrawShadowText(@sprites["level"].bitmap, 8, 148, 118, 28,
|
||||||
_INTL("Level {1}", @level.to_s), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
_INTL("Level {1}", @level.to_s), Color.new(60, 60, 60), Color.new(150, 190, 170), 1)
|
||||||
# Displays total and current coins
|
# Displays total and current coins
|
||||||
pbUpdateCoins
|
pbUpdateCoins
|
||||||
@@ -119,18 +124,15 @@ class VoltorbFlip
|
|||||||
@numbers = []
|
@numbers = []
|
||||||
# Draw numbers for each row (precautionary)
|
# Draw numbers for each row (precautionary)
|
||||||
@squares.length.times do |i|
|
@squares.length.times do |i|
|
||||||
if i % 5 == 0
|
next if (i % 5) != 0
|
||||||
num = 0
|
num = 0
|
||||||
voltorbs = 0
|
voltorbs = 0
|
||||||
j = i + 5
|
j = i + 5
|
||||||
(i...j).each do |k|
|
(i...j).each do |k|
|
||||||
num += @squares[k][2]
|
num += @squares[k][2]
|
||||||
if @squares[k][2] == 0
|
voltorbs += 1 if @squares[k][2] == 0
|
||||||
voltorbs += 1
|
|
||||||
end
|
end
|
||||||
end
|
pbUpdateRowNumbers(num, voltorbs, i / 5)
|
||||||
end
|
|
||||||
pbUpdateRowNumbers(num, voltorbs, (i / 5).abs)
|
|
||||||
end
|
end
|
||||||
# Reset arrays to empty
|
# Reset arrays to empty
|
||||||
@voltorbNumbers = []
|
@voltorbNumbers = []
|
||||||
@@ -141,9 +143,7 @@ class VoltorbFlip
|
|||||||
voltorbs = 0
|
voltorbs = 0
|
||||||
5.times do |j|
|
5.times do |j|
|
||||||
num += @squares[i + (j * 5)][2]
|
num += @squares[i + (j * 5)][2]
|
||||||
if @squares[i + (j * 5)][2] == 0
|
voltorbs += 1 if @squares[i + (j * 5)][2] == 0
|
||||||
voltorbs += 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
pbUpdateColumnNumbers(num, voltorbs, i)
|
pbUpdateColumnNumbers(num, voltorbs, i)
|
||||||
end
|
end
|
||||||
@@ -157,10 +157,8 @@ class VoltorbFlip
|
|||||||
@sprites["bg"].bitmap = RPG::Cache.load_bitmap(@directory, "boardbg")
|
@sprites["bg"].bitmap = RPG::Cache.load_bitmap(@directory, "boardbg")
|
||||||
@sprites["text"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
@sprites["text"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
||||||
pbSetSystemFont(@sprites["text"].bitmap)
|
pbSetSystemFont(@sprites["text"].bitmap)
|
||||||
@sprites["text"].bitmap.font.size = 26
|
|
||||||
@sprites["level"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
@sprites["level"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
||||||
pbSetSystemFont(@sprites["level"].bitmap)
|
pbSetSystemFont(@sprites["level"].bitmap)
|
||||||
@sprites["level"].bitmap.font.size = 28
|
|
||||||
@sprites["curtain"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
@sprites["curtain"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
|
||||||
@sprites["curtain"].z = 99999
|
@sprites["curtain"].z = 99999
|
||||||
@sprites["curtain"].bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0))
|
@sprites["curtain"].bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0))
|
||||||
@@ -284,7 +282,8 @@ class VoltorbFlip
|
|||||||
# Part1
|
# Part1
|
||||||
animation = []
|
animation = []
|
||||||
3.times do |j|
|
3.times do |j|
|
||||||
animation[0] = icons[0] = [@directory + "tiles", (@index[0] * 64) + 128, @index[1] * 64, 704 + (64 * j), 0, 64, 64]
|
animation[0] = icons[0] = [@directory + "tiles", (@index[0] * 64) + 128, @index[1] * 64,
|
||||||
|
704 + (64 * j), 0, 64, 64]
|
||||||
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
||||||
pbWait(Graphics.frame_rate / 20)
|
pbWait(Graphics.frame_rate / 20)
|
||||||
@sprites["animation"].bitmap.clear
|
@sprites["animation"].bitmap.clear
|
||||||
@@ -292,7 +291,8 @@ class VoltorbFlip
|
|||||||
# Part2
|
# Part2
|
||||||
animation = []
|
animation = []
|
||||||
6.times do |j|
|
6.times do |j|
|
||||||
animation[0] = [@directory + "explosion", (@index[0] * 64) - 32 + 128, (@index[1] * 64) - 32, j * 128, 0, 128, 128]
|
animation[0] = [@directory + "explosion", (@index[0] * 64) - 32 + 128, (@index[1] * 64) - 32,
|
||||||
|
j * 128, 0, 128, 128]
|
||||||
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
||||||
pbWait(Graphics.frame_rate / 10)
|
pbWait(Graphics.frame_rate / 10)
|
||||||
@sprites["animation"].bitmap.clear
|
@sprites["animation"].bitmap.clear
|
||||||
@@ -316,14 +316,15 @@ class VoltorbFlip
|
|||||||
end
|
end
|
||||||
# Update level text
|
# Update level text
|
||||||
@sprites["level"].bitmap.clear
|
@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)
|
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
|
@points = 0
|
||||||
pbUpdateCoins
|
pbUpdateCoins
|
||||||
# Revert numbers to 0s
|
# Revert numbers to 0s
|
||||||
@sprites["numbers"].bitmap.clear
|
@sprites["numbers"].bitmap.clear
|
||||||
5.times do |i|
|
5.times do |j|
|
||||||
pbUpdateRowNumbers(0, 0, i)
|
pbUpdateRowNumbers(0, 0, j)
|
||||||
pbUpdateColumnNumbers(0, 0, i)
|
pbUpdateColumnNumbers(0, 0, j)
|
||||||
end
|
end
|
||||||
pbDisposeSpriteHash(@sprites)
|
pbDisposeSpriteHash(@sprites)
|
||||||
@firstRound = false
|
@firstRound = false
|
||||||
@@ -332,7 +333,8 @@ class VoltorbFlip
|
|||||||
# Play tile animation
|
# Play tile animation
|
||||||
animation = []
|
animation = []
|
||||||
4.times do |j|
|
4.times do |j|
|
||||||
animation[0] = [@directory + "flipAnimation", (@index[0] * 64) - 14 + 128, (@index[1] * 64) - 16, j * 92, 0, 92, 96]
|
animation[0] = [@directory + "flipAnimation", (@index[0] * 64) - 14 + 128, (@index[1] * 64) - 16,
|
||||||
|
j * 92, 0, 92, 96]
|
||||||
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
pbDrawImagePositions(@sprites["animation"].bitmap, animation)
|
||||||
pbWait(Graphics.frame_rate / 20)
|
pbWait(Graphics.frame_rate / 20)
|
||||||
@sprites["animation"].bitmap.clear
|
@sprites["animation"].bitmap.clear
|
||||||
@@ -365,7 +367,8 @@ class VoltorbFlip
|
|||||||
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
|
# Update level text
|
||||||
@sprites["level"].bitmap.clear
|
@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
|
old_coins = $player.coins
|
||||||
$player.coins += @points
|
$player.coins += @points
|
||||||
$stats.coins_won += $player.coins - old_coins if $player.coins > old_coins
|
$stats.coins_won += $player.coins - old_coins if $player.coins > old_coins
|
||||||
@@ -410,7 +413,8 @@ class VoltorbFlip
|
|||||||
pbShowAndDispose
|
pbShowAndDispose
|
||||||
@quit = true
|
@quit = true
|
||||||
end
|
end
|
||||||
elsif pbConfirmMessage(_INTL("If you quit now, you will recieve {1} Coin(s). Will you quit?", @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))
|
pbMessage(_INTL("{1} received {2} Coin(s)!", $player.name, @points.to_s_formatted))
|
||||||
old_coins = $player.coins
|
old_coins = $player.coins
|
||||||
$player.coins += @points
|
$player.coins += @points
|
||||||
@@ -428,62 +432,42 @@ class VoltorbFlip
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pbUpdateRowNumbers(num, voltorbs, i)
|
def pbUpdateRowNumbers(num, voltorbs, i)
|
||||||
# Create and split a string for the number, with padded 0s
|
numText = sprintf("%02d", num)
|
||||||
zeroes = 2 - num.to_s.length
|
numText.chars.each_with_index do |digit, j|
|
||||||
numText = ""
|
@numbers[j] = [@directory + "numbersSmall", 472 + (j * 16), 8 + (i * 64), digit.to_i * 16, 0, 16, 16]
|
||||||
zeroes.times do
|
|
||||||
numText += "0"
|
|
||||||
end
|
end
|
||||||
numText += num.to_s
|
@voltorbNumbers[i] = [@directory + "numbersSmall", 488, 34 + (i * 64), voltorbs * 16, 0, 16, 16]
|
||||||
numImages = numText.chars[0...2]
|
|
||||||
2.times do |j|
|
|
||||||
@numbers[j] = [@directory + "numbersSmall", 472 + (j * 16), (i * 64) + 8, numImages[j].to_i * 16, 0, 16, 16]
|
|
||||||
end
|
|
||||||
@voltorbNumbers[i] = [@directory + "numbersSmall", 488, (i * 64) + 34, voltorbs * 16, 0, 16, 16]
|
|
||||||
# Display the numbers
|
# Display the numbers
|
||||||
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
|
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
|
||||||
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
|
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pbUpdateColumnNumbers(num, voltorbs, i)
|
def pbUpdateColumnNumbers(num, voltorbs, i)
|
||||||
# Create and split a string for the number, with padded 0s
|
numText = sprintf("%02d", num)
|
||||||
zeroes = 2 - num.to_s.length
|
numText.chars.each_with_index do |digit, j|
|
||||||
numText = ""
|
@numbers[j] = [@directory + "numbersSmall", 152 + (i * 64) + (j * 16), 328, digit.to_i * 16, 0, 16, 16]
|
||||||
zeroes.times do
|
|
||||||
numText += "0"
|
|
||||||
end
|
end
|
||||||
numText += num.to_s
|
@voltorbNumbers[i] = [@directory + "numbersSmall", 168 + (i * 64), 354, voltorbs * 16, 0, 16, 16]
|
||||||
numImages = numText.chars[0...2]
|
|
||||||
2.times do |j|
|
|
||||||
@numbers[j] = [@directory + "numbersSmall", (i * 64) + 152 + (j * 16), 328, numImages[j].to_i * 16, 0, 16, 16]
|
|
||||||
end
|
|
||||||
@voltorbNumbers[i] = [@directory + "numbersSmall", (i * 64) + 168, 354, voltorbs * 16, 0, 16, 16]
|
|
||||||
# Display the numbers
|
# Display the numbers
|
||||||
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
|
pbDrawImagePositions(@sprites["numbers"].bitmap, @numbers)
|
||||||
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
|
pbDrawImagePositions(@sprites["numbers"].bitmap, @voltorbNumbers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pbCreateCoins(source, y)
|
def pbCreateCoins(source, y)
|
||||||
zeroes = 5 - source.to_s.length
|
coinText = sprintf("%05d", source)
|
||||||
coinText = ""
|
coinText.chars.each_with_index do |digit, i|
|
||||||
zeroes.times do
|
@coins[i] = [@directory + "numbersScore", 6 + (i * 24), y, digit.to_i * 24, 0, 24, 38]
|
||||||
coinText += "0"
|
|
||||||
end
|
|
||||||
coinText += source.to_s
|
|
||||||
coinImages = coinText.chars[0...5]
|
|
||||||
5.times do |i|
|
|
||||||
@coins[i] = [@directory + "numbersScore", 6 + (i * 24), y, coinImages[i].to_i * 24, 0, 24, 38]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pbUpdateCoins
|
def pbUpdateCoins
|
||||||
# Update coins display
|
# Update coins display
|
||||||
@sprites["totalCoins"].bitmap.clear
|
@sprites["totalCoins"].bitmap.clear
|
||||||
pbCreateCoins($player.coins, 44)
|
pbCreateCoins($player.coins, 46)
|
||||||
pbDrawImagePositions(@sprites["totalCoins"].bitmap, @coins)
|
pbDrawImagePositions(@sprites["totalCoins"].bitmap, @coins)
|
||||||
# Update points display
|
# Update points display
|
||||||
@sprites["currentCoins"].bitmap.clear
|
@sprites["currentCoins"].bitmap.clear
|
||||||
pbCreateCoins(@points, 110)
|
pbCreateCoins(@points, 112)
|
||||||
pbDrawImagePositions(@sprites["currentCoins"].bitmap, @coins)
|
pbDrawImagePositions(@sprites["currentCoins"].bitmap, @coins)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -527,7 +511,8 @@ class VoltorbFlip
|
|||||||
icons = []
|
icons = []
|
||||||
pbSEPlay("Voltorb Flip tile")
|
pbSEPlay("Voltorb Flip tile")
|
||||||
5.times do |j|
|
5.times do |j|
|
||||||
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
|
end
|
||||||
pbDrawImagePositions(@sprites[i].bitmap, icons)
|
pbDrawImagePositions(@sprites[i].bitmap, icons)
|
||||||
pbWait(Graphics.frame_rate / 20)
|
pbWait(Graphics.frame_rate / 20)
|
||||||
|
|||||||
Reference in New Issue
Block a user