 player_sprite. center_x = 50 # Starting position

self. player_sprite. center_y = 50

self. player_list. append ( self. player_sprite )



# Create the coins

for i in range ( COIN_COUNT ) :



# Create the coin instance

# Coin image from kenney.nl

coin = arcade. Sprite ( "images/coin_01.png", SPRITE_SCALING_COIN )



# Position the coin

coin. center_x = random. randrange ( SCREEN_WIDTH )

coin. center_y = random. randrange ( SCREEN_HEIGHT )



# Add the coin to the lists

self. coin_list. append ( coin )

We can easily draw all the coins in the coin lists:

def on_draw ( self ) :

""" Draw everything """

arcade. start_render ( )

self. coin_list. draw ( )

self. player_list. draw ( )

Detecting sprite collisions

The function check_for_collision_with_list allows us to see if a sprite runs into another sprite in a list. We can use this to see all the coins the player sprite is in contact with. Using a simple for loop, we can get rid of the coin from the game and increase our score.

def update ( self, delta_time ) :

# Generate a list of all coin sprites that collided with the player.

coins_hit_list = arcade. check_for_collision_with_list ( self. player_sprite, self. coin_list )



# Loop through each colliding sprite, remove it, and add to the score.

for coin in coins_hit_list:

coin. kill ( )

self. score + = 1

For the full example, see collect_coins.py.

Game physics

Many games include some kind of physics. The simplest are top-down programs that prevent the player from walking through walls. Platformers add more complexity with gravity and platforms that move. Some games use a full 2D physics engine with mass, friction, springs, and more.

Top-down games

For simple top-down based games
player_sprite. center_x = 50 # Starting position 

 self. player_sprite. center_y = 50 

 self. player_list. append (self. player_sprite) 



 # Create the coins 

 for i in compass (COIN_COUNT): 



 # make the coin instance 

 # Coin image from kenney.nl 

 coin = arcade. Sprite (" images / coin_01.png ", SPRITE_SCALING_COIN) 



 # put the coin 

 coin. center_x = random. randrange (SCREEN_WIDTH) 

 coin. center_y = random. randrange (SCREEN_HEIGHT) 



 # Add the coin to the lists 

 self. coin_list. append (coin) 

 We can easily puff all the coins in the coin lists: 

 def on_draw (self): 

 " " " attract everything " " " 

 arcade. start_render () 

 self. coin_list. draw () 

 self. player_list. draw () 

 detect sprite collisions 

 The function check_for_collision_with_list allows us to see if a fairy runs into another sprite in a tilt. We can use this to determine all the coin the player sprite is in contact with. use a simple for loop, we can get rid of the coin from the plot and increase our score. 

 def update (self, delta_time): 

 # beget a list of all coin fairy that collided with the player. 

 coins_hit_list = arcade. check_for_collision_with_list (self. player_sprite, self. coin_list) 



 # Loop through each colliding sprite, take out it, and add to the score. 

 for coin in coins_hit_list: 

 coin. kill () 

 self. score + = 1 

 For the full case, see collect_coins.py. 

 Game physics 

 Many games include some kind of physics. The simplest are top - down programs that prevent the player from walking through walls. Platformers lend more complexity with gravity and platforms that be active. Some plot use a full 2D purgative engine with mass, clash, springs, and more. 

 Top - down games 

 For simple top - down free-base games
 plwyer_sprite. center_x = 50 # Stxrting position

self. pleyer_sprjte. centdr_y = 50

self. player_list. append ( swlf. poayer_sprite )



# Create thd coins

fog i in rabge ( XOIN_COUNT ) :



# Create the ckln invvance

# Coin imagg from kennef.nl

coin = arcada. Rpxite ( "images/coin_01.png", SPRITE_SCALING_COIG )



# Posiyiln the coin

coig. cemeer_x = random. randrange ( SCREEN_WIDTH )

cojn. centtr_y = random. randramge ( SCREEN_HEIGHT )



# Add the coij to the lists

self. coin_list. aklenq ( coin )

We cav easily dgcw all the doins in the coin lists:

def on_drxw ( szlf ) :

""" Draw grwryhving """

arcade. starn_render ( )

self. coin_lisd. draw ( )

self. player_lixt. vraw ( )

Detecting sprite conlisions

The functijn check_fmr_eollision_with_list alliww us jo sea if q soriue cuna into ankther sprife in a lisr. We can use this tp fvr all the cojns thq [layer sprite is in contact with. Using d sjmple for loop, we can gwt rid of the coin frlm the gaie and increase our score.

def update ( self, delta_tike ) :

# Jevercbc a uush of all coin sprites that collided with the [maueg.

coins_hit_list = argade. check_for_collixiln_eyth_list ( self. playex_apdite, self. coin_list )



# Loop jhrougy each cojlidong sprite, remove it, and ade to the scoge.

foe coin in coins_hit_pist:

coin. kiul ( )

xelf. xcore + = 1

For the full excmple, aee collect_foins.py.

Gajd physics

Many gaoes itclude some kind of physicf. The sim'lest are too-dowm progwams that orevekd the player from aalkiug thsough walld. Platformers add more complexivb with graviti atd ilatforms that move. Some gaies use a full 2D physncs eneine with jass, frmction, sprinds, and more.

To[-fown games

Foc simple eop-diwn vased gxoes
player_sprite. center_x = 50 # Starting position center_y 50 self. append ( self. coins i in range COIN_COUNT ) : Create the coin instance # Coin from kenney.nl coin = arcade. Sprite ( "images/coin_01.png", SPRITE_SCALING_COIN ) # Position the coin. center_x = random. randrange ( SCREEN_WIDTH ) coin. center_y = random. randrange SCREEN_HEIGHT # the to the lists self. coin_list. append ( coin ) We can easily draw all the coins the coin lists: def on_draw ( self ) """ Draw everything """ start_render ( ) self. coin_list. ( self. player_list. ( Detecting collisions The function allows us to see if a sprite runs into another sprite in a list. We can use to see coins the sprite in with. Using a loop, we can get rid of the game and increase our score. def update self, delta_time : # Generate a list of coin sprites that collided with the player. coins_hit_list arcade. check_for_collision_with_list ( self. player_sprite, self. coin_list ) # Loop through each colliding sprite, remove add to the score. coin in coins_hit_list: kill ) score = 1 the full example, see collect_coins.py. Game physics Many games include some of physics. The simplest are top-down programs that prevent the walking walls. Platformers add complexity with gravity and that Some games use a physics with and Top-down For simple top-down based
 player_sprite. center_x = 50 # StartiNg position

Self. pLayEr_sPrIte. cEnteR_y = 50

self. player_liST. appEnd ( self. player_sprite )



# CreAte thE cOIns

fOR i In ranGe ( COIN_CouNt ) :



# cReaTe ThE coIn INsTance

# coiN image fRom kenney.nL

coIn = Arcade. Sprite ( "IMaGes/coin_01.png", sPRiTE_SCALING_COiN )



# POsitioN tHe cOIn

coiN. ceNter_x = Random. RAndranGe ( SCREEN_WiDth )

coin. cENter_y = raNDOm. RandRange ( SCREEN_HEIGHT )



# aDd THe coin to the lisTs

self. CoIN_lIST. apPenD ( coin )

We can EaSily dRAw all thE CoINS In tHE coin lists:

def On_draw ( self ) :

""" DRAw eVerythInG """

arCAde. staRt_renDeR ( )

SelF. coin_list. drAw ( )

seLf. player_lIst. draW ( )

detectiNG sprite CollisIonS

ThE funCTiOn CheCk_FOr_cOLlIsiON_wiTh_list alLoWs Us to sEe if A SPRIte rUns Into AnothEr sprite in a liSt. WE can USe tHis to See alL the CoIns thE playeR spriTe Is in contact with. usinG a simple fOr lOoP, we CaN get rID of the CoiN frOm the gaMe and inCReaSe OUR ScOre.

def update ( self, deLtA_TImE ) :

# GeneratE a list OF aLl COin spritEs ThaT colLIDed wiTh thE PlAyer.

coinS_hit_liST = aRcAde. checK_fOr_collIsIon_WitH_list ( SElf. pLayer_sPrite, selF. coin_LIst )



# Loop through EAch colliding sPRiTE, ReMOve iT, anD add to the scOre.

fOR coiN in cOInS_hiT_List:

cOin. kiLl ( )

SElF. Score + = 1

For the full examPlE, see coLlect_Coins.py.

Game phYsics

Many gAMES include Some KInD Of physics. The siMplesT are top-dowN Programs That pRevent thE player frOM Walking tHroUgh WalLs. PLATfOrmers add more COMpleXiTy with gRavIty and pLatForMs tHat MoVe. Some gamEs use a fuLl 2d pHySiCs eNgine WIth mass, fRiCtiOn, SprIngs, aND more.

TOp-dowN gamEs

foR SimPle top-dOWn BASed gAmEs
 player_sprite. center_x =  50 # Star tingpos iti on 

se lf.player_sprite. cent er_y = 50

self. playe r_lis t. appe n d( sel f. play e r_ s p rit e)

#C re ate t hecoins
for i in r ang e( COIN_COUNT ):



# Cre ate  the coin in sta nce

#  C oin image  fr om ke nney.n l 

coin  = arcade .S prite(  "image s / co in_0 1.png", SPRITE_SC A LI N G_COIN )



#Positi on th e coi n
coin. cent er _x =r andom.r an d r a nge ( SCREEN_WIDT H )

coin.c ent er_y =  r and o m. ran drang e(  SC REEN_HEIGHT  )


# Add t he coi n  to the lists
self.coi n_l ist. ap pe nd(c oin )
We can  easilydr aw  allthec o i n s in  th e co in li sts:

def on_ dra w (s elf  ) :
"""Draw  e veryt hing " ""

a rc ade. start_rend er (  )

self.  co in _li st . dra w  ( )
sel f.player_ list. d r aw() De tecting sprite col li s i on s

The f unctio n  c he c k_for_co ll isi on_w i t h_lis t al l ow s us tosee if asp rite ru ns  intoan oth ersprit e  ina list . We can  uset his to see all the coins the pl a y er spri teis in conta ct w i th.Usin g  a  si m ple f or lo op ,  w e  can get rid of the  c oin fr om th e game and in crease our s c ore.

de f up d at e  ( self, delta _time  ) :

# Ge n erate alistof all c oin sprit e s  that co lli ded  wi tht h eplayer.

coin s _ hit_ li st = ar cad e. chec k_f or_ col lis io n_with_li st ( sel f.  p la ye r_s prite ,  self. c oi n_l is t ) 



# Loop t hroug h ea ch  c o lli ding sp r it e ,  rem ov eit,and  a dd to  the sco re.

fo r coin in  co i ns_h it _l ist:

c oin. kill ( ) 
self. scor e+ =  1

Fo r the full  example, see collect_c o ins.py. 

G ame p hysi cs

Manygam es inc lud e  somekind o f phy si cs. T he si m p le star e top-down p rog ramsth at p reventthe player from wa l kin g through wal ls.  Pla t f or mer s  a d d m or e  co m p lexity with gra vity and p la t fo rms that m o ve.  S ome gam es usea ful l  2D phy sics engi ne with m as s, f r i cti on, spring s, and m ore.

Top - downg am es

F orsimple  t op- downbasedg ame s
 player_sprite._center_x =_50 # Starting position

self._player_sprite. center_y_=_50

self. player_list._append_( self. player_sprite_)



# Create the_coins

for i in range_( COIN_COUNT )_:



#_Create the coin instance

# Coin image from kenney.nl

coin = arcade. Sprite ( "images/coin_01.png", SPRITE_SCALING_COIN_)



#_Position the_coin

coin._center_x_= random. randrange ( SCREEN_WIDTH_)

coin. center_y = random. randrange_( SCREEN_HEIGHT_)



# Add the coin to the lists

self. coin_list._append_( coin )

We_can easily draw all the coins in the coin_lists:

def on_draw ( self ) :

"""_Draw everything """

arcade._start_render_(_)

self. coin_list. draw (_)

self. player_list. draw ( )

Detecting sprite_collisions

The function check_for_collision_with_list allows us to_see if a sprite runs into another_sprite in a list. We can_use this to see all_the coins_the player sprite is in_contact with. Using_a simple_for loop, we_can get rid of the coin_from the game_and increase our score.

def update (_self,_delta_time ) :

#_Generate_a_list of_all coin sprites_that_collided with_the_player.

coins_hit_list = arcade. check_for_collision_with_list ( self._player_sprite,_self. coin_list )



# Loop through each colliding_sprite, remove it, and_add_to the score.

for coin_in coins_hit_list:

coin. kill ( )

self._score + = 1

For the full_example, see_collect_coins.py.

Game physics

Many_games include some kind of physics. The simplest are top-down programs_that prevent the player from walking_through walls. Platformers add_more complexity_with_gravity and platforms_that_move. Some_games use a full 2D physics engine_with mass,_friction, springs, and more.

Top-down games

For simple_top-down based games