Check this example. I have a button class with multiple variables. I have instantiated an button b1 from this class. The b1 object's parameters are described by the class Button. Can you think of any extra object parameters that could/should be included in the Button class?
Sorry if i wasn't being clear because i'm a beginner and i don't even know if what i'm even saying even making any sense i'm taking an intro to computer science high school class so i'm very new to all of the concepts.
I just realized that my question didn't make sense because I was trying to specify some values of variables for my new objects with a variable that I needed to state in the same line. If there is a way around this please let me know, thanks.
I was trying to use the size variable to specify the ships max and minimum x positions when really the starting and ending x was being stated in the same line as size.
I tried making the starting x and y intercepts random and with a minimum if more than half of the ship size and the max the width divided by half of the size also so they wouldn't get stuck on spawning but it didn't work.
Oh ok i get it now! Thanks again for making my code so much better.Have you seen my actual sketch lol. You could probably duplicate it in a minute. ^:)^
Answers
Check this example. I have a button class with multiple variables. I have instantiated an button b1 from this class. The b1 object's parameters are described by the class Button. Can you think of any extra object parameters that could/should be included in the Button class?
This next guide could provide you more details of the main concepts you want to master: https://processing.org/tutorials/objects/
Kf
Yea I didn't get it I still need help, can someone give a straight answer.
Not based on the information you've given us, no.
Post some code.
I'M TRYING TO PUT SIZE(THE CLASS VARIABLE) WHERE IT SAYS /HERE/ IN THE SETUP FUNCTION BUT I DON'T KNOW IF IT'S POSSIBLE.
Sorry if i wasn't being clear because i'm a beginner and i don't even know if what i'm even saying even making any sense i'm taking an intro to computer science high school class so i'm very new to all of the concepts.
It is not clear at all what you are asking. The member variable shipX belongs to your class spaceship. When you do this next:
You are assigning the value random(71, width-71) to shipX. The variable shipX cannot be freely access unless you do something like:
println("The value of shipX in spaceship1 is " + spaceship1 .getX);
You need to look into exactly what you want to do.
Kf
I just realized that my question didn't make sense because I was trying to specify some values of variables for my new objects with a variable that I needed to state in the same line. If there is a way around this please let me know, thanks.
I was trying to use the size variable to specify the ships max and minimum x positions when really the starting and ending x was being stated in the same line as size.
Here's the failure piece of code.
I tried making the starting x and y intercepts random and with a minimum if more than half of the ship size and the max the width divided by half of the size also so they wouldn't get stuck on spawning but it didn't work.
shipX and shipY = spaceship starting point.(random)
alienX and alienY = alien head starting point.(random)
size = size of spaceship(not random)
velX and velY = steps the ship takes.
is this solved or do you still have a question?
still a question
wanted to know if their was a way of using size to specify shipX one of the parameters even though size was being given a value on the same line.
you can make one var "size" in setup, say its value in setup and pass it to all 4 spaceships
when size is the same for all ships, you can just state it in the class, in line 48, then you don't pass it
so how would I still be able to change the size variable independently throughout the new spaceships?
i still need to be able to change size too
when you want different sizes for the ships, you should pass them separately
what you could do is that you calculate size1 in setup separately and then use it in multiple places in the line with "new"
(you can use random for size as well)
Thanks, that's a good solution i'll take it. ^:)^
Just a little repetitive but i bet there's no other way.
Thanks!
you can change size later with
or so
by the way:
you call drawSpaceship, xBounce, yBounce, drawFace for all
when you make a function script in the class, this can be shortened:
so in draw for each spaceship you put:
spaceship1.script();
so script basically means that you want to run every function in the class?
yeah, making your
draw()
much shorterthe name script can be changed of course
Oh ok i get it now! Thanks again for making my code so much better.Have you seen my actual sketch lol. You could probably duplicate it in a minute. ^:)^
I still don't even know how to use arrays :))
yeah, arrays would be cool
another remark: you can hit ctrl-t to auto-format your code (in processing)
Yea it looks a lot better now thanks!
no use to pass mouseX, mouseY in setup(), they are just 0 there anyway
say centerX = 0; in the constructor
ok got it thanks again =D>
sure!
well done!