Skip to content

Commit 335c1c8

Browse files
committed
Added Pinata Game.
Added what will become the Pinata game. When you click the "candy!" button it starts the power bar. The Power bar cycles between the 0 and 100 position. Click again you will stop the power bar.
1 parent cf6e757 commit 335c1c8

File tree

7 files changed

+164
-0
lines changed

7 files changed

+164
-0
lines changed

Firefox.jpg

378 KB
Loading

Firefox_wallpaper.png

903 KB
Loading

Pinata/Pinata.fla

6.52 KB
Binary file not shown.

Pinata/Pinata.swf

2.19 KB
Binary file not shown.

Pinata/energyBar.as

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package
2+
{
3+
import flash.display.Sprite;
4+
import flash.geom.Rectangle;
5+
import flash.events.Event;
6+
7+
public class energyBar extends Sprite
8+
{
9+
private var _do:Sprite;
10+
private var _ev:uint;
11+
12+
public function energyBar(displayObj, energyValue)
13+
{
14+
_do = displayObj;
15+
_ev = energyValue;
16+
init();
17+
addEventListener(Event.ENTER_FRAME, onFrame);
18+
}
19+
20+
private function onFrame(evt:Event):void
21+
{
22+
x = _do.x;
23+
y = _do.y - 20;
24+
}
25+
26+
private function init():void
27+
{
28+
x = _do.x;
29+
y = _do.y - 20;
30+
31+
this.graphics.lineStyle(1);
32+
this.graphics.beginFill(0x000000);
33+
this.graphics.drawRect(0,0,102,15);
34+
this.graphics.endFill();
35+
this.graphics.beginFill(0x00ff00);
36+
this.graphics.drawRect(1,1,_ev,13);
37+
this.graphics.endFill();
38+
}
39+
40+
public function updateBar(newval):void
41+
{
42+
_ev = newval;
43+
this.graphics.clear();
44+
this.graphics.lineStyle(1);
45+
this.graphics.beginFill(0x000000);
46+
this.graphics.drawRect(0,0,102,15);
47+
this.graphics.endFill();
48+
this.graphics.beginFill(0x00ff00);
49+
this.graphics.drawRect(1,1,newval,13);
50+
this.graphics.endFill();
51+
}
52+
}
53+
}

Pinata/game.as

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package
2+
{
3+
import flash.display.Sprite;
4+
import energyBar;
5+
import flash.events.Event;
6+
import flash.events.MouseEvent;
7+
import flash.events.TimerEvent;
8+
import flash.utils.Timer;
9+
10+
public class game extends Sprite
11+
{
12+
private var b:energyBar;
13+
private var val:uint = 0;
14+
private var myTimer:Timer = new Timer(50);
15+
private var a:Candy = new Candy();
16+
//Decides whether the power bar is traveling in the right direction.
17+
//Moving left to right is True, and right to left is False.
18+
private var directionControl:Boolean;
19+
20+
21+
public function game()
22+
{
23+
init();
24+
}
25+
26+
private function init():void
27+
{
28+
29+
a.x = 50;
30+
a.y = 50;
31+
addChild(a);
32+
33+
b = new energyBar(a, val);
34+
addChild(b);
35+
36+
a.addEventListener(MouseEvent.CLICK, onClick);
37+
}
38+
39+
private function onClick(e:Event):void
40+
{
41+
if(val >= 0 && val != 100)
42+
{
43+
myTimer.start();
44+
myTimer.addEventListener(TimerEvent.TIMER, blah);
45+
}
46+
else
47+
{
48+
myTimer.stop();
49+
}
50+
a.removeEventListener(MouseEvent.CLICK, onClick);
51+
a.addEventListener(MouseEvent.CLICK, onSecondClick);
52+
53+
}
54+
55+
private function blah(e:TimerEvent):void
56+
{
57+
if(val == 0 )
58+
{
59+
val+=5;
60+
b.updateBar(val);
61+
directionControl = true;
62+
}
63+
else if (val == 100 )
64+
{
65+
val -= 5;
66+
b.updateBar(val);
67+
directionControl = false;
68+
69+
}
70+
else if (val > 0 && val != 100 && directionControl == false)
71+
{
72+
val-=5;
73+
b.updateBar(val);
74+
}
75+
else if (val > 0 && val != 100 && directionControl == true)
76+
{
77+
val+=5;
78+
b.updateBar(val);
79+
}
80+
81+
}
82+
private function onSecondClick(e:Event):void
83+
{
84+
myTimer.stop();
85+
a.removeEventListener(MouseEvent.CLICK, onSecondClick);
86+
a.addEventListener(MouseEvent.CLICK, onClick);
87+
}
88+
89+
90+
91+
}
92+
}

Pinata/hero.as

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package
2+
{
3+
import flash.display.MovieClip;
4+
import flash.events.Event;
5+
6+
public class hero extends MovieClip
7+
{
8+
9+
public function hero()
10+
{
11+
addEventListener(Event.ENTER_FRAME, onFrame);
12+
}
13+
private function onFrame(evt:Event):void
14+
{
15+
x++;
16+
y++;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)