Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("class")
- require("engine")
- require("gui")
- Game = newClass(engine.Engine)
- function Game:setup()
- self:setScene(Intro)
- self:setTitle("Game Test")
- self.fade = 1
- end
- Intro = newClass(engine.Entity)
- function Intro:setup()
- self:setBackgroundColor({255, 255, 255})
- self.hasBackground = true
- local title = engine.Label:new(self.engine, self)
- self:addChild(title, "Game Test")
- title:setFont(love.graphics.newFont(50))
- local sub = engine.Label:new(self.engine, self)
- self:addChild(sub, "By MegaLoler")
- sub:setFont(love.graphics.newFont(20))
- sub:setPosition(title.x, title.y + title.height)
- end
- function Intro:update(dt)
- if self.time > 3 then
- self:next()
- end
- end
- function Intro:mousepressed(x, y, button)
- self:next()
- end
- function Intro:next()
- self.engine:fadeToScene(Menu)
- end
- Menu = newClass(engine.Entity)
- function Menu:setup()
- self:setBackgroundColor({31, 31, 31})
- self.clearCanvas = false
- self.backgroundAlpha = 63
- self.hasBackground = true
- self.staticDrawing = false
- self.camX = 0
- self.camY = 0
- self.targetCamX = 0
- self.targetCamY = 0
- self.camSpeed = 0.2
- self.container = engine.Container:new(self.engine, self)
- self:addChild(self.container, self.width * 2, self.height * 2)
- self.container.staticDrawing = false
- self.container.hasBackground = false
- self.container.hasBorder = false
- self.container:setOrigin(0, 0)
- self.container:setPosition(0, 0)
- self.container.preDraw = self.drawBackground
- self.button = engine.Button:new(self.engine, self.container)
- self.container:addChild(self.button, "Start")
- self.button:setFont(love.graphics.newFont(30))
- self.button:setTextColor({20, 20, 20})
- self.button:setPosition(self.width / 2, self.height / 2 - 20)
- self.button2 = engine.Button:new(self.engine, self.container)
- self.container:addChild(self.button2, "Help", function() self.container.container:goToScreen(1, 0) end)
- self.button2:setFont(love.graphics.newFont(30))
- self.button2:setTextColor({20, 20, 20})
- self.button2:setPosition(self.width / 2, self.button.y + self.button.height + 10)
- self.button3 = engine.Button:new(self.engine, self.container)
- self.container:addChild(self.button3, "Credits", function() self.container.container:goToScreen(0, 1) end)
- self.button3:setFont(love.graphics.newFont(30))
- self.button3:setTextColor({20, 20, 20})
- self.button3:setPosition(self.width / 2, self.button2.y + self.button2.height + 10)
- self.button4 = engine.Button:new(self.engine, self.container)
- self.container:addChild(self.button4, "Quit", love.event.quit)
- self.button4:setFont(love.graphics.newFont(30))
- self.button4:setTextColor({20, 20, 20})
- self.button4:setPosition(self.width / 2, self.button3.y + self.button3.height + 10)
- self.button:setText("Start")
- self.button2:setText("Help")
- self.button3:setText("Credits")
- self.button4:setText("Exit")
- self.title = engine.Label:new(self.engine, self.container)
- self.container:addChild(self.title, "Menu")
- self.title:setFont(love.graphics.newFont(40))
- self.title.hasShadow = true
- self.title.shadowOffsetX = -5
- self.title.shadowOffsetY = 5
- self.title:setOrigin(0, 0)
- self.title:setTextColor({240, 240, 240})
- self.title:setPosition(50, 50)
- self.title2 = engine.Label:new(self.engine, self.container)
- self.container:addChild(self.title2, "Help")
- self.title2:setFont(love.graphics.newFont(40))
- self.title2.hasShadow = true
- self.title2.shadowOffsetX = -5
- self.title2.shadowOffsetY = 5
- self.title2:setOrigin(0, 0)
- self.title2:setTextColor({240, 240, 240})
- self.title2:setPosition(50 + self.width, 50)
- self.title3 = engine.Label:new(self.engine, self.container)
- self.container:addChild(self.title3, "Credits")
- self.title3:setFont(love.graphics.newFont(40))
- self.title3.hasShadow = true
- self.title3.shadowOffsetX = -5
- self.title3.shadowOffsetY = 5
- self.title3:setOrigin(0, 0)
- self.title3:setTextColor({240, 240, 240})
- self.title3:setPosition(50, 50 + self.height)
- self.title4 = engine.Label:new(self.engine, self.container)
- self.container:addChild(self.title4, "Stuff")
- self.title4:setFont(love.graphics.newFont(40))
- self.title4.hasShadow = true
- self.title4.shadowOffsetX = -5
- self.title4.shadowOffsetY = 5
- self.title4:setOrigin(0, 0)
- self.title4:setTextColor({240, 240, 240})
- self.title4:setPosition(50 + self.width, 50 + self.height)
- self.screenX = 0
- self.screenY = 0
- end
- function Menu:update(dt)
- self.button:move(math.cos(self.time * 2) / 3, math.sin(self.time * 2) / 3)
- self.button2:move(math.cos(self.time * 2 - 0.2) / 3, math.sin(self.time * 2 - 0.2) / 3)
- self.button3:move(math.cos(self.time * 2 - 0.4) / 3, math.sin(self.time * 2 - 0.4) / 3)
- self.button4:move(math.cos(self.time * 2 - 0.6) / 3, math.sin(self.time * 2 - 0.6) / 3)
- self.title:move(0, math.sin(self.time * 5))
- self.title2:move(0, math.sin(self.time * 5))
- self.title3:move(0, math.sin(self.time * 5))
- self.title4:move(0, math.sin(self.time * 5))
- self.camX = self.camX + (self.targetCamX - self.camX) * self.camSpeed
- self.camY = self.camY + (self.targetCamY - self.camY) * self.camSpeed
- self.container:move((-self.camX - self.container.x) * self.camSpeed, (-self.camY - self.container.y) * self.camSpeed)
- end
- function Menu:goToScreen(x, y)
- if x then self.screenX = x end
- if y then self.screenY = y end
- self.targetCamX = (x or self.screenX) * self.width
- self.targetCamY = (y or self.screenY) * self.height
- end
- function Menu:drawBackground()
- local ox = math.sin(self.time * 2.2) * 200
- local oy = math.cos(self.time * 2.9) * 200
- for x = -1, self.width / 128 do
- for y = -1, self.height / 128 do
- local xp = x * 200 + ox % 200
- local yp = y * 200 + oy % 200
- love.graphics.setColor(31 + xp / 8, 31 + yp / 8, 63)
- love.graphics.polygon("fill", xp, yp, xp + 100, yp, xp + 100, yp + 100, xp, yp + 100)
- xp = xp + 100
- yp = yp + 100
- love.graphics.setColor(31 + xp / 8, 31 + yp / 8, 63)
- love.graphics.polygon("fill", xp, yp, xp + 100, yp, xp + 100, yp + 100, xp, yp + 100)
- end
- end
- for x = -1, self.width / 128 do
- for y = -1, self.height / 128 do
- local xp = x * 200 + 5 + ox % 200
- local yp = y * 200 - 5 + oy % 200
- love.graphics.setColor(31 + xp / 8, 31 + yp / 8, 127)
- love.graphics.polygon("fill", xp, yp, xp + 100, yp, xp + 100, yp + 100, xp, yp + 100)
- xp = xp + 100
- yp = yp + 100
- love.graphics.setColor(31 + xp / 8, 31 + yp / 8, 127)
- love.graphics.polygon("fill", xp, yp, xp + 100, yp, xp + 100, yp + 100, xp, yp + 100)
- end
- end
- end
- function Menu:keypressed(key, unicode)
- if key == "left" then
- self.screenX = self.screenX - 1
- elseif key == "right" then
- self.screenX = self.screenX + 1
- elseif key == "down" then
- self.screenY = self.screenY + 1
- elseif key == "up" then
- self.screenY = self.screenY - 1
- end
- self.screenX = math.min(self.screenX, 1)
- self.screenY = math.min(self.screenY, 1)
- self.screenX = math.max(self.screenX, 0)
- self.screenY = math.max(self.screenY, 0)
- self:goToScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement