Write simple games, learn programming languages-python, programming languages-python

Source: Internet
Author: User

Write simple games, learn programming languages-python, programming languages-python

Well, first of all, I have to admit that this question is exaggerated. I am a newbie, and I also know the concept of game-related programming. However, I am more interested in game development. I believe most people like to play games because it brings a lot of fun to people, and programming language learning is at least boring for me, so when I learn a new language, I usually find something small to practice to increase the motivation for learning. Today, I saw a book that is really worth recommending. I introduced python beginners and pygame's good foreign books. The portal is here: http://cs.simpson.edu/files/cs_intro_book.htm.

This introductory book is recommended because it is repeatedly interspersed with the basic python syntax and pygame example learning, I think the organizational form of this article is indeed easier to accept than the general introductory books (For Me, I read 1/3 for an hour without knowing it ). Playing the simplest game is not only familiar with python syntax, but also learning simple graphics in game programming. It is helpful for the basic understanding of game development. Some may ask if it is necessary to introduce the new pygame framework to become familiar with it for a long time. In fact, it is not necessary because the framework is simple and easy to understand, you only need to check several common interface functions and methods to easily write a simple game demo. Of course, if you have other game engine knowledge, let alone. In fact, this book is mainly suitable for beginners of python learning. Through interesting examples, I not only learned python syntax but also trained the implementation of game logic and basic knowledge of graphic development, on this basis, you can also improve the example to enrich the game content. Here is a simple example. The example of the simplest animation entry in a modembook (snowflake falling) is as follows:


1 import pygame
 2 pygame.init ()
 3 width, height = 640, 640
 4 green = [0,255,0]
 5 import random
 6 screen = pygame.display.set_mode ((width, height))
 7 done = False
 8 pos_x = 20
 9 start_list = []
10 clock = pygame.time.Clock ()
11 for i in range (50):
12 x = random.randrange (0,640)
13 y = random.randrange (0,640)
14 start_list.append ([x, y])
15 while done == False:
16 screen.fill ([0,0,0])
17 for event in pygame.event.get ():
18 # check if the event is the X button
19 if event.type == pygame.QUIT:
20 # if it is quit the game
21 done = True
22 for i in range (len (start_list)):
23 pygame.draw.circle (screen, green, start_list [i], 2)
24 start_list [i] [1] + = 1
25 if start_list [i] [1]> 640:
26 y = random.randrange (-50, -10)
27 start_list [i] [1] = y
28 x = random.randrange (0,640)
29 start_list [i] [0] = x
30 clock.tick (20)
31 pygame.display.flip ()
32 pos_x + = 10
33 if pos_x is 180:
34 pos_x = 20
35 pygame.quit ()
36 exit (0) 

Here I use green to draw a circular genie. It seems that not the snowflake falls. It should be changed to the leaf shape and the green leaves fall .. Haha .. :)

Code writing is not technical, but I think the inspiration from this book is quite useful. Learning new languages and implementing what you like are the pleasure of programming, this is my original intention to record the article. The document is rough. Come on!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.