Keyboard controls in fullscreen
forked from test (diff: 86)
Can you shoot while moving diagonally in all directions? use arrows to move and either space or tab to shoot. In my tests (on win XP and linux) space+left+up doesn't work, but tab key works fine with all diagonals. Would be nice if someone could test on a mac/vista/7 and with other keyboards (could be a hardware issue?). Arrows, space and tab are the only keys that work in fullscreen mode, so if arrows+tab work for everybody we might be able to write fullscreen shmups with reasonable performance (using fullScreenSourceRect). EDIT: What I mean to ask is: Is there anyone here for whom tab and arrow keys *don't* work? by 'work' I mean you can move in every direction (including diagonals) while firing, by pressing 1 or 2 arrow keys and the tab key in *any* order. And, if it doesn't work for you - * What are your specs? (player version, OS, keyboard make and model) * Do space and arrow keys work properly? Thanks. EDIT 2: http://www.sjbaker.org/wiki/index.php?title=Keyboards_Are_Evil
ActionScript3 source code
/**
* Copyright yonatan ( http://wonderfl.net/user/yonatan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5Bhx
*/
// forked from yonatan's test
package {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.ui.Keyboard;
import org.si.cml.*;
import org.si.cml.extensions.*;
import org.si.b3.*;
[SWF(frameRate="30")]
public class CMLObjectSample extends Sprite {
public var stageCML:String = "py-160[px$??*100n{{[rw]}vy$?*10+2i40v~bm$i?(5)+2,45f5vd-10}w60]";
function CMLObjectSample() {
addEventListener(Event.ADDED_TO_STAGE, _setup);
}
private function _setup(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, _setup);
mc = new CMLMovieClip(this, (465-W)/2, (465-H)/2, W, H, 0, true, _onFirstFrame);
mc.control.mapButtons(["SPACE", Keyboard.TAB], ["X","M"], ["C",","], ["V","."]);
}
private function _onFirstFrame():void {
var cmlMaster:CMLMaster = new CMLMaster;
cmlMaster.create(0, 0);
cmlMaster.execute(new CMLSequence(stageCML));
addEventListener("enterFrame", _onEnterFrame);
stage.fullScreenSourceRect = new Rectangle(0, 0, 465, 465);
var fs:FullScreenButton = new FullScreenButton(stage)
fs.x = (465-fs.width)/2;
addChild(fs);
}
private function _onEnterFrame(e:Event):void {
// hit check between shots and enemies
Actor.testf(shotFactory.evalIDNumber, enemyFactory.evalIDNumber);
// hit check between bullets and player
Actor.testf(playerFactory.evalIDNumber, bulletFactory.evalIDNumber);
// render
mc.screen.lock();
mc.clearScreen();
Actor.draw();
mc.screen.unlock();
}
}
}
import flash.display.*;
import org.si.cml.*;
import org.si.cml.extensions.*;
import org.si.b3.*;
import org.si.b3.modules.*;
const W:int = 400;
const H:int = 400;
var mc:CMLMovieClip;
var enemyFactory:ActorFactory;
var bulletFactory:ActorFactory;
var playerFactory:ActorFactory;
var shotFactory:ActorFactory;
var player:Player;
var frameCount:int = 0;
class CMLMaster extends CMLObject {
public function CMLMaster():void {
enemyFactory = new ActorFactory(Enemy);
bulletFactory = new ActorFactory(Bullet);
playerFactory = new ActorFactory(Player);
shotFactory = new ActorFactory(Shot);
player = playerFactory.newInstance();
player.create(0, 100);
player.setAsDefaultTarget();
super();
}
override public function onNewObject(args:Array):CMLObject {
return enemyFactory.newInstance();
}
}
class Enemy extends Actor {
public function Enemy() { size = 4; super(); }
override public function onFireObject(args:Array):CMLObject {
return bulletFactory.newInstance();
}
override public function onDraw():void {
mc.fillRect(0xff4040, x-4, y-4, 9, 9);
}
override public function onHit(act:Actor):void {
destroy(1);
}
}
class Bullet extends Actor {
public function Bullet() { size = 2; super(); }
override public function onDraw():void {
mc.fillRect(0xff8080, x-2, y-2, 5, 5);
}
}
class Player extends Actor {
public var ignoreHit:int = 60;
public function Player() { size = 4; super(); }
override public function onDraw():void {
if(!(ignoreHit & 1)) mc.fillRect(0x4040ff, x-4, y-4, 9, 9);
}
override public function onUpdate():void {
x += mc.control.x;
y += mc.control.y;
limitScope();
if(mc.control.isPressed(CMLMovieClipControl.KEY_BUTTON0)) {
if(mc.control.getPressedFrame(CMLMovieClipControl.KEY_BUTTON0) & 1) {
var shot:Shot = shotFactory.newInstance();
shot.create(x, y);
}
}
if(ignoreHit) ignoreHit--;
}
override public function onHit(act:Actor):void {
ignoreHit = 60;
}
}
class Shot extends Actor {
public function Shot() { size = 3; super(); }
override public function onDraw():void {
mc.fillRect(0x8080ff, x-1, y-2, 3, 5);
}
override public function onUpdate():void {
y -= 10;
super.onUpdate(); // for isEscaped test - without this we leak resources
}
}
import flash.display.*;
import flash.events.*;
class FullScreenButton extends Sprite {
private var outPoints:Array = [4, 2, 6, 4, 8, 2, 8, 8, 2, 8, 4, 6, 2, 4];
private var inPoints:Array = [];
private var enterFull:Sprite = new Sprite;
private var exitFull:Sprite = new Sprite;
public function FullScreenButton(stage:Stage) {
var i:int;
for each(var n:Number in outPoints) inPoints.push(n-10);
enterFull.graphics.beginFill(0);
enterFull.graphics.drawRect(0, 0, 20, 20);
exitFull.graphics.beginFill(0);
exitFull.graphics.drawRect(0, 0, 20, 20);
for(i=0; i<4; i++) {
var s:Shape;
s = makeShape(outPoints);
s.rotation = i*90;
s.x = s.y = 10;
enterFull.addChild(s);
s = makeShape(inPoints);
s.rotation = i*90;
s.x = s.y = 10;
exitFull.addChild(s);
}
buttonMode = true;
tabEnabled = false;
addChild(enterFull);
addEventListener("click", onClick);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onDisplayStateChange);
}
private function onDisplayStateChange(e:FullScreenEvent):void {
if(e.fullScreen) {
removeChild(enterFull);
addChild(exitFull);
} else {
removeChild(exitFull);
addChild(enterFull);
}
}
private function onClick(e:Event):void {
if(stage.displayState == StageDisplayState.FULL_SCREEN) {
stage.displayState = StageDisplayState.NORMAL;
} else {
stage.displayState = StageDisplayState.FULL_SCREEN;
}
}
private function makeShape(pts:Array):Shape {
var shape:Shape = new Shape;
var g:Graphics = shape.graphics;
g.beginFill(0xffffff);
g.moveTo(pts[0], pts[1]);
for(var i:int=2; i<pts.length; i+=2) g.lineTo(pts[i], pts[i+1]);
g.endFill();
return shape;
}
}