-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenemy_bot.js
More file actions
139 lines (125 loc) · 3.42 KB
/
enemy_bot.js
File metadata and controls
139 lines (125 loc) · 3.42 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
ig.module(
'game.entities.enemy_bot'
)
.requires(
'impact.entity',
'plugins.bot'
)
.defines(function(){
EntityEnemy_bot = ig.bot.extend({
// Types
type: ig.Entity.TYPE.B,
checkAgainst: ig.Entity.TYPE.A,
collides: ig.Entity.COLLIDES.PASSIVE,
// Movement properties
maxVel: { x: 80, y: 240 },
accelDef: { ground: 400, air: 200 },
frictionDef: { ground: 400, air: 100 },
jump: 100,
bounciness: 0,
// Configure bot
bot: {
config: {
loop: true, // [boolean] (Optional, default true) - Loop routine
hole_jump: true, // [boolean] (Optional, default true) - If there's a hole in the collision map, jump
hole_wall: false, // [boolean] (Optional, default false) - If there's a hole in the collision map, change direction
death_fall: true // [boolean] (Optional, default true) - The bot dies if it falls off the screen (pos.y > collisionMap height)
},
movements: [
// Wait for player and then wait 100 milliseconds
{
action: 'wait',
entity: 'player',
duration: 0.1,
start: function() {
console.log('Starts waiting');
},
during: function() {
console.log('Im waiting!');
},
complete: function() {
console.log('Movement complete!')
}
},
// Walk left
{
action: 'walk',
direction: 'left',
distance: 90,
start: function() {
console.log('Starts walking');
},
during: function() {
console.log('Im walking!');
},
complete: function() {
console.log('Movement complete!')
}
},
// Jump to the right
{
action: 'jump',
direction: 'right',
vel: 100,
start: function() {
console.log('Starts jumping');
},
during: function() {
console.log('Im jumping!!1!');
},
complete: function() {
console.log('Movement complete!')
}
},
// Call a function
{
action: function() {
console.log('Routine complete')
}
}
]
},
// Image
size: {x: 6, y: 10 },
offset: { x: 2, y: 6 },
animSheet: new ig.AnimationSheet('media/enemy_bot.png', 12, 16),
flip: true,
// Properties
health: 60,
direction: 'right',
// Debug
debug: true,
init: function(x, y, settings) {
this.parent( x, y, settings);
// Animations
this.addAnim('idle', 0.07, [01]);
this.addAnim('walk', 0.07, [00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11]);
this.addAnim('jump', 1.00, [12]);
this.addAnim('fall', 1.00, [12]);
},
update: function() {
// Animation
if(this.vel.x != 0 && this.vel.y == 0) {
if(this.currentAnim != this.anims.walk) this.currentAnim = this.anims.walk;
} else if(this.vel.y < 0) {
if(this.currentAnim != this.anims.jump) {
this.currentAnim = this.anims.jump;
this.currentAnim.rewind();
}
} else if(this.vel.y > 0) {
if(this.currentAnim != this.anims.fall) this.currentAnim = this.anims.fall;
} else if(this.standing) {
if(this.currentAnim != this.anims.idle) this.currentAnim = this.anims.idle;
}
// Flip
if(this.vel.x > 0) { this.flip = false; } else if(this.vel.x < 0) { this.flip = true; }
this.currentAnim.flip.x = this.flip;
// Refresh
this.parent();
},
handleMovementTrace: function(res) {
// Continue resolving the collision as normal
this.parent(res);
}
});
});