Pygame help

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
lifeyears
Level 1
Level 1
Posts: 3
Joined: Fri Mar 16, 2018 4:57 pm

Pygame help

Post by lifeyears » Mon May 28, 2018 11:05 pm

I'm trying to make a simple 2d adventure rpg tile game like the old version of Pokemon without the Pokemon and I am trying to make a camera follow affect so the camera can follow the player sprite up and down so the player just doesn’t walk off the screen but I'm having a really hard time trying to figure this out. So if any of you lovely people are pygame experts please help. and the script isn't mine I'm just messing with it so I don't mess with my original scrip.

code down below and images will be added as attachments:

Code: Select all

import pygame, sys
from pygame.locals import *

pygame.init()

size = width, height = 400,320
screen = pygame.display.set_mode(size)
r = 0
bif = pygame.image.load("map5.png")
pygame.display.set_caption("test1")
#x,y=0,0
x = 0
y = 0
#get_width = 0
#get_heighth = 0
camerax = 0
cameray = 0
movex, movey = 0,0
charecter = "221.png"
player = pygame.image.load(charecter).convert_alpha()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    movex = -5
                elif event.key == pygame.K_d:
                    movex = 5
                elif event.key == pygame.K_w:
                    movey = -5
                elif event.key == pygame.K_s:
                    movey = 5

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_a or event.key == pygame.K_d or event.key == pygame.K_w or event.key == pygame.K_s:
                movex = 0
                #movey = 0

        if x > width /4 *3:
            camerax += 2.6
        
        if y > height /4 *3:
            cameray = 1.9

        x+=movex
        y+=movey

        screen.fill((r,0,0))
        screen.blit(bif,(0 -camerax,0 -cameray))
        screen.blit(player,(x -camerax,y -cameray))
        pygame.display.flip()
Thanks.
Attachments
map5.png
221.png
221.png (6.45 KiB) Viewed 117 times

Post Reply

Return to “Other topics”