Okay Everyone.... Here is my game.... xD!!!
onClipEvent(load){
var speedx=0
var acceleratex=.8
var deceleratex=.6
var maxspeedx=14
var speedy=0
var h=84
var w=19
var jump=false
var duck=false
var slide=false
var pressed=false
var cosmo=""
var damagedlength=0
charColor = new Color(this)
function damage(damage){
_root.difficulty=1
_root.health-=damage*_root.difficulty
charColor.setTransform({ra:'50',rb:'20',ga:'0',gb:'0',ba:'0',bb:'0',aa:'100',ab:'255'})
damagedlength++
}
function scroll(valuex, valuey){
if((_x>500 and valuex>0) or (_x<300 and valuex<0)){
if(_root.background._x>_root.background.x+200 and _root.background._currentframe!=1){
_root.background._x-=950
_root.background.gotoAndStop(_root.background._currentframe-1)
}else if(_root.background._x<_root.background.x-800 and _root.background._currentframe!=3){
_root.background._x+=950+valuex
_root.background.gotoAndStop(_root.background._currentframe+1)
}else{
_root.background._x-=valuex
}
for(var i=0; i<=100; i++){
_root["object"+i]._x-=valuex
_root["newb"+i]._x-=valuex
_root["neweb"+i]._x-=valuex
_root["newcase"+i]._x-=valuex
}
}else{
_x+=valuex
}
if((_y<250 and valuey>0) or (_y>400 and valuey<0)){
_root.background._y+=valuey
for(var i2=0; i2<=100; i2++){
_root["object"+i2]._y+=valuey
_root["newb"+i2]._y+=valuey
_root["neweb"+i2]._y+=valuey
_root["newcase"+i2]._y+=valuey
}
}else{
_y-=valuey
}
}
function move(valuex, valuey){
if(valuex>0){
if(!_root.background.solid.hitTest(_x+valuex+.6*w, _y-.3*h, true) and !_root.background.solid.hitTest(_x+valuex+.6*w, _y-.6*h, true) and !_root.background.solid.hitTest(_x+valuex+.6*w, _y-h, true) and !(!_root.background.solid.hitTest(_x+valuex+.3*w, _y+5, true) and _root.background.solid.hitTest(_x+valuex+.5*w, _y, true))){
scroll(valuex, 0)
}else{
if(!_root.background.solid.hitTest(_x+.6*w+valuex, _y-.9*h, true) and _root.background.solid.hitTest(_x, _y-h, true)){
scroll(valuex, 0)
}else{
while(_root.background.solid.hitTest(_x+.7*w+valuex, _y, true) and !_root.background.solid.hitTest(_x+.51*w, _y, true)){
_x+=.1
}
speedx=0
}
}
}
if(valuex<0){
if(!_root.background.solid.hitTest(_x+valuex-.6*w, _y-.3*h, true) and !_root.background.solid.hitTest(_x+valuex-.6*w, _y-.6*h, true) and !_root.background.solid.hitTest(_x+valuex-.6*w, _y-h, true) and !(!_root.background.solid.hitTest(_x+valuex-.3*w, _y+5, true) and _root.background.solid.hitTest(_x+valuex-.6*w, _y, true))){
scroll(valuex, 0)
}else{
if(!_root.background.solid.hitTest(_x-.6*w+valuex, _y-.9*h, true) and _root.background.solid.hitTest(_x, _y-h, true)){
scroll(valuex, 0)
}else{
while(_root.background.solid.hitTest(_x-.7*w+valuex, _y, true) and !_root.background.solid.hitTest(_x-.51*w, _y, true)){
_x-=.1
}
speedx=0
}
}
}
if(valuey>0){
if(!_root.background.solid.hitTest(_x, _y-h, true) and !_root.background.solid.hitTest(_x+.5*w, _y-h, true) and !_root.background.solid.hitTest(_x-.5*w, _y-h, true)){
scroll(0, valuey)
}else{
speedy=0
jump=false
}
}
if(valuey<0){
if(!_root.background.solid.hitTest(_x, _y, true) and !_root.background.solid.hitTest(_x+.4*w, _y, true) and !_root.background.solid.hitTest(_x-.4*w, _y, true) and (_root.dead==true or !(!(Key.isDown(_root.Kdown) and Key.isDown(_root.Kup)) and (_root.background.platform.hitTest(_x, _y, true) or _root.background.platform.hitTest(_x+.4*w, _y, true) or _root.background.platform.hitTest(_x-.4*w, _y, true))))){
scroll(0, valuey)
}else{
speedy=0
}
}
}
}
onClipEvent(enterFrame){
if(_root.stopped==false){
if(_root.dead==false){
//CONTROLS
if(Key.isDown(_root.Kright) and !Key.isDown(_root.Kleft)){
speedx+=acceleratex
}
if(Key.isDown(_root.Kleft) and !Key.isDown(_root.Kright)){
speedx-=acceleratex
}
if(Key.isDown(_root.Kup) and !Key.isDown(_root.Kdown)){
if(pressed==false){
var pressed=true
if(_root.background.solid.hitTest(_x, _y+3, true) or _root.background.solid.hitTest(_x+.4*w, _y+3, true) or _root.background.solid.hitTest(_x-.4*w, _y+3, true) or _root.background.platform.hitTest(_x, _y+3, true) or _root.background.platform.hitTest(_x+.4*w, _y+3, true) or _root.background.platform.hitTest(_x-.4*w, _y+3, true)){
jump=true
speedy=0
jumpdistance=-jumpheight
}else if(Key.isDown(_root.Kright) and (_root.background.solid.hitTest(_x+.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x+.6*w, _y, true))){
jump=true
speedy=0
speedx=-15
jumpdistance=-jumpheight
}else if(Key.isDown(_root.Kleft) and (_root.background.solid.hitTest(_x-.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x-.6*w, _y, true))){
jump=true
speedy=0
speedx=15
jumpdistance=-jumpheight
}
}
}else{
var pressed=false
}
if(Key.isDown(_root.Kup) and !Key.isDown(_root.Kdown) and jump==true and duck==false and jumpdistance<=0){
speedy=jumpspeed
jumpdistance+=jumpspeed
jump=true
}else{
jump=false
}
if(Key.isDown(_root.Kdown) and !Key.isDown(_root.Kup) and speedy<=0 and (_root.background.solid.hitTest(_x, _y, true) or _root.background.solid.hitTest(_x+.5*w, _y, true) or _root.background.solid.hitTest(_x-.5*w, _y, true) or _root.background.platform.hitTest(_x, _y, true) or _root.background.platform.hitTest(_x+.5*w, _y, true) or _root.background.platform.hitTest(_x-.5*w, _y, true))){
if(duck==false){
_root.char.head._y+=25
_root.char.arm._y+=25
_root.char.arm2._y+=25
_root.char.cape._y+=25
maxspeedx-=12
h-=25
duck=true
}
}else{
if(!_root.background.solid.hitTest(_x, _y-84, true) and !_root.background.solid.hitTest(_x+.5*w, _y-84, true) and !_root.background.solid.hitTest(_x-.5*w, _y-84, true)){
if(duck==true){
_root.char.head._y-=25
_root.char.arm._y-=25
_root.char.arm2._y-=25
_root.char.cape._y-=25
maxspeedx+=12
h+=25
duck=false
}
}
}
}else{
jump=false
}
//PHYSICS
//Gravity
if(!_root.background.solid.hitTest(_x, _y, true) and !_root.background.solid.hitTest(_x+.5*w, _y, true) and !_root.background.solid.hitTest(_x-.5*w, _y, true) and (_root.dead==true or !(!(Key.isDown(_root.Kdown) and Key.isDown(_root.Kup)) and (_root.background.platform.hitTest(_x, _y, true) or _root.background.platform.hitTest(_x+.5*w, _y, true) or _root.background.platform.hitTest(_x-.5*w, _y, true)))) and jump==false){
speedy-=acceleratedown
}
//Wall
if((Key.isDown(_root.Kright) and (_root.background.solid.hitTest(_x+.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x+.6*w, _y, true))) or (Key.isDown(_root.Kleft) and (_root.background.solid.hitTest(_x-.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x-.6*w, _y, true)))){
if(speedy<-1){
speedy=-1
}
}
//Friction
if(!(Key.isDown(_root.Kright) and !Key.isDown(_root.Kleft)) and speedx>0){
speedx-=deceleratex
}
if(!(Key.isDown(_root.Kleft) and !Key.isDown(_root.Kright)) and speedx<0){
speedx+=deceleratex
}
//Precheckup
if(Math.abs(speedx)
speedx=0
}
if(speedx>maxspeedx){
speedx=maxspeedx
}
if(speedx<-maxspeedx){
speedx=-maxspeedx
}
if(speedy<-maxspeeddown){
speedy=-maxspeeddown
}
move(speedx, speedy)
//Bounce
if(cosmo=="run"){
if(_root.char.body._currentframe==8 or _root.char.body._currentframe==9 or _root.char.body._currentframe==18 or _root.char.body._currentframe==19){
_y-=1.5
}
if(_root.char.body._currentframe==1 or _root.char.body._currentframe==20 or _root.char.body._currentframe==11 or _root.char.body._currentframe==10){
_y+=1.5
}
}
//Postcheckup
while(_root.background.solid.hitTest(_x, _y-1, true) or _root.background.solid.hitTest(_x+.5*w, _y-1, true) or _root.background.solid.hitTest(_x-.5*w, _y-1, true) or (speedy<=0 and _root.dead==false and !(Key.isDown(_root.Kup) and Key.isDown(_root.Kdown)) and (_root.background.platform.hitTest(_x, _y-1, true) or _root.background.platform.hitTest(_x+.4*w, _y-1, true) or _root.background.platform.hitTest(_x-.4*w, _y-1, true)))){
_y--
speedy=0
}
while(_root.background.solid.hitTest(_x, _y-h+1, true) or _root.background.solid.hitTest(_x+.4*w, _y-h+1, true) or _root.background.solid.hitTest(_x-.4*w, _y-h+1, true)){
_y++
}
if(damagedlength>0){
damagedlength++
if(damagedlength>=3){
charColor.setTransform({ra:'100',rb:'0',ga:'100',gb:'0',ba:'100',bb:'0',aa:'100',ab:'255'})
damagedlength=0
}
}
//Cosmetics
_root.cosmo=cosmo
if(_root.dead==true){
cosmo="dead"
}else if(speedy>0 or (!_root.background.solid.hitTest(_x, _y+5, true) and !_root.background.solid.hitTest(_x+.5*w, _y+5, true) and !_root.background.solid.hitTest(_x-.5*w, _y+5, true) and !((_root.background.platform.hitTest(_x, _y+2, true) or _root.background.platform.hitTest(_x+.5*w, _y+2, true) or _root.background.platform.hitTest(_x-.5*w, _y+2, true)) and !(Key.isDown(_root.KDown) and Key.isDown(_root.KUp))))){
if(speedy<0 and ((Key.isDown(_root.Kright) and (_root.background.solid.hitTest(_x+.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x+.6*w, _y, true))) or (Key.isDown(_root.Kleft) and (_root.background.solid.hitTest(_x-.6*w, _y-.8*h, true) or _root.background.solid.hitTest(_x-.6*w, _y, true))))){
cosmo="wall"
}else{
cosmo="air"
}
}else{
if(duck==true){
if(speedx==0){
cosmo="duck"
}else{
cosmo="duckmove"
}
}else{
if(Math.abs(speedx)>=2*acceleratex){
cosmo="run"
}else{
cosmo="still"
}
}
}
if((speedx>0 or (speedx==0 and Key.isDown(_root.KRight) and !Key.isDown(_root.KLeft))) and _xscale!=100){
_root.char.arm._rotation*=-1
_root.char.arm2._rotation*=-1
_root.char.arm._xscale*=-1
_root.char.arm2._xscale*=-1
_xscale=100
}
if((speedx<0 or (speedx==0 and Key.isDown(_root.KLeft) and !Key.isDown(_root.KRight))) and _xscale!=-100){
_root.char.arm._rotation*=-1
_root.char.arm2._rotation*=-1
_root.char.arm._xscale*=-1
_root.char.arm2._xscale*=-1
_xscale=-100
}
var armrotation=_root.char.arm._rotation
var arm2rotation=_root.char.arm2._rotation
var headrotation=_root.char.head._rotation
this.gotoAndStop(_root.char.cosmo)
_root.char.arm._rotation=armrotation
_root.char.head._rotation=headrotation
_root.char.arm.gotoAndStop(_root.weapon)
if((_root.weapon1type==1 and _root.weapon==1) or (_root.weapon2type==1 and _root.weapon==2)){
_root.char.arm2.gotoAndStop(10)
}else{
_root.char.arm2.gotoAndStop(_root.weapon)
}
}
}