Im making a game in flash actionscript 3, almost done but I have some problems...
I'll explaing the game first: you are a character(for the moment a black square) and you have to get as high as possible by jumping on blocks that are falling. What I can do at the moment is jump and have a collision with the blocks (left - right) and jump onto the blocks.
The problem I have is: When 2 blocks fall exactly next to each other (Block A falls next to Block B ) Then I jump on Block A and I want to Run to Block B(just run without jumping) I get something very weird, i can't walk on blocks :s
I'm searching for over a week now and still no progress. So im hope I can get any help here. It's very hard to explain the problem without any visualization so I uploaded the files so u can test for yourselves.
download link: http://www.megaupload.com/?d=JT4158KA
also attached the files in the topic, but it doesnt work..
Im still a beginner, so getting a bit help would be great.. Im stuck at this for over a week :s
I even asked my teacher and he couldn't solve it. So I hope you guys can help
But if you understand my explanation and/or are to lazy to download my files (17kb big
package Classes
{
import flash.events.*;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.ui.Keyboard;
import Classes.KeyObject;
public class Player extends MovieClip
{
var isJumping:Boolean = false;
var jumpPower:int = 0;
var ground:int;
var stageRef:Stage;
var key:KeyObject;
var isDead:Boolean = false;
var allBlocks:Array;
var blockX:int;
var blockY:int;
var blockWidth:int;
var blockHeight:int;
var steps:int = 10;
var upPressed:Boolean = false;
public function Player(stageReff:Stage,allBlocks:Array)
{
stageRef = stageReff;
key = new KeyObject(stageRef);
this.allBlocks = allBlocks;
ground = stageRef.stageHeight;
addEventListener(Event.ENTER_FRAME,update);
//addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
function isHit()
{
for (var j = 0; j < allBlocks.length; j++)
{
if (this.hitTestObject(allBlocks[j]) && allBlocks[j] != isOnTopOf())
{
blockX = allBlocks[j].x;
blockY = allBlocks[j].y;
blockWidth = allBlocks[j].width;
blockHeight = allBlocks[j].height;
return true;
}
}
return false;
}
function isHitTop()
{
for (var j = 0; j < allBlocks.length; j++)
{
if (this.PlayerBottom.hitTestObject(allBlocks[j].hitBoxTop))
{
jumpPower = 0;
isJumping = false;
this.y = allBlocks[j].y - allBlocks[j].height;
return true;
}
}
return false;
}
function isHitBottom()
{
for (var j = 0; j<allBlocks.length; j++)
{
if (this.hitTestObject(allBlocks[j].hitBoxBottom))
{
if (isJumping)
{
this.y = allBlocks[j].y + this.height;
jumpPower=0;
isJumping = false;
isDead = false;
trace(isDead);
}
else
{
isDead = true;
trace(isDead);
}
}
}
}
function isOnTopOf()
{
for (var j = 0; j < allBlocks.length; j++)
{
if (this.PlayerBottom.hitTestObject(allBlocks[j].hitBoxTop))
{
trace("is WEL onTopOf");
return allBlocks[j];
}
}
trace("is NIET onTopOf");
return null;
}
function update(evt:Event):void
{
if (!isDead)
{
isHitTop();
isHitBottom();
if (key.isDown(Keyboard.UP))
{
//Voorkomen dat hij 2x springt
if (! isJumping)
{
jumpPower = 12;
isJumping = true;
}
}
if (key.isDown(Keyboard.LEFT))
{
if (this.x > stageRef.stageWidth - stageRef.stageWidth)
{
this.x -= steps;
if (isHit() == true)
{
this.x = blockX + blockWidth + 1;
//trace("is gehit maar staat er niet op");
}
}
}
else if (key.isDown(Keyboard.RIGHT))
{
if (this.x < stageRef.stageWidth - this.width)
{
this.x += steps;
if (isHit() == true)
{
this.x = blockX - this.width - 1;
this.y = blockY;
}
}
}
if (isJumping)
{
this.y -= jumpPower;
jumpPower -= 2;
isHitTop();
isHitBottom();
}
if (! isJumping && ! isHitTop())
{
this.y += 7;
}
if (this.y > ground)
{
this.y = ground;
isJumping = false;
}
}
else
{
removeEventListener(Event.ENTER_FRAME,update);
}
}
}
}
This post has been edited by mXX: 13 January 2012 - 01:10 PM

New Topic/Question
Reply



MultiQuote



|