#random question because i need help with my ap cs a assignment

1 messages · Page 1 of 1 (latest)

ocean yoke
#

my teacher wants us to remake this old game called kaboom, and I wanted to create an array of integers of the same y position that I could re use. However the y position is basically a velocity, so within a public int class it looks like this:

public int yBombPos () {
yBombPos = yBombPos + ySpeed;
return yBombPos;
}

am I able to set an integer in my array to a constantly changing value? I am just wondering because I have tried this a couple times and haven't gotten it to work so far, and want to make sure I'm not chasing something that just wouldn't work. and if it doesn't work, any tips for how I would do this? I am essentially dropping an infinite amount of objects within a second of each other and at different x positions, and I obviously can't have the same variable when the objects will all have multiple different y positions at the same time (each object has the same velocity). I thought an array would work best, but please let me know if there are any better solutions. thanks🙏

also btw here is what I currently have. the objects do go to the correct ypos when they're supposed to, but there is just no velocity

public Bomb () {
yBombPos = -200;
ySpeed = 0;
k=0;
lock = 0;
arr = new int [10000];

}
public int yBombPos () {
yBombPos = yBombPos + ySpeed;
return yBombPos;
}

public int [] arrInitialize () {
if (lock == 0) {
k=0;
arr[k]=yBombPos();
k++;
}
else {
k=0;
yBombPos = 75;
ySpeed = 2;
arr[k]=yBombPos();
k++;
}
return arr;
}

public static void set() {
lock = 1;
}
public static int arr(int x) {
return arr[x];
}

final edit here but if its possible, can I just create an array of an object? im just redrawing the same image over and over, and that would be waaaaay less complicated than like a million variables and other things

delicate cobaltBOT
#

<@&987246399047479336> please have a look, thanks.

candid tulip
#

do this

#
class MutableInt {
    int value;

    MutableInt(int value) {
        this.value = value;
    }
}
#
class MutableInt {
    int value;

    MutableInt(int value) {
        this.value = value;
    }
    
    @Override
    public String toString() {
        return String.valueOf(this.value);
    }
}
    
void main() {
    var ints = new MutableInt[100];
    for (int i = 0; i < ints.length; i++) {
        ints[i] = new MutableInt(0);
    }
    
    System.out.println(ints[5]);
    
    var i = ints[5];
    i.value = 9;
    
    System.out.println(ints[5]);
}
#

so you can use the MutableInt now to have the value in an array be accesible from other places

ocean yoke
#

thanks ill try this