-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
56 lines (49 loc) · 1.44 KB
/
main.lua
File metadata and controls
56 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local snake = require("snake")
local map = require("map")
local fruit = require("fruit")
local win_Size = love.graphics.getWidth()
local counter = 0
local updateTick = 10
function love.load()
love.window.setPosition(640, 180)
map.load(50, 50, win_Size)
fruit.random_Point(map)
end
function love.update(dt)
counter = counter + 1
if counter % updateTick == 0 then
--print(snake.x)
--print(snake.y)
--print(snake.cords[1])
--print(snake.cords[2])
snake.tick(map)
end
if snake.x == pos_X and snake.y == pos_Y then
fruit.random_Point(map)
snake.tail_length = snake.tail_length + 1
table.insert(snake.tail, {0, 0})
end
if snake.x == snake.cords[1] and snake.y == snake.cords[2] then
snake.restart()
fruit.random_Point(map)
end
end
function love.draw()
snake.draw(map)
fruit.draw(map)
map.draw(snake)
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
end
if key == "w" or key == "up" and snake.dir_Y == 0 then
snake.changeDir(0, -1)
elseif key == "s" or key == "down" and snake.dir_Y == 0 then
snake.changeDir(0, 1)
elseif key == "a" or key == "left" and snake.dir_X == 0 then
snake.changeDir(-1, 0)
elseif key == "d" or key == "right" and snake.dir_X == 0 then
snake.changeDir(1, 0)
end
end