Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shooting a Fireball  (Read 1707 times)
0 Members and 1 Guest are viewing this topic.
Offline DeafTV

Junior Newbie





« Posted 2012-03-20 20:14:39 »

Hey guys,
In my game I've been trying to shoot a fireball.  So far I've been successful in getting it to shoot from the character, but I've run into a little problem.  I have two variables for my player's location, playerX and playerY, and when you move these are overwritten based on which key you hit (Ex. right = playerX += 25).  The problem i'm having is that the fireball draws from the original X and Y, where the character is originally drawn in, not the new X and Y coordinates from when I move.  I would post the code but it's a bit messy and lengthy.  Any suggestions?  Huh

P.S. I'm pretty fluent in Java, but still a begginner in Game development so anything helps Smiley
Offline sproingie
« Reply #1 - Posted 2012-03-20 20:26:18 »

Why would you want the fireball to move from any position other than where it was originally shot from?  Is this a guided fireball?
Offline Rorkien
« Reply #2 - Posted 2012-03-20 21:09:48 »

You can create a Fireball class (or subclass, if you have any other projectiles), with its own X and Y positions, then use a list to manage them
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Geemili

Junior Member


Projects: 1


No Games Finished


« Reply #3 - Posted 2012-03-20 23:27:57 »

I think what he is saying is that the fireball is made where the players starting x and starting y is. I would have to see the code, but others might be able to help you.
Offline GabrielBailey74

JGO Knight


Medals: 8
Projects: 6


<3 Java


« Reply #4 - Posted 2012-03-20 23:30:13 »

I wouldn't mind seeing some code.
Hey guys,
In my game I've been trying to shoot a fireball. So far I've been successful in getting it to shoot from the character, but I've run into a little problem.  I have two variables for my player's location, playerX and playerY, and when you move, these are overwritten based on which key you hit (Ex. right = playerX += 25).  The problem i'm having is that the fireball draws from the original X and Y, where the character is originally drawn in, not the new X and Y coordinates from when I move.  I would post the code but it's a bit messy and lengthy.  Any suggestions?  Huh

So what your saying (Example):
Let's say you have a 40x40 sprite for your player.
Lets say you're shooting always to the right.
First of all, decrease that gargantious amount of movement from twenty five, to a way smaller number, otherwyse if you add collision for example, your player will just HOP through the X/Y you said he couldnt.
After you've fixed that huge hop of X/Y increment we can work:
Of course you're going to want to draw it off of the playerX + like 3 (So it appears infront of him), now for the playerY:
1  
2  
int startingBulletX = Player.getX() + 3;
int startingBulletY = Player.getY() + Player.getHeight() / 2 - Bullet.getHeight();


So it appears infront of the player, and DIRECTLY in the center of the player  - the bullets height, now I still have yet myself figure out how to change the bullets direction, based off of the players current direction of travel, i've gotten to the point where it's implemented, but if the player moves the bullets direction changes.

And so..
Hoping this helps in some way, hoping it isn't 100% irrelevant to what you need.
If it is just rephrase the question, and throw some code snippets out.

Offline DeafTV

Junior Newbie





« Reply #5 - Posted 2012-03-21 02:26:56 »

Thanks for the help guys!  I've gotten the fireball firing mostly correct now.  I have one bug though, I have to change directions and shoot before being able to shoot again.  If I can't fix this i'll post the code, but if anyone might have any ideas I'm all ears!  Thanks again for the help!  Smiley

Edit: All fixed and working great now Smiley Thanks!
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #6 - Posted 2012-03-23 03:29:06 »

Why is your name DeafTV? 
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (70 views)
2013-05-17 21:29:12

alaslipknot (80 views)
2013-05-16 21:24:48

gouessej (111 views)
2013-05-16 00:53:38

gouessej (106 views)
2013-05-16 00:17:58

theagentd (117 views)
2013-05-15 15:01:13

theagentd (106 views)
2013-05-15 15:00:54

StreetDoggy (150 views)
2013-05-14 15:56:26

kutucuk (174 views)
2013-05-12 17:10:36

kutucuk (171 views)
2013-05-12 15:36:09

UnluckyDevil (180 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.076 seconds with 20 queries.