Sprite-Background collision detection

  Рет қаралды 1,399

agpxnet

agpxnet

5 ай бұрын

A video that explains how to determine the collision between sprites and the background (English version). #commodore64 #sprites #background #collision
If you liked the video and want to see more, please "like", share and subscribe! Thank you!
Link to the source code of the formula implementation: drive.google.com/file/d/1kLrO...
UPDATE:
A second version more memory friendly (10 times less, spending 12 more clock cycles):
drive.google.com/file/d/1ld0J...
Link to the demo: drive.google.com/file/d/1r4s0...
Italian version: • Rilevamento collisioni...
Voices generated via TTS from the site: ttsfree.com/text-to-speech

Пікірлер: 16
@agpxnet
@agpxnet 5 ай бұрын
Update: in the description you can find a second version of the formula implementation, which requires only 50 bytes instead of 512, spending 12 more clock cycles. It depends on the circumstances: whether you need maximum performance or to save memory. And speaking of performance, you can also avoid subtracting 24 and 50 in the formula and instead do it directly in the coordinates of the contact points.
@gamesgonenuts
@gamesgonenuts 5 ай бұрын
cool to see how this is done smashed the like
@agpxnet
@agpxnet 5 ай бұрын
Happy to hear that. If you liked my video, please share it so I can make more. Thanks in advance.
@jadermonari2272
@jadermonari2272 5 ай бұрын
Grazie !!! Molto utile!!!
@mityaboy4639
@mityaboy4639 5 ай бұрын
my only comment on this would be that for such a simple platformer (and such limited memory and cpu power) one contact(check) point would be perfectly enough. To make the game work smoother, the collision reference point needs to be reallocated when the character turns around (so that it always looks like its under the feet in front) In an environment where the movement is more refined, and needs more precision i tend to use 3 points (left, center, right) and depending on the game mechanics, check for the relevant ones to determine whether the character needs to fall, continue to fall or stop. but thats also because i am too lazy to recalculate the positions :D with wall (door) detection i tend to use a more or less acceptable collision box - but here i think the whole sprite would only need maybe 4 points to calculate front, back, feet and head bumps and then act accordingly. Also also: i don't think we need to check constant collisions while we are walking / running - what we need is check into the next move to determine if our next step would land on the filed or not - if it does, then do nothing - if it will fail then trigger a fall sequence. jump also only need to test for collision under the feet while falling (which makes the logic the same thus the code smaller) (falling and finishing off a jump is the same process) And lastly while on the commodore you have to be careful with memory, normally we shouldn't track the video memory - but rather keep an internal status of where a platform is on the screen. (this is a comment for whoever decides to do this on any more modern hardware) for example if you try to do this on a canvas in Javascript (its a good platform to practice these concepts) - reading back from the canvas comes with huge cost on performace - it makes more sense to not to :) On a C64 it has some clear advantage - as the system memory and screen memory is the same from a technical point of view, just on a different address - but all handled by the CPU therefore no performance loss there anyway, good material :)
@agpxnet
@agpxnet 5 ай бұрын
The contact points with the floor shown are purely indicative. Of course, in the demo I don't use two points for a single foot, but for a larger segment. In my experience, one point of contact is not enough. Especially, if the player lands very close to the end of a platform. In any case, I calibrated the test points empirically. In the demo I use 3 test points: 1 front and 2 for the feet (which are flipped together with the player). I don't need the rear, in my case the front is enough. A point for the head could be added, but currently the demo does not take this into account. I check the 3 points for each frame and if there is nothing under my feet, I activate the fall procedure. When I jump, I also test the front point because I might hit the key or another object and I prefer it to be caught by the player. However, how many and which points to use is a choice, it depends on what you want to achieve. As for accessing video memory, obviously this tutorial is designed for Commodore machines, I would never dream of reading the video memory of a GPU, it's a huge bottleneck. Thanks for the comment.
@Icelink256
@Icelink256 5 ай бұрын
@@agpxnet In my experience, one point of collision really only works, when slopes are involved...
@agpxnet
@agpxnet 5 ай бұрын
​@@Icelink256Depends on the scene. In that showed in the demo, after some tests, I see that 2 points work better. In any case slopes require a special treatment. I will try to investigate it, thanks for the suggestion.
@ArneChristianRosenfeldt
@ArneChristianRosenfeldt 5 ай бұрын
Why do we need to supply contact points? I thought that they are the result of a collision, and used to confine to sliding and rotation. So your sprite moves 2px per frame max? Then do two game steps. So you detect any stick after one px and just go back a game step .. even at angles. Fast games like Sonic the Hedgehog are more difficult. Good explanation while sprite tile collision doesn’t work. If at least this was limited to mines and spikes .. like char >= $B0 or so Do we need a real z coordinate to jump onto platforms from the front? SuperMario bounces his head.
@agpxnet
@agpxnet 5 ай бұрын
Perhaps the term contact points is not very suitable, I should have called them test points, but the substance does not change (contact points in the video are the points where, we suppose, the sprite can potentially have contact with a character). The video simply shows a way to determine what characters a sprite is colliding with, or to be more precise, what characters we have in the test points. We are talking about discrete (not continuous) collisions: the continuous, on slow processors like the 6502, are difficult to implement in real time. I don't understand what you mean when you say the collision system doesn't work. In the demo the speed (i.e. the number of pixels) with which the player moves is almost constant, but it's a choice, not a limitation, it could be variable. Up to a certain step size (but this depends on the background) the system works perfectly (it depends also on how you implement the response to the collision, which we will see in the next video), beyond some value there may be the "tunnel effect", which can cause the sprite to skip a wall (however there are some solutions to alleviate this problem).
@ArneChristianRosenfeldt
@ArneChristianRosenfeldt 5 ай бұрын
@@agpxnet I mean, a step size over 1px needs vectors. DIV and MUL. 6502 has super fast bit test. Maniac Miner had the walking animation aligned to bit shift. Otherwise shift takes two branches. We could call the points the Minkowski sum of the sprite and the 8x8 block. I may need to rewatch what you said about other background tiles. Now I come back to open borders ( top and bottom ). Set the whole palette to the background color. Clear idle byte. Copy the surrounding background of the player into one or two sprites. Good thing is that we don’t need the zero page for this ( unlike the CPU method ). Then test 6 position/animation frames before the screen starts: “bounce back” before the racing electron beams sees us in the wall. With 4 sprites for background incremental all directions update is possible. Looks like 2*21 sprites can be stacked in the top. 8 scanlines ( none of which is bad ) should be enough to bounce. Put the background sprite in slot 0..3 so that they don’t steal cycles from the CPU. I would not waste memory on look up for your formula. SEC SBC 50 SHR SHR SHR is like 10 cycles? The sprite method allows to 2x zoom the monochrome collision map to match multicolor resolution. Maybe your game allows to hide an area in the background. ( sky , earth , status display) and then try collisions there. Can use chars , but it is all hires then.
@agpxnet
@agpxnet 5 ай бұрын
@@ArneChristianRosenfeldt Subtracting 50 and dividing by 8 is not enough, we also have a product (* 40), for which I would use a look-up table. Anyway, the implementation shown tries to be as efficient as possible, but the tradeoff between speed and memory depends on how many resources are left. In any case, by spending 12 more clock cycles I can reduce the table from 512 bytes to 50 bytes which I think is acceptable in the end. I've added another implementation in the comment that uses this more memory efficient table. Thanks for the comment.
@ArneChristianRosenfeldt
@ArneChristianRosenfeldt 5 ай бұрын
As efficient as possible. Ah okay. I think this is why I cannot appreciate Demo coding. I strive a middle ground in my first pass ( so: only minimal slow BASIC and almost no look-up. Then profile. For C64 games I have seen raster bars in the border used for profiling. I read that the C64 is too slow for super Mario. codingSecrets showed how coders struggled with the CPU even on the NES. If the hardware manufactures just would have given us more power from the start. Consoles are so low on memory, so there is even more pressure to solve everything in the CPU. You may guess that I like the genesis. Z80 is probably the lesser evil than all those SID registers. So times 40 is like you don't divide by 8, but only AND the top bits. Then STA, SHL, SHL, ADC. (Carry should be clear because we don't expect a carry in SHL ). @@agpxnet
@agpxnet
@agpxnet 5 ай бұрын
​@@ArneChristianRosenfeldt Unfortunately the raster beam runs very fast (or the CPU is too slow...), especially in NTSC, so personally I prefer to give a little more weight to computational efficiency. Anyway, I think you need a little more instructions because the product result is 16 bits and therefore you have to handle the carry. An easy way to increase speed is to completely eliminate the subtraction of 24s and 50s and do it directly at the contact points.
Rilevamento collisioni Sprite-Sprite
6:42
agpxnet
Рет қаралды 300
C64 Sprite Multiplexing (EN)
12:34
agpxnet
Рет қаралды 17 М.
Happy 4th of July 😂
00:12
Pink Shirt Girl
Рет қаралды 44 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 13 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
8-way Smooth Scrolling
9:58
agpxnet
Рет қаралды 2,6 М.
How A Steam Bug Deleted Someone’s Entire PC
11:49
Kevin Fang
Рет қаралды 919 М.
C64 - Hiding machine language in a REM statement
10:07
Retro Old Guy
Рет қаралды 13 М.
Dithering on the Sega Genesis with Composite Video
10:30
Displaced Gamers
Рет қаралды 266 М.
How to Create Your Own C64 Platform Game: "The Runner"
9:40
Reverse Engineering Game Code from the Neutral Zone
40:59
Retro Game Mechanics Explained
Рет қаралды 552 М.
ZX Spectrum Next: a quick look at the board in action
8:17
Henrique Olifiers
Рет қаралды 34 М.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,7 МЛН
PART 52 || DIY Wireless Switch forElectronic Lights - Easy Guide!
1:01
HUBAB__OFFICIAL
Рет қаралды 35 МЛН
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 4,1 МЛН
Blue Mobile 📲 Best For Long Audio Call 📞 💙
0:41
Tech Official
Рет қаралды 1 МЛН