-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
205 lines (182 loc) · 6 KB
/
main.lua
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
anim8 = require 'anim8'
function love.load(arg)
width = love.graphics.getWidth()
height = love.graphics.getHeight()
-- loads the two backgrounds and the player
backgroundimg = love.graphics.newImage('assets/background.jpg')
playerFrameX = 250
playerFrameY = 120
local playerImage = love.graphics.newImage('assets/idle.png')
flyingImage = love.graphics.newImage('assets/flying.png')
local g = anim8.newGrid(playerFrameX, playerFrameY, playerImage:getWidth(), playerImage:getHeight())
animation = anim8.newAnimation(g(1,'1-60', 1, '60-1'), (1 / 25))
bunnyImg = love.graphics.newImage('assets/bunny.png')
offsetX = playerFrameX / 2
offsetY = playerFrameY / 2
player = {
x = offsetX,
y = 504,
image = playerImage,
heading = 0,
velX = 1,
velY = 1,
acceleration = 20,
}
win = false
lose = false
startingX = player.x
startingY = player.y
--set the count
--set the count
mousepos = 0
jump = false
firstloop = true
launchvel = 0
mousex = 1
mousey = 1
angledeg = 0
love.graphics.setNewFont(30)
end
--draws the objects we loaded above and prints the info I want
function love.draw(dt)
love.graphics.draw(backgroundimg)
animation:draw(player.image, player.x, player.y, 0, 1, 1, offsetX, offsetY)
love.graphics.print("https://github.com/spantz/rocket-fox", 10, 0)
if win then
love.graphics.print("KILLED THAT BASTARD", 650, 20)
else
love.graphics.draw(bunnyImg, 900, 500)
end
if lose then
love.graphics.print("Missed, Idiot", 650, 20)
end
-- love.graphics.print("X Mouse Position: " .. xmousepos, 200, 20)
-- love.graphics.print("Y Mouse Position: " .. ymousepos, 200, 40)
-- love.graphics.print("End x Pos: " .. mousex, 200, 60)
-- love.graphics.print("End y Pos: " .. mousey, 200, 80)
-- love.graphics.print("Velocity: " .. velocity, 200, 100)
-- love.graphics.print("Angle: " .. angle, 200, 120)
-- love.graphics.print("Xposition: " .. player.x, 350, 20)
-- love.graphics.print("Yposition: " .. player.y, 350, 40)
-- love.graphics.print("Heading : " .. player.heading, 350, 60)
--
-- love.graphics.print("LaunchVel: " .. launchvel, 650, 20)
-- love.graphics.print("Yvel: " .. player.velY, 650, 50)
-- love.graphics.print("xvel: " .. player.velX, 650, 70)
-- love.graphics.print("degangle: " .. degangle, 650, 90)
--
-- if jump then
-- love.graphics.print("Jumping", 50, 210)
-- end
--
-- love.graphics.line(startingX, startingY, mousex, mousey)
end
-- Updating
-- function love.update(dt)
-- animation:update(dt)
-- -- I always start with an easy way to exit the game
-- if love.keyboard.isDown('escape') then
-- love.event.push('quit')
-- end
--
-- xmousepos = love.mouse.getX()
-- ymousepos = love.mouse.getY()
--
-- velocity = (math.dist(offsetX,offsetY,mousex,mousey))
-- angle = (math.angle(offsetX,offsetY,mousex,mousey))
--
-- degangle = math.deg(angle)
--
-- if jump then
-- player.img = love.graphics.newImage('assets/flying.png')
--
-- -- radsin = math.sin(angle)
-- -- degsin = math.deg(radsin)
-- --
-- -- radcos = math.cos(angle)
-- -- degcos = math.deg(radcos)
--
-- if firstloop then
-- player.velY = 3*(startingY - mousey)
-- player.velX = 2*(mousex - startingX)
-- firstloop = false
-- else
-- player.velY = player.velY + (-1500 * dt)
--
-- -- player.velX = (radsin * player.acceleration * dt)
-- -- player.velY = (radcos * -player.acceleration * dt)
--
-- -- player.velX = (player.velX * player.acceleration * dt)
-- -- player.velY = (player.velY * -player.acceleration * dt)
-- moveFox(dt)
-- end
--
-- end
-- end
function love.update(dt)
animation:update(dt)
-- I always start with an easy way to exit the game
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
xmousepos = love.mouse.getX()
ymousepos = love.mouse.getY()
velocity = (math.dist(offsetX,offsetY,mousex,mousey))
angle = (math.angle(offsetX,offsetY,mousex,mousey))
degangle = math.deg(angle)
if jump then
player.img = love.graphics.newImage('assets/flying.png')
if looping then
player.velY = player.velY + (-1500 * dt)
moveFox(dt)
if player.y > 550 then
looping = false
done = true
end
end
if firstloop then
player.velY = 3*(startingY - mousey)
player.velX = 3*(mousex - startingX)
startingVelY = player.velY
if player.velX < 800 then
player.velX = player.velX
elseif player.velX > 800 then
player.velX = 800
end
if player.velY < 1000 then
player.velY = player.velY
elseif player.velY > 1000 then
player.velY = 1000
end
firstloop = false
looping = true
end
end
if done then
if player.x > 700 and player.x < 1050 then
win = true
else
lose = true
end
end
end
function moveFox(dt)
player.x = player.x + player.velX * dt
player.y = (player.y - player.velY * dt)
end
--gets the position of mouse release
function love.mousereleased(x, y, button)
if button == 1 then
print('MOUSE RELEASE')
mousex = x
mousey = y
jump = true
player.image = flyingImage
newG = anim8.newGrid(playerFrameX, playerFrameY, player.image:getWidth(), player.image:getHeight())
animation = anim8.newAnimation(newG(1,'1-60'), (1 / 120), 'pauseAtEnd')
end
end
function math.angle(x1,y1, x2,y2) return math.atan2(y2-y1, x2-x1) end
function math.dist(x1,y1, x2,y2)
return ((x2-x1)^2+(y2-y1)^2)^0.5
end