mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-05 15:00:29 +00:00
Lint whitespace during CI
This commit is contained in:
parent
3f98b2785e
commit
0de5969ec1
3
.github/workflows/main-ci.yml
vendored
3
.github/workflows/main-ci.yml
vendored
@ -37,3 +37,6 @@ jobs:
|
||||
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
|
||||
chmod +x bin/illuaminate
|
||||
bin/illuaminate lint
|
||||
|
||||
- name: Check whitespace
|
||||
run: python3 tools/check-lines.py
|
||||
|
@ -1 +1 @@
|
||||
adventure is a text adventure game for CraftOS. To navigate around the world of adventure, type simple instructions to the interpreter, for example: "go north", "punch tree", "craft planks", "mine coal with pickaxe", "hit creeper with sword"
|
||||
adventure is a text adventure game for CraftOS. To navigate around the world of adventure, type simple instructions to the interpreter, for example: "go north", "punch tree", "craft planks", "mine coal with pickaxe", "hit creeper with sword"
|
||||
|
@ -3,4 +3,4 @@ alias assigns shell commands to run other programs.
|
||||
ex:
|
||||
"alias dir ls" will make the "dir" command run the "ls" program
|
||||
"alias dir" will remove the alias set on "dir"
|
||||
"alias" will list all current aliases.
|
||||
"alias" will list all current aliases.
|
||||
|
@ -2,4 +2,4 @@ Surf the rednet superhighway with "chat", the networked chat program for CraftOS
|
||||
|
||||
ex:
|
||||
"chat host forgecraft" will create a chatroom with the name "forgecraft"
|
||||
"chat join forgecraft direwolf20" will connect to the chatroom with the name "forgecraft", using the nickname "direwolf20"
|
||||
"chat join forgecraft direwolf20" will connect to the chatroom with the name "forgecraft", using the nickname "direwolf20"
|
||||
|
@ -1 +1 @@
|
||||
clear clears the screen.
|
||||
clear clears the screen.
|
||||
|
@ -1,2 +1,2 @@
|
||||
coroutine is a standard Lua5.1 API.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
|
@ -1 +1 @@
|
||||
dance is a program for Turtles. Turtles love to get funky.
|
||||
dance is a program for Turtles. Turtles love to get funky.
|
||||
|
@ -14,4 +14,4 @@ disk.getID( drive )
|
||||
Events fired by the disk API:
|
||||
"disk" when a disk or other item is inserted into a disk drive. Argument is the name of the drive
|
||||
"disk_eject" when a disk is removed from a disk drive. Argument is the name of the drive
|
||||
Type "help events" to learn about the event system.
|
||||
Type "help events" to learn about the event system.
|
||||
|
@ -3,4 +3,4 @@ dj plays Music Discs from disk drives attached to the computer.
|
||||
ex:
|
||||
"dj" or "dj play" plays a random disc.
|
||||
"dj play left" plays the disc in the drive on the left of the computer.
|
||||
"dj stop" stops the current disc.
|
||||
"dj stop" stops the current disc.
|
||||
|
@ -2,4 +2,4 @@ drive tells you which disk drive the current or specified directory is located i
|
||||
|
||||
ex:
|
||||
"drive" tell you the disk drive of the current directory.
|
||||
"drive foo" tells you the disk drive of the subdirectory "foo"
|
||||
"drive foo" tells you the disk drive of the subdirectory "foo"
|
||||
|
@ -16,4 +16,4 @@ getDiskID()
|
||||
Events fired by the Disk Drive:
|
||||
"disk" when a disk or other item is inserted into the drive. Argument is the name of the drive.
|
||||
"disk_eject" when a disk is removed from a drive. Argument is the name of the drive.
|
||||
Type "help events" to learn about the event system.
|
||||
Type "help events" to learn about the event system.
|
||||
|
@ -1 +1 @@
|
||||
Mostly harmless.
|
||||
Mostly harmless.
|
||||
|
@ -1,4 +1,4 @@
|
||||
edit is a text editor for creating or modifying programs or text files. After creating a program with edit, type its filename in the shell to run it. You can open any of the builtin programs with edit to learn how to program.
|
||||
|
||||
ex:
|
||||
"edit hello" opens a file called "hello" for editing.
|
||||
"edit hello" opens a file called "hello" for editing.
|
||||
|
@ -1 +1 @@
|
||||
exit will exit the current shell.
|
||||
exit will exit the current shell.
|
||||
|
@ -4,7 +4,7 @@ Type "help gpsapi" for help using GPS functions in lua programs.
|
||||
ex:
|
||||
"gps locate" will connect to nearby GPS servers, and try to determine the position of the computer or turtle.
|
||||
"gps host" will try to determine the position, and host a GPS server if successful.
|
||||
"gps host 10 20 30" will host a GPS server, using the manually entered position 10,20,30.
|
||||
"gps host 10 20 30" will host a GPS server, using the manually entered position 10,20,30.
|
||||
|
||||
Take care when manually entering host positions. If the positions entered into multiple GPS hosts
|
||||
are not consistent, the results of locate calls will be incorrect.
|
||||
are not consistent, the results of locate calls will be incorrect.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Functions in the GPS API:
|
||||
gps.locate( timeout )
|
||||
|
||||
The locate function will send a signal to nearby gps servers, and wait for responses before the timeout. If it receives enough responses to determine this computers position then x, y and z co-ordinates will be returned, otherwise it will return nil. If GPS hosts do not have their positions configured correctly, results will be inaccurate.
|
||||
The locate function will send a signal to nearby gps servers, and wait for responses before the timeout. If it receives enough responses to determine this computers position then x, y and z co-ordinates will be returned, otherwise it will return nil. If GPS hosts do not have their positions configured correctly, results will be inaccurate.
|
||||
|
@ -1 +1 @@
|
||||
hello prints the text "Hello World!" to the screen.
|
||||
hello prints the text "Hello World!" to the screen.
|
||||
|
@ -1,4 +1,4 @@
|
||||
help is the help tool you're currently using.
|
||||
Type "help index" to see all help topics.
|
||||
Type "help" to see the help intro.
|
||||
Type "help helpapi" for information on the help Lua API.
|
||||
Type "help helpapi" for information on the help Lua API.
|
||||
|
@ -2,4 +2,4 @@ id prints the unique identifier of this computer, or a Disk in an attached Disk
|
||||
|
||||
ex:
|
||||
"id" will print this Computers ID and label
|
||||
"id left" will print the ID and label of the disk in the Disk Drive on the left
|
||||
"id left" will print the ID and label of the disk in the Disk Drive on the left
|
||||
|
@ -1,2 +1,2 @@
|
||||
io is a standard Lua5.1 API, reimplemented for CraftOS. Not all the features are availiable.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
|
@ -3,7 +3,7 @@ The keys API contains constants for all the key codes that can be returned by th
|
||||
Example usage:
|
||||
local sEvent, nKey = os.pullEvent()
|
||||
if sEvent == "key" and nKey == keys.enter then
|
||||
-- Do something
|
||||
-- Do something
|
||||
end
|
||||
|
||||
See http://www.minecraftwiki.net/wiki/Key_codes, or the source code, for a complete reference.
|
||||
See http://www.minecraftwiki.net/wiki/Key_codes, or the source code, for a complete reference.
|
||||
|
@ -1 +1 @@
|
||||
ls will list all the directories and files in the current location. Use "type" to find out if an item is a file or a directory.
|
||||
ls will list all the directories and files in the current location. Use "type" to find out if an item is a file or a directory.
|
||||
|
@ -1 +1 @@
|
||||
lua is an interactive prompt for the lua programming language. It's a useful tool for learning the language.
|
||||
lua is an interactive prompt for the lua programming language. It's a useful tool for learning the language.
|
||||
|
@ -1,2 +1,2 @@
|
||||
math is a standard Lua5.1 API.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
|
@ -2,4 +2,4 @@ mkdir creates a directory in the current location.
|
||||
|
||||
ex:
|
||||
"mkdir foo" creates a directory named "foo".
|
||||
"mkdir ../foo" creates a directory named "foo" in the directory above the current directory.
|
||||
"mkdir ../foo" creates a directory named "foo" in the directory above the current directory.
|
||||
|
@ -9,4 +9,4 @@ transmit( channel, replyChannel, message )
|
||||
isWireless()
|
||||
|
||||
Events fired by Modems:
|
||||
"modem_message" when a message is received on an open channel. Arguments are name, channel, replyChannel, message, distance
|
||||
"modem_message" when a message is received on an open channel. Arguments are name, channel, replyChannel, message, distance
|
||||
|
@ -3,4 +3,4 @@ Type "help monitors" for help using monitors as peripherals in lua programs.
|
||||
|
||||
ex:
|
||||
"monitor left hello" will run the "hello" program on the monitor to the left of the computer.
|
||||
"monitor top edit foo" will run the edit program on the top monitor, editing the file "foo".
|
||||
"monitor top edit foo" will run the edit program on the top monitor, editing the file "foo".
|
||||
|
@ -1,2 +1,2 @@
|
||||
multishell is the toplevel program on Advanced Computers which manages background tabs.
|
||||
Type "help shellapi" for information about the shell lua api.
|
||||
Type "help shellapi" for information about the shell lua api.
|
||||
|
@ -23,4 +23,4 @@ os.reboot()
|
||||
Events emitted by the os API:
|
||||
"timer" when a timeout started by os.startTimer() completes. Argument is the token returned by os.startTimer().
|
||||
"alarm" when a time passed to os.setAlarm() is reached. Argument is the token returned by os.setAlarm().
|
||||
Type "help events" to learn about the event system.
|
||||
Type "help events" to learn about the event system.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Functions in the Parallel API:
|
||||
parallel.waitForAny( function1, function2, ... )
|
||||
parallel.waitForAll( function1, function2, ... )
|
||||
These methods provide an easy way to run multiple lua functions simultaneously.
|
||||
These methods provide an easy way to run multiple lua functions simultaneously.
|
||||
|
@ -3,4 +3,4 @@ Functions in the pocket API:
|
||||
pocket.equipBack()
|
||||
pocket.unequipBack()
|
||||
|
||||
When equipping upgrades, it will search your inventory for a suitable upgrade, starting in the selected slot. If one cannot be found then it will check your offhand.
|
||||
When equipping upgrades, it will search your inventory for a suitable upgrade, starting in the selected slot. If one cannot be found then it will check your offhand.
|
||||
|
@ -9,4 +9,4 @@ getPageSize()
|
||||
setCursorPos( x, y )
|
||||
getCursorPos()
|
||||
write( text )
|
||||
endPage()
|
||||
endPage()
|
||||
|
@ -8,4 +8,4 @@ To quickly shutdown a computer, hold Ctrl+S for 1 second.
|
||||
To quickly reboot a computer, hold Ctrl+R for 1 second.
|
||||
|
||||
To learn about the programming APIs availiable, type "apis" or "help apis".
|
||||
If you get stuck, visit the forums at http://www.computercraft.info/ for advice and tutorials.
|
||||
If you get stuck, visit the forums at http://www.computercraft.info/ for advice and tutorials.
|
||||
|
@ -1,2 +1,2 @@
|
||||
reboot will turn the computer off and on again.
|
||||
You can also hold Ctrl+R at any time to quickly reboot.
|
||||
You can also hold Ctrl+R at any time to quickly reboot.
|
||||
|
@ -6,4 +6,4 @@ ex:
|
||||
"redstone set right blue false" turns off the blue wire in the bundled cable on the right redstone output.
|
||||
"redstone pulse front 10 1" emits 10 one second redstone pulses on the front redstone output.
|
||||
|
||||
Type "help redstoneapi" or "help rs" for information on the redstone Lua API.
|
||||
Type "help redstoneapi" or "help rs" for information on the redstone Lua API.
|
||||
|
@ -3,4 +3,4 @@ refuel is a program for Turtles. Refuel will consume items from the inventory as
|
||||
ex:
|
||||
"refuel" will refuel with at most one fuel item
|
||||
"refuel 10" will refuel with at most 10 fuel items
|
||||
"refuel all" will refuel with as many fuel items as possible
|
||||
"refuel all" will refuel with as many fuel items as possible
|
||||
|
@ -1 +1 @@
|
||||
repeat is a program for repeating rednet messages across long distances. To use, connect 2 or more modems to a computer and run the "repeat" program; from then on, any rednet message sent from any computer in wireless range or connected by networking cable to either of the modems will be repeated to those on the other side.
|
||||
repeat is a program for repeating rednet messages across long distances. To use, connect 2 or more modems to a computer and run the "repeat" program; from then on, any rednet message sent from any computer in wireless range or connected by networking cable to either of the modems will be repeated to those on the other side.
|
||||
|
@ -1,2 +1,2 @@
|
||||
shell is the toplevel program which interprets commands and runs program.
|
||||
Type "help shellapi" for information about the shell lua api.
|
||||
Type "help shellapi" for information about the shell lua api.
|
||||
|
@ -1 +1 @@
|
||||
shutdown will turn off the computer.
|
||||
shutdown will turn off the computer.
|
||||
|
@ -1,2 +1,2 @@
|
||||
string is a standard Lua5.1 API.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
|
@ -1,2 +1,2 @@
|
||||
table is a standard Lua5.1 API.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||
|
@ -1 +1 @@
|
||||
time prints the current time of day.
|
||||
time prints the current time of day.
|
||||
|
@ -1 +1 @@
|
||||
type determines the type of a file or directory. Prints "file", "directory" or "does not exist".
|
||||
type determines the type of a file or directory. Prints "file", "directory" or "does not exist".
|
||||
|
@ -1,8 +1,8 @@
|
||||
--[[
|
||||
battleship,
|
||||
|
||||
|
||||
by GopherAtl, 2013
|
||||
|
||||
|
||||
Do whatever you want, just don't judge me by
|
||||
what a mess this code is.
|
||||
--]]
|
||||
@ -17,21 +17,21 @@ local myTurn
|
||||
local targetX,targetY
|
||||
local shipsLeft=5
|
||||
local oppShipsLeft=5
|
||||
|
||||
|
||||
local originalTerm = term.current()
|
||||
|
||||
|
||||
--bounding box of the target grid
|
||||
local targetGridBounds={
|
||||
minX=16, maxX=25,
|
||||
minY=4, maxY=13
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
local function doColor(text,background)
|
||||
term.setTextColor(text)
|
||||
term.setBackgroundColor(background)
|
||||
end
|
||||
|
||||
|
||||
local function doColor_mono(text,background)
|
||||
if text==colors.blue or text==colors.red or text==colors.black or text==colors.lime or background==colors.lightGray then
|
||||
term.setTextColor(colors.black)
|
||||
@ -39,9 +39,9 @@ local function doColor_mono(text,background)
|
||||
else
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.black)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function doScreenColor()
|
||||
if term.isColor() then
|
||||
doColor(colors.white,colors.lightGray)
|
||||
@ -49,16 +49,16 @@ local function doScreenColor()
|
||||
doColor(colors.black,colors.white)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function toGridRef(x,y)
|
||||
return string.sub("ABCDEFGHIJ",x,x)..string.sub("1234567890",y,y)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
if not term.isColor() then
|
||||
doColor=doColor_mono
|
||||
end
|
||||
|
||||
|
||||
local function quit()
|
||||
if openedSide then
|
||||
rednet.close(openedSide)
|
||||
@ -68,7 +68,7 @@ local function quit()
|
||||
print()
|
||||
error()
|
||||
end
|
||||
|
||||
|
||||
local foundModem=false
|
||||
--find modem
|
||||
for k,v in pairs(redstone.getSides()) do
|
||||
@ -81,17 +81,17 @@ for k,v in pairs(redstone.getSides()) do
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if not foundModem then
|
||||
print("You must have a modem to play!")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if action==nil or (action~="join" and action~="host") then
|
||||
print("Invalid parameters. Usage:\n> battleship host\nHosts a game, waits for another computer to join\n> battleship join\nLooks for another game to join")
|
||||
quit()
|
||||
end
|
||||
|
||||
|
||||
--get player name
|
||||
while true do
|
||||
doColor(colors.cyan,colors.black)
|
||||
@ -108,13 +108,13 @@ while true do
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if action=="join" then
|
||||
print("Attempting to join a game...\n(press q to cancel)")
|
||||
while true do
|
||||
local retryTimer=os.startTimer(1);
|
||||
rednet.broadcast("bs join "..myName);
|
||||
|
||||
|
||||
while true do
|
||||
local event,p1,p2,p3=os.pullEvent();
|
||||
if event=="rednet_message" then
|
||||
@ -131,7 +131,7 @@ if action=="join" then
|
||||
end
|
||||
end
|
||||
local joined=false
|
||||
|
||||
|
||||
if opponentID then
|
||||
print("Joining game!")
|
||||
rednet.send(opponentID,"bs start")
|
||||
@ -142,7 +142,7 @@ elseif action=="host" then
|
||||
print("Waiting for challenger...\n(Press q to cancel)")
|
||||
while true do
|
||||
while true do
|
||||
local event,p1,p2=os.pullEvent()
|
||||
local event,p1,p2=os.pullEvent()
|
||||
if event=="rednet_message" then
|
||||
opponent=string.match(p2,"bs join %s*(.+)%s*") if opponent then
|
||||
print("found player, inviting..")
|
||||
@ -154,7 +154,7 @@ elseif action=="host" then
|
||||
quit()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if opponentID then
|
||||
rednet.send(opponentID,"bs accept "..myName)
|
||||
local timeout=os.startTimer(1)
|
||||
@ -166,17 +166,17 @@ elseif action=="host" then
|
||||
elseif event=="timer" and p1==timeout then
|
||||
print("player joined another game. Waiting for another...")
|
||||
opponentID=nil
|
||||
break
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if opponentID then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local ships={
|
||||
{pos=nil,dir="h",size=5,name="carrier",hits=0},
|
||||
{pos=nil,dir="h",size=4,name="battleship",hits=0},
|
||||
@ -184,12 +184,12 @@ local ships={
|
||||
{pos=nil,dir="h",size=3,name="submarine",hits=0},
|
||||
{pos=nil,dir="h",size=2,name="destroyer",hits=0},
|
||||
}
|
||||
|
||||
|
||||
local myShotTable={ {1,1,true},{5,5,false} }
|
||||
local oppShotTable={ }
|
||||
|
||||
|
||||
local myGrid,oppGrid={title=myName},{title=opponent}
|
||||
|
||||
|
||||
--setup grids
|
||||
for i=1,10 do
|
||||
myGrid[i]={}
|
||||
@ -199,8 +199,8 @@ for i=1,10 do
|
||||
oppGrid[i][j]={hit=false,ship=false}
|
||||
end
|
||||
end
|
||||
|
||||
local function drawShipsToGrid(ships,grid)
|
||||
|
||||
local function drawShipsToGrid(ships,grid)
|
||||
for i=1,#ships do
|
||||
local x,y=table.unpack(ships[i].pos)
|
||||
local stepX=ships[i].dir=="h" and 1 or 0
|
||||
@ -211,18 +211,18 @@ local function drawShipsToGrid(ships,grid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function drawShotToGrid(shot,grid)
|
||||
grid[shot[1]][shot[2]].shot=true
|
||||
grid[shot[1]][shot[2]].hit=shot[3]
|
||||
grid[shot[1]][shot[2]].hit=shot[3]
|
||||
end
|
||||
|
||||
|
||||
local function makeShot(x,y,grid)
|
||||
local tile=grid[x][y]
|
||||
if tile.shot==true then
|
||||
return nil --already shot here!
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local shot={x,y,tile.ship}
|
||||
drawShotToGrid(shot,grid)
|
||||
if tile.ship then
|
||||
@ -232,12 +232,12 @@ local function makeShot(x,y,grid)
|
||||
end
|
||||
end
|
||||
return shot
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
local function drawTile(scrX,scrY,tile)
|
||||
term.setCursorPos(scrX,scrY)
|
||||
|
||||
|
||||
if tile.ship then
|
||||
if tile.shot then
|
||||
doColor(colors.red,colors.gray)
|
||||
@ -259,31 +259,31 @@ local function drawTile(scrX,scrY,tile)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function drawGrid(scrX,scrY,grid)
|
||||
doColor(colors.white,colors.black)
|
||||
term.setCursorPos(scrX,scrY+1)
|
||||
term.write(" ")
|
||||
doColor(colors.white,colors.gray)
|
||||
doColor(colors.white,colors.gray)
|
||||
term.setCursorPos(scrX,scrY)
|
||||
local pad=11-#grid.title
|
||||
term.write(string.rep(" ",math.ceil(pad/2))..grid.title..string.rep(" ",math.floor(pad/2)))
|
||||
|
||||
|
||||
for gx=1,10 do
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setCursorPos(scrX+gx,scrY+1)
|
||||
term.write(gx==10 and "0" or string.char(string.byte("0")+gx))
|
||||
|
||||
|
||||
term.setCursorPos(scrX,scrY+gx+1)
|
||||
term.write(string.char(string.byte("A")+gx-1))
|
||||
for gy=1,10 do
|
||||
drawTile(scrX+gx,scrY+gy+1,grid[gx][gy])
|
||||
drawTile(scrX+gx,scrY+gy+1,grid[gx][gy])
|
||||
end
|
||||
end
|
||||
doColor(colors.white,colors.black)
|
||||
end
|
||||
|
||||
|
||||
function moveTargetIndicator(newX,newY)
|
||||
--if x has changed...
|
||||
if targetX and targetY then
|
||||
@ -303,8 +303,8 @@ function moveTargetIndicator(newX,newY)
|
||||
term.write("^")
|
||||
term.setCursorPos(targetGridBounds.minX+newX-1,targetGridBounds.minY-3)
|
||||
term.write("v")
|
||||
|
||||
targetX=newX
|
||||
|
||||
targetX=newX
|
||||
end
|
||||
if newY~=targetY then
|
||||
--space over old
|
||||
@ -319,11 +319,11 @@ function moveTargetIndicator(newX,newY)
|
||||
term.write("<")
|
||||
term.setCursorPos(targetGridBounds.minX-2,targetGridBounds.minY+newY-1)
|
||||
term.write(">")
|
||||
|
||||
|
||||
targetY=newY
|
||||
end
|
||||
term.setCursorPos(15,15)
|
||||
term.write("Target : "..toGridRef(targetX,targetY))
|
||||
term.write("Target : "..toGridRef(targetX,targetY))
|
||||
--if the target tile is a valid target, draw a "+"
|
||||
if not oppGrid[targetX][targetY].shot then
|
||||
term.setCursorPos(targetX+targetGridBounds.minX-1,targetY+targetGridBounds.minY-1)
|
||||
@ -331,18 +331,18 @@ function moveTargetIndicator(newX,newY)
|
||||
term.write("+")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local log={}
|
||||
|
||||
|
||||
local termWidth,termHeight=term.getSize()
|
||||
|
||||
|
||||
local logHeight=termHeight-3
|
||||
local logWidth=termWidth-28
|
||||
|
||||
|
||||
for i=1,logHeight do
|
||||
log[i]=""
|
||||
end
|
||||
|
||||
|
||||
local function printLog()
|
||||
doColor(colors.white,colors.black)
|
||||
for i=1,logHeight do
|
||||
@ -358,9 +358,9 @@ local function printLog()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--shipX/Y are the position of ship on grid; gridX/Y are the offset of the top-left of grid
|
||||
local function drawShip(size,align,x,y,char)
|
||||
local stepX=align=="h" and 1 or 0
|
||||
@ -371,31 +371,31 @@ local function drawShip(size,align,x,y,char)
|
||||
x,y=x+stepX,y+stepY
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function setStatusLine(lineNum,text)
|
||||
doScreenColor()
|
||||
local pad=math.floor((termWidth-#text)/2)
|
||||
term.setCursorPos(1,16+lineNum)
|
||||
term.write((" "):rep(pad)..text..(" "):rep(termWidth-#text-pad))
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
doScreenColor()
|
||||
term.clear()
|
||||
|
||||
|
||||
drawGrid(2,2,myGrid)
|
||||
|
||||
|
||||
setStatusLine(1,"Started game with "..opponent.." at computer #"..(opponentID or "nil"))
|
||||
|
||||
|
||||
local function getShipBounds(ship)
|
||||
return {
|
||||
minX=ship.pos[1],
|
||||
minY=ship.pos[2],
|
||||
maxX=ship.pos[1]+(ship.dir=="h" and ship.size-1 or 0),
|
||||
maxY=ship.pos[2]+(ship.dir=="v" and ship.size-1 or 0)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
local function getPointBounds(x,y)
|
||||
return {
|
||||
minX=x,
|
||||
@ -404,20 +404,20 @@ local function getPointBounds(x,y)
|
||||
maxY=y,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
local function boundsIntersect(boundsA,boundsB)
|
||||
return not (
|
||||
boundsA.minX>boundsB.maxX or
|
||||
boundsA.maxX<boundsB.minX or
|
||||
boundsA.minY>boundsB.maxY or
|
||||
boundsA.maxY<boundsB.minY
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
local function checkShipCollision(shipIndex)
|
||||
local myBounds=getShipBounds(ships[shipIndex])
|
||||
for i=1,#ships do
|
||||
for i=1,#ships do
|
||||
if i~=shipIndex and ships[i].pos then
|
||||
if boundsIntersect(myBounds,getShipBounds(ships[i])) then
|
||||
return i
|
||||
@ -426,9 +426,9 @@ local function checkShipCollision(shipIndex)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local function randomizeShips()
|
||||
for i=1,5 do
|
||||
ships[i].pos=nil
|
||||
@ -447,10 +447,10 @@ local function randomizeShips()
|
||||
ship.dir=dir
|
||||
until checkShipCollision(i)==0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function shipPlacement()
|
||||
local selection=1
|
||||
local collidesWith=0
|
||||
@ -458,7 +458,7 @@ local function shipPlacement()
|
||||
local moveShip=nil
|
||||
local clickedOn=nil
|
||||
local clickedAt=nil
|
||||
|
||||
|
||||
doScreenColor()
|
||||
term.setCursorPos(28,3)
|
||||
write("use arrows to move ship")
|
||||
@ -480,7 +480,7 @@ local function shipPlacement()
|
||||
write('"f" when finished')
|
||||
randomizeShips()
|
||||
setStatusLine(1,"Arrange your ships on the grid")
|
||||
|
||||
|
||||
while true do
|
||||
--local placed=0
|
||||
--draw sea
|
||||
@ -502,7 +502,7 @@ local function shipPlacement()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local event,p1,p2,p3=os.pullEvent()
|
||||
if event=="key" then
|
||||
if not dragging then
|
||||
@ -533,14 +533,14 @@ local function shipPlacement()
|
||||
end
|
||||
elseif p1==keys.r then
|
||||
randomizeShips();
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event=="mouse_click" then
|
||||
clickedOn=nil
|
||||
--click event! figure out what we clicked on
|
||||
local clickBounds=getPointBounds(p2,p3)
|
||||
local clickGridBounds=getPointBounds(p2-2,p3-3)
|
||||
|
||||
|
||||
for i=1,#ships do
|
||||
if ships[i].pos and boundsIntersect(clickGridBounds,getShipBounds(ships[i])) and
|
||||
(collidesWith==0 or collidesWith==i or i==selection) then
|
||||
@ -554,7 +554,7 @@ local function shipPlacement()
|
||||
clickedOffset={p2-2-ships[i].pos[1],p3-3-ships[i].pos[2]}
|
||||
selection=i
|
||||
break
|
||||
--[[else
|
||||
--[[else
|
||||
local labelBounds={minX=15,maxX=24,minY=2*i,maxY=1+2*i}
|
||||
if boundsIntersect(clickBounds,labelBounds) and
|
||||
(collidesWith==0 or collidesWith==i or i==selection) then
|
||||
@ -583,20 +583,20 @@ local function shipPlacement()
|
||||
--can't drag from a right-click!
|
||||
clickedOn=nil
|
||||
if ships[selection].dir=="h" then
|
||||
ships[selection].dir="v"
|
||||
ships[selection].dir="v"
|
||||
moveShip={p2-2-ships[selection].pos[1],-(p2-2-ships[selection].pos[1])}
|
||||
else
|
||||
ships[selection].dir="h"
|
||||
else
|
||||
ships[selection].dir="h"
|
||||
moveShip={p3-3-(ships[selection].pos[2]+ships[selection].size-1),p3-3-(ships[selection].pos[2])}
|
||||
end
|
||||
end
|
||||
elseif event=="mouse_drag" and clickedOn~=nil then
|
||||
elseif event=="mouse_drag" and clickedOn~=nil then
|
||||
--mode="place"
|
||||
moveShip={
|
||||
p2-2-clickedOffset[1]-ships[selection].pos[1],
|
||||
p3-3-clickedOffset[2]-ships[selection].pos[2]}
|
||||
p3-3-clickedOffset[2]-ships[selection].pos[2]}
|
||||
end
|
||||
|
||||
|
||||
if moveShip then
|
||||
local curShip=ships[selection]
|
||||
--calc position limits based on ship size and alignment
|
||||
@ -610,15 +610,15 @@ local function shipPlacement()
|
||||
--place the ship
|
||||
ships[selection].pos=newPos
|
||||
--check for collisions with other ships
|
||||
|
||||
|
||||
collidesWith=checkShipCollision(selection)
|
||||
moveShip=nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function displayGameHelp()
|
||||
doScreenColor()
|
||||
doScreenColor()
|
||||
term.setCursorPos(28,3)
|
||||
write("arrows to move cursor")
|
||||
term.setCursorPos(28,4)
|
||||
@ -626,27 +626,27 @@ local function displayGameHelp()
|
||||
if term.isColor() then
|
||||
term.setCursorPos(28,6)
|
||||
write("click on grid to fire")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function hideHelpArea()
|
||||
doScreenColor()
|
||||
doScreenColor()
|
||||
for y=3,13 do
|
||||
term.setCursorPos(28,y)
|
||||
write(string.rep(" ",32))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
local function runGame()
|
||||
|
||||
|
||||
--first, ship placement phase!!
|
||||
shipPlacement()
|
||||
|
||||
|
||||
hideHelpArea()
|
||||
|
||||
|
||||
--hide the old help, draw the new
|
||||
|
||||
|
||||
--tell the other guy we're done
|
||||
rednet.send(opponentID,"bs ready")
|
||||
if not opponentReady then
|
||||
@ -655,17 +655,17 @@ local function runGame()
|
||||
os.pullEvent()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--now, play the game
|
||||
--draw my final ship positions intto the grid
|
||||
drawShipsToGrid(ships,myGrid)
|
||||
|
||||
|
||||
|
||||
|
||||
--if I'm host, flip a coin
|
||||
if action=="host" then
|
||||
math.randomseed(os.time())
|
||||
myTurn=math.floor(100*math.random())%2==0
|
||||
rednet.send(opponentID,"bs cointoss "..tostring(not myTurn))
|
||||
rednet.send(opponentID,"bs cointoss "..tostring(not myTurn))
|
||||
if myTurn then
|
||||
setStatusLine(2,"Your turn, take your shot!")
|
||||
else
|
||||
@ -678,15 +678,15 @@ local function runGame()
|
||||
os.pullEvent()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
setStatusLine(1,"")
|
||||
if myTurn then
|
||||
--I won, I go first
|
||||
displayGameHelp()
|
||||
end
|
||||
|
||||
--draw a target grid
|
||||
|
||||
--draw a target grid
|
||||
drawGrid(2,2,myGrid)
|
||||
drawGrid(15,2,oppGrid)
|
||||
--initialize target indicators
|
||||
@ -719,7 +719,7 @@ local function runGame()
|
||||
elseif p1>="0" and p1<="9" then
|
||||
local t=string.byte(p1)-string.byte("0")
|
||||
if t==0 then t=10 end
|
||||
moveTargetIndicator(t,targetY)
|
||||
moveTargetIndicator(t,targetY)
|
||||
end
|
||||
elseif e=="key" then
|
||||
if p1==keys.enter or p1==keys.space and targetX and targetY then
|
||||
@ -736,7 +736,7 @@ local function runGame()
|
||||
moveTargetIndicator(math.max(targetX-1,1),targetY)
|
||||
elseif p1==keys.right then
|
||||
moveTargetIndicator(math.min(targetX+1,10),targetY)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--shot sent, wait for my turn to resolve (top coroutine will switch turns and draw the hit to the grid)
|
||||
@ -746,12 +746,12 @@ local function runGame()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local gameRoutine=coroutine.create(runGame)
|
||||
--if advanced terminal, default focus to chat, can play with mouse
|
||||
local inChat=term.isColor()
|
||||
local savedCursorPos={7,19}
|
||||
|
||||
|
||||
--redirect just to block scroll
|
||||
local redir={}
|
||||
for k,v in pairs(originalTerm) do
|
||||
@ -762,12 +762,12 @@ for k,v in pairs(originalTerm) do
|
||||
end
|
||||
end
|
||||
originalTerm = term.redirect(redir)
|
||||
|
||||
|
||||
--run the game routine once
|
||||
coroutine.resume(gameRoutine)
|
||||
--hide cursor
|
||||
term.setCursorBlink(false)
|
||||
|
||||
|
||||
while true do
|
||||
local e,p1,p2,p3,p4,p5=os.pullEventRaw()
|
||||
if e=="terminate" then
|
||||
@ -791,7 +791,7 @@ while true do
|
||||
opponentReady=true
|
||||
os.queueEvent("kickcoroutine")
|
||||
elseif cmd=="cointoss" then
|
||||
myTurn=args=="true"
|
||||
myTurn=args=="true"
|
||||
if myTurn then
|
||||
setStatusLine(2,"Your turn, take your shot!")
|
||||
else
|
||||
@ -807,11 +807,11 @@ while true do
|
||||
local tile=myGrid[tx][ty]
|
||||
local shot=makeShot(tx,ty,myGrid)
|
||||
rednet.send(opponentID,"bs result "..(shot[3] and "hit" or "miss"))
|
||||
drawTile(2+tx,3+ty,tile)
|
||||
drawTile(2+tx,3+ty,tile)
|
||||
myTurn=true
|
||||
os.queueEvent("kickcoroutine")
|
||||
displayGameHelp()
|
||||
setStatusLine(1,opponent.." fired at "..toGridRef(tx,ty).." and "..(shot[3] and "hit" or "missed"))
|
||||
setStatusLine(1,opponent.." fired at "..toGridRef(tx,ty).." and "..(shot[3] and "hit" or "missed"))
|
||||
setStatusLine(2,"Your turn, take your shot!")
|
||||
end
|
||||
elseif cmd=="sink" then
|
||||
@ -838,7 +838,7 @@ while true do
|
||||
setStatusLine(2,"Waiting for opponent...")
|
||||
os.queueEvent("kickcoroutine")
|
||||
end
|
||||
|
||||
|
||||
elseif cmd=="win" then
|
||||
--we won!
|
||||
setStatusLine(3,"You won the game! Congratulations!")
|
||||
@ -852,24 +852,24 @@ while true do
|
||||
print("game coroutine crashed with the following error: "..err)
|
||||
quit()
|
||||
end
|
||||
|
||||
|
||||
if coroutine.status(gameRoutine)=="dead" then
|
||||
--game over
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
term.setCursorPos(1,19)
|
||||
term.clearLine()
|
||||
term.write(" Press any key to continue...")
|
||||
os.pullEvent("key")
|
||||
--if a char event was queued following the key event, this will eat it
|
||||
os.sleep(0)
|
||||
|
||||
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.clear()
|
||||
quit()
|
||||
--
|
||||
--
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
--
|
||||
--
|
||||
-- Lua IDE
|
||||
-- Made by GravityScore
|
||||
--
|
||||
--
|
||||
|
||||
|
||||
-- -------- Variables
|
||||
@ -44,7 +44,7 @@ local function isAdvanced() return term.isColor and term.isColor() end
|
||||
|
||||
local function modRead(properties)
|
||||
local w, h = term.getSize()
|
||||
local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil,
|
||||
local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil,
|
||||
liveUpdates = nil, exitOnKey = nil}
|
||||
if not properties then properties = {} end
|
||||
for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end
|
||||
@ -58,7 +58,7 @@ local function modRead(properties)
|
||||
|
||||
local function redraw(repl)
|
||||
local scroll = 0
|
||||
if properties.visibleLength and sx + pos > properties.visibleLength + 1 then
|
||||
if properties.visibleLength and sx + pos > properties.visibleLength + 1 then
|
||||
scroll = (sx + pos) - (properties.visibleLength + 1)
|
||||
end
|
||||
|
||||
@ -133,9 +133,9 @@ local function modRead(properties)
|
||||
elseif (but == keys.up or but == keys.down) and properties.history then
|
||||
redraw(" ")
|
||||
if but == keys.up then
|
||||
if historyPos == nil and #properties.history > 0 then
|
||||
if historyPos == nil and #properties.history > 0 then
|
||||
historyPos = #properties.history
|
||||
elseif historyPos > 1 then
|
||||
elseif historyPos > 1 then
|
||||
historyPos = historyPos - 1
|
||||
end
|
||||
elseif but == keys.down then
|
||||
@ -173,9 +173,9 @@ local function modRead(properties)
|
||||
elseif but == keys["end"] then
|
||||
pos = line:len()
|
||||
redraw()
|
||||
elseif properties.exitOnKey then
|
||||
if but == properties.exitOnKey or (properties.exitOnKey == "control" and
|
||||
(but == 29 or but == 157)) then
|
||||
elseif properties.exitOnKey then
|
||||
if but == properties.exitOnKey or (properties.exitOnKey == "control" and
|
||||
(but == 29 or but == 157)) then
|
||||
term.setCursorBlink(false)
|
||||
return nil
|
||||
end
|
||||
@ -296,7 +296,7 @@ end
|
||||
|
||||
local function centerRead(wid, begt)
|
||||
local function liveUpdate(line, e, but, x, y, p4, p5)
|
||||
if isAdvanced() and e == "mouse_click" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10
|
||||
if isAdvanced() and e == "mouse_click" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10
|
||||
and y >= 13 and y <= 15 then
|
||||
return true, ""
|
||||
end
|
||||
@ -707,7 +707,7 @@ languages.brainfuck.mapLoops = function(code)
|
||||
loopLocations[loc] = true
|
||||
elseif let == "]" then
|
||||
local found = false
|
||||
for i = loc, 1, -1 do
|
||||
for i = loc, 1, -1 do
|
||||
if loopLocations[i] == true then
|
||||
loopLocations[i] = loc
|
||||
found = true
|
||||
@ -877,7 +877,7 @@ local function run(path, lines, useArgs)
|
||||
local s = centerRead(w - 13, fs.getName(path) .. " ")
|
||||
for m in string.gmatch(s, "[^ \t]+") do ar[#ar + 1] = m:gsub("^%s*(.-)%s*$", "%1") end
|
||||
end
|
||||
|
||||
|
||||
saveFile(path, lines)
|
||||
term.setCursorBlink(false)
|
||||
term.setBackgroundColor(colors.black)
|
||||
@ -949,7 +949,7 @@ local function run(path, lines, useArgs)
|
||||
term.setCursorPos(5, 14)
|
||||
term.write(b)
|
||||
end
|
||||
|
||||
|
||||
local opt = prompt({{"Error Help", w/2 - 15, 17}, {"Go To Line", w/2 + 2, 17}},
|
||||
"horizontal")
|
||||
if opt == "Error Help" then
|
||||
@ -1459,7 +1459,7 @@ end
|
||||
|
||||
local function writeHighlighted(line)
|
||||
if curLanguage == languages.lua then
|
||||
while line:len() > 0 do
|
||||
while line:len() > 0 do
|
||||
line = attemptToHighlight(line, "^%-%-%[%[.-%]%]", colors[theme.comment]) or
|
||||
attemptToHighlight(line, "^%-%-.*", colors[theme.comment]) or
|
||||
attemptToHighlight(line, "^\".*[^\\]\"", colors[theme.string]) or
|
||||
@ -1491,7 +1491,7 @@ local function draw()
|
||||
for i = 1, edh do
|
||||
local a = lines[scrolly + i]
|
||||
if a then
|
||||
local ln = string.rep(" ", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i)
|
||||
local ln = string.rep(" ", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i)
|
||||
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
||||
ln = ln .. ":"
|
||||
|
||||
@ -1541,7 +1541,7 @@ local function drawLine(...)
|
||||
for _, ly in pairs(ls) do
|
||||
local a = lines[ly]
|
||||
if a then
|
||||
local ln = string.rep(" ", offx - 1 - tostring(ly):len()) .. tostring(ly)
|
||||
local ln = string.rep(" ", offx - 1 - tostring(ly):len()) .. tostring(ly)
|
||||
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
||||
ln = ln .. ":"
|
||||
|
||||
@ -1651,7 +1651,7 @@ local function edit(path)
|
||||
draw()
|
||||
term.setCursorPos(x + offx, y + offy)
|
||||
term.setCursorBlink(true)
|
||||
|
||||
|
||||
-- Main loop
|
||||
local tid = os.startTimer(3)
|
||||
while true do
|
||||
@ -1692,8 +1692,8 @@ local function edit(path)
|
||||
if f then
|
||||
table.insert(lines, y + 1, string.rep(" ", spaces + 2))
|
||||
if not f:find("else", 1, true) and not f:find("elseif", 1, true) then
|
||||
table.insert(lines, y + 2, string.rep(" ", spaces) ..
|
||||
(f:find("repeat", 1, true) and "until " or f:find("{", 1, true) and "}" or
|
||||
table.insert(lines, y + 2, string.rep(" ", spaces) ..
|
||||
(f:find("repeat", 1, true) and "until " or f:find("{", 1, true) and "}" or
|
||||
"end"))
|
||||
end
|
||||
x, y = spaces + 3, y + 1
|
||||
@ -1771,7 +1771,7 @@ local function edit(path)
|
||||
x = math.min(lines[y]:len() + 1, x)
|
||||
cursorLoc(x, y, true)
|
||||
end
|
||||
elseif e == "char" and allowEditorEvent and (displayCode and true or
|
||||
elseif e == "char" and allowEditorEvent and (displayCode and true or
|
||||
y + scrolly - 1 == liveErr.line) then
|
||||
local shouldIgnore = false
|
||||
for k, v in pairs(liveCompletions) do
|
||||
@ -2083,7 +2083,7 @@ local function changeTheme()
|
||||
sleep(1.6)
|
||||
return "menu"
|
||||
end
|
||||
|
||||
|
||||
term.write("LuaIDE - Could Not Load Theme!")
|
||||
fs.delete("/.LuaIDE_temp_theme_file")
|
||||
sleep(1.6)
|
||||
@ -2100,7 +2100,7 @@ local function settings()
|
||||
title("LuaIDE - Settings")
|
||||
|
||||
local opt = prompt({{"Change Theme", w/2 - 17, 8}, {"Return to Menu", w/2 - 19, 13},
|
||||
--[[{"Check for Updates", w/2 + 2, 8},]] {"Exit IDE", w/2 + 2, 13, bg = colors[theme.err],
|
||||
--[[{"Check for Updates", w/2 + 2, 8},]] {"Exit IDE", w/2 + 2, 13, bg = colors[theme.err],
|
||||
highlight = colors[theme.errHighlight]}}, "vertical", true)
|
||||
if opt == "Change Theme" then return changeTheme()
|
||||
-- elseif opt == "Check for Updates" then return update()
|
||||
@ -2189,7 +2189,7 @@ if err and not err:find("Terminated") then
|
||||
term.write("Please report this error to")
|
||||
term.setCursorPos(6, cy + 3)
|
||||
term.write("GravityScore! ")
|
||||
|
||||
|
||||
term.setBackgroundColor(colors[theme.background])
|
||||
if isAdvanced() then centerPrint("Click to Exit...", h - 1)
|
||||
else centerPrint("Press Any Key to Exit...", h - 1) end
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[
|
||||
Project info:
|
||||
|
||||
|
||||
Name: Maze
|
||||
Creator: Jesusthekiller
|
||||
Language: Lua (CC)
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
--[[
|
||||
LICENSE:
|
||||
|
||||
|
||||
Maze
|
||||
Copyright (c) 2013 Jesusthekiller
|
||||
|
||||
@ -73,7 +73,7 @@ repeat
|
||||
|
||||
cwrite("Enter maze size (5-99):")
|
||||
size = read()
|
||||
|
||||
|
||||
size = tonumber(size)
|
||||
if not size then
|
||||
size = 0
|
||||
@ -82,18 +82,18 @@ until size > 4 and size < 100
|
||||
|
||||
-- The generate
|
||||
local function mazeGen(mx, my)
|
||||
|
||||
|
||||
--[[
|
||||
Format:
|
||||
|
||||
|
||||
maze.x.y.(1/2/3/4) = true/false
|
||||
|
||||
|
||||
1 - top
|
||||
2 - bottom
|
||||
3 - right
|
||||
4 - left
|
||||
]]--
|
||||
|
||||
|
||||
local maze = {}
|
||||
for i = 1, mx do
|
||||
maze[i] = {}
|
||||
@ -116,26 +116,26 @@ local function mazeGen(mx, my)
|
||||
local intact = {}
|
||||
local x = curr.x
|
||||
local y = curr.y
|
||||
|
||||
|
||||
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
||||
intact[#intact+1] = {x-1, y, 1}
|
||||
end
|
||||
|
||||
|
||||
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
||||
intact[#intact+1] = {x+1, y, 2}
|
||||
end
|
||||
|
||||
|
||||
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
||||
intact[#intact+1] = {x, y+1, 3}
|
||||
end
|
||||
|
||||
|
||||
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
||||
intact[#intact+1] = {x, y-1, 4}
|
||||
end
|
||||
|
||||
|
||||
if #intact > 0 then
|
||||
local i = math.random(1, #intact) -- Choose random
|
||||
|
||||
|
||||
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
||||
maze[intact[i][1]][intact[i][2]][2] = false
|
||||
elseif intact[i][3] == 2 then
|
||||
@ -145,11 +145,11 @@ local function mazeGen(mx, my)
|
||||
elseif intact[i][3] == 4 then
|
||||
maze[intact[i][1]][intact[i][2]][3] = false
|
||||
end
|
||||
|
||||
|
||||
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
||||
|
||||
|
||||
vis = vis + 1 -- Increase vis
|
||||
|
||||
|
||||
stack[#stack+1] = intact[i] -- Add to stack
|
||||
else
|
||||
local tmp = table.remove(stack) -- Get last cell
|
||||
@ -157,7 +157,7 @@ local function mazeGen(mx, my)
|
||||
curr.y = tmp[2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return maze
|
||||
end
|
||||
|
||||
@ -177,7 +177,7 @@ local tab = {}
|
||||
|
||||
for x = 1, size * 2 + 1 do
|
||||
tab[x] = {}
|
||||
|
||||
|
||||
for y = 1, size * 2 + 1 do
|
||||
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
||||
tab[x][y] = false
|
||||
@ -201,7 +201,7 @@ repeat
|
||||
-- Print map
|
||||
term.setBackgroundColor(colors.white)
|
||||
term.clear()
|
||||
|
||||
|
||||
if posx == 2 and posy == 2 then
|
||||
term.setCursorPos(1, 1)
|
||||
term.setTextColor(colors.black)
|
||||
@ -211,27 +211,27 @@ repeat
|
||||
print("Goal: Step on # (It's on bottom right corner)")
|
||||
print("\nGood Luck!")
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
term.setTextColor(colors.black)
|
||||
term.setCursorPos(1, 19)
|
||||
write("X: "..posx.." Y: "..posy)
|
||||
]]
|
||||
|
||||
|
||||
for x, tV in ipairs(tab) do -- Print the map
|
||||
for y, v in ipairs(tV) do
|
||||
if offsety+y > 20 then
|
||||
break
|
||||
end
|
||||
|
||||
|
||||
term.setCursorPos(offsetx+x, offsety+y)
|
||||
|
||||
|
||||
if v then
|
||||
term.setBackgroundColor(colors.black)
|
||||
else
|
||||
term.setBackgroundColor(colors.white)
|
||||
end
|
||||
|
||||
|
||||
if offsety+y < 20 and offsety+y > 0 and offsetx+x < 52 and offsetx+x > 0 then
|
||||
if x == size*2 and y == size*2 then
|
||||
if term.isColor() then
|
||||
@ -243,51 +243,51 @@ repeat
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if offsetx+x > 51 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
term.setCursorPos(51/2, 19/2)
|
||||
term.setBackgroundColor(colors.white)
|
||||
|
||||
|
||||
if term.isColor() then
|
||||
term.setTextColor(colors.red)
|
||||
else
|
||||
term.setTextColor(colors.black)
|
||||
end
|
||||
|
||||
|
||||
write("X")
|
||||
|
||||
|
||||
-- Wait for key
|
||||
|
||||
|
||||
local e, k = os.pullEvent("char")
|
||||
|
||||
|
||||
if k == "a" and (not tab[posx-1][posy]) then
|
||||
posx = posx - 1
|
||||
offsetx = offsetx + 1
|
||||
end
|
||||
|
||||
|
||||
if k == "d" and (not tab[posx+1][posy]) then
|
||||
posx = posx + 1
|
||||
offsetx = offsetx - 1
|
||||
end
|
||||
|
||||
|
||||
if k == "w" and (not tab[posx][posy-1]) then
|
||||
posy = posy - 1
|
||||
offsety = offsety + 1
|
||||
end
|
||||
|
||||
|
||||
if k == "s" and (not tab[posx][posy+1]) then
|
||||
posy = posy + 1
|
||||
offsety = offsety - 1
|
||||
end
|
||||
|
||||
|
||||
if k == "q" then
|
||||
break
|
||||
end
|
||||
|
||||
|
||||
if k == "r" then
|
||||
posx = 2
|
||||
posy = 2
|
||||
@ -324,4 +324,4 @@ term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
cprint(" Maze by JTK. Thanks for playing!")
|
||||
cprint(" Maze by JTK. Thanks for playing!")
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[
|
||||
Project info:
|
||||
|
||||
|
||||
Name: Maze 3D
|
||||
Creator: Jesusthekiller
|
||||
Language: Lua (CC)
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
--[[
|
||||
LICENSE:
|
||||
|
||||
|
||||
Maze 3D
|
||||
Copyright (c) 2013 Jesusthekiller
|
||||
|
||||
@ -78,7 +78,7 @@ repeat
|
||||
|
||||
cwrite("Enter maze size (5-99):")
|
||||
size = read()
|
||||
|
||||
|
||||
size = tonumber(size)
|
||||
if not size then
|
||||
size = 0
|
||||
@ -87,18 +87,18 @@ until size > 4 and size < 100
|
||||
|
||||
-- The generate
|
||||
local function mazeGen(mx, my)
|
||||
|
||||
|
||||
--[[
|
||||
Format:
|
||||
|
||||
|
||||
maze.x.y.(1/2/3/4) = true/false
|
||||
|
||||
|
||||
1 - top
|
||||
2 - bottom
|
||||
3 - right
|
||||
4 - left
|
||||
]]--
|
||||
|
||||
|
||||
local maze = {}
|
||||
for i = 1, mx do
|
||||
maze[i] = {}
|
||||
@ -121,26 +121,26 @@ local function mazeGen(mx, my)
|
||||
local intact = {}
|
||||
local x = curr.x
|
||||
local y = curr.y
|
||||
|
||||
|
||||
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
||||
intact[#intact+1] = {x-1, y, 1}
|
||||
end
|
||||
|
||||
|
||||
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
||||
intact[#intact+1] = {x+1, y, 2}
|
||||
end
|
||||
|
||||
|
||||
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
||||
intact[#intact+1] = {x, y+1, 3}
|
||||
end
|
||||
|
||||
|
||||
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
||||
intact[#intact+1] = {x, y-1, 4}
|
||||
end
|
||||
|
||||
|
||||
if #intact > 0 then
|
||||
local i = math.random(1, #intact) -- Choose random
|
||||
|
||||
|
||||
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
||||
maze[intact[i][1]][intact[i][2]][2] = false
|
||||
elseif intact[i][3] == 2 then
|
||||
@ -150,11 +150,11 @@ local function mazeGen(mx, my)
|
||||
elseif intact[i][3] == 4 then
|
||||
maze[intact[i][1]][intact[i][2]][3] = false
|
||||
end
|
||||
|
||||
|
||||
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
||||
|
||||
|
||||
vis = vis + 1 -- Increase vis
|
||||
|
||||
|
||||
stack[#stack+1] = intact[i] -- Add to stack
|
||||
else
|
||||
local tmp = table.remove(stack) -- Get last cell
|
||||
@ -162,7 +162,7 @@ local function mazeGen(mx, my)
|
||||
curr.y = tmp[2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return maze
|
||||
end
|
||||
|
||||
@ -180,7 +180,7 @@ local tab = {}
|
||||
|
||||
for x = 1, size * 2 + 1 do
|
||||
tab[x] = {}
|
||||
|
||||
|
||||
for y = 1, size * 2 + 1 do
|
||||
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
||||
tab[x][y] = " "
|
||||
@ -263,13 +263,13 @@ if redirect then
|
||||
print("redirect API found, using buffer")
|
||||
else
|
||||
local pe=printError
|
||||
rawset(_G,"printError",error)
|
||||
rawset(_G,"printError",error)
|
||||
local ok, err=pcall(os.loadAPI,"redirect")
|
||||
if not ok then
|
||||
print("trying "..shell.dir().."/redirect")
|
||||
ok,err=pcall(os.loadAPI,shell.dir().."/redirect")
|
||||
end
|
||||
if ok then
|
||||
if ok then
|
||||
print("Loaded redirect API, using buffer")
|
||||
buffer=redirect.createRedirectBuffer()
|
||||
loadedAPI=true
|
||||
@ -277,7 +277,7 @@ else
|
||||
print("redirect API not found or could not be loaded, drawing directly; this may cause flickering.")
|
||||
end
|
||||
rawset(_G,"printError",pe)
|
||||
end
|
||||
end
|
||||
|
||||
local colorSchemes = {
|
||||
{0,8}, --white+gray
|
||||
@ -338,10 +338,10 @@ local function cast(cx,cy,angle)
|
||||
end
|
||||
local wall=map[y]:sub(x,x)
|
||||
if wall~=" " then
|
||||
|
||||
|
||||
return colorSchemes[tonumber(wall)][isX and 1 or 2], hitD
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local w,h=term.getSize()
|
||||
@ -370,7 +370,7 @@ for x=1,w do
|
||||
t.angle=math.atan2(x-centerX,screenDist)
|
||||
t.dist=((x-centerX)^2+screenDist^2)^.5/screenDist
|
||||
end
|
||||
|
||||
|
||||
local function redraw()
|
||||
local oldTerm
|
||||
if buffer.isBuffer then
|
||||
@ -411,15 +411,15 @@ local function clampCollision(x,y,radius)
|
||||
--I am. Complete fail, do nothing.
|
||||
return x,y
|
||||
end
|
||||
|
||||
|
||||
--ok, check the neighbors.
|
||||
local right=math.floor(x+radius)>gx
|
||||
local left=math.floor(x-radius)<gx
|
||||
local front=math.floor(y-radius)<gy
|
||||
local back=math.floor(y+radius)>gy
|
||||
|
||||
|
||||
local pushed=false
|
||||
|
||||
|
||||
if right and map[gy]:sub(gx+1,gx+1)~=" " then
|
||||
--push left
|
||||
pushed=true
|
||||
@ -429,7 +429,7 @@ local function clampCollision(x,y,radius)
|
||||
pushed=true
|
||||
x=gx+radius
|
||||
end
|
||||
|
||||
|
||||
if front and map[gy-1]:sub(gx,gx)~=" " then
|
||||
--push back
|
||||
pushed=true
|
||||
@ -442,7 +442,7 @@ local function clampCollision(x,y,radius)
|
||||
|
||||
y=gy+1-radius
|
||||
end
|
||||
|
||||
|
||||
--if I wasn't pushed out on any side, I might be hitting a corner
|
||||
if not pushed then
|
||||
--square rad
|
||||
@ -482,7 +482,7 @@ local function clampCollision(x,y,radius)
|
||||
x=x+pushx
|
||||
y=y+pushy
|
||||
end
|
||||
|
||||
|
||||
return x,y
|
||||
end
|
||||
|
||||
@ -533,7 +533,7 @@ while true do
|
||||
redraw()
|
||||
dirty=false
|
||||
end
|
||||
|
||||
|
||||
local e={os.pullEvent()}
|
||||
if e[1]=="key" then
|
||||
if e[2]==keys.left then
|
||||
@ -565,7 +565,7 @@ while true do
|
||||
dir=startdir
|
||||
dirty=true
|
||||
end
|
||||
|
||||
|
||||
if px >= mapW-1 and py >= mapH-1 then
|
||||
win = true
|
||||
break
|
||||
|
@ -23,4 +23,4 @@ if fs.exists(args[1]) then
|
||||
else
|
||||
print("Client rejected file!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -718,4 +718,4 @@ elseif #args >= 1 then --either no server running or we are the local shell on t
|
||||
else
|
||||
print("Usage: nsh <serverID> [resume]")
|
||||
print(" nsh host [remote [local [name]]]")
|
||||
end
|
||||
end
|
||||
|
@ -32,4 +32,4 @@ if message ~= "fileNotFound" then
|
||||
else
|
||||
print("Empty file not written!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -124,7 +124,7 @@ end
|
||||
local function getAIMove()
|
||||
-- make it seem like the computer actually has to think about its move
|
||||
sleep(0.8)
|
||||
|
||||
|
||||
-- check if AI can win and return the 3rd tile to create a win, if it cannot, check for a human attempt at winning and stop it, if there is none, return a random
|
||||
return (search(currentPlayer) or search(opposites[currentPlayer])) or math.random(1,9)
|
||||
end
|
||||
@ -177,7 +177,7 @@ local function modread( _mask, _history, _limit )
|
||||
redraw(' ')
|
||||
if event[2] == keys.up then
|
||||
if not historyPos then
|
||||
historyPos = #_history
|
||||
historyPos = #_history
|
||||
elseif historyPos > 1 then
|
||||
historyPos = historyPos - 1
|
||||
end
|
||||
@ -308,14 +308,14 @@ local function render()
|
||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, 3)
|
||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh-2)
|
||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh)
|
||||
|
||||
|
||||
if term.isColor and term.isColor() then
|
||||
term.setCursorPos(sw, 1)
|
||||
term.setBackgroundColor(colors.red)
|
||||
term.setTextColor(colors.black)
|
||||
writeWithFormat('X')
|
||||
end
|
||||
|
||||
|
||||
-- set our colours
|
||||
term.setBackgroundColor(colors.white)
|
||||
term.setTextColor(colors.black)
|
||||
@ -359,7 +359,7 @@ local function render()
|
||||
writeAt((board[i + 6] == 'x' and '/\\' or '\\/'), 18+((i-1)*7), 14)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- draw the current player
|
||||
term.setCursorPos(3, sh - 3)
|
||||
if not winner then
|
||||
@ -441,4 +441,4 @@ cwriteWithFormat('&4Thank you for playing CCTicTacToe v1.0', 1)
|
||||
cwriteWithFormat('&4By &8TheOriginal&3BIT\n', 2)
|
||||
|
||||
-- restore the default terminal object
|
||||
term.redirect( oldTermObj )
|
||||
term.redirect( oldTermObj )
|
||||
|
@ -22,7 +22,7 @@ while not bFinished do
|
||||
break
|
||||
end
|
||||
|
||||
-- Get this every frame incase the monitor resizes
|
||||
-- Get this every frame incase the monitor resizes
|
||||
local w,h = term.getSize()
|
||||
local startX = math.floor( (w - 65) / 2 )
|
||||
local startY = math.floor( (h - 14) / 2 )
|
||||
|
@ -1 +1 @@
|
||||
print( "\"talk\" was removed in ComputerCraft 1.6, use the builtin \"chat\" program instead!" )
|
||||
print( "\"talk\" was removed in ComputerCraft 1.6, use the builtin \"chat\" program instead!" )
|
||||
|
@ -27,11 +27,11 @@ function initVariables()
|
||||
human6x = 85
|
||||
human6y = 18
|
||||
human1 = true
|
||||
human2 = true
|
||||
human3 = true
|
||||
human4 = true
|
||||
human5 = true
|
||||
human6 = true
|
||||
human2 = true
|
||||
human3 = true
|
||||
human4 = true
|
||||
human5 = true
|
||||
human6 = true
|
||||
human1Abducted=false
|
||||
human2Abducted=false
|
||||
human3Abducted=false
|
||||
@ -245,7 +245,7 @@ function printScore()
|
||||
end
|
||||
|
||||
function rewriteScores()
|
||||
if newScore > score1 then
|
||||
if newScore > score1 then
|
||||
name5=name4 score5=score4
|
||||
name4=name3 score4=score3
|
||||
name3=name2 score3=score2
|
||||
@ -264,7 +264,7 @@ function rewriteScores()
|
||||
name5=name4 score5=score4
|
||||
name4=newName score4=newScore
|
||||
elseif newScore > score5 then
|
||||
name5=newName score5=newScore
|
||||
name5=newName score5=newScore
|
||||
end
|
||||
local highScoreTable = {{name1, score1}, {name2,score2}, {name3,score3}, {name4,score4}, {name5,score5}}
|
||||
local newHighScoreStr = textutils.serialize(highScoreTable)
|
||||
@ -289,7 +289,7 @@ function newHighScoreObtained()
|
||||
newNameStr=newNameStr..p1
|
||||
newNameStrLen=newNameStrLen+1
|
||||
printCent(14,newNameStr.." ")
|
||||
|
||||
|
||||
elseif event=="key" and p1 == 14 and newNameStrLen>0 then
|
||||
newNameStr=string.sub(newNameStr,1,string.len(newNameStr)-1)
|
||||
newNameStrLen=newNameStrLen-1
|
||||
@ -303,9 +303,9 @@ function newHighScoreObtained()
|
||||
printScore()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function highScore()
|
||||
@ -327,8 +327,8 @@ function highScore()
|
||||
newHighScoreObtained()
|
||||
end
|
||||
printScore()
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -351,24 +351,24 @@ function gameOver(gameOverMsg)
|
||||
running=false
|
||||
sleep(1.5)
|
||||
highScore()-- new
|
||||
--playAgain
|
||||
--playAgain
|
||||
end
|
||||
|
||||
function playAgain()
|
||||
sleep(1)
|
||||
printCent(12,"Play again (Y or N)")
|
||||
|
||||
|
||||
while true do
|
||||
local event,p1,p2,p3 = os.pullEvent()
|
||||
if event=="char" then
|
||||
if string.lower(p1)=="y" then
|
||||
if string.lower(p1)=="y" then
|
||||
runGame()
|
||||
elseif string.lower(p1)=="n" then
|
||||
elseif string.lower(p1)=="n" then
|
||||
os.shutdown()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function killPlayer()
|
||||
@ -378,7 +378,7 @@ function killPlayer()
|
||||
moveDown=false
|
||||
delShip(shipYPos)
|
||||
lives=lives-1
|
||||
if lives==0 then
|
||||
if lives==0 then
|
||||
gameOver("OUT OF LIVES")
|
||||
end
|
||||
killedState=true
|
||||
@ -438,7 +438,7 @@ function right()
|
||||
end
|
||||
|
||||
function up()
|
||||
if shipYPos > 2 then
|
||||
if shipYPos > 2 then
|
||||
delShip(shipYPos)
|
||||
shipYPos=shipYPos-1
|
||||
checkShipCollision()
|
||||
@ -449,7 +449,7 @@ function up()
|
||||
end
|
||||
|
||||
function down()
|
||||
if shipYPos<17 then
|
||||
if shipYPos<17 then
|
||||
delShip(shipYPos)
|
||||
shipYPos=shipYPos+1
|
||||
checkShipCollision()
|
||||
@ -480,7 +480,7 @@ function checkShipCollision()
|
||||
if human3x >=24 and human3x <= 26 then
|
||||
human3=false
|
||||
humanHitRoutine()
|
||||
end
|
||||
end
|
||||
elseif human4==true and human4y==shipYPos then
|
||||
if human4x >=24 and human4x <= 26 then
|
||||
human4=false
|
||||
@ -495,7 +495,7 @@ function checkShipCollision()
|
||||
if human6x >=24 and human6x <= 26 then
|
||||
human6=false
|
||||
humanHitRoutine()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -551,7 +551,7 @@ function alienDown()
|
||||
alien1Abduct=true
|
||||
alien1Carry=true
|
||||
alien1Step=17
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -564,74 +564,74 @@ function alienRoutine()
|
||||
end
|
||||
alien1Abduct=false
|
||||
alien1Carry=false
|
||||
if humansLeft==0 then
|
||||
if humansLeft==0 then
|
||||
gameOver("NO HUMANS LEFT")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function alienUp()
|
||||
if alien1==true and alien1Abduct==true then
|
||||
if alien1x+1 == human1x then
|
||||
if alien1x+1 == human1x then
|
||||
human1Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human1y=math.floor(alien1Step)+1
|
||||
human1x=alien1x+1
|
||||
if human1y<=2 then
|
||||
if human1y<=2 then
|
||||
alienRoutine()
|
||||
human1=false
|
||||
end
|
||||
elseif alien1x+1 == human2x then
|
||||
elseif alien1x+1 == human2x then
|
||||
human2Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human2y=math.floor(alien1Step)+1
|
||||
human2x=alien1x+1
|
||||
if human2y<=2 then
|
||||
if human2y<=2 then
|
||||
alienRoutine()
|
||||
human2=false
|
||||
end
|
||||
elseif alien1x+1 == human3x then
|
||||
elseif alien1x+1 == human3x then
|
||||
human3Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human3y=math.floor(alien1Step)+1
|
||||
human3x=alien1x+1
|
||||
if human3y<=2 then
|
||||
if human3y<=2 then
|
||||
alienRoutine()
|
||||
human3=false
|
||||
end
|
||||
elseif alien1x+1 == human4x then
|
||||
elseif alien1x+1 == human4x then
|
||||
human4Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human4y=math.floor(alien1Step)+1
|
||||
human4x=alien1x+1
|
||||
if human4y<=2 then
|
||||
if human4y<=2 then
|
||||
alienRoutine()
|
||||
human4=false
|
||||
end
|
||||
elseif alien1x+1 == human5x then
|
||||
elseif alien1x+1 == human5x then
|
||||
human5Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human5y=math.floor(alien1Step)+1
|
||||
human5x=alien1x+1
|
||||
if human5y<=2 then
|
||||
if human5y<=2 then
|
||||
alienRoutine()
|
||||
human5=false
|
||||
end
|
||||
elseif alien1x+1 == human6x then
|
||||
elseif alien1x+1 == human6x then
|
||||
human6Abducted=true
|
||||
alien1Step=alien1Step-stepValue
|
||||
alien1y=math.floor(alien1Step)
|
||||
human6y=math.floor(alien1Step)+1
|
||||
human6x=alien1x+1
|
||||
if human6y<=2 then
|
||||
if human6y<=2 then
|
||||
alienRoutine()
|
||||
human6=false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if alien1==false then alienGen() end
|
||||
@ -645,7 +645,7 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
||||
moveDown=true
|
||||
moveUp=false
|
||||
elseif pressedKey==203 or pressedKey == 30 then -- left
|
||||
moveLeft=true
|
||||
moveLeft=true
|
||||
moveRight=false
|
||||
elseif pressedKey==205 or pressedKey == 32 then -- right
|
||||
moveRight=true
|
||||
@ -654,7 +654,7 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
||||
if bulletState==false then
|
||||
bulletYPos=shipYPos
|
||||
bulletState=true
|
||||
if shipFacingRight==true then
|
||||
if shipFacingRight==true then
|
||||
bulletXPos=shipXPos+3
|
||||
bulletGoingRight=true
|
||||
else
|
||||
@ -665,13 +665,13 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
||||
elseif pressedKey==25 then -- q (use 25 if p for quit)
|
||||
gameOver("YOU QUIT")
|
||||
end
|
||||
|
||||
|
||||
--term.setCursorPos(30,1)
|
||||
--write(pressedKey.." ")
|
||||
end
|
||||
|
||||
function removeBullet()
|
||||
if bulletGoingRight==true then
|
||||
if bulletGoingRight==true then
|
||||
bulletXPos = 60
|
||||
else
|
||||
bulletXPos = -10
|
||||
@ -691,7 +691,7 @@ end
|
||||
function humanHitRoutine()
|
||||
score=score-50
|
||||
humansLeft=humansLeft-1
|
||||
if humansLeft==0 then
|
||||
if humansLeft==0 then
|
||||
gameOver("NO HUMANS LEFT")
|
||||
end
|
||||
if alien1Carry==true then alien1Carry=false end
|
||||
@ -699,9 +699,9 @@ end
|
||||
|
||||
|
||||
function checkBulletCollision()
|
||||
if alien1 == true and bulletYPos == alien1y then
|
||||
if bulletXPos >= alien1x and bulletXPos <= alien1x + 3 then
|
||||
alien1Hit()
|
||||
if alien1 == true and bulletYPos == alien1y then
|
||||
if bulletXPos >= alien1x and bulletXPos <= alien1x + 3 then
|
||||
alien1Hit()
|
||||
end
|
||||
end
|
||||
if human1 == true and bulletYPos == human1y and bulletXPos == human1x then human1=false humanHitRoutine() end
|
||||
@ -737,15 +737,15 @@ end
|
||||
function gameControl()
|
||||
|
||||
gameTimer=os.startTimer(0.1)
|
||||
|
||||
|
||||
while running do
|
||||
local event,p1,p2,p3 = os.pullEvent()
|
||||
if score<0 then score=0 end
|
||||
term.setCursorPos(1,1)
|
||||
term.setBackgroundColour(colours.yellow)
|
||||
write(string.rep(" ",w))
|
||||
|
||||
|
||||
|
||||
|
||||
term.setTextColour(colours.red)
|
||||
term.setCursorPos(5,1)
|
||||
write("Score: "..score.." ")
|
||||
@ -753,15 +753,15 @@ function gameControl()
|
||||
write("Humans Left: "..humansLeft.." ")
|
||||
term.setCursorPos(40,1)
|
||||
write("Lives: "..lives.." ")
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.white)
|
||||
|
||||
|
||||
local newStepValue = (score+0.1)/1000
|
||||
if newStepValue > stepValue then stepValue= newStepValue end
|
||||
if stepValue>0.4 then stepValue=0.4 end
|
||||
|
||||
|
||||
|
||||
|
||||
--[[DEBUG
|
||||
term.setCursorPos(2,2)
|
||||
write("human1x "..human1x.." ")
|
||||
@ -776,10 +776,10 @@ function gameControl()
|
||||
term.setCursorPos(2,7)
|
||||
write("human6x "..human6x.." ")
|
||||
]]--
|
||||
|
||||
|
||||
|
||||
|
||||
if event=="timer" and gameTimer == p1 then
|
||||
if killedState==true then
|
||||
if killedState==true then
|
||||
delShip(shipYPos)
|
||||
delHumans()
|
||||
dropHumans()
|
||||
@ -800,15 +800,15 @@ function gameControl()
|
||||
else
|
||||
moveLeft=true
|
||||
moveRight=false
|
||||
end
|
||||
end
|
||||
killedDelay=0
|
||||
end
|
||||
else
|
||||
|
||||
|
||||
--alienGen()
|
||||
drawShip(shipYPos)
|
||||
delAliens()
|
||||
|
||||
|
||||
delHumans()
|
||||
dropHumans()
|
||||
alienDown()
|
||||
@ -817,7 +817,7 @@ function gameControl()
|
||||
drawHumans()
|
||||
drawBorder()
|
||||
end
|
||||
|
||||
|
||||
if bulletState==true then
|
||||
if bulletGoingRight==true then
|
||||
delBullet()
|
||||
@ -839,7 +839,7 @@ function gameControl()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if moveLeft==true then
|
||||
left()
|
||||
end
|
||||
@ -852,16 +852,16 @@ function gameControl()
|
||||
if moveDown==true then
|
||||
down()
|
||||
end
|
||||
|
||||
|
||||
gameTimer=os.startTimer(0.1)
|
||||
|
||||
elseif event=="key" and killedState==false then
|
||||
|
||||
elseif event=="key" and killedState==false then
|
||||
pressedKey=p1
|
||||
keyPress()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function runGame()
|
||||
@ -875,7 +875,7 @@ end
|
||||
|
||||
|
||||
function pix(xCo,yCo,text,col)
|
||||
if col== nil then term.setBackgroundColour(colours.black)
|
||||
if col== nil then term.setBackgroundColour(colours.black)
|
||||
elseif col =="white" then term.setBackgroundColour(colours.white)
|
||||
elseif col =="green" then term.setBackgroundColour(colours.green)
|
||||
elseif col =="pink" then term.setBackgroundColour(colours.pink)
|
||||
@ -977,7 +977,7 @@ function line2()
|
||||
pix(38,5," ","white")
|
||||
pix(40,5," ","white")
|
||||
pix(42,5," ","white")
|
||||
|
||||
|
||||
end
|
||||
|
||||
function line3()
|
||||
@ -1030,7 +1030,7 @@ function startScreen()
|
||||
term.setCursorPos(1,h)
|
||||
write(string.rep(" ",w))
|
||||
local screenStage=0
|
||||
|
||||
|
||||
screenTimer=os.startTimer(0.1)
|
||||
while true do
|
||||
local event,p1,p2,p3=os.pullEvent()
|
||||
@ -1039,12 +1039,12 @@ function startScreen()
|
||||
clear()
|
||||
runGame()
|
||||
elseif event=="timer" and screenTimer == p1 then
|
||||
|
||||
|
||||
--term.setCursorPos(1,1) write("screenStage: "..screenStage.." ")
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setCursorPos(35,1) write("SPACE WHEN READY")
|
||||
|
||||
|
||||
if screenStage>0 and screenStage<0.5 then
|
||||
humanPixY = 18
|
||||
drawHumanPix()
|
||||
@ -1055,17 +1055,17 @@ function startScreen()
|
||||
alienPixY = -2
|
||||
delAlienPix()
|
||||
alienPixY = -1
|
||||
drawAlienPix()
|
||||
drawAlienPix()
|
||||
elseif screenStage>4 and screenStage<4.9 then
|
||||
alienPixY = -1
|
||||
delAlienPix()
|
||||
alienPixY = 0
|
||||
drawAlienPix()
|
||||
drawAlienPix()
|
||||
elseif screenStage>5 and screenStage<5.9 then
|
||||
alienPixY = 0
|
||||
delAlienPix()
|
||||
alienPixY = 1
|
||||
drawAlienPix()
|
||||
drawAlienPix()
|
||||
elseif screenStage>6 and screenStage<6.9 then
|
||||
alienPixY = 1
|
||||
delAlienPix()
|
||||
@ -1080,7 +1080,7 @@ function startScreen()
|
||||
alienPixY = 3
|
||||
delAlienPix()
|
||||
alienPixY = 4
|
||||
drawAlienPix()
|
||||
drawAlienPix()
|
||||
elseif screenStage>8 and screenStage<9.9 then
|
||||
alienPixY = 4
|
||||
delAlienPix()
|
||||
@ -1120,7 +1120,7 @@ function startScreen()
|
||||
pix(22,17," ","yellow")
|
||||
pix(22,18," ","yellow")
|
||||
humanPixY = 18
|
||||
drawHumanPix()
|
||||
drawHumanPix()
|
||||
elseif screenStage>10.8 and screenStage<11 then
|
||||
pix(25,8," ","yellow")
|
||||
pix(24,9," ","yellow")
|
||||
@ -1134,7 +1134,7 @@ function startScreen()
|
||||
pix(20,17," ","yellow")
|
||||
pix(20,18," ","yellow")
|
||||
humanPixY = 18
|
||||
drawHumanPix()
|
||||
drawHumanPix()
|
||||
elseif screenStage>11.9 and screenStage<12 then
|
||||
pix(1,6," ","yellow")
|
||||
elseif screenStage>12 and screenStage<12.1 then
|
||||
@ -1142,7 +1142,7 @@ function startScreen()
|
||||
pix(3,6," ","yellow")
|
||||
elseif screenStage>12.1 and screenStage<12.2 then
|
||||
pix(3,6," ")
|
||||
pix(5,6," ","yellow")
|
||||
pix(5,6," ","yellow")
|
||||
elseif screenStage>12.2 and screenStage<12.3 then
|
||||
pix(5,6," ")
|
||||
pix(7,6," ","yellow")
|
||||
@ -1166,102 +1166,102 @@ function startScreen()
|
||||
end
|
||||
humanPixY=18
|
||||
drawHumanPix()
|
||||
elseif screenStage>13 and screenStage<13.1 then
|
||||
elseif screenStage>13 and screenStage<13.1 then
|
||||
shipPixX= -16
|
||||
drawShipPix()
|
||||
elseif screenStage>13 and screenStage<13.1 then
|
||||
elseif screenStage>13 and screenStage<13.1 then
|
||||
delShipPix()
|
||||
shipPixX= -15
|
||||
drawShipPix()
|
||||
elseif screenStage>13.1 and screenStage<13.2 then
|
||||
drawShipPix()
|
||||
elseif screenStage>13.1 and screenStage<13.2 then
|
||||
delShipPix()
|
||||
shipPixX= -12
|
||||
drawShipPix()
|
||||
elseif screenStage>13.2 and screenStage<13.3 then
|
||||
drawShipPix()
|
||||
elseif screenStage>13.2 and screenStage<13.3 then
|
||||
delShipPix()
|
||||
shipPixX= -9
|
||||
drawShipPix()
|
||||
elseif screenStage>13.2 and screenStage<13.3 then
|
||||
elseif screenStage>13.2 and screenStage<13.3 then
|
||||
delShipPix()
|
||||
shipPixX= -6
|
||||
drawShipPix()
|
||||
elseif screenStage>13.3 and screenStage<13.4 then
|
||||
elseif screenStage>13.3 and screenStage<13.4 then
|
||||
delShipPix()
|
||||
shipPixX= -3
|
||||
drawShipPix()
|
||||
elseif screenStage>13.4 and screenStage<13.5 then
|
||||
elseif screenStage>13.4 and screenStage<13.5 then
|
||||
delShipPix()
|
||||
shipPixX= 0
|
||||
drawShipPix()
|
||||
elseif screenStage>13.6 and screenStage<13.7 then
|
||||
elseif screenStage>13.6 and screenStage<13.7 then
|
||||
delShipPix()
|
||||
shipPixX= 3
|
||||
drawShipPix()
|
||||
elseif screenStage>13.8 and screenStage<13.9 then
|
||||
elseif screenStage>13.8 and screenStage<13.9 then
|
||||
delShipPix()
|
||||
shipPixX= 6
|
||||
drawShipPix()
|
||||
elseif screenStage>13.9 and screenStage<14 then
|
||||
elseif screenStage>13.9 and screenStage<14 then
|
||||
delShipPix()
|
||||
shipPixX= 9
|
||||
drawShipPix()
|
||||
elseif screenStage>14.1 and screenStage<14.2 then
|
||||
elseif screenStage>14.1 and screenStage<14.2 then
|
||||
delShipPix()
|
||||
shipPixX= 12
|
||||
drawShipPix()
|
||||
elseif screenStage>14.2 and screenStage<14.3 then
|
||||
elseif screenStage>14.2 and screenStage<14.3 then
|
||||
delShipPix()
|
||||
shipPixX= 15
|
||||
drawShipPix()
|
||||
elseif screenStage>14.3 and screenStage<14.4 then
|
||||
elseif screenStage>14.3 and screenStage<14.4 then
|
||||
delShipPix()
|
||||
shipPixX= 18
|
||||
drawShipPix()
|
||||
elseif screenStage>14.4 and screenStage<14.5 then
|
||||
elseif screenStage>14.4 and screenStage<14.5 then
|
||||
delShipPix()
|
||||
shipPixX= 21
|
||||
drawShipPix()
|
||||
elseif screenStage>14.5 and screenStage<14.6 then
|
||||
elseif screenStage>14.5 and screenStage<14.6 then
|
||||
delShipPix()
|
||||
shipPixX= 24
|
||||
drawShipPix()
|
||||
elseif screenStage>14.6 and screenStage<14.7 then
|
||||
elseif screenStage>14.6 and screenStage<14.7 then
|
||||
delShipPix()
|
||||
shipPixX= 27
|
||||
drawShipPix()
|
||||
elseif screenStage>14.7 and screenStage<14.8 then
|
||||
elseif screenStage>14.7 and screenStage<14.8 then
|
||||
delShipPix()
|
||||
shipPixX= 30
|
||||
drawShipPix()
|
||||
elseif screenStage>14.8 and screenStage<14.9 then
|
||||
elseif screenStage>14.8 and screenStage<14.9 then
|
||||
delShipPix()
|
||||
shipPixX= 33
|
||||
drawShipPix()
|
||||
elseif screenStage>14.9 and screenStage<15 then
|
||||
elseif screenStage>14.9 and screenStage<15 then
|
||||
delShipPix()
|
||||
shipPixX= 36
|
||||
drawShipPix()
|
||||
elseif screenStage>15 and screenStage<15.1 then
|
||||
elseif screenStage>15 and screenStage<15.1 then
|
||||
delShipPix()
|
||||
shipPixX= 39
|
||||
drawShipPix()
|
||||
elseif screenStage>15.1 and screenStage<15.2 then
|
||||
elseif screenStage>15.1 and screenStage<15.2 then
|
||||
delShipPix()
|
||||
shipPixX= 41
|
||||
drawShipPix()
|
||||
elseif screenStage>15.2 and screenStage<15.3 then
|
||||
elseif screenStage>15.2 and screenStage<15.3 then
|
||||
delShipPix()
|
||||
shipPixX= 44
|
||||
drawShipPix()
|
||||
elseif screenStage>15.3 and screenStage<15.4 then
|
||||
elseif screenStage>15.3 and screenStage<15.4 then
|
||||
delShipPix()
|
||||
shipPixX= 47
|
||||
drawShipPix()
|
||||
elseif screenStage>15.4 and screenStage<15.5 then
|
||||
elseif screenStage>15.4 and screenStage<15.5 then
|
||||
delShipPix()
|
||||
shipPixX= 50
|
||||
drawShipPix()
|
||||
elseif screenStage>15.5 and screenStage<15.6 then
|
||||
elseif screenStage>15.5 and screenStage<15.6 then
|
||||
delShipPix()
|
||||
elseif screenStage>16 and screenStage<16.9 then
|
||||
humanPixY=18
|
||||
@ -1284,7 +1284,7 @@ function startScreen()
|
||||
write("Fire when ready")
|
||||
elseif screenStage>22.1 and screenStage <27 then
|
||||
introHighScoreTable()
|
||||
elseif screenStage>27 then
|
||||
elseif screenStage>27 then
|
||||
term.setBackgroundColour(colours.black)
|
||||
for i = 2,h-1 do
|
||||
term.setCursorPos(1,i)
|
||||
@ -1292,7 +1292,7 @@ function startScreen()
|
||||
end
|
||||
screenStage=0
|
||||
end
|
||||
|
||||
|
||||
screenStage=screenStage+0.1
|
||||
screenTimer=os.startTimer(0.025)
|
||||
end
|
||||
@ -1308,4 +1308,4 @@ else
|
||||
term.setCursorPos(1,1)
|
||||
print("I'm sorry, Protector requires an Advanced Computer to run")
|
||||
print(" ")
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +89,7 @@ local titleLevel = {
|
||||
local function parseValue(x, y, lchar)
|
||||
if tonumber(lchar, 16) then
|
||||
lchar = math.pow(2, tonumber(lchar,16))
|
||||
|
||||
|
||||
if lchar == colours.blue then
|
||||
map[y][x] = 0
|
||||
elseif lchar == colours.brown then
|
||||
@ -146,7 +146,7 @@ local function loadMap(_sPath)
|
||||
goldMap = {}
|
||||
monks = {}
|
||||
goldCount = 0
|
||||
|
||||
|
||||
local file = fs.open(_sPath, "r")
|
||||
local line = file:readLine()
|
||||
while line do
|
||||
@ -279,14 +279,14 @@ local function resetMap()
|
||||
monk.x = monk.spawnX
|
||||
monk.y = monk.spawnY
|
||||
end
|
||||
|
||||
|
||||
for _,timer in pairs(blockTimers) do
|
||||
map[timer.y][timer.x] = 0
|
||||
end
|
||||
blockTimers = {}
|
||||
plX = plspawnX
|
||||
plY = plspawnY
|
||||
|
||||
|
||||
moveTimer = -1
|
||||
shootTimer = -1
|
||||
spawnTimer = -1
|
||||
@ -320,27 +320,27 @@ end
|
||||
local function drawLevelList()
|
||||
local minLev = ((levelLot-1) * 10 + 1)
|
||||
local maxLev = minLev + math.min(10, #levelList - (levelLot-1) * 10) - 1
|
||||
|
||||
|
||||
term.setCursorPos(7, 2)
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.clearLine()
|
||||
for j = 1,49 do updateMap(j,2) end
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.white)
|
||||
term.setCursorPos(7, 2)
|
||||
local msg = "Levels "..minLev.." to "..maxLev.." of "..#levelList
|
||||
term.write(msg)
|
||||
|
||||
|
||||
term.setTextColour(colours.yellow)
|
||||
term.setCursorPos(4, 2)
|
||||
if levelLot > 1 then term.write("<-")
|
||||
else term.write(" ") end
|
||||
|
||||
else term.write(" ") end
|
||||
|
||||
term.setCursorPos(8 + #msg, 2)
|
||||
if maxLev < #levelList then term.write("->")
|
||||
else term.write(" ") end
|
||||
|
||||
|
||||
for i = 1,10 do
|
||||
term.setCursorPos(1, 3+i)
|
||||
for j = 1,49 do updateMap(j,3+i) end
|
||||
@ -371,12 +371,12 @@ local function loadTitleScreen()
|
||||
if #map == 18 then break end
|
||||
end
|
||||
maxGoldCount = goldCount
|
||||
|
||||
|
||||
drawMap()
|
||||
term.setCursorPos(1,19)
|
||||
term.setBackgroundColour(colours.blue)
|
||||
term.clearLine()
|
||||
|
||||
|
||||
menIndex = 1
|
||||
titleLoaded = true
|
||||
end
|
||||
@ -384,22 +384,22 @@ end
|
||||
--Opens an in-game menu to display a series of options.
|
||||
local function inGameMenu(menuList)
|
||||
menIndex = 1
|
||||
|
||||
|
||||
local squareTop,squareBottom = 4,6 + #menuList * 2
|
||||
local squareSize = 0
|
||||
for i=1,#menuList do squareSize = math.max(squareSize, #menuList[i] + 6) end
|
||||
|
||||
|
||||
for y=squareTop,squareBottom do
|
||||
term.setCursorPos(w/2 - squareSize/2, y)
|
||||
term.setBackgroundColour(colours.lightBlue)
|
||||
term.write(string.rep(" ", squareSize))
|
||||
|
||||
|
||||
if y ~= squareTop and y ~= squareBottom then
|
||||
term.setCursorPos(w/2 - squareSize/2 + 1, y)
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.write(string.rep(" ", squareSize - 2))
|
||||
end
|
||||
|
||||
|
||||
if y ~= squareTop and y ~= squareBottom and y % 2 == 0 then
|
||||
local opt = menuList[(y - squareTop) / 2]
|
||||
term.setCursorPos(w/2 - #opt/2, y)
|
||||
@ -407,7 +407,7 @@ local function inGameMenu(menuList)
|
||||
term.write(opt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local p1 = nil
|
||||
repeat
|
||||
for i=1,#menuList do
|
||||
@ -426,20 +426,20 @@ local function inGameMenu(menuList)
|
||||
end
|
||||
end
|
||||
_,p1 = os.pullEvent("key")
|
||||
|
||||
|
||||
if p1 == keys.up and menIndex > 1 then menIndex = menIndex - 1
|
||||
elseif p1 == keys.down and menIndex < #menuList then menIndex = menIndex + 1 end
|
||||
until p1 == keys.enter
|
||||
|
||||
|
||||
return menuList[menIndex]
|
||||
end
|
||||
|
||||
--Checks to see if any given desired move is legal. Monks and players both use this.
|
||||
local function isLegalMove(initX,initY,finX,finY)
|
||||
if finY < 1 or finY > #map or finX < 1 or finX > 49 then
|
||||
return false
|
||||
if finY < 1 or finY > #map or finX < 1 or finX > 49 then
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
if map[finY][finX] ~= 0 and map[finY][finX] ~= '#' then
|
||||
--This reports 'self moves' as being illegal, but that's fine
|
||||
for _,monk in pairs(monks) do
|
||||
@ -450,10 +450,10 @@ local function isLegalMove(initX,initY,finX,finY)
|
||||
then return true
|
||||
elseif finY == initY+1 and (map[finY][finX] == "H" or (map[finY][finX] == "h" and goldCount == 0)
|
||||
or (type(map[finY][finX]) == "number" and map[finY][finX] > 0) or map[finY][finX] == nil or
|
||||
map[finY][finX] == "V" or map[finY][finX] == "-" or (map[finY][finX] == 'h' and goldCount ~= 0))
|
||||
map[finY][finX] == "V" or map[finY][finX] == "-" or (map[finY][finX] == 'h' and goldCount ~= 0))
|
||||
then return true
|
||||
elseif finX == initX-1 or finX == initX+1 then
|
||||
return true
|
||||
elseif finX == initX-1 or finX == initX+1 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -461,12 +461,12 @@ end
|
||||
--Moves the player to a given step.
|
||||
local function movePlayer(x,y,ignoreLegal)
|
||||
if not ignoreLegal and not isLegalMove(plX,plY,x,y) then return false end
|
||||
|
||||
|
||||
local ox = plX
|
||||
local oy = plY
|
||||
plX = x
|
||||
plY = y
|
||||
|
||||
|
||||
updateMap(ox,oy)
|
||||
updateMap(x,y)
|
||||
if goldMap[y][x] == 1 then
|
||||
@ -481,14 +481,14 @@ local function movePlayer(x,y,ignoreLegal)
|
||||
started = false
|
||||
nextLevel = true
|
||||
end
|
||||
|
||||
pfalling = (y < #map and map[y][x] ~= '-' and map[y][x] ~= 'H' and not (map[y][x] == 'h' and goldCount == 0)
|
||||
|
||||
pfalling = (y < #map and map[y][x] ~= '-' and map[y][x] ~= 'H' and not (map[y][x] == 'h' and goldCount == 0)
|
||||
and (map[y+1][x] == nil or map[y+1][x] == "V" or map[y+1][x] == 2 or map[y+1][x] == '-'))
|
||||
if (y < #map and map[y+1][x] == 'h' and goldCount ~= 0) then pfalling = true end
|
||||
for _,monk in pairs(monks) do
|
||||
if monk.x == plX and monk.y == plY + 1 then pfalling = false break end
|
||||
end
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -634,7 +634,7 @@ local function updateMonks()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if not (monk.trapped or monk.dead) then
|
||||
--Has the monk decided on moving left or right? If so we try to move him
|
||||
if monk.desX and not monk.falling then
|
||||
@ -708,7 +708,7 @@ local function updateBlockTimer(tid)
|
||||
end
|
||||
|
||||
local function shootBlock(x,y)
|
||||
if y <= #map and map[y][x] == 0 and (map[y-1][x] == nil
|
||||
if y <= #map and map[y][x] == 0 and (map[y-1][x] == nil
|
||||
or map[y-1][x] == 2 or (map[y-1][x] == 'h' and goldCount > 0)) then
|
||||
map[y][x] = 3
|
||||
table.insert(blockTimers, {x = x; y = y; timer = os.startTimer(0.1);} )
|
||||
@ -718,14 +718,14 @@ end
|
||||
|
||||
local function handleEvents()
|
||||
local id,p1,p2,p3 = os.pullEvent()
|
||||
|
||||
|
||||
if id == "key" then
|
||||
--Menu Handling
|
||||
if p1 == keys.up then
|
||||
if menIndex > 1 then menIndex = menIndex - 1 end
|
||||
elseif p1 == keys.down then
|
||||
if inLevelSelect then
|
||||
if menIndex < math.min(10, #levelList - (levelLot-1)*10) then
|
||||
if inLevelSelect then
|
||||
if menIndex < math.min(10, #levelList - (levelLot-1)*10) then
|
||||
menIndex = menIndex + 1
|
||||
end
|
||||
elseif menIndex < #titleOptions then menIndex = menIndex + 1 end
|
||||
@ -736,7 +736,7 @@ local function handleEvents()
|
||||
levelLot = levelLot + 1
|
||||
drawLevelList()
|
||||
end
|
||||
|
||||
|
||||
--Game Handling
|
||||
if p1 == keys.a and moveTimer == -1 and spawnTimer == -1 then
|
||||
movePlayer(plX-1,plY)
|
||||
@ -811,7 +811,7 @@ local function handleEvents()
|
||||
monk.trapped = nil
|
||||
monk.behaviour = "none"
|
||||
monk.justEscaped = true
|
||||
|
||||
|
||||
updateMap(monk.x, monk.y+1)
|
||||
drawMonk(monk)
|
||||
end
|
||||
@ -859,12 +859,12 @@ local pallette = { { t = colours.black, b = colours.blue, s = " ", n = "Solid G
|
||||
local brushType = 1
|
||||
|
||||
local function getHexOf(colour)
|
||||
if not colour or not tonumber(colour) then
|
||||
return " "
|
||||
if not colour or not tonumber(colour) then
|
||||
return " "
|
||||
end
|
||||
local value = math.log(colour)/math.log(2)
|
||||
if value > 9 then
|
||||
value = hexnums[value]
|
||||
if value > 9 then
|
||||
value = hexnums[value]
|
||||
end
|
||||
return value
|
||||
end
|
||||
@ -878,7 +878,7 @@ local function drawFooter()
|
||||
term.setCursorPos(w,i)
|
||||
term.write(" ")
|
||||
end
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.blue)
|
||||
term.setCursorPos(2,h)
|
||||
@ -904,7 +904,7 @@ local function drawPallette(xpos,ypos)
|
||||
local top = ypos
|
||||
if xpos + xdim > w then left = left + (w - xpos - xdim) end
|
||||
if ypos + ydim > h then top = top + (h - ypos - ydim) end
|
||||
|
||||
|
||||
--There's no easy way to do this... so we draw it manually :(
|
||||
for i=0,4 do
|
||||
term.setCursorPos(left, top + i)
|
||||
@ -913,25 +913,25 @@ local function drawPallette(xpos,ypos)
|
||||
if i == 0 or i == 4 then term.write("*-----*")
|
||||
else term.write("* *") end
|
||||
end
|
||||
|
||||
|
||||
for i=1,#pallette-1 do
|
||||
local ypl = 1
|
||||
local xmv = i
|
||||
if i > 5 then ypl = 2 xmv = i - 5 end
|
||||
|
||||
|
||||
term.setCursorPos(left + xmv, top+ypl)
|
||||
term.setBackgroundColour(pallette[i].b)
|
||||
term.setTextColour(pallette[i].t)
|
||||
term.write(pallette[i].s)
|
||||
end
|
||||
|
||||
|
||||
term.setCursorPos(left + 1, top + 3)
|
||||
term.setBackgroundColour(colours.red)
|
||||
term.setTextColour(colours.black)
|
||||
term.write("ERASE")
|
||||
|
||||
|
||||
local _,button,x,y = os.pullEvent("mouse_click")
|
||||
|
||||
|
||||
if button == 1 then
|
||||
if y == top + 1 and x > left and x < left + 6 then
|
||||
brushType = x-left
|
||||
@ -941,9 +941,9 @@ local function drawPallette(xpos,ypos)
|
||||
brushType = 11
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for y = top,top+ydim do
|
||||
for x = left,left+xdim do
|
||||
for x = left,left+xdim do
|
||||
--Not sure why the -2 is necessary
|
||||
if map[y+drawOffsetY] then updateMap(x-2,y+drawOffsetY) end
|
||||
end
|
||||
@ -955,7 +955,7 @@ end
|
||||
local function saveCurrentMap(path)
|
||||
local file = io.open(shell.resolve(".").."/levels/"..path, "w")
|
||||
if not file then return false end
|
||||
|
||||
|
||||
drawMap()
|
||||
drawFooter()
|
||||
local msg = "Saving.."
|
||||
@ -968,7 +968,7 @@ local function saveCurrentMap(path)
|
||||
term.write(string.rep(" ", 18))
|
||||
term.setCursorPos(w/2-9,6)
|
||||
term.setBackgroundColour(colours.lime)
|
||||
|
||||
|
||||
for y=1,#map do
|
||||
local xstr = ""
|
||||
for x=1,49 do
|
||||
@ -1016,14 +1016,14 @@ local function runLevelEditor()
|
||||
end
|
||||
monks = {}
|
||||
end
|
||||
|
||||
|
||||
drawMap()
|
||||
drawFooter()
|
||||
|
||||
|
||||
while inLevelEditor do
|
||||
local id,button,x,y = os.pullEvent()
|
||||
if id == "mouse_click" or id == "mouse_drag" then
|
||||
if button == 2 then
|
||||
if button == 2 then
|
||||
drawPallette(x,y)
|
||||
elseif x > drawOffsetX and x <= 49 + drawOffsetX and y > drawOffsetY and y <= 18 + drawOffsetY then
|
||||
if pallette[brushType].v == "player" then
|
||||
@ -1095,7 +1095,7 @@ local function runLevelSelect()
|
||||
if not titleLoaded then
|
||||
loadTitleScreen()
|
||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||
else
|
||||
else
|
||||
drawMap()
|
||||
drawEndgameMap()
|
||||
term.setCursorPos(1,19)
|
||||
@ -1103,11 +1103,11 @@ local function runLevelSelect()
|
||||
term.clearLine()
|
||||
end
|
||||
drawLevelList()
|
||||
|
||||
|
||||
menSel = "none"
|
||||
repeat
|
||||
handleEvents()
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.yellow)
|
||||
for i=1,10 do
|
||||
@ -1131,23 +1131,23 @@ local function runTitle()
|
||||
term.write("Gold Runner")
|
||||
term.setCursorPos(16,4)
|
||||
term.write("By Nitrogen Fingers")
|
||||
|
||||
|
||||
term.setTextColour(colours.white)
|
||||
for i=1,#titleOptions do
|
||||
term.setCursorPos(19, 5 + (i*2))
|
||||
term.write(titleOptions[i])
|
||||
end
|
||||
|
||||
|
||||
term.setCursorPos(16, 7)
|
||||
term.setTextColour(colours.yellow)
|
||||
term.write("->")
|
||||
|
||||
|
||||
menSel = "none"
|
||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||
|
||||
|
||||
repeat
|
||||
handleEvents()
|
||||
|
||||
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.yellow)
|
||||
for i=1,#titleOptions do
|
||||
@ -1166,25 +1166,25 @@ local function playLevel()
|
||||
drawHUD()
|
||||
os.pullEvent("key")
|
||||
movePlayer(plX,plY,true)
|
||||
|
||||
|
||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||
moveTimer = os.startTimer(moveIntv)
|
||||
shootTimer = -1
|
||||
spawnTimer = -1
|
||||
|
||||
|
||||
started = true
|
||||
while started do
|
||||
handleEvents()
|
||||
end
|
||||
|
||||
|
||||
if menSel == "Quit" or menSel == "Back to Title" or menSel == "Edit Level" then
|
||||
running = false
|
||||
return
|
||||
end
|
||||
menSel = "none"
|
||||
|
||||
|
||||
if nextLevel then
|
||||
if currentLevel == #levelList then
|
||||
if currentLevel == #levelList then
|
||||
started = false
|
||||
running = false
|
||||
break
|
||||
@ -1198,12 +1198,12 @@ local function playLevel()
|
||||
else
|
||||
playerLives = playerLives-1
|
||||
if playerLives > 0 then resetMap()
|
||||
else
|
||||
running = false
|
||||
else
|
||||
running = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if nextLevel then
|
||||
local msg = "All levels defeated, Gold Runner!"
|
||||
term.setBackgroundColour(colours.black)
|
||||
@ -1247,7 +1247,7 @@ while menSel ~= "Quit" do
|
||||
term.setCursorPos(1,19)
|
||||
term.setBackgroundColour(colours.blue)
|
||||
term.clearLine()
|
||||
|
||||
|
||||
term.setCursorPos(16,10)
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.setTextColour(colours.white)
|
||||
@ -1256,13 +1256,13 @@ while menSel ~= "Quit" do
|
||||
term.setCursorPos(17,11)
|
||||
term.setCursorBlink(true)
|
||||
local levelName = ""
|
||||
|
||||
|
||||
local id,p1
|
||||
repeat
|
||||
id,p1 = os.pullEvent()
|
||||
if id == "key" and p1 == keys.backspace then
|
||||
levelName = string.sub(levelName, 1, #levelName - 1)
|
||||
elseif id == "timer" and p1 == monkTimer then
|
||||
elseif id == "timer" and p1 == monkTimer then
|
||||
updateMonks()
|
||||
monkTimer = os.startTimer(moveIntv * 2)
|
||||
elseif id == "char" and #levelName < 14 then
|
||||
@ -1273,15 +1273,15 @@ while menSel ~= "Quit" do
|
||||
term.write(levelName..string.rep(" ",14 - #levelName))
|
||||
term.setCursorPos(17 + #levelName ,11)
|
||||
until id == "key" and p1 == keys.enter and #levelName > 0
|
||||
|
||||
|
||||
term.setCursorBlink(false)
|
||||
levelEditName = levelName
|
||||
runLevelEditor()
|
||||
|
||||
|
||||
if menSel == "Play Level" then
|
||||
currentLevel = nil
|
||||
levelList = fs.list(shell.resolve(".").."/levels")
|
||||
for num,name in pairs(levelList) do
|
||||
for num,name in pairs(levelList) do
|
||||
if name == levelName then
|
||||
currentLevel = num
|
||||
break
|
||||
@ -1296,7 +1296,7 @@ while menSel ~= "Quit" do
|
||||
runLevelEditor()
|
||||
term.setBackgroundColour(colours.black)
|
||||
term.clear()
|
||||
|
||||
|
||||
if menSel == "Play Level" then
|
||||
menSel = "New Game"
|
||||
else
|
||||
|
@ -1,7 +1,7 @@
|
||||
--[[
|
||||
3D Print
|
||||
A printing program for use with NPaintPro
|
||||
|
||||
|
||||
By NitrogenFingers
|
||||
]]--
|
||||
|
||||
@ -30,7 +30,7 @@ local commandList = {
|
||||
["DE"] = endPrint;
|
||||
}
|
||||
|
||||
--Splits a string according to a pattern into a table
|
||||
--Splits a string according to a pattern into a table
|
||||
local function split(str, pattern)
|
||||
local t = { }
|
||||
local fpat = "(.-)" .. pattern
|
||||
@ -56,11 +56,11 @@ local function respondToQuery()
|
||||
print("Listening for ACT/ID query")
|
||||
local id,key = rednet.receive()
|
||||
print("Received : "..key)
|
||||
|
||||
|
||||
if key == "$3DPRINT IDENTIFY" then
|
||||
print("Requested Identification")
|
||||
rednet.send(id, "$3DPRINT IDACK "..os.getComputerLabel())
|
||||
|
||||
|
||||
elseif key == "$3DPRINT ACTIVATE" then
|
||||
print("Requested Activation")
|
||||
activeCommander = id
|
||||
@ -76,10 +76,10 @@ local function performPrint()
|
||||
while operatingPrint do
|
||||
local id,msg = rednet.receive()
|
||||
print("Command : "..msg)
|
||||
|
||||
|
||||
if id == activeCommander and string.find(msg, "$PC") == 1 then
|
||||
local cmds = split(msg, " ")
|
||||
|
||||
|
||||
--It's a bit of a hack, but those are the 2 methods required for a refuel
|
||||
if turtle.getFuelLevel() == 0 and cmds[2] ~= "SS" and cmds[2] ~= "RF" then
|
||||
rednet.send(id, "$3DPRINT OOF")
|
||||
@ -95,7 +95,7 @@ local function performPrint()
|
||||
commandList[cmds[2]][i](tonumber(cmds[3]))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
rednet.send(activeCommander, "$3DPRINT ACK")
|
||||
end
|
||||
end
|
||||
@ -116,4 +116,4 @@ while true do
|
||||
respondToQuery()
|
||||
--Perform the print
|
||||
performPrint()
|
||||
end
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ function initializeBuffer(terminal)
|
||||
if not terminal.isColour() then
|
||||
error("Parameter does not represent an advanced computer.")
|
||||
end
|
||||
|
||||
|
||||
tw,th = terminal.getSize()
|
||||
backbuffer = { }
|
||||
for y=1,th do
|
||||
@ -41,8 +41,8 @@ end
|
||||
function clearBuffer(colour)
|
||||
if not backbuffer then
|
||||
error("Back buffer not yet initialized!")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for y=1,#backbuffer do
|
||||
backbuffer[y] = { }
|
||||
if colour then
|
||||
@ -60,26 +60,26 @@ end
|
||||
function writeToBuffer(entity)
|
||||
if not backbuffer then
|
||||
error("Back buffer not yet initialized!")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local image = nil
|
||||
if entity.type == "animation" then
|
||||
image = entity.frames[entity.currentFrame]
|
||||
else
|
||||
image = entity.image
|
||||
end
|
||||
|
||||
|
||||
for y=1,image.dimensions.height do
|
||||
for x=1,image.dimensions.width do
|
||||
if image[y][x] then
|
||||
local xpos,ypos = x,y
|
||||
if entity.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||
if entity.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||
|
||||
|
||||
--If the YPos doesn't exist, no need to loop through the rest of X!
|
||||
--Don't you love optimization?
|
||||
if not backbuffer[entity.y + ypos - 1] then break end
|
||||
|
||||
|
||||
backbuffer[entity.y + ypos - 1][entity.x + xpos - 1] = image[y][x]
|
||||
end
|
||||
end
|
||||
@ -93,7 +93,7 @@ end
|
||||
function drawBuffer(terminal)
|
||||
if not backbuffer then
|
||||
error("Back buffer not yet initialized!")
|
||||
end
|
||||
end
|
||||
if not terminal then terminal = term end
|
||||
if not terminal.setCursorPos or not terminal.setBackgroundColour or not terminal.write then
|
||||
error("Parameter cannot be used to initialize the backbuffer.")
|
||||
@ -101,7 +101,7 @@ function drawBuffer(terminal)
|
||||
if not terminal.isColour() then
|
||||
error("Parameter does not represent an advanced computer.")
|
||||
end
|
||||
|
||||
|
||||
for y=1,math.min(#backbuffer, th) do
|
||||
for x=1,tw do
|
||||
if backbuffer[y][x] then
|
||||
@ -167,14 +167,14 @@ end
|
||||
]]--
|
||||
local function drawS(self)
|
||||
local image = self.image
|
||||
|
||||
|
||||
for y=1,image.dimensions.height do
|
||||
for x=1,image.dimensions.width do
|
||||
if image[y][x] then
|
||||
local xpos,ypos = x,y
|
||||
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||
|
||||
|
||||
term.setBackgroundColour(image[y][x])
|
||||
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
||||
term.write(" ")
|
||||
@ -198,7 +198,7 @@ local function drawA(self, frame)
|
||||
local xpos,ypos = x,y
|
||||
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||
|
||||
|
||||
term.setBackgroundColour(image[y][x])
|
||||
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
||||
term.write(" ")
|
||||
@ -259,16 +259,16 @@ local function drawBounds(entity, colour)
|
||||
local image = nil
|
||||
if entity.type == "animation" then image = entity.frames[entity.currentFrame]
|
||||
else image = entity.image end
|
||||
|
||||
|
||||
term.setBackgroundColour(colour)
|
||||
|
||||
|
||||
corners = {
|
||||
topleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y - 1 };
|
||||
topright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y - 1 };
|
||||
botleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
||||
botright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
||||
}
|
||||
|
||||
|
||||
term.setCursorPos(corners.topleft.x, corners.topleft.y)
|
||||
term.write(" ")
|
||||
term.setCursorPos(corners.topright.x, corners.topright.y)
|
||||
@ -308,7 +308,7 @@ end
|
||||
local function rCollidesWith(self, other)
|
||||
--First we construct the rectangles
|
||||
local img1C, img2C = createRectangle(self), createRectangle(other)
|
||||
|
||||
|
||||
--We then determine the "relative position" , in terms of which is farther left or right
|
||||
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
||||
if img1C.left < img2C.left then
|
||||
@ -325,13 +325,13 @@ local function rCollidesWith(self, other)
|
||||
topmost = img2C
|
||||
botmost = img1C
|
||||
end
|
||||
|
||||
|
||||
--Then we determine the distance between the "extreme" edges-
|
||||
--distance between leftmost/right edge and rightmost/left edge
|
||||
--distance between topmost/bottom edge and bottommost/top edge
|
||||
local xdist = rightmost.left - leftmost.right
|
||||
local ydist = botmost.top - topmost.bottom
|
||||
|
||||
|
||||
--If both are negative, our rectangles intersect!
|
||||
return xdist <= 0 and ydist <= 0
|
||||
end
|
||||
@ -352,13 +352,13 @@ local function pCollidesWith(self, other)
|
||||
else img1 = self.image end
|
||||
if other.type == "animation" then img2 = other.frames[other.currentFrame]
|
||||
else img2 = other.image end
|
||||
|
||||
|
||||
--...then we position them...
|
||||
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
||||
--We also keep track of which is left and which is right- it doesn't matter in a rectangle
|
||||
--collision but it does in a pixel collision.
|
||||
img1T,img2T = {},{}
|
||||
|
||||
|
||||
if img1C.left < img2C.left then
|
||||
leftmost = img1C
|
||||
rightmost = img2C
|
||||
@ -377,15 +377,15 @@ local function pCollidesWith(self, other)
|
||||
botmost = img1C
|
||||
img2T.top = true
|
||||
end
|
||||
|
||||
|
||||
--...and we again find the distances between the extreme edges.
|
||||
local xdist = rightmost.left - leftmost.right
|
||||
local ydist = botmost.top - topmost.bottom
|
||||
|
||||
|
||||
--If these distances are > 0 then we stop- no need to go any farther.
|
||||
if xdist > 0 or ydist > 0 then return false end
|
||||
|
||||
|
||||
|
||||
|
||||
for x = rightmost.left, rightmost.left + math.abs(xdist) do
|
||||
for y = botmost.top, botmost.top + math.abs(ydist) do
|
||||
--We know a collision has occurred if a pixel is occupied by both images. We do this by
|
||||
@ -398,16 +398,16 @@ local function pCollidesWith(self, other)
|
||||
else testX = x - img1C.left + 1 end
|
||||
if img1T.top then testY = y - img1C.top + 1
|
||||
else testY = y - img1C.top + 1 end
|
||||
|
||||
|
||||
local occupy1 = img1[testY + img1.bounds.y-1][testX + img1.bounds.x-1] ~= nil
|
||||
|
||||
|
||||
if img2T.left then testX = x - img2C.left + 1
|
||||
else testX = x - img2C.left + 1 end
|
||||
if img2T.top then testY = y - img2C.top + 1
|
||||
else testY = y - img2C.top + 1 end
|
||||
|
||||
|
||||
local occupy2 = img2[testY + img2.bounds.y-1][testX + img2.bounds.x-1] ~= nil
|
||||
|
||||
|
||||
if occupy1 and occupy2 then return true end
|
||||
end
|
||||
end
|
||||
@ -429,7 +429,7 @@ local function moveTo(self, x, y)
|
||||
else
|
||||
image = self.image
|
||||
end
|
||||
|
||||
|
||||
self.x = x - image.bounds.x + 1
|
||||
self.y = y - image.bounds.y + 1
|
||||
end
|
||||
@ -448,7 +448,7 @@ image:table = a table of the image. Indexed by height, a series of sub-tables, e
|
||||
dimensions:table =
|
||||
width = the width of the entire image in pixels
|
||||
height = the height of the entire image in pixels
|
||||
|
||||
|
||||
mirror:table =
|
||||
x:bool = whether or not the image is mirrored on the X axis
|
||||
y:bool = whether or not the image is mirrored on the Y axis
|
||||
@ -464,19 +464,19 @@ draw:function = see drawS (above)
|
||||
y:number = the initial Y position of the sprite
|
||||
]]--
|
||||
function loadSprite(path, x, y)
|
||||
local sprite = {
|
||||
local sprite = {
|
||||
type = "sprite",
|
||||
x = x,
|
||||
y = y,
|
||||
image = { },
|
||||
mirror = { x = false, y = false }
|
||||
}
|
||||
|
||||
|
||||
if fs.exists(path) then
|
||||
local file = io.open(path, "r" )
|
||||
local leftX, rightX = math.huge, 0
|
||||
local topY, botY = nil,nil
|
||||
|
||||
|
||||
local lcount = 0
|
||||
for line in file:lines() do
|
||||
lcount = lcount+1
|
||||
@ -492,7 +492,7 @@ function loadSprite(path, x, y)
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
|
||||
|
||||
sprite.image.bounds = {
|
||||
x = leftX,
|
||||
width = rightX - leftX + 1,
|
||||
@ -503,10 +503,10 @@ function loadSprite(path, x, y)
|
||||
width = rightX,
|
||||
height = botY
|
||||
}
|
||||
|
||||
|
||||
sprite.x = sprite.x - leftX + 1
|
||||
sprite.y = sprite.y - topY + 1
|
||||
|
||||
|
||||
sprite.repaint = repaintS
|
||||
sprite.rCollidesWith = rCollidesWith
|
||||
sprite.pCollidesWith = pCollidesWith
|
||||
@ -536,13 +536,13 @@ function loadAnimation(path, x, y, currentFrame)
|
||||
mirror = { x = false, y = false },
|
||||
currentFrame = currentFrame
|
||||
}
|
||||
|
||||
|
||||
table.insert(anim.frames, { })
|
||||
if fs.exists(path) then
|
||||
local file = io.open(path, "r")
|
||||
local leftX, rightX = math.huge, 0
|
||||
local topY, botY = nil,nil
|
||||
|
||||
|
||||
local lcount = 0
|
||||
for line in file:lines() do
|
||||
lcount = lcount+1
|
||||
@ -589,17 +589,17 @@ function loadAnimation(path, x, y, currentFrame)
|
||||
}
|
||||
anim.x = anim.x - leftX + 1
|
||||
anim.y = anim.y - topY + 1
|
||||
|
||||
if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
|
||||
currentFrame > #anim.frames then
|
||||
anim.currentFrame = 1
|
||||
|
||||
if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
|
||||
currentFrame > #anim.frames then
|
||||
anim.currentFrame = 1
|
||||
end
|
||||
|
||||
|
||||
anim.timerID = nil
|
||||
anim.lowerBound = 1
|
||||
anim.upperBound = #anim.frames
|
||||
anim.updating = false
|
||||
|
||||
|
||||
anim.repaint = repaintA
|
||||
anim.rCollidesWith = rCollidesWith
|
||||
anim.pCollidesWith = pCollidesWith
|
||||
@ -612,4 +612,4 @@ function loadAnimation(path, x, y, currentFrame)
|
||||
else
|
||||
error(path.." not found!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -175,4 +175,4 @@ drawScreen()
|
||||
while true do
|
||||
loop()
|
||||
parallel.waitForAny(loop, compute)
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@
|
||||
--
|
||||
-- @tparam string func The function's name
|
||||
-- @tparam int idx The argument index to this function
|
||||
-- @tparam string ty The type this argument should have. May be 'value' for
|
||||
-- @tparam string ty The type this argument should have. May be 'value' for
|
||||
-- any non-nil value.
|
||||
-- @param val val The value to check
|
||||
-- @throws If this value doesn't match the expected type.
|
||||
|
@ -39,7 +39,7 @@ describe("The rm program", function()
|
||||
expect(capture(stub, "rm"))
|
||||
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
|
||||
end)
|
||||
|
||||
|
||||
it("errors when trying to delete a read-only file", function()
|
||||
expect(capture(stub, "rm /rom/startup.lua"))
|
||||
:matches { ok = true, output = "", error = "/rom/startup.lua: Access denied\n" }
|
||||
|
@ -2,7 +2,7 @@ local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The edit program", function()
|
||||
|
||||
it("displays its usage when given no argument", function()
|
||||
it("displays its usage when given no argument", function()
|
||||
expect(capture(stub, "edit"))
|
||||
:matches { ok = true, output = "Usage: edit <path>\n", error = "" }
|
||||
end)
|
||||
|
@ -51,7 +51,7 @@ describe("The pastebin program", function()
|
||||
|
||||
local file = fs.open( "testup", "w" )
|
||||
file.close()
|
||||
|
||||
|
||||
expect(capture(stub, "pastebin", "put", "testup" ))
|
||||
:matches { ok = true, output = "Connecting to pastebin.com... Success.\nUploaded as https://pastebin.com/abcde\nRun \"pastebin get abcde\" to download anywhere\n", error = "" }
|
||||
end)
|
||||
|
@ -1,7 +1,7 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The id program", function()
|
||||
|
||||
|
||||
it("displays computer id", function()
|
||||
local id = os.getComputerID()
|
||||
|
||||
|
@ -7,7 +7,7 @@ describe("The motd program", function()
|
||||
file.write("Hello World!")
|
||||
file.close()
|
||||
settings.set("motd.path", "/modt_check.txt")
|
||||
|
||||
|
||||
expect(capture(stub, "motd"))
|
||||
:matches { ok = true, output = "Hello World!\n", error = "" }
|
||||
end)
|
||||
|
@ -6,7 +6,7 @@ describe("The set program", function()
|
||||
settings.clear()
|
||||
settings.set("Test", "Hello World!")
|
||||
settings.set("123", 456)
|
||||
|
||||
|
||||
expect(capture(stub, "set"))
|
||||
:matches { ok = true, output = '"123" is 456\n"Test" is "Hello World!"\n', error = "" }
|
||||
end)
|
||||
@ -15,12 +15,12 @@ describe("The set program", function()
|
||||
settings.clear()
|
||||
settings.set("Test", "Hello World!")
|
||||
settings.set("123", 456)
|
||||
|
||||
|
||||
expect(capture(stub, "set Test"))
|
||||
:matches { ok = true, output = '"Test" is "Hello World!"\n', error = "" }
|
||||
end)
|
||||
|
||||
it("set a setting", function()
|
||||
it("set a setting", function()
|
||||
expect(capture(stub, "set Test Hello"))
|
||||
:matches { ok = true, output = '"Test" set to "Hello"\n', error = "" }
|
||||
|
||||
|
@ -5,7 +5,7 @@ describe("The time program", function()
|
||||
it("displays time", function()
|
||||
local time = textutils.formatTime(os.time())
|
||||
local day = os.day()
|
||||
|
||||
|
||||
expect(capture(stub, "time"))
|
||||
:matches { ok = true, output = "The time is " .. time .. " on Day " .. day .. "\n", error = "" }
|
||||
end)
|
||||
|
28
tools/check-lines.py
Normal file
28
tools/check-lines.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pathlib, sys
|
||||
|
||||
problems = False
|
||||
|
||||
# Skip images and files without extensions
|
||||
exclude = [ ".png", "" ]
|
||||
|
||||
for path in pathlib.Path(".").glob("src/**/*"):
|
||||
if path.is_dir() or path.suffix in exclude:
|
||||
continue
|
||||
|
||||
with path.open(encoding="utf-8") as file:
|
||||
has_dos, has_trailing, needs_final = False, False, False
|
||||
for i, line in enumerate(file):
|
||||
if len(line) >= 2 and line[-2] == "\r" and line[-1] == "\n" and not has_line:
|
||||
print("%s has contains '\\r\\n' on line %d" % (path, i + 1))
|
||||
problems = has_dos = True
|
||||
|
||||
if len(line) >= 2 and line[-2] in " \t" and line[-1] == "\n" and not has_trailing:
|
||||
print("%s has trailing whitespace on line %d" % (path, i + 1))
|
||||
problems = has_trailing = True
|
||||
|
||||
if line is not None and len(line) >= 1 and line[-1] != "\n":
|
||||
print("%s should end with '\\n'" % path)
|
||||
problems = True
|
||||
|
||||
if problems:
|
||||
sys.exit(1)
|
Loading…
Reference in New Issue
Block a user