simple player for gamediscs
This commit is contained in:
parent
5168b64a4c
commit
4acdc4cd6d
51
src/GamePlayer.as
Normal file
51
src/GamePlayer.as
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package
|
||||||
|
{
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.events.Event;
|
||||||
|
import flash.events.MouseEvent;
|
||||||
|
import flash.geom.Point;
|
||||||
|
/**
|
||||||
|
* ...
|
||||||
|
* @author jjp
|
||||||
|
*/
|
||||||
|
public class GamePlayer extends Sprite
|
||||||
|
{
|
||||||
|
private var videotube:Videotube;
|
||||||
|
private var gamedisc:Gamedisc;
|
||||||
|
private var clickarea:ClickArea;
|
||||||
|
public function GamePlayer(videotube:Videotube, gamedisc:Gamedisc)
|
||||||
|
{
|
||||||
|
this.videotube = videotube;
|
||||||
|
this.gamedisc = gamedisc;
|
||||||
|
clickarea = null;
|
||||||
|
addEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
|
}
|
||||||
|
private function init(e:Event):void
|
||||||
|
{
|
||||||
|
removeEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
|
addEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
||||||
|
stage.addEventListener(MouseEvent.CLICK, onClick);
|
||||||
|
videotube.addEventListener(EventQte.QTE, onQte);
|
||||||
|
}
|
||||||
|
private function cleanup(e:Event):void
|
||||||
|
{
|
||||||
|
removeEventListener(Event.REMOVED_FROM_STAGE, cleanup);
|
||||||
|
stage.removeEventListener(MouseEvent.CLICK, onClick);
|
||||||
|
videotube.removeEventListener(EventQte.QTE, onQte);
|
||||||
|
}
|
||||||
|
private function onQte(e:EventQte):void
|
||||||
|
{
|
||||||
|
clickarea = new ClickArea(e.qte.rgpoint, 0xffff00, 0.7);
|
||||||
|
addChild(clickarea);
|
||||||
|
}
|
||||||
|
private function onClick(mouse:MouseEvent):void
|
||||||
|
{
|
||||||
|
if (clickarea != null && clickarea.FHit(new Point(mouse.stageX, mouse.stageY)))
|
||||||
|
{
|
||||||
|
removeChild(clickarea);
|
||||||
|
clickarea = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
src/Main.as
35
src/Main.as
|
@ -2,8 +2,10 @@ package
|
||||||
{
|
{
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
import flash.geom.Point;
|
import flash.geom.Point;
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ...
|
* ...
|
||||||
|
@ -14,6 +16,7 @@ package
|
||||||
private var videotube:Videotube;
|
private var videotube:Videotube;
|
||||||
private var gamedisc:Gamedisc;
|
private var gamedisc:Gamedisc;
|
||||||
private var gameeditor:GameEditor;
|
private var gameeditor:GameEditor;
|
||||||
|
private var gameplayer:GamePlayer;
|
||||||
|
|
||||||
public function Main():void
|
public function Main():void
|
||||||
{
|
{
|
||||||
|
@ -27,10 +30,38 @@ package
|
||||||
{
|
{
|
||||||
removeEventListener(Event.ADDED_TO_STAGE, init);
|
removeEventListener(Event.ADDED_TO_STAGE, init);
|
||||||
// entry point
|
// entry point
|
||||||
gameeditor = new GameEditor(videotube, gamedisc);
|
|
||||||
addChild(videotube);
|
addChild(videotube);
|
||||||
|
toggleGame();
|
||||||
|
stage.addEventListener(KeyboardEvent.KEY_UP, onKey);
|
||||||
|
videotube.play();
|
||||||
|
}
|
||||||
|
private function toggleGame():void
|
||||||
|
{
|
||||||
|
if (gameeditor == null)
|
||||||
|
{
|
||||||
|
if (gameplayer != null)
|
||||||
|
{
|
||||||
|
removeChild(gameplayer);
|
||||||
|
gameplayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
gameeditor = new GameEditor(videotube, gamedisc);
|
||||||
addChild(gameeditor);
|
addChild(gameeditor);
|
||||||
videotube.stream.play(gamedisc.urlVideo);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
removeChild(gameeditor);
|
||||||
|
gameeditor = null;
|
||||||
|
|
||||||
|
gameplayer = new GamePlayer(videotube, gamedisc);
|
||||||
|
addChild(gameplayer);
|
||||||
|
}
|
||||||
|
videotube.stream.seek(0);
|
||||||
|
}
|
||||||
|
private function onKey(key:KeyboardEvent):void
|
||||||
|
{
|
||||||
|
if (key.keyCode == Keyboard.SPACE)
|
||||||
|
toggleGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue