|
| 1 | +GAME_STATES = { |
| 2 | + MAIN_MENU = "main_menu", |
| 3 | + TEAM_SETUP = "team_setup", |
| 4 | + DRIVER_MANAGEMENT = "driver_management", |
| 5 | + CAR_UPGRADES = "car_upgrades", |
| 6 | + RACE_SETUP = "race_setup", |
| 7 | + RACE = "race", |
| 8 | + RESULTS = "results", |
| 9 | + OPTIONS = "options" |
| 10 | +} |
1 | 11 |
|
| 12 | +currentState = GAME_STATES.MAIN_MENU |
| 13 | + |
| 14 | +playerTeam = createTeam("Your Team") |
| 15 | + |
| 16 | +opponents = {} |
| 17 | +raceLaps = 50 |
| 18 | +currentLap = 0 |
| 19 | +positions = {} |
| 20 | +tireTypes = { "Soft", "Medium", "Hard" } |
| 21 | +playerTireChoice = "Medium" |
| 22 | +playerPitStops = 1 |
| 23 | +raceEvents = {} |
| 24 | + |
| 25 | +function initGame() |
| 26 | + generateOpponents(8) |
| 27 | +end |
| 28 | + |
| 29 | +function updateGame(dt) |
| 30 | + if currentState == GAME_STATES.RACE then |
| 31 | + if currentLap < raceLaps then |
| 32 | + simulateLap() |
| 33 | + else |
| 34 | + currentState = GAME_STATES.RESULTS |
| 35 | + end |
| 36 | + end |
| 37 | +end |
| 38 | + |
| 39 | +function drawGame() |
| 40 | + love.graphics.setColor(1, 1, 1) |
| 41 | + |
| 42 | + if currentState == GAME_STATES.MAIN_MENU then |
| 43 | + drawMainMenu() |
| 44 | + elseif currentState == GAME_STATES.TEAM_SETUP then |
| 45 | + drawTeamSetup() |
| 46 | + elseif currentState == GAME_STATES.DRIVER_MANAGEMENT then |
| 47 | + drawDriverManagement() |
| 48 | + elseif currentState == GAME_STATES.CAR_UPGRADES then |
| 49 | + drawCarUpgrades() |
| 50 | + elseif currentState == GAME_STATES.RACE_SETUP then |
| 51 | + drawRaceSetup() |
| 52 | + elseif currentState == GAME_STATES.RACE then |
| 53 | + drawRace() |
| 54 | + elseif currentState == GAME_STATES.RESULTS then |
| 55 | + drawResults() |
| 56 | + elseif currentState == GAME_STATES.OPTIONS then |
| 57 | + drawOptions() |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +function handleKeyPress(key) |
| 62 | + if key == "q" then |
| 63 | + love.event.quit() |
| 64 | + end |
| 65 | + |
| 66 | + if currentState == GAME_STATES.MAIN_MENU then |
| 67 | + if key == "1" then currentState = GAME_STATES.TEAM_SETUP |
| 68 | + elseif key == "2" then currentState = GAME_STATES.DRIVER_MANAGEMENT |
| 69 | + elseif key == "3" then currentState = GAME_STATES.CAR_UPGRADES |
| 70 | + elseif key == "4" then currentState = GAME_STATES.RACE_SETUP |
| 71 | + elseif key == "5" then currentState = GAME_STATES.OPTIONS |
| 72 | + end |
| 73 | + elseif currentState == GAME_STATES.TEAM_SETUP then |
| 74 | + -- Tutaj obsługa klawiszy dla setupu zespołu |
| 75 | + if key == "m" then currentState = GAME_STATES.MAIN_MENU end |
| 76 | + elseif currentState == GAME_STATES.DRIVER_MANAGEMENT then |
| 77 | + if key == "1" then upgradeDriver(1, "speed") |
| 78 | + elseif key == "2" then upgradeDriver(1, "reliability") |
| 79 | + elseif key == "3" then upgradeDriver(2, "speed") |
| 80 | + elseif key == "4" then upgradeDriver(2, "reliability") |
| 81 | + elseif key == "m" then currentState = GAME_STATES.MAIN_MENU end |
| 82 | + elseif currentState == GAME_STATES.CAR_UPGRADES then |
| 83 | + if key == "1" then upgradeCar("performance") |
| 84 | + elseif key == "m" then currentState = GAME_STATES.MAIN_MENU end |
| 85 | + elseif currentState == GAME_STATES.RACE_SETUP then |
| 86 | + if key == "1" then playerTireChoice = "Soft" |
| 87 | + elseif key == "2" then playerTireChoice = "Medium" |
| 88 | + elseif key == "3" then playerTireChoice = "Hard" |
| 89 | + elseif key == "+" then playerPitStops = playerPitStops + 1 |
| 90 | + elseif key == "-" and playerPitStops > 0 then playerPitStops = playerPitStops - 1 |
| 91 | + elseif key == "r" then |
| 92 | + startRace() |
| 93 | + currentState = GAME_STATES.RACE |
| 94 | + elseif key == "m" then currentState = GAME_STATES.MAIN_MENU end |
| 95 | + elseif currentState == GAME_STATES.RESULTS then |
| 96 | + if key == "m" then |
| 97 | + awardPrizes() |
| 98 | + currentState = GAME_STATES.MAIN_MENU |
| 99 | + end |
| 100 | + elseif currentState == GAME_STATES.OPTIONS then |
| 101 | + if key == "m" then currentState = GAME_STATES.MAIN_MENU end |
| 102 | + end |
| 103 | +end |
0 commit comments