# Collision in 2D-Game

**URL:** <https://discourse.processing.org/t/collision-in-2d-game/31914>\
**Category:** Coding Questions\
**Created:** [August 25, 2021, 8:00am UTC](https://discourse.processing.org/t/collision-in-2d-game/31914 "2021-08-25T08:00:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [August 27, 2021, 10:01am UTC](https://discourse.processing.org/t/collision-in-2d-game/31914/4 "2021-08-27T10:01:15Z")

</div>

Hi! I thought this was an interesting challenge so I made a simple demo program.  
ONLY WATCH IF YOU DON’T WANT TO FIND THE SOLUTION YOURSELF!!!

I posted it in my project library; here is the link to the “solution”

> [@My projects library #4! Gallery Megathread](https://discourse.processing.org/t/my-projects-library-4-gallery-megathread/31103/19):
>
> #54 2D simple collisions demo 1 This is a simple demo for a 2D collision detection with rectangles. The only square that can move is the player. If you find any bugs, do tell! 
> 
> > **Code**
> >
> > int px = 10, py = 10, a = 20; int cx = 0, cy = 0, speed = 1; obstacle o = new obstacle(275, 275, 50, 50); void setup() { size(600, 600); } void draw() { background(0); movePlayer(); fill(255); square(px, py, a); o.display(); } void movePlayer() { for (int i = 0; i \< speed; i++) { int nx = px+cx, …

---

_[View the full topic](https://discourse.processing.org/t/collision-in-2d-game/31914)._
