473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

flash cs3 gaming help

2
hi
im creating a brick builder game

ive got the paddle and ball moving now i just want the ball to bounce off the paddle hit the brick and then the brick disappears, i am using document classes, im just stuck on this bit, any help would be appreciated, please need your help lol

Expand|Select|Wrap|Line Numbers
  1. package {
  2.     import flash.display.*;
  3.     import flash.events.*;
  4.     import flash.text.*;
  5.     import flash.ui.Mouse;
  6.     public class Breakout extends Sprite {
  7.         var ball_mc:Ball;
  8.         var xVel:int=10;
  9.         var yVel:int=10;
  10.  
  11.         var paddle_mc:Paddle;
  12.  
  13.         function Breakout() {
  14.             ball_mc=new Ball();
  15.             ball_mc.x=100;
  16.             ball_mc.y=100;
  17.             this.addChild(ball_mc);
  18.  
  19.             paddle_mc=new Paddle();
  20.             paddle_mc.x=250;
  21.             paddle_mc.y=380;//this positions the paddle on the screen, currently at the bottom of the screen//
  22.             this.addChild(paddle_mc);
  23.             paddle_mc.init();
  24.             start_btn.addEventListener(MouseEvent.CLICK,startGame);
  25.             this.addEventListener(Event.ENTER_FRAME, updateGame);
  26.         }
  27.         function startGame(evt:MouseEvent) {
  28.             this.addEventListener(Event.ENTER_FRAME,moveBall);
  29.             start_btn.visible=false;
  30.         }
  31.         private function updateGame(e:Event) {
  32.             paddle_mc.moveIt();
  33.         }
  34.         function moveBall(e:Event) {
  35.             ball_mc.y=ball_mc.y-yVel;
  36.             ball_mc.x=ball_mc.x-xVel;
  37.             if (ball_mc.x>this.stage.stageWidth || ball_mc.x<0) {
  38.                 xVel=xVel*-1;
  39.             }
  40.             if (ball_mc.y>this.stage.stageHeight || ball_mc.y<0) {
  41.                 yVel=yVel*-1;
  42.             }
  43.         }
  44.         //Hitting the paddle
  45.         if (Ball.hitTestObject(Paddle)) {
  46.             calcBallAngle();
  47.         }
  48.     }
  49. }
Expand|Select|Wrap|Line Numbers
  1. package {
  2.     import flash.display.MovieClip;
  3.     import flash.events.*;
  4.     import flash.events.KeyboardEvent;
  5.  
  6.     public class Paddle extends MovieClip {
  7.         var left:Boolean;                    
  8.         var right:Boolean;                    
  9.  
  10.         function Paddle() {
  11.             this.stop();
  12.         }
  13.         function init() {
  14.             this.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);    
  15.             this.stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);        
  16.         }
  17.  
  18.         private function keyDownHandler(e:KeyboardEvent):void {
  19.             if (e.keyCode==37) {            
  20.                 left=true;
  21.             }
  22.             if (e.keyCode==39) {            
  23.                 right=true;
  24.             }
  25.         }
  26.         private function keyUpHandler(e:KeyboardEvent):void {
  27.             if (e.keyCode==37) {            
  28.                 left=false;
  29.             }
  30.             if (e.keyCode==39) {            
  31.                 right=false;
  32.             }
  33.         }
  34.  
  35.         function moveIt() {
  36.             if (left==true) {                
  37.                 this.x-=10;
  38.             }
  39.             if (right==true) {                
  40.                 this.x+=10;
  41.             }
  42.             if (this.x <= 48) {                
  43.                 this.x+=10;
  44.             }
  45.             if (this.x >= 500) {            
  46.                 this.x-=10;
  47.             }
  48.         }
  49.     }
  50. }
my two class files, your help would be much appreciated thank you
Mar 29 '10 #1
0 1240

Sign in to post your reply or Sign up for a free account.

Similar topics

42
by: Manu | last post by:
How can i do with a flash object for obtain the w3c label ? the "embed" is not accepted ! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title>...
0
by: Uma Vivek | last post by:
Hi, I have a problem with Flash remoting via .NET . I seem to have all the code right, but flash does not seem to display the data at all. Here's is what Ive done so far... (1) Ive...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
9
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes...
10
by: Scott | last post by:
I have written an Access application that our employees use on a daily basis to enter information. It's comprises of a series of forms, a few data integrity check queries that run in the...
0
by: tanv70 | last post by:
Hello, I am considering starting up my own online gaming site to include muti-player bingo, slots, keno, and possibly more. This will need to include player registration and password...
0
by: Jeff Rush | last post by:
At PyCon this year we're going to have a multi-day game programming clinic and challenge. This is a first-time event and an experiment to find those in the Python community who enjoy playing and...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
1
by: dosingh | last post by:
i've put this page together using asp, html, javascript amd flash. java passes a number of variables over to the flash file but the flash graph does not appear. The error which appears is...
1
by: breckj | last post by:
Hi, I would like to learn C++ and become a gaming programmer. Your suggestions to the following are appreciated. Q1) What development software do you suggest (compiler, code editor, ide, etc)?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.