-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
61 lines (48 loc) · 1.49 KB
/
player.lua
File metadata and controls
61 lines (48 loc) · 1.49 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
57
58
59
60
61
---@diagnostic disable: lowercase-global, undefined-global
constants = require 'constants'
SHIP_SPEED = 200
playerScore = 0;
playerY = VIRTUAL_HEIGHT / 2 + 100
playerX = VIRTUAL_WIDTH / 2 - 25
-- drawing player ship
function drawPlayer()
love.graphics.setColor(BLUE)
drawShip('line', playerX + 25, playerY + 10)
if playerX < 50 then
drawShip('line', playerX + VIRTUAL_WIDTH + 25, playerY + 10)
elseif playerX > VIRTUAL_WIDTH - 50 then
drawShip('line', playerX - VIRTUAL_WIDTH + 25, playerY + 10)
end
end
function handleMovement(dt)
if love.keyboard.isDown('left') then
playerX = playerX - SHIP_SPEED * dt
elseif love.keyboard.isDown('right') then
playerX = playerX + SHIP_SPEED * dt
end
handleBoundaries()
end
function handleBoundaries()
playerX = (playerX + VIRTUAL_WIDTH) % VIRTUAL_WIDTH
end
function drawShip(mode, x, y)
local w1 = math.atan(2 / 5)
local w2 = math.atan(5 / 5)
local k1 = math.sqrt(4 + 25)
local k2 = math.sqrt(25 + 25)
local a = 10
local b = a * math.tan(w1 / 2)
local c = a * math.tan(k1 / 2)
local d = a * math.tan(k2 / 2)
local vertices = {
a, b, c, d, d, c, b, a,
-b, a, -d, c, -c, d, -a, b,
-a, -b, -c, -d, -d, -c, -b, -a,
b, -a, d, -c, c, -d, a, -b
}
love.graphics.push()
love.graphics.translate(x + 0.4, y + 0.4)
love.graphics.polygon('line', vertices)
love.graphics.translate(-x - 0.4, -y - 0.4)
love.graphics.pop()
end