Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 5th, 2005, 7:55 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Feedback on program please.

100% original code, so I know exactly how to change it if you think it would look better changed. Any input will be considered. I tried using a sprite image, but there were too many images for it to load at once, that it lagged. If anyone can actually put it into the code so that it works, that would be great.

import pygame
import random

def video_settings():
    pygame.init()
    screen = pygame.display.set_mode((800, 700))
    pygame.display.set_caption('Soulodine v 0.2')
    pygame.mouse.set_visible(1)

    return screen

snowfall = 50
speed = 1

def create_snow(screen):
    snow_set = []
    colors = []
    direction = []

    for set in range (0, snowfall):
        snow = [ random.randrange(240, screen.get_width() - 240),
                 random.randrange(240, screen.get_height() - 240)]
        snow_set.append(snow);

        col = random.randrange(170, 255)
        colors.append(col);

        direct = random.randrange(1, 3)
        if direct == 2:
            direct = -1
        else:
            direct = 1
        direction.append(direct);

    return snow_set, colors, direction

def check_snow(snow_set, temp, direction, speed):
    temp = temp + 1
    for set in range (0, snowfall):
        if snow_set[set][1] > 460:
            snow_set[set] = [random.randrange(240, screen.get_width() - 240),
                             240]
        else:
            snow_set[set][1] = snow_set[set][1] + speed
            if temp < 40:
                if temp %4 == 0:
                    snow_set[set][0] = snow_set[set][0] + direction[set]
            elif temp > 39:
                if temp %4 == 0:
                    snow_set[set][0] = snow_set[set][0] - direction[set]
            if temp == 79:
                temp = -1
    return temp

def draw_snow(snow_set, screen, colors):
    for set in range (0, snowfall):
        pygame.draw.circle(screen, (colors[set],colors[set],colors[set]), (snow_set[set][0], snow_set[set][1]), 3, 0)

def main_loop(screen, temp):
    pygame.init()
    pygame.display.set_caption("Soulodine v0.2")   
    snow_set, colors, direction = create_snow(screen)

    while 1:
        pygame.draw.rect(screen, (255, 255, 255), ( (250, 250), (550, 450) ), 0)   
        draw_snow(snow_set, screen, colors)
        temp = check_snow(snow_set, temp, direction, speed)
        pygame.draw.rect(screen, 0, ( (0, 0), (250, 700) ), 0)
        pygame.draw.rect(screen, 0, ( (250, 0), (800, 250) ), 0)
        pygame.draw.rect(screen, 0, ( (550, 250), (800, 700) ), 0)
        pygame.draw.rect(screen, 0, ( (250, 450), (550, 700) ), 0)   
        pygame.display.update()

screen = video_settings()  
temp = 0
main_loop(screen, temp)
Sane is offline   Reply With Quote
Old Apr 5th, 2005, 8:28 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Quote:
Originally Posted by terminal shell
Traceback (most recent call last):
File "weird.py", line 1, in ?
import pygame
ImportError: No module named pygame
I don't program in python, so i'm not sure if this is my error or yours...
__________________

tempest is offline   Reply With Quote
Old Apr 5th, 2005, 8:53 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
You need pygame.

www.pygame.org

Get the one for your version if you are still interested in seeing it.
Sane is offline   Reply With Quote
Old Apr 6th, 2005, 3:00 PM   #4
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
I tried using a sprite image, but there were too many images for it to load at once, that it lagged.
Were you loading the image, setting aside, then drawing the loaded image whenever needed? Or were you loading the image and painting it for each frame?
Cerulean is offline   Reply With Quote
Old Apr 6th, 2005, 4:26 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
I didn't know how else then loading them and displaying them in a for loop. Because I'm not sure how to load more then one image in the same frame.

Unless....if I add pygame.update() at the end of all the images being displayed, it only displays in one frame?

Hmm...I'll try this later...

Edit: That aside, what did you think of it?
Sane is offline   Reply With Quote
Old Apr 6th, 2005, 7:44 PM   #6
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Seems good in general. If there's any part you want specific advice with just say so and i'll be more meticulous in that area.
Cerulean is offline   Reply With Quote
Old Apr 6th, 2005, 9:31 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Well, if you saw it overlapping a game window during an RPG whenever it snows, would you be like "whatever", or would you yell at the people who made the game? =P
Sane is offline   Reply With Quote
Old Apr 7th, 2005, 4:38 AM   #8
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Depends on the style of the game. That looks like cartoony/animated snow, so yeah, I think it would look quite good on a game of that style (older final fantasy's, etc).
For a little more realism try making the snow not just go left and right while falling down - try making some cut across from the top left of the window to the bottom right, if you see what I mean. Looks a little pre-defined.
As an exercise, try making the snow pile up at the bottom if you're bored
Cerulean is offline   Reply With Quote
Old Oct 28th, 2005, 1:04 PM   #9
Nebula
Hobbyist Programmer
 
Nebula's Avatar
 
Join Date: Oct 2005
Posts: 199
Rep Power: 3 Nebula is on a distinguished road
Send a message via AIM to Nebula
When i tried to run the module, it said "error, need module." i dont know if thats my problem? or an error in your code.
__________________
When will Jesus bring the porkchops?
Nebula is offline   Reply With Quote
Old Oct 28th, 2005, 1:05 PM   #10
Nebula
Hobbyist Programmer
 
Nebula's Avatar
 
Join Date: Oct 2005
Posts: 199
Rep Power: 3 Nebula is on a distinguished road
Send a message via AIM to Nebula
Quote:
i'll tell you what your problem is:
in the next post i post
hqahahahahahahasdjfhjkasdhfhaiseyifugaruilwegfgera jvguir
Jackass, your bus is leaving.
__________________
When will Jesus bring the porkchops?
Nebula is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC