d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help In Java > Processing
Add Reply New Topic New Poll
Member
Posts: 2,732
Joined: Apr 26 2012
Gold: 2,378.00
Nov 28 2015 08:59pm
I have to do an assignment in Processing using mainly classes and arrays. To be exact, I have to create a simple game.
I came up with a space invaders type of a game and I have already objects for the 'enemies' and the player and the missiles, but I don't know how to create a new instance of an object each time an argument is met and then when another argument is meant, I'd like that object instance to be destroyed.

Anyone knows how to go about this?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 28 2015 11:10pm
i assume you have some kind of list that keeps track of active ones so that it can be drawn. to create a new one, use the 'new' keyword to create the object, then add to the list. to 'destroy' your object, simply remove it from the list.
https://processing.org/tutorials/objects/
Member
Posts: 2,732
Joined: Apr 26 2012
Gold: 2,378.00
Nov 29 2015 09:01am
Quote (carteblanche @ Nov 29 2015 06:10am)
i assume you have some kind of list that keeps track of active ones so that it can be drawn. to create a new one, use the 'new' keyword to create the object, then add to the list. to 'destroy' your object, simply remove it from the list.
https://processing.org/tutorials/objects/


What do you mean by the list?



here's what I have currently ->


Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 29 2015 11:12am
Quote (CreativeCode @ Nov 29 2015 10:01am)
What do you mean by the list?



here's what I have currently ->
http://i63.tinypic.com/142u13o.png


have you not gone over data structures yet?


Like, arrays for example?

An array can be thought of as a list
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 29 2015 12:04pm
Quote (CreativeCode @ Nov 29 2015 10:01am)
What do you mean by the list?



here's what I have currently ->
http://i63.tinypic.com/142u13o.png


ok, so you already know how to create new players and missiles since i see that in your setup. your real question is "how can i use a collection to maintain more than one missile?" and the answer is to use an arraylist:

https://processing.org/reference/ArrayList.html

create an array list, and use a loop to create however many missiles you want and add them to the arraylist. in your draw method, you loop through your arraylist and draw everything in it
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll