Trying to do a charged shot for a game
My name is Justin and I know next to nothing about Coding. Yet I was assigned to a coding team for a game we're working on for school. I managed to put together a decent shooting mechanic for our game by watching tutorials but I can't find any sources or tutorials on how to do charged shots. Here's my code. Any help would be much appreciated.
Main timeline:
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;
var leftBumpPoint:Point = new Point(-30, -55);
var rightBumpPoint:Point = new Point(30, -55);
var upBumpPoint:Point = new Point(0, -120);
var downBumpPoint:Point = new Point(0, 0);
var scrollX:Number = 0;
var scrollY:Number = 0;
var xSpeed:Number = 0;
var ySpeed:Number = 0;
var speedConstant:Number = 4;
var frictionConstant:Number = 0.9;
var gravityConstant:Number = 1.8;
var jumpConstant:Number = -35;
var maxSpeedConstant:Number = 18;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(Event.ENTER_FRAME, loop);
var bulletList:Array = new Array();
function loop(e:Event):void{
if(back.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
leftBumping = true;
} else {
leftBumping = false;
if(back.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
rightBumping = true;
} else {
rightBumping = false;
if(back.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
upBumping = true;
} else {
upBumping = false;
if(back.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
downBumping = true;
} else {
downBumping = false;
if(leftPressed){
xSpeed -= speedConstant;
} else if(rightPressed){
xSpeed += speedConstant;
if(leftBumping){
if(xSpeed < 0){
xSpeed *= -0.5;
if(rightBumping){
if(xSpeed > 0){
xSpeed *= -0.5;
if(upBumping){
if(ySpeed < 0){
ySpeed *= -0.5;
if(downBumping){
if(ySpeed > 0){
ySpeed = 0;
if(upPressed){
ySpeed = jumpConstant;
} else {
ySpeed += gravityConstant;
if(xSpeed > maxSpeedConstant){
xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){
xSpeed = (maxSpeedConstant * -1);
xSpeed *= frictionConstant;
ySpeed *= frictionConstant;
if(Math.abs(xSpeed) < 0.5){
xSpeed = 0;
scrollX -= xSpeed;
scrollY -= ySpeed;
back.x = scrollX;
back.y = scrollY;
function keyDownHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = true;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = true;
} else if(e.keyCode == Keyboard.UP){
upPressed = true;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = true;
function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = false;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = false;
} else if(e.keyCode == Keyboard.UP){
upPressed = false;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = false;
if(e.keyCode == Keyboard.SPACE){
fireBullet();
function fireBullet():void {
var playerDirection:String;
if(player.scaleX < 0){
playerDirection = "left";
} else if(player.scaleX > 0){
playerDirection = "right";
var bullet:Bullet = new Bullet(player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);
back.addChild(bullet);
bullet.addEventListener(Event.REMOVED, bulletRemoved);
bulletList.push(bullet);
function bulletRemoved(e:Event):void
e.currentTarget.removeEventListener(Event.REMOVED, bulletRemoved); //this just removes the eventListener so we don't get an error
bulletList.splice(bulletList.indexOf(e.currentTarg et), 1); //this removes 1 object from the bulletList, at the index of whatever object caused this function to activate
External AS File(Bullet)
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
public class Bullet extends MovieClip {
private var speed:int = 30;
private var initialX:int;
public function Bullet(playerX:int, playerY:int, playerDirection:String, playerSpeed:int) {
// constructor code
if(playerDirection == "left") {
speed = -30 + playerSpeed; //speed is faster if player is running
x = playerX - 25;
} else if(playerDirection == "right") {
speed = 30 + playerSpeed;
x = playerX + 25
y = playerY - 75;
initialX = x; //use this to remember the initial spawn point
addEventListener(Event.ENTER_FRAME, loop);
public function loop(e:Event):void
//looping code goes here
x += speed;
if(speed > 0) { //if player is facing right
if(x > initialX + 640) { //and the bullet is more than 640px to the right of where it was spawned
removeSelf(); //remove it
} else { //else if player is facing left
if(x < initialX - 640) { //and bullet is more than 640px to the left of where it was spawned
removeSelf(); //remove it
public function removeSelf():void
trace("remove self");
removeEventListener(Event.ENTER_FRAME, loop); //stop the loop
this.parent.removeChild(this); //tell this object's "parent object" to remove this object
//in our case, the parent is the background because in the main code we said:
//back.addChild(bullet);
import flash.events.KeyboardEvent;
import flash.utils.Timer;
stage.addEventListener(KeyboardEvent.KEY_DOWN, startTimer);
stage.addEventListener(KeyboardEvent.KEY_UP, endTimer);
var _timer:Timer = new Timer(3000,1);
var charged:Boolean = false;
var _keyDown:Boolean = false;
_timer.addEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
function startTimer(e:KeyboardEvent):void{
if(!_keyDown){
_keyDown = true;
_timer.start();
charged = false;
function endTimer(e:KeyboardEvent):void{
trace("KEY UP");
_keyDown = false;
if(_timer.running){
_timer.stop();
trace(charged);
function completeHandler(e:TimerEvent):void{
trace("TIMER ENDED");
charged = true;
_timer.stop();
Similar Messages
-
Got charged $80 for a game I never bought
I got charged $80 for one of those games with in-app purchases. I never bought this game (I'm the one who has access to my laptop and iPod), so it wasn't a mistake from someone else. I don't even have that game installed on the iPod or in iTunes.
The game was:
MetalStorm: Online™, A Gigantic Pack of Coins, Seller: Z2Live, Inc
Does Apple give back the money in situations like this?
What worries me the most though, was that some kind of scam/hacking that the creators of the game did, is it a common mistake, or someone tried to hack my account?
Should I change passwords?
ThanksWow, same happen to me too. Some stupid game i dont even have. In-app $10 purchase on June 18th... I didn't even use my ipad for 3 days...
So i am also wodering what apple will do about that. -
Hello all
My daughter has tried to download paid apps, she is three so is forgiven but I don't want them and certainly don't want charging for them.
Only issue is its now wanting me to enter billing info when I download a free appHow can I get a prepaid iTunes card?
Buy one from the Apple Store or retailer who sells them. Since you don't say where you are, I can't tell you specific store names.
How much is it?
They're issued in denominations. In the US, they start at $10.
what would be the procedure for me to pay that money I owe, since I dont have another credit card?
Redeem a prepaid card or gift certificate.
Your only other option would be to contact the iTunes Store, explain the problem, and ask if they'll cancel that 99-cent purchase. There's no way of knowing if they will since the terms of sale state that all sales are final, but you can ask. Go here:
http://www.apple.com/support/itunes/contact/
and follow the instructions to contact them.
Regards. -
HT201359 I have been charged twice for a game ? How do I get my money back ?
I have been charged twice to unlock an episode on candy crush ' how do I get my money back pls ?
Thanks
MichelleYou can contact iTunes support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
-
Hi, im trying to make an inapp purchase for a game. However whenever i clicked buy, a pop-up appears and said " your purchase could not be completed" please contact... and the transaction never occurs. Do you have any idea what isN
Hi..
First, turn off the auto subscription until the matter is resolved > iTunes Store: Purchasing and managing auto-renewing subscriptions
Since you have not heard back from the developer, report the issue to Apple.
You can use the email form here.
And try here > iOS: Troubleshooting applications purchased from the App Store -
My iPhone 4 died. I tried charging it for 3 hours; it wont hard reset or even show up on my computer or itunes. is there anything i can do?
Try:
- Reset the iOS device. Nothing will be lost
Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears.
- Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
- Make an appointment at the Genius Bar of an Apple store.
Apple Retail Store - Genius Bar
You can also try going to Settings>General>Reset>Ease all content and Settings. However, you may not be able to restore via iTunes. You might only be able to only restore from iCloud backup if you have a hardware problem, -
i got charged twice for a movie (Safe House). Can i get a refund for that? we were not able to finish the movie last night, and now we're trying to watch it again. We have an hour left, however the apple tv is still loading the movie again for 2 hrs & 46 mins.
Welcome to the Apple Community.
Apple's policy on sales of digital content is that all sales are final. If however you wish to appeal to Apple, select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History. -
I had switches off my iPhone 5 at around 20 percent battery next morning I was not able to switch it on. I tried to get it charged but it didn't showed any sign of charging even when plugged in for about 2 hours. I had to take it to apple care centre but they refused to repair it after confirming the problem with the device as it was out of warranty and asked me to get it replaced for INR 22500. I got it repaired outside but after that also if I switch it off in the same situation it again happens and I have to take it for repair it has happened 3 times after that. Is it a inherent problem in iPhone that it uses battery even when switched off and if in that case battery drain out then refuse to get charged because this is the scenario i have experienced every time?
Apple told you it was unrepairable.... You had it serviced by an unauthorized party. It's now no longer eligible for out of warranty replacement by Apple.
There's really nothing else we can say about it. Find a competent 3rd party repair shop or buy a new one. -
Hi, my iPad dies in the middle of a purchase for a game add on, when I charged the iPad and reloaded the game a box is on the screen that says " cannot complete your purchase" I can't slope this box, and cat play the game while it is there, I have tried removing the game several times and reinstalling but the box still appears, I even tried installing the game on a different apple I'd, and still the box is there, do you k ow how to fix this?
Hi Bev076,
I would try these ideas first:
iPhone, iPad, iPod touch: Turning off and on (restarting) and resetting
http://support.apple.com/kb/HT1430
If that doesn't resolve the situation, I would suggest reporting it:
How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
http://support.apple.com/kb/ht1933
Take care,
- Ari -
So I was downloading albums for my phone on the macbook pro and I tried putting in the charger for my phone but i had it in reverse and when i tried putting it in it just completely turned off. When i connected it to the charger the light on the charger for the laptop would just flickr green and red lightly.
-
I have a iPod classic 2gb. I haven't used in years and I charged it for 3 hours and it won't turn on and I tried resetting and nothing. I plugged it into iTunes and iTunes doesn't even recognize it. I just have a black screen. PLEASE HELP!!!
I'm sorry it's a nano 2gb silver
-
Hello I was charged twice for adobe story plus, I need this problem corrected and a refund issued for one of the subscription charges, I tried chatting with Adobe and they were unable to help me. Where is email support?
This is an open forum, not Adobe support... you need Adobe staff to help
Adobe contact information - http://helpx.adobe.com/contact.html
-Select your product and what you need help with
-Click on the blue box "Still need help? Contact us"
-or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html -
My iPhone 5s won't turn on. Its battery was drained for more than a month. I tried charging it for more than an hour then pressed reset but it still won't turn on. What could be the problem?, My iPhone 5s won't turn on. Its battery was drained for more than a month. I tried charging it for more than an hour then pressed reset but it still won't turn on. What could be the problem?
You said "reset," so Meg assumed that's what you did. But "reset" is not a button; to reset the phone you must hold the HOME and SLEEP buttons at the same time until an Apple logo appears. You may have to hold for up to 30 seconds, and if the battery was completely drained, you will have to restore iOS using iTunes on your computer.
-
I was told at the Mac store, if download Numbers and Pages with my Imac I could install it on my Macbook for no extra charge. True? Tried it and was charged twice
Cynthia7 wrote:
so if i'm trying to use keynote on my imac after i purchased it on my ipad first, can i do that for free if i already paid for it once? and if i can, how? any advice will help. thanks.
Sorry, no. The versions for Macs and iDevices are different. -
Hi, I've tried charging continuously for 72 hours. But to no avail. It just stopped working out of the blue. Actually I believe I let the battery die off completely. When I tried charging it again, it never worked.
I had only used it for about 1 month.
I bought this in January at Best Buy, and still have the receipt. I was on long business trip and just got back. I can't get the 90 day customer service. How can I get this returned to Black Berry, they won't allow me to contact them without providing my credit card for incidence based service.
Please help! Thanks.do any LED color happen when you plug it in?
if only RED, then pug in until red goes out, wait 6 seconds and plug in again.
repeat 3 times and wait to see if 5 green flashes while plugged in
after 5 flahes, leave it plugged in for 90 minutes and it should boot up. if not hold power button down for 20 seconds and try again.
You have 1 year warranty, choose option other when calling in and not phone support. This is confusing I know.
Click here to Backup the data on your BlackBerry Device! It's important, and FREE!
Click "Accept as Solution" if your problem is solved. To give thanks, click thumbs up
Click to search the Knowledge Base at BTSC and click to Read The Fabulous Manuals
BESAdmin's, please make a signature with your BES environment info.
SIM Free BlackBerry Unlocking FAQ
Follow me on Twitter @knottyrope
Want to thank me? Buy my KnottyRope App here
BES 12 and BES 5.0.4 with Exchange 2010 and SQL 2012 Hyper V
Maybe you are looking for
-
Synchronising contract data in R3 AND CRM
Hi All , Greetings for the day!! I had appended a new field in contract (VBAP-ZZFIELD) in R3.This contract first get created in CRM and gets copied in R3. Whatever changes i make to new field in R3 must gets copied to same contract in CRM & vice ver
-
Audio Missing When Exporting to Flash
When I export this Keynote presentation to Flash, I get an error message that says "Can't export an audio file because of an unknown error." Then it says that "Couldn't export a media file on slide 1" and so on for all 10 slides. It's basically a pre
-
Reservation Creation in Issue Unit of Measure
Hi, I have a product whose component has Base Unit of Measure as EACH and Issue unit of Measure is PIECE. ( 5 Piece = 1 Each) .In BOM we maintain as PIECE and in Work Scheduling view of materialMaster issue unit is maintained as PIECE. Now the issu
-
Wacom Intuous4 in Lightroom configuration/settings
I bought a Wacom Intous4 about a month ago, and am loving it so far. I'm still in the process of deciding how I want to set up my ExpressKeys, Touch Ring, and Radial Menu, so I thought I'd check in here and see what other folks are doing. How have yo
-
CcBPM: Message outbound status, Message being sent
Hi I have a message with status flag message being sent at the outbound status PE since 30 days. Because of this message many messages got blocked with scheduled on outbound side status. I tried to delete work items related to the message in SWWL, bu