未完成品:SRPG戦闘シーンのようなもの
前に作ったいくつかを一つにまとめただけです。肝心のキャラクターの移動だったり戦闘だったりが出来ていません。
右下の矢印と◯でカメラ位置が変わるのと、長方形のキャラをクリックでメニューが出るだけです。
コード汚い('A`)ヴァー
http://blog.livedoor.jp/link_w/archives/51208072.html
ブログの方でも少し解説しています
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vYFg
*/
// forked from ton_'s 大差はない
package {
import flash.display.DisplayObject;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.objects.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import caurina.transitions.Tweener;
import flash.events.*;
[SWF(backgroundColor = 0xefdfff)]
public class mf extends BasicView {
//
//
//cube格納用オブジェクト
private var field:DisplayObject3D;
//表面用と下部用のcube
private var ucube:Cube;
private var dcube:Cube;
//cubeの縦横高さとcube間の長さ;
private var wide:int = 50;
private var high:int =20;
private var dx:int = 5;
//cubeの色指定配列:cubes[x軸][z軸]
//数値は0x[uColor][dColor][hCube]に対応している
//uColor=上部の色;dColor = 下部の色;hCube = cubeの高さ(hCube*high)
private var cubes:Array = [[0x015,0x014,0x012,0x112,0x113],
[0x014,0x012,0x111,0x210,0x220],
[0x012,0x111,0x210,0x220,0x220],
[0x013,0x112,0x112,0x210,0x220],
[0x014,0x013,0x113,0x220,0x220],
];
//cube用colormaterial;実際に使うのはcubeMat配列のみ
private var gr:ColorMaterial = new ColorMaterial(0x60ff60);
private var br:ColorMaterial = new ColorMaterial(0xd0a080);
private var bl:ColorMaterial = new ColorMaterial(0x50b0ff);
private var g:MaterialsList = new MaterialsList( { all:gr } );
private var l:MaterialsList = new MaterialsList( { all:br } );
private var b:MaterialsList = new MaterialsList( { all:bl } );
private var cubeMat:Array = [g,l,b];
//
//
//plane格納用オブジェクト
private var chara:DisplayObject3D;
//charaの管理配列と通し番号用変数
private var c:Array = new Array();
private var charaNo:int = 0;
private var plane:Plane;
//Plane用material;実際に使うのはplaneMat配列のみ
private var aka:WireframeMaterial = new WireframeMaterial(0xcc0000,3);
private var ao:WireframeMaterial = new WireframeMaterial(0x0000dd,3);
private var midori:WireframeMaterial = new WireframeMaterial(0x00cc00,3);
private var planeMat:Array = [aka,ao,midori];
//planeの配置;1=akaPlane,2=aoPlane,3=midoriPlane;
private var haiti:Array = [[1,1,0,0,2],
[0,1,0,0,0],
[1,0,0,0,0],
[0,0,0,0,3],
[2,2,0,0,0],
];
//
//
//土台baseと軸表示plane
private var baseColor:ColorMaterial = new ColorMaterial(0x8a5040);
private var baseMat:MaterialsList = new MaterialsList({all:baseColor});
private var base:Cube;
private var planeColor:ColorMaterial = new ColorMaterial(0x000000,0.2);
private var planeX:Plane;
private var planeY:Plane;
private var planeZ:Plane;
//ウインドウ作成用
private var mado:Mado;
private var ma:int = 0;
//視点切り替え用
private var ya:yazirusi;
private var rad:int = 30;
private var d:int = 400;
//文章表示用
private var bunsyo:Bunsyo;
private var bunsyo2:Bunsyo;
private var bunsyo3:Bunsyo;
//constructer
public function mf() {
//ウインドウの設定
super(465,465,true,true);
for(var m:int=0;m<planeMat.length;m++){
planeMat[m].interactive = true;
}
//文章の表示
bunsyo = new Bunsyo("説明:右の矢印キーでカメラ位置を変更できます。");
stage.addChild(bunsyo);
bunsyo.x = 10;
bunsyo.y = 380;
bunsyo2 = new Bunsyo("説明2:各Planeクリックでメニューが出ます。 ");
stage.addChild(bunsyo2);
bunsyo2.x = 10;
bunsyo2.y = 400;
bunsyo3 = new Bunsyo(" :メニューは閉じる以外は未実装('A') ");
stage.addChild(bunsyo3);
bunsyo3.x = 10;
bunsyo3.y = 420;
//init
init();
}
private function init():void{
for(var m:int = 0;m<planeMat.length; m++){
planeMat[m].doubleSided = true;
}
field = new DisplayObject3D;
chara = new DisplayObject3D;
scene.addChild(field);
scene.addChild(chara);
for(var i:int = 0; i<cubes.length; i++){
for(var j:int = 0; j<cubes[i].length; j++){
var ucolor:int = cubes[i][j] >> 8 & 0xF;
var dcolor:int = cubes[i][j] >> 4 & 0xf;
var h:int = cubes[i][j] & 0xF;
//Fieldの作成
ucube = new Cube(cubeMat[ucolor],wide,wide,high/2);
dcube = new Cube(cubeMat[dcolor],wide,wide,(h+1)*high);
ucube.x = dcube.x = -((wide+dx)*Math.floor(cubes.length/2)) + ((wide+dx)*i);
ucube.z = dcube.z = -((wide+dx)*Math.floor(cubes[i].length/2)) + ((wide+dx)*j);
dcube.y = ((h+1)*high)/2;
ucube.y = dcube.y*2 + high/4;
field.addChild(ucube,"UC_x"+i+"z"+j);
field.addChild(dcube,"DC_x"+i+"z"+j);
//charaの追加
//ここまだ代数にしてない
if(haiti[i][j] != 0){
plane = new Plane(planeMat[haiti[i][j]-1],40,60,4,8);
plane.x = -((wide+dx)*Math.floor(cubes.length/2)) + ((wide+dx)*i);
plane.z = -((wide+dx)*Math.floor(cubes[i].length/2)) + ((wide+dx)*j);
plane.y = ucube.y + 55;
plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,oOC);
c[charaNo] = plane;
chara.addChild(c[charaNo], "CHARA_"+charaNo);
charaNo +=1;
}
}
}
//baseと軸planeの追加
base = new Cube(baseMat,(wide+dx)*cubes.length-dx,(wide+dx)*cubes[0].length-dx,10);
base.y = -high/2;
scene.addChild(base);
/*
planeColor.doubleSided = true;
planeX = new Plane(planeColor,500,500);
planeX.rotationY = 90;
scene.addChild(planeX);
*/
planeY = new Plane(planeColor,500,500);
planeY.rotationX = 90;
scene.addChild(planeY);
/*
planeZ = new Plane(planeColor,500,500);
scene.addChild(planeZ);
*/
//camera.x = 400;
camera.y = 250;
camera.z = -400;
//視点切り替え用
ya = new yazirusi();
stage.addChild(ya);
ya.x = 400;
ya.y = 400;
camera.y = 300;
camera.z = -d*Math.cos(rad*Math.PI/180);
camera.x = d*Math.sin(rad*Math.PI/180);
for(var yan:int; yan<ya.ya.length; yan++){
ya.ya[yan].addEventListener(MouseEvent.CLICK,oMC2);
}
ya.maru.addEventListener(MouseEvent.CLICK,oMC2);
//ここまで
startRendering();
}
//-----以下メニューウインドウ制御用-----
private function oOC(e:Event):void{
if(ma == 1){
removeChild(mado);
ma = 0;
}
if(ma == 0){
mado = new Mado();
mado.x = mouseX;
mado.y = mouseY;
addChild(mado);
mado.buttons[2].addEventListener(MouseEvent.CLICK,oMC);
ma = 1;
}
}
private function oMC(e:Event):void{
if(ma==1){
removeChild(mado);
ma = 0;
}
}
//-----ここまで-----
//-----以下視点切り替え用-----
private function oMC2(e:MouseEvent):void{
switch (e.target.name) {
case "0":
rad += -90;
Tweener.addTween(camera,{
z: -d*Math.cos(rad*Math.PI/180),
time: 2,
transition: "easeInOutSine"
});
Tweener.addTween(camera,{
x: d*Math.sin(rad*Math.PI/180),
time: 2,
transition: "easeInOutSine"
});
break;
case "1":
if(camera.y == 300){
Tweener.addTween(camera,{
y: 450,
time: 1,
transition: "easeInOutSine"
});
}
break;
case "2":
rad += 90;
Tweener.addTween(camera,{
z: -d*Math.cos(rad*Math.PI/180),
time: 2,
transition: "easeInOutSine"
});
Tweener.addTween(camera,{
x: d*Math.sin(rad*Math.PI/180),
time: 2,
transition: "easeInOutSine"
});
break;
case "3":
if(camera.y == 450){
Tweener.addTween(camera,{
y: 300,
time: 1,
transition: "easeInOutSine"
});
}
break;
case "4":
if(d == 400){
d = 600;
}else {
d = 400;
}
Tweener.addTween(camera,{
z: -d*Math.cos(rad*Math.PI/180),
time: 1,
transition: "easeInOutSine"
});
Tweener.addTween(camera,{
x: d*Math.sin(rad*Math.PI/180),
time: 1,
transition: "easeInOutSine"
});
break;
default:
}
}
//-----ここまで-----
}
}
//-----以下メニューウインドウ制御用-----
import flash.display.Sprite;
import flash.events.*;
class Mado extends Sprite{
public var buttons:Array = new Array();
public var txt:Array = ["移動","たたかう","閉じる"];
public var tf:mozi;
private var sprite:Sprite;
public var spr1:Sprite;
public var spr2:Sprite;
public function Mado(){
init();
}
private function init():void{
//下地の描画
graphics.lineStyle(0,0xfadfbf);
graphics.beginFill(0xfadfbf);
graphics.drawRoundRect(0,0,100,120,5,5);
graphics.endFill();
graphics.lineStyle(2,0xba9f7f);
graphics.moveTo(3,3);
graphics.lineTo(97,3);
graphics.moveTo(3,113);
graphics.lineTo(97,113);
graphics.moveTo(3,117);
graphics.lineTo(97,117);
for(var i:int = 0; i<3; i++){
sprite = new Sprite();
sprite.graphics.lineStyle(1,0xff9999,0.3);
sprite.graphics.beginFill(0xff9999,0.3);
sprite.graphics.drawRect(5,8,90,30);
sprite.graphics.endFill();
addChild(sprite);
sprite.y = i*34;
//以下を書くとテキスト上でもハンドカーソルになる
sprite.mouseChildren = false;
tf = new mozi(txt[i]);
sprite.addChild(tf);
sprite.buttonMode = true;
buttons[i] = sprite;
}
}
}
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
class mozi extends TextField{
private var tf:TextFormat = new TextFormat();
public function mozi(txt:String){
width = 80;
height = 30;
y = 13;
x = 2;
autoSize = TextFieldAutoSize.LEFT
tf.size = 24;
tf.color = 0x000000;
defaultTextFormat = tf;
text = txt;
}
}
//-----ここまで-----
//-----以下カメラ視点移動用-----
import flash.display.Sprite;
import flash.events.MouseEvent;
class yazirusi extends Sprite{
public var ya:Array = new Array();
public var maru:Sprite;
public function yazirusi(){
init();
}
private function init():void{
graphics.lineStyle(3,0x444444);
graphics.beginFill(0xffffff,0.5);
graphics.drawCircle(0,0,40);
graphics.lineStyle(5,0xff9999);
graphics.beginFill(0x999999,0.5);
graphics.drawCircle(0,0,32);
graphics.endFill();
for(var i:int =0; i<4; i++){
var spr:Sprite = new Sprite();
spr.graphics.lineStyle(1);
spr.graphics.beginFill(0xff0000);
spr.graphics.moveTo(-28,0);
spr.graphics.lineTo(-12,-7);
spr.graphics.lineTo(-12,7);
spr.graphics.lineTo(-28,0);
spr.graphics.endFill();
spr.rotation = 90 * i;
addChild(spr);
spr.buttonMode = true;
spr.name = String(i);
ya[i] = spr;
ya[i].addEventListener(MouseEvent.CLICK,oMC);
}
maru = new Sprite();
maru.graphics.lineStyle(1);
maru.graphics.beginFill(0xff0000);
maru.graphics.drawCircle(0,0,7);
maru.graphics.endFill();
addChild(maru);
maru.buttonMode = true;
maru.name = String(4);
}
private function oMC(e:MouseEvent):void{
}
}
//-----ここまで-----
//-----以下文章表示用-----
import com.actionscriptbible.Example;
class Bunsyo extends Example{
public function Bunsyo(str:String){
trace("-",str,"-");
}
}
//-----ここまで-----