more pictures, better stencil mesh over the bg

This commit is contained in:
2021-12-23 21:36:06 +01:00
parent 963b3ac174
commit 3a297f9130
11 changed files with 115 additions and 80 deletions

View File

@@ -1,2 +1,15 @@
# SpiderCut # SpiderCut
Lua game inspired by an old arcade game using LOVE2D for Linux. 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
graphics/images/hentai2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@@ -64,7 +64,11 @@ gSounds = {
} }
gImages = { gImages = {
['img1'] = love.graphics.newImage('graphics/images/wp_18.jpg'), -- convert wp_30.jpg -resize 364x176! wp_30.jpg
['img2'] = love.graphics.newImage('graphics/images/wp_30.jpg'), love.graphics.newImage('graphics/images/wp_18.jpg'),
['img3'] = love.graphics.newImage('graphics/images/wp_46.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'),
} }

View File

@@ -1,23 +1,24 @@
-- require('mobdebug').start() -- require('mobdebug').start()
Level = Class {} Level = Class {}
function Level:init() function Level:init(stage)
self.stage = stage
self.points = {}
self.player = {}
self.segments = self:createLevel() self.segments = self:createLevel()
self.polygon = self:createPolygon() self.polygon = self:createPolygon()
self.player = {} self.mesh = poly2mesh(self.points)
self.mesh = {}
end end
function Level:update(dt) function Level:update(dt)
self:createPolygon() -- print_r(self.points)
if #self.polygonPoints < 3 then -- print(tostring(#self.points))
self.mesh = {} -- if self.mesh == nil and #self.points > 2 then
else -- self.mesh = poly2mesh(self.points)
print_r(self.polygonPoints) -- end
self.mesh = poly2mesh(self.polygonPoints) self.mesh = poly2mesh(self.points)
end -- print_r(self.mesh:getVertices())
end end
function Level:render() function Level:render()
@@ -30,8 +31,11 @@ function Level:renderOuterSegments()
end end
function Level:renderBackground() 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,
love.graphics.draw(self.mesh, 0, 0) LEVEL_RENDER_OFFSET_TOP)
if self.mesh:type() == "Mesh" then
love.graphics.draw(self.mesh, 0, 0)
end
end end
function Level:createLevel() function Level:createLevel()
@@ -149,6 +153,7 @@ end
function Level:createPolygon() function Level:createPolygon()
local polygon = {} local polygon = {}
local polygonPoints = {} local polygonPoints = {}
local pointlist = {}
local j = 1 local j = 1
for i, segment in ipairs(self.segments) do for i, segment in ipairs(self.segments) do
polygon[i] = {} polygon[i] = {}
@@ -159,10 +164,15 @@ function Level:createPolygon()
polygonPoints[j + 1] = polygon[i].y polygonPoints[j + 1] = polygon[i].y
polygonPoints[j + 2] = polygon[i + 1].x polygonPoints[j + 2] = polygon[i + 1].x
polygonPoints[j + 3] = polygon[i + 1].y polygonPoints[j + 3] = polygon[i + 1].y
table.insert(pointlist, polygon[i].x)
table.insert(pointlist, polygon[i].y)
j = j + 4 j = j + 4
i = i + 1 i = i + 1
end end
self.polygonPoints = polygonPoints self.polygonPoints = polygonPoints
self.points = pointlist
return polygon return polygon
end end
@@ -524,6 +534,8 @@ function Level:cutLevel()
end end
end end
self:createPolygon()
self.mesh = poly2mesh(self.points)
end end
function Level:orderSegments(segs) function Level:orderSegments(segs)

View File

@@ -1,11 +1,9 @@
-- require('mobdebug').start() -- require('mobdebug').start()
--[[ --[[
Given an "atlas" (a texture with multiple sprites), as well as a Given an "atlas" (a texture with multiple sprites), as well as a
width and a height for the tiles therein, split the texture into width and a height for the tiles therein, split the texture into
all of the quads by simply dividing it evenly. 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 sheetWidth = atlas:getWidth() / tilewidth
local sheetHeight = atlas:getHeight() / tileheight local sheetHeight = atlas:getHeight() / tileheight
@@ -14,9 +12,11 @@ function GenerateQuads(atlas, tilewidth, tileheight)
for y = 0, sheetHeight - 1 do for y = 0, sheetHeight - 1 do
for x = 0, sheetWidth - 1 do for x = 0, sheetWidth - 1 do
spritesheet[sheetCounter] = spritesheet[sheetCounter] = love.graphics.newQuad(x * tilewidth,
love.graphics.newQuad(x * tilewidth, y * tileheight, tilewidth, y * tileheight,
tileheight, atlas:getDimensions()) tilewidth,
tileheight,
atlas:getDimensions())
sheetCounter = sheetCounter + 1 sheetCounter = sheetCounter + 1
end end
end end
@@ -28,89 +28,95 @@ end
Recursive table printing function. Recursive table printing function.
https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/ https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/
]] ]]
function print_r ( t ) function print_r(t)
local print_r_cache={} local print_r_cache = {}
local function sub_print_r(t,indent) local function sub_print_r(t, indent)
if (print_r_cache[tostring(t)]) then if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t)) print(indent .. "*" .. tostring(t))
else else
print_r_cache[tostring(t)]=true print_r_cache[tostring(t)] = true
if (type(t)=="table") then if (type(t) == "table") then
for pos,val in pairs(t) do for pos, val in pairs(t) do
if (type(val)=="table") then if (type(val) == "table") then
print(indent.."["..pos.."] => "..tostring(t).." {") print(indent .. "[" .. pos .. "] => " .. tostring(t) ..
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8)) " {")
print(indent..string.rep(" ",string.len(pos)+6).."}") sub_print_r(val, indent ..
elseif (type(val)=="string") then string.rep(" ", string.len(pos) + 8))
print(indent.."["..pos..'] => "'..val..'"') print(indent .. string.rep(" ", string.len(pos) + 6) ..
"}")
elseif (type(val) == "string") then
print(indent .. "[" .. pos .. '] => "' .. val .. '"')
else else
print(indent.."["..pos.."] => "..tostring(val)) print(indent .. "[" .. pos .. "] => " .. tostring(val))
end end
end end
else else
print(indent..tostring(t)) print(indent .. tostring(t))
end end
end end
end end
if (type(t)=="table") then if (type(t) == "table") then
print(tostring(t).." {") print(tostring(t) .. " {")
sub_print_r(t," ") sub_print_r(t, " ")
print("}") print("}")
else else
sub_print_r(t," ") sub_print_r(t, " ")
end end
print() print()
end end
function math.round(x,precision) function math.round(x, precision) return x + precision - (x + precision) % 1 end
return x + precision - (x + precision) % 1
end
function print_s(segments) function print_s(segments)
for k, s in ipairs(segments) do for k, s in ipairs(segments) do s:debug(tostring(k)) end
s:debug(tostring(k))
end
end end
-- convert a list of points forming a polygon {x1, y1, x2, y2, ...} into a mesh -- convert a list of points forming a polygon {x1, y1, x2, y2, ...} into a mesh
function poly2mesh(points) function poly2mesh(points)
-- remove duplicates??? -- remove duplicates???
local polypts = love.math.triangulate(points) if #points > 2 then
local tlist local polypts = love.math.triangulate(points)
local tlist
local vnums = {} local vnums = {}
local vcoords = {} local vcoords = {}
do do
local verthash = {} local verthash = {}
local n = 0 local n = 0
local v local v
-- use unique vertices by using a coordinate hash table -- use unique vertices by using a coordinate hash table
for i = 1, #polypts do for i = 1, #polypts do
for j = 1, 3 do for j = 1, 3 do
local px = polypts[i][j * 2 - 1] local px = polypts[i][j * 2 - 1]
local py = polypts[i][j * 2] local py = polypts[i][j * 2]
if not verthash[px] then verthash[px] = {} end if not verthash[px] then
if not verthash[px][py] then verthash[px] = {}
n = n + 1 end
verthash[px][py] = n if not verthash[px][py] then
vcoords[n * 2 - 1] = px n = n + 1
vcoords[n * 2] = py verthash[px][py] = n
v = n vcoords[n * 2 - 1] = px
else vcoords[n * 2] = py
v = verthash[px][py] v = n
else
v = verthash[px][py]
end
vnums[(i - 1) * 3 + j] = v
end end
vnums[(i - 1) * 3 + j] = v
end end
end end
end local mesh = love.graphics.newMesh(#vcoords, "triangles", "static")
local mesh = love.graphics.newMesh(#vcoords, "triangles", "static") for i = 1, #vcoords / 2 do
for i = 1, #vcoords / 2 do local x, y = vcoords[i * 2 - 1], vcoords[i * 2]
local x, y = vcoords[i * 2 - 1], vcoords[i * 2]
-- Here's where the UVs are assigned -- Here's where the UVs are assigned
mesh:setVertex(i, x, y, x / 50, y / 50, .5, .5, .9, 1) 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
mesh:setVertexMap(vnums)
return mesh
end end

View File

@@ -5,7 +5,7 @@ PlayState = Class{__includes = BaseState}
function PlayState:init() function PlayState:init()
self.name = 'PlayState' self.name = 'PlayState'
self.stage = 1 self.stage = 1
self.level = Level() self.level = Level(self.stage)
self.player = Player ( ENTITY_DEFS['player'] , self.level) self.player = Player ( ENTITY_DEFS['player'] , self.level)
self.level.player = self.player self.level.player = self.player
self.balls = {} self.balls = {}
@@ -97,7 +97,7 @@ function PlayState:nextStage()
gStateStack:push(FadeOutState({ gStateStack:push(FadeOutState({
r = 255/255, g = 255/255, b = 255/255}, 1,function() r = 255/255, g = 255/255, b = 255/255}, 1,function()
self.stage = self.stage + 1 self.stage = self.stage + 1
self.level = Level() self.level = Level(self.stage)
self.player:reset() self.player:reset()
self.player.score = self.player.score + self.player.multiplier * #self.balls self.player.score = self.player.score + self.player.multiplier * #self.balls
self.player.multiplier = self.player.multiplier + #self.balls self.player.multiplier = self.player.multiplier + #self.balls