• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

K1NNY

Members
  • Content count

    56
  • Joined

  • Last visited

Community Reputation

163 Neutral

About K1NNY

  • Rank
    Member
  1.   I'm not sure why it isn't in the code sections above but i called for "DISPLAY" to be filled "WHITE" and it is not working. I combined CreateDisplay.py and Game.py, and added pygame.diplsay.flip() to the Game() definition and it works fine now. I assumed having pygame.display.update() in Main.py would be enough.
  2.   I've made many programs using one file and am doing my new project this way to learn how to properly do it. So I should only import pygame in Main.py?
  3. I have three files: Main.py, Game.py, and CreateDisplay.py . Obviously Main is going to be the main file where everything is going to run from. This is my first project that i have split the code into separate modules and i am having problems.   The problem i am having is that when the display is made, the background isn't filled with white, its black, and no matter what i do to the variable 'WHITE' it stays black.   Here is the code for each:   Main.py import pygame import sys import Game import CreateDisplay #####the main file##### pygame.init() if __name__ == '__main__': Game.Main() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.display.update()     Game.py   import pygame import sys import CreateDisplay #####the real main game file##### pygame.init() def Main(): while True: CreateDisplay.Display() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit()     CreateDisplay.py   import pygame import sys #####this is the file to make the screen##### pygame.init() def Display(): WHITE = (255, 255, 255) DISPLAY = pygame.display.set_mode((1024, 720))   Please help! I can't figure out what is wrong and i've been working with it for about an hour.
  4. Thanks for the help. I planned on moving all the keyboard input events into check_input() i was just testing it first. And i'm still not sure whats causing the display (or the while loops) to update.
  5. [quote name='Zed McJack' timestamp='1352400325' post='4998971'] [quote name='K1NNY' timestamp='1352399784' post='4998966'] the suggestion you gave earlier worked after i changed around some stuff. now im having problems with the most basic things in my program like switching while loops which doesnt work at all now. [/quote] Post the part that is problematic with error lines [/quote] i wish i could but it doesn't show an error. it gets the input, it just doesn't switch while loops. the code for detecting the input is in my check_input definition here: [source lang="python"]######check input definition#################################### def check_input(): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: global a print "detection" a.draw(DISPLAY) if event.key == pygame.K_F1: terminal = False inst_prgrms_scrn = True if event.key == pygame.K_F5: terminal = False slaves_scrn = True if event.key == pygame.K_SLASH: terminal = False help_page_1 = True [/source] none of these work including when i try to draw "a" to the screen, but it does detect some input because it will print "detection".
  6. [quote name='Zed McJack' timestamp='1352398720' post='4998957'] Ok, I tried. Created both files and run root.py but now i am missing textrect because i get error at the line [b]import textrect [/b] Since Letter.py is not so big file I would suggest you first try moving everything in one file till it works and then separate class letter in its own file after that. Well that was what I did in myPong and it worked. [/quote] the suggestion you gave earlier worked after i changed around some stuff. now im having problems with the most basic things in my program like switching while loops which doesnt work at all now.
  7. [quote name='Zed McJack' timestamp='1352393866' post='4998927'] Well, untill someone who really knows Python jumps in I will state the obvious, though I am beginner myself. Its not clear where do you create instances of Letter class in root.py or letter py. Leave Class code in Letter.py and move code where you create instances in main or in your case root.py and with [b]import Letter[/b] at the beginning of root.py that error should clear. But for clearing any missunderstandig post both scripts here. [/quote] I brought my objects (a, b, c) over into root.py but i get the following error message: Traceback (most recent call last): File "E:\Root\root.py", line 5, in <module> import letter File "E:\Root\letter.py", line 2, in <module> from root import * File "E:\Root\root.py", line 97, in <module> a = Letter('A', letters_x, letters_y) NameError: name 'Letter' is not defined
  8. Here is the root.py script, please excuse its sloppiness:[source lang="python"]import pygame import sys import textrect import time import letter from letter import * from ConfigParser import SafeConfigParser from pygame.locals import * pygame.init() global DISPLAY, letters_x, letters_y, insertion, terminal, help_page_1, help_page_2, inst_prgrms_scrn, slaves_scrn #DISPLAY DISPLAY = pygame.display.set_mode((640, 480)) pygame.display.set_caption('Root') #COLORS BLACK = (0, 0, 0) WHITE = (255, 255, 255) #Font font1 = pygame.font.Font('vgasys.fon', 10) ######get parser parser = SafeConfigParser() ###############################classes######################################## ######class to handle our insertion point class I_point(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([5, 16]) self.image.fill((WHITE)) self.rect = self.image.get_rect() self.rect.topleft = [x,y] def update(self): self.rect.x += self.change_y self.rect.y += self.change_x ######insertion point x and y i_x = 60 i_y = 16 ######create the insertion point using the class we made insertion = I_point( i_x,i_y ) insertion_point = pygame.sprite.RenderPlain((insertion)) ######class to handle IP's class IP_Address: def __init__(self, address, difficulty): self.address = address self.difficulty = difficulty def slaved(self): slaves = open('slaves.txt', 'a') slaves.write(self.address) slaves.close() ######class to handle all the programs class Program: def __init__(self, name, level): self.name = name self.level = level def installed(self): programs = open('installed_programs.txt', 'a') programs.write(self.name) programs.close() letters_x = insertion.rect.left letters_y = insertion.rect.top ##########import letter down here to avoid not having certain ##########things necessary in letter letters_list = pygame.sprite.RenderPlain() ######check input definition#################################### def check_input(): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: global a print "detection" a.draw(DISPLAY) if event.key != pygame.K_RETURN and event.key != pygame.K_BACKSPACE and event.key != pygame.K_ESCAPE and event.key != pygame.K_LSHIFT and event.key != pygame.K_RSHIFT and event.key != pygame.K_CAPSLOCK and event.key != pygame.K_RALT and event.key != pygame.K_LALT and event.key != pygame.K_HOME and event.key != pygame.K_F1 and event.key != pygame.K_F2 and event.key != pygame.K_F3 and event.key != pygame.K_LEFT and event.key != pygame.K_UP and event.key != pygame.K_DOWN and event.key != pygame.K_F5 and event.key != pygame.K_SLASH: insertion.rect.left += insertion.rect.width if event.key == pygame.K_RETURN: admn_y += 16 insertion.rect.top += insertion.rect.height if event.key == pygame.K_BACKSPACE and insertion.rect.x >= 65: insertion.rect.right -= insertion.rect.width if event.key == pygame.K_LEFT and insertion.rect.x >= 65: insertion.rect.right -= insertion.rect.width if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() if event.key == pygame.K_F1: terminal = False inst_prgrms_scrn = True if event.key == pygame.K_F5: terminal = False slaves_scrn = True if event.key == pygame.K_SLASH: terminal = False help_page_1 = True if event.type == QUIT: pygame.quit() sys.exit() ######admin text x and y admn_x = 0 admn_y = 16 #words admin = font1.render('::admin\>', True, WHITE) admin_rect = admin.get_rect() guest = font1.render('::guest\>', True, WHITE) guest_rect = admin.get_rect() ######help help_file_1 = open('help_1.txt').read() help_1_rect = pygame.Rect((40, 40, 640, 480)) help_1 = textrect.render_textrect(help_file_1, font1, help_1_rect, WHITE, BLACK) help_file_2 = open('help_2.txt').read() help_2_rect = pygame.Rect((40, 40, 640, 480)) help_2 = textrect.render_textrect(help_file_2, font1, help_1_rect, WHITE, BLACK) ######header header_file = open('header.txt').read() header = font1.render(header_file, True, WHITE) header_rect = header.get_rect() ######installed programs programs_file = open('installed_programs.txt').read() programs_rect = pygame.Rect((40, 40, 640, 480)) inst_programs = textrect.render_textrect(programs_file, font1, programs_rect, WHITE, BLACK) inst_programs_header = font1.render('The Programs you currently have installed', True, WHITE) ######slaves slaves_file = open('slaves.txt').read() slaves_rect = pygame.Rect((40, 40, 640, 480)) slaves = textrect.render_textrect(slaves_file, font1, slaves_rect, WHITE, BLACK) slaves_header = font1.render('The slaves you currently have control of:', True, WHITE) ######clock control clock = pygame.time.Clock() ########################ig things the player interacts with###################### ######ip's ip_1 = IP_Address('255.0.0.1', 1) slaves_making_bank = 0 ######programs passcrack_1 = Program('n00b_passCrack.bat', 1) while True: terminal = True help_page_1 = False help_page_2 = False inst_prgrms_scrn = False slaves_scrn = False while terminal: DISPLAY.fill(BLACK) DISPLAY.blit(header, (0, 0)) DISPLAY.blit(admin, (admn_x, admn_y)) insertion_point.draw(DISPLAY) check_input() pygame.display.flip() while help_page_1: DISPLAY.fill(BLACK) DISPLAY.blit(help_1, (0, 0)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_2: help_page_1 = False help_page_2 = True if event.type == QUIT: pygame.quit() sys.exit() while help_page_2: DISPLAY.fill(BLACK) DISPLAY.blit(help_2, (0, 0)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_HOME: help_page_2 = False terminal = True if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() if event.type == QUIT: pygame.quit() sys.exit() while inst_prgrms_scrn: DISPLAY.fill(BLACK) DISPLAY.blit(inst_programs_header, (0, 0)) DISPLAY.blit(inst_programs, (0, 50)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_HOME: inst_prgrms_scrn = False terminal = True if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() if event.type == QUIT: pygame.quit() sys.exit() while slaves_scrn: DISPLAY.fill(BLACK) DISPLAY.blit(slaves_header, (0, 0)) DISPLAY.blit(slaves, (0, 50)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_HOME: slaves_scrn = False terminal = True if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() if event.type == QUIT: pygame.quit() sys.exit() clock.tick(30) pygame.display.flip() [/source] Here is letter.py: [source lang="python"]import pygame from root import * pygame.init() class Letter(pygame.sprite.Sprite): def __init__(self, name, x, y): pygame.sprite.Sprite.__init__(self) self.name = name self.x = x self.y = y self.image = font1.render(self.name, True, WHITE) self.rect = self.image.get_rect() self.rect.topleft = [x,y] def update(self): self.rect.x += self.change_y self.rect.y += self.change_x def draw(self, display): self.display = display display.blit(self.image, (self.x, self.y)) global letters_x, letters_y, a a = Letter('A', letters_x, letters_y) b = Letter('B', letters_x, letters_y) c = Letter('C', letters_x, letters_y) [/source]
  9. [url="http://www.cyber-dojo.com"]http://www.cyber-dojo.com[/url] has some excercises in almost every programming language.
  10. I have a program that has the majority of a games code in it called "root.py". Needless to say, the code was getting cluttered and very large so i am trying to seperate it up into different modules. My first attempt has been completely unsuccesful because there is always some type on import error. the only other module i have is "letter.py" which has a class in it that uses parts from our main file root. in both of these, i have them importing one another (in root, i have the import letter line, and in letter i import root). They are in the same directory. the errors i keep getting involving variables within the two files. For instance, this is the class in letter: [source lang="python"]class Letter(pygame.sprite.Sprite): def __init__(self, name, x, y): pygame.sprite.Sprite.__init__(self) self.name = name self.x = x self.y = y self.image = font1.render(self.name, True, WHITE) self.rect = self.image.get_rect() self.rect.topleft = [x,y] def update(self): self.rect.x += self.change_y self.rect.y += self.change_x def draw(self, display): self.display = display display.blit(self.image, (self.x, self.y))[/source] and with it i create these: [source lang="python"]a = Letter('A', letters_x, letters_y) b = Letter('B', letters_x, letters_y) c = Letter('C', letters_x, letters_y)[/source] When i try to use "a" in root, it says it is not defined. Plus, "letters_x" and "letters_y" are found in root, and they also don't work. This is very frustrating because i thought i knew how to import modules properly. Please help.
  11. I thought hard on it overnight and fixed it this morning. Thanks for the help! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  12. Here is the full code (excluding all the text surfaces) all >= have been replaced with >: [source lang="python"]import pygame, random import sys from pygame.locals import * pygame.init() FPS = 30 fpsClock = pygame.time.Clock() #variables year = 2011 p = 50 pop = 100000 help_credits = 5 #definition time #get colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) DARKRED = (128, 0, 0) BLUE = (0, 0, 255) GREEN = (0, 255, 0) #get display stuff DISPLAY = pygame.display.set_mode((640,480)) pygame.display.set_caption('UTOPIA') pygame.mouse.set_visible(True) #create fonts fontObj1 = pygame.font.Font('freesansbold.ttf', 16) fontObj2 = pygame.font.Font('freesansbold.ttf', 12) #make words #get images title = pygame.image.load('title.png') stitle = pygame.transform.scale(title, (264, 64)) bg = pygame.image.load('bg.png') sbg = pygame.transform.scale(bg, (640, 480)) gbg = pygame.image.load('Game_bg.png') help_bg_root = pygame.image.load('help_bg.png') help_bg = pygame.transform.scale(help_bg_root, (640, 480)) #Menu screen start_screen = True while start_screen: DISPLAY.blit(sbg, (0, 0)) DISPLAY.blit(stitle, (188, 10)) DISPLAY.blit(textObj1, RectObj1) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: start_screen = False instructions = True if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() #################################Game loop###################################### #Main Loop while True: if help_credits > 1: help_events = True elif help_credits == 0: help_events = False while instructions: DISPLAY.blit(sbg, (0, 0)) DISPLAY.blit(instructions_1, (100, 36)) DISPLAY.blit(instructions_2, (9, 54)) DISPLAY.blit(instructions_3, (175, 72)) DISPLAY.blit(instructions_4, (85, 100)) DISPLAY.blit(instructions_5, (78, 118)) DISPLAY.blit(instructions_6, (40, 136)) DISPLAY.blit(instructions_7, (260, 154)) DISPLAY.blit(instructions_8, (310, 154)) DISPLAY.blit(instructions_9, (350, 154)) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: instructions = False game = True if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() elect_new = False lower_int = False cut_taxes = False while game: x = random.randint(1, 10) y = random.randint(1, 3) show_year = fontObj1.render(str(year), True, BLACK) show_pop = fontObj1.render(str(pop), True, BLACK) DISPLAY.blit(gbg, (0, 0)) DISPLAY.blit(controls_1, (225, 50)) DISPLAY.blit(controls_2, (225, 66)) DISPLAY.blit(controls_3, (225, 82)) DISPLAY.blit(controls_4, (225, 100)) for event in pygame.event.get(): #the pplrty determiner if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: year += 1 print year print x print p DISPLAY.blit(show_year, (563, 400)) DISPLAY.blit(show_pop, (400, 400)) if x == 1: DISPLAY.blit(events_1, (45, 50)) DISPLAY.blit(events_1_2, (45, 66)) DISPLAY.blit(events_1_3, (45, 82)) p += 2 if x == 2: DISPLAY.blit(events_2, (45, 50)) DISPLAY.blit(events_2_2, (45, 66)) DISPLAY.blit(events_2_3, (45, 82)) p -= 2 if x == 3: DISPLAY.blit(events_3, (45, 50)) DISPLAY.blit(events_3_2, (45, 66)) DISPLAY.blit(events_3_3, (45, 82)) p -= 3 if x == 4: DISPLAY.blit(events_4, (45, 50)) DISPLAY.blit(events_4_2, (45, 66)) DISPLAY.blit(events_4_3, (45, 82)) DISPLAY.blit(events_4_4, (45, 98)) DISPLAY.blit(events_4_5, (45, 114)) DISPLAY.blit(events_4_6, (45, 130)) p -= 5 if x == 5: DISPLAY.blit(events_5, (45, 50)) DISPLAY.blit(events_5_2, (45, 66)) p -= 5 if x == 6: DISPLAY.blit(events_6, (45, 50)) DISPLAY.blit(events_6_2, (45, 66)) DISPLAY.blit(events_6_3, (45, 82)) DISPLAY.blit(events_6_4, (45, 98)) DISPLAY.blit(events_6_5, (45, 114)) p -= 4 if x == 7: DISPLAY.blit(events_7, (45, 50)) DISPLAY.blit(events_7_2, (45, 66)) DISPLAY.blit(events_7_3, (45, 82)) DISPLAY.blit(events_7_4, (45, 98)) p -= 4 if x == 8: DISPLAY.blit(events_8, (45, 50)) DISPLAY.blit(events_8_2, (45, 66)) p -= 2 if x == 9: DISPLAY.blit(events_9, (45, 50)) DISPLAY.blit(events_9_2, (45, 66)) DISPLAY.blit(events_9_3, (45, 82)) DISPLAY.blit(events_9_4, (45, 98)) p -= 6 if x == 10: DISPLAY.blit(events_10, (45, 50)) DISPLAY.blit(events_10_2, (45, 66)) DISPLAY.blit(events_10_3, (45, 82)) p += 0 if p > 50 and p < 60: DISPLAY.blit(pplrty_decent, (225, 400)) pop += 10000 elif p > 60 and p < 85: DISPLAY.blit(pplrty_good, (230, 400)) pop += 30000 elif p > 85 and p < 100: DISPLAY.blit(pplrty_great, (230, 400)) pop += 50000 elif p > 25 and p < 50: DISPLAY.blit(pplrty_bad, (225, 400)) pop -= 10000 elif p < 25: DISPLAY.blit(pplrty_awful, (225, 400)) pop -= 30000 pygame.display.update() if event.type == QUIT: pygame.quit() sys.exit() while help_events: if p < 15 and y == 1: game = False elect_new = True elif p < 15 and y == 2: game = False lower_int = True elif p < 15 and y == 3: game = False cut_taxes = True while elect_new: DISPLAY.blit(help_bg, (0, 0)) DISPLAY.blit(elect_1, (165, 75)) DISPLAY.blit(elect_2, (165, 93)) DISPLAY.blit(elect_3, (165, 111)) DISPLAY.blit(yes, (300, 350)) DISPLAY.blit(under, (300, 350)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_y: DISPLAY.blit(enter, (285, 370)) p += 30 help_credits -= 1 elect_new = False game = True if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() while lower_int: DISPLAY.blit(help_bg, (0, 0)) DISPLAY.blit(elect_1, (165, 75)) DISPLAY.blit(lower_int_1, (165, 93)) DISPLAY.blit(lower_int_2, (165, 111)) DISPLAY.blit(lower_int_3, (165, 129)) DISPLAY.blit(yes, (300, 350)) DISPLAY.blit(under, (300, 350)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_y: DISPLAY.blit(enter, (285, 370)) p += 30 help_credits -= 1 lower_int = False game = True if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() while cut_taxes: DISPLAY.blit(help_bg, (0, 0)) DISPLAY.blit(elect_1, (165, 75)) DISPLAY.blit(cut_taxes_1, (165, 93)) DISPLAY.blit(cut_taxes_2, (165, 111)) DISPLAY.blit(cut_taxes_3, (165, 129)) DISPLAY.blit(yes, (300, 350)) DISPLAY.blit(under, (300, 350)) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_y: DISPLAY.blit(enter, (285, 370)) p += 30 help_credits -= 1 cut_taxes = False game = True if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() [/source]
  13. This worked perfectly until i tried implementing a new part of the game. I need it to be able to control how many times it can access "elect_new". I tried this: [source lang="python"]help_credits = 5 while True: while game: if help_credits >= 1: help_events = True elif help_credits == 0: help_events = False [/source] [source lang="python"] while help_events: if p < 15 and y == 1: game = False elect_new = True elif p < 15 and y == 2: game = False lower_int = True elif p < 15 and y == 3: game = False cut_taxes = True[/source] Of course i cut out most of the code only leaving in the new parts i added. Using this, the program just hangs and becomes unresponsive. (sorry for it being in two parts again, look at it like one piece of code because the code segment insert thing isn't working for me at all) CORRECTION: The program doesn't go to the "elect_new" loop at all now using this.
  14. They are not in a while a loop, they are on their own. So i should put them in a while loop? Should i put them in my main loop? because it is just sitting at the bottom doing nothing.
  15. This was an accidental post and i cant delete it.