| ~Hakurei Shrine~ > Rika and Nitori's Garage Experiments |
| A solution to some Danmakufu Problems, only if it'd... |
| << < (2/2) |
| Nuclear Cheese:
--- Quote from: Aphid on June 11, 2009, 02:39:45 PM ---Ah, yes, of course, you can put statements such as t = 5t into a computer, it'll just increase the thing with a factor five. Anyway, the point of the code was to create a bullet that could dynamically depend on time. When using the standard bullet functions CreateShot01, etc. you assign angle, velocity, accelleration, etc. once. You can't change them after the bullet is fired. You can have a set of speeds/angles and change it a couple times, it just doesn't work terribly well for something complicated. But you can of course assign angle, etc. every frame with an object bullet. The thing about concatenation helps though... could save a line from the array version. And unfortunately, using t++ alone is not enough... it's in the @mainloop, of course. It's just that, when you enter something with t in it into a bullet's velocity, etc. that it will make this thing a static value. For example, say that I entered some formula of t, f(t) into my code as a bullet's velocity somewhere, and that f(0) = 4, f(1) = 6. Now when I make a bullet at time t=0, it will get a velocity of 4. And it stays that way. At frame 1, the bullet will not change its velocity to f(1). That's why I need the bullet to change velocity at every frame (both x and y, hence vx, vy). And that can be done by either: --- End quote --- You are right. The function does not carry over. Once you've assigned the value, it is fixed for that shot, if you're just using basic CreateShot01(); other forms can give some dynamics. However, you need to reassign the shot's speed each frame if you want to do something like what you describe - object shots are probably the ideal candidate for this, as I mention below. --- Quote from: Aphid on June 11, 2009, 02:39:45 PM ---a) Loop a SetShotDataA a couple hundred times (equal to the amount of time the bullet is on screen) and put in the command; like --- Code: ---CreateShotA(<ID>, GetX, GetY, 0); ascent(q in 0..N){ SetShotDataA_XY(<ID>, q, vx(q+t), vy(q+t), d/dt * vx(q+t), d/dt * vy(q+t), vx(q+t)/|vx(q+t)| * 20, vy(q+t)/|vy(q+t)| * 20, <shot type>);} SetShotKillTime(<ID>, N); --- End code --- N equals the amount of frames the bullet need be on the screen. Replace 't' with 'q + t' in the formula and it should work. However, it isn't the most effective method of doing this, as you can see we need to call this thing a bunch of times. Also interesting, you could reduce computing time at the cost of accuracy by having q ascend in steps of 2, 3, or more. You just get more jagged movement. It's not possible with some functions though. Example using this version, a large round bullet going in a lissajous pattern adjusted a bit downwards, something rather hard to accomplish with just the standard functions. Notice the pi over 180-term being there to adjust for the fact that the sines in danmakufu use degrees instead of radians; --- Code: ---CreateShotA(1, GetCenterX, GetCenterY, 0); ascent(q in 0..480){ SetShotDataA_XY(1, q, sin(2*(t+q)), cos(t+q) + 0.4, 2 / 180 * 3.1415 * cos(2*(t+q)), -1 / 180 * 3.1415 * sin(t + q), (sin(2*(t+q)))/|(sin(2*(t+q)))| * 20, (cos(t+q))/|(cos(t+q))| * 20, RED03);} SetShotKillTime(1, 480); --- End code --- The main problem is the 480 loops required for just a single bullet, and I cannot have it interact either. --- End quote --- The much simpler way to do this is simply to track each bullet as an Object shot (in an array, or a set of arrays if necessary), and simply update the information each frame while they exist. While not exactly the same thing, the same basic structure is used in my spellcard Random Sign 「Entropy」 found in my thread. Basically, you track each object shot as it lives, and update its information as necessary. The difference would be that, whereas in my example the code randomly decides to spontaneously change all of a shot's information with no real pattern, what you're aiming to achieve would have the shot information being updated every frame based on your formulae. --- Quote from: Aphid on June 11, 2009, 02:39:45 PM ---Ah yes, that line should be reversed with the one above it. That'll check for the object deletion for each particular object. It includes the while-loop so each object will be treated separately as it's supposed to. --- End quote --- What I was pointing out is that, in your script with the array, obj is an array. If you try to say Obj_BeDeleted(obj), you'll get an error, because of the type mismatch. What you need to do is add a counter that counts through the list of objects in the array, and checks each: --- Code: ---let i = 0; while (i < length(obj)) { if (Obj_BeDeleted(obj[i])) // check if element number i has been deleted { // stuff when it is deleted } else { // stuff when it is not deleted } i++; // Increment the loop counter. Forget this and the code gets stuck in an infinite loop :V }; --- End code --- Since obj is an array of object IDs, we need to pull each individual object ID out of the array and check it individually. I use the variable i to index the array; the first index is always zero and the last index is always one lower than the total number of items in the array. |
| Navigation |
| Message Index |
| Previous page |