more pictures, better stencil mesh over the bg
13
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
|
||||
BIN
graphics/images/1534_4255446.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
graphics/images/hentai2.jpg
Normal file
|
After Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 214 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 428 KiB After Width: | Height: | Size: 53 KiB |
@@ -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'),
|
||||
}
|
||||
@@ -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(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)
|
||||
|
||||
70
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,54 +28,54 @@ 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???
|
||||
if #points > 2 then
|
||||
local polypts = love.math.triangulate(points)
|
||||
local tlist
|
||||
|
||||
@@ -90,7 +90,9 @@ function poly2mesh(points)
|
||||
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] then
|
||||
verthash[px] = {}
|
||||
end
|
||||
if not verthash[px][py] then
|
||||
n = n + 1
|
||||
verthash[px][py] = n
|
||||
@@ -112,5 +114,9 @@ function poly2mesh(points)
|
||||
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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||