In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Flint Study 4

study4 : play with MutualGravity
Get Adobe Flash player
by codeonwort 22 Sep 2011
  • Forked from codeonwort's Flint Study 3
  • Diff: 132
  • Related works: 5
  • Talk

    codeonwort at 21 Sep 2011 09:48
    Wonderfl's FLiNT version is too low. Current official version is 3.0.1 but wonderfl's flint version is 2.0.0. I wondered first time why addParticle appears not a method of Emitter class.
    gameegg at 21 Sep 2011 16:18
    오.. 파티클 엔진인가요?? 흥미롭네요.. +_+ 그런데 원더플에 내장된 엔진 버전은 원더플 관리자가 업데이트 해줘야 하나요?
    codeonwort at 21 Sep 2011 16:52
    그럴 겁니다 서버에 라이브러리 놔두고 컴파일할 때 경로 지정하는 방식일 테니
    gameegg at 21 Sep 2011 17:28
    그렇다면, 영원히 2.0.0에서 정지할수도 있는거군요..!
    codeonwort at 21 Sep 2011 18:19
    앙대 addParticle 쓰고 싶어요
    Embed
/**
 * Copyright codeonwort ( http://wonderfl.net/user/codeonwort )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/a2K4
 */

// forked from codeonwort's Flint Study 3
// forked from codeonwort's Flint Study 1
// forked from codeonwort's Flint Study 2
package {
    import flash.display.Shape;
    import flash.text.TextField;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.events.Event
    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.ui.Keyboard
    import flash.utils.setInterval
    import flash.utils.clearInterval
    
    import org.flintparticles.common.actions.*;
    import org.flintparticles.common.particles.*;
    import org.flintparticles.common.counters.*;
    import org.flintparticles.common.initializers.*;
    import org.flintparticles.common.displayObjects.*
    import org.flintparticles.twoD.actions.*;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.initializers.*;
    import org.flintparticles.twoD.renderers.*;
    import org.flintparticles.twoD.zones.*
    import org.flintparticles.twoD.particles.*;
    
    public class FlintTest4 extends Sprite {
        
        private var key:Object = {}
        private var player:Player
        private var emitter:Emitter2D
        private var itvID:int
        private var score:int = 0
        
        public function FlintTest4() {
            emitter = new Emitter2D
            
            // renderer
            var renderer:DisplayObjectRenderer = new DisplayObjectRenderer
            renderer.addEmitter(emitter)
            addChild(renderer)
            
            // initializers
            emitter.addInitializer( new ColorInit(0xff000000, 0xffff0000) )
            emitter.addInitializer( new ImageClass( Dot, 25 ) )
            emitter.addInitializer( new Position( new RectangleZone(150, 0, 465, 465) ) )
            
            // actions
            emitter.addAction( new Move );
            emitter.addAction( new MutualGravity( -1000, 10000, 50 ) )
            emitter.addAction( new CollisionZone( new RectangleZone( 0, 0, 465, 465 ) ) )
            
            // run
            emitter.counter = new Blast(5)
            emitter.start()
            itvID = setInterval(levelUp, 2000)
            
            addChild( player = new Player )
            player.x = player.y = player.radius
            
            addEventListener("enterFrame", gameLoop)
            stage.addEventListener("keyDown", kd)
            stage.addEventListener("keyUp", ku)
        }
        
        private function gameLoop(e:Event):void {
            if(isDown(Keyboard.LEFT)) player.x -= 7
            else if(isDown(Keyboard.RIGHT)) player.x += 7
            if(isDown(Keyboard.UP)) player.y -= 7
            else if(isDown(Keyboard.DOWN)) player.y += 7
            player.x = Math.max(10, Math.min(455, player.x))
            player.y = Math.max(10, Math.min(455, player.y))
            
            score ++
            
            // hit test
            var dx:Number, dy:Number
            for each(var p:Particle2D in emitter.particles){
                dx = p.x - player.x
                dy = p.y - player.y
                if(Math.sqrt(dx*dx + dy*dy) < (25 + player.radius)){
                    gameOver()
                }
            }
        }
        
        private function levelUp():void {
            var shape:Shape = new Shape
            shape.graphics.beginFill(0x0)
            shape.graphics.drawCircle(0, 0, 25)
            shape.x = 25 + Math.random() * 440
            shape.y = 25 + Math.random() * 440
            shape.alpha = 0
            addChild(shape)
            shape.addEventListener("enterFrame", particle_appearing)
            function particle_appearing(e:Object):void {
                shape.alpha += 0.05
                if(shape.alpha >= 1){
                    shape.removeEventListener("enterFrame", particle_appearing)
                    removeChild(shape)
                    var p:Particle2D = new Particle2D
                    emitter.addExistingParticles([p], true)
                    //emitter.addParticle(p, true)
                    p.x = shape.x
                    p.y = shape.y
                    p.collisionRadius = 25
                }
            }
        }
        
        private function gameOver():void {
            removeEventListener("enterFrame", gameLoop)
            for(;numChildren;)removeChildAt(0)
            var tf:TextField = new TextField
            tf.autoSize = "center"
            tf.x = tf.y = 465 / 2
            tf.text = "Game Over\nYour score is " + score
            tf.selectable = false
            addChild(tf)
            
            emitter.stop()
            clearInterval(itvID)
            player.alpha = .5
        }

        
        private function kd(e:KeyboardEvent):void {
            key[e.keyCode] = true
        }
        private function ku(e:KeyboardEvent):void {
            delete key[e.keyCode]
        }
        private function isDown(keyCode:uint):Boolean {
            return key[keyCode] != null
        }
        
    }
    
}

import flash.display.Shape
class Player extends Shape {
    public var radius:Number = 10
    public function Player() {
        with(graphics){
            lineStyle(1, 0x0)
            beginFill(0x123456)
            drawCircle(0, 0, radius)
        }
    }
}