Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --===========================КАРТА=====================--
- --ПЕРЕМЕННЫЕ - ДАННЫЕ О КАРТЕ/ИГРОКЕ
- texture={}
- map_background=0x355E3B
- texture.bullets_number=20
- FUEL=1000
- map_label="Заминированное☢болото"
- map_resolution={}
- map_resolution.x=80
- map_resolution.y=25
- myPosX=2
- myPosY=2
- SpawnX=12
- SpawnY=12
- HEALTH=20
- CANSHOOT=true
- texture.mines={}
- collizions={}
- direction="right"
- lastKey=""
- DESTROYED=false
- --БИБЛИОТЕКИ
- gpu=require("component").gpu
- term=require("term")
- keyboard=require("keyboard")
- event=require("event")
- unicode=require("unicode")
- --ТЕКСТУРЫ
- texture.myTank="■"
- texture.wall="█"
- texture.duloYB="↑"
- texture.duloYM="↓"
- texture.duloXB="→"
- texture.duloXM="←"
- texture.bullet="✺"
- texture.mine_default="×"
- texture.mine_nuclear="☢"
- texture.mine_default_boomed="☼"
- --КОНЕЦ ТЕКСТУР
- --======================КОНЕЦ КАРТЫ=======================--
- --ФУНКЦИИ
- W, H = gpu.getResolution()
- function printTheTank()
- createCollizion(myPosX, myPosY, "myTank", 0xffffff, "myTANK")
- if direction=="right" then
- createCollizion(myPosX+1, myPosY, "duloXB", 0xffffff, "myDULO")
- elseif direction=="left" then
- createCollizion(myPosX-1, myPosY, "duloXM", 0xffffff, "myDULO")
- elseif direction=="up" then
- createCollizion(myPosX, myPosY-1, "duloYB", 0xffffff, "myDULO")
- elseif direction=="down" then
- createCollizion(myPosX, myPosY+1, "duloYM", 0xffffff, "myDULO")
- end
- end
- function hit_calculation_x(BULL)
- for NUM=1, #texture.mines do
- local x, y = texture.mines[NUM].x, texture.mines[NUM].y
- if x==BULL and y==myPosY then
- texture.mines[NUM]=nil
- createCollizion(x, y, "mine_default_boomed", 0xffffff)
- _G.NEWSHOOT=false
- end
- end
- for NUMCOLLIZION=1, #collizions do
- local x, y = collizions[NUMCOLLIZION].x, collizions[NUMCOLLIZION].y
- if x==BULL and y==myPosY then
- _G.NEWSHOOT=false
- end
- end
- end
- function hit_calculation_y(BULL)
- for NUM=1, #texture.mines do
- local x, y = texture.mines[NUM].x, texture.mines[NUM].y
- if x==myPosX and y==BULL then
- texture.mines[NUM]=nil
- createCollizion(x, y, "mine_default_boomed", 0xffffff)
- _G.NEWSHOOT=false
- end
- end
- for NUMCOLLIZION=1, #collizions do
- local x, y, opsisanie = collizions[NUMCOLLIZION].x, collizions[NUMCOLLIZION].y, collizions[NUMCOLLIZION].descrption
- if x==myPosX and y==BULL and opsisanie~="myDULO" then
- _G.NEWSHOOT=false
- end
- end
- end
- function shoot()
- if texture.bullets_number~=0 then
- _G.NEWSHOOT=true
- if direction=="right" then
- for BULL=myPosX+1, W do
- if _G.NEWSHOOT==true then
- printTheTank()
- printTheData()
- gpu.set(BULL, myPosY, texture.bullet)
- gpu.set(BULL-1, myPosY, " ")
- hit_calculation_x(BULL)
- os.sleep(0.0000000000000000000001)
- end
- printTheTank()
- printTheData()
- end
- elseif direction=="left" then
- for BULL=myPosX-1, 0, -1 do
- if _G.NEWSHOOT==true then
- printTheTank()
- printTheData()
- gpu.set(BULL, myPosY, texture.bullet)
- gpu.set(BULL+1, myPosY, " ")
- hit_calculation_x(BULL)
- os.sleep(0.0000000000000000000001)
- end
- printTheTank()
- printTheData()
- end
- elseif direction=="up" then
- for BULL=myPosY-1, -1, -1 do
- if _G.NEWSHOOT==true then
- printTheTank()
- printTheData()
- gpu.set(myPosX, BULL, texture.bullet)
- gpu.set(myPosX, BULL+1, " ")
- hit_calculation_y(BULL)
- os.sleep(0.0000000000000000000001)
- end
- printTheTank()
- printTheData()
- end
- elseif direction=="down" then
- for BULL=myPosY+1, H+1 do
- if _G.NEWSHOOT==true then
- printTheTank()
- printTheData()
- gpu.set(myPosX, BULL, texture.bullet)
- gpu.set(myPosX, BULL-1, " ")
- hit_calculation_y(BULL)
- os.sleep(0.0000000000000000000001)
- end
- printTheTank()
- printTheData()
- end
- end
- texture.bullets_number=texture.bullets_number-1
- printTheData()
- end
- end
- function clearTheTank()
- collizions["myTANK"]=nil
- collizions["myDULO"]=nil
- end
- function createMine(x, y, power)
- tmp={}
- tmp.x=x
- tmp.y=y
- tmp.power=power
- table.insert(texture.mines, tmp)
- gpu.set(x, y, texture.mine_default)
- end
- function checkMines()
- if type(HEALTH)=="number" then
- for i=1, #texture.mines do
- local x, y = texture.mines[i].x, texture.mines[i].y
- if x==myPosX and y==myPosY then
- HEALTH=HEALTH-texture.mines[i].power
- texture.mines[i]=nil
- createCollizion(x, y, "mine_default_boomed", 0xffffff)
- end
- end
- end
- end
- function printTheMines()
- for MINE=1, #texture.mines do
- local x, y = texture.mines[MINE].x, texture.mines[MINE].y
- gpu.set(x, y, texture.mine_default)
- end
- end
- function checkHealth()
- if type(HEALTH)=="number" then
- if HEALTH<=0 then
- DESTROYED=true
- clearTheTank()
- FUEL="ТОПЛИВО СГОРЕЛО"
- HEALTH="ТАНК УНИЧТОЖЕН"
- texture.bullets_number="БОЕУКЛАДКА УНИЧТОЖЕНА"
- printTheData()
- end
- end
- end
- function move()
- printTheData()
- if myPosX-2>-1 and myPosX+2<W+1 and myPosY-2>-1 and myPosY+2<H+1 then
- if lastKey=="w" then
- if direction=="up" and canIGoForward() and canIGoForwardD() then
- if type(FUEL)=="number" then
- if FUEL<=0 then
- return false
- else
- FUEL=FUEL-1
- end
- end
- clearTheTank()
- myPosY=myPosY-1
- printTheTank()
- else
- direction="up"
- clearTheTank()
- printTheTank()
- end
- elseif lastKey=="d" then
- if direction=="right" and canIGoForward() and canIGoForwardD() then
- if type(FUEL)=="number" then
- if FUEL<=0 then
- return false
- else
- FUEL=FUEL-1
- end
- end
- clearTheTank()
- myPosX=myPosX+1
- printTheTank()
- else
- direction="right"
- clearTheTank()
- printTheTank()
- end
- elseif lastKey=="a" then
- if direction=="left" and canIGoForward() and canIGoForwardD() then
- if type(FUEL)=="number" then
- if FUEL<=0 then
- return false
- else
- FUEL=FUEL-1
- end
- end
- clearTheTank()
- myPosX=myPosX-1
- printTheTank()
- else
- direction="left"
- clearTheTank()
- printTheTank()
- end
- elseif lastKey=="s" then
- if direction=="down" and canIGoForward() and canIGoForwardD() then
- if type(FUEL)=="number" then
- if FUEL<=0 then
- return false
- else
- FUEL=FUEL-1
- end
- end
- clearTheTank()
- myPosY=myPosY+1
- printTheTank()
- else
- direction="down"
- clearTheTank()
- printTheTank()
- end
- elseif lastKey=="space" then
- shoot()
- end
- else
- clearTheTank()
- myPosX=SpawnX
- myPosY=SpawnY
- clearTheTank()
- printTheTank()
- end
- end
- function printMapLabel()
- local map_len=unicode.len(map_label)/2
- local startx=math.floor(W/2-map_len)
- gpu.set(startx, 1, map_label)
- end
- function clearMapLabel()
- local map_len=unicode.len(map_label)/2
- local startx=math.floor(W/2-map_len)
- gpu.fill(1, 1, W, 1, " ")
- end
- function go()
- _, _, _, key = event.pull("key_down")
- lastKey=keyboard.keys[key]
- move()
- end
- function printTheData()
- gpu.set(1, H, "Жизни: "..HEALTH.." ")
- gpu.set(1, H-1, "Снаряды: "..texture.bullets_number.." ")
- gpu.set(1, H-2, "Топливо: "..FUEL.." ")
- end
- function printOtherTank(x, y, direction, color)
- createCollizion(x, y, "myTank", color)
- if direction=="right" then
- createCollizion(x+1, y, "duloXB", color)
- elseif direction=="left" then
- createCollizion(x-1, y, "duloXM", color)
- elseif direction=="up" then
- createCollizion(x, y-1, "duloYB", color)
- elseif direction=="down" then
- createCollizion(x, y+1, "duloYM", color)
- end
- gpu.setForeground(0xffffff)
- end
- function clearOtherTank(x, y)
- gpu.set(x, y, " ")
- gpu.set(x+1, y, " ")
- gpu.set(x-1, y, " ")
- gpu.set(x, y+1, " ")
- gpu.set(x, y-1, " ")
- end
- function getFacingX()
- if direction=="right" then
- return myPosX+2
- elseif direction=="left" then
- return myPosX-2
- else
- return myPosX
- end
- end
- function getFacingY()
- if direction=="up" then
- return myPosY-2
- elseif direction=="down" then
- return myPosY+2
- else
- return myPosY
- end
- end
- function getFacingXX()
- if direction=="right" then
- return myPosX+1
- elseif direction=="left" then
- return myPosX-1
- else
- return myPosX
- end
- end
- function getFacingYY()
- if direction=="up" then
- return myPosY-1
- elseif direction=="down" then
- return myPosY+1
- else
- return myPosY
- end
- end
- function canIGoForwardD(X, Y)
- for TABLENUM=1, #collizions do
- local x, y, textureCollizion, color, descrption = collizions[TABLENUM].x, collizions[TABLENUM].y, collizions[TABLENUM].textureCollizion, collizions[TABLENUM].color, collizions[TABLENUM].descrption
- if x==getFacingXX() and y==getFacingYY() and descrption~="myDULO" and descrption~="myTANK" then
- return false
- end
- end
- return true
- end
- function createCollizion(x, y, textureCollizion, color, descrption)
- local tmp={}
- tmp.x=x
- tmp.y=y
- tmp.textureCollizion=textureCollizion
- tmp.color=color
- tmp.descrption=descrption or "nil"
- if descrption~="myDULO" and descrption~="myTANK" then
- table.insert(collizions, tmp)
- elseif descrption=="myDULO" then
- collizions["myDULO"]=tmp
- elseif descrption=="myTANK" then
- collizions["myTANK"]=tmp
- end
- end
- function printCollizions()
- for TABLENUM=1, #collizions do
- local x, y, textureCollizion, color = collizions[TABLENUM].x, collizions[TABLENUM].y, collizions[TABLENUM].textureCollizion, collizions[TABLENUM].color
- gpu.setForeground(color)
- gpu.set(x, y, texture[textureCollizion])
- end
- local x, y, textureCollizion, color = collizions["myTANK"].x, collizions["myTANK"].y, collizions["myTANK"].textureCollizion, collizions["myTANK"].color
- gpu.setForeground(color)
- gpu.set(x, y, texture[textureCollizion])
- local x, y, textureCollizion, color = collizions["myDULO"].x, collizions["myDULO"].y, collizions["myDULO"].textureCollizion, collizions["myDULO"].color
- gpu.setForeground(color)
- gpu.set(x, y, texture[textureCollizion])
- gpu.setForeground(0xffffff)
- end
- function canIGoForward(X, Y)
- for TABLENUM in pairs(collizions) do
- local x, y, textureCollizion, color, descrption = collizions[TABLENUM].x, collizions[TABLENUM].y, collizions[TABLENUM].textureCollizion, collizions[TABLENUM].color, collizions[TABLENUM].descrption
- if x==getFacingX() and y==getFacingY() and descrption~="myDULO" and descrption~="myTANK" then
- return false
- end
- end
- return true
- end
- --СТАРТ ПРОГРАММЫ
- gpu.setBackground(map_background)
- local x, y = map_resolution.x, map_resolution.y
- local Wmax, Hmax = gpu.maxResolution()
- if x>Wmax and y>Hmax then
- print("Ошибка! Разрешение карты не соответствует разрешению монитора!")
- os.exit()
- else
- gpu.setResolution(x, y)
- end
- term.clear()
- printTheTank()
- printMapLabel()
- printOtherTank(50, 15, "left", 0x004DFF)
- createCollizion(15, 15, "wall", 0xff0000)
- event.timer(3, clearMapLabel)
- --УСТАНОВКА МИНЫ
- createMine(40, 14, math.random(1, 20))
- --КОНЕЦ:)
- while true do
- if DESTROYED~=true then
- term.clear()
- printTheMines()
- printCollizions()
- checkMines()
- checkHealth()
- printTheData()
- go()
- os.sleep(0.1)
- else
- gpu.set(myPosX, myPosY, "†")
- os.sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement