Drawing Arcs (For a cannon game)

I was wondering if anyone could help me out with a java program I'm trying to write. I need to draw an arc from a specific location (which I can handle) but I want it to simulate a cannon fire. All I'm really worrying about at this time is involving gravity - I have no idea how to do this. I'm asking the user for an angle, and the velocity.
If anyone can help explain an equation that would draw an arc please do so! :)
(I've tried looping through the x coordinates which seems to work well, but I don't have a proper equation for y :P)

I think you wouldn't draw an actual arc at all. Instead you'd plot points. You know the cannon velocity. From the cannon angle you can get the X and Y delta (Amount of change in X and Y per time click).
For each time click you plot a point in the X direction - wind speed and in the Y direction - gravity.
For example, let's say that that we ignore wind and we're just shooting from left to right and we're shooting at a 45 degree angle. Y = mX + b tells us that the rise and run for a 45 degree angle are the same. And just for fun let's say that gravity is 0.2 So for each plot you take the previous plot and add subtract the energy lost to gravity. But your X direction stays constant because of the lack of wind resistence. Here we go:
Turn is the time click, X and Y are your delta and LocX and LocY are the location of the dot relative to the end of the cannon
Turn  X   Y    LocX   LocY
1     1   1     1       1
2     1   0.8   2       1.8
3     1   0.6   3       2.4
4     1   0.4   4       2.8
5     1   0.2   5       3.0
6     1   0     6       3.0
7     1  -0.2   7       2.8
8     1  -0.4   8       2.4
9     1  -0.6   9       1.8
10    1  -0.8   10      1.0
11    1  -1.0   11      0So after 11 turns the shell crashes into the ground (Assuming level ground) For uneven ground you just test LocX and LocY for an intercept with your ground level.
You can see how you would do the same thing for wind resistence as well. That would simply change your X increment.
Hope that helps
Greg

Similar Messages

  • New To Illustrator CS4  - How do you select the Arc Tool to Draw Arcs?

    PDF on Illustrator doesn't indicate how to select the Arc tool. Extract from toe pdf follows:
    Draw arcs
    1 Select the Arc tool .  (HELP -- I CAN'T LOCATE THE ARC TOOL).
    2 Do one of the following:
    • Position the pointer where you want the arc to begin, and drag to where you want the arc to end.
    • Click where you want the arc to begin. In the dialog box, click a square on the reference point locator to determine the point from which the arc is drawn. Then set any of the following options, and click OK.
    Length X-Axis
    Specifies the width of the arc.
    Length Y-Axis
    Specifies the height of the arc.
    Type
    Specifies whether you want the object to be an open path or a closed path.
    Base Along
    Specifies the direction of the arc. Choose X Axis or Y Axis depending on whether you want to draw the base of the arc along the horizontal (x) axis or vertical (y) axis.
    Slope
    Specifies the direction of the arc’s slope. Enter a negative value for a concave (inward) slope. Enter a positive value for a convex (outward) slope. A slope of 0 creates a straight line.
    Fill Arc
    Fills the arc with the current fill color.
    Note: To see a dynamic preview of the arc as you set options, double-click the arc tool in the Tools panel.

    You're welcome.
    Can i suggest that you explore al the tools there are drop down menus and on the panels as well in the upper right hand corner there is a drop down with useful functions and options. Also look at the control panel under the menu bar as you change tools to see the option each tool has and also some tools have further settings if you double click the icon in the tool bar other have option if you click in the document window once you have selected them.
    But the best advice I can give you is to buy Mordy Goldings book Real World Illustrator CS 4 he also has one for  the suites, it is a worthwhile investment.

  • Need help/hints/tips with a method for connect 4 game.

    Hi!
    I'm currently trying to get my "movepiece"-method to make it so that players can only drag a piece into the empty square at the bottom row, and if the square is not empty the method will move up one row and check if it's empty if not, repeat until
     6 are checked if no one is empty then move is invalid.
    I've been trying out while loops and for loops but i think i might set the wrong conditions for exiting the loop...
    Here the code for the method without any loops simply adds pieces.
            /// <summary>
            /// Method that performs the actual move.
            /// The old piece gets overrun by the attacking piece. 
            /// The attacking piece's position becomes null.
            /// </summary>public Piece[,] MoveAttackpiece(int[,] changearray)
    int origX = changearray[0, 0];
    int origY = changearray[0, 1];
    int targetX = changearray[1, 0];
    int targetY = changearray[1, 1];
    pieceArray[targetX, targetY] = pieceArray[origX, origY]; //swap
    return pieceArray;
    The game is using winforms and a 2D array(pieceArray)to draw the game board
    I'm using a Constants class for declaring the height and width of the board, which the pieceArray is based on, Namely const int BOARDESIZEx and BOARDERSIZEy.
    And while i'm at it when i did different loops for tryng to make the piece move down/up (based on if a square in bottom row was empty or not) the program crashes and i get the "Null Reference Exception unhandled"
    at this part in the game.CS (the earlier code reside in a class named Squares.cs)
    if (changearray != null)
    //Building string to print (split over several rows for readability but also to avoid calculations)
    Piece attackpiece = pieceArray[changearray[1, 0], changearray[1, 1]];
    string message = "";
    if (move % 2 == 1) message += "TURN " + move / 2 + ":\r\n"; //integer division, as there are two draws per turn
    message += attackpiece.Name + ": "; //Walker:
    message += IntegerToChar(changearray[0, 1]); //Walker: A
    message += (changearray[0, 0] + 1) + " - "; //Walker A1 -
    message += IntegerToChar(changearray[1, 1]); //Walker A1 - B
    message += (changearray[1, 0] + 1); //Walker A1 - B2
    if (move % 2 == 0) message += "\r\n"; //blank row inserted after each completed turn
    Board.PrintMove(message);
    I've tried making
    While(piecearray[targetX, targetY]!=null)
    pieceArray[targetX, targetY]==pieceArray[targetX, targetY +1];
    return array;
    but that didn't work and i don't really know how to make the game start at bottom row.
    I appreciate any help or tips on how to get this to work since it's the only thing left for making the game work as intended.
    Cheers and thanks for reading.
    PS: if there's anything you wonder just ask and i'll explain as much as i can.
    Regards Gabbelino
    Student at the University of Borås, Sweden

    Let's look at what's wrong with the following code.
    While(piecearray[targetX, targetY]!=null)
    pieceArray[targetX, targetY]=pieceArray[targetX, targetY +1]; // I assume the "==" in your post above was a typo.
    Suppose, for the sake of argument, that targetX is 2 and targetY is 3, and that pieceArray[2,3] is not null. The line inside the loop will then become...
    pieceArray[2,3] = pieceArray[2, 4];
    ...and this line will keep being executed as long as pieceArray[2,3] is not null, which if pieceArray[2,4] is not null will be forever (infinite loop).
    I suspect that your loop should look something like this...
    for(int i = 0; i < BOARDSIZEy; i++)
    // Look for the first available square in the target column.
    // When found, set the piece on that square then break out.
    if(pieceArray[targetX, i] == null)
    pieceArray[targetX, i] = pieceArray[origX, origY];
    break;

  • How to find a good AI strategy for a survival game?

    Hi, I'm a college student here developing a tank survival game for the finals. I have had very little experience in AI strategies, so I wonder if anyone here can give me a hint or two to start.
    Thanks.
    The game's description is below:
    Goal:
    Develop a good AI strategy for survival.
    ������������������������������������������������������������������������������������������
    Game Name: Tank Survival
    How game starts: All tanks will be placed on the board in random position
    How game ends: When we have only one tank surviving, that's the winner
    When does a tank die? When the energy of a tank is zero, it dies.
    Game environment: A 15x15 closed environment, like a chess board
    Participants: 5 teams, 3 tanks per team
    ������������������������������������������������������������������������������������������
    Game Basic Rule
    For each tank, only 1 action is allowed each turn.
    A tank can move with a shield on, but shield costs energy.
    When one tank destroyed another one, it takes all the energy left of the victim
    tank. *(Bonus from kill � 1000 + (1/2)*Enemy energy before kil)
    The tank's weapon can only shoot in continuous linear way.
    ������������������������������������������������������������������������������������������
    Facts about the tank
    Initial Tank Energy - 10000
    Life Support Energy cost �- 50
    Missile yield multiplier - � 3
    Shield multiplier - � 5
    Radar Cost = [(distance * accuracy) ^1.3] * 3 + 100
    Missile Cost � yield + accuracy * distance * 7
    Movement Cost = (distance^1.4) *50
    Shield Cost = multiplier * Energy shielded
    Maximum movement - distance � 5 (any direction)
    Bonus from kill -� 1000 + (1/2)*Enemy energy before kill
    Missile accuracy -� not disclosed
    Radar Accruacy �- not disclosed
    ������������������������������������������������������������������������������������������
    Key problems
    � I only have 3 tanks. . .
    � I have to survive among the other 15 tanks.
    � None of the actions, misile, radar, or shield are 100% working. There are always chances that they don't work.

    I think the first stage is to work out what constitutes a "state" and a "move." A state is the current board positions with all the tank energies and other parameters. A move is a transition from one state to another. Can you move around? Can you fire the gun and move the tank at the same time? If you fire the gun, does it miss sometimes?
    You then have to have a way to evaluate a state. For instance, if you move closer to an enemy tank, does that put you in a better position or a worse position?
    You can then draw a Moves Tree. This starts from where you are, shows all the moves you could make and the states you could end up in after one move. You can attach a value to each state.
    Then you can extend the state tree by adding all the counter moves your enemy could make, and the states in which those moves would leave the game. Thus the transition from your state now, to your state after the enemy has moved, will show a gain or a loss, depending on whether you or the enemy gained more or lost less.
    The strategy that wins the game will be the one that takes you from the start state to the goal state in such a way that your enemy cannot stop you. There are two possible strategies for choosing moves, Minimax and Maximin. Minimax means minimise your maximum loss; Maximim means maximise your minimum gain.
    Try it first with a simple game like Nought and Crosses. The state tree grows very rapidly in the number of moves, so you may need some algorithm for pruning it or for generating only part of it at a time, as modern chess playing algorithms do.
    Write in a computer language that is good at handling state trees. I used to use Prolog but some programmers swear by Lisp. You won't be able to solve the problem in a crap language like Basic, Pascal or anything like those.
    You will need to read around the subject. If Alan Bundy has written anything recently, look at that first: he is an excellent writer and a very skilful practitioner as well.

  • When did Draw Arc .vi Change Format?

    In LabView 6.1, Draw Arc .vi had different wiring than in LabView 2010.  I ran into a problem with a VI that I was using as a small subVi that is part of a much bigger Vi and now won't work because the Draw Arc.vi has incorrect wiring.  The only difference I can see is that what is now a connection for "PEN" (cluster wire) was a connection for "black in B/W" (boolean wire).  Basically I had a green circle that slowly turned to black as seconds ticked down.  I have tried using the "PEN" control, entering "0" as pen color and line as "solid" but still does not work as before.  Any help would be much appreciated.  Thank You, Scott

    swins,
    hmm, sounds to me like it might not be the draw arc control. Are you sure that's the only one that could have broken in the upgrade? I dropped a simple little visual counter (just tied the arc size to the index of a for loop) into a sub vi as a test, and everything is working just fine for me. I'm interested to find out what's going on with your control that I can't replicate the issue. Maybe it's something specific with the color changing? 
    Cheers!
    TJ G

  • When I upgraded to ios 5, it asked me a for a new game center name.  How do I use my old game center name, since it makes me start some games over without it?

    When I upgraded to ios 5, it asked me a for a new game center name.  How do I use my old game center name, since it makes me start some games over without it?

    Carefully follow steps 1-9 outlined by wjosten in this post: https://discussions.apple.com/message/13356770#13356770.  This will not, however, avoid wiping any non-purchased media from your phone (ripped CDs, etc.) as this is only synced one way: from your computer to your phone.  You will have to either rebuild your iTunes library with this content and sync again to restore it to your phone, or purchase 3rd party software to copy it from your phone to iTunes prior to syncing (such as Touch Copy).

  • I have an iPad 2 and so does my mom.  We both have the app Slotomania and now all of sudden after having it for months, our games connected and we don't know how to fix it.  Deleting it and reinstalling does not work.

    I have an iPad 2 and so does my mom.  We both have the app Slotomania and now all of sudden after having it for months, our games connected and we don't know how to fix it.  Deleting it and reinstalling does not work.

    Does the app now use iCloud, do you use iCloud and do the two of you use the same account on iCloud?
    Just a guess.

  • Purchased Itunes card..Have balance on my itunes account but trying to use the balance for an APP game...how do i transfer the funds ?

    I had a itunes card purchased for me...I redeemed it on my iphone in the Itunes APP...shows it was redeemed succesfully.Want to use the balance for an APP game i have....SImpsons Tapped out...hoe do i transfer it to it . it keeps using my credit card for purchasing premium items...how do i fix this to the itunes balance...thanks

    So then put any sim card in and restore it.  this isn't rocket science

  • Looking for a IPad Game App

    HI I am look my for a iPad Game Apps. Is there a Scrabble/Words with Friends type Games (That are Similar) where you can use First Bames and the Names of Countries?

    Search the Apple Store, there are many many words games in the style of Scarbble, inluding Scrabble itself. What rules they have and what types of words they allow Is hard to say.  But you can download some free versions and try them out to see how they play, and what they allow.

  • Looking for a simple drawing application for my grand-daughters

    Well, that's more or less it, I'm looking for a simple drawing application for my grand-daughters. In the children section of iTunes store, there's only a few books and nothing more. I bought the iPad mainly for my grand-children to teach them a bit and I don't find interesting things for them.
    Can anybody help me with that?
    Pedro Godfroid Goffin

    Brushes is a nice finger drawing app. Since you didn't say how old they are, I don't know if the interface is to difficult for them to use.
    Sketchbook is another nice drawing app.
    Neither are free.
    Glor

  • Trying to install Camera Raw 6.7 for a Cannon EosX, always fails.

    Hello,
    I am trying to install the Camera Raw 6.7 update for a Cannon EosX on a Mac, it always fails during the install saying that the administrator is suppressing the update.  I am logged into the administrative account on this computer, and can not figure out what is preventing the install from going through.
    The laptop is an OS 10.8.5 Mac, using Potoshop CS5.
    Has anyone run into this?  Any solutions out there?

    try a manual update, http://www.adobe.com/downloads/updates/

  • I want to buy Diamonds for my tos game but it come out a message ask me to contact itune support, can anyone help me with this? Cuz I had tried for a long time but still can't buy.

    I Want to buy diamonds for my tos game but it come out a message ask me to contact itune support. Can anyone help me with this? What should I do so that I can buy my diamonds?

    You can contact iTunes support via this page and ask them why the message is appearing (on these forums we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then try selecting Purchases, Billing & Redemption

  • Is there a app that will restrict all accesss to my iphone except for my sons games

    I was curious if there are specific apps out there to limit complete access to my phone except for my sons games, as in if he wants to play a game i click an app witch i can add and remove games to and once he is in that app he cant go to the home screen, he cant access anything on the phone, no messages, no calls, no nothing. I was looking at restrictions but i dont want him to try and figure out a pin number then incidentally make an emergency call. So in short is there a way or an app that will basically function as a multiple users on a computer dose?

    There is guided access, that you can enable a single app to run in, and it can not be easily exited from.
    Settings>General>Accessibility>Guided Acess

  • Not really a problem just would like to know if I install firefox 4 beta...will I lose my bookmarks already in my current firefox browers and is that the same for the farmville game bar from facebook

    Not really a problem just would like to know if I install firefox 4 beta...will I lose my bookmarks already in my current firefox browers and is that the same for the farmville game bar from facebook

    It should not be a problem, as long as you are careful. Note the delete settings option when uninstalling firefox will delete bookmarks etc for ALL installed versions of firefox.
    Firefox attempts to retain the profile information, that include bookmarks etc when updating. It may still be prudent to consider other backup methods not entirely dependent on firefox.
    The firefox 4 beta will install by default in a slightly different location, you are then able to run either the current or the beta version of firefox. It is recommended you set up a new profile for the new version of firefox. see
    * [[managing profiles]]
    *[http://kb.mozillazine.org/Testing_pre-release_versions]

  • Using Java for scripting in games - which technology to use?

    Hi, I'm currently in the process of implementing a java scripting implementation for a 3D game engine. Any suggestions on which java technology to use? It will handle high level game specific logic and a gui. So there will be a native implementation of awt created as well. I'm starting off with win32 and will port to mac and linux later.
    I'm thinking J2ME-CDC, but then theres CDLC, the personal edition, and so on. CDC and CDLC are nice since the jvm code is included but the CDC one needs to be ported to win32 (anyone already do this?)

    J2ME is designed for small consumer devices such as mobile phones, pda, pagers, set-top boxes and so on.
    You'r designing something for windows, mac and linux so I'd suggest standard edition rather than micro edition.
    I'm confused as to what you want to do though.
    Also, "porting" a java program shouldn't really be an issue (unless you've used lots of JNI or Runtime stuff).
    Basically though I don't really understand what you want to do, I did have some idea, but then you started talking about Micro Edition.

Maybe you are looking for

  • ESB FTP Adapter Help

    Hi I am switch from TIBCO products to Oracle so I am kinda lost. Sorry if these questions are too newbie. 1. Is it possible to configure multiple FTP adapters polling files from various FTP sites? I think it s a YES. Can you tell me how? I need to pe

  • Using multiply effect on illustrator file with 2 color job?

    Hi, Encountering a tricky problem and not sure if its an InDesign fix or an Illustrator fix. I am working on a 2 color job—pms color + black on a book cover. The cover needs to seperate into these 2 colors. Also, I need to make a high res and lowres

  • Create an image and not display it but saving it as a gif

    hi there, i want to save an offImage as a gif. i have something like this (just the main lines) JPanel jp = new JPanel() Image img = jp.createImage(w,h); Graphics gph = img.getGraphics(); gph.draw... I've got an encoder class (GifEncoder) which works

  • Problem with loading dll in CrEme VM

    Hi, I want to create an application for Pocket PC and I must user a dll. I use NetBeans 6 on my desktop and CrEme as CDC implementation. I write a CDC application which works fine on my PC, but in the Emulator (Windows Mobile 6) throw this error java

  • SAP Crystal Reports

    I downloaded and installed a CR for visual studio 2010 beta 2. However after installing it on windows 7, there seems to be an error when i try tom load vs 2010. An error 'VSTS for Database Professionals Sql Server Data-tier Application' package did n