-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyPress.py
More file actions
51 lines (48 loc) · 1.1 KB
/
keyPress.py
File metadata and controls
51 lines (48 loc) · 1.1 KB
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
45
46
47
48
49
50
51
import pygame
import time
wi=640
he=480
#wi=int(input("Enter width of screen:"))
#he=int(input("Enter height of the screen:"))
pygame.init()
win = pygame.display.set_mode((wi,he))
j=True
jcount=10
pygame.display.set_caption("HI")
x=50
y=50
width=50
height=60
neg=1
vel=15
run=True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type==pygame.QUIT:
run=False
k=pygame.key.get_pressed()
if k[pygame.K_LEFT] and x>vel:
x=x-vel
if k[pygame.K_RIGHT] and x<wi-width-vel:
x=x+vel
if not(j):
if k[pygame.K_UP] and y>vel:
y=y-vel
if k[pygame.K_DOWN]and he-height-vel:
y=y+vel
if k[pygame.K_SPACE]:
j=True
else:
if jcount>=-10:
if jcount<0:
neg=-1
y-=(jcount*4)*neg
jcount=jcount-1
else:
j=False
jcount=10
win.fill((0,0,0))
pygame.draw.rect(win,(255,0,0),(int(x),int(y),width,height))
pygame.display.update()
pygame.quit()