#31
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Your while condition is an OR, but should be an AND. Using an OR this program will stop looping once both scores have passed 4.

    Remember, a "WHILE ... OR ..." will proceed if any of its conditions are TRUE, a "WHILE ... AND ..." requires that all conditions are TRUE.

    This is an instructive lesson in how relatively simple conditionals can turn out tricky when you momentarily forget the different behaviors that conjunctions (AND, OR, XOR, etc.) have when used as inclusive conditions (do while) and exclusive conditions (do unless) or especially an inverse of either two.

    That said, I strongly disagree with the way the problem places design mandates on the coder -- particularly mandates that enforce bad design rules. That you already understand this makes it a decent exercise for you, but for the legion of well-intentioned-yet-programatically-disinclined it is an exercise that reinforces bad habits. Most importantly, there is nothing about using a tuple, dict or list, nor anything about using a self-defined function that would detract from the point of the lesson here... weird.
    Last edited by zxq9; July 15th, 2013 at 08:18 AM.
  2. #32
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Thanks zx, I'm relieved to know that the code was correct for the most part.

    And yes, this would of been a whole lot easier had they not put those restrictions on me, I fail to see the point of as well.
  4. #33
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by Wretch11
    And yes, this would of been a whole lot easier had they not put those restrictions on me, I fail to see the point of as well.
    If you want to become a programmer working for someone else in the future then get used to it. Wildly stupid requirements put on developers from time to time for the most stupid, senseless, self-defeating reasons. Stupidity rarely seen outside government is commonplace in some development environments.

    The damning thing is that most government idiocy is explainable once it is understood that the personal interests of those in government are nearly always at odds with the stated organizational goal, whereas in for-profit business individual and organizational interests are (generally) aligned. This magically doesn't stop people who have zero technical competency from getting into positions where they can dictate policy over the very things they don't understand.
  6. #34
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Thanks for the warning, that'll definitely be something to be prepared for.

    It just so happens that I am contemplating becoming a programmer. In fact, it's a bit more than contemplation at this point as I'll be starting college in September 2014. I live near Montreal and this city is quickly becoming a video game development capital, I figure that if I apply myself, my chances of becoming a video game programmer are better than average.

    The point of learning Python, coding my first basic arcade game, it's all to ready myself and get a basic understanding of how it's done. Of course I understand that Python probably isn't used that much (if at all) in the game development industry, but having python as a first language will probably help a lot when comes the time to learn a second, third and fourth language.
  8. #35
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Game development is fascinating in many ways. Its just too bad that deadlines usually suck the fun/life right out of it -- but if you luck out and wind up with a solid team (may take a few tries) you'll really have some great experiences.

    One of my goals with my own company is to apply the lessons learned in games to business software. It has always been a bit silly to me that the average 6th grader can manage, with relative ease, to play Eve Online (you know, the gigantic spreadsheet and inventory program that's disguised as a video game) without ever having read the manual, yet most small and medium businesses are still struggling with basic inventory and accountability tracking using ad-hoc, buggy, hacked together, VB crap someone sold them for $30k in Excel.

    Anyway, once you get through a project or two you'll realize that game problems aren't any more or less interesting than business data problems -- because they are the same problems in the vast majority of cases.

    Python will help you. Especially if you (later on) start learning how to profile your programs and locate the performance-needy parts and write those in C. That experience will give you a lot of insight when it comes to learning C++ widget and games APIs. As far as Python's use in the industry... there is some, but in the weird corners of game systems -- AI/quest/dynamic item scripting (some lispy languages are common here too), installers, update checkers, etc.
  10. #36
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    I'm still playing around with pygame a bit as I do my course.

    My code
    Code:
    import pygame
    import random
    
    # Defined colors
    black    = (   0,   0,   0)
    white    = ( 255, 255, 255)
    green    = (   0, 255,   0)
    red      = ( 255,   0,   0)
    dark_green_night_grass = (12, 99, 38)
    dark_blue_night_sky = (44, 12, 99)
    night_mountain_brown = (105, 75, 5)
    mountain_shadow = (71, 71, 69)
    pi = 3.141592653
    TRANSPARENT = (255,0,255)
    
    pygame.init()
      
    
    size = [700,500]
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("My Game")
    
    clock = pygame.time.Clock()
    
    done = False
    
    ellipse_x = 480
    ellipse_y = 75
    
    ellipse_x_two = 600
    ellipse_y_two = 50
    
    ellipse_change_x = -1
    ellipse_change_y = 0
    
      
    surf1 = pygame.Surface((700,500))
    surf1.fill(TRANSPARENT)
    surf1.set_colorkey(TRANSPARENT)
    pygame.draw.rect(surf1,(1,1,1,100),[0,0,700,500],0)
    surf1.set_alpha(100)
    
    # -------- Main Program Loop -----------
    while done == False:
        
        for event in pygame.event.get(): # User did something
            if event.type == pygame.QUIT: # If user clicked close
                done = True # Flag that we are done so we exit this loop
        
        screen.fill(white)
    
        pygame.draw.rect(screen,dark_blue_night_sky,[0,0,700,200],0)
        
        for i in range(10):
            star_x = random.randrange(1,701)
            star_y = random.randrange(1,501)
            pygame.draw.circle(screen,white,(star_x,star_y), 2,)   
            
        pygame.draw.rect(screen,dark_green_night_grass,[0,200,700,300],0)
        pygame.draw.polygon(screen,night_mountain_brown,[(0,199),(150,100),(250,150),(300,90),(450,199),(-450,199)])
        pygame.draw.lines(screen,(0, 0, 0),False,[(0,199),(150,100),(250,150),(300,90),(450,199),],3)
        pygame.draw.circle(screen,(240, 239, 223),(235, 104), 26,)
        pygame.draw.circle(screen,(237, 217, 135),(235, 104), 25,2)
        pygame.draw.polygon(screen,(0, 0, 0),[(290,500),(345,200),(355,200),(410,500),(-120,500)],3)
        pygame.draw.polygon(screen,(82, 62, 29),[(291,499),(346,199),(354,199),(409,499),(-121,499)])
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x,ellipse_y,200,50])
        if ellipse_x <= 260 and ellipse_x >= 10:
            screen.blit(surf1,(0,0,700,500))
    
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x_two,ellipse_y_two,70,30])
    
        ellipse_x += ellipse_change_x
        ellipse_y += ellipse_change_y
        ellipse_x_two += ellipse_change_x
        ellipse_y_two += ellipse_change_y
    
        if ellipse_x < -300 and ellipse_x_two < -50:
            ellipse_x = 880
            ellipse_x_two = 1000
    
    
        pygame.display.flip()
         
            
        clock.tick(20)
         
    
    pygame.quit()
    My question:

    How do i get the section of code below to display at a different framerate than the rest of the main program loop? I've tried placing a different clock.tick() value inside the for loop that draws the circles, but that didnt work.

    Code:
    for i in range(10):
            star_x = random.randrange(1,701)
            star_y = random.randrange(1,501)
            pygame.draw.circle(screen,white,(star_x,star_y), 2,)
  12. #37
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by Wretch11
    How do i get the section of code below to display at a different framerate than the rest of the main program loop? I've tried placing a different clock.tick() value inside the for loop that draws the circles, but that didnt work.
    This is a narrowly pygame specific question. The general thing that can be said about this is that you only have a single clock instance -- its global to your program. When you set clock initially it is set for everything. When you reset it in the loop its doing exactly what you told it to: resetting the global clock. This provides no local difference between the different elements that are dependent on it. (But I'm not clear yet if the intent is to have one or two elements display at a different rate than everything else, or to have the entire display appear to go in slow-mo when an event happens.)

    Anyway, the program gets its initial tic set, and then immediately (like probably only a few nanoseconds later) gets it reset because the first occurrence of while() is true, which means from where the human is sitting you'll never even notice the nanosecond or so during which the tic was set to its initial value.

    What effect are you trying to achieve? There may be a different way of getting there than adjusting the global tic.
    Last edited by zxq9; July 17th, 2013 at 03:47 AM.
  14. #38
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    I was trying to create blinking stars. My idea is to have a circle be constantly redrawn at randomly generated coordinates. I've managed to get that to happen, but the circle is being redrawn 20 times per second and so the effect doesn't look good because it's going too fast.
  16. #39
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Hmmm. Twinkling is a special sort of effect which is usually easier to represent as a scripted event that gets called to happen and then runs itself until its finished. So instead of redrawing a circle randomly for an instant and then moving somewhere else every tic, see if you can create an event/function that does the star effect for a random duration at a random interval. Then you can play with the range of the two random inputs until you find a good balance. Creating scripted lighting effects that occur on random triggers is very common in games and there is probably a way to do this with pygame -- but it may be part of a module that you haven't gotten to yet, since its in the realm of "graphic effects" not "direct draw".

    Another (old and very common) way of doing this is to create an animated sprite (a multi-frame image like an animated GIF or PNG (MNG/APNG, etc)) and display that/them with a random distribution, and have the animation of the sprites themselves handle the twinkling effect. Since all the stars flashing in unison would be weird (a mistake seen in many game backgrounds) you would want to take your basic star animation and then create several versions of it, each with a different start time within the animation and length.That way you have some that start out dark, some that start out bright, some that have a long period and some that have a short period. With a decent mix of speeds and starts you can get a pretty decent looking sky with sprites -- all on the same global clock.
  18. #40
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Thanks for pointing me in the right direction zx. I found this module called Pyganim sprite animation. I'll give it a try and see what I can do with it. I'll post the new code once I figured it out. As always, if I have more questions I'll post em here.
  20. #41
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Learning sprites is definitely the easiest way to get some basic animation going and looking pretty without having to become a graphics specialist.

    The bit I wrote above about effects that run on their own timer is most effective when you want to apply a lighting/filter/distortion effect to a region based on a trigger. Like for instance in an FF style RPG where each character has his own turn timer the fight effects (which are a combination of sprite animations and region effects) have to be scripted so that they can get triggered and run without having to worry about interactions with other fight effects which might turn up at any time (when other characters initiate their own actions). Sprite animations can just go (easy) but the effect overlays have to be written so they can, say, shade or distort a region that is being painted and updated concurrently to make it look like a flash, bang, dimension spell, or whatever, without being totally opaque and boring (this gets back to your original transparency question) or doing weird stuff like shearing sprites that are in motion into/outof the affected region.

    A lot late 80's/early 90's RPG and fantastical fight games did some pretty amazing stuff that came off cleaner than any 2D I've seen in years on laughably "weak" hardware by today's standards. (Which reminds me... Nintendo did some serious graphics hardware/software/language ninja hacks when they produced the original StarFox game for Super FamiCom. Not sure if any industry literature has escaped from those days, though...)

    Anyway, back to sprites... if you look into sprites, backgrounds and region paint effects you might wind up deciding that its easier to just draw yourself a background night screen, draw a cloud or two, draw some variations of flashing stars, etc. and stitch the art together with sprite animations. Its a comparatively easy way to get things done in a hurry. Its also really funny to do game mock-up screens using sprites created by taking scans of pencil drawings and hand doodles. Like Paper Mario, but badly done -- which is part of where the original Paper Mario idea came from (goofing off with scanned initial proof sprites).

    [EDIT: @Mekire: Thanks for the link to the story! That was indeed interesting. I never realize Argonaut stayed with Nintendo for so long.]

    Comments on this post

    • Mekire agrees : An interesting read on Star Fox if you haven't already seen it: http://www.eurogamer.net/articles/2013-07-04-born-slippy-the-making-of-star-fox
    Last edited by zxq9; July 19th, 2013 at 10:30 PM.
  22. #42
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Hey Back again with another question.

    Ok so I'm still working on the course. Here's a question I needed to answer

    Code:
    # 16. The game you are working on seems to randomly ignore user keystrokes, particularly when
    #     the user is pressing keys very fast. What might be the problem?
    My answer

    Code:
    """If the screen is being updated slower than the user is inputing his keystrokes, this would cause the program to ignore the user's input
    (e.g If screen updates at clock.tick(5) and user inputs six keystrokes per second, the sixth storke would be ignored by the program"""
    I simply want to know if my answer here is accurate.

    Thanks as usual
  24. #43
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    No clue specifically what he is going for, and I use pygame a lot. My answer would be keyboard ghosting/blocking, but this is a hardware problem that your programming can't fix, so it is unlikely it is the answer he is looking for.

    Honestly I don't much care for the tutorial site you are going through. I see people throwing links to it around constantly though. He demonstrates some very bad habits which I try to get pygame programmers away from. He writes his event and game loops in the global namespace and he doesn't seem to understand how to write proper if statements.

    Anyway, rant over (for now),
    -Mek
    Last edited by Mekire; July 31st, 2013 at 09:15 AM.
  26. #44
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    I just decided on this course because it seemed streamlined in it's goal: Teaching a complete programming noob how to code a very basic arcade style game using python.

    Whether it demonstrates bad habit or not is not apparent to me (Kind of like how terrible art might appear ok to an untrained eye). What I can say though is that using this and code academy, I was able to get a firm grasp on the basics and get that much closer to coding my first actual game (rudimentary though it may be).

    But I digress. Could you point me to something you would consider more efficient/ better at teaching me to code a simple game?
  28. #45
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    Well in a bout of flagrant self promotion I can point you at my pygame example repo:

    https://github.com/Mekire/meks-pygame-samples

    My philosophy is about the opposite though; I think that people shouldn't dive into game programming until they have firm grasps of the basics. My goal is to show concise examples that each illustrate key concepts, but are still written as cleanly as possible.

    However, they aren't tutorials. They have docstrings and comments where I deemed them useful, but they are just examples.

    -Mek

IMN logo majestic logo threadwatch logo seochat tools logo