Python Forum
[PyGame] I'm following a tutorial, i don't know what i'm doing wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] I'm following a tutorial, i don't know what i'm doing wrong
#1
Think Huh So I was following a tutorial right like any nooby does and I change the variable so I actually learn from it and not just suck and spit information out.Then I come upon this problem where my PYTHON IDE PYCHARM SAYS THERE ARE NO MAJOR MISTAKES BUT WHEN I PRESS THE INPUT BUTTONS I GAVE DIFFERENT OUTPUTS AND THEY WERE ALL THE SAME ILL GIVE YOU THE GUYS CHANNEL IM ON EPISODE 6 HERE IS THE LINK https://www.youtube.com/watch?v=AvV6UxuzH5c anD THIS IS MY CODE bY THE WAY IF YOU DONT HAVE PYGAME GO INSTALL IT FIRST IF YOU WANNA TRY THIS OUT. Big Grin BY THE WAY I INSTALLED PICTURES LIKE MARIO FOR MY GAME IT BASICALLY SPACE INVADERS THAT'S WHY THERE'S PNG'S INSIDE THERE



import pygame
# Making sure the pygame or whatever you installed works
pygame.init()

# making the default pygame screen appear
screen = pygame.display.set_mode((800, 600))

# Changing the color and icon of this game
pygame.display.set_caption("Mario Invaders(Space Invaders)")
icon = pygame.image.load('mario.png')
pygame.display.set_icon(icon)

# Player
player_IMG = pygame.image.load('mario paper.png')
playerX = 20
playerY = 230
playerY_position = 0

def player(x,y):
screen.blit(player_IMG, (x,y))


working = True
while working:
screen.fill((78, 134, 242))

player(playerX,playerY)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
working = False


if event.type ==pygame.KEYDOWN:
print("Hi")
if event.type == pygame.KEYUP:
print("hello")
if event.type == pygame.K_RIGHT:
print("good")
if event.type == pygame.K_LEFT:
print("SUP")
if event.key == pygame.KEYUP or event.key == pygame.KEYDOWN:
print("Heloo")
Reply
#2
Think Huh So I was following a tutorial right like any nooby does and I change the variable so I actually learn from it and not just suck and spit information out.Then I come upon this problem where my PYTHON IDE PYCHARM SAYS THERE ARE NO MAJOR MISTAKES BUT WHEN I PRESS THE INPUT BUTTONS I GAVE DIFFERENT OUTPUTS AND THEY WERE ALL THE SAME ILL GIVE YOU THE GUYS CHANNEL IM ON EPISODE 6 HERE IS THE LINK https://www.youtube.com/watch?v=AvV6UxuzH5c anD THIS IS MY CODE bY THE WAY IF YOU DONT HAVE PYGAME GO INSTALL IT FIRST IF YOU WANNA TRY THIS OUT. Big Grin BY THE WAY I INSTALLED PICTURES LIKE MARIO FOR MY GAME IT BASICALLY SPACE INVADERS THAT'S WHY THERE'S PNG'S INSIDE THERE


import pygame
# Making sure the  pygame or whatever you installed works
pygame.init()

# making the default pygame screen appear
screen = pygame.display.set_mode((800, 600))

# Changing the color and icon of this game
pygame.display.set_caption("Mario Invaders(Space Invaders)")
icon = pygame.image.load('mario.png')
pygame.display.set_icon(icon)

# Player
player_IMG = pygame.image.load('mario paper.png')
playerX = 20
playerY = 230
playerY_position = 0

def player(x,y):
    screen.blit(player_IMG, (x,y))


working = True
while working:
    screen.fill((78, 134, 242))

    player(playerX,playerY)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            working = False


    if event.type ==pygame.KEYDOWN:
     print("Hi")
     if event.type == pygame.KEYUP:
      print("hello")
      if event.type == pygame.K_RIGHT:
        print("good")
     if event.type == pygame.K_LEFT:
        print("SUP")
        if event.key == pygame.KEYUP or event.key == pygame.KEYDOWN:
             print("Heloo")
Reply
#3
Please post your code and errors given using the proper tags. Also please refrain from typing in caps.
"Often stumped... But never defeated."
Reply
#4
Please, don't use ALL CAPS, that's yelling
Please, uUse descriptive thread titles, that describe your problem
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Please, don't start new thread unnecessarily
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Ok I'll use coding tags next time I just started yesterday so I was unaware of how to do it thanks for telling me.

I am having trouble with a python script I am using for Pygame. So each time you pressed an arrow key a different output should appear in the output box like"Hello" or "Good day" but it only gives the same output"Hello" and"Heloo"I was considering if anybody could help me please understand that i have limited experience in coding in general.This is my script
import pygame
# Making sure the  pygame or whatever you installed works
pygame.init()

# making the default pygame screen appear
screen = pygame.display.set_mode((800, 600))

# Changing the color and icon of this game
pygame.display.set_caption("Mario Invaders(Space Invaders)")
icon = pygame.image.load('mario.png')
pygame.display.set_icon(icon)

# Player
player_IMG = pygame.image.load('mario paper.png')
playerX = 20
playerY = 230
playerY_position = 0

def player(x,y):
    screen.blit(player_IMG, (x,y))


working = True
while working:
    screen.fill((78, 134, 242))

    player(playerX,playerY)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            working = False

        #If arrow key is pressed give output
        if event.type == pygame.KEYDOWN:
            print("Hello")
        if event.type == pygame.KEYUP:
            print("Heloo")
        if event.type == pygame.K_RIGHT:
            print("Hi")
        if event.type == pygame.K_LEFT:
            print("Good day")
If you are wondering why there are .png files there is because of making a mario fan-based game Big Grin
Reply
#6
See in the following example that it is organized by type first (KEYDOWN, KEYUP). Specific keys aren't types.



  for event in pygame.event.get():
        # check if the event is the X button 
        if event.type == pygame.QUIT:
            # if it is quit the game
            pygame.quit() 
            exit(0) 
        if event.type == pygame.KEYDOWN:
            if event.key==K_UP:
                keys[0]=True
            elif event.key==K_LEFT:
                keys[1]=True
            elif event.key==K_DOWN:
                keys[2]=True
            elif event.key==K_RIGHT:
                keys[3]=True
 
        if event.type == pygame.KEYUP:
            if event.key==pygame.K_UP:
                keys[0]=False
            elif event.key==pygame.K_LEFT:
                keys[1]=False
            elif event.key==pygame.K_DOWN:
                keys[2]=False
            elif event.key==pygame.K_RIGHT:
                keys[3]=False
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020