Advertisement
Guest User

Gilmore Adventure

a guest
Aug 19th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.01 KB | None | 0 0
  1. function love.load()
  2.   userInput = 0
  3.   jumpReady = 1
  4.   room = 0
  5.   timer1 = 1
  6.   gilmoreHoriz = 0
  7.   gilmoreVert = 0
  8.   gilmoreWalk = 0
  9.   animTimer = 100
  10.   nGilX = 650/2
  11.   nGilY = 650/2
  12.   record = 1
  13.   menu = 1
  14.   pan = 1
  15.   --
  16.   love.physics.setMeter(64)
  17.   world = love.physics.newWorld(0, 9.81*64, true)
  18.   --
  19.   images = {}
  20.   --
  21.   images.logo = love.graphics.newImage("resources/miscThings/logo.png")
  22.   images.logo2 = love.graphics.newImage("resources/miscThings/logo2.png")
  23.   images.logo3 = love.graphics.newImage("resources/miscThings/logo3.png")
  24.   images.main = love.graphics.newImage("resources/miscThings/main.png")
  25.   images.main2 = love.graphics.newImage("resources/miscThings/main2.png")
  26.   images.main3 = love.graphics.newImage("resources/miscThings/main3.png")
  27.   images.backLayer = love.graphics.newImage("resources/miscThings/backLayer.png")
  28.   --
  29.   music = {}
  30.   --
  31.   music.bossTheme = love.audio.newSource("resources/music/bossTheme.mp3")
  32.   music.intro = love.audio.newSource("resources/music/intro.mp3")
  33.   music.egg = love.audio.newSource("resources/music/intro.mp3")
  34.   --
  35.   sounds = {}
  36.   --
  37.   sounds.street = love.audio.newSource("resources/sounds/street.mp3")
  38.   --
  39.   sprites = {}
  40.   --
  41.   sprites.headOn = love.graphics.newImage("resources/gilmoreSprites/headOn.png")
  42.   sprites.driftLeft = love.graphics.newImage("resources/gilmoreSprites/driftLeft.png")
  43.   sprites.driftRight = love.graphics.newImage("resources/gilmoreSprites/driftRight.png")
  44.   sprites.falling = love.graphics.newImage("resources/gilmoreSprites/falling.png")
  45.   sprites.fallingUp = love.graphics.newImage("resources/gilmoreSprites/fallingUp.png")
  46.   sprites.fallLeft = love.graphics.newImage("resources/gilmoreSprites/fallLeft.png")
  47.   sprites.fallRight = love.graphics.newImage("resources/gilmoreSprites/fallRight.png")
  48.   sprites.jettingUp = love.graphics.newImage("resources/gilmoreSprites/jettingUp.png")
  49.   sprites.movingLeft = love.graphics.newImage("resources/gilmoreSprites/movingLeft.png")
  50.   sprites.movingRight = love.graphics.newImage("resources/gilmoreSprites/movingRight.png")
  51.   sprites.upLeft = love.graphics.newImage("resources/gilmoreSprites/upLeft.png")
  52.   sprites.upRight = love.graphics.newImage("resources/gilmoreSprites/upRight.png")
  53.   --
  54.   objects = {}
  55.   --
  56. --  objects.groundOne = {}
  57. --  objects.groundOne.body = love.physics.newBody(world, 650/2, 650/2)
  58. --  objects.groundOne.shape = love.physics.newRectangleShape(650, 50)
  59. --  objects.groundOne.fixture = love.physics.newFixture(objects.groundOne.body, objects.groundOne.shape);
  60.   --
  61.   objects.groundTwo = {}
  62.   objects.groundTwo.body = love.physics.newBody(world, 1200/2, 675)
  63.   objects.groundTwo.shape = love.physics.newRectangleShape(1200, 25)
  64.   objects.groundTwo.fixture = love.physics.newFixture(objects.groundTwo.body, objects.groundTwo.shape);
  65.   --
  66.   objects.gilmore = {}
  67.   objects.gilmore.body = love.physics.newBody(world, 1200/2, 600, "dynamic")
  68.   objects.gilmore.shape = love.physics.newCircleShape(32)
  69.   objects.gilmore.fixture = love.physics.newFixture(objects.gilmore.body, objects.gilmore.shape, 1)
  70.   objects.gilmore.body:setAngularDamping(20)
  71.   love.graphics.setBackgroundColor(145, 145, 145)
  72.   love.window.setMode(1200, 675)
  73.   --
  74.   love.audio.play(music.intro)
  75. end
  76.  
  77. function love.textinput( )
  78.     if menu == 1 then
  79.     room = 2
  80.     menu = 0
  81.     timer1 = 255
  82.     end
  83. end
  84.  
  85. function love.update(dt)
  86.   world:update(dt)
  87.   if pan == 1 and room == 3 and timer1 <= 400 and timer1 > 200 then
  88.     timer1 = (timer1 - 1)
  89.   elseif pan == 1 and room == 3 and timer1 <= 200 and timer1 > 0 then
  90.     timer1 = (timer1 - 1)
  91.     camera.y = (0 - timer1)
  92.   elseif pan == 1 and room == 3 and timer1 == 0 then
  93.     pan = 0
  94.   end
  95.   if pan == 0 and room == 3 then
  96.     camera.x = (objects.gilmore.body:getX() + -1200/2)
  97. --    camera.y = (objects.gilmore.body:getY() + -675/2)
  98.   end
  99.  
  100.   gilX = objects.gilmore.body:getX()
  101.   gilY = objects.gilmore.body:getY()
  102.   nGilX = (nGilX - gilX)
  103.   nGilY = (nGilY - gilY)
  104.   deltaGil1 = (nGilX + nGilY)
  105.   deltaGil = (deltaGil1 / 2)
  106. -- Animation Timer Start
  107.     if room > 0 then
  108.       if animTimer <= 255 and animTimer > 0 then
  109.         animTimer = (animTimer - 5)
  110.       elseif animTimer == 0 then
  111.         animTimer = 255
  112.       end
  113.     end
  114. --Animation Timer End
  115.   if deltaGil > 500 or deltaGil < -500 then
  116.     freakout = 0
  117.   elseif deltaGil < 500 and deltaGil > -500 then
  118.     freakout = 1
  119.   end
  120.   gilmoreHoriz, gilmoreVert = objects.gilmore.body:getLinearVelocity()
  121.   if gilmoreHoriz > 500 then
  122.     objects.gilmore.body:setLinearVelocity(500, gilmoreVert)
  123.   elseif gilmoreHoriz < -500 then
  124.     objects.gilmore.body:setLinearVelocity(-500, gilmoreVert)
  125.   end
  126.   if love.keyboard.isDown("right") then
  127.     objects.gilmore.body:applyForce(500, 0)
  128.     gilmoreWalk = 1
  129.     if love.keyboard.isDown("up") and gilmoreVert == 0 then
  130.     objects.gilmore.body:applyLinearImpulse(0, -400)
  131.     end
  132.   elseif love.keyboard.isDown("left") then
  133.     objects.gilmore.body:applyForce(-500, 0)
  134.     gilmoreWalk = 1
  135.     if love.keyboard.isDown("up") and gilmoreVert == 0 then
  136.     objects.gilmore.body:applyLinearImpulse(0, -400)
  137.     end
  138.   elseif love.keyboard.isDown("up") and gilmoreVert == 0 then
  139.     objects.gilmore.body:applyLinearImpulse(0, -400)
  140.     gilmoreWalk = 1
  141.   elseif not love.keyboard.isDown("right") or not love.keyboard.isDown("left") or not love.keyboard.isDown("up") then
  142.     gilmoreWalk = 0
  143.     if gilmoreHoriz < 5 or gilmoreHoriz > -5 then
  144.     objects.gilmore.body:setLinearVelocity(0, gilmoreVert)
  145.     end
  146.   end
  147.   if record == 1 and gilX > 700/2 then
  148.  -- love.audio.play(music.bossTheme)
  149.   record = 0
  150.   end
  151. end
  152.  
  153. function love.draw()
  154.  
  155.   if room == 3 then
  156.     camera:set()
  157.     --
  158.     love.graphics.draw(images.backLayer, 0, 0, 0, 0.625, 0.625, 0, 0, 0, 0)
  159.     --
  160.     love.graphics.setColor(50, 50, 50)
  161. --  love.graphics.polygon("fill", objects.groundOne.body:getWorldPoints(objects.groundOne.shape:getPoints()))
  162.     --
  163.     love.graphics.setColor(50, 50, 50)
  164.     love.graphics.polygon("fill", objects.groundTwo.body:getWorldPoints(objects.groundTwo.shape:getPoints()))
  165.     --
  166.     love.graphics.setColor(255, 255, 255)
  167. -- Gilmore Animation Core Start
  168.     if freakout == 0 then
  169.      if gilmoreHoriz == 0 and gilmoreVert == 0 then
  170.      love.graphics.draw(sprites.headOn, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 1, 1, 0, 0, 0, 0)
  171.      elseif gilmoreHoriz > -3 and gilmoreVert == 0 and gilmoreWalk == 0 then
  172.      love.graphics.draw(sprites.driftRight, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  173.      elseif gilmoreHoriz < 3 and gilmoreVert == 0 and gilmoreWalk == 0 then
  174.      love.graphics.draw(sprites.driftLeft, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  175.      elseif gilmoreHoriz == 0 and gilmoreVert > 0 then
  176.      love.graphics.draw(sprites.falling, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  177.      elseif gilmoreHoriz == 0 and gilmoreVert < 0 and gilmoreWalk == 0 then
  178.      love.graphics.draw(sprites.fallingUp, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  179.      elseif gilmoreHoriz > 0 and gilmoreVert == 0 and gilmoreWalk == 1 then
  180.      love.graphics.draw(sprites.movingRight, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  181.      elseif gilmoreHoriz < 0 and gilmoreVert == 0 and gilmoreWalk == 1 then
  182.      love.graphics.draw(sprites.movingLeft, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  183.      elseif gilmoreHoriz == 0 and gilmoreVert < 0 and gilmoreWalk == 1 then
  184.      love.graphics.draw(sprites.jettingUp, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  185.      elseif gilmoreHoriz > 0 and gilmoreVert > 0 then
  186.      love.graphics.draw(sprites.fallRight, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  187.      elseif gilmoreHoriz < 0 and gilmoreVert > 0 then
  188.      love.graphics.draw(sprites.fallLeft, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  189.      elseif gilmoreHoriz < 0 and gilmoreVert < 0 then
  190.      love.graphics.draw(sprites.upLeft, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  191.      elseif gilmoreHoriz > 0 and gilmoreVert < 0  then
  192.      love.graphics.draw(sprites.upRight, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 4, 4, 0, 0, 0, 0)
  193.      end
  194.     elseif freakout == 1 then
  195.      love.graphics.draw(sprites.headOn, objects.gilmore.body:getX(), objects.gilmore.body:getY(), 0, 1, 1, 0, 0, 0, 0)
  196.     end
  197. -- Gilmore Animation Core End
  198.     camera:unset()
  199.   elseif room == 0 then
  200.     timer1 = (.969 + timer1)
  201.     if timer1 < 255 then
  202.       love.graphics.setColor(timer1, timer1, timer1)
  203.       love.graphics.setBackgroundColor(timer1, timer1,timer1)
  204.       love.graphics.draw(images.logo, 284.468, 0, 0, 1.337, 1.337, 0, 0, 0, 0)
  205.     elseif timer1 > 255 and timer1 < 510 then
  206.       love.graphics.setBackgroundColor(0, 0, 0)
  207.       love.graphics.setColor(timer1-255, timer1-255, timer1-255)
  208.       love.graphics.draw(images.logo2, 262.5, 0, 0, 1.32, 1.32, 0, 0, 0, 0)
  209.     elseif timer1 > 510 and timer1 < 765 then
  210.       love.graphics.setColor(timer1-510, timer1-510, timer1-510)
  211.       love.graphics.draw(images.logo3, 0, 0, 0, 2.344, 2.344, 0, 0, 0, 0)
  212.     elseif timer1 > 765 and timer1 < 850 then
  213.     love.graphics.draw(images.logo3, 0, 0, 0, 2.344, 2.344, 0, 0, 0, 0)
  214.     elseif timer1 > 850 then
  215.       room = 1
  216.     end
  217.   elseif room == 1 then
  218.       love.graphics.setColor(255, 255, 255)
  219.       love.graphics.draw(images.main, 0, 0, 0, 1, 1, 0, 0, 0, 0)
  220.       love.graphics.draw(images.main2, 350, 200, 0, 1.5, 1.5, 0, 0, 0, 0)
  221.       love.graphics.setColor(animTimer, animTimer, animTimer)
  222.       love.graphics.draw(images.main3, 450, 350, 0, 1, 1, 0, 0, 0, 0)
  223.   end
  224.   if room == 2 then
  225.       if timer1 <= 255 and timer1 > 0 then
  226.       love.graphics.setColor(timer1, timer1, timer1)
  227.       love.audio.setVolume(timer1/255)
  228.       love.graphics.draw(images.main, 0, 0, 0, 1, 1, 0, 0, 0, 0)
  229.       love.graphics.draw(images.main2, 350, 200, 0, 1.5, 1.5, 0, 0, 0, 0)
  230.       love.graphics.draw(images.main3, 450, 350, 0, 1, 1, 0, 0, 0, 0)
  231.       timer1 = (timer1 - 1)
  232.       elseif timer1 == 0 then
  233.       room = 3
  234.       love.graphics.setBackgroundColor(100, 100, 100)
  235.       love.audio.stop(music.intro)
  236.       love.audio.setVolume(1)
  237.       timer1 = 400
  238.       love.audio.play(sounds.street)
  239.       camera.y = -200
  240.       end
  241.   end
  242. end
  243. -- Camera Core Start
  244. camera = {}
  245. camera.x = 0
  246. camera.y = 0
  247. camera.scaleX = 1
  248. camera.scaleY = 1
  249. camera.rotation = 0
  250. function camera:set()
  251.   love.graphics.push()
  252.   love.graphics.rotate(-self.rotation)
  253.   love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
  254.   love.graphics.translate(-self.x, -self.y)
  255. end
  256. function camera:unset()
  257.   love.graphics.pop()
  258. end
  259. function camera:move(dx, dy)
  260.   self.x = self.x + (dx or 0)
  261.   self.y = self.y + (dy or 0)
  262. end
  263. function camera:rotate(dr)
  264.   self.rotation = self.rotation + dr
  265. end
  266. function camera:scale(sx, sy)
  267.   sx = sx or 1
  268.   self.scaleX = self.scaleX * sx
  269.   self.scaleY = self.scaleY * (sy or sx)
  270. end
  271. function camera:setPosition(x, y)
  272.   self.x = x or self.x
  273.   self.y = y or self.y
  274. end
  275. function camera:setScale(sx, sy)
  276.   self.scaleX = sx or self.scaleX
  277.   self.scaleY = sy or self.scaleY
  278. end
  279. -- Camera Core End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement