外星人入侵_外星人

news2024/9/9 0:38:25

项目_外星人入侵_外星人

  • 1创建第一个外星人
    • 1.1创建Alien类
    • 1.2创建Alien实例
    • 1.3让外星人出现在屏幕上
  • 2创建一群外星人
    • 2.1确定一行可以容纳多少外星人
    • 2.2 创建多行外星人
    • 2.3创建外星人群
    • 2.4重构create_fleet()
    • 2.5添加行
  • 3让外星人群移动
    • 3.1向右移动外星人
    • 3.2创建表示外星人移动方向的设置
    • 3.3检查外星人是否撞到了屏幕边缘
    • 3.4向下移动外星人群并改变移动方向
  • 4射杀外星人
    • 4.1检测子弹与外星人的碰撞
    • 4.2为测试创建大子弹
    • 4.3生成新的外星人群
    • 4.4重构update_bullets()
  • 5结束游戏
    • 5.1检测外星人和飞船碰撞
    • 5.2响应外星人和飞船碰撞
    • 5.3有外星人达到屏幕底端
    • 5.4游戏结束
  • 6确定应运行游戏的哪些部分

1创建第一个外星人

1.1创建Alien类

alien.py:

import pygame
from pygame.sprite import Sprite

class Alien(Sprite):
    """表示单个外星人并设置其初始位置"""

    def __init__(self, ai_settings, screen):
        """初始化外星人并设置其初始位置"""
        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        #加入外星人图像,并设置其rect属性
        self.image = pygame.image.load('images/alien.bmp')
        self.rect = self.image.get_rect()

        #每个外星人最初都在屏幕左上角附近
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        #存储外星人的准确位置
        self.x = float(self.rect.x)

    def blitme(self):
        """在指定位置绘制外星人"""
        self.screen.blit(self.image, self.rect)

1.2创建Alien实例

alien_invasion.py中创建一个Alien实例:


    #  创建飞船
    ship = Ship(ai_setting, screen)
    #创建外星人
    alien = Alien(ai_setting, screen)
        #开始游戏的主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_setting, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)

        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_setting, screen, ship, bullets, alien)

1.3让外星人出现在屏幕上

game_function():

def update_screen(ai_settings, screen, ship, bullets, alien):
    """更新屏幕上的图像,并切换到新屏幕"""
    # 每次循环都重绘屏幕
    screen.fill(ai_settings.bg_color)
    #在飞船和外星人后面重绘所有子弹
    for bullet in bullets.sprites():
        bullet.draw_bullet()

    ship.blitme()  # 确保飞船绘制在屏幕上,并出现在背景前面
    alien.blitme()  # 确保外星人在屏幕上,并出现在背景前面

    # 让最近绘制的屏幕可见
    pygame.display.flip()

在这里插入图片描述

2创建一群外星人

2.1确定一行可以容纳多少外星人

可容纳外星人的水平空间为屏幕宽度减去屏幕两边留下的边距(边距设置为外星人的宽度):
available_space_x = ai_settings.screen.width - alien_width*2
一行可容纳的外星人的个数为可容纳外星人的水平空间除以一个外星人所需的水平空间(即外星人宽度的两倍:一个宽度放外星人,一个宽度为外星人右边的空白区域):
number_aliens_x = int(available_space_x / (2 * alien_width))

2.2 创建多行外星人

alien_invasion.py

    #  创建飞船
    ship = Ship(ai_setting, screen)
    
    #创建一组用于存储子弹的编组
    bullets = Group()    #创建一个Group实例
    # 创建外星人
    aliens = Group()

    #开始游戏的主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_setting, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.create_fleet(ai_setting, screen, aliens)

        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_setting, screen, ship, bullets, aliens)

game_function()修改update_screen():

def update_screen(ai_settings, screen, ship, bullets, aliens):
    """更新屏幕上的图像,并切换到新屏幕"""
    # 每次循环都重绘屏幕
    screen.fill(ai_settings.bg_color)
    #在飞船和外星人后面重绘所有子弹
    for bullet in bullets.sprites():
        bullet.draw_bullet()

    ship.blitme()  # 确保飞船绘制在屏幕上,并出现在背景前面
    aliens.draw(screen)  # 1确保外星人在屏幕上,并出现在背景前面

    # 让最近绘制的屏幕可见
    pygame.display.flip()

1处对编组调用draw()时,Pygame自动绘制编组的每个元素,绘制位置由元素的属性rect决定。aliens.draw(screen)表示在屏幕上绘制编组中的每一个外星人。

2.3创建外星人群

game_function():

def create_fleet(ai_settings, screen, aliens):
    """创建外星人群"""
    #创建一个外星人,并计算一行可以容纳多少外星人
    # 外星人间距为外星人宽度
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    available_space_x = ai_settings.screen.width - alien_width*2
    number_aliens_x = int(available_space_x / (2 * alien_width))

    #创建第一行外星人
    for alien_number in number_aliens_x:
        #创建一个外星人并加入当前行
        alien = Alien(ai_settings, screen)
        alien.x = alien_width + 2 * alien_number * alien_number
        alien.rect.x = alien.x
        aliens.add(alien)

在这里插入图片描述

2.4重构create_fleet()

create_fleet重构为get_number_aliens_xcreate_alien,使得添加新行创建整群外星人变得容易。
game_function.py

def get_number_aliens_x(ai_settings, alien_width):
    """计算每行可容纳多少外星人"""
    # 外星人间距为外星人宽度
    available_space_x = ai_settings.screen_width - alien_width * 2
    number_aliens_x = int(available_space_x / (2 * alien_width))
    return number_aliens_x

def create_alien(ai_settings, screen, alien_number, aliens):
    # 创建一个外星人并将其放在当前行
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    aliens.add(alien)

def create_fleet(ai_settings, screen, aliens):
    """创建外星人群"""
    #计算一行可以容纳多少外星人
    alien = Alien(ai_settings, screen)
    number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width)
    #创建第一行外星人
    for alien_number in range(number_aliens_x):
        create_alien(ai_settings, screen, alien_number, aliens)

2.5添加行

首先计算可用的垂直空间:将屏幕高度减去第一行外星人的上边距(外星人高度)、飞船的高度、最初外星人群与飞船的距离(外星人高度的2倍):
available_space_y = (ai_settings.screen_height - (3 * alien_height) - ship_height)
然后计算可容纳外星人的行数:可用垂直空间/外星人高度的两倍
number_rows = int(available_space_y / (2 * alien_height))
知道可容纳多少行后,重复执行创建一行外星人的代码:
game_function.py

def get_number_rows(ai_settings, ship_height, alien_height):
    """计算屏幕可容纳多少行外星人"""
    available_space_y = (ai_settings.screen_height - (3 * alien_height) - ship_height)   #可容纳空间
    number_rows = int(available_space_y / (2 * alien_height))      #可容纳的外星人行数
    return number_rows

def create_alien(ai_settings, screen, alien_number, aliens, row_number):
    # 创建一个外星人并将其放在当前行
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
    aliens.add(alien)

def create_fleet(ai_settings, screen, aliens, ship):
    """创建外星人群"""
    #计算一行可以容纳多少外星人
    alien = Alien(ai_settings, screen)
    number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width)
    number_rows = get_number_rows(ai_settings, ship.rect.height, alien.rect.height)
    #创建外星人群
    for row_number in range(number_rows):
        for alien_number in range(number_aliens_x):
            create_alien(ai_settings, screen, alien_number, aliens, row_number)

alien_invasion.py:

# 创建外星人
    aliens = Group()
    gf.create_fleet(ai_setting, screen, aliens, ship)   #应该在循环外面创建外星人群

在修改代码时需要注意函数实参的使用(究竟是什么)
在这里插入图片描述

3让外星人群移动

下面让外星人在屏幕上向右移动,撞到屏幕后下移一定的距离,再沿相反方向移动。

3.1向右移动外星人

settings.py设置外星人速度

# 外星人速度设置
        self.alien_speed_factor = 0.5

game_function.py中添加更新外星人函数:

def update_aliens(aliens):
    """更新外星人群所有的外星人位置"""
    aliens.update()

最后在alien_invasion.py调用此函数:

    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_setting, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)

        gf.update_aliens(aliens)
        #aliens.update()

        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_setting, screen, ship, bullets, aliens)

在这里插入图片描述

3.2创建表示外星人移动方向的设置

settings.py:

 # 外星人速度设置
        self.alien_speed_factor = 0.5
        self.fleet_drop_speed = 10   #外星人撞到屏幕边缘时下降速度
        #fleet_direction为1表示向右移动,为-1表示向左移动
        self.fleet_direction = 1

3.3检查外星人是否撞到了屏幕边缘

alien.py:

    def check_edges(self):
        """如果外星人处于屏幕边缘,返回True"""
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right:
            return True
        elif self.rect.left <= 0:
            return True

    def update(self):
        """向右移动外星人"""
        self.x += self.ai_settings.alien_speed_factor * self.ai_settings.fleet_direction
        self.rect.x = self.x

3.4向下移动外星人群并改变移动方向

当有外星人到达屏幕边缘时,需要将正群外星人下一,并改变他们的移动方向。
game_functipn.py


def check_fleet_edges(aliens, ai_settings, screen):
    """有外星人到达边缘时采取相应行动"""
    for alien in aliens.sprites():
        if alien.check_edges():        #调用函数需要加小括号
            change_fleet_direction(aliens, ai_settings, screen)  # 调整外星人下移并改变方向
            break


def change_fleet_direction(aliens, ai_settings, screen):
    #调增外星人下移,并改变他们的方向
    screen_rect = screen.get_rect()
    for alien in aliens.sprites():
        #if alien.rect.bottom <= screen_rect.bottom:   去掉此if,外星人下落到底端会继续下落
            alien.rect.y += ai_settings.fleet_drop_speed
    ai_settings.fleet_direction *= -1


def update_aliens(aliens, ai_settings, screen):
    """检查外星人的位置,更新外星人群所有的外星人位置"""
    check_fleet_edges(aliens, ai_settings, screen)
    aliens.update()

4射杀外星人

这里希望子弹击中外星人时,能够击落外星人,使用sprite.groupcollide()检测两个编组成员之间的碰撞。

4.1检测子弹与外星人的碰撞

首先进行检测碰撞,game_function.py

def update_bullets(bullets, aliens):
    bullets.update()
    # 更新子弹的位置,并删除已经消失的子弹
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)
        #检查是否有子弹击中外星人
        #如果是这样,就删除相应的子弹和外星人
        collisions = pygame.sprite.groupcollide(bullets, aliens, True, True)    #1

在1处使用方法sprite.groupcollide()将每颗子弹的rect同每个外星人的rect进行比较,并返回一个字典,其中包含发生了碰撞的子弹和外星人。在这个字典中,每个键都是一颗子弹,而相应的值都是被击中的外星人。
sprite.groupcollide()先遍历编组bullets中的每颗子弹,再遍历编组aliens中的每个外星人。每当有子弹和外星人的rect重叠时,groupcollide()就在他返回的字典中添加一个键-值对。两个实参True告诉Pygame删除发生碰撞的子弹和外星人(要模拟能够穿行到屏幕顶端的高能子弹——消灭它击中的每一个外星人,可将第一个布尔实参设置为False,第二个布尔实参设置为True,这样被击中的外星人将会消失,二所有的子弹始终有效,知道地道屏幕顶端后消失。)

修改alien_invasion.py中调用实参:

gf.update_bullets(bullets, aliens)

现在运行游戏,被击中的外星人会消失。
在这里插入图片描述

4.2为测试创建大子弹

在测试代码能否正确处理外星人编组为空的情形时,需要花很长时间将屏幕上的外星人击落。
因此可以增大子弹的尺寸,并使其在击中外星人后依然有效。
类似这样的代码修改可以提高测试效率,还能激发出如何赋予玩家更大威力的思想火花。

self.bullet_width = 300

在这里插入图片描述

4.3生成新的外星人群

本游戏一个重要特点为外星人无穷无尽,一个外星人群被消灭后,又会出现一群外星人。
因此需要首先检查编组aliens是否为空。如果为空,就调用create_fleet()。将在update_bullets()中执行这种检查,因为外星人都是在这里被消灭的。
game_function.py

def update_bullets(ai_settings, screen, ship, bullets, aliens):
    bullets.update()
    # 更新子弹的位置,并删除已经消失的子弹
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)
        #检查是否有子弹击中外星人
        #如果是这样,就删除相应的子弹和外星人
        collisions = pygame.sprite.groupcollide(bullets, aliens, False, True)
        if len(aliens) == 0:
            # 删除现有子弹并新建一群外星人
            bullets.empty()
            create_fleet(ai_settings, screen, aliens, ship)

修改alien_invasion.py中调用实参:

gf.update_bullets(ai_setting, screen, ship, bullets, aliens)

4.4重构update_bullets()

重构update_bullets()使其不再完成那么多任务。
将处理子弹和外星人碰撞的代码移到独立的函数中。
game_function.py

def update_bullets(ai_settings, screen, ship, bullets, aliens):
    bullets.update()
    # 更新子弹的位置,并删除已经消失的子弹
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)
        # 检查是否有子弹击中外星人并处理
        check_bullet_alien_collisions(bullets, aliens, ai_settings, screen, ship)
            
def check_bullet_alien_collisions(bullets, aliens, ai_settings, screen, ship):
    # 检查是否有子弹击中外星人
    # 如果是这样,就删除相应的子弹和外星人
    collisions = pygame.sprite.groupcollide(bullets, aliens, False, True)
    if len(aliens) == 0:
        # 删除现有子弹并新建一群外星人
        bullets.empty()
        create_fleet(ai_settings, screen, aliens, ship)

创建了一个新函数check_bullet_alien_collisions以检测子弹和外星人之间的碰撞以及整群外星人都被消灭时采取相应的措施。

5结束游戏

游戏结束条件:
①外星人撞到飞船飞船将摧毁
②足够短时间没有消灭外星人飞船将摧毁
③外星人达到屏幕底端飞船将摧毁
④玩家使用完了所有飞船,游戏结束。

5.1检测外星人和飞船碰撞

game_function.py

def update_aliens(aliens, ai_settings, screen,ship):
    """检查外星人的位置,更新外星人群所有的外星人位置"""
    check_fleet_edges(aliens, ai_settings, screen)
    aliens.update()

    #检测外星人和飞船之间的碰撞
    if pygame.sprite.spritecollideany(ship, aliens):
        print("Ship hit!!!")

方法sprite.spritecollideany接受两个实参,一个精灵和一个编组。它检查编组是否有成员和精灵发生了碰撞,并在找到与精灵发生额了碰撞的成员后停止遍历编组。在这里它遍历编组aliens,并返回它找到的第一个与飞船发生了碰撞的外星人。
如果没有发生碰撞,spritecollideany()将分会None,if里面的代码块不会执行,如果找到了飞船发生碰撞的外星人,则返回这个外星人。
碰撞后需要删除余下的外星人和子弹,让飞船重新居中,创建一群新的外星人。

5.2响应外星人和飞船碰撞

第一步:ship被撞时不销毁并创建新的ship,而是最总游戏的统计信息来记录飞船被撞了多少次,创建一个统计类
game_stats.py:

class GameStats():
    """跟踪游戏的统计信息"""
    def __init__(self, ai_settings):
        """初始化统计信息"""
        self.ai_settings = ai_settings
        self.reset_stats()

    def reset_stats(self):
        """初始化在游戏运行期间可能变化的统计信息"""
        self.ship_left = self.ai_settings.ship_limit

第二步:设置飞船的个数
settings.py:\

#飞船设置
        self.ship_speed_factor = 1.5     #设置飞船速度为1.5
        self.ship_limit = 3   # 飞船的个数限制为3

第三步:在alien_invasion.py中创建GameStats实例,并更新调用update_aliens()中的实参:

# 创建一个用于存储游戏统计信息的实例
    stats = GameStats(ai_setting)
    #开始游戏的主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_setting, screen, ship, bullets)
        ship.update()
        gf.update_bullets(ai_setting, screen, ship, bullets, aliens)

        gf.update_aliens(aliens, ai_setting, screen, ship, stats, bullets)
        #aliens.update()

        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_setting, screen, ship, bullets, aliens)

第四步:响应外星人撞到飞船game_function:

def update_aliens(aliens, ai_settings, screen, ship, stats, bullets):
    """检查外星人的位置,更新外星人群所有的外星人位置"""
    check_fleet_edges(aliens, ai_settings, screen)
    aliens.update()

    #检测外星人和飞船之间的碰撞
    if pygame.sprite.spritecollideany(ship, aliens):
        ship_hit(stats, aliens, bullets, ai_settings, screen, ship)

def ship_hit(stats, aliens, bullets, ai_settings, screen, ship):
    """响应被外星人撞到的飞船"""
    # 将ship_left-1
    stats.ship_left -= 1

    # 清空子弹和外星人列表
    aliens.empty()
    bullets.empty()

    # 创建一群新的外星人,并将飞船放到屏幕底端中央
    create_fleet(ai_settings, screen, aliens, ship)
    ship.center_ship()

    # 暂停
    sleep(0.5)

其中,center_ship()方法为ship.py中的新方法:

    def center_ship(self):
        """让飞船在屏幕上居中"""
        self.center = self.screen_rect.centerx

5.3有外星人达到屏幕底端

game_function.py

def update_aliens(aliens, ai_settings, screen, ship, stats, bullets):
    """检查外星人的位置,更新外星人群所有的外星人位置"""
    check_fleet_edges(aliens, ai_settings, screen)
    aliens.update()

    #检测外星人和飞船之间的碰撞
    if pygame.sprite.spritecollideany(ship, aliens):
        ship_hit(stats, aliens, bullets, ai_settings, screen, ship)
    check_aliens_bottom(screen, aliens, stats, bullets, ai_settings, ship)

def check_aliens_bottom(screen, aliens, stats, bullets, ai_settings, ship):
    """检查是否有外星人到达屏幕底端"""
    screen_rect = screen.get_rect()
    for alien in aliens.sprites():
        if alien.rect.bottom <= screen_rect.bottom:
            ship_hit(stats, aliens, bullets, ai_settings, screen, ship)

5.4游戏结束

刚启动游戏处于活跃状态:
game_stats

    def __init__(self, ai_settings):
        """初始化统计信息"""
        self.ai_settings = ai_settings
        self.reset_stats()
        self.game_active = True   #游戏刚启动处于活跃状态

当飞船数为0时,使得游戏非活跃状态:
game_function.py:

def ship_hit(stats, aliens, bullets, ai_settings, screen, ship):
    """响应被外星人撞到的飞船"""

    if stats.ship_left > 0:
        # 将ship_left-1
        stats.ship_left -= 1

        # 清空子弹和外星人列表
        aliens.empty()
        bullets.empty()

        # 创建一群新的外星人,并将飞船放到屏幕底端中央
        create_fleet(ai_settings, screen, aliens, ship)
        ship.center_ship()

        # 暂停
        sleep(0.5)
    else:
        stats.game_active = False

6确定应运行游戏的哪些部分

最后确认游戏哪些部分在任何情况都运行,哪些部分仅在游戏处于活动状态才运行:

    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_setting, screen, ship, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_setting, screen, ship, bullets, aliens)

            gf.update_aliens(aliens, ai_setting, screen, ship, stats, bullets)
            #aliens.update()

        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_setting, screen, ship, bullets, aliens)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1958530.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

迷你世界魔方模型快速制作

做六个不一样颜色的顶部 --黄&#xff0c;绿&#xff0c;红&#xff0c;蓝&#xff0c;橙&#xff0c;白 --local ids{4000,3999, 3998,3997,3996,3995} 游戏脚本运行上一期文章 local x0,y0,z0-39,7,10--起点坐标 --框架、底面、侧面1-4、顶面 local id{682,671,681,680,66…

消息队列rabbitmq的使用

前提条件&#xff1a;环境安装amqp和安装rabbitmq sudo apt-get update sudo apt-get install rabbitmq-amqp-dev 1、创建CMakeLists.txt文件 # Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.# CMake lowest version requirement cmake_minimum_…

tof系统标定流程之lens标定

1、lens标定详解 为什么在标定tof时需要进行lens的标定,可以说lens标定是一个必不可少的步骤,tof模组也是有镜头的,镜头的畸变会导致进入的光线出现偏差,最终照射到tof芯片表面导致深度图的分布出现畸变,通常是枕形畸变。例外一个用途在于,在计算fppn误差环节需要知道镜头…

机器学习算法与Python实战 | 两行代码即可应用 40 个机器学习模型--lazypredict 库!

本文来源公众号“机器学习算法与Python实战”&#xff0c;仅用于学术分享&#xff0c;侵权删&#xff0c;干货满满。 原文链接&#xff1a;两行代码即可应用 40 个机器学习模型 今天和大家一起学习使用 lazypredict 库&#xff0c;我们可以用一行代码在我们的数据集上实现许多…

【数据结构】队列(链表实现 + 力扣 + 详解 + 数组实现循环队列 )

Hi~&#xff01;这里是奋斗的明志&#xff0c;很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~~ &#x1f331;&#x1f331;个人主页&#xff1a;奋斗的明志 &#x1f331;&#x1f331;所属专栏&#xff1a;数据结构 &#x1f4da;本系列文章为个人学…

流行巨星布兰妮·斯皮尔斯发生了什么事?她现在在哪里过得怎么样

流行音乐公主布兰妮斯皮尔斯是 21 世纪初的经典偶像。她从 15 岁起就开始唱歌和表演&#xff0c;并创作了《Oops I Did it Again》和《Baby One More Time》等热门歌曲。她的歌曲非常出色&#xff0c;在 2000 年荣登榜首。她接下来的几张专辑变得更加畅销&#xff0c;她毫不畏惧…

学习008-02-04-04 Enable Split Layout in a List View(在列表视图中启用拆分布局 )

Enable Split Layout in a List View&#xff08;在列表视图中启用拆分布局 &#xff09; This lesson explains how to enable a Split Layout in a List View. 本课介绍如何在列表视图中启用拆分布局。 The Detail View opens when you select an object from the List Vie…

G120 EPos配置方案及应用场景

EPos功能就是基本定位器功能,它可计算出轴的运行特性,使轴以时间最佳的方式移动到目标位置。EPos功能主要包括:设定值 直接给定(MDI)功能、 选择程序段功能、回参考点功能、点动功能、运行到固定挡块功能。 EPos功能通过处理给定的加速度、速度和位置值生成运行特性曲线,…

node+mysql+layui+ejs实现左侧导航栏菜单动态显示

nodemysqllayuiejs实现左侧导航菜单动态显示 实现思路效果图数据库技术栈代码实现main.html&#xff08;前端首页页面&#xff09;查询资源菜单方法 jsapp.js配置ejs模板 node入门到入土项目实战开始&#xff0c;前端篇项目适合node小白入门&#xff0c;因为我也是小白来学习no…

机器人笛卡尔空间阻抗控制

机器人笛卡尔空间阻抗控制是一种重要的机器人控制策略,它关注于机器人末端执行器在笛卡尔空间(即任务空间)内的动态特性,以实现与环境的柔顺交互。以下是对机器人笛卡尔空间阻抗控制的详细解释: 一、基本概念 笛卡尔空间:指机器人末端执行器(如手爪、工具等)所处的三维…

Hive之扩展函数(UDF)

Hive之扩展函数(UDF) 1、概念讲解 当所提供的函数无法解决遇到的问题时&#xff0c;我们通常会进行自定义函数&#xff0c;即&#xff1a;扩展函数。Hive的扩展函数可分为三种&#xff1a;UDF,UDTF,UDAF。 UDF&#xff1a;一进一出 UDTF&#xff1a;一进多出 UDAF&#xff1a…

YOLO v8目标检测(三)模型训练与正负样本匹配

YOLO v8目标检测 损失函数理论 在YOLO v5模型中&#xff0c;cls, reg, obj代表的是三个不同的预测组成部分&#xff0c;对应的损失函数如下&#xff1a; cls: 这代表类别预测&#xff08;classification&#xff09;。对应的损失是类别预测损失&#xff08;loss_cls&#xff…

Win10出现错误代码0x80004005 一键修复指南

对于 Windows 10 用户来说&#xff0c;错误代码 0x80004005 就是这样一种迷雾&#xff0c;它可能在不经意间出现&#xff0c;阻碍我们顺畅地使用电脑。这个错误通常与组件或元素的缺失有关&#xff0c;它可能源自注册表的错误、系统文件的损坏&#xff0c;或者是软件的不兼容。…

listener监听

背景: 过滤器代码也可实现接口请求次数统计,但会影响过滤器本意;故在dispatcher servlet层进行监听统计 价值: 所有接口的次数统计可适用于系统全天访问量; 单个请求接口的次数统计可在企业中根据接口次数的高低,可分析出接口对应的功能受用户的喜好程度 请求通过过滤器到了s…

common-intellisense:助力TinyVue 组件书写体验更丝滑

本文由体验技术团队Kagol原创~ 前两天&#xff0c;common-intellisense 开源项目的作者 Simon-He95 在 VueConf 2024 群里发了一个重磅消息&#xff1a; common-intellisense 支持 TinyVue 组件库啦&#xff01; common-intellisense 插件能够提供超级强大的智能提示功能&…

c生万物系列(职责链模式与if_else)

从处理器的角度来说&#xff0c;条件分支会导致指令流水线的中断&#xff0c;所以控制语句需要严格保存状态&#xff0c;因为处理器是很难直接进行逻辑判断的&#xff0c;有可能它会执行一段时间&#xff0c;发现出错后再返回&#xff0c;也有可能通过延时等手段完成控制流的正…

skynet 实操篇

文章目录 概述demo启动文件skynet_start配置文件main.luastart函数thread_workerskynet_context_message_dispatchskynet_mq_popdispatch_message 小结 概述 上一篇写完skynet入门篇&#xff0c;这一篇写点实操性质的。 demo 对于一个开源框架&#xff0c;大部分都有他们自己…

《Linux运维总结:基于x86_64架构CPU使用docker-compose一键离线部署zookeeper 3.8.4容器版分布式集群》

总结&#xff1a;整理不易&#xff0c;如果对你有帮助&#xff0c;可否点赞关注一下&#xff1f; 更多详细内容请参考&#xff1a;《Linux运维篇&#xff1a;Linux系统运维指南》 一、部署背景 由于业务系统的特殊性&#xff0c;我们需要面对不同的客户部署业务系统&#xff0…

C++客户端Qt开发——界面优化(美化登录界面)

美化登录界面 在.ui中拖入一个QFream&#xff0c;顶层窗口的QWidget无法设置背景图片&#xff0c;套上一层QFrame将背景图片设置到QFrame上即可 用布局管理器管理元素&#xff1a;用户名LineEdit&#xff0c;密码LineEdit&#xff0c;记住密码ComboBox&#xff0c;登录Button…

ubuntu2204安装elasticsearch7.17.22

下载安装 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.22-amd64.deb wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.22-amd64.deb.sha512 shasum -a 512 -c elasticsearch-7.17.22-amd64.deb.sha512 su…