• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with a code in ActionScript please

New Here ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

HI! I'm a student of NTA from Brera Academy (Italy), and I have to made a lil game in Animate for an exam. Unfortunately the prof doesn't have so much time to explain everything, so I'm trying to work on the code (even I don't know anything about coding!)

I have to make move my character, following the mouse. It look ok but the animation of the symbol doesn't work! So I can't understand of to making the animation play.

Here is the code, for the character I'm using 4 frames: 1= left stop, 2= right move, 3= right stop, 4= left move

var incx = 2;

var cat1;

var ipo;

var distanza_calcolata = 0;

var movimenti = true;

var lontananza = 0;

var vel = 10;

stop();

addEventListener(Event.ENTER_FRAME, sposta);

function sposta(event: Event): void {

Porte();

Calcola_distanza();

var posmaouseX = mouseX;

var posmaouseY = mouseY;

incx = cat1 / 20;

//incy=cat2/20

if (cat1 <= lontananza) {

incx = 0;

//trace("x-zero");

}

/*if(cat2<=lontananza)

{

incy=0;

//trace("y-zero");

}*/

///////////////////////////if(movimenti==true){

if (posmaouseX != scout.x) {

if (posmaouseX > scout.x) {

scout.x += incx;

Controllalabirinto();

sfondomobile();

Porte();

} else {

scout.x -= incx;

Controllalabirinto();

sfondomobile();

Porte();

}

///////////////////////////}

/*if(posmaouseY!=scout.y){

if(posmaouseY>scout.y){

scout.y+=incy;

}else{

scout.y-=incy;

}

Calcola_distanza();

Controllalabirinto();

}*/

}

////////////////////////////////////////////////////////////////////////

//HERE IS THE CHARACTER MOVEMENT//

if (scout.x > mouseX) {

omino.gotoAndStop(1); //1 = fermo sulla SX

}

if (scout.x - 55 > mouseX) {

omino.gotoAndStop(4); //sx cammina

}

if (scout.x < mouseX) {

omino.gotoAndStop(3); //dx fermo

}

if ( scout.x + 55 < mouseX) {

omino.gotoAndStop(2); //dx cammina

}

} //end movimenti*/

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Calcola_distanza() {

cat1 = Math.floor(Math.max(mouseX, scout.x) - Math.min(mouseX, scout.x));

distanza_calcolata = Math.floor(cat1);

}

function Controllalabirinto() {

if (strada.hitTestPoint(scout.x, scout.y, true)) {

omino.x = scout.x;

} else {

scout.x = omino.x;

}

}

//SFONDO SCORREVOLE----------------------------------

function sfondomobile() {

if (limitesx.hitTestPoint(scout.x, scout.y, true)) {

if (schermata.x < 1310) {

schermata.x += vel;

}

}

if (limitedx.hitTestPoint(scout.x, scout.y, true)) {

if (schermata.x > 476) {

schermata.x -= vel;

}

}

}

Hope u can help me! Really thak u!

Views

189

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Hi.

Is it possible for you to name your variables and functions in English? Or at least you can give us a sample of the kind of movement and control you want to achieve and we may be able to suggest an alternative route for you.

Also, remember to always set the data types of your variables (var moving:Boolean = true; instead of just var moving = true;) and to properly name them and also follow other syntax conventions.

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

LATEST

Yeah I'm sorry (i worked only on the character movement, the rest of the code was made by another one of my group)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var incx = 2;

var cat1;

var ipo;

var calculated_distance= 0;

var moves = true;

var distance= 0;

var speed = 10;

stop();

addEventListener(Event.ENTER_FRAME, move);

function move (event: Event): void {

Doors();

calculated_distance();

var posmaouseX = mouseX;

var posmaouseY = mouseY;

 

incx = cat1 / 20;

if (cat1 <= distance) {

incx = 0;

}

if (posmaouseX != scout.x) {

if (posmaouseX > scout.x) {

scout.x += incx;

Checkmaze();

mobilebackground();

Doors();

} else {

scout.x -= incx;

Checkmaze();

mobilebackground();

Doors();

}

}

////////////////////////////////////////////////////////////////////////

//HERE IS THE CHARACTER MOVEMENT//

if (scout.x > mouseX) {

avatar.gotoAndStop(1); //left stop

}

if (scout.x - 55 > mouseX) {

avatar.gotoAndStop(4); //left walk

}

if (scout.x < mouseX) {

avatar.gotoAndStop(3); //right stop

}

if ( scout.x + 55 < mouseX) {

avatar.gotoAndStop(2); //right walk

}

} //end movement*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Check_maze () {

cat1 = Math.floor (Math.max(mouseX, scout.x) - Math.min(mouseX, scout.x));

calculated_distance = Math.floor(cat1);

}

function Check_maze () {

if (street.hitTestPoint(scout.x, scout.y, true)) {

avatar.x = scout.x;

} else {

scout.x = avatar.x;

}

}

//MOBILE BACKGROUND ----------------------------------

function mobilebackground () {

if (limitesx.hitTestPoint(scout.x, scout.y, true)) {

if (desktop.x < 1310) {

desktop.x += vel;

}

}

if (limitedx.hitTestPoint(scout.x, scout.y, true)) {

if (desktop.x > 476) {

desktop.x -= speed;

}

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here it is! Hi hope is ok now! And thank u for helping me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines