-
Notifications
You must be signed in to change notification settings - Fork 1
/
demostate.lua
119 lines (97 loc) · 2.99 KB
/
demostate.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
-- demostate
demostate = {}
-- entities
local Player = require "src.entities.Player"
local Enemy = require "src.entities.Enemy"
local EnemyWalkerShooter = require "src.entities.EnemyWalkerShooter"
local Spawner = require "src.entities.Spawner"
local Water = require "src.entities.Water"
local UIImage = require "src.entities.UIImage"
-- libs
local HClib = require "lib.hc"
local player
local uiScore
local score = 0
HC = nil
local assets = require "src.assets"
local spawner
function demostate:enter()
HC = HClib.new(150)
player = Player()
timer.clear()
score = 0
self.setupExplosionSmokeParticles()
self.world = tiny.world(
require("src.systems.BGColorSystem")(32,70,49),
require("src.systems.UpdateSystem")(),
require("src.systems.DrawSystem")(),
require("src.systems.MoveTowardsAngleSystem")(),
require("src.systems.MoveTowardsTargetSystem")(),
require("src.systems.CollisionSystem")(),
require("src.systems.MovableSystem")(),
require("src.systems.ShooterSystem")(),
require("src.systems.DestroyOffScreenSystem")(),
require("src.systems.SpriteSystem")(),
require("src.systems.DrawUISystem")("hudForeground"),
UIImage(assets.level160, 0, 0),
player,
UIImage(assets.titlesmall, "center", 20, 1,1)
)
spawner = Spawner()
world = self.world
world:add(spawner)
-- add water
for i=math.floor(push:getWidth()/12),0,-1
do
world:add(Water(12 * i,120))
end
-- timer.after(0.8, function() switchPalette() end)
end
function demostate:update(dt)
if love.keyboard.isDown("q") then
Gamestate.switch(menustate)
end
smokePs:update(dt)
end
function demostate:setupExplosionSmokeParticles()
smokePs = love.graphics.newParticleSystem(assets.smoke, 100)
smokePs:setPosition(push:getWidth()/2, push:getHeight()/2)
smokePs:setParticleLifetime(0.5, 1.2)
smokePs:setDirection(1.5*3.14)
smokePs:setSpread(3.14/3)
smokePs:setSpeed(10, 800)
smokePs:setLinearAcceleration(0, -600)
smokePs:setLinearDamping(50)
smokePs:setSpin(0, 30)
smokePs:setColors(82, 127, 57, 255);
smokePs:setRotation(0, 2*3.14)
smokePs:setSizes(.5, 0)
smokePs:setInsertMode('random')
end
function demostate:draw()
PaletteSwitcher:set()
push:apply("start")
love.graphics.draw(smokePs, 0, 0, 0, 1, 1)
push:apply("end")
PaletteSwitcher:set()
love.graphics.setColor(215,232,148)
-- love.graphics.setFont(assets.font_sm)
love.graphics.printf("BY SUPERNAUGHT", 0, love.graphics.getHeight()-50, love.graphics.getWidth()/2, "center", 0, 2, 2)
-- love.graphics.printf(score, 0, 30, love.graphics.getWidth()/2, "center", 0, 2, 2)
-- love.graphics.print("FPS: " .. tostring(love.timer.getFPS()) .. "\nEntities: " .. world:getEntityCount(), 5, 5)
PaletteSwitcher:unset()
end
function demostate.getPlayer()
return player
end
function demostate.addScore(n)
score = score + (n or 1)
if score % 20 == 0 then
world:add(EnemyWalkerShooter())
end
if score % 10 == 0 and score < 50 then
-- spawner.spawnDelayMin = spawner.spawnDelayMin - 0.03
-- spawner.spawnDelayMax = spawner.spawnDelayMax - 0.12
end
end
return demostate