Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import *
- pygame.init()
- # some parameters
- screen_size = width, height = (480, 360)
- shift = 60
- origins = (0, 0)
- ghost_start_pos = (470, 0)
- # screen
- screen = pygame.display.set_mode(screen_size)
- pygame.display.set_caption('just trying')
- # images
- mario = pygame.image.load('NewRaccoonMario.png').convert_alpha()
- ghost = pygame.image.load('ghost.gif').convert()
- mario_rect = mario.get_rect()
- ghost_rect = ghost.get_rect()
- background = pygame.image.load('mario_scenario.jpg').convert()
- while 1:
- for event in pygame.event.get():
- if event.type == QUIT:
- exit()
- elif event.type == KEYDOWN:
- key = pygame.key.get_pressed()
- if key[K_ESCAPE]:
- exit()
- elif key[K_UP]:
- mario_rect.move_ip(0, -shift)
- elif key[K_DOWN]:
- mario_rect.move_ip(0, shift)
- elif key[K_RIGHT]:
- mario_rect.move_ip(shift, 0)
- elif key[K_LEFT]:
- mario_rect.move_ip(-shift, 0)
- ghost_rect.move_ip(-50, 0)
- if ghost_rect.left < 0:
- ghost_rect.move_ip(ghost_start_pos)
- if mario_rect.left < 0:
- mario_rect.move_ip(1, 0)
- elif mario_rect.right > width:
- mario_rect.move_ip(470, 0)
- elif mario_rect.top > height:
- mario_rect.move_ip(359, 0)
- elif mario_rect.bottom < 0:
- mario_rect.move_ip(0, 0)
- if mario_rect.colliderect(ghost_rect):
- pass
- screen.blit(background, origins)
- screen.blit(mario, mario_rect)
- screen.blit(ghost, ghost_rect)
- pygame.time.delay(50)
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment