Skip to content

Commit 82ef2b5

Browse files
committed
How to animate the object - Python #PyGame Lesson 1
How to animate the object - Python #PyGame Lesson 1
1 parent 6a681b4 commit 82ef2b5

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/python____project.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python PyGame/main.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import pygame
2+
pygame.init()
3+
window = pygame.display.set_mode((500,500))
4+
pygame.display.set_caption("Turtle Code")
5+
6+
x = 50
7+
y = 50
8+
width = 40
9+
height = 60
10+
mov = 5
11+
12+
isJump = False
13+
jumpCount = 10
14+
15+
run = True
16+
17+
while run:
18+
pygame.time.delay(100)
19+
20+
for event in pygame.event.get():
21+
if event.type == pygame.QUIT:
22+
run = False
23+
24+
keys = pygame.key.get_pressed()
25+
26+
if keys[pygame.K_LEFT] and x > mov:
27+
x -= mov
28+
if keys[pygame.K_RIGHT] and x < 500 - mov - width:
29+
x +=mov
30+
31+
if not(isJump):
32+
if keys[pygame.K_UP] and y > mov:
33+
y -= mov
34+
if keys[pygame.K_DOWN] and y < 500 - height - mov:
35+
y += mov
36+
if keys[pygame.K_SPACE]:
37+
isJump = True
38+
39+
else:
40+
if jumpCount >= -10:
41+
y -= (jumpCount * abs(jumpCount)) * 0.5
42+
jumpCount -= 1
43+
else:
44+
jumpCount = 10
45+
isJump = False
46+
47+
window.fill((0,0,0))
48+
49+
pygame.draw.rect(window, (0,255,0), (x,y,width,height))
50+
pygame.display.update()
51+
52+
pygame.quit()

0 commit comments

Comments
 (0)