

XNA pixel perfect collision detection with transforms ported to Javascript : gam...
source link: https://www.reddit.com/r/gamedev/comments/7l3e5s/xna_pixel_perfect_collision_detection_with/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

XNA pixel perfect collision detection with transforms ported to Javascript
XNA pixel perfect collision detection with transforms ported to Javascript
I started developing SpaceBallz back in DirectX 9.0 days with C++ using a basic class inheritance design. While using class inheritance during development it eventually became harder to add new features or make changes.
Next I ported SpaceBallz to C# XNA while learning Entity Component Systems (ECS) and using TransformedCollision_4_0.zip from XNA samples for pixel perfect collision detection. This worked well but I had issues developing the desktop installer with InstallShield LE and WIX trying to get a clean solution for installing the pre-requisites, namely XNA Game Studio, and the .NET Framework Redistributable.
At this point I realized a trend where people preferred not to run desktop installers for simple games. So then I started looking into porting SpaceBallz to the web using HTM5 canvas element and Javascript. With component based game objects and a simple message system, it is so much easier to add and modify features. I’m also planning to use this framework for my next two upcoming games.
Here is the first release. Enjoy!
Play the game here www.cosmicwebgames.comSource code here www.github.com/rscott442/spaceballzGNU General Public License v3.0
I don't remember Space donuts, but I started with Asteroids gameplay and made a much more playable and smoother game mechanic.
The source code is useful for anyone learning Javascript and needs examples for ECS, simple physics, particle system, and simple messaging system.
I’ve been exploring using OpenAI’s chatbot ChatGPT as a gamedev tool a little bit and have come up with some mixed results. Sometimes it is very impressive but other times it only appears impressive but is actually incorrect. Most of the time for me it’s somewhere in the middle area of “That could sometimes be useful I guess.”
The first thing I tried was asking it to optimize a bit of code that was a small, simple function that I just thought looked ugly when I went quickly looking for an example to give ChatGPT. It’s a function that takes a 2D point and quad parameters, and returns the minimum distance from the point to a point on the edge of the quad, or 0 if the point is already inside:
https://i.imgur.com/aGJi8ni.png
I was initially extremely impressed! This code looks nicer, and it says it’s more optimized. I was particularly impressed with how it has no definition for my custom TileNavMeshQuad class, nor was it explicitly told that the pos property of the quad corresponds to the top-left corner of the quad, but from my existing code it correctly guessed how everything is structured.
But wait – this is incorrect; this ignores diagonal distances to a corner of the quad for when the point is both beside and above/below the object. Let’s ask it to fix that. In thinking of how to word my request of what I wanted, I decided to just be pretty vague to see it if understood what I meant. Also as an aside I felt kind of weird being polite to a robot? Like I intentionally didn’t want to personify it. So I dropped the please from my request.
https://i.imgur.com/6iGah2m.png
Awesome! It understood what I meant, and now includes diagonals. I was honestly kind of caught up in excitement at this point, thinking I was getting some nicer, optimized code. But I notice one more error, it doesn’t return 0 if the point is in the quad like my original function did so I tell it that and it fixes that problem:
https://i.imgur.com/GlUZq1L.png
Ok perfect! ChatGPT has rewritten my code to do the same thing but faster. So I go to test just how much faster…
And I find that it’s in fact about 5x SLOWER than my original code. So I tell it:
https://i.imgur.com/3xCy3G0.png
Cool, it adjusts the order of some checks to improve the performance. I do another test and this is faster, but still 1.5x slower than my original code. I didn’t want to just say “faster” again, maybe I should say “as fast as possible?”
https://i.imgur.com/abfERqK.png
Here ChatGPT stored some calculations in some variables once so that they don’t need to be calculated “every time,” but in this case they’re still only used once. So this basically does nothing. I tell it:
https://i.imgur.com/28aQpyT.png
Some very general advice that doesn’t help here. It’s at this point I’m realizing none of this really helped me at all. I took another look at my original code and noticed it was in fact already very optimized. I know ChatGPT can optimize ugly code from seeing some examples from other people, but it doesn’t actually test out code. It seems to just confidently provide some code and tells you it’s optimized when the ideal response to my original prompt should be “I don’t know how to make that faster.”
I switch up tasks and think more about things that would actually help me in my current project. Maybe some brainstorming?
https://i.imgur.com/m83FldK.png
This was pretty cool. I had already thought of pretty much all of these things, except for pools of water and cobwebs, which are good ideas I may now consider. The drawback is it’s all fairly generic ideas, so you’ll still need some individual creativity if you want your game to stand out more, but perhaps this could be a handy time-saver for some tasks? The alternative is either googling or browsing various sites with collection of concept art or photos for inspiration.
I try another example:
https://i.imgur.com/IlR1fTb.png
A pretty extensive list of monsters, but they are of course fairly generic. It does provide some nice little explanations of why they are relevant to a desert.
I decide to do a little test. I decide on a new area for monsters, and first give myself one minute to brainstorm on my own to which compare to ChatGPT’s. I decide as an example a swamp environment, and in one minute came up with:
toads/frogs
witches
mosquitoes
giant bugs
giant birds
snakes
leaping fish
spiders
mud golems
I then ask ChatGPT to do the same:
https://i.imgur.com/ZOU56ld.png
Not bad. There is a bit of overlap in our ideas, but ideas like slimes, goblins/lizardfolk, the undeads that were trapped, and large predators are all pretty different than what I came up with. Nothing amazing, but for an instant response from just typing a response, it could be a nice springboard for ideas on a new area.
I feel like I’m not using ChatGPT to it’s full potential, which includes longer conversations, so I provide a more unique task and ask it to elaborate more on the swamp monsters:
https://i.imgur.com/Ufn8Lie.png
Some possible fun ideas to consider! I like how it tries to explain the connection between the monsters and ruins, providing reasons for their existence and behaviors. This is something that my quick barebones list was lacking.
I’m still searching for ways I would actually use this and so far the brainstorming ideas seems to be the most helpful. I think tasks like that may work best since they are very open-ended and there is no one correct answer, unlike most coding problems, where ChatGPT may confidently give you an incorrect answer.
It is pretty helpful at explaining code, however, as well as spotting errors. These could be a nice use case. In one test I took this random reddit post of someone asking for help with a complex regex expression, copy and pasted their post verbatim to ChatGPT, and was given the same correct solution as the top commenter of that thread, which was impressive. ChatGPT could possibly drastically reduce the number of reddit and stackoverflow threads of “why isn’t this code working?”
There are a handful of cons as well, however. In some other attempts I asked for some help with a general issue I faced with some collisions in Unity, asking how I could achieve something, and ChatGPT explained a non existent feature of “conditional fields” for physics layers.
Sometimes people talk about ChatGPT as if someone without programming knowledge can use it to make a game which is far from the truth. You still need knowledge to test it’s answers, and tell it when it got things wrong. For me I was originally most interested in using it for coding tasks but that seems unlikely now, aside from very occasionally tasks.
It is also still limited in scope to what you give it. I keep an (embarrassingly long) todo list of tasks I need to do to fix things in my game, and went through it trying to find tasks that ChatGPT could help with and didn’t really find anything. I tried a few but didn’t have any luck getting something useful. The main problem is that for example my todo task of “fix game pausing issues during cutscenes” involves my cutscene system, entity movements, and other map updates spread through hundreds of lines of code across dozens of different classes and subclasses that’s needed just to understand the system enough to fix the problem. I’m sure it won’t be long until a bot can be given access to your entire project for this however.
ChatGPT is so open-ended on what it’s capable of that it’s kind of difficult to think of new use-cases, so I’m sure new ones will pop up as people continue to explore its capabilities and as the model is improved. It’s also worth mentioning that ChatGPT itself is a tool that can take some practice to efficiently use. Currently I don’t think it’s a perfect magic answer to any individual problem, although it does show promise with being helpful at some tasks.
Recommend
-
114
Collisions Collisions is a JavaScript library for quickly and accurately detecting collisions between Polygons, Circles, and Points. It combines the efficiency of a
-
93
A Simple 2D Golang collision detection and resolution library for games - SolarLune/resolv
-
52
This is a series about Star Anise Chronicles: Cheezball Rising , an expansive adventure game about my cat for the Game Boy Color. Follow al...
-
8
Relative performance for collision detection techniques in ActionScript 3 Friday, June 26, 2009 If you have read my blog any
-
6
Strategies for optimizing collision detection with BitmapData.hitTest Thursday, June 25, 2009 Yesterday I blogged about how you can use the
-
11
Using BitmapData.hitTest for Collision Detection Wednesday, June 24, 2009 The Flash Player contains a number of APIs for handling collision detection within Flash content. The [DisplayObject][1] class contains hitTest and hi...
-
5
Collision Detection is Hard: The Story of Alf Jul 26, 2021 Today we’re talking about ALF. It’s a surprising move for Nicole Express; we do not condone cat-eating. But neither did...
-
8
How to create a simple and efficient collision detection between paths in your HTML5 Canvas app or game? In this article we will create a maze, allow a player to navigate through the maze and detect when the player collides with the walls.
-
8
Libgdx Box2D - Collision detection advertisements I am trying detect player collisions with a sensor body. Imagine a collectible in a platform...
-
6
GJK: Collision detection algorithm in 2D/3D In my last article, I only covered sphere vs. sphere collisions because they are the simplest to compute. Spheres are nice and all, but there comes a time...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK