前回よりダウングレードしてKongregate投稿用に作成したコードです
forked from ごまかし?当たり判定付きでROKUに復活してもらいました (diff: 91)
ActionScript3 source code
/**
* Copyright siouxcitizen ( http://wonderfl.net/user/siouxcitizen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iOi2
*/
// forked from siouxcitizen's ごまかし?当たり判定付きでROKUに復活してもらいました
//前回よりダウングレードしてKongregate投稿用に作成したコードです
//Kongregateに投稿するにあたって、自分作成でない3Dモデルを使わないように変更しました
//結果、使用しているのはPapervision3DのPrimitiveモデルだけに。。。
//ちなみにKongregate投稿先は、
//http://www.kongregate.com/games/siouxcitizen/simple-mini-shooting
//です
//
//操作方法
//・マウス左右操作で操作PaperPlaneオブジェクとが左右に移動
//・左クリック押下で攻撃弾発射
//攻撃弾で鋼板を破壊?する毎にSCOREに100ポイント加算となります
//操作PaperPlaneオブジェクがhitTestObject()による当たり判定で鋼板と衝突するとゲームオーバーとなります
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.PaperPlane;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.lights.PointLight3D;
import flash.text.*;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.utils.escapeMultiByte;
public class Main extends Sprite {
private var planeFields:Vector.<Plane>;
private var mountens:Vector.<DAE>;
private var steelPlates:Vector.<Cube>;
private var powers:Vector.<Sphere>
private var player:PaperPlane;
private var scene:Scene3D;
private var camera:Camera3D;
private var vp:Viewport3D;
private var rd:BasicRenderEngine;
private var tm:Timer;
private var gameOver:Boolean = false;
private var light:PointLight3D;
private var colorMate:ColorMaterial;
private var flatShadeMate:FlatShadeMaterial;
private var materials:MaterialsList;
private var score:int = 0;
private const PLATE_SIZE : int = 120; //鋼板Cubeの一辺のサイズ
private const PLATE_THICK : int = 5; //鋼板Cubeの厚さ
private var scoreTxt : TextField;//スコアテキスト
private var scoreTxtFormat : TextFormat;//スコアテキストフォーマット
private var gameOverTxt : TextField;//「ゲームオーバー」表示テキスト
private var gameOverTxtFormat : TextFormat;//「ゲームオーバー」表示テキストフォーマット
private var tweetBtn : CustomButton; //「ツイート」ボタン
private var restartBtn : CustomButton; //「リスタート」ボタン
public function Main():void {
scene = new Scene3D();
camera = new Camera3D();
rd = new BasicRenderEngine();
vp = new Viewport3D(stage.stageWidth , stage.stageHeight );
addChild(vp);
camera.zoom = 50;
//スコア文字列設定
scoreTxt = new TextField;
scoreTxt.text = "ButtonTest!";
scoreTxt.x = 370;
scoreTxt.y = 10;
scoreTxt.width = 100;
scoreTxt.multiline = true;
scoreTxt.text = "SCORE: " + score;
addChild(scoreTxt);
//スコア字列用フォーマット設定(デフォルト設定)
//scoreTxtFormat = new TextFormat();
//scoreTxtFormat.font = "Courier New";
//scoreTxtFormat.bold = true;
//scoreTxtFormat.size = 13;
//scoreTxt.setTextFormat(scoreTxtFormat);
//「GAME OVER」文字列設定
gameOverTxt = new TextField;
gameOverTxt.x = 55;
gameOverTxt.y = 170;
gameOverTxt.width = 400;
gameOverTxt.height = 200;
gameOverTxt.multiline = false;
gameOverTxt.text = "GAME OVER";
//addChild(gameOverTxt);
//「GAME OVER」字列用フォーマット設定
gameOverTxtFormat = new TextFormat();
gameOverTxtFormat.font = "Courier New";
gameOverTxtFormat.bold = true;
gameOverTxtFormat.size = 70;
gameOverTxt.setTextFormat(gameOverTxtFormat);
//光源設定
light = new PointLight3D();
light.y = -8000;
light.x = -8000;
light.z = -8000;
//フィールド用マテリアル設定
colorMate = new ColorMaterial(0x00aa00,0.5);
//鋼板用マテリアル設定
flatShadeMate = new FlatShadeMaterial(light, 0xdddddd, 0x555555);
flatShadeMate.doubleSided = true;
materials = new MaterialsList(
{front:flatShadeMate,back:flatShadeMate,right:flatShadeMate,left:flatShadeMate,top:flatShadeMate,bottom:flatShadeMate});
createPlaneFields();
createSteelPlate();
createPlayer();
camera.y = 120;
powers = new Vector.<Sphere>();
tm = new Timer(200);
tm.addEventListener(TimerEvent.TIMER , shotting );
tweetBtn = new CustomButton("Tweet");
tweetBtn.x = 110;
tweetBtn.y = 130;
tweetBtn.addEventListener(MouseEvent.MOUSE_DOWN,onTweetBtnDown);
restartBtn = new CustomButton("Restart");
restartBtn.x = 260;
restartBtn.y = 130;
restartBtn.addEventListener(MouseEvent.MOUSE_DOWN,onRestartBtnDown);
this.addEventListener(Event.ENTER_FRAME , loop);
stage.addEventListener(MouseEvent.MOUSE_DOWN , shot );
stage.addEventListener(MouseEvent.MOUSE_UP , stopShot );
}
private function onTweetBtnDown(e:MouseEvent):void {
var tweetMesseage:String = "Simple Mini Shooting -> Your SCORE: " + (score*100);
var post:String = tweetMesseage + " " + "http://www.kongregate.com/games/siouxcitizen/simple-mini-shooting" + " " + "#kongregate ";
//var post:String = "Simple Mini Shooting -> Your " + tweetMesseage;
//var post:String = tweetMesseage + " " + "http://wonderfl.net/c/3wEQt/" + " " + "#wonderfl ";
navigateToURL(new URLRequest("http://twitter.com/home?status=" + escapeMultiByte(post)), "_blank");
}
private function onRestartBtnDown(e:MouseEvent):void {
score = 0;
scoreTxt.text = "SCORE: " + (score*100);
gameOver = false;
removeChild(gameOverTxt);//「GAME OVER」文字列非表示
removeChild(tweetBtn);
removeChild(restartBtn);
}
private function shot(e:MouseEvent):void {
tm.start();
}
private function stopShot(e:MouseEvent):void {
tm.stop();
}
private function shotting(e:TimerEvent):void {
var c:ColorMaterial = new ColorMaterial(0xFF0000,0.5);
var p:Sphere = new Sphere( c , 50 );
p.x = player.x;
p.y = player.y;
p.z = player.z
scene.addChild(p);
powers.push(p);
}
private function createPlaneFields():void {
planeFields = new Vector.<Plane>();
for(var i:int = 0 ; i<=10 ; i++){
var planeField:Plane = new Plane(colorMate,2500,100,2,2);
scene.addChild(planeField);
planeField.rotationX = 90;
planeField.y = -100;
planeField.x = 100;
planeField.z = 1000 - (200*i);
planeFields.push(planeField);
}
}
private function createSteelPlate():void {
steelPlates = new Vector.<Cube>();
for(var i:int = 0 ; i<=2 ; i++){
var steelPlate:Cube = new Cube(materials,PLATE_SIZE,PLATE_THICK,PLATE_SIZE,1,1,1);
scene.addChild(steelPlate);
steelPlate.y = 100;
steelPlate.x = 1000-(Math.random()*2000);
steelPlate.z = 1000 - (Math.random() * 2000);
steelPlates.push(steelPlate);
}
}
private function createPlayer():void{
//var c:ColorMaterial = new ColorMaterial(0x0000FF, 0.7);
var w:WireframeMaterial = new WireframeMaterial(0xFF0000);
player= new PaperPlane(w);
player.scale = 1.5;
player.y = 50;
player.z = -500;
scene.addChild(player);
}
private function loop(event:Event):void {
if(gameOver){return;} //ゲームオーバー時は処理をストップ
var sx:Number = (mouseX-(stage.stageWidth/2)) - player.x;
player.x += sx/10;
for (var i:String in planeFields) {
planeFields[i].z -= 50;
if (planeFields[i].z < -1000) {
planeFields[i].z = 1000;
planeFields[i].x = 100;
}
}
for (var j:uint=0;j<powers.length;j++){
powers[j].z += 150;
if (powers[j].z > 5000) {
scene.removeChild(powers[j]);
//powers.splice(int(j), 1);
}
for (var k:uint=0;k<steelPlates.length;k++){
if(powers[j].hitTestObject(steelPlates[k])) {
scene.removeChild(powers[j]);
//powers.splice(int(j), 1);
steelPlates[k].z = 1000;
steelPlates[k].x = 1000-(Math.random()*2000);
score++;
scoreTxt.text = "SCORE: " + (score*100);
}
}
}
for (i in steelPlates) {
steelPlates[i].z -= 50;
steelPlates[i].rotationX -= 20;
if (player.hitTestObject(steelPlates[i])) {
steelPlates[i].z = 1000;
steelPlates[i].x = 1000-(Math.random()*2000);
gameOver = true;
addChild(gameOverTxt);//「GAME OVER」文字列表示
addChild(tweetBtn);
addChild(restartBtn);
return;
}
if (steelPlates[i].z < -1000) {
steelPlates[i].z = 1000;
steelPlates[i].x = 1000-(Math.random()*2000);
}
}
rd.renderScene(scene , camera, vp);
}
}
}
//■■■カスタムボタンクラス■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
import flash.display.*;
import flash.system.*;
import flash.text.*;
//カスタムボタン
class CustomButton extends SimpleButton {
private var btnName : String = "";//ボタン名
private var btnNo : int = 0;//ボタン番号
//コンストラクタ
public function CustomButton(label:String="",no:int=0) {
btnName = label;
btnNo = no;
//状態
upState = makeSprite(label,0x00ff00);
overState = upState;
downState = makeSprite(label,0x0000ff);
hitTestState = upState;
}
public function getBtnName():String {
return btnName;
}
public function getBtnNo():int {
return btnNo;
}
//ボタン用スプライト作成
private function makeSprite(text:String,color:uint):Sprite{
//ボタン用ラベル作成
var label : TextField = new TextField();
label.text = text;
label.autoSize = TextFieldAutoSize.CENTER;
label.selectable = false;
//ボタン用スプライト作成
var sp:Sprite = new Sprite();
sp.graphics.beginFill(color);
sp.graphics.drawRoundRect(0, 0, 100, 20, 15);
sp.graphics.endFill();
sp.alpha = 0.8;
sp.addChild(label);
//ラベル用フォーマット設定
var format:TextFormat=new TextFormat();
format.font = "Courier New";
format.bold = true;
format.size = 13;
label.setTextFormat(format);
return sp;
}
}
