![]() |
Forum Index : Microcontroller and PC projects : CMM2: 64 Bouncing Rubber Duckies
Author | Message | ||||
jeff510 Newbie ![]() Joined: 19/07/2020 Location: United StatesPosts: 13 |
This is a silly little script I put together to bounce 64 rubber duckies on the screen. I'd appreciate feedback on the general approach - using a 2d array to store the sprite data. If there's a better way, I'd love to know. DUCKIES.zip |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
Cool, it's good to see that sort of example. I prefer to have the object's properties in separate arrays. e.g. instead of movers(mover,0) = rnd*SCREEN_RIGHT 'X POS movers(mover,1) = RND*SCREEN_BOTTOM 'Y POS movers(mover,2) = rnd*4-2 'X VEL you'd have x_pos(mover) = rnd*SCREEN_RIGHT 'X POS y_pos(mover) = RND*SCREEN_BOTTOM 'Y POS x_vel(mover) = rnd*4-2 'X VEL or xPos(mover) = rnd*SCREEN_RIGHT 'X POS yPos(mover) = RND*SCREEN_BOTTOM 'Y POS xVel(mover) = rnd*4-2 'X VEL I don't know if it's better but I find it easier to read. If you want, you could include "movers" in the array names, e.g. movers_x_pos(mover) = rnd*SCREEN_RIGHT 'X POS movers_y_pos(mover) = RND*SCREEN_BOTTOM 'Y POS or x_pos_movers(mover) = rnd*SCREEN_RIGHT 'X POS y_pos_movers(mover) = RND*SCREEN_BOTTOM 'Y POS update: I just noticed you can use periods in variable names. So you could use names like movers.xVel(mover) and movers.yPos(mover) This suggests they're part of the same "movers" structure, if you're used to some other languages. Edited 2020-07-21 17:05 by capsikin |
||||
jeff510 Newbie ![]() Joined: 19/07/2020 Location: United StatesPosts: 13 |
Perfect! That's much more readable. |
||||
mkopack73 Senior Member ![]() Joined: 03/07/2020 Location: United StatesPosts: 261 |
Ooh! Totally am going to look at this tonight. I was just starting to dig into sprites last night and could use some example code to look at. Thanks!! |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Them thars a whole lotta duckies! I like it. I would _not_ split the arrays into separately named ones. A few times now I started with separate arrays for each aspect of a collection of items to be animated and found processing easier once they were combined. If you are concerned with readability, assign the array index numbers to named constants: CONST X_POS = 0 CONST Y_POS = 1 CONST X_VEL = 2 CONST Y_VEL = 3 CONST RED = 4 CONST BLUE = 5 CONST GREEN = 6 Then a statement like SPRITE next mover+1,movers(mover,X_POS ), movers(mover,Y_POS ) is easy to understand.Because sprites start with number 1, I prefer not to use element 0 for the first sprite. Element 0 could instead hold some globally relevant data - maybe the next sprite to update or whatever. Then the slightly confusing "SPRITE next mover+1, ..." gets simplified to "SPRITE next mover, ..." Also, you can clean up the flickering by using pages. For example, add the line "page write 1 : cls" right after selecting the mode. The, just before the PAUSE command at the end, add the line "page copy 1,0,B" This combination changes all your drawing to happen on page 1 (which is invisible) and then copies the entire thing to page 0 (which _is_ visible) during the next blanking interval. I'd love to see a version of bouncing duckies with collision detection, so they bounce off each other. Great work! Visit Vegipete's *Mite Library for cool programs. |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
There is only one Rubber Duck! Looking forward to checking this out after finally having got my CMM2! Edited 2020-07-22 05:21 by Poppy ![]() ![]() | ||||
Womble![]() Senior Member ![]() Joined: 09/07/2020 Location: United KingdomPosts: 267 |
Ten Four Poppy |
||||
jeff510 Newbie ![]() Joined: 19/07/2020 Location: United StatesPosts: 13 |
Alright, I've used pages to clean up the flickering, and constants for the indices. It looks much more clean and readable. vegipete said: I did that too. It's called DUCKIES_GROUP_COLLIDE.BAS I tried to figure out a way to get the duckies to orient to their x velocity, but they leave artifacts when they flip, even with a CLS. DUCKIES.zip Edited 2020-07-22 17:11 by jeff510 |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Ten Two - Ten Four Womble! ![]() ![]() | ||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
vegipete said: I did that too. It's called DUCKIES_GROUP_COLLIDE.BAS I tried to figure out a way to get the duckies to orient to their x velocity, but they leave artifacts when they flip, even with a CLS. DUCKIES.zip Do you have the version that leaves artifacts? It would be good to figure out how to change sprite graphics, it's pretty common in games. (update - if you don't have it I can figure out how to put in the SPRITE SWAP command, which then gets to the harder task of figuring out how to prevent artifacts - they are probably from changing sprites that are underneath other sprites) (update 2 - I didn't understand SPRITE SWAP as well as I thought) Edited 2020-08-15 10:04 by capsikin |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |