Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ruler501

Pages: 1 ... 170 171 [172] 173 174 ... 184
2566
Miscellaneous / Re: Where Did Your Name Come From?
« on: February 02, 2011, 08:40:52 pm »
I forgot to say I write programs on my notebook paper that are usually over elaborate and partially useless. I run out of paper really fast. I am also a seventh grader who has taught himself most of the advanced math he knows and is now learning calculus. Am I still disappointing? If that still didn't work I code in multiple languages at once sometimes. It gets annoying when I try to type in a python/C++ hybrid program so many errors

that is an interesting story squidgetx I have a lizard he has the very creative name of Max

2567
Miscellaneous / Re: Where Did Your Name Come From?
« on: February 02, 2011, 08:32:02 pm »
I actually got it from the books which I have over 100 of and have read even more. I am basically the perfect frame for the nerdy kid in school. I do math in my spare time. Use my computer for everything code and read all the time

2568
Miscellaneous / Re: Where Did Your Name Come From?
« on: February 02, 2011, 08:27:49 pm »
That''s much more interesting than my story. I wanted it to be ruler101 on another site but that was already taken so I took ruler501 after the 501st division from star wars. I know its nerdy and boring but thats how I got mine

2569
Miscellaneous / Re: Coding Battles Project poll
« on: February 02, 2011, 05:15:06 pm »
I've decided to base the time limit on the project instead of having some overreaching unchangeable time limit.

2570
UberGraphX / Re: Project Paradise - Ubercalculator
« on: February 02, 2011, 05:13:20 pm »
This is amazing. If you can manage to get the cost below $200 I'll definitely buy it(I might buy it anyways, It looks awesome). My offer for help with any python programming still stands.

2571
Computer Projects and Ideas / Re: My physics game
« on: February 02, 2011, 04:22:03 pm »
Right now what I need is a good collision detection function. I can't do much without that.

2572
Computer Projects and Ideas / Re: My physics game
« on: February 02, 2011, 02:53:48 pm »
I now have platforms randomly falling from the sky with a slightly slower gravity(assuming a large air resistance)1/12.5fp/s/s. I have them generate randomly in the sky at a random spot and fall. I have also made the jumping for the player slightly more realistic. You can't jump while you are in the air. The gravity for the player is 1/15fp/s/s. I will post my code in just a little bit.

EDIT: I have a question do you guys think I should make it impossible to change the direction of a jump once your in the air? I have tried to implement this and failed so I'll keep trying if you guys find it a good idea I'll quit if not. Here is my code:
Code: [Select]
#import modules
import pygame, math, random, os
from pygame.locals import *

#Check to see if pygame is working right
if not pygame.font:
    print 'Warning, fonts disabled'
if not pygame.mixer:
    print 'Warning, sound disabled'

#define any needed global variables here

   
#Create a function to load images for sprites.
def load_image(name, colorkey=None):
    fullname = os.path.join('data', name)
    try:
        image = pygame.image.load(fullname)
    #If an error exit
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

#create a function to load sound
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = os.path.join('data', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    #if an error exit
    except pygame.error, message:
        print 'Cannot load sound:', fullname
        raise SystemExit, message
    return sound

class Platform(pygame.sprite.Sprite):
    #moves a clenched fist on the screen, following the mouse
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.image, self.rect = load_image('platform.bmp')
#        self.area=screen.get_rect()
        self.downforce=0
        self.dead=1
        self.rect.topleft

    def update(self):
        #move the player based on direction chosen
        if self.dead==0:
            self.gravity()
            newpos=self.rect.move((0,self.downforce))
            self.rect=newpos

    def gravity(self):
        if self.rect.bottom>615:
            self.downforce=0
            self.dead=1
        else:
            self.downforce+=1/12.5
   
    def alive(self):
        self.dead=0
        self.initial=random.randint(0,750)
        self.rect.topleft=self.initial, 1
       


#classes for our game objects
class Player(pygame.sprite.Sprite):
    #moves a clenched fist on the screen, following the mouse
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.image, self.rect = load_image('sprite.bmp')
        self.rect.topleft=1, 558
        self.direction=0
        self.downforce=0
        self.jump=0
        self.change=0
#        self.area=screen.get_rect()

    def update(self):
        #move the player based on direction chosen
        self.gravity()
        if self.direction == 0:
            newpos = self.rect.move((0, self.downforce))
        elif self.direction == 1:
            if self.jump==0 or self.rect.bottom>=599:
                self.jump=1
                self.downforce-=3.5
            newpos = self.rect.move((0, self.downforce))
        elif self.direction == 3:
            newpos = self.rect.move((-4, self.downforce))
        elif self.direction == 4:
            newpos = self.rect.move((4, self.downforce))
        elif self.direction == 5:
            newpos = self.rect.move((-2, -2))
        elif self.direction == 6:
            newpos = self.rect.move((2, -2))
        self.rect = newpos

    def gravity(self):
        #need a collision detector here
        if self.rect.bottom>=599:
            self.downforce=0
            self.jump=0
            self.change=0
            self.rect.bottom=599
        else:
            self.downforce+=1/15.0

    def up(self):
        if self.jump==0:
            self.direction=1

    def left(self):
        self.direction=3

    def right(self):
        self.direction=4

    def still(self):
        self.direction=0

    def upleft(self):
        self.direction=5

    def upright(self):
        self.direction=6


#function to load the game engine
def game_engine():
    #nothing done here yet
    return

#function for playing the game
def play_game():
    #load the game engine
    game_engine()
    #start the game
    #Initialize Everything
    pygame.init()
    screen = pygame.display.set_mode((900, 600))
    pygame.display.set_caption('Physics!')
    pygame.mouse.set_visible(1)
    turn = 0
    win = False
    lose = False
    achievements = 0

    #Create The Backgound
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((250, 250, 250))

    #Display The Background
    screen.blit(background, (0, 0))
    pygame.display.flip()

    #Prepare Game Objects
    clock = pygame.time.Clock()
    player = Player()
    platforma = Platform()
    platformb = Platform()
    platformc = Platform()
    platformd = Platform()
    platforme = Platform()
    allsprites = pygame.sprite.RenderPlain((player, platforma, platformb, platformc, platformd, platforme))
    #Main Loop
    while 1:
        clock.tick(25)

        #Generate Events
        rand=random.randint(1,250)
        if rand==20 and platforma.dead==1:
            platforma.alive()
        if rand==10 and platformb.dead==1:
            platformb.alive()
        if rand==30 and platformc.dead==1:
            platformc.alive()
        if rand==40 and platformd.dead==1:
            platformd.alive()
        if rand==75 and platforme.dead==1:
            platforme.alive()

    #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                pygame.quit()
                return
            if event.type == KEYDOWN and event.key == K_UP and event.key == K_LEFT:
                player.upleft()
            elif event.type == KEYDOWN and event.key == K_UP and event.key == K_RIGHT:
                player.upright()
            elif event.type == KEYDOWN and event.key == K_UP:
                player.up()
            elif event.type == KEYDOWN and event.key == K_LEFT:
                player.left()
            elif event.type == KEYDOWN and event.key == K_RIGHT:
                player.right()
            else:
                player.still()

        allsprites.update()

    #Draw Everything
        screen.blit(background, (0, 0))
        allsprites.draw(screen)
        pygame.display.flip()

def main():
    #define needed local variables here
   
    #start game
    play_game()
   
if __name__ == '__main__':
    main()
Again I still need ideas for improvements and optimizations. thank you for any help you might give.

EDIT 2: I redid the description above to add more detail and bring it to where I currently am

2573
Computer Projects and Ideas / Re: Coding Battles
« on: February 02, 2011, 11:50:32 am »
Then I'll just ask when I start it what people think the time limit should be and use that.

2574
Computer Projects and Ideas / Re: Coding Battles
« on: February 02, 2011, 11:00:18 am »
Sorry to hear Sircmpwn Hope you can compete again sometime

@DJDo you think it would be a good idea to choose the time limit based on the project?

2575
Miscellaneous / Re: Where Did Your Name Come From?
« on: February 02, 2011, 10:42:21 am »
^^^^
Same with me

2576
Computer Projects and Ideas / Re: My physics game
« on: February 01, 2011, 09:34:05 pm »
I didn't think you could work with partial pixels

EDIT: I tried doing 1/25 instead of 1 and it didn't work
EDIT 2: I fixed it I had put it as 1/25 when it needed to be 1/25.0 It is working now at a much more manageable speed
EDIT3:I also made it so that the sprite stops falling when it hits the bottom. Now I need to start on scenery and collision detection.

2577
Computer Projects and Ideas / Re: My physics game
« on: February 01, 2011, 09:12:35 pm »
i know most of the physics of this I just don't know the coding of it

here is my code I have commented out some of the sections I am currently working on. Again I still would appreciate all input on optimization and improvements for my code. My main problem right now is gravity is too fast. after I finish this next I will start on adding collision detection.
Code: [Select]
#import modules
import pygame, math, random, os
from pygame.locals import *

#Check to see if pygame is working right
if not pygame.font:
    print 'Warning, fonts disabled'
if not pygame.mixer:
    print 'Warning, sound disabled'

#define any needed global variables here

   
#Create a function to load images for sprites.
def load_image(name, colorkey=None):
    fullname = os.path.join('data', name)
    try:
        image = pygame.image.load(fullname)
    #If an error exit
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

#create a function to load sound
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = os.path.join('data', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    #if an error exit
    except pygame.error, message:
        print 'Cannot load sound:', fullname
        raise SystemExit, message
    return sound

#classes for our game objects
class Player(pygame.sprite.Sprite):
    #moves a clenched fist on the screen, following the mouse
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.image, self.rect = load_image('sprite.bmp', -1)
        self.direction=0
        self.downforce=0

    def update(self):
        #move the player based on direction chosen
        self.gravity()
        if self.direction == 0:
            newpos = self.rect.move((0, self.downforce))
            self.rect = newpos
        elif self.direction == 1:
            self.downforce-=2
            newpos = self.rect.move((0, self.downforce))
            self.rect = newpos
            self.downforce+=2
        elif self.direction == 2:
            self.downforce+=2
            newpos = self.rect.move((0,self.downforce))
            self.rect = newpos
            self.downforce-=2
        elif self.direction == 3:
            newpos = self.rect.move((-2, self.downforce))
            self.rect = newpos
        elif self.direction == 4:
            newpos = self.rect.move((2, self.downforce))
            self.rect = newpos
##        elif self.direction == 5:
##            newpos = self.rect.move((-2, -2))
##            self.rect = newpos
##        elif self.direction == 6:
##            newpos = self.rect.move((2, -2))
##            self.rect = newpos
##        elif self.direction == 7:
##            newpos = self.rect.move((-2, 2))
##            self.rect = newpos
##        elif self.direction == 8:
##            newpos = self.rect.move((2, 2))
##            self.rect = newpos

    def gravity(self):
        #need a collision detector here
        self.downforce+=1

    def up(self):
        self.direction=1

    def down(self):
        self.direction=2

    def left(self):
        self.direction=3

    def right(self):
        self.direction=4

    def still(self):
        self.direction=0

##   def upleft(self):
##        self.direction=5
##
##    def upright(self):
##        self.direction=6
##
##    def downleft(self):
##        self.direction=7
##
##    def downright(self):
##        self.direction=8

#function to load the game engine
def game_engine():
    #nothing done here yet
    return

#function for playing the game
def play_game():
    #load the game engine
    game_engine()
    #start the game
    #Initialize Everything
    pygame.init()
    screen = pygame.display.set_mode((975, 325))
    pygame.display.set_caption('Physics!')
    pygame.mouse.set_visible(1)
    turn = 0
    win = False
    lose = False
    achievements = 0

    #Create The Backgound
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((250, 250, 250))

    #Display The Background
    screen.blit(background, (0, 0))
    pygame.display.flip()

    #Prepare Game Objects
    clock = pygame.time.Clock()
    player = Player()
    allsprites = pygame.sprite.RenderPlain((player))
    #Main Loop
    while 1:
        clock.tick(25)

    #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return
##            elif event.type == KEYDOWN and event.key == K_UP and event.key == K_LEFT:
##                player.upleft()
##            elif event.type == KEYDOWN and event.key == K_UP and event.key == K_RIGHT:
##                player.upright()
##            elif event.type == KEYDOWN and event.key == K_DOWN and event.key == K_LEFT:
##                player.downleft()
##            elif event.type == KEYDOWN and event.key == K_DOWN and event.key == K_RIGHT:
##                player.downright()
            elif event.type == KEYDOWN and event.key == K_UP:
                player.up()
            elif event.type == KEYDOWN and event.key == K_DOWN:
                player.down()
            elif event.type == KEYDOWN and event.key == K_LEFT:
                player.left()
            elif event.type == KEYDOWN and event.key == K_RIGHT:
                player.right()
            else:
                player.still()
               
               

        allsprites.update()

    #Draw Everything
        screen.blit(background, (0, 0))
        allsprites.draw(screen)
        pygame.display.flip()

def main():
    #define needed local variables here
   
    #start game
    play_game()
   
if __name__ == '__main__':
    main()

2578
Computer Projects and Ideas / Re: My physics game
« on: February 01, 2011, 08:27:40 pm »
I need to get this to work efficiently this is looking harder and harder every second. I could use any help with optimization. I almost have some gravity working. It is just a little to fast right now. Any way for me to slow it down a little. It is at 1 pixel per frame per frame at 25 frames per second.

2579
Computer Projects and Ideas / Re: My physics game
« on: February 01, 2011, 08:07:28 pm »
Oh I was planning on trying to set up a rule that would make gravity work right.

How would I be able to test all the pixels in a small area if they were of different types. I'm planning on having many different kind of things in this so I don't want it going through platforms and stuff like that.

2580
Miscellaneous / Re: Coding Battles Project poll
« on: February 01, 2011, 08:05:11 pm »
I added in z80 mans idea to the poll.

Pages: 1 ... 170 171 [172] 173 174 ... 184