Untitled
unknown
plain_text
10 months ago
1.5 kB
2
Indexable
Never
import pygame, sys clock = pygame.time.Clock() from pygame.locals import * pygame.init() # initiates pygame pygame.display.set_caption("First Game ") WINDOW_SIZE = (400,400) screen = pygame.display.set_mode(WINDOW_SIZE,0,32) #Initiates window player_image = pygame.image.load("player.png") moving_right = False moving_left = False player_location = [50,50] player_y_momentum = 0 while True: #game loop screen.fill((0,255,0)) screen.blit(player_image,player_location) if player_location[1] > WINDOW_SIZE[1]-player_image.get_height(): #IF A PLAYER LOCATION IS MORE THAN THE WINDOW SIZE Y VALUE MINUS THE PLAYER HEIGHT (BASICALLY BOTTOM OF IMAGE) player_y_momentum = -player_y_momentum else: player_y_momentum += 0.2 player_location[1] += player_y_momentum if moving_right == True: player_location[0] += 4 if moving_left == True: player_location[0] -= 4 for event in pygame.event.get(): if event.type == QUIT: sys.exit() if event.type == KEYDOWN: if event.key == K_RIGHT: moving_right = True if event.key == K_LEFT: moving_left = True if event.type == KEYUP: if event.key == K_RIGHT: moving_right = False if event.key == K_LEFT: moving_left= False pygame.display.update() clock.tick(60)
Leave a Comment