diff --git a/README.md b/README.md index 6e69e26..fb666ba 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # SpiderCut + Lua game inspired by an old arcade game using LOVE2D for Linux. + +## TO-DO + +- Stop player from creating crossed lines + +- Fix creation of the lines / polygon / points + +- Add more pictures (manga?) + +- Fix Mesh + +- Fix balls sometimes attaching to the lines \ No newline at end of file diff --git a/graphics/images/1534_4255446.jpg b/graphics/images/1534_4255446.jpg new file mode 100644 index 0000000..d15b93a Binary files /dev/null and b/graphics/images/1534_4255446.jpg differ diff --git a/graphics/images/hentai2.jpg b/graphics/images/hentai2.jpg new file mode 100644 index 0000000..f3fee6f Binary files /dev/null and b/graphics/images/hentai2.jpg differ diff --git a/graphics/images/wp_18.jpg b/graphics/images/wp_18.jpg index 8de3057..35f1ac5 100644 Binary files a/graphics/images/wp_18.jpg and b/graphics/images/wp_18.jpg differ diff --git a/graphics/images/wp_3.jpg b/graphics/images/wp_3.jpg index 6b10c48..98584d7 100644 Binary files a/graphics/images/wp_3.jpg and b/graphics/images/wp_3.jpg differ diff --git a/graphics/images/wp_30.jpg b/graphics/images/wp_30.jpg index 796a9e6..c3c4a5a 100644 Binary files a/graphics/images/wp_30.jpg and b/graphics/images/wp_30.jpg differ diff --git a/graphics/images/wp_46.jpg b/graphics/images/wp_46.jpg index 439bcff..69258b1 100644 Binary files a/graphics/images/wp_46.jpg and b/graphics/images/wp_46.jpg differ diff --git a/src/Dependencies.lua b/src/Dependencies.lua index 5bef68e..8f238f6 100644 --- a/src/Dependencies.lua +++ b/src/Dependencies.lua @@ -64,7 +64,11 @@ gSounds = { } gImages = { - ['img1'] = love.graphics.newImage('graphics/images/wp_18.jpg'), - ['img2'] = love.graphics.newImage('graphics/images/wp_30.jpg'), - ['img3'] = love.graphics.newImage('graphics/images/wp_46.jpg'), + -- convert wp_30.jpg -resize 364x176! wp_30.jpg + love.graphics.newImage('graphics/images/wp_18.jpg'), + love.graphics.newImage('graphics/images/wp_30.jpg'), + love.graphics.newImage('graphics/images/wp_46.jpg'), + love.graphics.newImage('graphics/images/wp_3.jpg'), + love.graphics.newImage('graphics/images/hentai2.jpg'), + love.graphics.newImage('graphics/images/1534_4255446.jpg'), } \ No newline at end of file diff --git a/src/Level.lua b/src/Level.lua index f7a2f6f..4becd5c 100644 --- a/src/Level.lua +++ b/src/Level.lua @@ -1,23 +1,24 @@ -- require('mobdebug').start() Level = Class {} -function Level:init() - +function Level:init(stage) + self.stage = stage + self.points = {} + self.player = {} self.segments = self:createLevel() self.polygon = self:createPolygon() - self.player = {} - self.mesh = {} + self.mesh = poly2mesh(self.points) end function Level:update(dt) - self:createPolygon() - if #self.polygonPoints < 3 then - self.mesh = {} - else - print_r(self.polygonPoints) - self.mesh = poly2mesh(self.polygonPoints) - end + -- print_r(self.points) + -- print(tostring(#self.points)) + -- if self.mesh == nil and #self.points > 2 then + -- self.mesh = poly2mesh(self.points) + -- end + self.mesh = poly2mesh(self.points) + -- print_r(self.mesh:getVertices()) end function Level:render() @@ -30,8 +31,11 @@ function Level:renderOuterSegments() end function Level:renderBackground() - love.graphics.draw(gImages["img1"], LEVEL_RENDER_OFFSET,LEVEL_RENDER_OFFSET_TOP) - love.graphics.draw(self.mesh, 0, 0) + love.graphics.draw(gImages[(self.stage % #gImages)], LEVEL_RENDER_OFFSET, + LEVEL_RENDER_OFFSET_TOP) + if self.mesh:type() == "Mesh" then + love.graphics.draw(self.mesh, 0, 0) + end end function Level:createLevel() @@ -149,6 +153,7 @@ end function Level:createPolygon() local polygon = {} local polygonPoints = {} + local pointlist = {} local j = 1 for i, segment in ipairs(self.segments) do polygon[i] = {} @@ -159,10 +164,15 @@ function Level:createPolygon() polygonPoints[j + 1] = polygon[i].y polygonPoints[j + 2] = polygon[i + 1].x polygonPoints[j + 3] = polygon[i + 1].y + + table.insert(pointlist, polygon[i].x) + table.insert(pointlist, polygon[i].y) + j = j + 4 i = i + 1 end self.polygonPoints = polygonPoints + self.points = pointlist return polygon end @@ -524,6 +534,8 @@ function Level:cutLevel() end end + self:createPolygon() + self.mesh = poly2mesh(self.points) end function Level:orderSegments(segs) diff --git a/src/Util.lua b/src/Util.lua index 94b0a8b..7f59c0f 100644 --- a/src/Util.lua +++ b/src/Util.lua @@ -1,11 +1,9 @@ - -- require('mobdebug').start() --[[ Given an "atlas" (a texture with multiple sprites), as well as a width and a height for the tiles therein, split the texture into all of the quads by simply dividing it evenly. -]] -function GenerateQuads(atlas, tilewidth, tileheight) +]] function GenerateQuads(atlas, tilewidth, tileheight) local sheetWidth = atlas:getWidth() / tilewidth local sheetHeight = atlas:getHeight() / tileheight @@ -14,9 +12,11 @@ function GenerateQuads(atlas, tilewidth, tileheight) for y = 0, sheetHeight - 1 do for x = 0, sheetWidth - 1 do - spritesheet[sheetCounter] = - love.graphics.newQuad(x * tilewidth, y * tileheight, tilewidth, - tileheight, atlas:getDimensions()) + spritesheet[sheetCounter] = love.graphics.newQuad(x * tilewidth, + y * tileheight, + tilewidth, + tileheight, + atlas:getDimensions()) sheetCounter = sheetCounter + 1 end end @@ -28,89 +28,95 @@ end Recursive table printing function. https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/ ]] -function print_r ( t ) - local print_r_cache={} - local function sub_print_r(t,indent) +function print_r(t) + local print_r_cache = {} + local function sub_print_r(t, indent) if (print_r_cache[tostring(t)]) then - print(indent.."*"..tostring(t)) + print(indent .. "*" .. tostring(t)) else - print_r_cache[tostring(t)]=true - if (type(t)=="table") then - for pos,val in pairs(t) do - if (type(val)=="table") then - print(indent.."["..pos.."] => "..tostring(t).." {") - sub_print_r(val,indent..string.rep(" ",string.len(pos)+8)) - print(indent..string.rep(" ",string.len(pos)+6).."}") - elseif (type(val)=="string") then - print(indent.."["..pos..'] => "'..val..'"') + print_r_cache[tostring(t)] = true + if (type(t) == "table") then + for pos, val in pairs(t) do + if (type(val) == "table") then + print(indent .. "[" .. pos .. "] => " .. tostring(t) .. + " {") + sub_print_r(val, indent .. + string.rep(" ", string.len(pos) + 8)) + print(indent .. string.rep(" ", string.len(pos) + 6) .. + "}") + elseif (type(val) == "string") then + print(indent .. "[" .. pos .. '] => "' .. val .. '"') else - print(indent.."["..pos.."] => "..tostring(val)) + print(indent .. "[" .. pos .. "] => " .. tostring(val)) end end else - print(indent..tostring(t)) + print(indent .. tostring(t)) end end end - if (type(t)=="table") then - print(tostring(t).." {") - sub_print_r(t," ") + if (type(t) == "table") then + print(tostring(t) .. " {") + sub_print_r(t, " ") print("}") else - sub_print_r(t," ") + sub_print_r(t, " ") end print() end -function math.round(x,precision) - return x + precision - (x + precision) % 1 -end +function math.round(x, precision) return x + precision - (x + precision) % 1 end function print_s(segments) - for k, s in ipairs(segments) do - s:debug(tostring(k)) - end + for k, s in ipairs(segments) do s:debug(tostring(k)) end end -- convert a list of points forming a polygon {x1, y1, x2, y2, ...} into a mesh function poly2mesh(points) -- remove duplicates??? - local polypts = love.math.triangulate(points) - local tlist + if #points > 2 then + local polypts = love.math.triangulate(points) + local tlist - local vnums = {} - local vcoords = {} - do - local verthash = {} - local n = 0 - local v - -- use unique vertices by using a coordinate hash table - for i = 1, #polypts do - for j = 1, 3 do - local px = polypts[i][j * 2 - 1] - local py = polypts[i][j * 2] - if not verthash[px] then verthash[px] = {} end - if not verthash[px][py] then - n = n + 1 - verthash[px][py] = n - vcoords[n * 2 - 1] = px - vcoords[n * 2] = py - v = n - else - v = verthash[px][py] + local vnums = {} + local vcoords = {} + do + local verthash = {} + local n = 0 + local v + -- use unique vertices by using a coordinate hash table + for i = 1, #polypts do + for j = 1, 3 do + local px = polypts[i][j * 2 - 1] + local py = polypts[i][j * 2] + if not verthash[px] then + verthash[px] = {} + end + if not verthash[px][py] then + n = n + 1 + verthash[px][py] = n + vcoords[n * 2 - 1] = px + vcoords[n * 2] = py + v = n + else + v = verthash[px][py] + end + vnums[(i - 1) * 3 + j] = v end - vnums[(i - 1) * 3 + j] = v end end - end - local mesh = love.graphics.newMesh(#vcoords, "triangles", "static") - for i = 1, #vcoords / 2 do - local x, y = vcoords[i * 2 - 1], vcoords[i * 2] + local mesh = love.graphics.newMesh(#vcoords, "triangles", "static") + for i = 1, #vcoords / 2 do + local x, y = vcoords[i * 2 - 1], vcoords[i * 2] - -- Here's where the UVs are assigned - mesh:setVertex(i, x, y, x / 50, y / 50, .5, .5, .9, 1) + -- Here's where the UVs are assigned + mesh:setVertex(i, x, y, x / 50, y / 50, .5, .5, .9, 1) + end + mesh:setVertexMap(vnums) + print_r(mesh:type()) + return mesh + else + return nil end - mesh:setVertexMap(vnums) - return mesh end diff --git a/src/states/game/PlayState.lua b/src/states/game/PlayState.lua index 3511c0d..f0e28cc 100644 --- a/src/states/game/PlayState.lua +++ b/src/states/game/PlayState.lua @@ -5,7 +5,7 @@ PlayState = Class{__includes = BaseState} function PlayState:init() self.name = 'PlayState' self.stage = 1 - self.level = Level() + self.level = Level(self.stage) self.player = Player ( ENTITY_DEFS['player'] , self.level) self.level.player = self.player self.balls = {} @@ -97,7 +97,7 @@ function PlayState:nextStage() gStateStack:push(FadeOutState({ r = 255/255, g = 255/255, b = 255/255}, 1,function() self.stage = self.stage + 1 - self.level = Level() + self.level = Level(self.stage) self.player:reset() self.player.score = self.player.score + self.player.multiplier * #self.balls self.player.multiplier = self.player.multiplier + #self.balls