#!/usr/bin/python
import pygame
import libsww
window = ""
def init_window():
global window, s
pygame.init()
window = pygame.display.set_mode((640, 800))
pygame.display.set_caption("Sinbot Worlds War")
bitmap = pygame.image.load("./data/fons/one.bmp").convert()
window.blit(bitmap, (0, 0))
pygame.key.set_repeat(2, 50)
#pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
s = libsww.Model(window, 0, 0, "hear")
pygame.display.update()
s.show()
def main():
global window, s
init_window()
x = 0
y = 0
while True:
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit(0)
elif i.type == pygame.KEYDOWN and i.key == pygame.K_LEFT:
s.set(s.x - 10, s.y)
s.show()
elif i.type == pygame.KEYDOWN and i.key == pygame.K_RIGHT:
s.set(s.x + 10, s.y)
s.show()
elif i.type == pygame.KEYDOWN and i.key == pygame.K_UP:
s.set(s.x, s.y - 10)
s.show()
elif i.type == pygame.KEYDOWN and i.key == pygame.K_DOWN:
s.set(s.x, s.y + 10)
s.show()
pygame.display.update()
if __name__ == '__main__':
main()
#!/usr/bin/python
import pygame
# Graphic
class Model:
def __init__(self, wind, xpos, ypos, name):
self.x = xpos
self.y = ypos
self.window = wind
self.bitmap = pygame.image.load("./data/models/" + name + ".swwm").convert()
self.bitmap.set_colorkey((255, 255, 255))
def set(self, xpos, ypos):
self.x = xpos
self.y = ypos
#def moveUP(self):
# def moveLEFT(self):
#def moveDOWN(self):
#def moveRIGHT(self):
def show(self):
pygame.display.flip()
self.window.blit(self.bitmap, (self.x, self.y), None, pygame.BLEND_MIN)
# Phisic
def Intersect():
if (s1_x > s2_x - 32) and (s1_x < s2_x + 32) and (s1_y > s2_y - 32) and (s1_y < s2_y + 32):
return True
else:
return False
когда нажимаешь кнопки, объект двигается, но оставляет за собой след:

И ещё вопрос: можно ли в pygame сделать поле для ввода текста?
И ещё один: как стереть нарисованную линию?