this repo has no description
1package;
2
3import flixel.FlxCamera.FlxCameraFollowStyle;
4import flixel.FlxG;
5import flixel.FlxObject;
6import flixel.FlxSprite;
7import flixel.FlxState;
8import flixel.addons.editors.ogmo.FlxOgmoLoader;
9import flixel.group.FlxGroup.FlxTypedGroup;
10import flixel.math.FlxMath;
11import flixel.math.FlxRect;
12import flixel.text.FlxText;
13import flixel.tile.FlxTilemap;
14import flixel.tweens.FlxEase;
15import flixel.tweens.FlxTween;
16import flixel.ui.FlxButton;
17import flixel.util.FlxColor;
18
19class PlayState extends FlxState
20{
21 private var _player:Player;
22 private var playerBullets:FlxTypedGroup<Bullet>;
23
24 private var _enemy:Enemy;
25 private var _enemyThoughts:FlxTypedGroup<Thoughts>;
26
27 private var _map:FlxOgmoLoader;
28 private var _mWalls:FlxTilemap;
29
30 private var _grpPeople:FlxTypedGroup<FlxSprite>;
31 private var _grpEnemies:FlxTypedGroup<Enemy>;
32 private var _grpText:FlxTypedGroup<FlxText>;
33
34 private var wasdTxt:FlxText;
35 private var _txtShoot:FlxText;
36
37 override public function create():Void
38 {
39 FlxG.mouse.visible = false;
40 FlxG.camera.bgColor = FlxColor.GRAY;
41 FlxG.camera.fade(FlxColor.BLACK, 5, true);
42 FlxG.sound.playMusic("assets/music/ambience.ogg", 0.5);
43
44 _map = new FlxOgmoLoader(AssetPaths.level1__oel);
45 _mWalls = _map.loadTilemap(AssetPaths.tiles__png, 32, 32, "Floors");
46 _mWalls.setTileProperties(1, FlxObject.ANY);
47 add(_mWalls);
48
49 _grpPeople = new FlxTypedGroup<FlxSprite>();
50 add(_grpPeople);
51
52 _grpEnemies = new FlxTypedGroup<Enemy>();
53 add(_grpEnemies);
54
55 _grpText = new FlxTypedGroup<FlxText>();
56 add(_grpText);
57
58 playerBullets = new FlxTypedGroup<Bullet>();
59 add(playerBullets);
60
61 _enemyThoughts = new FlxTypedGroup<Thoughts>();
62 add(_enemyThoughts);
63
64 _player = new Player(20, 300, playerBullets);
65 _grpPeople.add(_player);
66
67 _map.loadEntities(placeEntities, "entities");
68
69 FlxG.worldBounds.setSize(10000, 10000);
70
71 wasdTxt = new FlxText(_player.x - 64, _player.y - 100, 0, "A & D == Move", 16);
72 add(wasdTxt);
73
74 _txtShoot = new FlxText(170, 720, 0, "Spacebar to shoot", 16);
75 add(_txtShoot);
76 _txtShoot.visible = false;
77
78 var barHeight:Float = 50;
79
80 var cinemaBar:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, Std.int(barHeight), FlxColor.BLACK);
81 // add(cinemaBar);
82 var cinemaBar2:FlxSprite = new FlxSprite(0, FlxG.height - barHeight).makeGraphic(FlxG.width, Std.int(barHeight), FlxColor.BLACK);
83 // add(cinemaBar2);
84
85 cinemaBar.scrollFactor.x = cinemaBar.scrollFactor.y = 0;
86 cinemaBar2.scrollFactor.x = cinemaBar2.scrollFactor.y = 0;
87
88 FlxG.camera.follow(_player, FlxCameraFollowStyle.SCREEN_BY_SCREEN, 0.25);
89 FlxG.camera.snapToTarget();
90 FlxG.camera.deadzone = FlxRect.get(0, cinemaBar.height, FlxG.width, cinemaBar2.y);
91
92 _grpPeople.forEach(initPeople);
93 _grpEnemies.forEach(initPeople);
94
95 var vig:FlxSprite = new FlxSprite().loadGraphic("assets/images/vignetteresized.png", false, 640, 480);
96 vig.scrollFactor.x = vig.scrollFactor.y = 0;
97 vig.setGraphicSize(FlxG.width, FlxG.height);
98 vig.updateHitbox();
99 vig.alpha = 0.4;
100 add(vig);
101
102 super.create();
103 }
104
105 private function placeEntities(entityName:String, entityData:Xml):Void
106 {
107 var x:Int = Std.parseInt(entityData.get("x"));
108 var y:Int = Std.parseInt(entityData.get("y"));
109 if (entityName == "player")
110 {
111 _player.x = x;
112 _player.y = y;
113 }
114 else if (entityName == "enemy")
115 {
116 var enemy:Enemy = new Enemy(x, y, playerBullets);
117 _grpEnemies.add(enemy);
118 }
119 else if (entityName == "text")
120 {
121 var textSpr:FlxText = new FlxText(x, y, 0, Std.string(entityData.get("displayText")), 32);
122 textSpr.color = FlxColor.WHITE;
123 _grpText.add(textSpr);
124 }
125 }
126
127 private function initPeople(p:FlxSprite):Void
128 {
129 p.acceleration.y = 600;
130 }
131
132 override public function update(elapsed:Float):Void
133 {
134 super.update(elapsed);
135 /*
136 if (_player.x >= _txtShoot.x)
137 {
138 _txtShoot.visible = true;
139 wasdTxt.visible = false;
140 }
141 */
142 if (_player.justShot)
143 {
144 var flash:MuzzleFlash = new MuzzleFlash(_player.xPos, _player.y + 26);
145 add(flash);
146
147 FlxG.camera.shake(0.01, 0.1);
148 }
149
150 playerBullets.forEachAlive(collisionCheck);
151
152 FlxG.collide(_grpPeople, _mWalls);
153 FlxG.collide(_grpEnemies, _mWalls);
154
155 _grpEnemies.forEachAlive(followCheck);
156
157 if (_player.y >= 1800 && !finalLevel)
158 {
159 finalLevel = true;
160 FlxG.camera.fade(FlxColor.WHITE, 0.05, false, finalFade);
161 FlxG.sound.play("assets/sounds/colorSwap.ogg", 0.8);
162 FlxG.sound.music.stop();
163 }
164 }
165
166 private var finalLevel:Bool = false;
167
168 private function enemyThink(e:Enemy, ?textOverride:String):Void
169 {
170 e.justThought = true;
171
172 FlxG.sound.play("assets/sounds/pop" + FlxG.random.int(1, 3) + ".ogg", FlxG.random.float(0.5, 0.7));
173
174 var thoughtText:String;
175
176 if (e.finalSection)
177 {
178 thoughtText = thoughtArray[FlxG.random.int(0, thoughtArray.length)];
179 }
180 else
181 {
182 if (e.color == FlxColor.WHITE)
183 {
184 thoughtText = "insert same opinion here";
185 }
186 else
187 {
188 thoughtText = "insert different opinion here";
189 }
190 }
191
192 var thought:Thoughts = new Thoughts(e.x + FlxG.random.float(-100, 100), e.y - FlxG.random.float(10, 100), 150, thoughtText, 16);
193 add(thought);
194
195 if (e.finalSection)
196 {
197 thought.color = FlxColor.BLACK;
198 }
199
200 if (textOverride != null)
201 {
202 thought.text = textOverride;
203 }
204
205 FlxTween.tween(thought, {y: thought.y - FlxG.random.float(8, 15)}, 1.25, {ease: FlxEase.quartOut});
206 }
207
208 private function followCheck(e:Enemy):Void
209 {
210 e.acceleration.x = 0;
211 if (!e.finalSection)
212 {
213 if (e.y > _player.y && e.velocity.y == 0 && e.color == FlxColor.WHITE)
214 {
215 e.velocity.y -= 360;
216 }
217
218 if (e.color == FlxColor.WHITE)
219 {
220 if (FlxMath.distanceBetween(e, _player) >= e.rndDistance)
221 {
222 var accel:Float = e.rndAccel;
223 if (e.x > _player.x)
224 {
225 e.acceleration.x = -accel;
226 }
227 else
228 {
229 e.acceleration.x = accel;
230 }
231 }
232 }
233 }
234
235 if (FlxMath.distanceBetween(_player, e) < 94 && !e.justThought)
236 {
237 enemyThink(e);
238 }
239 }
240
241 private function collisionCheck(b:Bullet):Void
242 {
243 for (e in _grpEnemies.members)
244 {
245 if (FlxG.overlap(b, e) && e.color != FlxColor.WHITE)
246 {
247 e.hit();
248 e.x += b.velocity.x * FlxG.random.float(0.001, 0.01);
249 muzzFlash(b);
250 }
251 }
252
253 if (FlxG.collide(b, _mWalls))
254 {
255 muzzFlash(b);
256 }
257 }
258
259 private function muzzFlash(b:Bullet):Void
260 {
261 var flash:MuzzleFlash = new MuzzleFlash(b.x, b.y);
262 add(flash);
263
264 b.kill();
265 }
266
267 private function finalFade():Void
268 {
269 FlxG.camera.fade(FlxColor.WHITE, 3, true);
270 FlxG.camera.bgColor = FlxColor.WHITE;
271 _player.color = Enemy.colorArray[FlxG.random.int(0, Enemy.colorArray.length)];
272 FlxG.sound.playMusic("assets/music/SomewhatOKIDKLMAO_V2.ogg", 0.7);
273 FlxG.sound.music.fadeIn(15, 0, 0.7);
274
275 _grpText.forEach(changeColor);
276 }
277
278 private function changeColor(t:FlxText):Void
279 {
280 t.color = FlxColor.BLACK;
281 }
282
283 private var thoughtArray:Array<String> = [
284 "I like anime a lot",
285 "You know some pop music isn't that bad",
286 "Crunchy peanut butter is alright",
287 "Dogs are pretty alright",
288 "Children are cool as hell",
289 "Cats are cool",
290 "Water is really better than soda",
291 "La La Land was a good movie",
292 "Carly Rae Jepsen music is my favourite",
293 "I'm a bit obnoxious online because I'm kinda shy in person",
294 "I envy others success",
295 "I often feel under appreciated",
296 "I don't like watching sports",
297 "I love Newgrounds a LOT",
298 "I feel guilty for not appreciating my heritage",
299 "Videogames are the best",
300 "I haven't watched anime for a while",
301 "I miss my old home sometimes, even though it sucked",
302 "The internet isn't as bad as many claim it is",
303 "insert something political here",
304 "My family is super cool",
305 "Shoutouts to Simpleflips",
306 "What kind of music do you like?",
307 "Wait, this game wasn't about racism?",
308 "I spend too much time on Twitter",
309 "Hip hop, man that stuff's my jam!",
310 "Hifumi from New Game is best waifu",
311 "I don't really like berries",
312 "High school was kinda alright",
313 "Teens are alright",
314 "Dogs are meh",
315 "Buzzfeed is alright nowadays"
316 ];
317}