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,9 +31,12 @@ 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,
LEVEL_RENDER_OFFSET_TOP)
if self.mesh:type() == "Mesh" then
love.graphics.draw(self.mesh, 0, 0) love.graphics.draw(self.mesh, 0, 0)
end end
end
function Level:createLevel() function Level:createLevel()
local level = { local level = {
@@ -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
@@ -38,9 +38,12 @@ function print_r ( t )
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 ..
string.rep(" ", string.len(pos) + 8))
print(indent .. string.rep(" ", string.len(pos) + 6) ..
"}")
elseif (type(val) == "string") then elseif (type(val) == "string") then
print(indent .. "[" .. pos .. '] => "' .. val .. '"') print(indent .. "[" .. pos .. '] => "' .. val .. '"')
else else
@@ -62,20 +65,17 @@ function print_r ( t )
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???
if #points > 2 then
local polypts = love.math.triangulate(points) local polypts = love.math.triangulate(points)
local tlist local tlist
@@ -90,7 +90,9 @@ function poly2mesh(points)
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
verthash[px] = {}
end
if not verthash[px][py] then if not verthash[px][py] then
n = n + 1 n = n + 1
verthash[px][py] = n verthash[px][py] = n
@@ -112,5 +114,9 @@ function poly2mesh(points)
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 end
mesh:setVertexMap(vnums) mesh:setVertexMap(vnums)
print_r(mesh:type())
return mesh return mesh
else
return nil
end
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