Last active
December 19, 2015 23:19
-
-
Save aalok74/6033866 to your computer and use it in GitHub Desktop.
2nd Rain Effect done by drawing random lines. Also added a splash animated tileset but could use some tweaks to the display and speed of the animation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- GenerateMap | |
-- generates the current map if it has not already been generated | |
function generateMap(map, tilesheet, tileWidth, tileHeight, animation) | |
local mm = {} -- table to store our meshes | |
local maxy,maxx = #map,#map[1] -- size of 2D map | |
for y,_ in ipairs(map) do | |
for x,t in ipairs(map[y]) do | |
local sheet = tilesheet[t] | |
if t ~= 0 then | |
if mm[t] == nil then -- add new mesh if we don't have this tile image yet | |
mm[t] = mesh() | |
mm[t].texture = tilesets[sheet.set].sheet | |
end | |
local ul,u,ur,r,dr,d,dl,l -- designates the 8 surrounding tiles: u = upper, d = down, r = right, l = left | |
if y == 1 then ul,u,ur=0,0,0 end -- the following make sure the map table is not read out of bounds | |
if y == maxy then dl,d,dr=0,0,0 end | |
if x == 1 then ul,l,dl=0,0,0 end | |
if x == maxx then ur,r,dr=0,0,0 end | |
if ul ~= 0 then ul=map[y-1][x-1] end -- if map will not be read out of bounds, use map to figure out surrounding tiles | |
if u ~= 0 then u=map[y-1][x] end | |
if ur ~= 0 then ur=map[y-1][x+1] end | |
if r ~= 0 then r=map[y][x+1] end | |
if dr ~= 0 then dr=map[y+1][x+1] end | |
if d ~= 0 then d=map[y+1][x] end | |
if dl ~= 0 then dl=map[y+1][x-1] end | |
if l ~= 0 then l=map[y][x-1] end | |
local w,h = (1/tilesets[sheet.set].x),1/tilesets[sheet.set].y | |
local tx,ty | |
if animation ~= nil then | |
tx,ty = (sheet.x+animation)*w,sheet.y*h | |
else | |
tx,ty = sheet.x*w,sheet.y*h | |
end | |
local type | |
if sheet.type == 1 then | |
w = w / 4 | |
h = h / 6 | |
type = "floor" | |
elseif sheet.type == 2 then | |
if tilesets[sheet.set].sheet.height%10 == 0 then | |
w = w / 4 | |
h = h / 10 | |
type = "wall" | |
else | |
w = w / 4 | |
h = h / 8 | |
type = "roof" | |
end | |
elseif sheet.type == 3 then | |
end | |
if sheet.type == 1 then -- algorithm used for auto tiling the floor tiles | |
local tul,tur,tdl,tdr -- tile pieces: tul=upper left, tur=upper right, tdl=bottom left, tdr=bottom right | |
if u ~= t and l ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*0),ty+(h*3),w,h) | |
elseif u ~= t and l == t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*3),w,h) | |
elseif u == t and l ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*0),ty+(h*1),w,h) | |
elseif u == t and l == t and ul ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*5),w,h) | |
else | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*1),w,h) | |
end | |
if u ~= t and r ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*3),w,h) | |
elseif u ~= t and r == t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*1),ty+(h*3),w,h) | |
elseif u == t and r ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*1),w,h) | |
elseif u == t and r == t and ur ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*5),w,h) | |
else | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*1),ty+(h*1),w,h) | |
end | |
if d ~= t and l ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*0),w,h) | |
elseif d ~= t and l == t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*0),w,h) | |
elseif d == t and l ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*2),w,h) | |
elseif d == t and l == t and dl ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*4),w,h) | |
else | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*2),w,h) | |
end | |
if d ~= t and r ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*0),w,h) | |
elseif d ~= t and r == t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*1),ty+(h*0),w,h) | |
elseif d == t and r ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*2),w,h) | |
elseif d == t and r == t and dr ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*4),w,h) | |
else | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-1)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*1),ty+(h*2),w,h) | |
end | |
elseif sheet.type == 2 then -- algorithm used for auto tiling roof/wall tiles | |
local tul,tur,tdl,tdr -- tile pieces: tul=upper left, tur=upper right, tdl=bottom left, tdr=bottom right | |
if u ~= t and l ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*0),ty+(h*7),w,h) | |
elseif u ~= t and l == t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*7),w,h) | |
elseif u == t and l ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*0),ty+(h*5),w,h) | |
elseif u == t and l == t and ul ~= t then | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*9),w,h) | |
else | |
tul = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tul,tx+(w*2),ty+(h*5),w,h) | |
end | |
if u ~= t and r ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*7),w,h) | |
elseif u ~= t and r == t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*1),ty+(h*7),w,h) | |
elseif u == t and r ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*5),w,h) | |
elseif u == t and r == t and ur ~= t then | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*3),ty+(h*9),w,h) | |
else | |
tur = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight)+tileHeight/2,tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tur,tx+(w*1),ty+(h*5),w,h) | |
end | |
if d ~= t and l ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*4),w,h) | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-2)*tileHeight)-tileHeight/4,tileWidth/2,tileHeight*2) | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*0),w,h*4) | |
elseif d ~= t and l == t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*4),w,h) | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-2)*tileHeight)-tileHeight/4,tileWidth/2,tileHeight*2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*0),w,h*4) | |
elseif d == t and l ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*6),w,h) | |
elseif d == t and l == t and dl ~= t then | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
if type == "roof" then | |
mm[t]:setRectTex(tdl,tx+(w*0),ty+(h*6),w,h) | |
else | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*8),w,h) | |
end | |
else | |
tdl = mm[t]:addRect(((x-1)*tileWidth),-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdl,tx+(w*2),ty+(h*6),w,h) | |
end | |
if d ~= t and r ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*4),w,h) | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-2)*tileHeight)-tileHeight/4,tileWidth/2,tileHeight*2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*0),w,h*4) | |
elseif d ~= t and r == t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*1),ty+(h*4),w,h) | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-2)*tileHeight)-tileHeight/4,tileWidth/2,tileHeight*2) | |
mm[t]:setRectTex(tdr,tx+(w*1),ty+(h*0),w,h*4) | |
elseif d == t and r ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*6),w,h) | |
elseif d == t and r == t and dr ~= t then | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
if type == "roof" then | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*6),w,h) | |
else | |
mm[t]:setRectTex(tdr,tx+(w*3),ty+(h*8),w,h) | |
end | |
else | |
tdr = mm[t]:addRect(((x-1)*tileWidth)+tileWidth/2,-((y-3)*tileHeight),tileWidth/2,tileHeight/2) | |
mm[t]:setRectTex(tdr,tx+(w*1),ty+(h*6),w,h) | |
end | |
elseif sheet.type == 3 then | |
elseif sheet.type == 4 then -- no algorithm used, simply place the object at designated location | |
local obj | |
local width = tilesets[sheet.set].sheet.width/tilesets[sheet.set].x | |
local height = tilesets[sheet.set].sheet.height/tilesets[sheet.set].y | |
if width%tileWidth ~= 0 then -- resize the object to fit the current map | |
local s = math.max(math.floor(width/tileWidth),1) | |
width,height = (tileWidth/width)*width*s,(tileWidth/width)*height*s | |
elseif height%tileHeight ~= 0 and width < tileWidth then | |
local s = math.max(math.floor(height/tileHeight),1) | |
width,height = (tileHeight/height)*width*s,(tileHeight/height)*height*s | |
end | |
obj = mm[t]:addRect(((x-1)*tileWidth)+(width/4),-((y-1)*tileHeight)+((height*3)/8),width,height) | |
mm[t]:setRectTex(obj,tx,ty,w,h) | |
end | |
end | |
end | |
end | |
return mm | |
end | |
function drawMap() | |
if aStep < ElapsedTime then | |
aStep = ElapsedTime + 1 | |
if ca == 3 and aDirection > 0 then | |
aDirection = -aDirection | |
elseif ca == 1 and aDirection < 0 then | |
aDirection = -aDirection | |
end | |
ca = ca + aDirection | |
end | |
animateMove(player) | |
local tw,th = maps[currentMap].tileWidth,maps[currentMap].tileHeight -- tile width and height of current map | |
local pimg = getCharasetImage(player,tw,th,0,0) -- player image pulled from mesh | |
local npcimgs = {} | |
local offx,offy = (WIDTH/tw)/2+1,(HEIGHT/th)/2+1 | |
pushMatrix() | |
-- move floor map to match player location | |
translate(-(tw/4)-(player.position.x-offx)*tw+player.moveX, (768-(th/4))+(player.position.y-offy)*th+player.moveY) | |
for i,v in pairs(gFloor[currentMap]) do | |
v:draw() | |
end | |
for i,v in pairs(gAnimated[ca][currentMap]) do | |
v:draw() | |
end | |
for i,v in pairs(npcs) do | |
if v.map == currentMap then | |
if v.speed ~= 0 then | |
animateMove(v) | |
if v.moveX == 0 and v.moveY == 0 then | |
if math.random(v.rate*100) == 1 and not showDialogue then | |
if dialogueNPC == i then | |
dialogueNPC = nil | |
end | |
local dir = math.random(4) | |
if dir == 1 then | |
move(v,"right") | |
elseif dir == 2 then | |
move(v,"left") | |
elseif dir == 3 then | |
move(v,"up") | |
elseif dir == 4 then | |
move(v,"down") | |
end | |
end | |
end | |
end | |
local npcimg = getCharasetImage(v,tw,th,v.moveX,v.moveY) | |
npcimg:draw() | |
npcimgs[i] = npcimg | |
end | |
end | |
popMatrix() | |
pimg:draw() -- draw player | |
pushMatrix() | |
-- move object map to match player location | |
translate(-(tw/4)-(player.position.x-offx)*tw+player.moveX, (768-(th/4))+(player.position.y-offy)*th+player.moveY) | |
for i,v in pairs(gObjects[currentMap]) do | |
v:draw() | |
end | |
for i,v in pairs(gDecor[currentMap]) do | |
v:draw() | |
end | |
-- test whether or not the npc should be drawn on top of an object | |
for i,v in pairs(npcs) do | |
if v.map == currentMap then | |
testBelow(v) | |
if not v.behind then | |
npcimgs[i]:draw() | |
end | |
npcimgs[i]:clear() | |
end | |
end | |
popMatrix() | |
testBelow(player) | |
if not player.behind then | |
pimg:draw() | |
end | |
pimg:clear() | |
Rain.spawnRate = BackgroundSpawnRate | |
Rain:update() | |
Rain:draw() | |
JoypadDraw() -- draw joypad | |
if player.moveX == 0 and player.moveY == 0 then | |
local e = maps[currentMap].events[player.position.y][player.position.x] -- check if an event at the current player location exists | |
if e > 0 then | |
local event = events[e] | |
if event.type == "teleport" then -- execute teleport event | |
teleport(event.map,event.x,event.y) | |
elseif event.type == "popup" or event.type == "entrance" then -- display text for popup and entrance events | |
popup(event.text) | |
end | |
end | |
end | |
if dialogueNPC ~= nil and showDialogue then | |
dialogue(dialogueNPC) | |
end | |
if joypadOP.status and not showDialogue then | |
currentPage = 0 | |
if player.moveX == 0 and player.moveY == 0 then | |
if math.abs(joypadOP.x) > math.abs(joypadOP.y) then | |
if joypadOP.x > 0 then | |
dialogueNPC = move(player,"right") | |
else | |
dialogueNPC = move(player,"left") | |
end | |
else | |
if joypadOP.y > 0 then | |
dialogueNPC = move(player,"up") | |
else | |
dialogueNPC = move(player,"down") | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Images | |
-- downloads and/or initializes the images necessary for the project to run | |
-- sheet: determines the tileset/charaset to use | |
-- x: number of sheets/sprites per row | |
-- y: number of rows | |
-- m: character sprite move order | |
function loadSheets() | |
local tilesets = { | |
{ sheet = readImage("Dropbox:Tilesheet-001"), x = 8, y = 4 }, -- 1 | |
{ sheet = readImage("Dropbox:Tilesheet-002"), x = 8, y = 3 }, -- 2 | |
{ sheet = readImage("Dropbox:Tilesheet-003"), x = 8, y = 2 }, | |
{ sheet = readImage("Dropbox:Tilesheet-004"), x = 8, y = 4 }, | |
{ sheet = readImage("Dropbox:Tilesheet-005"), x = 8, y = 16 }, | |
{ sheet = readImage("Dropbox:Tilesheet-006"), x = 16, y = 16 }, | |
{ sheet = readImage("Dropbox:Tilesheet-007"), x = 16, y = 16 }, | |
{ sheet = readImage("Dropbox:Tilesheet-008"), x = 16, y = 16 }, | |
{ sheet = readImage("Dropbox:Tilesheet-009"), x = 16, y = 16 }, | |
{ sheet = readImage("Dropbox:rain_drop"), x = 5, y = 1 }, | |
} | |
local charasets = { | |
{ sheet = readImage("Dropbox:Character-001"), x = 4, y = 4, m = {0,1,2,3} }, -- player | |
{ sheet = readImage("Dropbox:Character-002"), x = 4, y = 4, m = {0,1,2,3} }, -- male dwarf | |
{ sheet = readImage("Dropbox:Character-003"), x = 4, y = 4, m = {0,1,2,3} }, -- male guard | |
{ sheet = readImage("Dropbox:Character-004"), x = 4, y = 4, m = {0,1,2,3} }, -- frog from Chrono Trigger | |
{ sheet = readImage("Dropbox:Character-005"), x = 3, y = 4, m = {1,2,1,0} } -- blonde female | |
} | |
local facesets = { | |
{ sheet = readImage("Dropbox:Facesets-001"), x = 4, y = 2 }, | |
{ sheet = readImage("Dropbox:Facesets-002"), x = 4, y = 2 }, | |
{ sheet = readImage("Dropbox:Facesets-003"), x = 4, y = 2 } | |
} | |
return tilesets, charasets, facesets | |
end | |
function loadImages() | |
imageStatus = "Ready" | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-001", "https://dl.dropboxusercontent.com/s/wly1w95sb8dan3n/Tilesheet-001.png", 1) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-002", "https://dl.dropboxusercontent.com/s/6m5u6ddkge8aph9/Tilesheet-002.png", 2) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-003", "https://dl.dropboxusercontent.com/s/ory16n5tbdw6m2h/Tilesheet-003.png", 3) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Character-001", "https://dl.dropboxusercontent.com/s/5jcfknfrwj7gbpl/Character-001.png", 4) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Character-002", "https://dl.dropboxusercontent.com/s/lrytxiuqklhqknw/Character-002.png", 5) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Character-003", "https://dl.dropboxusercontent.com/s/7zaq49bawr4vy89/Character-003.png", 6) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Character-004", "https://dl.dropboxusercontent.com/s/g8m4h7wzdsr9aqn/Character-004.png", 7) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Facesets-001", "https://dl.dropboxusercontent.com/s/2osjogd0ixs91qv/Facesets-001.png", 8) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Facesets-002", "https://dl.dropboxusercontent.com/s/oh902oev1o3xp4v/Facesets-002.png", 9) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Facesets-003", "https://dl.dropboxusercontent.com/s/zs5tu4gw58wygph/Facesets-003.png", 10) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-004", "https://dl.dropboxusercontent.com/s/te3hr49tka856gp/Tilesheet-004.png", 11) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-005", "https://dl.dropboxusercontent.com/s/cqwxtz144inuwav/Tilesheet-005.png", 12) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-006", "https://dl.dropboxusercontent.com/s/zw9m83jli9imusy/Tilesheet-006.png", 13) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-007", "https://dl.dropboxusercontent.com/s/jl0kp0qy0mnljco/Tilesheet-007.png", 14) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-008", "https://dl.dropboxusercontent.com/s/xy2qi07int9a1b0/Tilesheet-008.png", 15) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Tilesheet-009", "https://dl.dropboxusercontent.com/s/1uas4l8zoicu3en/Tilesheet-009.png", 16) | |
end | |
if imageStatus == "Ready" then | |
loadImage("Dropbox:Character-005", "https://dl.dropboxusercontent.com/s/jsra04rcnjv0erx/Character-005.png", 17) | |
end | |
if imageStatus == "Ready" and imageTable == nil then setup2() end | |
end | |
function loadImage(fileName, url, index) | |
local i = readImage(fileName) | |
if i ~= nil or imageState[index] then | |
return | |
else | |
imageTable = { name = fileName, url = url } | |
imageStatus = "Loading" | |
http.request(imageTable.url, imageDownloaded) | |
end | |
end | |
function imageDownloaded(img, status) | |
saveImage(imageTable.name, img) | |
if status == 200 then | |
imageCount = imageCount + 1 | |
imageState[imageCount] = true | |
end | |
imageTable = nil | |
loadImages() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Main | |
-- RPG | |
VERSION = "0.3.15" | |
PROJECTNAME = "RPG" | |
BUILD = false | |
-- Slashin8r | |
-- Thank You for all your help and contributions: Ignatz and Briarfox | |
supportedOrientations(LANDSCAPE_ANY) | |
displayMode(FULLSCREEN) | |
noSmooth() | |
function setup3() | |
VersionUpdateChecker.check() | |
end | |
function setup() | |
autoUpdate = false | |
if autoUpdate then | |
setup3() | |
end | |
imageState = {} | |
imageCount = 0 | |
loadImages() | |
end | |
function setup2() | |
-- load all of our tables | |
tilesets, charasets, facesets = loadSheets() | |
characters = loadCharacters() | |
npcs = loadNPCs() | |
maps = loadMaps() | |
tiles = loadTiles() | |
aTiles = loadAnimatedTiles() | |
objects = loadObjects() | |
decor = loadDecor() | |
events = loadEvents() | |
Rain = RainAnimations() | |
-- tables to store generated maps and characters | |
gFloor = {} | |
gAnimated = {{},{},{}} | |
gObjects = {} | |
gDecor = {} | |
gCharacters = {} | |
gFaces = {} | |
for i=1,#characters do | |
gCharacters[i] = {} | |
end | |
ca = 1 -- current animation | |
aDirection = 1 | |
aStep = 0 -- next animation step | |
-- player character | |
player = { | |
id = 1, | |
name = "", | |
character = 5, | |
imgX = 1, | |
imgY = 1, | |
moveX = 0, | |
moveY = 0, | |
speed = 2, | |
position = vec2(10,10), | |
behind = false | |
} | |
-- dialogue variables | |
showDialogue = false | |
dialogueChoice = nil | |
dialogueNPC = nil | |
currentPage = 0 | |
-- menu variables | |
currentMenu = 0 | |
--textBox1000 = TextBox('Text Box', 380, 520, 570, 570) | |
--button1001 = TextButton('Button', 380, 440, 570, 480, printText) | |
-- initialize fps | |
fps = 0 | |
-- joypad variables | |
GlobalTouches = {} | |
joypadOP = {} | |
joypad = { | |
x = 120, | |
y = 120, | |
radius = 80, | |
stickRadius = 40 | |
} | |
-- generate our starting map | |
currentMap = 1 | |
table.insert(gFloor, currentMap, generateMap(maps[currentMap].floor, tiles, maps[currentMap].tileWidth, maps[currentMap].tileHeight, nil)) | |
table.insert(gAnimated[1], currentMap, generateMap(maps[currentMap].animated, aTiles, maps[currentMap].tileWidth, maps[currentMap].tileHeight, 0)) | |
table.insert(gAnimated[2], currentMap, generateMap(maps[currentMap].animated, aTiles, maps[currentMap].tileWidth, maps[currentMap].tileHeight, 1)) | |
table.insert(gAnimated[3], currentMap, generateMap(maps[currentMap].animated, aTiles, maps[currentMap].tileWidth, maps[currentMap].tileHeight, 2)) | |
table.insert(gObjects, currentMap, generateMap(maps[currentMap].objects, objects, maps[currentMap].tileWidth, maps[currentMap].tileHeight, nil)) | |
table.insert(gDecor, currentMap, generateMap(maps[currentMap].decor, decor, maps[currentMap].tileWidth, maps[currentMap].tileHeight, nil)) | |
end | |
--function printText() | |
--print(textBox1000.text) | |
--currentMenu = 0 | |
--end | |
function touched(touch) | |
--button1001:touched(touch) | |
--textBox1000:touched(touch) | |
if touch.state == ENDED then | |
player.imgX = 0 | |
if not joypadOP.status then -- tap on screen other than use of joypad | |
if showDialogue and dialogueNPC ~= nil then | |
currentPage = currentPage + 1 | |
return | |
end | |
if dialogueNPC ~= nil and not showDialogue then | |
dialogue(dialogueNPC) | |
end | |
local e = maps[currentMap].events[player.position.y][player.position.x] | |
if e > 0 then | |
local event = events[e] | |
if event.type == "entrance" and not showDialogue then -- execute entrance event if it exists on map at current location | |
teleport(event.map,event.x,event.y) | |
end | |
end | |
end | |
GlobalTouches[touch.id] = nil | |
joypadOP.status = false | |
else | |
GlobalTouches[touch.id] = touch | |
end | |
end | |
--function keyboard(key) | |
--if CCActiveTextBox then | |
--CCActiveTextBox:acceptKey(key) | |
--end | |
--end | |
function orientationChanged(newOrientation) | |
end | |
function draw() | |
if imageStatus ~= "Ready" and imageTable ~= nil then return end -- this line must be at the top of draw() | |
background(0) | |
if currentMenu ~= 0 then | |
--textBox1000:draw() | |
--button1001:draw() | |
else | |
drawMap() | |
end | |
showFPS() | |
end | |
function JoypadDraw() | |
fill(255, 255, 255, 50) | |
ellipseMode(RADIUS) | |
ellipse(joypad.x, joypad.y, joypad.radius) | |
for _,touch in pairs(GlobalTouches) do | |
fill(0, 0, 0, 100) | |
local dx, dy, r = (touch.x-joypad.x), (touch.y-joypad.y), joypad.radius | |
if ((dx * dx) + (dy * dy)) < (r * r) then | |
ellipse(touch.x, touch.y, joypad.stickRadius) | |
joypadOP.status = true | |
joypadOP.x = dx | |
joypadOP.y = dy | |
end | |
end | |
end | |
function showFPS() | |
if math.floor(ElapsedTime*10)%5 == 0 then | |
fps = math.floor(1/DeltaTime) | |
end | |
pushStyle() | |
fill(255, 0, 0, 255) | |
rect(WIDTH - 100, HEIGHT-20, 100,20) | |
fill(255, 255, 255, 255) | |
text("FPS: "..fps, WIDTH - 50, HEIGHT - 10) | |
popStyle() | |
end | |
parameter.integer("BackgroundSpawnRate",0,3,2) | |
----------------------------- | |
--Update Checker Code added by AutoGist | |
----------------------------- | |
VersionUpdateChecker = {} | |
VersionUpdateChecker.gistURL = "https://api.github.com/gists/5992265" | |
VersionUpdateChecker.check = function() | |
local jsonURL = "https://dl.dropboxusercontent.com/s/9e4nvqeu4hsux2q/Json.lua?token_hash=AAFyMB98j4bnt_1gawf9wSke52hsoC7hsIvARcTuZNeOEw&dl=1" | |
local jsonSuccess = function(data) | |
local jsonCode = data | |
if jsonCode then local l = loadstring(jsonCode) l() end | |
local handleSuccess = function(data) | |
local gist = json.decode(data) | |
local version = string.match(gist.description,"%d+%.%d+%.%d+") | |
if VERSION ~= version then | |
displayMode(STANDARD) | |
print("Click Update_Project.") | |
alert("New Update Availiable! Click Update.","Update") | |
parameter.action("Update_Project",function() VersionUpdateChecker.GetProject() end) | |
end | |
end | |
http.request(VersionUpdateChecker.gistURL,handleSuccess,function() print("Update Failed") end) | |
end | |
http.request(jsonURL,jsonSuccess,function() print("Check Internet Connection") end) | |
end | |
function VersionUpdateChecker.GetProject() | |
local handleSuccess = function(data,i,j) | |
if listProjectTabs(PROJECTNAME) == nil then | |
error("Check Project Name") | |
end | |
local gist = json.decode(data) | |
local projName = PROJECTNAME | |
if gist.files["1aTabOrder"] then | |
print("***Tab Order Found***") | |
local taborder = gist.files["1aTabOrder"].content | |
local strStart =1 | |
local strEnd =0 | |
strStart = string.find(taborder,"#",strEnd) | |
strEnd = string.find(taborder,"\n",strStart) | |
while strStart do | |
local tmp = string.sub(taborder,strStart+1,strEnd-1) | |
local name = PROJECTNAME..":"..tmp | |
tmp = tmp..".lua" | |
saveProjectTab(name,gist.files[tmp].content) | |
strStart = string.find(taborder,"#",strEnd) | |
strEnd = string.find(taborder,"\n",strStart) | |
end | |
else | |
for k,v in pairs(gist.files) do | |
local name = PROJECTNAME .. ":" .. string.gsub(k,".lua","") | |
saveProjectTab(name, v.content) | |
end | |
end | |
if gist.files["ChangeLog.lua"] then | |
local str = gist.files["ChangeLog.lua"].content | |
alert(str,"Version Notes") | |
end | |
sound(SOUND_PICKUP, 24058) | |
print("Reload Project to finish update!") | |
end | |
http.request(VersionUpdateChecker.gistURL,handleSuccess,function(data) print("Update Failed") end) | |
end | |
--End of Update Checker | |
-------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------------------- | |
-- Single line | |
---------------------------------------------- | |
RainAnimation = class() | |
function RainAnimation:init(pos, vel) | |
self.position = pos | |
self.velocity = vel | |
end | |
function RainAnimation:update() | |
self.position.y = self.position.y - self.velocity | |
end | |
function RainAnimation:draw() | |
p = self.position | |
line(p.x,p.y,p.x,p.y + self.velocity) | |
end | |
function RainAnimation:shouldCull() | |
-- Check if off the bottom of the screen | |
if (self.position.y + self.velocity) < 0 then | |
return true | |
end | |
return false | |
end | |
---------------------------------------------- | |
-- All lines | |
---------------------------------------------- | |
RainAnimations = class() | |
function RainAnimations:init() | |
self.minSpeed = 5 | |
self.speed = 30 | |
self.spawnRate = 2 | |
self.lines = {} | |
end | |
function RainAnimations:updateAndCull() | |
toCull = {} | |
for i,v in ipairs(self.lines) do | |
if v:shouldCull() then | |
-- table.insert( toCull, i ) | |
table.remove( self.lines, i ) | |
else | |
v:update() | |
end | |
end | |
end | |
function RainAnimations:update() | |
-- Create spawnRate lines per update | |
for i = 1,self.spawnRate do | |
-- Generate random spawn location | |
vel = math.random(self.minSpeed, self.speed) | |
spawn = vec2( math.random(WIDTH), HEIGHT + vel ) | |
table.insert(self.lines, RainAnimation(spawn, vel)) | |
end | |
-- Update and cull offscreen lines | |
self:updateAndCull() | |
end | |
function RainAnimations:draw() | |
pushStyle() | |
noSmooth() | |
stroke(59, 25, 223, 216) | |
strokeWidth(3) | |
lineCapMode(PROJECT) | |
for i,v in ipairs(self.lines) do | |
v:draw() | |
end | |
popStyle() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Tiles | |
-- table of locations for the floor tiles | |
-- my tile sheets are broken down from a large sheet of multiple tile sheets | |
-- set: determines the tileset to be used from the tilesets table in the Images tab | |
-- x/y: indicates the position of the sheet in the tileset with (0,0) being the bottom left | |
-- type: autotile type 1=floor/ceiling 2=roof/wall 3=waterfall 4=none | |
-- passable: whether or not the player can walk on the tile | |
function loadTiles() | |
local tiles = { | |
{ set = 1, x = 0, y = 3, type = 1, passable = true }, -- 1 -- world map grass | |
{ set = 1, x = 0, y = 2, type = 1, passable = true }, -- 2 -- world map arid | |
{ set = 1, x = 0, y = 1, type = 1, passable = true }, -- 3 -- world map desert | |
{ set = 1, x = 0, y = 0, type = 1, passable = true }, -- 4 -- world map snow | |
{ set = 1, x = 3, y = 3, type = 1, passable = true }, -- 5 -- town/dungeon grass | |
{ set = 1, x = 3, y = 2, type = 1, passable = true }, -- 6 -- town/dungeon arid | |
{ set = 1, x = 3, y = 1, type = 1, passable = true }, -- 7 -- town/dungeon desert | |
{ set = 1, x = 3, y = 0, type = 1, passable = true }, -- 8 -- town/dungeon snow | |
{ set = 1, x = 6, y = 3, type = 1, passable = true }, -- 9 -- town/dungeon cobblestone | |
{ set = 1, x = 6, y = 2, type = 1, passable = true }, -- 10 -- town/dungeon carpet | |
{ set = 1, x = 6, y = 1, type = 1, passable = true }, -- 11 -- town/dungeon church carpet | |
{ set = 1, x = 6, y = 0, type = 1, passable = true }, -- 12 -- town/dungeon metal | |
{ set = 1, x = 7, y = 3, type = 1, passable = true }, -- 13 -- town/dungeon table | |
{ set = 1, x = 7, y = 2, type = 1, passable = true }, -- 14 -- town/dungeon embossed table | |
{ set = 1, x = 7, y = 1, type = 1, passable = true }, -- 15 -- town/dungeon stone table | |
{ set = 1, x = 7, y = 0, type = 1, passable = true } -- 16 -- town/dungeon ice table | |
} | |
return tiles | |
end | |
function loadAnimatedTiles() | |
local aTiles = { | |
{ set = 4, x = 0, y = 3, type = 1, passable = false }, -- 1 -- town/dungeon shore water | |
{ set = 4, x = 0, y = 2, type = 1, passable = false }, -- 2 -- world map ocean (must overlap floor tile) | |
{ set = 10, x = 0, y = 0, type = 4, passable = true } -- 3 -- Rain puddles | |
} | |
return aTiles | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment