Can you help me with something, please?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Can you help me with something, please?

Post by Mateus »

Hey guys,
I am reamking a slot machine game called Multiplay81.
You probably don't know how slot games work so let me write down a quick introduction.

This specific game has 81 pay lines.
Pay line = 3-4 matching symbols from left to right.
81 lines on 4 reel game means any combination from left to right is a winning combination.
Example:
Image

The problem:
I don't really want to write down all 81 lines and define them one by one. I am sure there is a way to do it faster with loops.. I just couldn't do it.. or am I just too lazy? Doesn't matter..
Also, there is a WILD symbol, that counts as any other symbol if there is winning combination on that specific line with the WILD symbol.
I would also appreciate if someone could help me with how to check if there are any win lines, and move them to array.

Thank you, if u're so kind and want to help, I can provide more info.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Can you help me with something, please?

Post by grump »

So it's basically just the count of each symbol, going from left to right?

Do you have some kind of representation of your reels and symbols already? It's certainly doable with loops, it just depends on how your code represents the game elements. You basically loop over the reels from left to right and increase a distinct counter for each symbol. Place some kind of stop marker if a reel does not have a symbol that was on a previous reel, and use it to stop counting that symbol. At the end, add the count of wildcards to the count of all other symbols.

I'm not sure I fully understood how this machine works though.

BTW, I love slot machines - please post the game once you have finished it!
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: Can you help me with something, please?

Post by Mateus »

Hey grump, thank you for your response!
I will post the game after, for sure!

Now to get technical,
after the spin ends, the symbols are in 4 arrays (4 reels).
Slider[1-4]. Where Slider[1][1] is the top symbol in the first reel. (Just to make it clear, Slider[1][3] would be the bottom symbol on the first reel).

For some reason I just can't use my brain like I used to (lol). Would be super cool to see some code examples on how you would aproach it.

Thanks!
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Can you help me with something, please?

Post by pgimeno »

Here's my take (needs hump.timer):

Code: Select all

local timer = require 'hump.timer'

local fruits = {"watermelon", "blueberry", "grapes", "lemon", "orange",
                "cherry", "bar", "7", "*"}

local screen = {}
local marks = {}

local finished = true

for i = 1, 3 do
  screen[i] = {}
  marks[i] = {}
end

local function nextRound()
  for i = 1, 3 do
    for j = 1, 4 do
      screen[i][j] = fruits[love.math.random(1, #fruits)]
    end
  end
end

local function matches(a, b, c, d)
  local kind
  if a == "*" then
    if b == "*" then
      if c == "*" then
        return true
      end
      kind = c
    else
      kind = b
    end
  else
    kind = a
  end
  assert(kind)
  return (a == kind or a == '*') and (b == kind or b == '*')
     and (c == kind or c == '*') and (d == kind or d == '*')
end

local function clearMarks()
  for i = 1, 3 do
    for j = 1, 4 do
      marks[i][j] = false
    end
  end
end

local function findLines(wait)
  finished = false
  wait(1)
  for c1 = 1, 3 do
    local fruitC1 = screen[c1][1]
    for c2 = 1, 3 do
      local fruitC2 = screen[c2][2]
      for c3 = 1, 3 do
        local fruitC3 = screen[c3][3]
        for c4 = 1, 3 do
          local fruitC4 = screen[c4][4]
          if matches(fruitC1, fruitC2, fruitC3, fruitC4) then
            marks[c1][1] = true
            marks[c2][2] = true
            marks[c3][3] = true
            marks[c4][4] = true
            wait(2)
            clearMarks()
          end
        end
      end
    end
  end
                
  finished = true
end

function love.update(dt)
  if finished then
    nextRound()
    timer.script(findLines)
  end
  timer.update(dt)
end

function love.draw()
  for i = 1, 3 do
    for j = 1, 4 do
      if marks[i][j] then
        love.graphics.setColor(1, 0, 0)
      else
        love.graphics.setColor(1, 1, 1)
      end
      love.graphics.print(screen[i][j], j * 150, i * 10)
    end
  end
end

function love.keypressed(k) if k == "escape" then return love.event.quit() end end
I think your rows and columns are swapped with respect to mine.
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: Can you help me with something, please?

Post by Mateus »

Hey pgimeno,
thank you for your reply!

I just finished my code, it was super simple, can't belive it took me so long to figure it out.. it is very similar to what you posted.

I must say that your replies helped me! Thank you very much!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 55 guests