Jumpman
←→移動
xキージャンプ
zキーダッシュ
// ←→移動
// xキージャンプ
// zキーダッシュ
package {
import flash.display.Sprite;
import flash.events.*;
[SWF(width=465, height=465, frameRate=60,backgroundColor=0x5080ff)]
public class Jumpman extends Sprite {
private var jumpmany:int = 150*0x100;
private var jumpmanx:Number = 100 * 0x1000;;
private var zxkey:int = 0;
private var zxkey2:int = 0;
private var sayuukey:int = 0;
private var keyState:int = 0;
private var keyState2:int = 0;
private var joutai:int = 0;
private var muki:int = 1;
private var muki2:int = 1;
private var dashflag:int = 0;
private var count:int = 0;
private var vxmax:Number = 0;
private var vvx:Number
private var vx:Number = 0;;
private var vy:Number = 0;
private var speed:Number=0;
private var dashspeed:Number = 0;
private var rakkavvy:Number;
private var rakkavvy2:Number;
private var sp:Sprite;
private var jimen:Sprite;
public function Jumpman() {
// write as3 code here..
stage.addEventListener(Event.ENTER_FRAME, update);
stage.addEventListener( KeyboardEvent.KEY_DOWN , onKeydown );
stage.addEventListener( KeyboardEvent.KEY_UP , onKeyup );
sp = new Sprite();
sp.graphics.beginFill(0xff0000, 1);
sp.graphics.drawRect(0, 0, 32, 32);;
sp.graphics.endFill();
jimen = new Sprite();
jimen.graphics.lineStyle(7, 0x000000, 1);
jimen.graphics.moveTo(0, 0);
jimen.graphics.lineTo(0, 150)
this.graphics.beginFill(0xc07000, 1);
this.graphics.drawRect(0, 332, 465, 377);
this.graphics.endFill();
addChild(sp);
addChild(jimen);
jimen.y = 335;
}
private function update(e:Event):void {
if ((keyState & 0x3) != 3) { keyState2 = keyState;}
moveset();
switch(joutai) {
case 0:
speedreset();
if (sayuukey != 0) { muki = sayuukey; }
speedset();
move();
break;
case 1:
if (vy < 0) {
if ((zxkey & 0x80 & zxkey2) == 0) {
if(150*0x100-jumpmany-0x100>0){
rakkavvy = rakkavvy2;
}
}
}else {
rakkavvy = rakkavvy2;
}
if (sayuukey != 0) { muki = sayuukey; }
if (sayuukey != 0) {
speedset();
}
move();
rakka();
break;
}
zxkey2 = zxkey;
if (vx > 0) { muki2 = 1; }
if (vx < 0) { muki2 = 2;}
sp.x = 170;
sp.y = (jumpmany / 0x100) * 2;
jimen.x = 465-((jumpmanx / 0x10) * 2) % 465;
if (jumpmanx < 0) { jumpmanx = jumpmanx + 465 * 0x10000;}
}
private function onKeydown(event:KeyboardEvent):void {
if (event.keyCode == 39 ) { keyState = keyState | 0x01; }//39→ 37← 38↑ 40↓
if (event.keyCode == 37 ) { keyState = keyState | 0x02; }
if (event.keyCode == 40 ) { keyState = keyState | 0x04; }
if (event.keyCode == 38 ) { keyState = keyState | 0x08; }
if (event.keyCode == 88 ) { keyState = keyState | 0x80; }//x
if (event.keyCode == 90 ) { keyState = keyState | 0x40; }//z
}
private function onKeyup(event:KeyboardEvent):void {
if (event.keyCode == 39) { keyState &= ~0x01; }
if (event.keyCode == 37) { keyState &= ~0x02; }
if (event.keyCode == 40) { keyState &= ~0x04; }
if (event.keyCode == 38) { keyState &= ~0x08;}
if (event.keyCode == 88) { keyState &= ~0x80; }
if (event.keyCode == 90) { keyState &= ~0x40;}
}
private function moveset():void {
count++;
if (count > 20) { count = 0; dashflag = 0;}
zxkey = keyState2 & 0xc0;
sayuukey = keyState2 & 0x03;
if ((zxkey&0x80)!=0 && (zxkey&0x80&zxkey2)==0 && joutai == 0) {
joutai = 1;
if (speed < 9*0x100) { rakkavvy = 0x20; rakkavvy2 = 0x70; vy = -0x400; }
if (speed >= 9*0x100 && speed < 16*0x100) { rakkavvy = 0x20; rakkavvy2 = 0x70; vy = -0x400; }
if (speed >= 16*0x100 && speed < 25*0x100) { rakkavvy = 0x1e; rakkavvy2 = 0x60; vy = -0x400; }
if (speed >= 25*0x100 && speed < 28*0x100) { rakkavvy = 0x28; rakkavvy2 = 0x90; vy = -0x500; }
if (speed >= 28*0x100) { rakkavvy = 0x28; rakkavvy2 = 0x90; vy = -0x500;}
}
if (joutai == 0) {
if (sayuukey == muki2) {
if ((zxkey & 0x40) || dashflag > 0) {
dashflag = 1;
vxmax = 40*0x100;
vvx = 0xe4;
if (muki != muki2) { vvx = vvx * 2;}
}else {
if (dashspeed > 0 || speed > 33*0x100) {
vxmax = 24*0x100;
vvx = 0xd0;
if (muki != muki2) { vvx = vvx * 2;}
}else {
vxmax = 24*0x100;
vvx = 0x98;
if (muki != muki2) { vvx = vvx * 2;}
}
}
}else {
if (dashspeed > 0 || speed > 33*0x100) {
vxmax = 24*0x100;
vvx = 0xd0;
if (muki != muki2) { vvx = vvx * 2;}
}else {
vxmax = 24*0x100;
vvx = 0x98;
if (muki != muki2) { vvx = vvx * 2;}
}
}
}else {
if (speed > 25*0x100) {
vxmax = 40*0x100;
vvx = 0xe4;
if (muki != muki2) { vvx = vvx * 2;}
}
if (speed <= 25*0x100) {
if (dashspeed > 0 || speed > 33*0x100) {
vxmax = 24*0x100;
vvx = 0xd0;
if (muki != muki2) { vvx = vvx * 2;}
}else {
vxmax = 24*0x100;
vvx = 0x98;
if (muki != muki2) { vvx = vvx * 2;}
}
}
}
}
private function speedreset():void {
if (speed > 28*0x100) {
dashspeed = speed;
}else {
if ((keyState2&0x7f) != 0) {
if ((keyState2&0x3) == muki2) {
dashspeed = 0;
}else {
if (speed < 11*0x100) {
muki2 = muki;
vx = 0;
}
}
}
}
}
private function speedset():void {
if (((keyState2&3) == 0 && vx < 0) || (keyState2 & 0x01)) {
vx = vx + vvx;
if (vx > vxmax) { vx = vxmax; }
}
if (((keyState2&3) == 0 && vx > 0) || (keyState2 & 0x02)) {
vx = vx - vvx;
if (vx < -vxmax) { vx = -vxmax; }
}
speed = vx;
if (speed < 0) { speed = -speed; }
}
private function move():void {
if (Math.floor(vx / 0x100) == -1) { jumpmanx = jumpmanx + 1; }
jumpmanx = jumpmanx +Math.floor(vx/0x100);
}
private function rakka():void {
jumpmany = jumpmany + vy;
if (jumpmany > 150*0x100) { jumpmany = 150*0x100; joutai = 0; }
vy = vy + rakkavvy;
if (vy > 0x480) {
vy = 0x400;
}
}
}
}