Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:56:05+00:00 2026-05-30T12:56:05+00:00

I’m trying to make a game in pygame, but for some reason actor and

  • 0

I’m trying to make a game in pygame, but for some reason actor and inp has the same value.
I tried to have them as arrays instead of classes, but it didn’t solve the problem.

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,360),0,32)

a=pygame.image.load('a.png')

class xy:
    x=0
    y=0
    jump=0

actor=xy
inp=xy

def events():
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            return
        elif event.type == KEYDOWN:
            if event.key==K_LEFT:
                inp.x=-1
            elif event.key==K_RIGHT:
                inp.x=1
            elif event.key==K_UP:
                inp.y=-1
            elif event.key==K_DOWN:
                inp.y=1
            elif event.key==K_SPACE:
                inp.jump=True
        elif event.type==KEYUP:
            if event.key==K_LEFT:
                inp.x=0
            elif event.key==K_RIGHT:
                inp.x=0
            elif event.key==K_UP:
                inp.y=0
            elif event.key==K_DOWN:
                inp.y=0
            elif event.key==K_SPACE:
                inp.jump=False
    return

def controller():
    if inp.x<0:
        actor.x-=1
    elif inp.x>0:
        actor.x+=1
    if inp.y<0:
        actor.y-=1
    elif inp.y>0:
        actor.y+=1

##    actor.x+=inp.x
##    actor.y+=inp.y
    return

def screen_update():
    pygame.draw.rect(screen, 0x006633, ((0,0),(640,360)),0)
    screen.blit(a, (actor.x,actor.y))
    pygame.display.update()

if __name__ == '__main__':
    while True:
        events()
        print 'inp='+str(inp.x)+','+str(inp.y)
        print 'actor='+str(actor.x)+','+str(inp.y)
        controller()
        screen_update()

Why can’t the things I make work properly? 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:56:06+00:00Added an answer on May 30, 2026 at 12:56 pm

    To put it simply, you’re doing classes completely wrong.

    class xy:
      def __init__(self):
        self.x = 0
        self.y = 0
        self.jump = 0
    
    actor = xy()
    inp = xy()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.