-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharactercontroller.lua
More file actions
2058 lines (1736 loc) · 63.1 KB
/
charactercontroller.lua
File metadata and controls
2058 lines (1736 loc) · 63.1 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--rewrite of physics.lua
--player character controller!
require "acca"
require "physics1"
require "buttonaction"
require "GhostingContainer"
position = {}
--physics = {}
jumped = false
stopJump = false
direction = 1
character_controller = {}
--grounded = false
buttonState = {left = false, right = false, jump = false, crouch = false, button1 = nil, button2 = nil}
windowSize = {x = 0,y=0, scale = 1}
windowSize.x, windowSize.y = love.window.getHeight(),love.window.getWidth()
blade_collider = {sprite = nil, x1 = 0, x2= 0, y1 = 0, y2 = 0}
vendorMenu = {}
vendorMenu.interacting = false
vendorMenu.animator = nil
vendorMenu.position = 0
vendorMenu.images = {}
vendorMenu.portrait = nil
coinDropper = {}
coinThing = {x = 0,y = 0,animator = nil,timer = 30}
function coinThing:new(o)
o = o or {}
setmetatable(o,self)
self.__index = self
return o
end
function updateCoinDropper(dt)
for _,coin in ipairs(coinDropper) do
coin.animator:update(dt)
coin.timer = coin.timer - 1
if coin.timer <= 0 then
table.remove(coinDropper,_)
end
end
end
function drawCoinDropper()
for _,coin in ipairs(coinDropper) do
coin.animator:draw(coin.x,coin.y,0,1,1)
end
end
quiver = {}
quiver.arrowMax = 2
quiver.arrows = 2
quiver.arrowQuiver = {}
quiver.fullRecharge = 60
quiver.arrowIcon = nil
quiver.rechargeMax = 80
quiver.rechargeTimer = 80
debugTools = {}
debugTools.deathCounter = 0
debugTools.timer = 0
debugTools.startTimer = 0
-- ditheringString = "// Ordered dithering aka Bayer matrix dithering
-- uniform sampler2D bgl_RenderedTexture;
-- float Scale = 1.0;
-- float find_closest(int x, int y, float c0)
-- {
-- int dither[8][8] = {
-- { 0, 32, 8, 40, 2, 34, 10, 42}, /* 8x8 Bayer ordered dithering */
-- {48, 16, 56, 24, 50, 18, 58, 26}, /* pattern. Each input pixel */
-- {12, 44, 4, 36, 14, 46, 6, 38}, /* is scaled to the 0..63 range */
-- {60, 28, 52, 20, 62, 30, 54, 22}, /* before looking in this table */
-- { 3, 35, 11, 43, 1, 33, 9, 41}, /* to determine the action. */
-- {51, 19, 59, 27, 49, 17, 57, 25},
-- {15, 47, 7, 39, 13, 45, 5, 37},
-- {63, 31, 55, 23, 61, 29, 53, 21} };
-- float limit = 0.0;
-- if(x < 8)
-- {
-- limit = (dither[x][y]+1)/64.0;
-- }
-- if(c0 < limit)
-- return 0.0;
-- return 1.0;
-- }
-- void main(void)
-- {
-- vec4 lum = vec4(0.299, 0.587, 0.114, 0);
-- float grayscale = dot(texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy), lum);
-- vec3 rgb = texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy).rgb;
-- vec2 xy = gl_FragCoord.xy * Scale;
-- int x = int(mod(xy.x, 8));
-- int y = int(mod(xy.y, 8));
-- vec3 finalRGB;
-- finalRGB.r = find_closest(x, y, rgb.r);
-- finalRGB.g = find_closest(x, y, rgb.g);
-- finalRGB.b = find_closest(x, y, rgb.b);
-- float final = find_closest(x, y, grayscale);
-- gl_FragColor = vec4(finalRGB, 1.0);
-- }
-- "
dashTrailTable = {}
dust = {timer = 10, animator = nil, x = 0, y = 0 }
function windowSize:scale(x)
windowSize.x = windowSize.x * x
windowSize.y = windowSize.y * x
windowSize.scale = x
end
local prev_x = 0
local prev_y = 0
function character_controller:new(o)
o = o or {}
setmetatable(o,self)
self.__index = self
return o
end
function character_controller:load(arg, loadPlayer)
--vendorMenu.animator = newCharacter()
vendorMenu.images[0] = love.graphics.newImage("img/Menus/VendorMenu/02.png")
vendorMenu.images[1] = love.graphics.newImage("img/Menus/VendorMenu/03.png")
vendorMenu.images[2] = love.graphics.newImage("img/Menus/VendorMenu/04.png")
vendorMenu.portrait = love.graphics.newImage("assets/doommask.png")
shader = love.graphics.newShader[[
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture,texture_coords);
//vec4 red = (1.0,0.0,0.0,1.0);
pixel.r = 1.0;
pixel.g = 0;
pixel.b = 0;
pixel.a = 0.5*pixel.a;
return pixel;
}]]
-- shader = love.graphics.newShader[[// Ordered dithering aka Bayer matrix dithering
-- uniform sampler2D bgl_RenderedTexture;
-- float Scale = 1.0;
-- float find_closest(int x, int y, float c0)
-- {
-- int dither[8][8] = {
-- { 0, 32, 8, 40, 2, 34, 10, 42}, /* 8x8 Bayer ordered dithering */
-- {48, 16, 56, 24, 50, 18, 58, 26}, /* pattern. Each input pixel */
-- {12, 44, 4, 36, 14, 46, 6, 38}, /* is scaled to the 0..63 range */
-- {60, 28, 52, 20, 62, 30, 54, 22}, /* before looking in this table */
-- { 3, 35, 11, 43, 1, 33, 9, 41}, /* to determine the action. */
-- {51, 19, 59, 27, 49, 17, 57, 25},
-- {15, 47, 7, 39, 13, 45, 5, 37},
-- {63, 31, 55, 23, 61, 29, 53, 21} };
-- float limit = 0.0;
-- if(x < 8)
-- {
-- limit = (dither[x][y]+1)/64.0;
-- }
-- if(c0 < limit)
-- return 0.0;
-- return 1.0;
-- }
-- void main(void)
-- {
-- vec4 lum = vec4(0.299, 0.587, 0.114, 0);
-- float grayscale = dot(texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy), lum);
-- vec3 rgb = texture2D(bgl_RenderedTexture, gl_TexCoord[0].xy).rgb;
-- vec2 xy = gl_FragCoord.xy * Scale;
-- int x = int(mod(xy.x, 8));
-- int y = int(mod(xy.y, 8));
-- vec3 finalRGB;
-- finalRGB.r = find_closest(x, y, rgb.r);
-- finalRGB.g = find_closest(x, y, rgb.g);
-- finalRGB.b = find_closest(x, y, rgb.b);
-- float final = find_closest(x, y, grayscale);
-- gl_FragColor = vec4(finalRGB, 1.0);
-- }
-- ]]
quiver.arrowIcon = love.graphics.newImage('assets/arrowicon.png')
quiver.axeIcon = love.graphics.newImage("img/MainCharacterAnimations/AxeThrow/axe.png")
quiver.bombIcon = love.graphics.newImage("itemimg/Bomb/bomb.png")
quiver.Icon = quiver.axeIcon
for x = 1,quiver.arrowMax do
local arrowItem = {}
arrowItem.usable = true
table.insert(quiver.arrowQuiver,arrowItem)
end
grounded = false
if loadPlayer then
player = {x = 160, y = 110, render_x = 0, render_y = 0, speed = 0, maxSpeed = 120, accelerationFactor = 60, img = nil, rigidbody = nil, state = nil, health = 10, healthMax = 10, hurt = false, hurtTimer = 50, normalAttacking = false, secondSlashTimer = 20, secondSlashing = false, attackSpeed = -1.6, attackAnimSpeed = 1.3, rolling = false, rollTimer = 30, pressingRight = false, pressingLeft = false, pressTimer = 20, getupTimer = 25, getupGroundTriggered = false, bufferAttack =false, bufferedKey = nil, canCharge = true, isChargingAttack = false, chargeMultiplier = 0, charging = false, chargeStrike = false, chargeFillValue = 0, chargeFillMax = 0, chargeFill = nil, offGroundDodge = false, maxFallSpeed = false, coins = 0, nearVendor = false, ammo = 10, ammoMax = 10, dead = false, respawnTimer = 100, respawnPoint = {x = 0,y = 0}, respawnPointTriggered = false, currentSpawnPoint = nil, respawnRoom = nil, nearFire = false}
end
player.img = love.graphics.newImage('img/MainCharacterAnimations/Walk/01.png')
blade_collider.sprite = love.graphics.newImage('img/MainCharacterAnimations/sword_collider.png')
mainCharPortrait = love.graphics.newImage('img/MainCharacterAnimations/maincharportrait.png')
collisions = physics:new()
button = buttonState:new()
button.button1 = button_action:new()
button.button1 = button_action:load("k",dagger_throw,"AxeThrow",shooting)
local meterToPixel = 64 --
gravityIterator = 0
MainCharacterAnim = newCharacter("img","MainCharacterAnimations","png",0.1,"Idle")
playerGhostContainer = GhostingContainer:new()
playerGhostContainer:init(3,.1,MainCharacterAnim,.1,player) -- trail length, spawn rate(lower = faster), animator, effect duration, reference
attackingTimer = 0
attackingFinished = 7
characterState = {buttons = button, collision = collisions, attacking = false, crouchAttack = false, jumping = false, moving = false, hasRing = true, canCrouchAttackWhileMoving = true, wallHanging = false, initiatedPullUp = false, pullUp_y = 0, savedLedgePoint = 0, falling = false, cantKnockBack = false, onOneWayPlatform = false, crouchedThiseFrame = false}
player.state = characterState
ledgePoint = 0
keyIndicator = newCharacter("img","KeyIndicators","png",0.1,"L")
end
function dust:new(o)
o = o or {}
setmetatable(o,self)
self.__index = self
return o
end
function getDoorPosition()
for _, door in ipairs(doorPositions) do
if door.x >= player.x and door.x <= player.x+player.img:getWidth() then
--if (door.y >= player.y and door.y <= player.y + player.img:getHeight()) or then
if player.y+32 >= (door.y-door.height) and player.y+32 <= (door.y) then
return true, door
end
end
end
return false
end
function character_controller:update(dt)
player_move(dt)
--world:update(dt)
--objects.player.body:setPosition(player.x,player.y)
--position.x, position.y = objects.player.body:getPosition()
MainCharacterAnim:update(dt)
MainCharacterAnim:setDirection("Forward")
end
function buttonState:new(o)
o = o or {}
setmetatable(o,self)
self.__index = self
return o
end
function love.keypressed(key)
-- if characterState.hasRing then
-- ring.obtained = false
-- end
if ingame then
KeyPress(key)
else
KeyPressGameStart(key)
end
end
function KeyPress(key)
characterState.collision = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1)
grounded = characterState.collision.down
local onewayCheck = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1, "player")
if onewayCheck.down then
grounded = true
end
if key == 'w' and grounded or characterState.onOneWayPlatform then
stopJump = true
end
onewayCheck = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1, "onlyoneway")
if onewayCheck.down and key=='j' and button.crouch then
player.y = player.y + 5
end
-- if canPlunge and key == 'l' and not characterState.attacking then
-- plunging = true
-- canPlunge = false
-- end
if not characterState.crouchedThiseFrame and not player.rolling and player.getupTimer == 25 and not player.charging and not player.isChargingAttack and not characterState.wallHanging and not characterState.initiatedPullUp then
if not characterState.attacking and not player.hurt and quiver.arrows > 0 and not button.crouch and player.ammo > 0 then
button.button1.class:keypressdown(key)
end
if not player.nearVendor and not player.nearFire then
if key == 'l' and not button.button1.boolean and not characterState.attacking and not button.crouch and (not player.hurt or characterState.cantKnockBack) and not plunging and not canPlunge and not characterState.canCrouchAttackWhileMoving then
characterState.attacking = true
elseif key =='l' and not button.button1.boolean and not characterState.isAttacking and not characterState.crouchAttack and (button.crouch or characterState.canCrouchAttackWhileMoving) and (not player.hurt or characterState.cantKnockBack) and not plunging and not canPlunge then
characterState.crouchAttack = true
end
end
if key == 'j' and grounded and not characterState.attacking and not button.crouch then
player.rolling = true
player.pressingRight = false
player.pressingLeft = false
player.pressTimer = 20
end
end
if characterState.wallHanging and key == 'w' then
characterState.collision = physics:get(characterState.collision,player.x+(4*direction),ledgePoint - player.img:getHeight(),player.img,direction,0)
local right = characterState.collision.right
local left = characterState.collision.left
if not right or not left then
characterState.initiatedPullUp = true
characterState.pullUp_y = (ledgePoint - player.img:getHeight())+(player.img:getHeight()/3)
characterState.savedLedgePoint = ledgePoint
end
end
-- if (key == 'd' and player.pressingRight) or (key == 'a' and player.pressingLeft) then
-- player.rolling = true
-- print("YOOYO")
-- player.pressingRight = false
-- player.pressingLeft = false
-- player.pressTimer = 20
-- end
-- if key == 's' and not button.button1.boolean and not characterState.attacking then
-- player.img = love.graphics.newImage('img/MainCharacterAnimations/Crouch/01.png')
-- player.y = player.y + (64-36)
-- button.crouch = true
-- end
if player.nearVendor and not vendorMenu.interacting then
if key == 'l' then
vendorMenu.interacting = true
end
end
if vendorMenu.interacting then
if key == 'a' and vendorMenu.position>0 then
vendorMenu.position = vendorMenu.position - 1
end
if key == 'd' and vendorMenu.position<2 then
vendorMenu.position = vendorMenu.position + 1
end
if vendorMenu.position == 2 and key == 'l' then
vendorMenu.interacting = false
vendorMenu.position = 0
end
end
if player.nearFire and key == 'l' then
player.respawnPoint.x = player.x
player.respawnPoint.y = player.y
player.respawnPointTriggered = true
player.currentSpawnPoint.on = true
player.respawnRoom = player.currentSpawnPoint.room
tableSave("/Users/alex/Documents/Game/gamesaves/gamesave1.lua")
end
end
function love.keyreleased(key)
if ingame then
KeyRelease(key)
else
end
end
function KeyRelease(key)
if key == 'w' and stopJump == true then
stopJump = false
jumped = false
cantJumpAgain = false
cantJump = false
gravityIterator = 0
end
if (not player.hurt or characterState.cantKnockBack) then
button.button1.class:keypressup(key)
end
if key == 's' then
plunging = false
canPlunge = false
end
if key == 'l' and player.isChargingAttack then
player.charging = true
player.isChargingAttack = false
player.canCharge = true
end
if key == 'k' and button.crouch then
for k in pairs(arrowsOnScreen) do
arrowsOnScreen[k] = nil
end
if button.button1.class == bomb_throw then
button.button1 = button_action:load("k",axe_throw,"AxeThrow",shooting)
quiver.Icon = quiver.axeIcon
else
-- button.button1 = button_action:load("k",shooter,"Shooting2",shooting)
-- quiver.Icon = quiver.arrowIcon
button.button1 = button_action:load("k",bomb_throw,"AxeThrow",shooting)
quiver.Icon = quiver.bombIcon
end
end
-- if key == 'd' and not player.pressingRight then
-- player.pressingRight = true
-- end
-- if key == 'a' and not player.pressingLeft then
-- player.pressingLeft = true
-- end
-- if key == 's' then
-- button.crouch = false
-- player.y = player.y - (64-36)
-- player.img = love.graphics.newImage('img/MainCharacterAnimations/Walk/01.png')
-- end
end
function getFlip()
if direction == 1 then
return player.x
elseif direction == -1 then
return player.x + player.img:getWidth()
end
end
function resetAttackStuff()
player.canCharge = true
player.isChargingAttack = false
player.charging = false
player.chargeStrike = false
player.chargeMultiplier = 0
characterState.attacking = false
player.chargeStrike = false
attackingTimer = 0
player.canCharge = true
player.chargeMultiplier = 0
player.normalAttacking = false
end
function checkForWallHang(x,y)
local checkTop, checkBottom = false,false
local blockTop1,blockTop2 = 0,0
checkTop, blockTop1 = getWallHang(x,y+1)
checkBottom, blockTop2 = getWallHang(x,y+9)
checkFeet = getWallHang(x-direction*16, y+player.img:getHeight()+16)
if not checkTop and checkBottom and not checkFeet then
return true, blockTop2
else
return false
end
end
function player_move(deltaTime)
--print(deltaTime)
if getNearVendor() then
player.nearVendor = true
else player.nearVendor = false
end
if getNearFire() then
player.nearFire = true
else player.nearFire = false
end
keyIndicator:update(deltaTime)
keyIndicator:setMode("bounce")
local healValue = 0
local ttype = nil
local gotCoin,healLocation_x,healLocation_y,ttype = getCoinItem()
--(player.health < player.healthMax)
if ttype ~= nil then
if gotCoin and ttype == "coin" then
--player.health = player. health + 1
player.coins = player.coins + 1
local coin = coinThing:new()
coin.x = healLocation_x-32
coin.y = healLocation_y-32
coin.animator = newCharacter("img","Items","png",0.1,"CoinDrop")
table.insert(coinDropper,coin)
elseif gotCoin and ttype == "ammo" then
if player.ammo < player.ammoMax then
player.ammo = player.ammo + 1
end
local coin = coinThing:new()
coin.x = healLocation_x-32
coin.y = healLocation_y-32
coin.animator = newCharacter("img","Items","png",0.1,"CoinDrop")
table.insert(coinDropper,coin)
else
player.health = player. health + 3
if player.health >= player.healthMax then
player.health = player.healthMax
end
local coin = coinThing:new()
coin.x = healLocation_x-32
coin.y = healLocation_y-32
coin.animator = newCharacter("img","Items","png",0.1,"CoinDrop")
table.insert(coinDropper,coin)
end
end
updateCoinDropper(deltaTime)
local wallHangingLastFrame = characterState.wallHanging
local wall_x,offset_wall = 1,3
if direction == -1 then
wall_x,offset_wall = 0,-3
end
characterState.wallHanging, ledgePoint = checkForWallHang(player.x+(player.img:getWidth()*wall_x)+offset_wall, player.y)
if not (characterState.wallHanging and fallingLastFrame) or button.crouch or characterState.attacking then characterState.wallHanging = false end
if wallHangingLastFrame and not characterState.wallHanging then
MainCharacterAnim:resetAction("OnLedge")
end
debugTools.timer = love.timer.getTime() - debugTools.startTimer
playerGhostContainer:update()
if player.bufferAttack and player.getupTimer == 25 then
KeyPress(player.bufferedKey)
if not love.keyboard.isDown(player.bufferedKey) then
KeyRelease(player.bufferedKey)
end
player.bufferAttack = false
end
--print(player.pressTimer)
if player.pressingRight or player.pressingLeft then
player.pressTimer = player.pressTimer - 1
end
if player.pressTimer <= 0 then
player.pressingLeft = false
player.pressingRight = false
player.pressTimer = 20
end
if player.hurt or player.rolling or characterState.wallHanging or characterState.initiatedPullUp then
activeTracking = false
else
activeTracking = true
end
--characterState.jumping = jumped
characterState.canCrouchAttackWhileMoving = (love.keyboard.isDown('s') and (love.keyboard.isDown('a') or love.keyboard.isDown('d')))
-- if characterState.canCrouchAttackWhileMoving and not crouchAtthen
-- button.crouch = false
-- end
characterState.collision = physics:get(characterState.collision,player.x,player.y,player.img,0,1)
up = characterState.collision.up
characterState.collision = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1, "player")
local C = characterState.collision.down
if love.keyboard.isDown('s') and not characterState.jumping and not button.button1.boolean and (not characterState.moving or characterState.crouchAttack) and not characterState.attacking and (not player.hurt or characterState.cantKnockBack) then
MainCharacterAnim:setAction("Crouch")
MainCharacterAnim:setMode("loop")
if not button.crouch then
player.y = player.y + (64-36)
resetAttackStuff()
characterState.crouchedThiseFrame = true
else
characterState.crouchedThiseFrame = false
end
button.crouch = true
player.img = love.graphics.newImage('img/MainCharacterAnimations/Crouch/01.png')
elseif not (characterState.crouchAttack or player.hurt) and not up then
if button.crouch and C then
player.y = player.y - (64-36)
resetAttackStuff()
end
button.crouch = false
player.img = love.graphics.newImage('img/MainCharacterAnimations/Walk/01.png')
end
local y = player.y
local x = player.x
local speed = player.speed
local prev_grav = gravityIterator
characterState.collision = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1)
local onewayCheck = physics:get(characterState.collision,player.x,player.y+1,player.img,0,-1, "player")
if characterState.wallHanging then
gravityIterator = 0
grounded = true
end
if not grounded then
gravityIterator = gravityIterator + 1
if 35*.009*gravityIterator <= 8 then
y = y + 35*.008*gravityIterator
player.maxFallSpeed = false
else
player.maxFallSpeed = true
y = y + 8
end
else
maxFallSpeed = false
--MainCharacterAnim:resetAction("Plunge")
--plunging = false
if not stopJump then
gravityIterator = 0
end
end
if characterState.collision.down or onewayCheck.down then
characterState.jumping = false
elseif not onDiagonalSlope then
onewayCheck = false
characterState.jumping = true
end
--characterState.collision = physics:get(characterState.collision,x,y+1,player.img,0,-1)
--grounded = characterState.collision.down
if stopJump then
jumped = true
--y = y - speed*.005*4.75
y = y - 200*.0065*5
end
player.secondSlashTimer = player.secondSlashTimer - 1
-- local jumpTime1 = MainCharacterAnim:getFrameAction("SwordAttack1")
-- local standTime1 = MainCharacterAnim:getFrameAction("SwordAttack1Jump")
-- local jumpTime2 = MainCharacterAnim:getFrameAction("SwordAttack2")
-- local standTime2 = MainCharacterAnim:getFrameAction("SwordAttack2Jump")
-- local jumpTime1timer = MainCharacterAnim:getTimerAction("SwordAttack1")
-- local standTime1timer = MainCharacterAnim:getTimerAction("SwordAttack1Jump")
-- local jumpTime2timer = MainCharacterAnim:getTimerAction("SwordAttack2")
-- local standTime2timer = MainCharacterAnim:getTimerAction("SwordAttack2Jump")
-- local frame1 = 0
-- local frame2 = 0
-- local timer1 = 0
-- local timer2 = 0
-- if jumpTime1timer >= standTime1timer then
-- timer1 = jumpTime1timer
-- else
-- timer1 = standTime1timer
-- end
-- if jumpTime2timer >= standTime2timer then
-- timer2 = jumpTime2timer
-- else
-- timer2 = standTime2timer
-- end
-- if jumpTime1 >= standTime1 then
-- frame1 = jumpTime1
-- else
-- frame1 = standTime1
-- end
-- if jumpTime2 >= standTime2 then
-- frame2 = jumpTime2
-- else
-- frame2 = standTime2
-- end
-- print(timer1)
-- print(timer2)
-- MainCharacterAnim:seekAction("SwordAttack1", frame1)
-- MainCharacterAnim:seekAction("SwordAttack1Jump", frame1)
-- MainCharacterAnim:seekAction("SwordAttack2", frame2)
-- MainCharacterAnim:seekAction("SwordAttack2Jump", frame2)
-- MainCharacterAnim:timerAction("SwordAttack1", timer1)
-- MainCharacterAnim:timerAction("SwordAttack1Jump", timer1)
-- MainCharacterAnim:timerAction("SwordAttack2", timer2)
-- MainCharacterAnim:timerAction("SwordAttack2Jump", timer2)
if characterState.attacking and not button.crouch and (not player.hurt or characterState.cantKnockBack) then --and (not love.keyboard.isDown('s') or player.normalAttacking) then
if player.secondSlashTimer < 0 and not player.secondSlashing and not player.chargeStrike then
if not characterState.jumping then
MainCharacterAnim:setActionSpeed("SwordAttack1",player.attackAnimSpeed)
MainCharacterAnim:setAction("SwordAttack1")
MainCharacterAnim:updateAction("SwordAttack1Jump", deltaTime)
else
MainCharacterAnim:setActionSpeed("SwordAttack1Jump",player.attackAnimSpeed)
MainCharacterAnim:setAction("SwordAttack1Jump")
MainCharacterAnim:updateAction("SwordAttack1", deltaTime)
end
MainCharacterAnim:setMode("once")
attackingFinished = 8 - player.attackSpeed
elseif not player.chargeStrike then
if not characterState.jumping then
MainCharacterAnim:setActionSpeed("SwordAttack2",player.attackAnimSpeed)
MainCharacterAnim:setAction("SwordAttack2")
MainCharacterAnim:updateAction("SwordAttack2Jump", deltaTime)
else
MainCharacterAnim:setActionSpeed("SwordAttack2Jump",player.attackAnimSpeed)
MainCharacterAnim:setAction("SwordAttack2Jump")
MainCharacterAnim:updateAction("SwordAttack2", deltaTime)
end
MainCharacterAnim:setMode("once")
player.secondSlashing = true
attackingFinished = 8 - player.attackSpeed
else
MainCharacterAnim:setActionSpeed("SwordChargeStrike",player.attackAnimSpeed)
MainCharacterAnim:setAction("SwordChargeStrike")
MainCharacterAnim:setMode("once")
attackingFinished = 12
end
player.normalAttacking = true
if love.keyboard.isDown('l') and player.canCharge and not player.chargeStrike then
if attackingTimer >= 4 then
--player.isChargingAttack = true
end
--MainCharacterAnim:setAction("SwordCharge")
else
player.canCharge = false
end
if attackingTimer >= 3 and attackingTimer <= 6 then
local first = 0
local second = 56
if player.secondSlashing then
first = 10
second = 66
end
if player.chargeStrike then
second = 74
first = 16
end
if direction == 1 then
blade_collider.x1 = player.x + 16
blade_collider.x2 = blade_collider.x1 + second
else
blade_collider.x1 = player.x-second+16
blade_collider.x2 = player.x+16
end
blade_collider.y1 = player.y+4
blade_collider.y2 = blade_collider.y1 + 32 - 16
if player.chargeStrike then
blade_collider.y1 = player.y - 16
blade_collider.y2 = blade_collider.y1 + 64+ 16
end
else
blade_collider.x1, blade_collider.x2, blade_collider.y1, blade_collider.y2 = 0,0,0,0
end
if attackingTimer <= attackingFinished then
attackingTimer = attackingTimer + .3
else
if not player.secondSlashing then
player.secondSlashTimer = 20
end
MainCharacterAnim:resetAction("SwordAttack1")
MainCharacterAnim:resetAction("SwordAttack1Jump")
MainCharacterAnim:resetAction("SwordChargeStrike")
--else
MainCharacterAnim:resetAction("SwordAttack2")
MainCharacterAnim:resetAction("SwordAttack2Jump")
player.secondSlashing = false
--end
resetAttackStuff()
end
elseif characterState.crouchAttack and (not player.hurt or characterState.cantKnockBack) then
MainCharacterAnim:setActionSpeed("CrouchSwordAttack",1.25)
--button.crouch = true
MainCharacterAnim:setAction("CrouchSwordAttack")
MainCharacterAnim:setMode("once")
if attackingTimer >= 1 and attackingTimer <= 3 then
local first = 0
local second = 46
if direction == 1 then
blade_collider.x1 = player.x + 32
blade_collider.x2 = blade_collider.x1 + second
else
blade_collider.x1 = player.x-second
blade_collider.x2 = player.x
end
blade_collider.y1 = player.y+15
blade_collider.y2 = blade_collider.y1 + 10
else
blade_collider.x1, blade_collider.x2, blade_collider.y1, blade_collider.y2 = 0,0,0,0
end
if attackingTimer <= (6-player.attackSpeed) then
attackingTimer = attackingTimer + .3
else
characterState.crouchAttack = false
MainCharacterAnim:resetAction("CrouchSwordAttack")
attackingTimer = 0
end
elseif characterState.jumping and plunging and not characterState.crouchAttack and (not player.hurt or characterState.cantKnockBack) then
MainCharacterAnim:setActionSpeed("Plunge",2)
--button.crouch = true
MainCharacterAnim:setAction("Plunge")
MainCharacterAnim:setMode("once")
if attackingTimer >= 2 and attackingTimer <= 10 then
local first = 0
local second = 28
if direction == 1 then
blade_collider.x1 = player.x
blade_collider.x2 = blade_collider.x1 + second+8
else
blade_collider.x1 = player.x-8
blade_collider.x2 = player.x+32
end
blade_collider.y1 = player.y+player.img:getHeight()-20
blade_collider.y2 = blade_collider.y1 + 20+second
else
blade_collider.x1, blade_collider.x2, blade_collider.y1, blade_collider.y2 = 0,0,0,0
end
if attackingTimer <= 4.5 then
attackingTimer = attackingTimer + .3
else
--characterState.crouchAttack = false
MainCharacterAnim:resetAction("Plunge")
plunging = false
attackingTimer = 0
plunging = false
end
else
blade_collider.x1, blade_collider.x2, blade_collider.y1, blade_collider.y2 = 0,0,0,0
attackingTimer = 0
--MainCharacterAnim:resetAction("Plunge")
end
if love.keyboard.isDown('a') and not (button.button1.boolean and characterState.collision.down) and not (characterState.attacking and characterState.collision.down) and not characterState.crouchAttack and not player.rolling then
if player.speed >= -player.maxSpeed then
player.speed = player.speed - player.accelerationFactor
else player.speed = -player.maxSpeed
end
x = player.x + speed*deltaTime -- move up
characterState.moving = true
if not characterState.attacking and not button.button1.boolean then
direction = -1
end
if not button.button1.boolean and not characterState.attacking and not characterState.jumping then
--MainCharacterAnim:resetAction("Jump")
--MainCharacterAnim:setMode("loop")
MainCharacterAnim:setAction("Walk")
MainCharacterAnim:setMode("loop")
end
elseif love.keyboard.isDown('d') and not (button.button1.boolean and characterState.collision.down) and not (characterState.attacking and characterState.collision.down) and not characterState.crouchAttack and not player.rolling then
if player.speed <= player.maxSpeed then
player.speed = player.speed + player.accelerationFactor
else player.speed = player.maxSpeed
end
x = player.x + speed*deltaTime -- move down
if not characterState.attacking and not button.button1.boolean then
direction = 1
end
characterState.moving = true
if not button.button1.boolean and not characterState.attacking and not characterState.jumping then
--MainCharacterAnim:resetAction("Jump")
--MainCharacterAnim:setMode("loop")
MainCharacterAnim:setAction("Walk")
MainCharacterAnim:setMode("loop")
end
elseif not button.button1.boolean and not characterState.attacking and not characterState.jumping and button.crouch and not characterState.crouchAttack then
MainCharacterAnim:setAction("Crouch")
MainCharacterAnim:setMode("loop")
characterState.moving = false
elseif not button.button1.boolean and not characterState.attacking and not characterState.jumping and not characterState.crouchAttack and not button.crouch and not player.rolling then
MainCharacterAnim:setAction("Idle")
MainCharacterAnim:setMode("loop")
characterState.moving = false
end
if not (love.keyboard.isDown('d') or love.keyboard.isDown('a')) then
if player.speed ~= 0 then
local slowdownFactor = 0
if player.speed > 0 then
slowdownFactor = -1
else slowdownFactor = 1
end
player.speed = player.speed + slowdownFactor*player.accelerationFactor
x = player.x + speed*deltaTime
-- if not characterState.attacking and not player.crouch then
-- MainCharacterAnim:setAction("Walk")
-- MainCharacterAnim:setMode("loop")
-- end
-- if love.keyboard.isDown('s') then
-- MainCharacterAnim:setAction("Crouch")
-- MainCharacterAnim:setMode("loop")
-- end
end
end
if characterState.moving and love.keyboard.isDown("s") and grounded and characterState.attacking then
characterState.moving = false
end
if characterState.jumping and not characterState.attacking and not button.button1.boolean and not characterState.falling then
--MainCharacterAnim:setActionSpeed("Jump",.8)
MainCharacterAnim:setMode("once")
if math.abs(player.speed) > 70 then
MainCharacterAnim:setAction("Jump2")
else
MainCharacterAnim:setAction("Jump1")
end
end
if plunging then
MainCharacterAnim:setAction("Plunge")
MainCharacterAnim:setMode("once")
end
if player.isChargingAttack then
player.chargeFill = true
player.chargeFillValue = player.chargeMultiplier
player.chargeFillMax = 15
player.speed = 50