Advertisement
Ruslan_Isaev

[love2d]--very basic platformer

Oct 30th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. local stage
  2. local groundlvl=-200
  3. function love.load(arg)
  4.   if arg[#arg] == "-debug" then require("mobdebug").start() end
  5.   themeA = love.audio.newSource( "themeA.ogg", "stream")
  6.   themeA:setVolume(0.5)
  7.   perehodSnd=love.audio.newSource("sounds/perehod.ogg","stream")
  8.   love.audio.play(themeA)
  9.   logoImg=love.graphics.newImage("graphics/logo.png")
  10.   stage=0
  11.  
  12.   player = {  
  13.   x = 0,
  14.   y = groundlvl,
  15.   image = love.graphics.newImage("graphics/plr.png"),
  16.   y_velocity = 0,
  17.   }
  18.   gravity = 600
  19.   jump_height = 300
  20.  
  21.   winW, winH = love.graphics.getWidth(), love.graphics.getHeight()  
  22. end
  23. function love.draw()
  24.   if stage==0 then
  25.     love.graphics.draw(logoImg, 0,0)
  26.     love.graphics.print("PRESS  ENTER TO  PLAY!!!!!!!!", 10, 500)
  27.     love.graphics.print("Ruslan  isaev  (c)2015",500,550)
  28.   elseif stage==1 then
  29.     love.graphics.draw(player.image,player.x,-player.y)
  30.     love.graphics.rectangle("fill", 0, winH / 2, winW, winH / 2)-- рисуем землю, используя наши перемнные minW и minH рисуем ее посредине экрана
  31.   love.graphics.translate(winW / 2, winH / 2) -- вам это лучше не знать :]
  32.   end
  33. end
  34. function love.keypressed(key)
  35.   if stage==0 then
  36.     if key=="return" then
  37.       stage=stage+1
  38.     end
  39.   elseif stage==1 then
  40.     if key == "w" then
  41.       if player.y_velocity == 0 then -- мы пробуем узнать, на земле ли герой, если да - прыгаем
  42.         player.y_velocity = jump_height
  43.       end
  44.     end
  45.    
  46.   end
  47.   if key=="escape" then
  48.     exit(1);
  49.   end
  50.  
  51. end
  52.  
  53. function love.update(dt)
  54.   if love.keyboard.isDown("a") then
  55.   player.x = player.x - 150*dt
  56.   end
  57.   if love.keyboard.isDown("d") then
  58.   player.x = player.x + 150*dt
  59.   end
  60.   --тут движение, это мы знаем
  61.   if player.y_velocity ~= 0 then -- если мы прыгаем
  62.   player.y = player.y + player.y_velocity * dt  
  63.   -- изменяем y нашего персонажа
  64.   player.y_velocity = player.y_velocity - gravity * dt
  65.   if player.y < groundlvl then -- мы опять на земле
  66.   player.y_velocity = 0 -- сила равна 0
  67.   player.y = groundlvl -- у = 0
  68.   end
  69.   end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement