Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:54 24 Nov 2024 Privacy Policy
Jump to

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 Kingdom
Posts: 2112
Posted: 09:05pm 05 Nov 2024
Copy link to clipboard 
Print this post

 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9101
Posted: 10:30pm 05 Nov 2024
Copy link to clipboard 
Print this post

NO
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 04:48pm 06 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 04:49pm 06 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4036
Posted: 05:01pm 06 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 05:32pm 06 Nov 2024
Copy link to clipboard 
Print this post

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: Canada
Posts: 479
Posted: 06:05pm 06 Nov 2024
Copy link to clipboard 
Print this post

  thwill said  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


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 Kingdom
Posts: 2112
Posted: 10:24pm 06 Nov 2024
Copy link to clipboard 
Print this post

converting gcbasic to mmbasic
https://www.youtube.com/watch?v=9pys3Y8_bns
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6772
Posted: 10:50pm 06 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 11:57pm 06 Nov 2024
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 4222
Posted: 08:31am 07 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 10:14pm 07 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 10:44pm 07 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 12:45am 08 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2112
Posted: 01:34am 08 Nov 2024
Copy link to clipboard 
Print this post

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: Germany
Posts: 1113
Posted: 08:18am 08 Nov 2024
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024