Roku : Man of Steel
forked from 某鋼板は256回攻撃しても破壊できないので避けてください (diff: 294)
ActionScript3 source code
/**
* Copyright amyneon ( http://wonderfl.net/user/amyneon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uPXr
*/
// forked from siouxcitizen's 某鋼板は256回攻撃しても破壊できないので避けてください
// forked from heart_thai's Roku Shooting Version
// forked from buccchi's オッス、おらロク!(墨エフェクト)
// forked from buccchi's オッス、おらロク!
//某鋼板は256回攻撃しても破壊できないので避けてください
//ロクと某鋼板が衝突すると画面がとまります
//最初の読み込み時少し重いです
//hitTestObjectがうまく機能しなかったので平方根によるテキトーな当たり判定してます。。。
//交差判定による当たり判定とかのほうが正確に判定できる???
/**
* 画面クリックで輪郭線表示+ズーム+スロー再生
* 再度クリックで元に戻ります
*
* ロク(猫)の写真はこちら
* http://www.flickr.com/photos/40441900@N08/
* Blenderでモデリング
*/
package {
import flash.display.*;
import flash.events.*;
import flash.net.NetStream;
import flash.system.Security;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.utils.getTimer;
import flash.events.TimerEvent;
import frocessing.color.ColorHSV;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
import net.hires.debug.Stats;
import org.papervision3d.core.geom.Pixels;
import org.papervision3d.core.geom.renderables.Pixel3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.layer.BitmapEffectLayer;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
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.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.lights.PointLight3D;
public class FlashTest extends Sprite {
private var mountens:Vector.<DAE>;
private var steelPlates:Vector.<Cube>;
private var powers:Vector.<Sphere>
private var roku:DAE;
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 flatShadeMate:FlatShadeMaterial;
private var materials:MaterialsList;
private const COLLISION_DIST : int = 30; //ロクと鋼板Cubeとの当たり判定用距離
private const PLATE_SIZE : int = 120; //鋼板Cubeの一辺のサイズ
private const PLATE_THICK : int = 5; //鋼板Cubeの厚さ
// button
private var wonderflcolor:WonderflColor;
private var panel:Sprite;
private var fullscreenBtn:Btn;
private var normalBtn:Btn;
public function FlashTest():void {
//addChild( new Stats() );
scene = new Scene3D();
camera = new Camera3D();
rd = new BasicRenderEngine();
vp = new Viewport3D(stage.stageWidth , stage.stageHeight );
addChild(vp);
camera.zoom = 50;
//光源設定
light = new PointLight3D();
light.y = -8000;
light.x = -8000;
light.z = -8000;
//鋼板用マテリアル設定
flatShadeMate = new FlatShadeMaterial(light, 0xdddddd, 0x555555);
flatShadeMate.doubleSided = true;
materials = new MaterialsList(
{front:flatShadeMate,back:flatShadeMate,right:flatShadeMate,left:flatShadeMate,top:flatShadeMate,bottom:flatShadeMate});
createMouten();
createSteelPlate();
createRoku();
camera.y = 100;
powers = new Vector.<Sphere>();
tm = new Timer(200);
tm.addEventListener(TimerEvent.TIMER , shotting );
//wonderflcolor
wonderflcolor = new WonderflColor(465, 465);
addChild(wonderflcolor);
// sprite for the button
panel = new Sprite();
addChild(panel);
panel.x = 232;
panel.y = 445;
// fullscreen Bouton
fullscreenBtn = new Btn();
panel.addChild(fullscreenBtn);
fullscreenBtn.x = 0;
fullscreenBtn.init({label: "full screen", width: 100});
fullscreenBtn.addEventListener(MouseEvent.CLICK, click, false, 0, true);
// normal Bouton
normalBtn = new Btn();
panel.addChild(normalBtn);
normalBtn.x = 0;
normalBtn.init({label: "normal", width: 100});
normalBtn.addEventListener(MouseEvent.CLICK, click, false, 0, true);
normalBtn.visible = false;
stage.addEventListener(Event.RESIZE, update, false, 0, true);
this.addEventListener(Event.ENTER_FRAME , loop);
stage.addEventListener(MouseEvent.MOUSE_DOWN , shot );
stage.addEventListener(MouseEvent.MOUSE_UP , stopShot );
}
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 = roku.x;
p.y = roku.y;
p.z = roku.z;
scene.addChild(p);
powers.push(p);
}
private function createMouten():void {
mountens = new Vector.<DAE>();
for(var i:int = 0 ; i<=20 ; i++){
var mountain:DAE = new DAE();
mountain.load("http://7980.oui-imja.com/wonderfl/201002/mountain.dae");
scene.addChild(mountain);
mountain.y = -100;
mountain.scale = 10;
mountain.x = 1000-(Math.random()*2000);
mountain.z = 1000 - (Math.random() * 2000);
mountens.push(mountain);
}
}
private function createSteelPlate():void {
steelPlates = new Vector.<Cube>();
for(var i:int = 0 ; i<=1 ; 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 createRoku():void{
roku = new DAE();
roku.load("http://7980.oui-imja.com/wonderfl/201002/roku.dae");
scene.addChild(roku);
roku.scale = 20;
roku.rotationY = 90;
roku.z = -700;
}
private function loop(event:Event):void {
if(gameOver){return;} //ゲームオーバー時は処理をストップ
var sx:Number = (mouseX-(stage.stageWidth/2)) - roku.x;
roku.x += sx/10;
for (var i:String in mountens) {
mountens[i].z -= 50;
if (mountens[i].z < -1000) {
mountens[i].z = 1000;
mountens[i].x = 1000-(Math.random()*2000);
}
}
for (i in steelPlates) {
steelPlates[i].z -= 50;
steelPlates[i].rotationX -= 20;
if (checkCollision(roku.x,roku.z,(steelPlates[i].x+(PLATE_SIZE/4)),steelPlates[i].z)) {
gameOver = true;
return;
}
if (steelPlates[i].z < -1000) {
steelPlates[i].z = 1000;
steelPlates[i].x = 1000-(Math.random()*2000);
}
}
for (i in powers) {
powers[i].z += 150;
if (powers[i].z > 5000) {
scene.removeChild(powers[i]);
powers.splice(int(i), 1);
}
}
rd.renderScene(scene , camera, vp);
}
private function checkCollision(rokuX:int,rokuZ:int,cubX:int,cubZ:int):Boolean {
//平方根を用いてロクとと鋼板Cubeとの距離を計算
var dist : Number = Math.sqrt(Math.pow(rokuX-cubX,2)+Math.pow(rokuZ-cubZ,2));
if (dist > COLLISION_DIST) {
return false;
} else {
return true;
}
}
private function update(evt:Event = null):void {
var sw:uint = stage.stageWidth;
var sh:uint = stage.stageHeight;
panel.x = sw/2;
panel.y = sh - 20;
wonderflcolor.width = sw;
wonderflcolor.height = sh;
if (stage.displayState == StageDisplayState.FULL_SCREEN) {
fullscreenBtn.visible = false;
normalBtn.visible = true;
} else {
fullscreenBtn.visible = true;
normalBtn.visible = false;
}
}
private function click(evt:Event):void {
if (stage.displayState == StageDisplayState.NORMAL) {
stage.displayState = StageDisplayState.FULL_SCREEN;
} else {
stage.displayState = StageDisplayState.NORMAL;
}
}
}
}
//////////////////////////////////////////////////
// WonderflColorクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
class WonderflColor extends Sprite {
private var color1:uint = 0x00AAE4;
private var color2:uint = 0x0069A0;
public function WonderflColor(w:uint, h:uint) {
//draw(100,150); //draw(w, h);
}
}
//////////////////////////////////////////////////
// Btnクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.filters.GlowFilter;
import flash.events.MouseEvent;
class Btn extends Sprite {
public var id:uint;
private var shade:Shape;
private var bottom:Shape;
private var light:Shape;
private var base:Shape;
private var txt:TextField;
private var label:String = "";
private static var fontType:String = "_ゴシック";
private var _width:uint = 60;
private static var _height:uint = 20;
private static var corner:uint = 5;
private var type:uint = 1;
private static var bColor:uint = 0xFFFFFF;
private static var sColor:uint = 0x000000;
private static var upColor:uint = 0x666666;
private static var overColor:uint = 0x333333;
private static var offColor:uint = 0x999999;
private static var gColor:uint = 0x0099FF;
private var blueGlow:GlowFilter;
private var shadeGlow:GlowFilter;
private var _clicked:Boolean = false;
private var _enabled:Boolean = true;
public function Btn() {
}
public function init(option:Object):void {
if (option.id != undefined) id = option.id;
if (option.label != undefined) label = option.label;
if (option.width != undefined) _width = option.width;
if (option.type != undefined) type = option.type;
draw();
}
private function draw():void {
switch (type) {
case 1 :
bColor = 0xFFFFFF;
sColor = 0x000000;
upColor = 0x666666;
overColor = 0x333333;
offColor = 0x999999;
break;
case 2 :
bColor = 0x000000;
sColor = 0xFFFFFF;
upColor = 0x666666;
overColor = 0x999999;
offColor = 0x333333;
break;
}
blueGlow = new GlowFilter(gColor, 0.6, 5, 5, 2, 3, false, true);
shadeGlow = new GlowFilter(sColor, 0.3, 4, 4, 2, 3, false, true);
shade = new Shape();
bottom = new Shape();
light = new Shape();
base = new Shape();
txt = new TextField();
addChild(shade);
addChild(bottom);
addChild(light);
addChild(base);
addChild(txt);
createBase(shade, _width, _height, corner, sColor);
shade.filters = [shadeGlow];
createBase(bottom, _width, _height, corner, sColor, 0.3);
createBase(light, _width, _height, corner, gColor);
light.filters = [blueGlow];
createBase(base, _width, _height, corner, bColor);
txt.x = -_width*0.5;
txt.y = -_height*0.5;
txt.width = _width;
txt.height = _height - 1;
txt.type = TextFieldType.DYNAMIC;
txt.selectable = false;
//txt.embedFonts = true;
//txt.antiAliasType = AntiAliasType.ADVANCED;
var tf:TextFormat = new TextFormat();
tf.font = fontType;
tf.size = 12;
tf.align = TextFormatAlign.CENTER;
txt.defaultTextFormat = tf;
txt.text = label;
enabled = true;
mouseChildren = false;
}
private function rollOver(evt:MouseEvent):void {
_over();
}
private function rollOut(evt:MouseEvent):void {
_up();
}
private function press(evt:MouseEvent):void {
_down();
}
private function release(evt:MouseEvent):void {
_up();
}
private function click(evt:MouseEvent):void {
}
private function _up():void {
txt.y = -_height*0.5;
txt.textColor = upColor;
base.y = -1;
light.visible = false;
light.y = -1;
}
private function _over():void {
txt.y = -_height*0.5;
txt.textColor = overColor;
base.y = -1;
light.visible = true;
light.y = -1;
}
private function _down():void {
txt.y = -_height*0.5 + 1;
txt.textColor = overColor;
base.y = 0;
light.visible = true;
light.y = 0;
}
private function _off():void {
txt.y = -_height*0.5 + 1;
txt.textColor = offColor;
base.y = 0;
light.visible = false;
light.y = 0;
}
public function get clicked():Boolean {
return _clicked;
}
public function set clicked(param:Boolean):void {
_clicked = param;
enabled = !_clicked;
if (_clicked) {
_down();
} else {
_up();
}
}
public function get enabled():Boolean {
return _enabled;
}
public function set enabled(param:Boolean):void {
_enabled = param;
buttonMode = _enabled;
mouseEnabled = _enabled;
useHandCursor = _enabled;
if (_enabled) {
_up();
addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
addEventListener(MouseEvent.MOUSE_DOWN, press, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
addEventListener(MouseEvent.CLICK, click, false, 0, true);
} else {
_off();
removeEventListener(MouseEvent.MOUSE_OVER, rollOver);
removeEventListener(MouseEvent.MOUSE_OUT, rollOut);
removeEventListener(MouseEvent.MOUSE_DOWN, press);
removeEventListener(MouseEvent.MOUSE_UP, release);
removeEventListener(MouseEvent.CLICK, click);
}
}
private function createBase(target:Shape, w:uint, h:uint, c:uint, color:uint, alpha:Number = 1):void {
target.graphics.beginFill(color, alpha);
target.graphics.drawRoundRect(-w*0.5, -h*0.5, w, h, c*2);
target.graphics.endFill();
}
}