We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, hope your well.
Im a beginner to processing and I need to create bullets for a space game using classes. How would I go about doing this?
ArrayList bullets;
void setup() {
}
void draw() {
bullets = new ArrayList();
}
class Bullet() {
}
Thanks
Answers
This is a pretty broad question. What have you tried? What exactly are you confused about?
I have an object oriented tutorial in Processing here: http://staticvoidgames.com/tutorials/objects/index.jsp
.
Did you take a look at the tutorial I posted? It shows you exactly how to create an array of Objects at a point. What specifically are you confused about?
Yeah is very helpful, trying to understand how I can create bullets instead of a ball using your example.
The wiki below is a nice tutorial as well:
http://wiki.processing.org/w/From_several_arrays_to_classes
And a Bullet class example:
http://studio.processingtogether.com/sp/pad/export/ro.91kLmk61vAOZp/latest
Would you give me a short example on how to create a bullet class?
That Bullet class is very complex, b/c it's meant to shoot in any direction. Hence it uses trigonometry w/ PVector.
Now, how many directions your Ship needs to shoot to? :-/
Take notice that a Bullet's initial coordinates are the same as the sprite which fired it! >-)
Well the idea is to make it shoot in all directions. Will it best to show you my code or send it to? sorry to bother you
If it's all directions, that's what the online example is about. Dunno how to make 1 otherwise! :-&
You should try something out, and post it here as an SSCCE, and we'll be glad to help you refine your approach. Especially if this is homework (but even if it's not homework), it's really important for you to understand the concepts involved, not just the syntax.
Hey, I managed to get my bullets working but I need it to come out from my ship Image. Instead of MouseX, MouseY.
void keyPressed() {
I have tried this:
//But I get an error "cannot be resolved or is not a field"
Like I said, you need to take a step back and really understand what you're doing.
Is myShip an Object of some kind? Does that Object contain a ship variable? Is the ship variable itself a variable? Does it contain both an x and a Y variable (notice the mixed case on those)?
I got it working, thanks for your help!
That doesn't really answer the questions. Does whatever Object myShip is contain a ship variable? Is that variable itself an Object? Does that object contain an x and a Y variable?
Object oriented programming can be confusing, which is why I think you should take a step back and try to answer these questions instead of just trying different syntax and hoping for the best.
this is the idea
hit space or mouse to fire
thread closed, cont'd elsewhere.
http://forum.processing.org/two/discussion/3673/how-to-rotate-my-ship-bullets