コード例 #1
0
        public static Vector2[,] Get_Bullet_Poses(Bullet[] bullets, bool[,] map, int steps = 120)
        {
            EnvShooter env = create_env();

            Bullet[] n_bullets = new Bullet[bullets.Length];
            Vector2[,] bullet_positions = new Vector2[steps, n_bullets.Length];

            for (int i = 0; i < bullets.Length; i++)
            {
                n_bullets[i] = new Bullet(bullets[i].Pos, bullets[i].Velocity, 2982397 + i, bullets[i].Color, env);
            }

            SetValue(env, "map", map);

            for (int j = 0; j < n_bullets.Length; j++)
            {
                for (int i = 0; i < steps; i++)
                {
                    call(n_bullets[j], "Move");

                    bullet_positions[i, j] = new Vector2(n_bullets[j].Pos.X, n_bullets[j].Pos.Y);

                    Vector2 velocity = n_bullets[j].Velocity * 0.99f;
                    SetValue(n_bullets[j], "velocity", velocity);

                    if (velocity != Vector2.Zero)
                    {
                        if (velocity.Length() < 0.1f)
                        {
                            // NOTHING HIT!
                            for (int y = i; y < steps; y++)
                            {
                                bullet_positions[y, j] = new Vector2(n_bullets[j].Pos.X, n_bullets[j].Pos.Y);
                            }
                            break;
                        }

                        if (velocity.Length() < 0.01f)
                        {
                            velocity = Vector2.Zero;
                        }
                    }
                }
            }
            return(bullet_positions);
        }
コード例 #2
0
        public static int CollidesWith(Vector2 pos, float radius, Bullet b, bool[,] map, int steps = 60)
        {
            EnvShooter env      = create_env();
            Bullet     n_bullet = new Bullet(b.Pos, b.Velocity, 2982397, b.Color, env);

            SetValue(env, "map", map);


            for (int i = 0; i < steps; i++)
            {
                call(n_bullet, "Move");

                // Check collision
                if (n_bullet.Pos.X + 0.2f + 0.1f >= pos.X - radius && n_bullet.Pos.X - (0.2f + 0.1f) <= pos.X + radius &&
                    n_bullet.Pos.Y + 0.2f + 0.1f >= pos.Y - radius && n_bullet.Pos.Y - (0.2f + 0.1f) <= pos.Y + radius)
                {
                    return(i);
                }

                Vector2 velocity = n_bullet.Velocity * 0.99f;
                SetValue(n_bullet, "velocity", velocity);

                if (velocity != Vector2.Zero)
                {
                    if (velocity.Length() < 0.1f)
                    {
                        // NOTHING HIT!
                        break;
                    }

                    if (velocity.Length() < 0.01f)
                    {
                        velocity = Vector2.Zero;
                    }
                }
            }
            return(-1);
        }