I'm 100% sure that I did it wrong, but I'm not sure how to do it right. BASICALLY, I'm trying to give this little game physics (not related to previous mapping questions), but uh... it's not working at all. I can't move the sprite at all, it doesn't even fall to the bottom of the screen (which it should be doing). Take a look (please!):
main.py
*It's not throwing an error, the sprite that renders just won't move.
#importing stuff
import pygame, render, universal, physics
#basic stuff
pygame.init()
screen1 = universal.BigScreen()
bigphysics = physics.Physics()
done = False
clock = pygame.time.Clock()
#defining stuff
delta = render.Character()
delta.anim("idle", 1)
bigphysics.outputx = 0
bigphysics.outputy = 0
while not done:
bigphysics.changeinx(0, bigphysics.outputx)
bigphysics.changeinx(0, bigphysics.outputy)
screen1.screen.fill((135, 206, 235))
delta.display(bigphysics.changeinx(0, bigphysics.outputx),bigphysics.changeinx(0, bigphysics.outputy))
#for doing stuff!
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
clock.tick(60)
render.py
*for loading and displaying animated sprites. Will probably only grow as time goes on to deal with more animations.
import pygame, os, universal
screen1 = universal.BigScreen()
#for all animated
class Character(object):
def __init__(self):
pass
def anim(self, filename, framecount):
self.filename = filename
self.framecount = framecount
frames = []
for frame in range(framecount):
frames.append(pygame.image.load(os.path.expanduser("~/Desktop/pythongame/pygametut/assets/sprites/" + filename + str(frame + 1) + ".png")).convert_alpha())
self.frames = frames
def display(self, y, x):
self.y = y
self.x = x
for frame in self.frames:
screen1.screen.blit(frame, (x, y))
physics.py
*the file in question... it's uh... I don't know. Basically trying to keep keep the physics (however basic atm) out of the main loop.
import pygame, universal
screen1 = universal.BigScreen()
class Physics(object):
def __init__(self):
pass
def changeinx(self, force, currentx):
outputx = currentx
#gravity
outputx += 10
#jumping
for event in pygame.event.get():
if event.type == pygame.K_SPACE:
outputx -= 20
#bounding
if(outputx < 0):
outputx = 0
if(outputx > screen1.screenheight):
outputx = screen1.screenheight - 34
self.outputx = outputx
return outputx
def changeiny(self, force, currenty):
outputy = currenty
#dashing goes here
#lateral movement
for event in pygame.event.get():
if event.type == pygame.K_LEFT:
outputy -= 1
if event.type == pygame.K_RIGHT:
outputy += 1
#bounding
if(outputy < 0):
outputy = 0
if(outputy > universal.BigScreen.screenwidth):
outputy = universal.BigScreen.screenwidth - 18
self.outputy = outputy
return outputy
universal.py
*basically for any sort of universal constants I may or may not need, and also importing screen rendering abilities to the physics class
import pygame
class BigScreen(object):
def __init__(self):
self.screen = pygame.display.set_mode((750, 750))
self.screenheight = 750
self.screenwidth = 750