Я пытаюсь создать анимацию терминала Perl, где сущность меняет направление, когда она сталкивается с другим объектом. Вот код, который у меня есть: < /p>
use Term::Animation 2.0;
use Term::Animation::Entity;
use Time::HiRes qw(time);
use Data::Dumper;
use Curses;
use strict;
use warnings;
main();
sub add_animal {
my ($anim, $y) = @_;
# Add the animal to the animation
my $animal = $anim->new_entity(
type => 'animal',
position => [3, $y, 1],
shape => '*',
color => 'r',
callback_args => [1, 0, 0, 0],
die_offscreen => 0,
coll_handler => \&animal_collision,
);
}
sub animal_collision {
my ($animal, $anim) = @_;
my $collisions = $animal->collisions();
#return unless defined $collisions;
foreach my $col_obj (@{$collisions}) {
# Get the current x direction from the callback_args
my $x_dir = $animal->callback_args->[0];
# Reverse the direction
$animal->callback_args->[0] = -$x_dir;
}
}
sub add_background {
my ($anim, $screen_width, $screen_height) = @_;
my $half_width = int($screen_width / 2);
my $ground_level = int($screen_height * 0.7);
for my $y (0..($screen_height)) {
$anim->new_entity(
shape => ['|'],
position => [$half_width, $y, 21],
color => ['w'],
);
}
}
sub main {
my $anim = Term::Animation->new();
$anim->color(1);
halfdelay(1);
my $paused = 0;
while(1) {
my $screen_width = $anim->width();
my $screen_height = $anim->height();
my $half_width = int($screen_width / 2);
my $ground_level = int($screen_height * 0.7);
add_background($anim, $screen_width, $screen_height);
add_animal($anim, ($ground_level - 1));
# animation loop
while(1) {
my $current_time = time();
# run and display a single animation frame
$anim->animate() unless($paused);
# use getch to control the frame rate, and get input at the same time.
my $input = getch();
if($input eq 'q') { quit(); }
if($input eq 'r' || $input eq KEY_RESIZE()) { last; }
if($input eq 'p') { $paused = !$paused; }
}
$anim->update_term_size();
$anim->remove_all_entities();
}
$anim->end();
}
< /code>
На данный момент объект животного проходит через другой объект без какого -либо изменения направления. Пожалуйста, дайте мне знать, что не так с детектором столкновений или любыми другими проблемами.
Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-working
Обнаружение столкновений с термином анимации Perl не работает ⇐ Linux
-
Anonymous
1741636719
Anonymous
Я пытаюсь создать анимацию терминала Perl, где сущность меняет направление, когда она сталкивается с другим объектом. Вот код, который у меня есть: < /p>
use Term::Animation 2.0;
use Term::Animation::Entity;
use Time::HiRes qw(time);
use Data::Dumper;
use Curses;
use strict;
use warnings;
main();
sub add_animal {
my ($anim, $y) = @_;
# Add the animal to the animation
my $animal = $anim->new_entity(
type => 'animal',
position => [3, $y, 1],
shape => '*',
color => 'r',
callback_args => [1, 0, 0, 0],
die_offscreen => 0,
coll_handler => \&animal_collision,
);
}
sub animal_collision {
my ($animal, $anim) = @_;
my $collisions = $animal->collisions();
#return unless defined $collisions;
foreach my $col_obj (@{$collisions}) {
# Get the current x direction from the callback_args
my $x_dir = $animal->callback_args->[0];
# Reverse the direction
$animal->callback_args->[0] = -$x_dir;
}
}
sub add_background {
my ($anim, $screen_width, $screen_height) = @_;
my $half_width = int($screen_width / 2);
my $ground_level = int($screen_height * 0.7);
for my $y (0..($screen_height)) {
$anim->new_entity(
shape => ['|'],
position => [$half_width, $y, 21],
color => ['w'],
);
}
}
sub main {
my $anim = Term::Animation->new();
$anim->color(1);
halfdelay(1);
my $paused = 0;
while(1) {
my $screen_width = $anim->width();
my $screen_height = $anim->height();
my $half_width = int($screen_width / 2);
my $ground_level = int($screen_height * 0.7);
add_background($anim, $screen_width, $screen_height);
add_animal($anim, ($ground_level - 1));
# animation loop
while(1) {
my $current_time = time();
# run and display a single animation frame
$anim->animate() unless($paused);
# use getch to control the frame rate, and get input at the same time.
my $input = getch();
if($input eq 'q') { quit(); }
if($input eq 'r' || $input eq KEY_RESIZE()) { last; }
if($input eq 'p') { $paused = !$paused; }
}
$anim->update_term_size();
$anim->remove_all_entities();
}
$anim->end();
}
< /code>
На данный момент объект животного проходит через другой объект без какого -либо изменения направления. Пожалуйста, дайте мне знать, что не так с детектором столкновений или любыми другими проблемами.
Подробнее здесь: [url]https://stackoverflow.com/questions/79499058/perl-term-animation-collision-detection-not-working[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия