Difference between revisions of "love.image"
m (→See Also: Reorder links.) |
|||
Line 1: | Line 1: | ||
− | + | local opponents = { | |
− | + | {name = "Itadori", image = "characters/itadori.png", selected = false}, | |
− | { | + | {name = "Megumi", image = "characters/megumi.png", selected = false}, |
− | + | {name = "Nobara", image = "characters/nobara.png", selected = false}, | |
− | + | {name = "Choso", image = "characters/choso.png", selected = false} | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | local player = { |
− | + | name = "Your Character", | |
+ | level = 1 | ||
+ | } | ||
+ | |||
+ | local characterImages = {} | ||
+ | |||
+ | function love.load() | ||
+ | for i, opponent in ipairs(opponents) do | ||
+ | characterImages[i] = love.graphics.newImage(opponent.image) | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function drawCharacter(characterImage, x, y, scale) | ||
+ | love.graphics.draw(characterImage, x, y, 0, scale, scale) | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | -- Draw the player character | ||
+ | drawCharacter(characterImages[1], 50, 50, 1) | ||
+ | |||
+ | -- Draw any opponent characters that have been selected | ||
+ | for i, opponent in ipairs(opponents) do | ||
+ | if opponent.selected then | ||
+ | drawCharacter(characterImages[i], 300, 50 * i, 1) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function displayMenu() | ||
+ | -- Print menu options | ||
+ | for i, opponent in ipairs(opponents) do | ||
+ | print(i .. ". Select " .. opponent.name) | ||
+ | end | ||
+ | print("5. Quit") | ||
+ | |||
+ | -- Get user choice | ||
+ | io.write("Enter your choice: ") | ||
+ | local choice = io.read() | ||
+ | choice = tonumber(choice) | ||
+ | |||
+ | -- Perform actions based on choice | ||
+ | if choice == 1 then | ||
+ | opponents[1].selected = true | ||
+ | elseif choice == 2 then | ||
+ | opponents[2].selected = true | ||
+ | elseif choice == 3 then | ||
+ | opponents[3].selected = true | ||
+ | elseif choice == 4 then | ||
+ | opponents[4].selected = true | ||
+ | elseif choice == 5 then | ||
+ | love.event.quit() | ||
+ | else | ||
+ | print("Invalid choice. Please try again.") | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function love.update(dt) | ||
+ | -- Display menu | ||
+ | displayMenu() | ||
+ | end |
Revision as of 18:42, 1 May 2024
local opponents = {
{name = "Itadori", image = "characters/itadori.png", selected = false}, {name = "Megumi", image = "characters/megumi.png", selected = false}, {name = "Nobara", image = "characters/nobara.png", selected = false}, {name = "Choso", image = "characters/choso.png", selected = false}
}
local player = {
name = "Your Character", level = 1
}
local characterImages = {}
function love.load()
for i, opponent in ipairs(opponents) do characterImages[i] = love.graphics.newImage(opponent.image) end
end
function drawCharacter(characterImage, x, y, scale)
love.graphics.draw(characterImage, x, y, 0, scale, scale)
end
function love.draw()
-- Draw the player character drawCharacter(characterImages[1], 50, 50, 1)
-- Draw any opponent characters that have been selected for i, opponent in ipairs(opponents) do if opponent.selected then drawCharacter(characterImages[i], 300, 50 * i, 1) end end
end
function displayMenu()
-- Print menu options for i, opponent in ipairs(opponents) do print(i .. ". Select " .. opponent.name) end print("5. Quit")
-- Get user choice io.write("Enter your choice: ") local choice = io.read() choice = tonumber(choice)
-- Perform actions based on choice if choice == 1 then opponents[1].selected = true elseif choice == 2 then opponents[2].selected = true elseif choice == 3 then opponents[3].selected = true elseif choice == 4 then opponents[4].selected = true elseif choice == 5 then love.event.quit() else print("Invalid choice. Please try again.") end
end
function love.update(dt)
-- Display menu displayMenu()
end