Back to Codea! The title says it all, the 2D Minecraft Project I’m doing is going to require WAAY more drawing than the simple thing I have so far, so I need to find a way to draw things faster so that the framerate is not affected. Here’s the code:
-- 2D Minecraft
-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
version = 0.1
saveProjectInfo("Author","Enro Corp")
saveProjectInfo("Description", "My quest to create a fun 2D Minecraft begins...")
saveProjectData("Version",version)
worldCreate:init()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(0)
-- This sets the line thickness
strokeWidth(5);rectMode(CENTER);
noStroke();fill(255)
font("ArialMT");fontSize(10)
text("Version "..readProjectData("Version"),WIDTH/2,HEIGHT - 50)
-- Do your drawing here
worldCreate:draw()
for r,row in ipairs(level) do
for c,cell in ipairs(row) do
if r == 10 then
local grass,img
grass = mesh()
img = readImage("Documents:blockGrass")
grass.texture = img
grass:addRect(-16 + c*32,-16 + r*32,32,32)
grass:draw()
else
local dirt,img
dirt = mesh()
img = readImage("Documents:blockDirt")
dirt.texture = img
dirt:addRect(-16 + c*32,-16 + r*32,32,32)
dirt:draw()
end
end
end
end
WORLD CREATE CLASS
worldCreate = class()
function worldCreate:init()
-- you can accept and set parameters here
height = 102
width = 10
level = {}
index = {}
for i = 1,width do
level[i] = {}
for j = 1,height do
level[i][j] = math.random(6)
end
end
for i = 1,width do
index[i] = {}
for j = 1,height do
index[i][j] = math.random(6)
end
end
end
function worldCreate:draw()
-- Codea does not automatically call this method
for r,row in ipairs(index) do
for c,cell in ipairs(row) do
text(r.."/"..c, WIDTH - width*40 + c*35,HEIGHT - height*40 + r*35)
end
end
end