From bd294836b00880dfcb0ae070ee7676bed8f7b906 Mon Sep 17 00:00:00 2001 From: 206530322 <1771577741@qq.com> Date: Fri, 18 Jun 2021 18:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=94=E9=83=A8=E5=88=865?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/alien.cpython-39.pyc | Bin 0 -> 1293 bytes __pycache__/bullet.cpython-39.pyc | Bin 0 -> 1110 bytes game_functions.py | 35 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 __pycache__/alien.cpython-39.pyc create mode 100644 __pycache__/bullet.cpython-39.pyc diff --git a/__pycache__/alien.cpython-39.pyc b/__pycache__/alien.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8f618b7f60912b7daaf228bed78c57fbacb26770 GIT binary patch literal 1293 zcmZ`(OK;RL5FR^^X1kA;w|E>lvJz^m@{$ljpdxYWrNALtVM6TPCYya=dj+kQQ!DW| zy2t(&ZX7LcocIfzm~mRPAYsXq8GADM{LSZN?e;3*`1a=OyYCUe4+@q?h`}?Q<_;PO zl2wq>lUHoSQ_kQe$Uuh2AVbBEf;5n954zD$%!b`AbMf9(7gpsIFOT3XF!#|>kTMA= z{{np`ndHX_*6~%-P)0I7hBT5ZGQns31wu$y@EZ*mJ+BHi&d*CxMe@(5d5eJs%jR&z zPxt~D%=sKdFvk@U+Ng|ARwP?c6wd*pWC7?m&~KEhWJS~aE$_E&$4AX0dZQ@;LGazf z^cj#A#sTi#kjCSxY*=csj+Kjg)qw6VmvS|o*oRck#dnQ zlOT%j?tVl*AODF zGGl}|grOyH_7zdZ1AUK!waY z8sHrkvpDFmR?xzE*zv4yoS!OZlyo-8C&ldGG*{6eVQ_+Ul}LOUEKn~*+bP@ah90X6 z-&cjz4NTQ7G^b2oB>&1ELseW%StE4~eZ$cJKWx=7>W%+{Alc3lQ%O*mhr!C=GCTqf z!o$P$PUSgE!H1_az34d+W~!7F{VcZ=?biC0!tTg|I#W!>9=Eco|AQWcn_}UX8)- zD@`rHGf@9@lMK=7BJEWZR;q8i+;i-jwH&?9{)OJm_fQ{z zz~3agO(sE;1g#56m_&XRg+yzvUEiY(* B8;t+} literal 0 HcmV?d00001 diff --git a/__pycache__/bullet.cpython-39.pyc b/__pycache__/bullet.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..76bba8e8aa4603ade8e86b454902a1fbb155750b GIT binary patch literal 1110 zcmZWo&2AGh5FUGfvPpN7LPhx%=SD(N)e3|VLa0UJ)&munRV1^lon*J$WU(EURJpZM zU!%Q|H{lt4<-{v+V(g?<1eWH| zAhniOj3MMIVnSw#*L4s(cCMevN?w`Vom3_oZr$L)|T-F)?qQ`CurMfJ7_mKAQpNg z3HIvVGl81cLQ31-M2r>VLNjJUl}jPUCah<}>{J;4lgM=%e|7lTS;6%vO;)>+D25|# ze2FQhk&Cew^1Jc$q&C5znq=CL+1;o4q?$+*IFoLzDyUir&IVboF&3}yy1wz1s0L;u zE0_{m7vrIlmM=UX74?FcCS!S(DaF_V{_GyU>3>#2s(x8y+Foc`YK ztC#z``+Ix+W#e8wlQ=t$f3=AY&^8IZZ4#5%Ym<^1+?jM$d%PnrB+rQ{{%m+ob2o z3d=I~9};^JhvW%58Zlhs=#(A`4ogXIJmOHuhZyb#vVq3K{NG zHjyn^dxmjEQ2{-_zrwT@#yQ718spU99JLrbo$zU8{g|hL5t^Jlwv81>WwPYy!{1J^iQNx{e{pDqn<*fFU`*Ed3=;CX|+^rnL(c2}iclHq- I#}SF?U*!P%>;M1& literal 0 HcmV?d00001 diff --git a/game_functions.py b/game_functions.py index 29753bf..0c664ae 100644 --- a/game_functions.py +++ b/game_functions.py @@ -201,3 +201,38 @@ def update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets): # Look for aliens hitting the bottom of the screen. check_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets) +def get_number_aliens_x(ai_settings, alien_width): + """Determine the number of aliens that fit in a row.""" + available_space_x = ai_settings.screen_width - 2 * alien_width + number_aliens_x = int(available_space_x / (2 * alien_width)) + return number_aliens_x + +def get_number_rows(ai_settings, ship_height, alien_height): + """Determine the number of rows of aliens that fit on the screen.""" + 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, aliens, alien_number, row_number): + """Create an alien, and place it in the row.""" + 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, ship, aliens): + """Create a full fleet of aliens.""" + # Create an alien, and find number of aliens in a row. + 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) + + # Create the fleet of aliens. + for row_number in range(number_rows): + for alien_number in range(number_aliens_x): + create_alien(ai_settings, screen, aliens, alien_number, + row_number)