Python game exercise 2

Source: Internet
Author: User
#! /Usr/bin/ENV python2.7 #-*-coding: UTF-8-*-# file: pg2.py # Date: 2013-6-30 # Author: wangyuimport pygamefrom pygame. locals import * From sys import exitpygame. init () screen_size = (640,480) screen = pygame. display. set_mode (screen_size, 0, 32) font = pygame. font. sysfont ("Arial", 16); # The first parameter is the font, And the last parameter is the size print fontfont_height = font. get_linesize () print font_heightevent_text = [] While true: event = pygame. event. wait () # event wait event_text.append (STR (event) # obtain the time name print event_text # test event_text = event_text [-screen_size [1]/font_height:] print event_text # This slicing operation ensures that only one screen text if event is retained in event_text. type = quit: exit () screen. fill (255,255, 0) y = screen_size [1]-font_height # find a suitable starting position and start from the bottom to retain the blank for text in reversed (event_text) Row): screen. BITs (font. render (text, true, (0, 0), (0, y) Y-= font_height # obtain the coordinates of pygame. display. update ()

These code actions are constantly updated when you move the mouse.

The two prints are the output coordinates in the command line. below is

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.