Advertisement
reqdqwdqwdq

Untitled

Jun 19th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. Renderer = require "tools.renderer"
  2. GameLoop = require "tools.gameLoop"
  3. rect = require "objects.rect"
  4. entity = require "objects.entity"
  5. Vec2 = require "tools.vec2"
  6. anim8 = require "libraries.anim8"
  7. bump = require "bump"
  8.  
  9. love.graphics.setDefaultFilter( "nearest" )
  10.  
  11. renderer = Renderer:create()
  12. gameLoop = GameLoop:create()
  13.  
  14. g_Width = love.graphics.getWidth()
  15. g_Height = love.graphics.getHeight()
  16.  
  17. g_GameTime = 0
  18.  
  19. local ent = entity:new(32,32,64,64,"Player")
  20.  
  21. local fps = 30
  22.  
  23. local world = bump.newWorld(50)
  24.  
  25. local A = {name = "A"}
  26.  
  27. world:add(A, 300, 26, 400, 91)
  28.  
  29. function ent:load()
  30. gameLoop:addLoop(self)
  31. tlm:load()
  32. end
  33.  
  34. function ent:tick(dt)
  35. print(self.id)
  36. end
  37.  
  38. local player = {}
  39.  
  40. player.y = {}
  41.  
  42. rightpicframes = {}
  43.  
  44. leftpicframes = {}
  45.  
  46. crouchpicframes = {}
  47.  
  48. standing = true
  49.  
  50. facing = false
  51.  
  52. crouching = false
  53.  
  54. function love.load()
  55. frames = {}
  56.  
  57. Lframes = {}
  58. for i = 2,7 do
  59. table.insert(rightpicframes,love.graphics.newImage("characters/sonic" .. i .. ".png"))
  60. end
  61.  
  62. for ii = 2,7 do
  63. table.insert(leftpicframes,love.graphics.newImage("characters/sonicflip" .. ii .. ".png"))
  64. end
  65.  
  66. playerimg = rightpicframes[1]
  67. playerimg = leftpicframes[1]
  68. playerimg = crouchpicframes[1]
  69.  
  70. nxtframe = 1
  71. player.y_velocity = 1
  72. player.jump_height = -200
  73. player.gravity = -500
  74. player.speed = 200
  75. player.x = g_Width / 2
  76. player.y = g_Height / 2.3
  77. player.ground = player.y
  78. myImg = love.graphics.newImage("Assets/bg.png")
  79. stage = love.graphics.newImage("Assets/mainstage.png")
  80. player.img = love.graphics.newImage("characters/sonic.png")
  81. crouch = love.graphics.newImage("characters/soniccrouch1.png")
  82. end
  83. thetimer = 0.1
  84.  
  85. tspeed = 200
  86.  
  87. -- its something here
  88. function love.update(dt)
  89. standing = true
  90.  
  91. if player.y_velocity ~= 0 then
  92. player.y = player.y + player.y_velocity * dt
  93. player.y_velocity = player.y_velocity - player.gravity * dt
  94. end
  95. if player.y > player.ground then
  96. player.y_velocity = 0
  97. player.y = player.ground
  98. end
  99. if love.keyboard.isDown('space') then
  100. if player.y_velocity == 0 then
  101. player.y_velocity = player.jump_height
  102. end
  103. end
  104. g_GameTime = g_GameTime + dt
  105. -- the game thinks im holding d
  106. if love.keyboard.isDown('d') and not crouching then
  107. player.x = player.x + tspeed * dt
  108. facing = false
  109. standing = false
  110. end
  111. if thetimer > 0.1 then
  112. nxtframe = nxtframe + 1
  113. thetimer = 0
  114. end
  115. if nxtframe > 8 then
  116. nxtframe = 1
  117. -- thats the d button press ^
  118. elseif love.keyboard.isDown('a') and not crouching then
  119. facing = true
  120. standing = false
  121. player.x = player.x - tspeed * dt
  122. end
  123.  
  124. thetimer = thetimer + dt
  125. if thetimer > 0.1 then
  126. nxtframe = nxtframe + 1
  127. thetimer = 0
  128. if nxtframe > 4 then
  129. nxtframe = 1
  130. end
  131. end
  132. if love.keyboard.isDown('lctrl') then
  133. standing = false
  134. crouching = true
  135. else
  136. crouching = false
  137. end
  138. function love.draw()
  139. love.graphics.rectangle("line",205,160,400,200)
  140. love.graphics.draw(myImg,0,0)
  141. love.graphics.draw(stage,200,26)
  142. love.graphics.print("FPS: "..tostring(love.timer.getFPS( )).."\nFACING: "..tostring(facing).."\nSTANDING: "..tostring(standing).."\nCROUCHING: "..tostring(crouching))
  143. if colliding then
  144. print("Collision Detected")
  145. end
  146. if standing then
  147. if facing == true then
  148. love.graphics.draw(player.img, player.x + 32, player.y, 0, -1, 1, 0, 32)
  149. elseif facing == false then
  150. love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 0, 32)
  151. end
  152. elseif crouching then
  153. if facing == true then
  154. love.graphics.draw(crouch, player.x + 32, player.y, 0, -1, 1, 0, 32)
  155. elseif facing == false then
  156. love.graphics.draw(crouch, player.x, player.y, 0, 1, 1, 0, 32)
  157. end
  158. else
  159. if facing == true then
  160. love.graphics.draw(leftpicframes[nxtframe], player.x, player.y, 0, 1, 1, 0, 32)
  161. elseif facing == false then
  162. love.graphics.draw(rightpicframes[nxtframe], player.x, player.y, 0, 1, 1, 0, 32)
  163. end
  164. end
  165. end
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement