A while back, I made a discussion showing off a proof of concept I had in which anybody could manipulate screen data from code without the use of images (like a C64). Now, I have completed this project. This is in NO WAY the final version I shall be working on. Anyways, without further ado, the code.
--# Main
function setup()
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_LEFT)
rectMode(CORNER)
FPS=0 -- -\\ Used for
framcnt=0 -- > Calculating
lastscnd=0 -- _/ FPS
pxSizeW=57 --Width of pixels
pxSizeH=43--Height of pixels
s = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
}
parameter.watch("FPS")
end
function draw()
noStroke()
noSmooth() --Smoothing tended to make a stroke-like effect
code()
for y=1,16 do
for x=1,16 do
fill(s[x][y])
rect(x*pxSizeW,y*pxSizeH,pxSizeW,pxSizeH)
end
end
--Code down here calculates FPS
framcnt = framcnt + 1
if (ElapsedTime > lastscnd + 1) then
lastscnd = lastscnd + 1
FPS=framcnt
framcnt = 0
end
end
function code() --Put your game code here
d = {
{255,255,0,0},
{255,0,255,0},
{255,0,0,255},
{255,0,0,255},
{255,0,255,0},
{255,255,0,0}
}
e = {
{255,255,255,0},
{255,0,0,0},
{255,0,0,0},
{255,255,0,0},
{255,0,0,0},
{255,255,255,0}
}
m = {
{255,255,255,255},
{255,255,0,255},
{255,0,0,255},
{255,0,0,255},
{255,0,0,255},
{255,0,0,255}
}
o = {
{255,255,255,255},
{255,0,0,255},
{255,0,0,255},
{255,0,0,255},
{255,0,0,255},
{255,255,255,255}
}
smile = {
{0,255,0,255,0},
{0,0,0,0,0},
{255,0,0,0,255},
{0,255,255,255,0}
}
Graphics:sFill(120)
Graphics:sprite(d, vec2(0,0))
Graphics:sprite(e, vec2(12,0))
Graphics:sprite(m, vec2(0,10))
Graphics:sprite(o, vec2(12,10))
Graphics:sprite(smile, vec2(math.floor(math.sin(ElapsedTime)*6+6),6))
end
--# Graphics
Graphics = class()
function Graphics:sFill(c)
for y = 1, 16 do
for x = 1, 16 do
s[y][x] = c
end
end
end
function Graphics:sprite(d,p)
y=1
x=1
for y = 1, #d do
for x = 1, #d[y] do
if (y+p.y <= 16 and x+p.x <= 16) then
s[y+p.y][x+p.x] = d[y][x]
end
end
end
end
function Graphics:hLine(y,l,sx,c)
for i = sx,sx+l do
s[y][i] = c
end
end
function Graphics:vLine(x,l,sy,c)
for i = sy,sy+l do
s[i][x] = c
end
end
--# README
--[[
To use this "game engine", put your code in 'function code()'
The engine uses portrait mode.
The Graphics class has many useful functions:
sFill- fills the screen
c: the color to fill the screen with
sprite- generates a sprite
d: a 2-dimensional array containing the pixel data of the sprite
p: a vec2 value of where the bottom left hand corner of the sprite will be placed
hLine- displays a horizontal line
y: the y-coordinate of the line
l: the length of the line
sx: the starting x-coordinate of the line (left to right)
c: the color of the line
vLine- displays a vertical line
x: the x-coordinate of the line
l: the length of the line
sy: the starting y-coordinate of the line (top to bottom)
c: the color of the line
]]