zoukankan      html  css  js  c++  java
  • 游戏

    #http://blog.jobbole.com/46308/
    import pygame
    import math
    from pygame.locals import *
    
    # initialize the game
    
    pygame.init()
    
    width,height = 640,480
    screen = pygame.display.set_mode((width,height))
    
    mybackcolor = 0,0,0
    keys = [False, False, False, False]
    playerpos=[100,100]
    acc = [0,0]
    arrows = []
    # load images
    
    player = pygame.image.load("resources/images/dude.png")
    grass = pygame.image.load("resources/images/grass.png")
    castle = pygame.image.load("resources/images/castle.png")
    arrow = pygame.image.load("resources/images/bullet.png")
    
    
    # keep looping through
    
    while 1:
        # clear the screen before drawing it again
        screen.fill(mybackcolor)
        #draw the screen elements
    
        for x in range(width/grass.get_width()+1):
            for y in range(height/grass.get_height()+1):
                screen.blit(grass, (x * 100, y * 100))
    
        screen.blit(castle,(0,30))
        screen.blit(castle,(0,135))
        screen.blit(castle, (0, 240))
        screen.blit(castle, (0, 345))
    
    
        position = pygame.mouse.get_pos()
        angle = math.atan2(position[1] - (playerpos[1]+32),position[0]-(playerpos[0]+26))
        playerrot = pygame.transform.rotate(player, 360 - angle * 57.29)
        playerpos1 = (playerpos[0] - playerrot.get_rect().width / 2, playerpos[1] - playerrot.get_rect().height / 2)
        #screen.blit(playerrot, playerpos1)
        screen.blit(playerrot, playerpos)
    
        if event.type == pygame.MOUSEBUTTONDOWN:
            position = pygame.mouse.get_pos()
            acc[1] += 1
            arrows.append([math.atan2(position[1] - (playerpos1[1] + 32), position[0] - (playerpos1[0] + 26)), playerpos1[0] + 32,playerpos1[1] + 32])
    
    
        # update the screen
        pygame.display.flip()
        # loop through the events
        for event in pygame.event.get():
            #check if the event is the x button
            if event.type == pygame.QUIT:
                #if it is quit the game
                pygame.quit()
                exit(0)
    
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                keys[0] = True
            elif event.key == pygame.K_a:
                keys[1] = True
            elif event.key == pygame.K_s:
                keys[2] = True
            elif event.key == pygame.K_d:
                keys[3] = True
    
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_w:
                keys[0] = False
            elif event.key == pygame.K_a:
                keys[1] = False
            elif event.key == pygame.K_s:
                keys[2] = False
            elif event.key == pygame.K_d:
                keys[3] = False
    
        # area limited
        # if keys[0]:
        #     if playerpos[1]>5 :
        #         playerpos[1] -= 5
        # elif keys[1]:
        #     if playerpos[1] > 5:
        #         playerpos[0] -= 5
        # elif keys[2]:
        #     if playerpos[0] < height:
        #         playerpos[1] += 5
        # elif keys[3]:
        #     if playerpos[1] < 
        #         playerpos[0] += 5
    
    
  • 相关阅读:
    【leetcode】1228.Missing Number In Arithmetic Progression
    【leetcode】1227. Airplane Seat Assignment Probability
    【leetcode】1224. Maximum Equal Frequency
    【leetcode】1222. Queens That Can Attack the King
    【leetcode】1221. Split a String in Balanced Strings
    【leetcode】1219. Path with Maximum Gold
    【leetcode】1220. Count Vowels Permutation
    【leetcode】1218. Longest Arithmetic Subsequence of Given Difference
    【leetcode】1217. Play with Chips
    2018.11.27 元器件选型(2)- 连接器
  • 原文地址:https://www.cnblogs.com/maskerk/p/7631833.html
Copyright © 2011-2022 走看看