Перейти к содержимому
  • 0
BenniShifer919

Не рисуется

Вопрос

Помогите пожалуйста найти ошибку! Я переношу свою игру на ОС, и у меня появились определенные трудности с отрисовкой. Я рисую, но оно не рисуется


Полный код

Скрытый текст

local function draw()
        local width = panelWidth
        gpu.setBackground(colors.black)
        gpu.fill(0,0,w,h," ")
        --Map draw logic
        local offset = 2
        for y=cntY-range,cntY+range,1 do
            for x=cntX-range,cntX+range,1 do
                gpu.setForeground(colors.white)
                gpu.setBackground(colors.black)
                dx,dy = x*2+offset-(cntX-range)*2,y*2+offset-(cntY-range)*2
                if map[y][x].top == true then
                    gpu.set(dx, dy,"# ")
                else
                    gpu.set(dx, dy,"##")
                end
                dx,dy = x*2+offset-(cntX-range)*2,y*2+1+offset-(cntY-range)*2
                local s = ""
                local sC = colors.white
                if y == cntY and x == cntX then
                    s = plrS
                    sC = colors.yellow
                elseif map[y][x].dark == true then
                    s = "#"
                    sC = colors.gray
                end
                if map[y][x].dark == false  or (y == cntY and x == cntX) then
                    if map[y][x].type == "shop" then
                        s = shpS
                        sC = colors.lime
                    elseif map[y][x].type == "portal" then
                        s = prtS
                        sC = colors.cyan
                    elseif map[y][x].type == "lava" then
                        s = lavS
                        sC = colors.red
                    elseif map[y][x].type == "ushop" then
                        s = ushS
                        sC = colors.blue
                    elseif map[y][x].type == "oshop" then
                        s = oshS
                        sC = colors.yellow
                    end
                end
                if map[y][x].left == true then
                    gpu.set(dx,dy," ")
                    gpu.setForeground(sC)
                    gpu.set(dx+1,dy,s)
                else
                    gpu.set(dx,dy,"#")
                    gpu.setForeground(sC)
                    gpu.set(dx+1,dy,s)
                end
            end
        end
        -- Coins, Food, Water level
        --FOOD
        gpu.setBackground(colors.brown)
        gpu.fill(0,h,w,1," ")
        gpu.set(1,h,"Food level: "..tostring(food))
        gpu.setForeground(colors.white)
        --Water
        gpu.setBackground(colors.cyan)
        gpu.fill(0,h-1,w,1," ")
        gpu.set(1,h-1,"Water level: "..tostring(water*10))
        gpu.setForeground(colors.white)
        --Coins
        gpu.setBackground(colors.orange)
        gpu.fill(0,h-2,w,1," ")
        gpu.set(1,h-2,"Coins: "..tostring(coins))
        gpu.setForeground(colors.white)
        --Shop menu display
        gpu.setBackground(colors.black)
        gpu.setForeground(colors.white)
        if map[cntY][cntX].type == "shop" then
            dx,dy = w-width,1
            gpu.setForeground(colors.lime)
            gpu.set(dx,dy,"Shop menu")
            for i=1,#shop_items,1 do
                gpu.setForeground(colors.white)
                dx,dy = w-width,i*2
                gpu.set(dx,dy,shop_items[i].name)
                if coins < shop_items[i].price then
                    gpu.setForeground(colors.red)
                end
                dx,dy = w-width,i*2+1
                gpu.set(dx,dy,tostring(shop_items[i].price))
            end
        end
        if map[cntY][cntX].type == "ushop" then
            dx,dy = w-width,1
            gpu.setForeground(colors.blue)
            gpu.set(dx,dy,"Upgrades")
            for i=1,#upgrades,1 do
                gpu.setForeground(colors.white)
                dx,dy = w-width,i*2
                gpu.set(dx,dy,upgrades[i].name..":"..tostring(upgrades[i].level))
                if coins < upgrades[i].price then
                    gpu.setForeground(colors.red)
                end
                dx,dy = w-width,i*2+1
                if upgrades[i].level >= upgrades[i].max_level then
                    gpu.setForeground(colors.yellow)
                    gpu.set(dx,dy,"Max LVL") 
                else
                    gpu.set(dx,dy,tostring(upgrades[i].price))
                end
            end
        end
        if map[cntY][cntX].type == "oshop" then
            dx,dy = w-width,1
            gpu.setForeground(colors.yellow)
            gpu.set(dx,dy,"Upgrades")
            for i=1,#once_upgrades,1 do
                gpu.setForeground(colors.white)
                dx,dy = w-width,i*2
                gpu.set(dx,dy,once_upgrades[i].name)
                if coins < once_upgrades[i].price then
                    gpu.setForeground(colors.red)
                end
                dx,dy = w-width,i*2+1
                if once_upgrades[i].has then
                    gpu.setForeground(colors.yellow)
                    gpu.set(dx,dy,"Already")
                else
                    gpu.set(dx,dy,tosting(once_upgrades[i].price))
                end
            end
        end
        if map[cntY][cntX].type == "portal" then
            dx,dy = w-width,2
            gpu.setForeground(colors.cyan)
            gpu.set(dx,dy,"Portal")
            dx,dy = w-width,4
            gpu.set(dx,dy,"TELEPORT")
        end
        --Inventory menu display
        gpu.setBackground(colors.black)
        gpu.setForeground(colors.white)
        dx,dy = w-width,8
        gpu.setForeground(colors.brown)
        gpu.set(w-width,8,"Backpack")
        dx,dy = w-width,9
        gpu.setForeground(colors.orange)
        gpu.set(dx,dy,"Food")
        dx,dy = w-width,10
        gpu.set(dx,dy,tostring(inventory.food).."x")
        dx,dy = w-width,11
        gpu.setForeground(colors.blue)
        gpu.set(dx,dy,"Water")
        dx,dy = w-width,12
        gpu.set(dx,dy,tostring(inventory.water).."x")
        dx,dy = w-width,13
        gpu.setForeground(colors.brown)
        gpu.set(dx,dy,"Alcohol")
        dx,dy = w-width,14
        gpu.set(dx,dy,tostring(inventory.poison).."x")
        --Room inventory display
        gpu.setBackground(colors.black)
        gpu.setForeground(colors.white)
        if #map[cntY][cntX].inventory > 0 then
            dx,dy = w-width,15
            gpu.setForeground(colors.gray)
            gpu.set(dx,dy,"Room")
            for i = 1,#map[cntY][cntX].inventory,1 do
                gpu.setForeground(colors.white)
                dx,dy = w-width,15+i
                gpu.set(dx,dy,map[cntY][cntX].inventory[i])
            end
        end
    end

 

Я абсолютно непонимаю что не так, никаких ошибок не выдает, клавиши и т.п. обрабатывает правильно, но почему-то только не рисует, черный экран и всё
2023-11-06-123449.png2023-11-06-123513.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Рекомендуемые сообщения

colors для указывания цветов видеокарты не подходит (ну, если не юзать палитру). Там true color нужен, 24-битный:

gpu.setForeground(0xffffff) -- белый: 0xff красного, 0xff зелёного, 0xff синего
gpu.setBackground(0x000000) -- чёрный

А так он пытается поставить цвет 0x00000f (colors.white — это вроде число 15). Градаций синих в цветах T3-видеокарты — 6: 0, 51, 102, 153, 204, 255. OpenComputers ищет ближайший цвет к 0x00000f из имеющихся и получает чистый чёрный (15 ближе к 0, чем к 51). И итого рисуется чёрным по чёрному.

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах
1 минуту назад, Fingercomp сказал:

colors для указывания цветов видеокарты не подходит (ну, если не юзать палитру). Там true color нужен, 24-битный:


gpu.setForeground(0xffffff) -- белый: 0xff красного, 0xff зелёного, 0xff синего
gpu.setBackground(0x000000) -- чёрный

А так он пытается поставить цвет 0x00000f (colors.white — это вроде число 15). Градаций синих в цветах T3-видеокарты — 6: 0, 51, 102, 153, 204, 255. OpenComputers ищет ближайший цвет к 0x00000f из имеющихся и получает чистый чёрный (15 ближе к 0, чем к 51). И итого рисуется чёрным по чёрному.

Мгм, а ведь я посути могу просто подменить эту таблицу своей верно? Но уже с правильными значениями?

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Прямо библиотеку colors я бы менять не советовал, но можно завести свою:

local colors = {
  white = 0xffffff,
  black = 0x000000,
  cyan = 0x66dbff,
  -- ...
}

 

P. S. В прошлом сообщении ошибся: градаций синего там пять, а не шесть.

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах
1 час назад, Fingercomp сказал:

Прямо библиотеку colors я бы менять не советовал, но можно завести свою:


local colors = {
  white = 0xffffff,
  black = 0x000000,
  cyan = 0x66dbff,
  -- ...
}

 

Я так и сделал, и это имел ввиду

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить на вопрос...

×   Вы вставили отформатированное содержимое.   Удалить форматирование

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отобразить как ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.


×
×
  • Создать...