simple player for gamediscs

This commit is contained in:
Jeremy Penner 2011-05-03 23:01:19 -07:00
parent 5168b64a4c
commit 4acdc4cd6d
2 changed files with 85 additions and 3 deletions

51
src/GamePlayer.as Normal file
View 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;
}
}
}
}

View file

@ -2,8 +2,10 @@ package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.ui.Keyboard;
/**
* ...
@ -14,6 +16,7 @@ package
private var videotube:Videotube;
private var gamedisc:Gamedisc;
private var gameeditor:GameEditor;
private var gameplayer:GamePlayer;
public function Main():void
{
@ -27,10 +30,38 @@ package
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
gameeditor = new GameEditor(videotube, gamedisc);
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);
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();
}
}
}