## I'm always looking for examples, so if I can provide one that I had a hard time
## finding , I will. Remember to put your own images in. mine only work for me.
## diagonal bounce from chapter 5, Beggining Game Development with Pygame,
## python: Will McGugan
background_image = ("UnicornPoop/CRSwall.jpg")
sprite_image_Right = ("UnicornPoop/brushRight.png") #your images here ###################("filename/imagename.png") or just('filename.ext')
sprite_image_Left = ("UnicornPoop/brushLeft.png")
import pygame
from pygame.locals import*
from sys import exit
from vectorMagnitude import Vector2
pygame.init()
screen = pygame.display.set_mode((600, 800), 0, 32)
background= pygame.image.load(background_image).convert()
sprite = pygame.image.load(sprite_image_Right)
sprite_left = pygame.image.load(sprite_image_Left)
clock = pygame.time.Clock()
x, y = 100., 100.
speed_x, speed_y = 133., 170.
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
screen.blit(background, (-5, -5))
screen.blit(sprite, (x, y))
time_passed = clock.tick(30)
time_passed_seconds = time_passed / 1000.
x += speed_x * time_passed_seconds
y += speed_y * time_passed_seconds
if x > 600 - sprite.get_width():
speed_x = -speed_x
x = 600 - sprite.get_width()
elif x < 0:
speed_x = -speed_x
x = 0
if y > 800 - sprite.get_height():
speed_y = -speed_y
y = 800 - sprite.get_height()
elif y < 0:
speed_y = -speed_y
y = 0
pygame.display.update()
## finding , I will. Remember to put your own images in. mine only work for me.
## diagonal bounce from chapter 5, Beggining Game Development with Pygame,
## python: Will McGugan
background_image = ("UnicornPoop/CRSwall.jpg")
sprite_image_Right = ("UnicornPoop/brushRight.png") #your images here ###################("filename/imagename.png") or just('filename.ext')
sprite_image_Left = ("UnicornPoop/brushLeft.png")
import pygame
from pygame.locals import*
from sys import exit
from vectorMagnitude import Vector2
pygame.init()
screen = pygame.display.set_mode((600, 800), 0, 32)
background= pygame.image.load(background_image).convert()
sprite = pygame.image.load(sprite_image_Right)
sprite_left = pygame.image.load(sprite_image_Left)
clock = pygame.time.Clock()
x, y = 100., 100.
speed_x, speed_y = 133., 170.
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
screen.blit(background, (-5, -5))
screen.blit(sprite, (x, y))
time_passed = clock.tick(30)
time_passed_seconds = time_passed / 1000.
x += speed_x * time_passed_seconds
y += speed_y * time_passed_seconds
if x > 600 - sprite.get_width():
speed_x = -speed_x
x = 600 - sprite.get_width()
elif x < 0:
speed_x = -speed_x
x = 0
if y > 800 - sprite.get_height():
speed_y = -speed_y
y = 800 - sprite.get_height()
elif y < 0:
speed_y = -speed_y
y = 0
pygame.display.update()
No comments:
Post a Comment