Я новичок в AS3 и должен сделать платформер для плитки для школы, к сожалению, мои учителя не так много помогают. У меня нет ни малейшего понятия о том, как столкнуться с моей игрой. Я уже некоторое время искал интернет и действительно не могу найти решение. Если вы знаете что-нибудь, что могло бы мне помочь, пожалуйста, оставьте комментарий!AS3 Tile Collision platformer
package {
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flashx.textLayout.formats.BlockProgression;
import flashx.textLayout.formats.BackgroundColor;
public class jump extends MovieClip {
//Var player
var persoon:testSubject = new testSubject();
var grond:Ground = new Ground();
var backGround:Background = new Background();
var health:Health = new Health();
var mapWidth = 10;
var mapHeight = 10;
var tileSide = 50;
var totalTiles = mapWidth * mapHeight;
var accel:Number = 2;
var speed:Number = 5;
var jumpSpeed:Number = 0;
var gravity:Number = 5;
var ground:Number = 745 - persoon.height;
var nr:Number = 3;
var sprint:Boolean = true;
var shiftButton:Boolean = false;
var leftButton:Boolean = false;
var rightButton:Boolean = false;
var upButton:Boolean = false;
var downButton:Boolean = false;
var isJumping:Boolean = true;
//Array map
var myMap:Array = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,1,1,1,1,1,1,1,1,0,0,0,1,3,2,4,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
public function jump() {
//Event listener up key
stage.addEventListener(KeyboardEvent.KEY_DOWN, upKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, upKeyUp);
stage.addEventListener(Event.ENTER_FRAME, moveChar);
//backGround
backGround.x = -1000;
backGround.y = -1000;
backGround.height = 2000;
backGround.width = 6000;
addChild(backGround);
//Map
for (var i:int=0; i<13; i++)
{
for (var u:int=0; u<36; u++){
var cell:MovieClip = new tile();
cell.gotoAndStop(myMap[i][u]+1);
cell.x=tileSide*u
cell.y=tileSide*i
addChild(cell);
}
}
//Player
persoon.x = 450;
persoon.y = 490;
persoon.width = 50;
persoon.height = 60;
addChild(persoon);
//Healthbar
health.x = 10;
health.y = 65;
health.gotoAndStop(4);
addChild(health);
}
//Spring function when key is pressed
public function upKeyDown(e:KeyboardEvent):void {
//Buttons Left - Up - Right - Down - Shift
if (e.keyCode == 37 || e.keyCode == 65) {
leftButton = true;
trace(persoon.y);
}
if (e.keyCode == 38 || e.keyCode == 87) {
upButton = true;
if(!isJumping) {
jumpSpeed = 31;
isJumping = true;
}
}
if (e.keyCode == 39 || e.keyCode == 68) {
rightButton = true;
}
if (e.keyCode == 40 || e.keyCode == 83) {
downButton = true;
}
if (e.keyCode == 16) {
shiftButton = true;
if (sprint == true) {
speed = speed * accel;
sprint = false;
}
}
}
//Spring function when key is released
public function upKeyUp(e:KeyboardEvent):void {
//Buttons Left - Up - Right - Down - Shift
if (e.keyCode == 37 || e.keyCode == 65) {
leftButton = false;
}
if (e.keyCode == 38 || e.keyCode == 87) {
upButton = false;
}
if (e.keyCode == 39 || e.keyCode == 68) {
rightButton = false;
}
if (e.keyCode == 40 || e.keyCode == 83) {
downButton = false;
}
if (e.keyCode == 16) {
shiftButton = false;
speed = 5;
sprint = true;
}
}
//Character Movement
public function moveChar(event:Event):void {
//Collision
//Walk Left & Right
if (leftButton == true) {
if (persoon.x > 78) {
persoon.x -= speed;
health.x = persoon.x - 440;
}
} else if (rightButton == true) {
if (persoon.x < 1722) {
persoon.x += speed;
health.x = persoon.x - 440;
}
}
//Jump
if(isJumping) {
health.y -= jumpSpeed;
persoon.y -= jumpSpeed;
jumpSpeed -= 2;
}
if (persoon.y + gravity < ground) {
persoon.y += gravity;
health.y += gravity;
trace(persoon.y);
} else {
health.y = ground - 420;
persoon.y = ground;
isJumping = false;
}
//Camera
root.scrollRect = new Rectangle (persoon.x - stage.stageWidth/2, persoon.y - 430, stage.stageWidth, stage.stageHeight);
}
}
}