1
1
import Vec2 from "vec2" ;
2
2
import Player from "./Player" ;
3
- import { eucDistance } from "./util" ;
4
3
import GameObject from '../gameobjects/GameObject' ;
5
- import { gameObjectSizes } from "../gameobjects/gameobjects" ;
6
- import { getWeaponAttackDetails , Weapons , hasCollision } from "../items/items" ;
4
+ import { getWeaponAttackDetails , hasCollision , getGameObjDamage } from "../items/items" ;
7
5
import GameState from "./GameState" ;
6
+ import { ItemType } from "../items/UpgradeItems" ;
7
+ import { getHat } from "./Hats" ;
8
8
9
9
function collideCircles ( pos1 : Vec2 , r1 : number , pos2 : Vec2 , r2 : number ) {
10
10
return pos1 . distance ( pos2 ) <= r1 + r2 ;
11
11
}
12
12
13
- function collideRectangles ( x1 : number , y1 : number , w1 : number , h1 : number , x2 : number , y2 : number , w2 : number , h2 : number ) {
13
+ function collideRectangles ( x1 : number , y1 : number , w1 : number , x2 : number , y2 : number , w2 : number , h2 : number ) {
14
14
return x1 + w1 >= x2 && x1 <= x2 + w2 && y1 + w1 >= y2 && y1 <= y2 + h2 ;
15
15
}
16
16
@@ -32,13 +32,39 @@ function collidePlayerGameObject(player: Player, gameObj: GameObject) {
32
32
}
33
33
34
34
function tryMovePlayer ( player : Player , delta : number , xVel : number , yVel : number , state : GameState ) {
35
+ let inTrap = false ;
36
+
35
37
let newLocation = new Vec2 (
36
38
player . location . x ,
37
39
player . location . y
38
40
) ;
39
41
40
42
for ( let gameObj of player . getNearbyGameObjects ( state ) ) {
41
- if ( ! gameObj . type && typeof gameObj . data === 'number' ) {
43
+ if ( gameObj . isPlayerGameObject ( ) && collidePlayerGameObject ( player , gameObj ) ) {
44
+ if (
45
+ gameObj . data === ItemType . PitTrap &&
46
+ gameObj . isEnemy ( player , state . tribes )
47
+ ) {
48
+ inTrap = true ;
49
+ }
50
+
51
+ let dmg = getGameObjDamage ( gameObj . data ) ;
52
+
53
+ if (
54
+ dmg &&
55
+ gameObj . isEnemy ( player , state . tribes )
56
+ ) {
57
+ let hat = getHat ( player . hatID ) ;
58
+
59
+ if ( hat ) {
60
+ dmg *= hat . dmgMult || 1 ;
61
+ }
62
+
63
+ let angle = Math . atan2 ( player . location . y - gameObj . location . y , player . location . x - gameObj . location . x ) ;
64
+ player . velocity . add ( Math . cos ( angle ) , Math . sin ( angle ) ) ;
65
+ player . health -= dmg ;
66
+ }
67
+
42
68
if ( ! hasCollision ( gameObj . data ) ) continue ;
43
69
}
44
70
@@ -47,20 +73,23 @@ function tryMovePlayer(player: Player, delta: number, xVel: number, yVel: number
47
73
yVel *= .75 ;
48
74
49
75
let angle = Math . atan2 ( newLocation . y - gameObj . location . y , newLocation . x - gameObj . location . x ) ;
76
+
50
77
newLocation = new Vec2 (
51
78
gameObj . location . x + Math . cos ( angle ) * ( gameObj . realScale + 35 ) ,
52
79
gameObj . location . y + Math . sin ( angle ) * ( gameObj . realScale + 35 )
53
80
) ;
54
81
}
55
82
}
56
83
84
+ player . inTrap = inTrap ;
85
+ if ( inTrap ) return ;
86
+
57
87
newLocation . clamp ( new Vec2 ( 0 + 35 , 0 + 35 ) , new Vec2 ( 14400 - 35 , 14400 - 35 ) ) ;
58
88
player . location = newLocation . add ( delta * xVel , delta * yVel ) ;
59
89
}
60
90
61
91
function movePlayer ( player : Player , delta : number , state : GameState ) {
62
92
if ( player . velocity . x || player . velocity . y ) {
63
- let angle = Math . atan2 ( player . velocity . y , player . velocity . x ) ;
64
93
tryMovePlayer ( player , delta , player . velocity . x , player . velocity . y , state ) ;
65
94
player . velocity = player . velocity . multiply ( 0.993 ** delta , 0.993 ** delta ) ;
66
95
}
@@ -91,7 +120,7 @@ function checkAttack(player: Player, players: Player[]) {
91
120
}
92
121
93
122
function collideGameObjects ( gameObject1 : GameObject , gameObject2 : GameObject ) {
94
- return collideCircles ( gameObject1 . location , gameObject1 . scale , gameObject2 . location , gameObject1 . scale ) ;
123
+ return collideCircles ( gameObject1 . location , gameObject1 . realScale * 0.9 , gameObject2 . location , gameObject1 . realScale ) ;
95
124
}
96
125
97
126
function checkAttackGameObj ( player : Player , gameObjects : GameObject [ ] ) {
0 commit comments