Jump to content

  • Log In with Google      Sign In   
  • Create Account

TreeSaaaaap

Member Since 24 Feb 2014
Offline Last Active Sep 12 2014 12:34 PM

Posts I've Made

In Topic: Vectors Newb

01 March 2014 - 03:13 PM

import pygame, sys

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("char.png").convert()
        self.rect = self.image.get_rect()

    def draw(self, screen):
        self.image = pygame.transform.scale(self.image, (75, 75))
        screen.blit(self.image, (self.rect.x, self.rect.y))
        
        
    def update(self, mlocX, mlocY, n_steps):
        self.rect.x += (mlocX - self.rect.x) / n_steps
        self.rect.y += (mlocY - self.rect.y) / n_steps

import pygame, sys
import oPC

pygame.init()

WINDOWSIZE = (1000, 800)
BLACK = (0, 0, 0)
              
screen = pygame.display.set_mode((WINDOWSIZE))
pygame.display.set_caption("TTB")

screen.fill(BLACK)
terrain = pygame.image.load("terrain.jpg").convert()
terrainRect = terrain.get_rect()
terrain = pygame.transform.scale(terrain, ((WINDOWSIZE)))
screen.blit(terrain, terrainRect)

oPC = oPC.Player()
oPC.draw(screen)
pygame.display.flip()
                               
running = True
n_steps = 80

while running == True:
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                running = False

        elif event.type == pygame.MOUSEBUTTONDOWN:
            mlocX, mlocY = pygame.mouse.get_pos()
            while mlocX != oPC.rect.x and mlocY != oPC.rect.y:
                oPC.update(mlocX, mlocY, n_steps)
                if n_steps > 1:
                    screen.fill(BLACK)
                    screen.blit(terrain, terrainRect)
                    n_steps -= 1
                    oPC.draw(screen)
                    pygame.display.flip()
            n_steps = 80
            
pygame.quit()
#sys.exit()

I understand the point of not wanting to have another loop running inside of there, but I'm not quite sure how to iterate it another way so it gradually moves towards the mouses target location (without having to click or roll the mouse wheel constantly).  I was thinking, would it be more efficient to control the movement by time somehow as opposed to using steps?  It works this way now, but the image makes it to different distances at the same amount of time, which isn't exactly great for character movement.


In Topic: Vectors Newb

27 February 2014 - 04:43 PM

Ok, I see what you're saying about not wanting to throw another loop in there, but I'm not sure how to iterate it another way so it moves on it's own and so that I don't need to keep clicking for each movement.  Right now, it only moves a step for each mouse event.


In Topic: Vectors Newb

27 February 2014 - 02:54 PM

So, I'm getting this closer to working it seems.  I'm getting it to run through the while loop, and the object actually moves to the location I've clicked.  However, when it reaches that point, the program freezes and I really have no clue why.  At some point, the conditions should be met (at the same time) and the while loop should end.  Is this crashing because x and y are not being met at the same moment?  Hmm...

import pygame, sys

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("char.png").convert()
        self.rect = self.image.get_rect()

    def draw(self, screen):
        self.image = pygame.transform.scale(self.image, (75, 75))
        screen.blit(self.image, (self.rect.x, self.rect.y))
        
        
    def update(self, mlocX, mlocY):
        self.rect.x += (mlocX - self.rect.x) / 110
        self.rect.y += (mlocY - self.rect.y) / 110
import pygame, sys
import oPC


pygame.init()

WINDOWSIZE = (1000, 800)
BLACK = (0, 0, 0)
              
screen = pygame.display.set_mode((WINDOWSIZE))
pygame.display.set_caption("TTB")

screen.fill(BLACK)
terrain = pygame.image.load("terrain.jpg").convert()
terrainRect = terrain.get_rect()
terrain = pygame.transform.scale(terrain, ((WINDOWSIZE)))
screen.blit(terrain, terrainRect)

oPC = oPC.Player()
oPC.draw(screen)
pygame.display.flip()

                                 
running = True

while running == True:
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                running = False

        elif event.type == pygame.MOUSEBUTTONDOWN:
            mlocX, mlocY = pygame.mouse.get_pos()
            while oPC.rect.x != mlocX and oPC.rect.y != mlocY:
                screen.fill(BLACK)
                screen.blit(terrain, terrainRect)
                oPC.update(mlocX, mlocY)
                oPC.draw(screen)
                pygame.display.flip()

                
pygame.quit()
#sys.exit()

In Topic: Vectors Newb

26 February 2014 - 06:23 PM

Ahhh..yes...>.<  An hour spent skipping over that....  I'm thinking it's quitting time for the day.  Thanks so much for the help guys!


In Topic: Vectors Newb

26 February 2014 - 05:54 PM

Having some serious trouble, just with line 2, and I have no clue why haha...

import pygame, sys

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("char.png").convert()
        self.rect = self.image.get_rect()

    def update(self, mlocX, mlocY):
        self.rect.x += (mlocX - self.rect.x) / 10
        self.rect.y += (mlocY - self.rect.y) / 10

    def draw(self, screen)
        screen.blit(self.image, (self.rect.x, self.rect.y))
        

import pygame, sys
import oPC


pygame.init()

WINDOWSIZE = (1000, 800)
BLACK = (0, 0, 0)
              
screen = pygame.display.set_mode((WINDOWSIZE))
pygame.display.set_caption("TTB")

screen.fill(BLACK)
terrain = pygame.image.load("terrain.jpg").convert()
terrainRect = terrain.get_rect()
terrain = pygame.transform.scale(terrain, ((WINDOWSIZE)))
screen.blit(terrain, terrainRect)
pygame.display.flip()

oPC = Player()

                                 
running = True

while running == True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                running = False

        elif event.type == pygame.MOUSEBUTTONDOWN:
            mlocX, mlocY = pygame.mouse.get_pos()
            screen.fill(BLACK)
            screen.blit(terrain, terrainRect)
            oPC.update(mlocX, mlocY)
            oPC.draw(screen)
            pygame.display.flip()

                
pygame.quit()
#sys.exit()

Traceback (most recent call last):
  File "C:/Users/Daniel/Downloads/PyServ/PyServ/TheGame/main.py", line 2, in <module>
    import oPC
  File "C:/Users/Daniel/Downloads/PyServ/PyServ/TheGame\oPC.py", line 15
    def draw(self, screen)
                         ^
SyntaxError: invalid syntax

I'm not sure what is going wrong...  Trying to weed out the errors.


PARTNERS