0 Replies - 548 Views - Last Post: 01 December 2009 - 04:26 PM

#1 briany  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 09

adobe flash need help with some of my codes

Posted 01 December 2009 - 04:26 PM

Hi im making a tennis game on Adobe Macromedia Flash and my game is just not working.... i was wondering if anybody can help me out

the game im making is a insane tennis game with 2 rackets your racket and the computers racket on each side of the screen and with 2 balls u have to hit the balls across the screen trying to make it pass each others racket but my collions does not work for my racket i can move it up and down but thats pretty much it and the computers racket collions work but it wont move... could anybody help me fix my game??? thanks...

my racket is = racket_mc
computer racket = opponentRacket_mc
ball = ball_mc
second ball =ball2_mc



Start 
stop();

start_btn.onRelease = function()
{
	gotoAndPlay("instructions")
}
controlValues();						

function controlValues()				
{
	horizontalBallSpeed = 20;			
	verticalBallSpeed = 20;				
	horizontalBall2Speed = 10;			
	verticalBall2Speed = 10;				
	opponentRacketSpeed = 2;			
	victoryScore = 60;					
}

Gameplay 
init(); 
stop();

this.onEnterFrame = function()
{
	move();
	checkBoundaries(ball_mc);
	checkBoundaries(ball2_mc);
	checkCollisions(ball_mc,ball2_mc,racket_mc);
	checkCollisions(ball_mc,ball2_mc,opponentRacket_mc);
}
function init()
{
	Mouse.hide();
	ball_mc.dx = horizontalBallSpeed;
	ball_mc.dy = verticalBallSpeed;
	ball2_mc.dx = horizontalBallSpeed;
	ball2_mc.dy = verticalBallSpeed;

	topBoundary = 0;
	bottomBoundary = Stage.height;
	leftBoundary = 0;
	rightBoundary = Stage.width;
	Score = 0;
	playerScore = 0;
}

function move()
{
	Racket_mc._y = _ymouse;
	ball_mc._x = ball_mc._x + ball_mc.dx;
	ball_mc._y = ball_mc._y + ball_mc.dy;
	ballXDist = opponentRacket_mc._x - ball_mc._x;
	ball2XDist = opponentRacket_mc._x - ball2_mc._x;
	if(ballXDist, ball2XDist < opponentRacket_mc._y)
	{
		chaseBall = ball_mc;
	}
	else
	{
		chaseBall = ball2_mc;
	}
	trace(chaseBall);
	
	
	if (ball_mc._y < opponentRacket_mc._y)
	{
		opponentRacket_mc.dy = -opponentRacketSpeed;
	}
	else
	{
		opponentRacket_mc.dy = opponentRacketSpeed;
	}
	opponentRacket_mc._y = opponentRacket_mc._y + opponentRacket_mc.dy;
	
	ball2_mc._x = ball2_mc._x + ball2_mc.dx;
	ball2_mc._y = ball2_mc._y + ball2_mc.dy;
	if (ball2_mc._y < opponentRacket_mc._y)
	{
		opponentRacket_mc.dy = -opponentRacketSpeed;
	}
	else
	{
		opponentRacket_mc.dy = opponentRacketSpeed;
	}
	opponentRacket_mc._y = opponentRacket_mc._y + opponentRacket_mc.dy;
	
} 
function checkBoundaries (sprite_mc)
{
	if(sprite_mc._y + sprite_mc._height/2 > Stage.height)		
	{
		sprite_mc.dy = -sprite_mc.dy;
	}
	if (sprite_mc._x + sprite_mc._width/2 > Stage.width)		
	{
		playerScore = playerScore + 1;
		if (playerScore==victoryScore)
		{
			gotoAndPlay("gameLose");
		}
		else
		{
			reset(sprite_mc);
		}
	}
	if(sprite_mc._y < 0)	
	{
		sprite_mc.dy = -sprite_mc.dy;
	}
	if(sprite_mc._x < 0)
	{
		trace("sprite " + sprite_mc + " just went off left side")
		Score = Score + 1;
		if (Score==victoryScore)
		{
			gotoAndPlay("gameLose");
		}
		else
		{
			reset(sprite_mc);
		}
	}
}
function reset(sprite_mc)
{
	sprite_mc._x = Stage.width / 2.0;
	sprite_mc._y = Stage.height / 2.0;
	sprite_mc.dx = -Math.abs(sprite_mc.dx); 
	sprite_mc._x = Stage.width / 2.2;
	sprite_mc._y = Stage.height / 2.2;
	sprite_mc.dx = -Math.abs(sprite_mc.dx);
}

function checkCollisions (currentBall_mc,currentBall2_mc,currentRacket_mc)
{
	if(currentBall_mc.hitTest(currentRacket_mc))
	{
		currentBall_mc.dx = -currentBall_mc.dx;
		currentBall_mc.dy = dyAdjustment (currentBall_mc,currentRacket_mc)
	}
}
function dyAdjustment (currentBall_mc,currentBall2_mc,currentRacket_mc)
{
	relativeY = currentBall_mc._y - currentRacket_mc._y;
	relativePosition = 2* (relativeY / currentRacket_mc._height);
	dyNew = verticalBallSpeed * relativePosition;
	return dyNew;
}
function checkCollision (currentBall_mc,currentBall2_mc,currentRacket_mc)
{
	if (currentBall_mc.hitTest (currentRacket_mc))
	{
		currentBall_mc.dx = -currentBall_mc.dx
		currentBall2_mc.dx = -currentBall2_mc.dx
		currentBall_mc.dy, currentBall2_mc.dy = dyAdjustment (currentBall_mc, currentBall2_mc, currentRacket_mc)
	}
}




thanks

This post has been edited by briany: 01 December 2009 - 04:31 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1