-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enemy ai #42
base: main
Are you sure you want to change the base?
Conversation
Now enemy can move, jump and, sometimes, - teleport. For the last one created the function MakeTeleport. Added the sprite for enemy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Помимо замечаний в коде, есть замечание к картинке. Насколько я помню, размер спрайта для противников никак не меняется при отрисовке и поэтому такой большой спрайт сломает всю игру. Можно, конечно, ничего не менять, но хотелось бы проект в рабочем состоянии...
README.md
Outdated
@@ -1,7 +1,7 @@ | |||
# Задание mit-game | |||
|
|||
В данном репозитории находятся подготовленные библиотеки, а также базовые файлы | |||
для работы программы. | |||
для работы программы.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
user.cpp
Outdated
@@ -130,7 +131,7 @@ void FixCollisions(Scene &scene, float dt) | |||
void ApplyGravity(Object &obj, float dt) | |||
{ | |||
ColliderType dynamic = ColliderType :: DYNAMIC; | |||
//проверяем должнали данная функция влиять на данный объект | |||
//проверяем должна ли данная функция влиять на данный объект |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не нужно менять код или комментарии, не относящиеся выполнению конкретной задачи.
user.cpp
Outdated
} | ||
|
||
void EnemyAI(Object &enemy, Scene &scene, float dt) { | ||
int FPS = 60; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Предполагать, что FPS будет равен 60 в локальной переменной функции – некорректно. Если мы решим выключить ограничение, либо изменить его, то код перестанет работать так, как предполагается.
user.cpp
Outdated
void EnemyAI(Object &enemy, Scene &scene, float dt) { | ||
int FPS = 60; | ||
|
||
if (int(dt) % 3 == 0) { // каждые три секунды есть 33% шанс подпрыгивания |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dt
– это время, прошедшее с прошлого кадра, а не со старта приложения. int(dt)
практически всегда будет равен 0 и 33% шанс превращается в 100% шанс.
user.cpp
Outdated
MakeTeleport(enemy); | ||
} | ||
else { | ||
float move = FPS * enemy.enemy.speed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для корректной работы скоростей в играх нужно умножать на dt
(либо делить на fps = 1 / dt). Учитывая, что здесь FPS захардкожен для этой функции, то смысла такое умножение несёт ещё меньше.
user.cpp
Outdated
int FPS = 60; | ||
|
||
if (int(dt) % 3 == 0) { // каждые три секунды есть 33% шанс подпрыгивания | ||
std::mt19937 mt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я не знаю как реализован random в C++, но могу предположить, что ему нужно задавать какой-то сид, чтобы рандом действительно был рандомным. Если каждый новый инстанс вихря Мерсенна создаётся с разным сидом, то всё нормально. Иначе, я предполагаю, результаты рандома всегда будут одинаковыми при каждом вызове этой функции (и той, что выше).
user.cpp
Outdated
enemy.position.y = mt() % 600; | ||
} | ||
|
||
void EnemyAI(Object &enemy, Scene &scene, float dt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отклоняться от стиля уже существующего проекта не стоит. Если везде открывающая скобка функции стоит на новой строке, то не нужно это менять. Во многих случаях такое может отклонить либо автоматический линтер, либо человек на код ревью. В нашем случае это не совсем ошибка, но всё же.
user.cpp
Outdated
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавлять рандомные пустые строчки, если целью не является стилевой рефакторинг проекта, тоже не нужно.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
No description provided.