bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
"""pygame.examples.moveit
|
||||
""" pygame.examples.moveit
|
||||
|
||||
This is the full and final example from the Pygame Tutorial,
|
||||
"How Do I Make It Move". It creates 10 objects and animates
|
||||
@@ -11,10 +11,8 @@ Note it's a bit scant on error checking, but it's easy to read. :]
|
||||
Fortunately, this is python, and we needn't wrestle with a pile of
|
||||
error codes.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import pygame
|
||||
import pygame as pg
|
||||
|
||||
main_dir = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
@@ -58,23 +56,23 @@ class GameObject:
|
||||
# quick function to load an image
|
||||
def load_image(name):
|
||||
path = os.path.join(main_dir, "data", name)
|
||||
return pygame.image.load(path).convert()
|
||||
return pg.image.load(path).convert()
|
||||
|
||||
|
||||
# here's the full code
|
||||
def main():
|
||||
pygame.init()
|
||||
clock = pygame.Clock()
|
||||
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
pg.init()
|
||||
clock = pg.time.Clock()
|
||||
screen = pg.display.set_mode((WIDTH, HEIGHT))
|
||||
|
||||
player = load_image("player1.gif")
|
||||
entity = load_image("alien1.gif")
|
||||
background = load_image("liquid.webp")
|
||||
background = load_image("liquid.bmp")
|
||||
|
||||
# scale the background image so that it fills the window and
|
||||
# successfully overwrites the old sprite position.
|
||||
background = pygame.transform.scale2x(background)
|
||||
background = pygame.transform.scale2x(background)
|
||||
background = pg.transform.scale2x(background)
|
||||
background = pg.transform.scale2x(background)
|
||||
|
||||
screen.blit(background, (0, 0))
|
||||
|
||||
@@ -84,26 +82,26 @@ def main():
|
||||
o = GameObject(entity, x * 40, x)
|
||||
objects.append(o)
|
||||
|
||||
pygame.display.set_caption("Move It!")
|
||||
pg.display.set_caption("Move It!")
|
||||
|
||||
# This is a simple event handler that enables player input.
|
||||
while True:
|
||||
# Get all keys currently pressed, and move when an arrow key is held.
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_UP]:
|
||||
keys = pg.key.get_pressed()
|
||||
if keys[pg.K_UP]:
|
||||
p.move(up=True)
|
||||
if keys[pygame.K_DOWN]:
|
||||
if keys[pg.K_DOWN]:
|
||||
p.move(down=True)
|
||||
if keys[pygame.K_LEFT]:
|
||||
if keys[pg.K_LEFT]:
|
||||
p.move(left=True)
|
||||
if keys[pygame.K_RIGHT]:
|
||||
if keys[pg.K_RIGHT]:
|
||||
p.move(right=True)
|
||||
|
||||
# Draw the background
|
||||
screen.blit(background, (0, 0))
|
||||
for e in pygame.event.get():
|
||||
for e in pg.event.get():
|
||||
# quit upon screen exit
|
||||
if e.type == pygame.QUIT:
|
||||
if e.type == pg.QUIT:
|
||||
return
|
||||
for o in objects:
|
||||
screen.blit(background, o.pos, o.pos)
|
||||
@@ -111,10 +109,11 @@ def main():
|
||||
o.move(right=True)
|
||||
screen.blit(o.image, o.pos)
|
||||
screen.blit(p.image, p.pos)
|
||||
pygame.display.update()
|
||||
clock.tick(60)
|
||||
pg.display.update()
|
||||
pg.time.delay(100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
pygame.quit()
|
||||
pg.quit()
|
||||
Reference in new issue
Block a user