├── bgs.png ├── Digimon1.png ├── shitsing.wav ├── DigimonText.png ├── digimonNIGHTMARE1.png ├── digimonNIGHTMARE2.png ├── digimonNIGHTMARE3.png ├── digimonNIGHTMARE1Flip.png ├── .vscode └── settings.json ├── README.md ├── debugTools ├── digiCare ├── timeTools ├── webTools ├── gfx └── main.lua /bgs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/bgs.png -------------------------------------------------------------------------------- /Digimon1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/Digimon1.png -------------------------------------------------------------------------------- /shitsing.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/shitsing.wav -------------------------------------------------------------------------------- /DigimonText.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/DigimonText.png -------------------------------------------------------------------------------- /digimonNIGHTMARE1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/digimonNIGHTMARE1.png -------------------------------------------------------------------------------- /digimonNIGHTMARE2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/digimonNIGHTMARE2.png -------------------------------------------------------------------------------- /digimonNIGHTMARE3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/digimonNIGHTMARE3.png -------------------------------------------------------------------------------- /digimonNIGHTMARE1Flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teru-dot-png/RG_Digimon/HEAD/digimonNIGHTMARE1Flip.png -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Lua.diagnostics.globals": [ 3 | "gdt", 4 | "flush", 5 | "poop" 6 | ] 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RG_Digimon 2 | 3 | Welcome to RG_Digimon, a Digivice virtual pet game created in Lua using the Retrogadgets engine! 4 | 5 | ![image](https://user-images.githubusercontent.com/68662335/232682871-8e7c556d-0a6b-488f-8b2b-53100b1ee99a.png) 6 | 7 | ## Game Description/Hardware 8 | 9 | In this game, you will be raising and training your own Digimon virtual pet. The Digivice is equipped with 3 buttons, 1 network card, 1 CPU, 1 GPU, 1 audio chip, 1 flash memory, and 1 ROM. 10 | 11 | ![image](https://user-images.githubusercontent.com/68662335/232683044-422f7368-aecc-4105-9aa8-0ba79007a3a0.png) ![image](https://user-images.githubusercontent.com/68662335/232683065-1286de71-c387-40cf-8ad1-1d606bdde8e1.png) ![image](https://user-images.githubusercontent.com/68662335/232683119-6f298486-7f0c-4e14-95a3-148b06bd0561.png) ![image](https://user-images.githubusercontent.com/68662335/232683176-496f96ae-7a3e-4b3e-8b61-cc29cd62627e.png) ![image](https://user-images.githubusercontent.com/68662335/232683227-da662ed0-3550-4bf5-bf73-8237b9570c60.png) 12 | 13 | 14 | 15 | 16 | 17 | 18 | ## Development 19 | 20 | This game was created using Lua and the Retrogadgets engine. If you are interested in contributing to the development of this game, feel free to submit a pull request or open an issue on the GitHub repository. 21 | 22 | ![image](https://user-images.githubusercontent.com/68662335/232682804-a6517b52-b982-47ac-909a-cf105f5db2e9.png) 23 | 24 | ## Acknowledgements 25 | 26 | Special thanks to the Retrogadgets team for creating the "engine" used to create this game. 27 | 28 | ![image](https://user-images.githubusercontent.com/68662335/232682627-d5a734bd-a290-40e6-9ece-6a9efdd77bb4.png) 29 | -------------------------------------------------------------------------------- /debugTools: -------------------------------------------------------------------------------- 1 | local debugTools = {} -- create an empty table to store the functions 2 | 3 | function debugTools.debugPrint(time, debugB, level, ...) 4 | -- Only show debugging messages if the `debug` flag is set to `true` 5 | if debugB then 6 | -- Add timestamps to the output 7 | if time == nil then 8 | timestamp = "[nil:nil:nil]" 9 | else 10 | timestamp = string.format("[%02d:%02d:%02d]", time.hours, time.minutes, time.seconds) 11 | end 12 | 13 | if level == "error" then 14 | setFgColor(91) -- red 15 | print(timestamp, "ERROR:") 16 | setFgColor(39) -- default color 17 | print(...) 18 | elseif level == "warning" then 19 | setFgColor(93) -- yellow 20 | print(timestamp, "WARNING:") 21 | setFgColor(39) -- default color 22 | print(...) 23 | elseif level == "info" then 24 | setFgColor(92) -- green 25 | print(timestamp, "INFO:") 26 | setFgColor(39) -- default color 27 | print(...) 28 | elseif level == "debug" then 29 | setFgColor(94) -- blue 30 | print(timestamp, "DEBUG:") 31 | setFgColor(39) -- default color 32 | print(...) 33 | elseif level == "time" then 34 | setFgColor(95) -- magenta 35 | print(timestamp) 36 | setFgColor(39) -- default color 37 | elseif level == "digimon" then 38 | setFgColor(33) -- magenta 39 | print(timestamp, "DIGIMON:") 40 | setFgColor(39) -- default color 41 | print(...) 42 | else 43 | setFgColor(91) -- red 44 | print(timestamp, "UNKNOWN:") 45 | setFgColor(39) -- default color 46 | print(...) 47 | end 48 | end 49 | end 50 | 51 | return debugTools -- return the table containing the functions 52 | -------------------------------------------------------------------------------- /digiCare: -------------------------------------------------------------------------------- 1 | --! Hardware 2 | local cpu:CPU = gdt.CPU0 3 | local vid:VideoChip = gdt.VideoChip0 -- graphics chip 4 | local web:Wifi = gdt.Wifi0 -- wifi web conectivity 5 | 6 | --! Assets 7 | local menuSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.Digimon1 -- Menu Sprites for main game 8 | local bgs:SpriteSheet = gdt.ROM.User.SpriteSheets.bgs -- Background sprites for the game 9 | local digimonSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1 -- digimon Sprites looking left 10 | local digimonSpritesFlip:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1Flip -- digimon Sprites looking right 11 | local shitsing:AudioSample = gdt.ROM.User.AudioSamples["shitsing.wav"] 12 | local flushing:AudioSample = gdt.ROM.User.AudioSamples["flushing.wav"] 13 | local bootsnd:AudioSample = gdt.ROM.User.AudioSamples["boot.wav"] 14 | 15 | 16 | --! Code modules 17 | local timeTools = require("timeTools") 18 | local gfx = require("gfx") 19 | local dt = require("debugTools") 20 | local debugPrint = dt.debugPrint 21 | local createTimer = timeTools.createTimer 22 | 23 | 24 | 25 | local digiCare = {} 26 | 27 | function digiCare.stats() 28 | 29 | debugPrint(nil,true,"warning","WIP NOT FINISHED") 30 | 31 | end 32 | 33 | 34 | --* this function will handdle the digimon stats and needs 35 | --$ the object this function is attached to is digimon and gdt 36 | function digiCare.digimonHandler(digimon) 37 | -- digimon time counter 38 | digimon.sleepTime0 += gdt.CPU0.DeltaTime 39 | 40 | -- Clamp the value of sleepTime0 to a range of 0 to 28800 (8 hours) 41 | digimon.sleepTime0 = math.clamp(digimon.sleepTime0, 0, 28800) 42 | 43 | --$ Check if the digimon is currently sleeping 44 | if digimon.sleeping then 45 | -- If the digimon has been sleeping for at least 2 hours, set sleeping to false 46 | if digimon.sleepTime0 >= 7200 then 47 | digimon.sleepTime0 -= 7200 48 | digimon.sleeping = false 49 | end 50 | else 51 | -- If the digimon has been awake for at least 8 hours, set sleeping to true 52 | if digimon.sleepTime0 >= 28800 then 53 | digimon.sleepTime0 -= 28800 54 | digimon.sleeping = true 55 | end --$ endof if digimon been awake for 8 hours 56 | end --$ endof digimon.sleeping check 57 | return digimon 58 | end 59 | 60 | --* this function will move the digimon once and a while 61 | --$ the object this function is attached to is digimon 62 | function digiCare.digimonMover(digimon) 63 | 64 | if not digimon.sleeping then 65 | -- random number for looking left or right 66 | digimon.looking = math.random() 67 | 68 | -- if its above 0.5 we move it 5 units else we go back 5 units 69 | if digimon.looking < 0.5 then 70 | 71 | 72 | digimon.pos += vec2(5, 0) 73 | else 74 | 75 | digimon.pos -= vec2(5, 0) 76 | end 77 | end 78 | return digimon 79 | end 80 | 81 | --* we do some colision checking in the rectangle 82 | --* Check if digimon is inside box 83 | --$ the object this function is attached to is digimon 84 | function digiCare.colision(digimon) 85 | -- we check if we moved out of bounds and reset it to wall values 86 | if digimon.pos.X < 0 then 87 | 88 | digimon.pos = vec2(3, 24) 89 | elseif digimon.pos.X > 71 then 90 | 91 | digimon.pos = vec2(60, 24) 92 | end 93 | return digimon 94 | end 95 | 96 | 97 | 98 | 99 | 100 | --* this is like a vibe check but to see if you shat yourself 101 | --$ the object this function is attached to is poop, digimon and gdt 102 | function digiCare.poopCheck(digimon, poop) 103 | 104 | 105 | if not digimon.sleeping then 106 | 107 | --$ check if conditon poop value is 10800, check if condition poop.r is 21 108 | if poop.value >= 10800 then 109 | gdt.AudioChip0:Play(shitsing,1) 110 | poop.r = math.random( 2, 10) 111 | poop.hasHappend = true 112 | poop.value = 0 113 | end -- $ endof if poop condition 114 | end -- $ endof sleep Check 115 | return poop 116 | end 117 | 118 | return digiCare 119 | -------------------------------------------------------------------------------- /timeTools: -------------------------------------------------------------------------------- 1 | 2 | --! Hardware 3 | local cpu:CPU = gdt.CPU0 4 | local vid:VideoChip = gdt.VideoChip0 -- graphics chip 5 | local web:Wifi = gdt.Wifi0 -- wifi web conectivity 6 | 7 | --! Assets 8 | local bgs:SpriteSheet = gdt.ROM.User.SpriteSheets.bgs -- Background sprites for the game 9 | local menuSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.Digimon1 -- Menu Sprites for main game 10 | local digimonSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1 -- digimon Sprites looking left 11 | local digimonSpritesFlip:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1Flip -- digimon Sprites looking right 12 | 13 | --! Code modules 14 | local dt = require("debugTools") 15 | local debugPrint = dt.debugPrint 16 | 17 | 18 | local debugBool = true 19 | 20 | 21 | local timeTools = {} 22 | 23 | 24 | 25 | --* this function will spread the timestamp to the time table 26 | -- @param timestamp_str is the timestamp string 27 | -- @param time is the time table 28 | function spreadTimestamp(timestamp_str, time) 29 | debugPrint(time, debugBool,"info", "timestamp_str: " .. timestamp_str) 30 | -- it should have a time format like this "datetime: 2023-04-17T23:26:15.425179-03:00" it has 32 characters for the timestamp 31 | -- we use the find function to find the datetime: and then we add 9 to get the start of the timestamp 32 | local start = timestamp_str:find("datetime: ") + 10 33 | -- now we use the start and it has 32 characters 34 | local datetime = timestamp_str:sub(start, start + 32) 35 | debugPrint(time, debugBool,"info", "datetime: " .. datetime) 36 | --the pattern is "YYYY-MM-DDTHH:MM:SS.000000-00:00" 37 | -- we use the sub function to get the year, month, day, hour, minute and second 38 | time.years = tonumber(datetime:sub(1, 4)) 39 | debugPrint(time, debugBool,"info", "time.years: " .. datetime:sub(1, 4)) 40 | time.months = tonumber(datetime:sub(6, 7)) 41 | debugPrint(time, debugBool,"info", "time.months: " .. datetime:sub(6, 7)) 42 | time.days = tonumber(datetime:sub(9, 10)) 43 | debugPrint(time, debugBool,"info", "time.days: " .. datetime:sub(9, 10)) 44 | time.hours = tonumber(datetime:sub(12, 13)) 45 | debugPrint(time, debugBool,"info", "time.hours: " .. datetime:sub(12, 13)) 46 | time.minutes = tonumber(datetime:sub(15, 16)) 47 | debugPrint(time, debugBool,"info", "time.minutes: " .. datetime:sub(15, 16)) 48 | time.seconds = tonumber(datetime:sub(18, 19)) 49 | debugPrint(time, debugBool,"info", "time.seconds: " .. datetime:sub(18, 19)) 50 | 51 | return time 52 | end 53 | 54 | 55 | 56 | 57 | 58 | 59 | --* this function will create a timer 60 | -- @param cpu is the cpu object 61 | -- @param interval is the interval of the timer 62 | -- @param func is the function to run 63 | -- @returns the timer object 64 | function timeTools.createTimer(cpu: CPU, interval: number, func: (totalTime: number) -> ()) 65 | local startTime = cpu.Time 66 | local lastInterval = startTime 67 | 68 | return { 69 | update = function() 70 | if(cpu.Time - lastInterval) >= interval then 71 | lastInterval = cpu.Time 72 | func(cpu.Time - startTime) 73 | end 74 | end, 75 | getTotalTime = function() 76 | return cpu.Time - startTime 77 | end, 78 | } 79 | end 80 | 81 | 82 | --* this function will run a function every x times 83 | -- @param func is the function to run 84 | -- @param counting is the counter 85 | -- @param ends is the number of times to run the function 86 | function timeTools.runEvery(func, counting, ends) 87 | if counting == 0 then 88 | -- do something here 89 | func() 90 | end 91 | counting = counting + 1 92 | if counting == ends then 93 | counting = 0 94 | end 95 | return counting 96 | end 97 | 98 | --* this function will increment the time 99 | -- @param time is the time object 100 | -- @returns the time object 101 | --$ the object this function is attached to is time 102 | function timeTools.incrementTime(time: {seconds: number, minutes: number, hours: number, days: number, weeks: number, months: number, years: number}) 103 | time.seconds = time.seconds + 1 104 | 105 | if time.seconds >= 60 then 106 | time.seconds = 0 107 | time.minutes = time.minutes + 1 108 | end 109 | 110 | if time.minutes >= 60 then 111 | time.minutes = 0 112 | time.hours = time.hours + 1 113 | end 114 | 115 | if time.hours >= 24 then 116 | time.hours = 0 117 | time.days = time.days + 1 118 | end 119 | 120 | if time.days >= 7 then 121 | time.days = 0 122 | time.weeks = time.weeks + 1 123 | end 124 | 125 | if time.weeks >= 4 then 126 | time.weeks = 0 127 | time.months = time.months + 1 128 | end 129 | 130 | if time.months >= 12 then 131 | time.months = 0 132 | time.years = time.years + 1 133 | end 134 | 135 | return time 136 | end 137 | 138 | return timeTools 139 | -------------------------------------------------------------------------------- /webTools: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | --! EventCH 5 | gdt.CPU0.EventChannels[1] = gdt.Wifi0 -- Adding the Wifi chip as the first element of this array, so that it can trigger events for the CPU to handle. 6 | --[[ 7 | This line of code initializes a table named handleFuncs, which maps request handles (numbers) 8 | to functions that accept a WifiWebResponseEvent parameter and return nothing 9 | (i.e. (result: WifiWebResponseEvent) -> ()). 10 | This table is used to store functions that should be called when a web request's 11 | response event is received. 12 | 13 | ]]-- 14 | local handleFuncs: {[number]: (result: WifiWebResponseEvent) -> ()} = {} 15 | 16 | 17 | --! Code modules 18 | local digiCare = require("digiCare") 19 | local timeTools = require("timeTools") 20 | local dt = require("debugTools") 21 | local debugPrint = dt.debugPrint 22 | local spreadTimestamp = timeTools.spreadTimestamp 23 | 24 | --! Hardware 25 | local cpu:CPU = gdt.CPU0 26 | local web:Wifi = gdt.Wifi0 -- wifi web conectivity 27 | 28 | --!---------------------------------------------------------------------------- 29 | --!---- EventCH 1 ------------------------------------------------------ 30 | --!---------------------------------------------------------------------------- 31 | --[[ 32 | This function is an event handler for the Wifi module, specifically for the WifiWebResponseEvent. 33 | When this event is triggered, it is passed to this function along with the Wifi module that triggered it. 34 | The function then looks up a function in the handleFuncs table using the RequestHandle from the event as the key. 35 | This function is then called with the event as its argument. Finally, the function stored in handleFuncs 36 | for the given RequestHandle is removed. This allows for the ability to associate a specific function with 37 | a specific web request, allowing for better organization and management of web requests in the code. 38 | ]]-- 39 | -- This function is an event handler for the Wifi module, specifically for the WifiWebResponseEvent. 40 | -- @param wifi: Wifi - The Wifi module that triggered the event. 41 | -- @param event: WifiWebResponseEvent - The event that was triggered. 42 | function eventChannel1(_: Wifi, event: WifiWebResponseEvent) 43 | handleFuncs[event.RequestHandle](event) 44 | handleFuncs[event.RequestHandle] = nil 45 | end 46 | --!---------------------------------------------------------------------------- 47 | 48 | --* this function sends a GET request to the specified URL and stores the provided function to be called when the request completes. 49 | local function fetch(wifi: Wifi, url: string, resultFunc: (response: WifiWebResponseEvent) -> ()) 50 | local handle = wifi:WebGet(url) 51 | handleFuncs[handle] = resultFunc 52 | end 53 | 54 | local debugBool = true 55 | 56 | local webTools = {} 57 | 58 | 59 | --* this function will get the current time from the web 60 | -- @param time is the time table 61 | -- @param web is the web object 62 | -- @param debugBool is a boolean to enable or disable debug prints 63 | --$ this function is dependant on the spreadTimestamp function and the debugPrint function and the fetch function and is conected to theese objects: time, web, debugBool 64 | function webTools.getTimeFromWeb(time) 65 | debugPrint(time, debugBool,"info", "TIME IS UPDATING...") 66 | time.health.updating = true 67 | -- Retrieve the current timestamp from the API 68 | -- Get IP to trow at api 69 | fetch(web, "https://api64.ipify.org/", function(response) 70 | -- print ip response to see if we got the right thing 71 | local ip = response.Text 72 | debugPrint(time, debugBool,"info", "GOT IP", ip ) 73 | if tonumber(ip:sub(1, 1)) then 74 | time.health.condition = true 75 | 76 | fetch(web, "http://worldtimeapi.org/api/ip/" .. ip .. ".txt" , function(response) 77 | --[[ 78 | (... etc ...) is a indicatior that the text is cut off 79 | responds with a text like this: 80 | ... etc ... 81 | datetime: 2023-04-17T23:26:15.425179-03:00 82 | ... etc ... 83 | ]] 84 | print(response.Text) 85 | local time_string = response.Text 86 | debugPrint(time, debugBool,"info","GOT WEBTextTime" ,time_string) 87 | -- here we do a check to see if we got a valid response 88 | singleChar = time_string:sub(1,1) 89 | debugPrint(time, debugBool,"info", "GOT", singleChar) 90 | -- now we check if its we got a valid response by checking if the first character is a "a" cause the response starts with "a" for abreviation 91 | -- if it is we update the time and if not we wait 1 minute and try again 92 | if singleChar == "a" then 93 | time.health.condition = true 94 | debugPrint(time, debugBool,"info", "TIME HAS BEEN UPDATED") 95 | time = spreadTimestamp(time_string, time) 96 | else 97 | time.health.condition = false 98 | -- There was an error with the request 99 | debugPrint(time, debugBool,"error", "WEB Error wait 1 minute\nWe got: ", response.Status, response.Text) 100 | -- we wait 1 minute before trying again 101 | time.health.updating = false 102 | end 103 | end) 104 | else 105 | debugPrint(time, debugBool,"error", "GOT", response.Text) 106 | 107 | end 108 | end) 109 | return time 110 | end 111 | 112 | 113 | 114 | 115 | 116 | 117 | return webTools 118 | -------------------------------------------------------------------------------- /gfx: -------------------------------------------------------------------------------- 1 | --! Hardware 2 | local cpu:CPU = gdt.CPU0 3 | local vid:VideoChip = gdt.VideoChip0 -- graphics chip 4 | local web:Wifi = gdt.Wifi0 -- wifi web conectivity 5 | 6 | --! Assets 7 | local bgs:SpriteSheet = gdt.ROM.User.SpriteSheets.bgs -- Background sprites for the game 8 | local menuSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.Digimon1 -- Menu Sprites for main game 9 | local digimonSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1 -- digimon Sprites looking left 10 | local digimonSpritesFlip:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1Flip -- digimon Sprites looking right 11 | 12 | --! Code modules 13 | local timeTools = require("timeTools") 14 | local dt = require("debugTools") 15 | local debugPrint = dt.debugPrint 16 | local createTimer = timeTools.createTimer 17 | 18 | 19 | --? Background values 20 | local _darkRoom = 5 -- We change to dark room set of sprites 21 | local _paddingX = 8.5 -- Padding for the X 22 | local _paddingY = 16 -- Padding for the Y 23 | local _spot = { 24 | one = 15, -- The first spot of the second bg sprite 25 | two = 15 *2, -- The second spot of the third bg sprite 26 | three = 15 *3, -- The third spot of the fourth bg sprite 27 | four = 15 *4 -- The fourth spot of the fifth bg sprite 28 | } 29 | 30 | local gfx = {} 31 | 32 | --* this function will handdle the digimon sprites 33 | function gfx.drawDigimon(digimon) 34 | 35 | if digimon.sleeping == false then 36 | -- if its looking left or right we use diferent sprites 37 | if digimon.looking < 0.5 then 38 | vid:DrawSprite(digimon.pos, digimonSpritesFlip, 0, 0 + digimon.r, color.white, color.clear) 39 | else 40 | vid:DrawSprite(digimon.pos, digimonSprites, 0, 0 + digimon.r, color.white, color.clear) 41 | end 42 | else 43 | if digimon.looking < 0.5 then 44 | vid:DrawSprite(digimon.pos, digimonSprites, 0, 3, color.white, color.clear) 45 | else 46 | vid:DrawSprite(digimon.pos, digimonSpritesFlip, 0, 3, color.white, color.clear) 47 | end 48 | end 49 | end 50 | 51 | --* draws the cursor at the position 52 | --$ the object this function is attached to is cursor and it uses the vid 53 | function gfx.drawSelSprite(cursor) 54 | vid:DrawSprite(cursor.pos, menuSprites, 5, 1, color.white, color.clear) 55 | end 56 | 57 | --* this function will draw poop if digimon has done the peepee poopoo caacaa 58 | --$ the object this function is attached to is poop, vid and it uses the menuSprites 59 | function gfx.drawPoop(poop) 60 | 61 | if poop.hasHappend then 62 | vid:DrawSprite(poop.pos + vec2(poop.r,0) + vec2(flush.posX - 55,0), menuSprites, 6, poop.anim, color.white, color.clear) 63 | end 64 | end 65 | 66 | --* draws the thing that flushes the shiz 67 | function gfx.drawflush(flush) 68 | 69 | if flush.queue > 0.5 then 70 | vid:DrawSprite(vec2(flush.posX, flush.posY), menuSprites, 4, 3, color.white, color.clear) 71 | vid:DrawSprite(vec2(flush.posX, flush.posY + 16), menuSprites, 4, 3, color.white, color.clear) 72 | end 73 | 74 | end 75 | 76 | 77 | --* This function will draw the background acordingly to the light state 78 | function gfx.drawbg(room) 79 | --$ Checks if lights are on or off 80 | if room.lights then 81 | vid:DrawSprite(vec2(_paddingX, _paddingY), bgs ,0 ,0, color.white, color.clear) 82 | vid:DrawSprite(vec2(_paddingX + _spot.one , _paddingY), bgs ,1 ,0, color.white, color.clear) 83 | vid:DrawSprite(vec2(_paddingX + _spot.two , _paddingY), bgs ,2 ,0, color.white, color.clear) 84 | vid:DrawSprite(vec2(_paddingX + _spot.three , _paddingY), bgs ,3 ,0, color.white, color.clear) 85 | vid:DrawSprite(vec2(_paddingX + _spot.four , _paddingY), bgs ,4 ,0, color.white, color.clear) 86 | 87 | vid:DrawSprite(vec2(_paddingX, _paddingY + _spot.one), bgs ,0 ,1, color.white, color.clear) 88 | vid:DrawSprite(vec2(_paddingX + _spot.one , _paddingY + _spot.one), bgs ,1 ,1, color.white, color.clear) 89 | vid:DrawSprite(vec2(_paddingX + _spot.two , _paddingY + _spot.one), bgs ,2 ,1, color.white, color.clear) 90 | vid:DrawSprite(vec2(_paddingX + _spot.three , _paddingY + _spot.one), bgs ,3 ,1, color.white, color.clear) 91 | vid:DrawSprite(vec2(_paddingX + _spot.four , _paddingY + _spot.one), bgs ,4 ,1, color.white, color.clear) 92 | else 93 | 94 | vid:DrawSprite(vec2(_paddingX, _paddingY), bgs ,0 + _darkRoom ,0, color.white, color.clear) 95 | vid:DrawSprite(vec2(_paddingX + _spot.one , _paddingY), bgs ,1 + _darkRoom ,0, color.white, color.clear) 96 | vid:DrawSprite(vec2(_paddingX + _spot.two , _paddingY), bgs ,2 + _darkRoom ,0, color.white, color.clear) 97 | vid:DrawSprite(vec2(_paddingX + _spot.three , _paddingY), bgs ,3 + _darkRoom ,0, color.white, color.clear) 98 | vid:DrawSprite(vec2(_paddingX + _spot.four , _paddingY), bgs ,4 + _darkRoom ,0, color.white, color.clear) 99 | 100 | vid:DrawSprite(vec2(_paddingX, _paddingY + _spot.one), bgs ,0 + _darkRoom ,1, color.white, color.clear) 101 | vid:DrawSprite(vec2(_paddingX + _spot.one , _paddingY + _spot.one), bgs ,1 + _darkRoom ,1, color.white, color.clear) 102 | vid:DrawSprite(vec2(_paddingX + _spot.two , _paddingY + _spot.one), bgs ,2 + _darkRoom ,1, color.white, color.clear) 103 | vid:DrawSprite(vec2(_paddingX + _spot.three , _paddingY + _spot.one), bgs ,3 + _darkRoom ,1, color.white, color.clear) 104 | vid:DrawSprite(vec2(_paddingX + _spot.four , _paddingY + _spot.one), bgs ,4 + _darkRoom ,1, color.white, color.clear) 105 | end --$ endof room.lights check 106 | 107 | end 108 | 109 | --* this will draw menu sprites 110 | function gfx.drawMenuSprites(digimon, room) 111 | 112 | --$ Check if the room lights are off 113 | if room.lights == false then 114 | -- Check if the digimon is sleeping 115 | if digimon.sleeping == true then 116 | -- If the digimon is sleeping, make zz appear when light off (draw zz sleeping particles in dark) 117 | vid:DrawSprite(digimon.pos + vec2(15, room.r), menuSprites, 6, room.r, color.white, color.clear) 118 | else 119 | -- If the digimon is not sleeping, and lights are of it will get angry (draw "#" angry symbol) 120 | vid:DrawSprite(digimon.pos + vec2(15, room.r), menuSprites, 7, 3, color.white, color.clear) 121 | end 122 | 123 | -- If the room lights are on 124 | else 125 | -- Check if the digimon is sleeping 126 | if digimon.sleeping == true then 127 | -- If the digimon is sleeping, draw (draw zz sleeping particles on a lit room) 128 | vid:DrawSprite(digimon.pos + vec2(15, room.r), menuSprites, 6, room.r, color.white, color.clear) 129 | end 130 | end --$ endof room.lights check 131 | 132 | --! makes the menu borders $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 133 | vid:DrawRect(vec2(7, 15), vec2(70, 47), color.black) 134 | -- two lil cheeky borders on the sides so it hides the digimon 135 | vid:FillRect(vec2(0, 15), vec2(6, 47), Color(0, 4, 25)) 136 | vid:FillRect(vec2(71, 15), vec2(79, 47), Color(0, 4, 25)) 137 | --! $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 138 | 139 | --! Draws the top menu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 140 | vid:DrawSprite(vec2(5, 5), menuSprites, 0, 0, color.white, color.clear) 141 | vid:DrawSprite(vec2(20, 5), menuSprites, 1, 0, color.white, color.clear) 142 | vid:DrawSprite(vec2(35, 5), menuSprites, 2, 0, color.white, color.clear) 143 | vid:DrawSprite(vec2(50, 5), menuSprites, 3, 0, color.white, color.clear) 144 | vid:DrawSprite(vec2(65, 5), menuSprites, 4, 0, color.white, color.clear) 145 | --!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 146 | 147 | --! draw the bottom menu @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 148 | vid:DrawSprite(vec2(5, 50), menuSprites, 0, 1, color.white, color.clear) 149 | vid:DrawSprite(vec2(20, 50), menuSprites, 1, 1, color.white, color.clear) 150 | vid:DrawSprite(vec2(35, 50), menuSprites, 2, 1, color.white, color.clear) 151 | vid:DrawSprite(vec2(50, 50), menuSprites, 3, 1, color.white, color.clear) 152 | vid:DrawSprite(vec2(65, 50), menuSprites, 4, 1, color.white, color.clear) 153 | --!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 154 | end 155 | 156 | function gfx.drawBoot() 157 | vid:Clear(Color(64,51,82)) 158 | vid:DrawSprite(vec2(29,25), menuSprites, 8, 0, color.white, color.clear) 159 | vid:DrawCircle(vec2(38,35),20,color.cyan) 160 | end 161 | 162 | 163 | 164 | 165 | return gfx -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | --! Assets 5 | local menuSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.Digimon1 -- Menu Sprites for main game 6 | local bgs:SpriteSheet = gdt.ROM.User.SpriteSheets.bgs -- Background sprites for the game 7 | local digimonSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1 -- digimon Sprites looking left 8 | local digimonSpritesFlip:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1Flip -- digimon Sprites looking right 9 | local shitsing:AudioSample = gdt.ROM.User.AudioSamples["shitsing.wav"] 10 | local flushing:AudioSample = gdt.ROM.User.AudioSamples["flushing.wav"] 11 | local bootsnd:AudioSample = gdt.ROM.User.AudioSamples["boot.wav"] 12 | 13 | --! Code modules 14 | local digiCare = require("digiCare") 15 | local timeTools = require("timeTools") 16 | local webTools = require("webTools") 17 | local gfx = require("gfx") 18 | local dt = require("debugTools") 19 | local debugPrint = dt.debugPrint 20 | local createTimer = timeTools.createTimer 21 | 22 | 23 | --! Hardware 24 | local cpu:CPU = gdt.CPU0 25 | local vid:VideoChip = gdt.VideoChip0 -- graphics chip 26 | local web:Wifi = gdt.Wifi0 -- wifi web conectivity 27 | local but0 = gdt.LedButton0 -- bottom button 28 | local but1 = gdt.LedButton1 -- mid button 29 | local but2 = gdt.LedButton2 -- top button 30 | 31 | 32 | --? Flag to enable debugging messages 33 | local debugBool = true 34 | 35 | --? keep track of room info 36 | local room = { 37 | lights = true, -- room lights if on then true if off then false 38 | r = 0 -- random number between (1, 0) 39 | } 40 | 41 | --? keep track of time deltas and frames 42 | local timeDlt = { 43 | counter = 0, -- this will keep track of DeltaTime 44 | frameDuration = 1, -- how long in seconds it runs 45 | frameNum = 0 -- keep track of the current frame 46 | } 47 | 48 | --? Time data i cant give info on this its pretty self explanatory 49 | local time = { 50 | seconds = 0, 51 | minutes = 0, 52 | hours = 0, 53 | days = 0, 54 | weeks = 0, 55 | months = 0, 56 | years = 0, 57 | counter = 0, 58 | health = { 59 | condition = false, -- a warning to see if the condition of the time is bad and unupdated 60 | updating = true -- if its updating or not 61 | }} 62 | 63 | --? keep track of digimon position and stats 64 | local digimon = { 65 | pos = vec2(35,24), -- possition of Digimon 66 | r = 0, -- Random value 67 | sleepTime0 = 0, -- Sleep timer 68 | looking = 0, -- facing (0 = left, 1 = right) 69 | sleeping = false -- if its sleeping or not 70 | } 71 | 72 | --? flush data 73 | flush = { 74 | ing = false, -- check if currently "flush-ing" 75 | queue = 0, -- asks a queue if it can flush 76 | posX = 55, -- possition of water 77 | posY = 16 -- possition of water 78 | } 79 | 80 | --? keep track of menu 81 | local menu = { 82 | current = 0, -- current menu from (0, 9) 83 | maxItems = 9, -- max number of items 84 | isInsideMenu = false, -- check if its inside sub menu 85 | isUnselected = false,-- check if its unselected 86 | 87 | 88 | --? Define an array of menu items and their associated actions. 89 | -- (0:info) 90 | -- (1:feed) 91 | -- (2:train) 92 | -- (3:challange) 93 | -- (4:flush) 94 | -- (5:lights) 95 | -- (6:patch) 96 | -- (7:inteligence training) 97 | -- (8:online) 98 | -- (9:wip) 99 | items = { 100 | {name = "info", action = function() 101 | debugPrint(time, debugBool,"info","Menu position 0 selected") 102 | end}, 103 | {name = "feed", action = function() 104 | debugPrint(time, debugBool,"info","Menu position 1 selected") 105 | end}, 106 | {name = "train", action = function() 107 | debugPrint(time, debugBool,"info","Menu position 2 selected") 108 | end}, 109 | {name = "quest", action = function() 110 | debugPrint(time, debugBool,"info","Menu position 3 selected") 111 | end}, 112 | {name = "flush", action = function() 113 | debugPrint(time, debugBool,"info","Menu position 4 selected") 114 | -- if sleeping = true we cant flush 115 | if not digimon.sleeping then 116 | -- if room lights are of theres also no reason to flush 117 | if room.lights then 118 | gdt.AudioChip0:Play(flushing,2) 119 | flush.queue = 1 120 | flush.ing = 1 121 | end 122 | end 123 | end}, 124 | {name = "Lights", action = function() 125 | debugPrint(time, debugBool,"info","Menu position 5 selected") 126 | -- turn on and off room lights 127 | if not room.lights then 128 | room.lights = true 129 | elseif room.lights then 130 | room.lights = false 131 | end 132 | end}, 133 | {name = "Patch", action = function() 134 | debugPrint(time, debugBool,"info","Menu position 6 selected") 135 | end}, 136 | {name = "Evo/info Album", action = function() 137 | debugPrint(time, debugBool,"info","Menu position 7 selected") 138 | end}, 139 | {name = "Online", action = function() 140 | debugPrint(time, debugBool,"info","Menu position 8 selected") 141 | end}, 142 | {name = "Alert", action = function() 143 | debugPrint(time, debugBool,"info","Menu position 9 selected") 144 | end}, 145 | }, 146 | 147 | -- This is a method of the `menu` object. It iterates over the `items` array and 148 | -- executes the appropriate action based on the value of the `current` property. 149 | select = function(self) 150 | for i, item in ipairs(self.items) do 151 | if self.current == i - 1 then 152 | item.action() 153 | end 154 | end 155 | end 156 | } 157 | 158 | --? keep track of position of selector 159 | local cursor = { 160 | pos = vec2(0,5), -- possition of the cursor 161 | posX = 0, -- X possition of the cursor 162 | posY = 5 -- Y possition of the cursor 163 | } 164 | 165 | 166 | 167 | 168 | --? as much as i dont want to we need to keep track of poop 169 | local poop = { 170 | r = 0,-- random number from 0, 10000 171 | value = 0, -- time until digimon shits itself 172 | hasHappend = false, -- if it has shat itself 173 | anim = 0, -- number between 1, 0 174 | pos = vec2(35, 35) -- shit position 175 | } 176 | 177 | 178 | 179 | 180 | 181 | 182 | --* this function handles the cursor position 183 | --$ the object this function is attached to is menu and cursor 184 | function CursorHandler() 185 | -- everytime the button is clicked 186 | menu.current += 1 -- menu position add 1 187 | cursor.pos += vec2(15,0) -- move the position to 15 units 188 | 189 | -- if the cursor position is over the screen we go to next 190 | if cursor.pos.X > 60 then 191 | cursor.pos = vec2(0, 50) 192 | end 193 | 194 | -- if its over the max options we go bac 195 | if menu.current > menu.maxItems then 196 | -- reseting positions 197 | menu.current = 0 198 | cursor.pos = vec2(0,5) 199 | end 200 | end 201 | 202 | 203 | 204 | 205 | 206 | --* this function checks if we made a request to flush 207 | --$ the object this function is attached to is flush, poop and it uses debugprint 208 | function flushPoop() 209 | --* check if we made a flush request 210 | if flush.queue > 0.5 then 211 | 212 | -- move the water left 213 | flush.posX += -10 214 | 215 | 216 | --$ if flush moved out of screen we set all values to default 217 | if flush.posX < 2 then 218 | flush.queue = 0 219 | flush.posX = 55 220 | flush.ing = false 221 | if poop.hasHappend then 222 | 223 | poop.hasHappend = false 224 | poop.value = 0 225 | debugPrint(time, debugBool,"info", "poop has been flushed") 226 | else 227 | debugPrint(time, debugBool,"info", "pressed flush with no shit") -- what a funny print 228 | end 229 | --$ endof poophashappend 230 | end 231 | --$ endof posX check 232 | end 233 | --$ endof flushqueue 234 | end 235 | 236 | 237 | 238 | 239 | 240 | --* this variable will count up to 8004 and then reset to 0 to run the time update 241 | local webtimeC = 0 242 | 243 | 244 | local timer = createTimer( 245 | gdt.CPU0, 246 | 0.5, 247 | function() 248 | webtimeC = timeTools.runEvery(function() 249 | time = webTools.getTimeFromWeb(time) 250 | end, 251 | webtimeC, 252 | 8004 -- 2 hours and 13 minutes 253 | ) 254 | time = timeTools.incrementTime(time) 255 | -- add 1 to the poop value 256 | poop.value += 1 257 | -- keeps track of time 258 | -- timeTracker() 259 | digimon.r = math.random(0, 1) 260 | poop.anim = math.random(2, 3) 261 | room.r = math.random(0, 1) 262 | digimon = digiCare.digimonMover(digimon) 263 | flushPoop() 264 | 265 | end 266 | ) 267 | 268 | 269 | local debugTimer = createTimer( 270 | gdt.CPU0, 271 | 5, 272 | function() 273 | --todo| info about positions for debugging 274 | debugPrint(time, debugBool,"digimon", "Digimon", "X" .. digimon.pos.X, "Y" .. digimon.pos.Y ) 275 | debugPrint(time, debugBool,"debug", "Cursor", "X".. cursor.pos.X, "Y".. cursor.pos.Y, "Menu:", menu.current) 276 | 277 | 278 | 279 | 280 | --$ check if condition of time health is ok 281 | if not time.health.condition and time.health.updating then 282 | debugPrint(time, debugBool,"warning", "TimeNotStarted/NotUpdated YOU ARE OFFLINE") 283 | local countRestart = 0 284 | countRestart += 1 285 | if countRestart == 12 then 286 | time = webTools.getTimeFromWeb(time) 287 | end 288 | end --$ endof timeHealth check 289 | end) 290 | 291 | local boot = false 292 | --! ################################################ 293 | --! ######## MAIN GAME LOOP ######################## 294 | --! ################################################ 295 | function update() 296 | 297 | if not boot then 298 | gdt.AudioChip0:Play(bootsnd,1) 299 | gfx.drawBoot() 300 | sleep(2) 301 | boot = true 302 | end 303 | --! important updater 304 | timer.update() 305 | debugTimer.update() 306 | -- clears the screen 307 | vid:Clear(Color(18,14,32)) 308 | -- draws the background 309 | gfx.drawbg(room) 310 | 311 | 312 | -- increase the counter by the CPU's DeltaTime 313 | timeDlt.counter += gdt.CPU0.DeltaTime 314 | 315 | -- does colision for digimon 316 | digimon = digiCare.colision(digimon) 317 | 318 | -- handdler for digimon stuff 319 | digimon = digicare.digimonHandler(digimon) 320 | 321 | -- checks if you shat yourself 322 | poop = digiCare.poopCheck(digimon, poop) 323 | 324 | -- draw funny poopoo.... uhhhh 325 | gfx.drawPoop(poop) 326 | 327 | -- draws the little waves to flush shit 328 | gfx.drawflush(flush) 329 | 330 | -- draws the digimon 331 | gfx.drawDigimon(digimon) 332 | 333 | -- this function will draw the menu sprites 334 | gfx.drawMenuSprites(digimon, room) 335 | 336 | -- draws the cursor 337 | gfx.drawSelSprite(cursor) 338 | 339 | 340 | if but2.ButtonDown then 341 | if flush.ing == false and room.lights == true then 342 | -- every time we exec this cursor moves to apropiate place 343 | -- cycle tru menu 344 | CursorHandler() 345 | end 346 | end 347 | 348 | if but1.ButtonDown then 349 | -- selects the item you where hovered over 350 | menu:select() 351 | end 352 | 353 | if but0.ButtonDown then 354 | -- debug shityourself button 355 | poop.value += 5000 356 | -- digimon.pos += vec2(4, 0) 357 | -- digimon.sleepTime0 += 28799 358 | --if not debugBool then 359 | -- debugBool = true 360 | --elseif debugBool then 361 | -- debugBool = false 362 | --end 363 | end 364 | 365 | 366 | 367 | 368 | 369 | -- Time tracker 370 | local elapsed = timer.getTotalTime() 371 | end --------------------------------------------------------------------------------