Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
local w, h = term.getSize() a = 0 timer = os.startTimer(0) --variables snakecolor = colors.green nInterval = 0.3 fruitcolor = colors.red textcolor = colors.yellow edgecolor = colors.blue HIGHSCORE = 0 HIGHSCOREP = "NoOne" --functions function drawpixel(x, y, color) term.setCursorPos(x, y) term.setBackgroundColor(color) term.write(" ") term.setBackgroundColor(colors.black) end local function printCentred(y, s) local x = math.floor((w - string.len(s)) / 2) term.setCursorPos(x, y) --term.clearLine() term.write(s) end local function addwall() yes = 0 while true do randomx = math.random(1, w) randomy = math.random(2, h) for i = 1, #sx do if sx[i] == randomx and sy[i] == randomy then yes = yes + 1 end end for i = 1, #fruitx do if fruitx[i] == randomx and fruity[i] == randomy then yes = yes + 1 end end if yes == 0 then break end end wallx[#wallx + 1] = randomx wally[#wally + 1] = randomy end local function addfruit(p1) yes = 0 while true do randomx = math.random(1, w) randomy = math.random(2, h) for i = 1, #sx do if sx[i] == randomx and sy[i] == randomy then yes = yes + 1 end end if yes == 0 then break end end fruitx[p1] = randomx fruity[p1] = randomy end function drawline(xc, yc, xv, yv, color) if xc == xv then if yc < yv then for i = 1, yv - yc + 1 do drawpixel(xc, yc + i - 1, color) end else for i = 1, yc - yv + 1 do drawpixel(xc, yc - i + 1, color) end end elseif yc == yv then if xc < xv then for i = 1, xv - xc + 1 do drawpixel(xc + i - 1, yc, color) end else for i = 1, xc - xv + 1 do drawpixel(xc - i + 1, yc, color) end end end end function edge() drawline(1, 1, 1, h, edgecolor) drawline(1, 1, w, 1, edgecolor) drawline(w, 1, w, h, colors.blue) drawline(1, h, w, h, edgecolor) end function drawgame() term.clear() for i = 1, #sx do term.setCursorPos(sx[i], sy[i]) term.setBackgroundColor(snakecolor) term.write(" ") term.setBackgroundColor(colors.black) end for i = 1, #fruitx do term.setCursorPos(fruitx[i], fruity[i]) term.setBackgroundColor(fruitcolor) term.write(" ") end for i = 1, #wallx do term.setCursorPos(wallx[i], wally[i]) term.setBackgroundColor(edgecolor) term.write(" ") end term.setBackgroundColor(colors.black) if diffeculty >= 2 then edge() end drawline(1,1,w,1,edgecolor) term.setBackgroundColor(edgecolor) term.setCursorPos(1, 1) term.write("score:" .. score*(diffeculty+1)) term.write(" ".."HIGHSCORE:"..HIGHSCORE.." Holder:\""..HIGHSCOREP.."\"") term.setCursorPos(w-string.len("Difficulty:" ..diffeculty), 1) term.write("Difficulty:" ..diffeculty) term.setBackgroundColor(colors.black) end function menu(list,clears,where) selected = 1 if not clears then term.clear() end term.setTextColor(textcolor) for i=1,#list do if selected == i then printCentred(h/2 - #list/2 + (i-1), "["..list[i].."]") else printCentred(h/2 - #list/2 + (i-1), list[i]) end end if where == 1 then printCentred(1,"press BackSpace (<----) to puase") end while true do local event, o1, o2 = os.pullEvent("key") term.clear() if clears then drawgame() end if where == 1 then printCentred(1,"press BackSpace (<----) to puase") end if o1 == keys.up then selected = selected + -1 end if o1 == keys.down then selected = selected - -1 end if selected > #list then selected = 1 end if selected < 1 then selected = #list end if o1 == keys.enter then break end for i=1,#list do if selected == i then printCentred(h/2 - #list/2 + (i-1), "["..list[i].."]") else printCentred(h/2 - #list/2 + (i-1), list[i]) end end end return selected end function start() --menu diffeculty = menu({"easy","normal","HARD","VERY HARD!","IMPOSIBLE!","Leave"},false,1) - 1 --game nInterval = 0.3 wallx = {} wally = {} sx = {6, 5, 4} sy = {5, 5, 5} dx = 1 dy = 0 die = false fb = 0 die = false if diffeculty > 0 then fb = 0.2 end if diffeculty >= 3 then fb = 0.4 end fruitx = {math.floor(w / 2)} fruity = {math.floor(h / 2)} nInterval = nInterval - fb local timer = os.startTimer(nInterval) move = 0 if diffeculty ~= 5 then while true do event, o1, o2 = os.pullEvent() if event == "timer" and o1 == timer then timer = os.startTimer(nInterval) end if event == "key" then if o1 == keys.right and dx == 0 and move == 0 then dx = 1 dy = 0 move = 1 end if o1 == keys.left and dx == 0 and move == 0 then dx = -1 dy = 0 move = 1 end if o1 == keys.up and dy == 0 and move == 0 then dx = 0 dy = -1 move = 1 end if o1 == keys.down and dy == 0 and move == 0 then dx = 0 dy = 1 move = 1 end if o1 == keys.backspace then if menu({"Resume","Difficulty Select"},true) == 2 then break end timer = os.startTimer(nInterval) end if o1 == keys.space then addfruit(#fruitx + 1) end end if event == "timer" then move = 0 table.insert(sx, 1, sx[1] + dx) table.insert(sy, 1, sy[1] + dy) for i = 1, #sx - 1 do if sx[1] == sx[i + 1] and sy[1] == sy[i + 1] then die = true end end for i = 1, #wallx do if sx[1] == wallx[i] and sy[1] == wally[i] then die = true end end for i = 1, #fruitx do if fruitx[i] == sx[1] and sy[1] == fruity[i] then addfruit(i) if diffeculty == 4 then addwall() end grow = true end end if #fruitx == 0 then addfruit(1) end if not grow then sx[#sx] = nil sy[#sy] = nil end grow = false if diffeculty < 2 then if sx[1] > w then sx[1] = 1 end if sx[1] < 1 then sx[1] = w end if sy[1] > h then sy[1] = 2 end if sy[1] < 2 then sy[1] = h end else if sx[1] > w - 1 then die = true end if sx[1] < 2 then die = true end if sy[1] > h - 1 then die = true end if sy[1] < 2 then die = true end end score = #sx -3 drawgame() if score*(diffeculty+1) > HIGHSCORE then HIGHSCOREP = "you" HIGHSCORE = score*(diffeculty+1) end if die then score = score*(diffeculty+1) term.clear() printCentred(math.floor(h / 2) - 1, "you died") printCentred(math.floor(h / 2), "score:" .. score) if HIGHSCOREP == "you" then HIGHSCOREP = "__" printCentred(math.floor(h / 2) + 1, "NEW HIGH SCORE!") printCentred(math.floor(h / 2) + 2, "EnterName:"..HIGHSCOREP) shift = 0 while true do local event, key = os.pullEvent("key") if key == keys.leftShift or key == keys.rightShift then shift = 1 - shift end kes = keys.getName(key) if shift == 1 then kes = string.upper(kes) end if #kes == 1 and string.sub(HIGHSCOREP,1,1) ~= "_" then HIGHSCOREP = string.sub(HIGHSCOREP,1,1) HIGHSCOREP = HIGHSCOREP..kes end if #kes == 1 and string.sub(HIGHSCOREP,1,1) == "_" then HIGHSCOREP = kes.."_" end if key == keys.backspace and string.sub(HIGHSCOREP,2,2) == "_" then HIGHSCOREP = "__" end if key == keys.backspace and string.sub(HIGHSCOREP,2,2) ~= "_" then HIGHSCOREP = string.sub(HIGHSCOREP,1,1) HIGHSCOREP = HIGHSCOREP.."_" end if key == keys.enter and string.sub(HIGHSCOREP,2,2) ~= "_" then break end printCentred(math.floor(h / 2) + 2, "EnterName:"..HIGHSCOREP) end printCentred(math.floor(h / 2) + 1, "NEW HIGH SCORE!") printCentred(math.floor(h / 2) + 2, "press ENTER to play agian") else printCentred(math.floor(h / 2) + 1, "press ENTER to play agian") end while true do local event, key = os.pullEvent("key") if key == keys.enter then break end end break end end end start() end term.clear() term.setCursorPos(1,1) end start()
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
CSS | 9 min ago | 0.23 KB
VNC SCRIPT 2/2: autoinput.vbs
VBScript | 3 hours ago | 0.23 KB
VNC SCRIPT 1/2: vncauto.bat
Batch | 3 hours ago | 0.72 KB
Metroid Mission Rescue state condition list f...
ASM (NASM) | 3 hours ago | 1.49 KB
videoscheomedia
XML | 5 hours ago | 1.00 KB
Untitled
10 hours ago | 14.91 KB
autconnectVNC.bat
Batch | 10 hours ago | 0.93 KB
Helpful Windows commands
11 hours ago | 0.75 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!