Created
July 18, 2013 22:23
-
-
Save aalok74/6033649 to your computer and use it in GitHub Desktop.
Added rain effect via shader to Slashin8r RPG project. This will use shaders to simulate rain.
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 | |
npcimgs[i].shader.toggle = false | |
if testBelow(v) then | |
npcimgs[i].shader.toggle = true | |
end | |
if not v.behind then | |
npcimgs[i]:draw() | |
end | |
npcimgs[i]:clear() | |
end | |
end | |
popMatrix() | |
pimg.shader.toggle = false | |
if testBelow(player) then | |
pimg.shader.toggle = true | |
end | |
if not player.behind then | |
pimg:draw() | |
end | |
pimg:clear() | |
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
-- 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 = RainEffect(WIDTH/2, HEIGHT/2) | |
-- 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 | |
----------------------------- | |
--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&d=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
-- Copyright 2012 Javier Moral | |
-- | |
-- Licensed under the Apache License, Version 2.0 (the "License"); | |
-- you may not use this file except in compliance with the License. | |
-- You may obtain a copy of the License at | |
-- | |
-- http://www.apache.org/licenses/LICENSE-2.0 | |
-- | |
-- Unless required by applicable law or agreed to in writing, software | |
-- distributed under the License is distributed on an "AS IS" BASIS, | |
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
-- See the License for the specific language governing permissions and | |
-- limitations under the License. | |
--Updated and maintained by Briarfox | |
Particular = class() | |
function Particular:init(x,y,settings) | |
self.x = x | |
self.y = y | |
if settings then | |
print("Settings Loaded") | |
self.sizeX = settings.sizeX or 0 | |
self.sizeY = settings.sizeY or 500 | |
self.partPerSec = settings.partPerSec or 2 | |
self.life = settings.life or 30 | |
self.lifeVariation = settings.lifeVariation or 0 | |
self.rotSpd = settings.rotSpd or 0.0 | |
self.rotSpdVariation = settings.rotSpdVariation or 0 | |
self.initPartSize = settings.initPartSize or 35 | |
self.partSizeVariation = settings.partSizeVariation or 0 | |
self.finalPartSize = settings.finalPartSize or -1 | |
self.velocity = settings.velocity or 10 | |
self.velocityVariation = settings.velocityVariation or 0 | |
self.initOpacity = settings.initOpacity or 255 | |
self.opacityVariation = settings.opacityVariation or 0 | |
self.finalOpacity = settings.finalOpacity or -1 | |
self.windX = settings.windX or 0 | |
self.airResistance = settings.airResistance or 0.1 | |
self.gravity = settings.gravity or 0 | |
self.useGravityVector = settings.useGravityVector or 0 | |
self.sizeWiggle = settings.sizeWiggle or 0 | |
self.turbulencePosAffect = settings.turbulencePosAffect or 0 | |
else | |
self.sizeX = 0 | |
self.sizeY = 0 | |
self.partPerSec = 2 | |
self.life = 30 | |
self.lifeVariation = 0 | |
self.rotSpd = 0.0 | |
self.rotSpdVariation = 0 | |
self.initPartSize = 35 | |
self.partSizeVariation = 0 | |
self.finalPartSize = -1 | |
self.velocity = 10 | |
self.velocityVariation = 0 | |
self.initOpacity = 255 | |
self.opacityVariation = 0 | |
self.finalOpacity = -1 | |
self.windX = 0 | |
self.airResistance = 0.1 | |
self.gravity = 0 | |
self.useGravityVector = 0 | |
self.sizeWiggle = 0 | |
self.turbulencePosAffect = 0 | |
end | |
self.rects = {} | |
self.deadRects = {} | |
self.parts = {} | |
self.particularMesh = mesh() | |
self.particularMesh.texture = settings.img or nil | |
self.evo = 0 | |
self.tSinceLast = 0.0 | |
self.particleLimit = 50 | |
end | |
function Particular:draw() | |
self.tSinceLast = self.tSinceLast + DeltaTime | |
local tCreation = 1 / self.partPerSec | |
local partCreated = 0 | |
if self.partPerSec == 0 then | |
self.tSinceLast = 0 | |
end | |
-- Creating new particles | |
while (self.tSinceLast > tCreation) do | |
partCreated = partCreated + 1 | |
if (partCreated<=self.particleLimit)then | |
self.tSinceLast = self.tSinceLast-tCreation | |
else | |
self.tSinceLast = 0 | |
end | |
self:createParticle() | |
end | |
local resistance = 1/(self.airResistance + 1) | |
-- Calculating gravity | |
local g | |
if self.useGravityVector > 0 then | |
if self.gravity == 0 then | |
g = vec2(0,0) | |
else if self.gravity > 0 then | |
g = vec2(Gravity.x,Gravity.y) | |
else | |
g = vec2(-Gravity.x,-Gravity.y) | |
end | |
end | |
else | |
g = vec2(0,-self.gravity) | |
end | |
for k,i in ipairs(self.rects) do | |
local p = self.parts[i] | |
-- Calculating turbulence | |
local nx = 0 | |
local ny = 0 | |
if self.turbulencePosAffect>0 then | |
local n = noise(p.x,p.y,self.evo) | |
if n > 0 then | |
n = n - math.floor(n) | |
else | |
n = n - math.ceil(n) | |
end | |
nx = n * math.cos(self.evo) | |
ny = n * math.sin(self.evo) | |
self.evo = self.evo + 1 | |
if self.evo > 9999 then | |
self.evo = 0 | |
end | |
end | |
if (p.lifeLeft > 0) then | |
-- Calculating position and velocity | |
p.x = p.x + p.v.x + | |
self.windX * 0.1 + | |
self.turbulencePosAffect*nx | |
p.y = p.y + p.v.y + | |
self.turbulencePosAffect*ny | |
p.v = p.v + g | |
p.v = p.v * resistance | |
local lifePercentage = (p.life-p.lifeLeft)/p.life | |
-- Calculating size | |
local size | |
if self.finalPartSize >= 0 then | |
local sizeInc = self.finalPartSize - p.initSize | |
size = (lifePercentage*sizeInc)+p.initSize | |
else | |
size = p.initSize | |
end | |
if ((self.sizeWiggle>0)and(size>1)) then | |
size = math.random(size) | |
end | |
if (size<0) then | |
size = 0 | |
end | |
-- Calculating opacity | |
local opacity | |
if self.finalOpacity >= 0 then | |
local opacityInc = self.finalOpacity - p.initOpacity | |
opacity = (lifePercentage*opacityInc)+p.initOpacity | |
else | |
opacity = p.initOpacity | |
end | |
-- Calculating rotation | |
p.angle = p.angle + p.rotSpd | |
p.lifeLeft = p.lifeLeft - 1 | |
self.particularMesh:setRect(i,p.x,p.y,size,size,p.angle) | |
self.particularMesh:setRectColor(i,255,255,255,opacity) | |
else | |
local deadPart = self.parts[i] | |
if not deadPart.isDead then | |
table.insert(self.deadRects,i) | |
self.particularMesh:setRect(i,0,0,0,0) | |
deadPart.isDead = true | |
end | |
end | |
end | |
self.particularMesh:draw() | |
end | |
function Particular:createParticle() | |
local psize = genNumber(self.initPartSize,self.partSizeVariation) | |
local v = vec2(math.random(-100,100),math.random(-100,100)) | |
v = v:normalize() | |
v = v * genNumber(self.velocity,self.velocityVariation) | |
local partX = self.x + math.random(-self.sizeX,self.sizeX) | |
local partY = self.y + math.random(-self.sizeY,self.sizeY) | |
local particle = Particle(partX, | |
partY, | |
psize, | |
genNumber(self.life,self.lifeVariation), | |
v, | |
0, | |
genNumber(self.initOpacity,self.opacityVariation), | |
genNumber(self.rotSpd,self.rotSpdVariation)) | |
local index | |
if (self.deadRects[1]==nil) then | |
index = self.particularMesh:addRect(self.x, | |
self.y, | |
psize, | |
psize) | |
table.insert(self.rects, index) | |
table.insert(self.parts, particle) | |
else | |
index = self.deadRects[1] | |
table.remove(self.deadRects,1) | |
self.particularMesh:setRect(index, | |
self.x, | |
self.y, | |
psize, | |
psize) | |
self.parts[index] = particle | |
end | |
self.particularMesh:setRectColor(index,255,255,255, | |
particle.initOpacity) | |
end | |
function genNumber(number,variation) | |
if variation == 0.0 then | |
return number | |
end | |
if number == 0 then | |
return number | |
end | |
number = number * 1000 | |
mult = true | |
ret = variation*0.01*math.abs(number) | |
ret = number + math.random(-ret,ret) | |
ret = ret / 1000 | |
return ret | |
end | |
-- | |
-- Particle class | |
-- | |
Particle = class() | |
Particle.DEFAULT_OPACITY = 125 | |
Particle.DEFAULT_ANGLE = 0 | |
Particle.DEFAULT_MASS = 1 | |
function Particle:init(posx,posy,size,life, | |
velocity,angle,opacity,rotSpd) | |
-- position | |
self.x = posx | |
self.y = posy | |
-- size | |
self.initSize = size | |
-- velocity | |
self.v = velocity | |
-- life | |
self.life = life | |
self.lifeLeft= life | |
-- angle | |
if angle == nil then | |
self.angle = self.DEFAULT_ANGLE | |
else | |
self.angle = angle | |
end | |
-- rotation speed | |
if rotSpd==nil then | |
self.rotSpd = 0.0 | |
else | |
self.rotSpd = rotSpd | |
end | |
-- opacity | |
self.initOpacity = opacity | |
self.isDead = false | |
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
--RainEffect Saved Particle | |
RainEffect = class(Particular) | |
RainEffect.settings = {} | |
RainEffect.settings.img = "Small World:Mote Sad" --Set Texture Here | |
RainEffect.settings.partPerSec = 200 | |
RainEffect.settings.sizeX = 500 | |
RainEffect.settings.sizeY = 500 | |
RainEffect.settings.life = 100 | |
RainEffect.settings.lifeVariation = 0 | |
RainEffect.settings.initPartSize = 0 | |
RainEffect.settings.partSizeVariation = 0 | |
RainEffect.settings.finalPartSize = 50 | |
RainEffect.settings.velocity = 23.8095 | |
RainEffect.settings.velocityVariation = 40 | |
RainEffect.settings.rotSpd = 0.18928 | |
RainEffect.settings.rotSpdVariation = 23 | |
RainEffect.settings.initOpacity = 255 | |
RainEffect.settings.opacityVariation = 1 | |
RainEffect.settings.finalOpacity = 92 | |
RainEffect.settings.windX = 0 | |
RainEffect.settings.airResistance = 0.359307 | |
RainEffect.settings.gravity = 5 | |
RainEffect.settings.useGravityVector = 0 | |
RainEffect.settings.sizeWiggle = 0 | |
RainEffect.settings.turbulencePosAffect = 10 | |
function RainEffect:init(x,y) | |
Particular.init(self,x,y,RainEffect.settings) | |
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
walkIn = { | |
vertexShader = [[ | |
uniform mat4 modelViewProjection; | |
attribute vec4 position; | |
attribute vec4 color; | |
attribute vec2 texCoord; | |
varying lowp vec4 vColor; | |
varying highp vec2 vTexCoord; | |
void main() | |
{ | |
vColor = color; | |
vTexCoord = texCoord; | |
gl_Position = modelViewProjection * position; | |
} | |
]], | |
fragmentShader = [[ | |
precision highp float; | |
uniform lowp sampler2D texture; | |
uniform bool toggle; | |
varying lowp vec4 vColor; | |
varying highp vec2 vTexCoord; | |
void main() | |
{ | |
lowp vec4 col = texture2D( texture, vTexCoord ) * vColor; | |
if (toggle) | |
{ | |
if (vTexCoord.y <= 1./16. || | |
(vTexCoord.y <= 5./16. && vTexCoord.y > 4./16.) || | |
(vTexCoord.y <= 9./16. && vTexCoord.y > 8./16.) || | |
(vTexCoord.y <= 13./16. && vTexCoord.y > 12./16.)) | |
{ | |
col.rgba = col.rgba*0.25; | |
} | |
} | |
gl_FragColor = col; | |
} | |
]]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment