StarCraft: Overlord and Bee (Seventeen)--Ultimate Body

Table of Contents of Series Articles

StarCraft: Little Overlord and Little Bee (16)--The Running Cat

StarCraft: Little Overlord and Little Bee (15)--The play is coming to an end

StarCraft: Little Overlord and Little Bee (14)--The Tears of the Capitalist

StarCraft: Little Overlord and Little Bee (13)--playing music and dancing

StarCraft: Little Overlord and Little Bee (12)--Cats have nine lives

  StarCraft: Little Overlord and Little Bee (11)--Kill, kill, kill

 StarCraft: Little Overlord and Little Bee (10)--Rat Road

StarCraft: Overlord and Bee (9) - Junkrat's Scourge

 StarCraft: Little Overlord and Little Bee (8)--Blue Rat and Big-faced Cat

  StarCraft: Little Overlord: Little Bee (7)--The disappearing bullet

StarCraft: Little Overlord and Little Bee (6)--Let the Bullets Fly

  StarCraft's Little Overlord's Little Bee (5)--Slow down the speed of the Little Bee

 StarCraft: Little Overlord and Little Bee (4)--Event Monitoring-Let the Little Bee Move


Table of contents

Table of Contents of Series Articles

Article directory

Preface

1. Change the rules for refreshing mice

2. Speed ​​up

Summarize


Preface

Yesterday we completed the preliminary transformation of the game. After the transformation of my personal mission, the game is more fun and more operable. At the same time, we also found areas that need improvement. Our mice are still the same as before. After a batch is created, they must be destroyed and then another batch will be created. My expectation is that mice will continue to be produced, which will also bring out a new batch. The problem is that the speed changes. In the past, the speed was increased after being eliminated, so here we have to rewrite the code.


1. Change the rules for refreshing mice

Previously, the mouse creation function was called after the mice were eliminated. Now, the created function needs to be called every 2 seconds or 3 seconds. Try rewriting the code and see.

 I encountered a difficulty when writing. At this time, creating a mouse and other things are independent things and require the knowledge of multi-threading. Sorry everyone, I don't know how. If I directly create a new mouse every time I refresh the screen, because The refresh speed is very fast, so there will be densely packed mice. We need to find a compromise. For example, if we meet certain conditions, we will create new mice, just like all mice are eliminated. The best way is to generate a batch of mice every 50 pixels when the mice drop. In this way, we set an attribute that has the same falling speed as the mice. When its y-axis coordinate is greater than 100, mice will be generated and its value will be changed. Return to 0, let's give it a try.

while True:
        gf.check_events(new_setting,screen,ship,bullets,stats,play_button,aliens,sb)
        if stats.game_active:
            if y<(new_setting.fleet_drop_speed*10)+150:
                y += new_setting.fleet_drop_speed
            else:
                gf.create_fleet(new_setting, screen, aliens, stats)
                y =0
            ship.update()
            gf.update_bullets(new_setting,screen,bullets,aliens,stats,sb)
            gf.update_aliens(new_setting,stats,screen,ship,aliens,bullets)
        gf.update_screen(new_setting,screen,stats,ship,bullets,aliens,play_button,sb)

 Let's test the effect

 

 It can be seen that the effect is surprisingly good, exactly as we expected.

2. Speed ​​up

After implementing the function of continuously generating mice, I think we can use the same idea to complete the rest of the speed increase. Set a variable to represent time to control. For example, the speed will be increased every time it reaches 1000, and then the variable will be reset to zero. You can also increase the speed according to the score, create a variable, and increase the speed every time 100 mice are eliminated, and then the variable is reset to zero. This can also achieve the effect of speeding up each time, which will not be written here.


Summarize

Little Bee version 1.1 is basically completed. Through today's study, we can fully discover the flexibility of the code, which requires us to constantly use our brains during use, rather than rigidly memorizing and copying the code. We're going to take a break later, and the update plan for this game is on hold because I feel like I need to learn other things.

Guess you like

Origin blog.csdn.net/m0_49914128/article/details/133713521