sheepShearing
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.*;
import flash.display.GradientType;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.utils.Timer;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.BitmapDataChannel;
import net.wonderfl.utils.SequentialLoader;
[SWF(width = "465", height = "465", backgroundColor = 0x86BA90, frameRate = "60")]
public class sheepShearing extends Sprite {
private var bg:Sprite;
private const SPEED:int = 5;
private const _LEFT:int = 0;
private const _RIGHT:int = 460;
private const _UE:int = 0;
private const _SITA:int = 460;
private const _LEFTbar:int = -10;
private const _RIGHTbar:int = 700;
private var mcBar:Sprite;
private var mcBall:Sprite;
private var arrayLife:Array=new Array();
private var ckLife:Boolean=false;
private var cntLife:uint=0;
private const maxLife:uint = 5;
private var xx:int=0;
private var yy:int=1;
private var bgArr:Array=[];
public function sheepShearing() {
//背景----------------------------------------------------------------------------------------------------
SequentialLoader.loadImages(["http://assets.wonderfl.net/images/related_images/f/ff/ff45/ff4592eaee533d11438df93ce0020ddfc7430b70"], bgArr, onLoaded);
}
private function onLoaded():void {
var loader:Loader=bgArr.pop();
var temp:BitmapData = new BitmapData(465, 465, true, 0x00FFFFFF);
temp.draw(loader);
var bm:Bitmap = new Bitmap(temp);
addChild(bm);
init();
}
//----------------------------------------------------------------------------------------------------
private function init(){
// --- ビットマップ作成
var layer:BitmapData = new BitmapData(465, 465, true,0);
var stage1:MovieClip = new MovieClip();addChildAt(stage1,1);stage1.addChild(new Bitmap(layer));
var brush_src:BitmapData = new BitmapData(465, 465, true, 0xFFFFFAEA);
var arrX=[40,95,180,260,300,70,130,210,255,270,120];
var arrY=[145,95,70,90,125,200,250,240,250,210,130];
for(var j:uint=0; j < 11; j++) {
var circle:Sprite = new blush_image(j);
var brush_shape:BitmapData = new BitmapData(circle.width*2, circle.height*2, true,0);
brush_shape.draw(circle);
var rndm:Number=Math.floor(Math.random()*20)-10;
var px:Number=arrX[j];
var py:Number=arrY[j];
var offset:Point = new Point(px,py);
var rect:Rectangle = new Rectangle(offset.x, offset.y, brush_shape.width, brush_shape.height);
layer.copyPixels(brush_src, rect, offset, brush_shape, new Point(0, 0), true);
}
var circle2:MovieClip = new eraze_image();
var eraser_shape:BitmapData = new BitmapData(circle2.width, circle2.height, true, 0xFFFFFFFF);
eraser_shape.draw(circle2);
eraser_shape.copyChannel(eraser_shape,eraser_shape.rect, new Point(0, 0),1,8);
// --- 消しゴムを使う
function useEraser():void {
var offset:Point = new Point(mcBall.x-10,mcBall.y-10);
var rect:Rectangle = new Rectangle(offset.x, offset.y, eraser_shape.width, eraser_shape.height);
layer.copyPixels(layer,rect,offset, eraser_shape, new Point(0, 0),false);
}
var myTimer:Timer = new Timer(500, 1);
myTimer.addEventListener("timer",setSTart );
myTimer.start();
function setSTart(ev){
funcLife();
funcBar();
stage.addEventListener(Event.ENTER_FRAME,useEraser);
}
}
//----------------------------------------------------------------------------------------------------
private function funcBar(){
mcBar=new Sprite();
mcBar.graphics.beginFill(0x72BB72,1);
mcBar.graphics.drawRoundRect(0,0,120,50,50);
mcBar.y=450;
mcBar.x=0;
addChild(mcBar);
ckLife=true;funcBall();
stage.addEventListener(MouseEvent.MOUSE_MOVE, function(e){
if((_LEFTbar<mouseX)&&(mouseX<_RIGHTbar)){mcBar.x=mouseX-mcBar.width/2;}
});
stage.addEventListener(MouseEvent.MOUSE_UP, function(e){if(ckLife==true){ckLife=false;}});
}
private function funcBall(){
mcBall=new Sprite();
mcBall.graphics.lineStyle(2,0xFFFFFF,1)
mcBall.graphics.beginFill(0xFF6975,1);
mcBall.graphics.drawCircle(0,0,10);
addChild(mcBall);
mcBall.addEventListener(Event.ENTER_FRAME, function(e){
if(ckLife==false){
ckWall();ckBar();
mcBall.y+=(yy*SPEED);
mcBall.x+=(xx*SPEED);
}
if(ckLife==true){
mcBall.y=420;
mcBall.x=mcBar.x+60;
}
});
}
private function funcLife(){
for (var j:int=0; j <maxLife; j++){
var mcLife:drawHeart=new drawHeart();
mcLife.scaleX=mcLife.scaleY=2.5;
mcLife.y=30;
mcLife.x=320+j*30;
arrayLife.push(mcLife);
addChild(mcLife);
}
}
private function ckWall(){
if(mcBall.y<_UE){yy=1;xx*=Math.random()*3;}
else if(mcBall.y>_SITA){damage();}
else if(mcBall.x<_LEFT){xx=1;}
else if(mcBall.x>_RIGHT){xx=-1;}
}
private function ckBar(){var arr=[null,null,null,null,null,1,2,3,4,5];
if(mcBall.y>445&&mcBall.x>mcBar.x&&mcBall.x<mcBar.x+mcBar.width){
yy=-1;
var par=Math.floor((mcBall.x-mcBar.x)/12);
if(par<6){xx=par*-1;}else{xx=arr[par];}
}
}
private function damage(){
if(cntLife!=maxLife){
arrayLife[cntLife].alpha=0;
ckLife=true;
cntLife++;
}
}
}
}
import flash.display.*;
import flash.filters.BlurFilter;
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
class blush_image extends Sprite{
private var arrW=[100,120,100,100,150,100,100,80,100,150,220];
private var arrH=[80,96,80,80,120,80,80,80,80,80,180];
function blush_image(arg:int){
var ww:uint=arrW[arg];
var hh:uint=arrH[arg];
graphics.beginFill(0x222222);
graphics.drawEllipse(0,0,ww,hh);
filters = [ new BlurFilter(5,5,2) ] ;
}}
class eraze_image extends MovieClip{
function eraze_image(){
graphics.beginFill(0x222222);
graphics.drawCircle(10,10,10);
}}
class drawHeart extends Sprite{
public function drawHeart(){
var arr:Array=[150,-150];
for(var j:int=0; j < 2; j++){
var _sp:Sprite = new Sprite();
_sp.graphics.beginFill(0xFCC4AD);
_sp.graphics.drawEllipse(-2,-1,4,10);
_sp.graphics.endFill();
_sp.rotation=arr[j];
addChild(_sp);
}
}
}