Part 9: Add support for WASD keys too

WASD-arrows

How do we recognize the WASD keys? You are right! Just like any other event.


The only change in the code is to recognize the WASD key press.

Change the “if” condition to-

if(user_input[pygame.K_UP] or user_input[pygame.K_w]):
        Y=Y-1
        if(Y<0):Y=SCREENHEIGHT
    elif(user_input[pygame.K_DOWN] or user_input[pygame.K_s]):
        Y=Y+1
        if(Y>SCREENHEIGHT):Y=0
    elif(user_input[pygame.K_LEFT] or user_input[pygame.K_a]):
        X=X-1
        if(X<0):X=SCREENWIDTH
    elif(user_input[pygame.K_RIGHT] or user_input[pygame.K_d]):
        X=X+1
        if(X>SCREENWIDTH):X=0

 

Now on to some actual gaming! Games usually involve one object colliding with another and scoring points. Let us collide our circle with a square next and see what can be done! Whoa! We have reached so far and we are only a little away from creating a full fledged simple game.
Come on!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s