-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
119 lines (103 loc) · 2.71 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
Railgun = {
Const = {
Category = {
player = 2,
enemy = 3,
bullet = 4,
wall = 5,
effect = 6,
grenade = 7,
},
},
Config = {
debug = false,
Enemy = {
Generate = true,
Max = 30,
},
Bonus = {
Generate = true,
Max = 1,
},
}
}
require('ulits')
class = require('30log')
require('GameObject')
require('World')
require('Player')
require('Bullet')
require('Enemy')
require('Map')
require('Grenade')
local mouse = {x = 0, y = 0}
local edgePoint = {x = 0, y = 0}
function love.load(arg)
if arg[#arg] == "-debug" then
require("mobdebug").start()
Railgun.Config.debug = true
end
love.graphics.setPointSize(2)
world = World:create()
if Railgun.Config.debug then
world.debug = {}
end
world:init({mapPath = 'res/map/stage2'})
end
local num = 0
function love.update(dt)
local player = world.player
if player.alive then
world:update(dt)
end
--[[
--edgePoint = updateEdgePoint()
]]--
end
function love.draw()
love.graphics.push('all')
world:draw()
love.graphics.pop()
local player = world.player
--love.graphics.print(love.timer.getFPS())
--love.graphics.print(string.format("%.1f", player.pos.x)..','..string.format("%.1f", player.pos.y))
--drawAimLine()
if not player.alive then
love.graphics.push('all')
love.graphics.setColor(255, 255, 0, 255)
love.graphics.print('Game Over', love.graphics.getWidth()/2, love.graphics.getHeight()/2, 0, 2, 2, 37, 7)
love.graphics.pop()
else
if world.pause then
love.graphics.push('all')
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print('Pause', love.graphics.getWidth()/2, love.graphics.getHeight()/2, 0, 2, 2, 37, 7)
love.graphics.pop()
else
local stats = love.graphics.getStats()
love.graphics.push('all')
love.graphics.print('HP:'.. player.hp .. '/100' .. ' | AMMO:' .. player.weapon.ammo .. '/' .. player.weapon.maxAmmo .. ' | Enemies:' .. world.enemyCount .. ' | FPS:' .. love.timer.getFPS() .. "\nDrawcalls: "..stats.drawcalls.."\nUsed VRAM: "..string.format("%.2f MB", stats.texturememory / 1024 / 1024), 0, 0)
love.graphics.pop()
end
end
end
function love.keypressed(key, isRepeat)
if key == 'escape' then
world.pause = not world.pause
end
if key == 'g' then
local x, y = world:mousePos()
local grenade = Grenade:new(world.physics, world.player.pos.x, world.player.pos.y)
world:add(grenade)
grenade:throw(x, y)
end
end
function love.resize( w, h )
if world.light then
world.light:refreshScreenSize()
end
end
--画瞄准线
local function drawAimLine()
love.graphics.line(player.pos.x, player.pos.y, edgePoint.x, edgePoint.y)
end