frog basic animation
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -8,7 +8,10 @@ window.onload = function()
8
8
[
9
9
{name:"arrow", url:"images/arrow.png", subImgTotal: 4, perRow: 2},
10
10
{name:"grass_dark", url:"images/grass_dark.png"},
11
{name:"grass_light", url:"images/grass_light.png"}
11
{name:"grass_light", url:"images/grass_light.png"},
12
{name:"frog_basic", url:"images/character/frog/frog_basic.png", subImgTotal: 8, perRow: 4},
13
{name:"frog_tongue_base", url:"images/character/frog/frog_tongue_base.png"},
14
{name:"frog_tongue_tip", url:"images/character/frog/frog_tongue_tip.png"}
12
15
]
13
16
);
14
17
@@ -25,9 +28,6 @@ createMainScene = function(game)
25
28
26
29
game.loadScene(scene);
27
30
28
var arrow = new Arrow(50, 50, game.images.arrow, 0);
29
arrow.renderer.subImage = 4;
30
31
31
scene.addObject(new GrassTiler(50, 50, game.images.arrow, 0));
32
scene.addObject(arrow);
32
scene.addObject(new Frog(50,50, game.images.frog_basic, 0));
33
33
}
@@ -8,7 +8,10 @@ window.onload = function()8
[8
[9
{name:"arrow", url:"images/arrow.png", subImgTotal: 4, perRow: 2},9
{name:"arrow", url:"images/arrow.png", subImgTotal: 4, perRow: 2},10
{name:"grass_dark", url:"images/grass_dark.png"},10
{name:"grass_dark", url:"images/grass_dark.png"},11
{name:"grass_light", url:"images/grass_light.png"}11
{name:"grass_light", url:"images/grass_light.png"},12
{name:"frog_basic", url:"images/character/frog/frog_basic.png", subImgTotal: 8, perRow: 4},13
{name:"frog_tongue_base", url:"images/character/frog/frog_tongue_base.png"},14
{name:"frog_tongue_tip", url:"images/character/frog/frog_tongue_tip.png"}12
]15
]13
);16
);14
17
@@ -25,9 +28,6 @@ createMainScene = function(game)25
28
26
game.loadScene(scene);29
game.loadScene(scene);27
30
28
var arrow = new Arrow(50, 50, game.images.arrow, 0);29
arrow.renderer.subImage = 4;30
31
scene.addObject(new GrassTiler(50, 50, game.images.arrow, 0));31
scene.addObject(new GrassTiler(50, 50, game.images.arrow, 0));32
scene.addObject(arrow);32
scene.addObject(new Frog(50,50, game.images.frog_basic, 0));33
}33
}@@ -0,0 +1,88 @@
1
class Frog extends GameObject {
2
3
facing = {
4
left: [4,5,6],
5
right: [0,1,2]
6
};
7
8
speed = 200;
9
10
currentFacing = this.facing.right;
11
idle = true;
12
13
currentIndex = 0;
14
frame = 0;
15
16
constructor(x,y,sprite,layer) {
17
super(x,y,sprite,layer);
18
}
19
20
update(deltaTime)
21
{
22
super.update(deltaTime);
23
this.idle = true;
24
25
if(GameInput.isHeld(GameInput.keys.ArrowRight))
26
{
27
this.transform.position.x += this.speed * deltaTime;
28
29
if(this.currentFacing != this.facing.right) {
30
this.changeImageDirection();
31
this.currentFacing = this.facing.right;
32
}
33
34
CookieManager.setCookie("arrow", "right");
35
this.idle = false;
36
this.cycleImage(deltaTime);
37
}
38
39
if(GameInput.isHeld(GameInput.keys.ArrowLeft))
40
{
41
this.transform.position.x -= this.speed * deltaTime;
42
43
if(this.currentFacing != this.facing.left) {
44
this.changeImageDirection();
45
this.currentFacing = this.facing.left;
46
}
47
48
CookieManager.setCookie("arrow", "left")
49
this.idle = false;
50
this.cycleImage(deltaTime);
51
}
52
53
if(this.idle) {
54
this.currentIndex = 0;
55
this.resolveToIdleImage();
56
}
57
}
58
59
changeImageDirection() {
60
if(this.renderer.subImage > 3) {
61
this.renderer.subImage -= 4;
62
} else {
63
this.renderer.subImage += 4;
64
}
65
}
66
67
resolveToIdleImage() {
68
if(this.renderer.subImage > 3) {
69
if(this.renderer.subImage != 4) {
70
this.renderer.subImage = 4;
71
}
72
} else {
73
if(this.renderer.subImage != 0) {
74
this.renderer.subImage = 0;
75
}
76
}
77
}
78
79
cycleImage(deltaTime) {
80
this.frame+= deltaTime;
81
82
if(this.frame > .05) {
83
this.frame = 0;
84
this.currentIndex++;
85
this.renderer.subImage = this.currentFacing[this.currentIndex % this.currentFacing.length];
86
}
87
}
88
}
@@ -0,0 +1,88 @@1
class Frog extends GameObject {2
3
facing = {4
left: [4,5,6],5
right: [0,1,2]6
};7
8
speed = 200;9
10
currentFacing = this.facing.right;11
idle = true;12
13
currentIndex = 0;14
frame = 0;15
16
constructor(x,y,sprite,layer) {17
super(x,y,sprite,layer);18
}19
20
update(deltaTime)21
{22
super.update(deltaTime);23
this.idle = true;24
25
if(GameInput.isHeld(GameInput.keys.ArrowRight))26
{27
this.transform.position.x += this.speed * deltaTime;28
29
if(this.currentFacing != this.facing.right) {30
this.changeImageDirection();31
this.currentFacing = this.facing.right;32
}33
34
CookieManager.setCookie("arrow", "right");35
this.idle = false;36
this.cycleImage(deltaTime);37
}38
39
if(GameInput.isHeld(GameInput.keys.ArrowLeft))40
{41
this.transform.position.x -= this.speed * deltaTime;42
43
if(this.currentFacing != this.facing.left) {44
this.changeImageDirection();45
this.currentFacing = this.facing.left;46
}47
48
CookieManager.setCookie("arrow", "left")49
this.idle = false;50
this.cycleImage(deltaTime);51
}52
53
if(this.idle) {54
this.currentIndex = 0;55
this.resolveToIdleImage();56
}57
}58
59
changeImageDirection() {60
if(this.renderer.subImage > 3) {61
this.renderer.subImage -= 4;62
} else {63
this.renderer.subImage += 4;64
}65
}66
67
resolveToIdleImage() {68
if(this.renderer.subImage > 3) {69
if(this.renderer.subImage != 4) {70
this.renderer.subImage = 4;71
}72
} else {73
if(this.renderer.subImage != 0) {74
this.renderer.subImage = 0;75
}76
}77
}78
79
cycleImage(deltaTime) {80
this.frame+= deltaTime;81
82
if(this.frame > .05) {83
this.frame = 0;84
this.currentIndex++;85
this.renderer.subImage = this.currentFacing[this.currentIndex % this.currentFacing.length];86
}87
}88
}