Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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 2717 times)
0 Members and 1 Guest are viewing this topic.
Offline DeafTV

Innocent Bystander





« Posted 2012-03-20 19: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

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-03-20 19: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 20: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!
Legends of Yore - The Casual Retro Roguelike
Offline Geemili

Senior Duke


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #3 - Posted 2012-03-20 22: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
« Reply #4 - Posted 2012-03-20 22: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 gbeebe
« Reply #5 - Posted 2012-03-23 02:29:06 »

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

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 06:59:02

Norakomi (42 views)
2014-10-16 18:22:06

Norakomi (32 views)
2014-10-16 18:20:20

lcass (37 views)
2014-10-15 19:18:58

TehJavaDev (68 views)
2014-10-14 03:39:48

TehJavaDev (66 views)
2014-10-14 03:35:47

TehJavaDev (59 views)
2014-10-14 03:32:37

BurntPizza (73 views)
2014-10-12 02:24:42

BurntPizza (45 views)
2014-10-12 02:10:45

BurntPizza (85 views)
2014-10-12 01:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!