Pages

Wednesday, May 7, 2014

pygame move formula

It's not working right,  But its a start.


import pygame
from pygame.locals import*

from sys import exit
import math

class MoveObject(object):
    def __init__(self, x1, y1, n, i, w, h, imgw, imgh):
        self.x1 = 0.0
        self.y1 = 0.0
        self.n = n
        self.i = i
        self.w = w
        self.h = h
        self.imgw = imgw
        self.imgh = imgh
       
       

   

    @classmethod
    def object_formula(self, x1, y1, n, i, w, h, imgw, imgh):
        if n * w >1 and n * w < w and i * h > 1 and i * h < h:
           
            return MoveObject(x1 + n * imgw, y1 + i * imgh)
        else:
            return (0 ,0)

def main(MoveObject):
   
    pygame.init()
    screen = pygame.display.set_mode((800, 800), 0, 32)
    UniBrush = pygame.image.load("apoobrush.png")
    unibrush = pygame.transform.scale(UniBrush, (90, 90))
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
       
       
        pressed_keys = pygame.key.get_pressed()
        if pressed_keys[K_LEFT]:
            n = -1.0
            n = n -1
        elif pressed_keys[K_RIGHT]:
            n = +1.0
            n = n + 1
        if pressed_keys[K_DOWN]:
            i = +1.0
            i = i + 1
        elif pressed_keys[K_UP]:
            i = -1.0
            i = i - 1
        else:
            n = 0
            i = 0
       
        (x, y) = MoveObject.object_formula(0, 0, n, i, 800, 800, 90, 90)
       
       
        screen.blit(unibrush, (x, y))
        pygame.display.flip()
       

main(MoveObject)
   
       
       
       
       
       

No comments:

Post a Comment