Einzelnen Beitrag anzeigen
Alt 18-07-2010, 02:51   #12 (permalink)
shin10
in the boondocks
 
Benutzerbild von shin10
 
Registriert seit: Feb 2006
Ort: Augsburg
Beiträge: 3.495
hi,

also wie versprochen hab ich nochmal geschaut. wie gesagt hab ich gerade einiges um die ohren. drum hab ich dir nur nen kleinen prototypen hingeschludert (also so richtig schludrig). was du brauchst sind zwei mcs: level und player
schau es dir einfach mal durch. ich denke als kleine inspiration wirds schon was taugen.
PHP-Code:
const TASTE_HOCH:uint 38;
const 
TASTE_RUNTER:uint 40;
const 
TASTE_LINKS:uint 37;
const 
TASTE_RECHTS:uint 39;

const 
g:Number 9.81 stage.frameRate;
const 
steigungMax 3;

player.speed 2;
player.speedX 0;
player.speedY 0;
player.sprungkraft 10;
player.bodenKontakt level.hitTestPoint(player.x,player.y,true);


var 
keys:Array = new Array(256);
for (var 
i:uint=0i<keys.lengthi++)
{
    
keys[i] = false;
}

function 
kdh(e:KeyboardEvent):void
{
    
keys[e.keyCode] = true;
}
function 
kuh(e:KeyboardEvent):void
{
    
keys[e.keyCode] = false;
}
function 
efh(e:Event):void
{
    
playerInput();
    
physics(player);
    
info.text "" player.bodenKontakt.toString() + "\n" clippingOben(player) + "\n" clippingUnten(player);
}

function 
playerInput():void
{
    if (
keys[TASTE_LINKS] == true && keys[TASTE_RECHTS] == false)
    {
        
player.speedX =  -  player.speed;
    }
    else if (
keys[TASTE_LINKS]==false && keys[TASTE_RECHTS]==true)
    {
        
player.speedX player.speed;
    }
    else
    {
        
player.speedX 0;
    }

    if (
keys[TASTE_HOCH] == true && player.bodenKontakt == true)
    {
        
player.speedY =  -  player.sprungkraft;
    }
}
function 
physics(obj:MovieClip):void
{
    
obj.speedY += g;
    if(
obj.bodenKontakt){
        
//kontollverlust >> rutschen
        
if(abrutschen(obj)){
            return;
        }
    }
    
schwerkraft(obj);
    
clippingUnten2(obj);
    
gehen(obj);
}
function 
abrutschen(obj:MovieClip):Boolean{
    if(
level.hitTestPoint(obj.x-1obj.y-(steigungMax+1), true) && level.hitTestPoint(obj.x+1obj.y+(steigungMax+1), true) == false){
        
obj.++;
        return 
true;
    }else if(
level.hitTestPoint(obj.x+1obj.y-(steigungMax+1), true) && level.hitTestPoint(obj.x-1obj.y+(steigungMax+1), true) == false){
        
obj.--;
        return 
true;
    }
    
    return 
false;
}

function 
gehen(obj:MovieClip):void
{
    var 
vX:int obj.speedX/(Math.abs(obj.speedX));
    for (var 
Math.abs(obj.speedX); i>0i--)
    {
        if (
level.hitTestPoint(obj.vXobj.steigungMaxtrue) == false)
        {
            
obj.+=  vX;
        }
    }
    
clippingUnten(obj);
}
function 
schwerkraft(obj:MovieClip):void
{
    var 
vY:int obj.speedY/(Math.abs(obj.speedY));
    for (var 
0i<Math.abs(obj.speedY); i++)
    {
        if ((
clippingUnten2(obj) == false || obj.bodenKontakt) && (clippingOben(obj)==false))
        {
            
obj.+=  vY;
        }
        else
        {
            return;
        }
    }
}
function 
clippingUnten2(obj:MovieClip):Boolean
{
    
obj.bodenKontakt level.hitTestPoint(obj.x,obj.1,true);
    if (
level.hitTestPoint(obj.x,obj.y,true) == false)
    {
        return 
false;
    }
    while (
level.hitTestPoint(obj.xobj.ytrue))
    {
        
obj.y--;
    }
    
obj.speedY 0;
    
obj.bodenKontakt true;
    return 
true;
}
function 
clippingUnten(obj:MovieClip):Boolean
{
    if (
level.hitTestPoint(obj.x,obj.y,true) == false)
    {
        return 
false;
    }
    while (
level.hitTestPoint(obj.xobj.ytrue))
    {
        
obj.y--;
    }
    return 
true;
}
function 
clippingOben(obj:MovieClip):Boolean
{
    if (
level.hitTestPoint(obj.x,obj.1,true) == false)
    {
        return 
false;
    }
    while (
level.hitTestPoint(obj.xobj.y-1true))
    {
        
obj.y++;
    }
    
obj.speedY 0;
    return 
true;
}

stage.addEventListener(Event.ENTER_FRAMEefh);
stage.addEventListener(KeyboardEvent.KEY_DOWNkdh);
stage.addEventListener(KeyboardEvent.KEY_UPkuh); 
mfg

sx
__________________

flintfabrik.de

Geändert von shin10 (18-07-2010 um 02:58 Uhr)
shin10 ist offline   Mit Zitat antworten