-
Notifications
You must be signed in to change notification settings - Fork 1
/
keymove2.py
executable file
·44 lines (38 loc) · 1.25 KB
/
keymove2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path
import pygame
from pygame.locals import *
class keyMove1:
def __init__(self):
self.SCR = { 'W' : 200, 'H' : 100 }
self.main()
def main(self):
pygame.init()
screen = pygame.display.set_mode((self.SCR['W'], self.SCR['H']))
pygame.display.set_caption('Hello pygame')
image = pygame.image.load( \
os.path.join(os.path.dirname(__file__), 'img/char.bmp'))
image = image.convert()
imagerect = image.get_rect()
clock = pygame.time.Clock()
while True:
clock.tick(60) # keep the 60 fps
screen.blit(image, imagerect)
pygame.display.flip()
for event in pygame.event.get():
if event.type == QUIT:
return
elif (event.type == KEYDOWN and event.key == K_ESCAPE):
return
else:
pass
keyin = pygame.key.get_pressed()
if keyin[K_RIGHT]:
imagerect.move_ip(1, 0)
elif keyin[K_LEFT]:
imagerect.move_ip(-1, 0)
else:
pass
if __name__ == '__main__':
main = keyMove1()