一人エアホッケー(制作中)
/**
* Copyright 0rafu0 ( http://wonderfl.net/user/0rafu0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xc7g
*/
//一人エアホッケー
/*実装予定項目
●得点カウント機能
●リトライ機能
●オブジェクト指向っぽいような書き方
●
*/
package {
import flash.text.TextField;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var table:Sprite = new Sprite();
private var goal1:Sprite = new Sprite();
private var goal2:Sprite = new Sprite();
private var ball:Sprite = new Sprite();
private var ballX:int = 200;
private var ballY:int = 200;
private var ballSx:int = 3;
private var ballSy:int = 2;
public function FlashTest() {
// write as3 code here..
//台の模様?作成
with (table){
//graphics.beginFill(0x000000);
graphics.lineStyle(5,0x666688);
graphics.drawCircle(246,246,60);
graphics.moveTo(0,246);
graphics.lineTo(512,246);
}
with (ball){
graphics.lineStyle(8,0x222222);
graphics.drawCircle(0,0,8);
x= 150;
y= 150;
}
goal1.graphics.beginFill(0x666688);
goal1.graphics.drawRect(0,0,100,20);
goal2.graphics.beginFill(0xFF6666);
goal2.graphics.drawRect(0,400,100,20);
addChild(table);
addChild(goal1);
addChild(goal2);
addChild(ball);
stage.addEventListener(Event.ENTER_FRAME,mainLoop);
}
function mainLoop(e:Event){
moveBall();
moveBar();
reflect();
// gameEnd();
}
function moveBall():void{
ball.x += ballSx;
ball.y += ballSy;
if (ball.x < 0 ) ballSx *= -1;
if (ball.x > 450 ) ballSx *= -1;
if (ball.y < 0 ) ballSy *= -1;
if (ball.y > 430 ) ballSy *= -1;
}
function moveBar():void{
//バーを動かす処理
goal1.x= goal2.x= stage.mouseX -50;
}
function reflect():void{
if(ball.y<=20 && ball.y>=0 ){
if(ball.x > goal1.x && ball.x < goal1.x +200) {
ballSy *= -1.2;
}
}
if(ball.y>=400 && ball.y<=420){
if(ball.x > goal2.x && ball.x < goal2.x +200) ballSy *= -1.2;
}
}
}
}