I have this code:
import pygame
from car import Car
import random
import os
Blue = (0, 28 , 234)
White = (255, 255 ,255)
Grey = (130, 130 ,131)
Black = (0, 0, 0)
Green =(50, 205, 50)
pygame.init()
screenwidth = 1100
screenheight = 700
size = (screenwidth, screenheight)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Dragos e boss")
enemyCar = pygame.image.load("enemycar.png").convert()
all_sprites_list = pygame.sprite.Group()
playerCar = Car(Blue , 40, 50)
playerCar.rect.x = 500
playerCar.rect.y = 400
all_sprites_list.add(playerCar)
carryOn = True
clock = pygame.time.Clock()
while carryOn:
for event in pygame.event.get():
if event.type == pygame.QUIT:
carryOn = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_x: #if you press x the g ame closes
carryOn = False
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
playerCar.moveLeft(5)
if keys[pygame.K_d]:
playerCar.moveRight(5)
if keys[pygame.K_w]:
playerCar.moveUp(4)
if keys[pygame.K_s]:
playerCar.moveDown(4)
if keys[pygame.K_z]:
playerCar.moveUp(10)
if keys[pygame.K_SPACE]:
playerCar.moveDown(7)
all_sprites_list.update()
screen.fill(Black)
pygame.draw.rect(screen ,Grey, (400, 0, 300,800))
pygame.draw.line(screen, White, (550,0), (550,800), 20)
all_sprites_list.draw(screen)
pygame.display.flip()
clock.tick(60)
pygame.quit()
I have a car that i can move, but it goes of the screen.
How can I make the “camera”, the view to go up with the car? Like I want to go upper in the window, with the car and be able to view it, some help to it please?