Finished FPS agnosticism, removed particle engine

This commit is contained in:
Maruno17
2023-06-03 21:55:02 +01:00
parent 68de25562a
commit 1901675e33
39 changed files with 652 additions and 1504 deletions

View File

@@ -6,28 +6,23 @@
# - The number is either 0 (easy), 1 (default) or 2 (hard).
#===============================================================================
class SlotMachineReel < BitmapSprite
attr_accessor :reel
attr_accessor :toppos
attr_accessor :spinning
attr_accessor :stopping
attr_accessor :slipping
SCROLLSPEED = 16 # Must be a divisor of 48
ICONSPOOL = [[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7], # 0 - Easy
[0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7], # 1 - Medium (default)
[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7]] # 2 - Hard
SCROLL_SPEED = 640 # Pixels moved per second
ICONS_SETS = [[3, 2, 7, 6, 3, 1, 5, 2, 3, 0, 6, 4, 7, 5, 1, 3, 2, 3, 6, 0, 4, 5], # Reel 1
[0, 4, 1, 2, 7, 4, 6, 0, 1, 5, 4, 0, 1, 3, 4, 0, 1, 6, 7, 0, 1, 5], # Reel 2
[6, 2, 1, 4, 3, 2, 1, 4, 7, 3, 2, 1, 4, 3, 7, 2, 4, 3, 1, 2, 4, 5]] # Reel 3
SLIPPING = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3]
def initialize(x, y, difficulty = 1)
def initialize(x, y, reel_num, difficulty = 1)
@viewport = Viewport.new(x, y, 64, 144)
@viewport.z = 99999
super(64, 144, @viewport)
@reel = []
ICONSPOOL[difficulty].length.times do |i|
@reel.push(ICONSPOOL[difficulty][i])
end
@reel.shuffle!
@reel_num = reel_num
@difficulty = difficulty
@reel = ICONS_SETS[reel_num - 1].clone
@toppos = 0
@current_y_pos = -1
@spin_speed = SCROLL_SPEED
@spin_speed /= 1.5 if difficulty == 0
@spinning = false
@stopping = false
@slipping = 0
@@ -39,11 +34,25 @@ class SlotMachineReel < BitmapSprite
def startSpinning
@spinning = true
@spin_timer_start = System.uptime
@initial_index = @index + 1
@current_y_pos = -1
end
def spinning?
return @spinning
end
def stopSpinning(noslipping = false)
@stopping = true
@slipping = SLIPPING[rand(SLIPPING.length)]
@slipping = SLIPPING.sample
if @difficulty == 0 # Easy
second_slipping = SLIPPING.sample
@slipping = [@slipping, second_slipping].min
elsif @difficulty == 2 # Hard
second_slipping = SLIPPING.sample
@slipping = [@slipping, second_slipping].max
end
@slipping = 0 if noslipping
end
@@ -59,15 +68,28 @@ class SlotMachineReel < BitmapSprite
def update
self.bitmap.clear
if @toppos == 0 && @stopping && @slipping == 0
@spinning = @stopping = false
end
if @spinning
@toppos += SCROLLSPEED
if @toppos > 0
@toppos -= 48
@index = (@index + 1) % @reel.length
@slipping -= 1 if @slipping > 0
new_y_pos = (System.uptime - @spin_timer_start) * @spin_speed
new_index = (new_y_pos / @images.height).to_i
old_index = (@current_y_pos / @images.height).to_i
@current_y_pos = new_y_pos
@toppos = new_y_pos
while @toppos > 0
@toppos -= @images.height
end
if new_index != old_index
if @stopping
if @slipping == 0
@spinning = false
@stopping = false
@toppos = 0
else
@slipping = [@slipping - new_index + old_index, 0].max
end
end
if @spinning
@index = (new_index + @initial_index) % @reel.length
end
end
end
4.times do |i|
@@ -130,11 +152,11 @@ class SlotMachineScene
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
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
combinations.length.times do |i|
break if i >= 1 && @wager <= 1 # One coin = centre row only
break if i >= 3 && @wager <= 2 # Two coins = three rows only
@@ -206,18 +228,25 @@ class SlotMachineScene
@sprites["light2"].visible = false
@sprites["window1"].src_rect.set(0, 0, 152, 208)
# Pay out
timer_start = System.uptime
last_paid_tick = -1
loop do
break if @sprites["payout"].score <= 0
Graphics.update
Input.update
update
@sprites["payout"].score -= 1
@sprites["credit"].score += 1
this_tick = ((System.uptime - timer_start) * 20).to_i # Pay out 1 coin every 1/20 seconds
if this_tick != last_paid_tick
@sprites["payout"].score -= 1
@sprites["credit"].score += 1
this_tick = last_paid_tick
end
if Input.trigger?(Input::USE) || @sprites["credit"].score == Settings::MAX_COINS
@sprites["credit"].score += @sprites["payout"].score
@sprites["payout"].score = 0
end
end
# Wait
timer_start = System.uptime
loop do
Graphics.update
@@ -247,9 +276,9 @@ class SlotMachineScene
@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["reel1"] = SlotMachineReel.new(64, 112, 1, difficulty)
@sprites["reel2"] = SlotMachineReel.new(144, 112, 2, difficulty)
@sprites["reel3"] = SlotMachineReel.new(224, 112, 3, difficulty)
(1..3).each do |i|
@sprites["button#{i}"] = IconSprite.new(68 + (80 * (i - 1)), 260, @viewport)
@sprites["button#{i}"].setBitmap("Graphics/UI/Slot Machine/button")
@@ -304,18 +333,18 @@ class SlotMachineScene
update
if Input.trigger?(Input::USE)
pbSEPlay("Slots stop")
if @sprites["reel1"].spinning
if @sprites["reel1"].spinning?
@sprites["reel1"].stopSpinning(@replay)
@sprites["button1"].visible = true
elsif @sprites["reel2"].spinning
elsif @sprites["reel2"].spinning?
@sprites["reel2"].stopSpinning(@replay)
@sprites["button2"].visible = true
elsif @sprites["reel3"].spinning
elsif @sprites["reel3"].spinning?
@sprites["reel3"].stopSpinning(@replay)
@sprites["button3"].visible = true
end
end
if !@sprites["reel3"].spinning
if !@sprites["reel3"].spinning?
@gameEnd = true
@gameRunning = false
end