E
E
Epchenkay2018-10-01 08:58:51
JavaScript
Epchenkay, 2018-10-01 08:58:51

How to make a collision with the player?

I’m making a toy, I can’t add it so that the enemy (in my case it’s a ball) touching the player (rectangle) displays a modal window that the game is over
https://codepen.io/tiyzz/pen/gdNrXE

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton fon Faust, 2018-10-01
@bubandos

https://yandex.by/search/?text=javascript%20%D1%81...

G
GreatRash, 2018-10-01
@GreatRash

You are doing everything wrong. I suggest you download a thread of a game engine (such as Phaser) and write on it. And if you really want to get up and write your own engine, then you need to start by writing a game loop.
I highly recommend this article about creating a competent game loop.
After you understand how the game loop works, I suggest you read what vectors are. How to specify a vector, how to add vectors, how to subtract vectors, how to normalize a vector, what is the scalar product of vectors, what is the normal of a vector, how to find the angle between two vectors, how to find the projection of a vector onto a line, etc.
Here is a good series of tutorials about vectors.
Once you are familiar with vectors, you can start writing collision definitions between two objects. To get started, implement the AABB (Axis Aligned Bounding Box) algorithm, read about the separating axes theorem. Then try to implement the collision of the ball and the line. Then try to implement a collision of two balls.
Here is a series of tutorials (in English of course) on how to detect various collisions.
In order for you to be able to quickly handle collisions of several dozen objects, you will have to read about the QuadTree algorithm . I like this video where the guy explains how it works.
After learning the above things, you will be able to write games like Arkanoid, Billiards.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question