mirror of
				https://github.com/LDDestroier/CC/
				synced 2025-10-31 15:32:59 +00:00 
			
		
		
		
	Prettied it up
This commit is contained in:
		
							
								
								
									
										44
									
								
								dodge.lua
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								dodge.lua
									
									
									
									
									
								
							| @@ -9,14 +9,18 @@ | |||||||
| --]] | --]] | ||||||
|  |  | ||||||
| local scr_x, scr_y = term.getSize() | local scr_x, scr_y = term.getSize() | ||||||
| local keysDown = {} --holds all pressed keys. It's way better than using "key" event for movement | local keysDown = {} -- holds all pressed keys. It's way better than using "key" event for movement | ||||||
| local walls = {}    --holds all screen data for walls. I could do slants if I wanted, not just walls | local walls = {}    -- holds all screen data for walls. I could do slants if I wanted, not just walls | ||||||
| local frame = 0     --for every screen update-oh, you know what a frame is | local frame = 0     -- for every screen update-oh, you know what a frame is | ||||||
| local maxFrame = 26 --max frames until new wall | local maxFrame = 26 -- max frames until new wall | ||||||
| local fframe = 0    --not a typo. is the buffer of spaces until the spaces between walls shrinks | local fframe = 0    -- not a typo. is the buffer of spaces until the spaces between walls shrinks | ||||||
| local maxFFrame = 6 --max fframes until the space between walls gets slightly tighter (down to 5, good luck m8) | local maxFFrame = 6 -- max fframes until the space between walls gets slightly tighter (down to 5, good luck m8) | ||||||
| local pause = false --pausing is a nice thing | local pause = false -- pausing is a nice thing | ||||||
| local tsv = term.current().setVisible --it is my belief that monitors and normal computers do not have the setVisible method for term.current() | local tsv = function(visible) -- monitors don't have term.current().setVisible, damn you | ||||||
|  | 	if term.current().setVisible then | ||||||
|  | 		term.current().setVisible(visible) | ||||||
|  | 	end | ||||||
|  | end | ||||||
| for a = 1, scr_x do | for a = 1, scr_x do | ||||||
| 	table.insert(walls,{top=1,bottom=scr_y,color=colors.black}) | 	table.insert(walls,{top=1,bottom=scr_y,color=colors.black}) | ||||||
| end | end | ||||||
| @@ -65,7 +69,7 @@ local trymove = function(dir) | |||||||
| end | end | ||||||
|  |  | ||||||
| local render = function() | local render = function() | ||||||
| 	if tsv then tsv(false) end | 	tsv(false) | ||||||
| 	term.setBackgroundColor(colors.white) | 	term.setBackgroundColor(colors.white) | ||||||
| 	term.setTextColor(colors.white) | 	term.setTextColor(colors.white) | ||||||
| 	term.clear() | 	term.clear() | ||||||
| @@ -78,11 +82,11 @@ local render = function() | |||||||
| 	term.clearLine() | 	term.clearLine() | ||||||
| 	for x = 1, #walls do | 	for x = 1, #walls do | ||||||
| 		term.setBackgroundColor(walls[x].color) | 		term.setBackgroundColor(walls[x].color) | ||||||
| 		for y = 1, walls[x].top do | 		for y = 2, walls[x].top do | ||||||
| 			term.setCursorPos(x,y) | 			term.setCursorPos(x,y) | ||||||
| 			term.write(" ") | 			term.write(" ") | ||||||
| 		end | 		end | ||||||
| 		for y = walls[x].bottom, scr_y do | 		for y = walls[x].bottom, scr_y - 1 do | ||||||
| 			term.setCursorPos(x,y) | 			term.setCursorPos(x,y) | ||||||
| 			term.write(" ") | 			term.write(" ") | ||||||
| 		end | 		end | ||||||
| @@ -90,7 +94,7 @@ local render = function() | |||||||
| 	term.setCursorPos(2,1) | 	term.setCursorPos(2,1) | ||||||
| 	term.setBackgroundColor(colors.black) | 	term.setBackgroundColor(colors.black) | ||||||
| 	term.write("SCORE: "..score.." | TIME: "..time) | 	term.write("SCORE: "..score.." | TIME: "..time) | ||||||
| 	if tsv then tsv(true) end | 	tsv(true) | ||||||
| end | end | ||||||
|  |  | ||||||
| local keepTime = function() | local keepTime = function() | ||||||
| @@ -113,9 +117,9 @@ local doGame = function() | |||||||
| 				if frame >= maxFrame then | 				if frame >= maxFrame then | ||||||
| 					frame = 0 | 					frame = 0 | ||||||
| 					fframe = fframe + 1 | 					fframe = fframe + 1 | ||||||
| 					ypos = math.random(4,scr_y-3) | 					ypos = math.random(4, scr_y-3) | ||||||
| 					wf = 3 | 					wf = 3 | ||||||
| 					randomcol = 2^math.random(1,14) | 					randomcol = 2^math.random(1, 14) | ||||||
| 				end | 				end | ||||||
| 				if wf > 0 then | 				if wf > 0 then | ||||||
| 					wf = wf - 1 | 					wf = wf - 1 | ||||||
| @@ -123,7 +127,7 @@ local doGame = function() | |||||||
| 				if not term.isColor() then | 				if not term.isColor() then | ||||||
| 					randomcol = colors.black --Shame. | 					randomcol = colors.black --Shame. | ||||||
| 				end | 				end | ||||||
| 				addNewWall(ypos-gap,ypos+gap,randomcol) | 				addNewWall(ypos-gap, ypos+gap, randomcol) | ||||||
| 			else | 			else | ||||||
| 				frame = frame + 1 | 				frame = frame + 1 | ||||||
| 				addNewWall(1,scr_y,colors.black) | 				addNewWall(1,scr_y,colors.black) | ||||||
| @@ -147,8 +151,8 @@ local doGame = function() | |||||||
| 			end | 			end | ||||||
| 			render() | 			render() | ||||||
| 		end | 		end | ||||||
| 		sleep(0) | 		sleep(0.05) | ||||||
| 		if guyY<=walls[guyX].top or guyY>=walls[guyX].bottom then | 		if guyY <= walls[guyX].top or guyY >= walls[guyX].bottom then | ||||||
| 			return "dead" | 			return "dead" | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| @@ -169,7 +173,7 @@ local getInput = function() | |||||||
| 						"Paused. Press 'P' to resume", | 						"Paused. Press 'P' to resume", | ||||||
| 						"The game is paused", | 						"The game is paused", | ||||||
| 						"GAME PAUSE !", | 						"GAME PAUSE !", | ||||||
| 						"What, gotta catch your breath??", | 						"What, gotta catch your breath?", | ||||||
| 						"Paused, the game is, hmmm?", | 						"Paused, the game is, hmmm?", | ||||||
| 						"PAUSED GAME", | 						"PAUSED GAME", | ||||||
| 						"GAME PAUSED", | 						"GAME PAUSED", | ||||||
| @@ -179,8 +183,6 @@ local getInput = function() | |||||||
| 						"UNPAUSE WITH 'P'", | 						"UNPAUSE WITH 'P'", | ||||||
| 						"Tip: press UP to go up", | 						"Tip: press UP to go up", | ||||||
| 						"Tip: press DOWN to go down", | 						"Tip: press DOWN to go down", | ||||||
| 						"Tip: read Narbonic comic, you tool", |  | ||||||
| 						"Tip: read Skin Horse comic, you twat", |  | ||||||
| 						"YOU HAVE NO CHANCE TO SURVIVE MAKE YOUR TIME", | 						"YOU HAVE NO CHANCE TO SURVIVE MAKE YOUR TIME", | ||||||
| 						"-PAUSED-", | 						"-PAUSED-", | ||||||
| 						"=PAUSED=", | 						"=PAUSED=", | ||||||
| @@ -203,7 +205,7 @@ local getInput = function() | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local uut = parallel.waitForAny(getInput,doGame,keepTime) | local uut = parallel.waitForAny(getInput, doGame, keepTime) | ||||||
| if uut == 2 then | if uut == 2 then | ||||||
| 	renderTEXT() | 	renderTEXT() | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier