Уведомления

Группа в Telegram: @pythonsu

#1 Дек. 19, 2014 14:55:35

Anna_tusur
Зарегистрирован: 2014-12-19
Сообщения: 9
Репутация: +  0  -
Профиль   Отправить e-mail  

ЕСТЬ КОД,НО ОН НЕ ЗАПУСКАЕТ В Pygame(что не так?)

# -*- coding: UTF-8 -*-
background_image_filename='pole.jpg'
message=“prog”

import pygame
from pygame.locals import *
from sys import exit
import time
import math
#import os

pygame.init()
screen=pygame.display.set_mode((640,480))
pygame.display.set_caption(message)
background=pygame.image.load(background_image_filename).convert()

class Bricks:
def __init__(self,xpos,ypos,filename):
self.x=xpos
self.y=ypos
self.bitmap=pygame.image.load(filename)
def render(self,angle):
self.ugol=pygame.transform.rotate(self.bitmap,angle)
screen.blit(self.ugol,(self.x,self.y))
stime()

x0=320
y0=240
brick=Bricks(x0,y0,'tank.png')

quit=0

def stime():
time.sleep(0.01)
pygame.display.update()


angle=0

while quit==0:
screen.blit(background,(0,0))

for event in pygame.event.get():
if event.type==QUIT:
exit()
if pygame.mouse.get_pressed():
x1,y1=pygame.mouse.get_pos()

if x1>x0:
a=x1-x0
elif x1<x0:
a=x0-x1
else:
a=x0

if y1>y0:
b=y1-y0
elif y1<y0:
b=y0-y1
else:
b=y0

c=math.hypot(a,b)
c=round(c,1)

rad=math.acos(a/c)
angle=math.degrees(rad)
#if x1>x0:
#angle=-angle
if x1>x0 and y1>y0:
angle=-90-angle
if x1<x0 and y1<y0:
angle=-270-angle
if x1>x0 and y1<y0:
angle=-90+angle
if x1<x0 and y1>y0:
angle=-270+angle

if x1==x0 and y1>y0:
angle=-180
if x1==x0 and y1<y0:
angle=0
if x1>x0 and y1==y0:
angle=-90
if x1<x0 and y1==y0:
angle=-270

z=1
#print x1, y1
#print angle
while c>=z:
dx=z*math.cos(rad)
dy=z*math.sin(rad)
if x1>x0:
brick.x=x0+dx
elif x1<x0:
brick.x=x0-dx
if y1>y0:
brick.y=y0+dy
elif y1<y0:
brick.y=y0-dy
z=z+1


screen.blit(background,(0,0))
brick.render(angle)

x0=brick.x
y0=brick.y
brick.render(angle)

Прикреплённый файлы:
attachment Снимок1.PNG (12,3 KБ)

Офлайн

#2 Дек. 19, 2014 14:56:08

Anna_tusur
Зарегистрирован: 2014-12-19
Сообщения: 9
Репутация: +  0  -
Профиль   Отправить e-mail  

ЕСТЬ КОД,НО ОН НЕ ЗАПУСКАЕТ В Pygame(что не так?)

pole.jpg и tank.png ещё нужно
но не знаю куда вставить и как

Офлайн

#3 Дек. 20, 2014 02:10:59

JOHN_16
От: Россия, Петропавловск-Камчатск
Зарегистрирован: 2010-03-22
Сообщения: 3292
Репутация: +  221  -
Профиль   Отправить e-mail  

ЕСТЬ КОД,НО ОН НЕ ЗАПУСКАЕТ В Pygame(что не так?)

никнейм Анна, виндовый юзер Елена, а перед монитором наверняка Александр?

возьмите (где то, возможно где брали код) два изображения pole.jpg и tank.png и положите рядом с файлом кодом программы.



_________________________________________________________________________________
полезный блог о python john16blog.blogspot.com

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version