@skythecoder I started to take your mesh suggestion but I have a bug…would you mind taking a curious look at it?
--# Button
Button = class()
function Button:init(x,y,w,h,d,s)
self.x = x
self.y = y
self.w = w
self.h = h
self.s = s
self.d = 1
self.action = nil
self.m = mesh()
-- print(unpack(self:makeCenter()))
self.m.vertices = {unpack(self:makeCenter())}
self.m:setColors (255,5,255,255)
self.m.texture = readImage("Character Horn Girl")
end
function Button:draw()
-- Codea does not automatically call this method
pushStyle()
noStroke()
fill(77, 146, 76, 255)
rect(self.d * self.x -1, self.y-self.h/4, self.x +2, self.h/2)
ellipse(self.x - self.w/2 + self.h/2,self.y - self.h/2 + self.h/2, self.h)
ellipse(self.x + self.w/2 - self.h/2,self.y - self.h/2 + self.h/2, self.h)
rect(self.x - self.w/2 + self.h/2 -.5, self.y - self.h/2 +.5, self.w -self.h+1 , self.h -1)
fill(207, 120, 120, 255)
rect(self.d * self.x, self.y-self.h/10*1.5, self.x , self.h/5*1.5)
ellipse(self.x - self.w/2 + self.h/2,self.y - self.h/2 + self.h/2, self.h/4*3)
ellipse(self.x + self.w/2 - self.h/2,self.y - self.h/2 + self.h/2, self.h/4*3)
rect(self.x - self.w/2 + self.h/2 , self.y - self.h/8*3 , self.w -self.h , self.h/4*3 )
fill(255, 255, 255, 255)
text(self.s, self.x, self.y)
popStyle()
self.m:draw()
end
function Button:touched(t)
-- Codea does not automatically call this method
local x = t.x
local y = t.y
if t.state == BEGAN and x>self.x- self.w/2 and x<self.x+self.w/2 and y>self.y-self.h/2 and y<self.y+self.w/2 then
if self.action ~= nil then
self.action()
end
end
end
function Button:makeCenter()
--returns the dataPoints for the interior meshing that buttons will utilize...
local t = {}
for a = 90,150,2 do
table.insert(t, vec2(self.x - self.w/2 + self.h*4.2/8
+ math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
if self.d == 0 then
table.insert(t,vec2(0, self.y + math.sin(math.rad(155)) * self.h/8*3))
table.insert(t,vec2(0, self.y + math.sin(math.rad(205)) * self.h/8*3))
else
for a = 150, 200, 2 do
table.insert(t, vec2(self.x - self.w/2 + self.h*4.2/8
+ math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
end
for a = 200,270,2 do
table.insert(t, vec2(self.x - self.w/2 + self.h*4.2/8
+ math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
-- table.insert(t, vec2(self.x - self.w/2 + self.h*4.2/8
-- + math.cos(math.rad(90)) * self.h/8*3, self.y + math.sin(math.rad(90)) * self.h/8*3))
for a = 270, 330,10 do
table.insert(t,vec2(self.x-self.w/2 + self.w - self.h *4.2/8+math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
if self.d == 1 then
table.insert(t,vec2(WIDTH, self.y + math.sin(math.rad(335)) * self.h/8*3))
table.insert(t,vec2(WIDTH, self.y + math.sin(math.rad(25)) * self.h/8*3))
else
for a = 325, 390,4 do
table.insert(t,vec2(self.x-self.w/2 + self.w - self.h *4.2/8+math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
end
for a = 25, 90,4 do
table.insert(t,vec2(self.x-self.w/2 + self.w - self.h *4.2/8+math.cos(math.rad(a)) * self.h/8*3, self.y + math.sin(math.rad(a)) * self.h/8*3))
end
return t
end
--# Main
-- 0 Little Quackys Rainy Day Adventure
function setup()
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
-- WIDTH = 480
-- HEIGHT = 480
displayMode(FULLSCREEN)
mode = TheTitle()
end
function draw()
mode:draw()
--fill(226, 115, 116, 138)
-- rect(0,0,WIDTH,HEIGHT)
end
function touched(t)
mode:touched(t)
end
--# TheGame
TheGame = class()
function TheGame:init(x)
end
function TheGame:draw()
end
function TheGame:touched(t)
end
--# TheTitle
TheTitle = class()
function TheTitle:init()
self.buttons = {Button(WIDTH/2, HEIGHT/5, WIDTH/2, HEIGHT/10, 1,"PLAY")}
self.buttons[1].action = function() print("&") end
end
function TheTitle:draw()
-- Codea does not automatically call this method
background(22, 247, 172, 255)
for a,b in pairs(self.buttons) do
b:draw()
end
end
function TheTitle:touched(t)
-- Codea does not automatically call this method
for a,b in pairs(self.buttons) do
b:touched(t)
end
end