Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : sprite collision simplify please
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
|
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9084 |
NO |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 479 |
In my game Knightmare, I followed the instructions from the CMM2 Basic manual, and it worked very well. This is my implementation for my game: https://github.com/leonicolas/knightmare-cmm2/blob/main/collision.inc |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
sorry, I'm looking at appendix sprite collision. I got 16 sprites, each can be sprite 1 or sprite 2, for animation and I can do 4 tests to see if any of the 16 sprites overlap the cannon or hit by missile. I just thought the sprite collision testing 16 sprites would be faster. probably is. more study needed. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4026 |
Note that (I believe) one of the (several?) wrinkles with the SPRITE function is that if you use SPRITE(C, #1) to get the number of collisions for sprite #1 and then iterate through and handle them using SPRITE(C, #1, m) then things can get "fun" if in handling the collisions you actually change the number of collisions, e.g. by destroying/hiding a sprite representing a bullet that has just collided ... you can end up missing a collision or trying to handle an invalid sprite #0. I believe this issue hits Knightmare currently requiring an ON ERROR to avoid the bad result. Best wishes, Tom Edited 2024-11-07 03:16 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
it's all for n=1 to sprites active test each of 3 missiles collided with any sprite, explode ,missile inactive ,sprite inactive. if sprite1x+sprite1_width < sprite2x then if sprite1x>sprite2x+sprite2_width then if sprite1y+sprite1_height < sprite2y then if sprite1y>sprite2y+sprite2_height then end if else collided |
||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 479 |
Yes, you are right. I'm using on error skip because is easier and faster to avoid the edge cases than creating a more complex logic to skip the invalid cases. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
converting gcbasic to mmbasic https://www.youtube.com/watch?v=9pys3Y8_bns |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6761 |
But *why* Stan? Just use the one that's best for the job. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
gcbasic never supported ili9341 and the arduino demo is a long story to implement but the logic is valid in mmbasic and uses frame f so it's just an exercise to learn mmbasic. world of difference between gcb and mmb |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4213 |
Stan, In "Rocks" I simply check sprite coordinates in MMBasic. When there are not many, it s doable and mantain a decent number fo frames per second The same is also used in PETSCII robots (there some sprites are in a different framebuffer). When there are many sprites, and checking intersprite collisions, then it slows down the game. But you can (as in PETSCII) only check Y coordinate, and when that is close, evaluate X coordinate. Volhout Edited 2024-11-07 18:32 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
Rocks is interesting code. I thought again about "Missile Command" now mouse demo read x,y worked and guess scroll wheel click button is detected so want to try coding and rocks missile routines could be useful as can't find my line x,y,x2,y2 pixel at a time code, Bresenham's line algorithm the original game video https://www.google.com/search?client=opera&q=missile+command+video+game&sourceid=opera&ie=UTF-8&oe=UTF-8#fpstate=ive&vld=cid:3f819b2c,vid:tz4YCQaOxOI,st:0 Edited 2024-11-08 08:35 by stanleyella |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
found this plotLine(x0, y0, x1, y1) if abs(y1 - y0) < abs(x1 - x0) if x0 > x1 plotLineLow(x1, y1, x0, y0) else plotLineLow(x0, y0, x1, y1) end if else if y0 > y1 plotLineHigh(x1, y1, x0, y0) else plotLineHigh(x0, y0, x1, y1) end if end if |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
this is the line command using plot. now mmbasic I'll get it to do 1 pixel each call. I'll edit the for nexts and use the values , hope Bresenham's line algorithm, it's fast on 2350 hdmi ,just academic , line is obviously faster but interesting it works so fast. hdmi usb, faster vga higher cpuspeed. cls x0=10:y0=10:x1=100:y1=150 plotLine(x0, y0, x1, y1) x0=120:y0=120:x1=160:y1=60 plotLine(x0, y0, x1, y1) x0=150:y0=70:x1=50:y1=100 plotLine(x0, y0, x1, y1) x0=40:y0=120:x1=170:y1=6 plotLine(x0, y0, x1, y1) end sub plotLine(x0, y0, x1, y1) if abs(y1 - y0) < abs(x1 - x0) then if x0 > x1 then plotLineLow(x1, y1, x0, y0) else plotLineLow(x0, y0, x1, y1) end if else if y0 > y1 then plotLineHigh(x1, y1, x0, y0) else plotLineHigh(x0, y0, x1, y1) end if end if end sub ' sub plotLineHigh(x0, y0, x1, y1) dx = x1 - x0 dy = y1 - y0 xi = 1 if dx < 0 then xi = -1 dx = -dx end if D = (2 * dx) - dy x = x0 for y = y0 to y1 pixel x, y if D > 0 then x = x + xi D = D + (2 * (dx - dy)) else D = D + 2*dx end if next end sub ' sub plotLineLow(x0, y0, x1, y1) dx = x1 - x0 dy = y1 - y0 yi = 1 if dy < 0 then yi = -1 dy = -dy end if D = (2 * dy) - dx y = y0 for x = x0 to x1 pixel x, y if D > 0 then y = y + yi D = D + (2 * (dy - dx)) else D = D + 2*dy end if next end sub Edited 2024-11-08 11:21 by stanleyella |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2109 |
this was when I used picaxe basic and I got oled 1306 to work and implement line cos it wasn't supported. had to work out the 1k buffer. 7 years ago. I moved to gcbasic, then mmbasic, where you don't have to do graphics, they're all sorted https://www.youtube.com/watch?v=kL3c1wry9ok picaxe was ok but slow and variables??? gcbasic pissed all over it but 8 bit, best was logic green technology 328 which ran at 32mhz, twice as fast as arduino 328 but mmbasic pissed all over gcbasic. I'm not very loyal am I? Edited 2024-11-08 11:59 by stanleyella |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
With "Gems N Rocks", for example, I made it so that the sprites were permanently queried and moved from bottom to top... always several rows per pass. The position of the stones and other objects on the playing field were managed in a 2-dimensional array. All movements and collision queries only took place in the array. On the screen, only the contents of the array were displayed but no collision detection were made there.. the advantage is that objects are also moved that are outside the screen and are therefore not currently displayed Edited 2024-11-08 22:15 by Martin H. 'no comment |
||||
Print this page |