473,549 Members | 5,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

flash cs3 gaming help

2 New Member
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 1250

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

Similar topics

42
4923
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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
0
2020
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 installed Flash Remoting MX, and copied over the contents of wwwroot\flashremoting\bin into my web application's folder\bin.
383
11856
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 poor man's DBMS, a broken email server and various other /application/ servers to try and crack the Internet and IS markets. In the case where they...
9
8566
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 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). On the aspx page I have the object tag as follows:
10
2727
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 background and a few reports. Quite often I lament at the limitations of using forms, in particular how to make something that looks "stylish". This...
0
1178
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 retrieval, scripts for the games to run smoothly, database for wins/losses, a My account area so players can edit information, e-commerce so I can actually...
0
1830
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 creating games. Python has several powerful modules for the creation of games among which are PyGame and PyOpenGL. On Friday evening, Phil Hassey...
8
5877
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic...
1
2272
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 SWFObject in undefined. The script tag contained <script type="text/javascript"> but after taking the "text/" out the, the pages shows not error but also not...
1
1717
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)? Free versions as well as priced, thanks. Q2) Regarding OS, does anyone recommend Linux over Windows (XP, Vista, 7)? What OS do you recommend? Q3)...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.