3D Flash Engine

Senin, 27 Juli 2009





That's the Top Down 3D in Flash 10
very easy

The File:

Main Class:

package waza
{
import flash.display.Sprite;
import flash.display.MovieClip;

import waza.Wazaman;
import waza.Wazatree;
import Land;
import Smallship;
import Trees;
public class Wazawaza extends Sprite
{
public static var instance:Wazawaza;
protected var sea :Sea;
protected var con :Sprite;
protected var world :Sprite;
protected var land :Land;
protected var wazas :Array;
public function Wazawaza ()
{
sea = new Sea();
this.addChild(sea);
land = new Land();
world = new Sprite();
world.x = 300;
world.y = 200;
world.z = 300;
world.rotationZ = 100;
world.addChild (land);
con = new Sprite();
con.rotationX = -25;
con.addChild (world);
this.addChild (con);
wazas = new Array();
var i:int = -1;
var s:Smallship;
while (++i <>
{
s = new Smallship();
s.x = (Math.random()-0.5) * 600;
s.y = (Math.random()-0.5) * 600;
s.z = Math.random() * 10;
s.rotationZ = Math.floor(Math.random()*360);
world.addChild (s);
}
world.addChild(new Trees());
i = -1
var w:Wazaman;
while (++i <>
{
w = new Wazaman();
w.x = (Math.random()-0.5) * 400;
w.y = (Math.random()-0.5) * 400;
w.z = Math.random() * 10;
world.addChild (w);
wazas.push(w);
}
Wazawaza.instance = this;
this.addEventListener(Event.ENTER_FRAME, updateAll);
}
public function checkVisibility (o:*):void
{
o.visible = o.hitTestObject(sea);
}
protected function updateAll(e:Event):void
{
var w:Wazaman;
for each(w in wazas) w.update();
world.x = 300-wazas[0].x;
world.y = 200-wazas[0].y;
if (world.z > 1)
{
world.z-=3;
world.rotationZ--;
}
}
}
}


The Wazaman:

package waza
{
import flash.display.MovieClip;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.filters.DropShadowFilter;
import waza.Wazawaza;
public class Wazaman extends MovieClip
{
protected var vx:Number;
protected var vy:Number;
protected var cn:int;
protected var cr:Number;
public function Wazaman()
{
bfan.rotationZ = 90;
wazaLeg.z = bfan.z = -5;
rot = Math.random()*360;
cn = 0;
cr = 3;
this.filters = [new DropShadowFilter(50, 45, 0, 0.8, 5, 5, 1.0)];
}
public function get rot():Number { return this.rotationZ; }
public function set rot(n:Number)
{
rotationZ = (n + 360) % 360;
var deg:Number = this.rotationZ*Math.PI/180;
vx = Math.sin(deg);
vy = Math.cos(deg);
}
public function update():void
{
wazaLeg.rotationZ+= 15;
this.x += vx * 5;
this.y -= vy * 5;
Wazawaza.instance.checkVisibility(this);
rot += cr;
cn++;
if (cn == 120)
{
cr *= -1;
cn = 0;
}
}
}
}

The Wazatree:

package waza
{
import flash.display.MovieClip;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.filters.DropShadowFilter;
public class Wazatree extends MovieClip
{
public function Wazatree()
{
this.filters = [new DropShadowFilter(10)];
this.rotationZ = Math.floor(Math.random()*360);
}
}
}

With those simple classes:
abra cadabra...

Too bad this block can not uploading flash (swf)

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda