-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
166 lines (143 loc) · 3.54 KB
/
Copy pathmain.lua
File metadata and controls
166 lines (143 loc) · 3.54 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
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
flux = require "lib/flux"
myfont = love.graphics.newFont("res/MSYH.TTC", 23)
love.graphics.setFont(myfont)
function love.load()
test = {
x = 400, --屏幕中央
y = 300,
speed = 5,
w = false,
s = false,
a = false,
d = false,
direct = 'd',
-- jump = false,
image = love.graphics.newImage("res/ball.png"),
show = true
}
bullet = {
x = 0,
y = 0,
w = 2,
h = 2,
speed = 10,
image = love.graphics.newImage("res/ball.png"),
}
end
function creat()
bullet.x = test.x
bullet.y = test.y
love.graphics.draw(bullet.image, bullet.x, bullet.y - 16, 0, 1, 1, bullet.w, bullet.h)
end
function love.draw()
init()
end
function init()
love.graphics.print('WSAD上下左右,J跳跃,-和+改变速度', 100, 100)
love.graphics.print(('方块当前位置x:%d,y:%d,速度:%d'):format(test.x, test.y, test.speed), 100, 126)
love.graphics.setColor(255, 255, 255, 255)
if test.show == true then
print('233')
d()
end
--love.graphics.draw(test.image,test.x - 32,test.y - 32)
love.graphics.setColor(255, 0, 0, 255)
love.graphics.draw(bullet.image, bullet.x, bullet.y, 0, 1, 1, bullet.w, bullet.h)
end
function d()
love.graphics.draw(test.image, test.x, test.y, 0, 1, 1, 32, 32)
end
function love.update(dt)
flux.update(dt)
if love.keyboard.isDown("w") then
test.w = true
test.direct = 'w'
end
if love.keyboard.isDown("s") then
test.s = true
test.direct = 's'
end
if love.keyboard.isDown("a") then
test.a = true
test.direct = 'a'
end
if love.keyboard.isDown("d") then
test.d = true
test.direct = 'd'
end
if love.keyboard.isDown("=") then
test.speed = test.speed + 1
end
if love.keyboard.isDown("-") then
test.speed = test.speed - 1
end
move()
bulletmove()
end
function bulletmove()
bullet.x = bullet.x + bullet.speed
end
function move()
if (not test.w) and (not test.s) and (not test.a) and (not test.d) then
return
end
if test.w then
test.y = test.y - test.speed
end
if test.s then
test.y = test.y + test.speed
end
if test.a then
test.x = test.x - test.speed
end
if test.d then
test.x = test.x + test.speed
end
end
function love.keyreleased(key)
if key == "j" then
if not test.jump then
flux.to(test, 0.3, { y = test.y - 100 })
:onstart(
function()
test.jump = true
end
)
:oncomplete(
function()
flux.to(test, 0.3, { y = test.y + 100 })
:oncomplete(
function()
test.jump = false
end
)
end
)
end
print('j')
end
if key == "k" then
-- creat()
test.show = false
print('k')
end
if key == "w" then
test.w = false
end
if key == "s" then
test.s = false
end
if key == "a" then
test.a = false
end
if key == "d" then
test.d = false
end
end
function bullet()
end
function a7(func)
func()
end
function love.mousepressed(x, y, key) --回调函数释放鼠标按钮时触发。
end