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 9204739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:46:51+00:00 2026-06-17T23:46:51+00:00

I am designing a game and need to convert the script-variables from meters to

  • 0

I am designing a game and need to convert the script-variables from meters to pixels. My conversion factor is 30; 30 pixels to 1 meter. I have three levels of code: my game engine, the game level, and my scripts.

The Game Engine creates a new game level “curmap” from the base class. Every frame in the game, the engine calls curmap.animate, which returns a list of where every object in the game gets blit’ed. The level iterates over every object within the level, and calls animate on each object.

My Problem

The issue I have is that in the Level-animate method, the player-animate method is returning direct references to the player-class-variables. The two commented lines in the Level-animate were meant to only alter the returned value, but instead they are modifying the player-variables. I can’t reproduce this in a test class so I’m at a complete loss.

How do I uncomment those two inline multiplication statements without changing the player script?

The Game Engine:

# fps is an instance of pygame.time.clock()
# events is a modified list of pygame.event.get()

for item in curmap.animate(fps.tick()/1000, events):
    screen.blit(curmap.assets['textures'][item[0]],item[1],item[2])

The Level:

def animate(self, timedelta, events):
    returns = []
    for item in self.objects:
        ret = item.animate(timedelta, events)

        #ret[1][0] *= 30
        #ret[1][1] *= 30

        returns.append(ret)
    return returns

The Player Script:

def animate(self, timedelta, input):
    # Process Inputs
    for item in input['keydown']:
        self.keydown.append(item)
    for item in input['keyup']:
        self.keydown.remove(item)

    # Change Velocity and Position
    if "left" in self.keydown:
        self.velocity[0] = 5
    elif 'right' in self.keydown:
        self.velocity[0] = -5
    else: self.velocity[0] = 0
    print(self.position, self.velocity)
    self.position[0] += self.velocity[0]*timedelta
    self.position[1] += self.velocity[1]*timedelta


    # Change Sprite
    self.time += timedelta
    if self.time > self.altertime:
        self.current = (self.current+1)%2
        self.time -= self.altertime

    return [self.image, self.position, self.sprite[self.current] + self.dimensions]
  • 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-06-17T23:46:52+00:00Added an answer on June 17, 2026 at 11:46 pm

    You didn’t say what exactly self.position is in your Player.animate method, but if it’s a simple list containing numeric values, just copy this list:

    return [self.image, self.position[:], self.sprite[self.current] + self.dimensions]
    

    You are returning the list Player.position, and when you alter it (you change the values inside the list) in Level.animate, you are actually changing Player.position, since you are working on the same list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a Game and have a large background. The background it a
usually people when designing proper software architectures on c++ that also need to have
I need to split my job with my partner for designing game stages, and
I need help in designing a Chess game. I've already started but haven't got
I'm creating a browser based game and at the moment I'm designing the script
For a learn-as-I-code game that I'm designing, I have a pretty rudimentary map: http://www.dixieandtheninjas.net/dynasties/images/dynasties_map_2.jpg
I'm designing a database with three tables: user, game and (probably) register. I want
Im designing a game, that transitions through a handful of states, I have seen
I'm designing a game server and I have never done anything like this before.
I am designing a sudoku game in android.I have tried 81 text views. It

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.