[Tutor] Issue With a Python Game

2013-04-14 Thread John Bochicchio
I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noahpython nickeladventuredemo.py
Traceback (most recent call last):
  File nickeladventuredemo.py, line 451, in module
main()
  File nickeladventuredemo.py, line 78, in main
levels = readLevelsFile('levels.txt')
  File nickeladventuredemo.py, line 371, in readLevelsFile
assert startx != None  and starty!= None, 'Level %s (around line %s) in
%s i
s missing a @ or + to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a @ or
+ t
o mark the start point.

The error has something to do with the levels. I will attach the code and
levels, as they are fairly long.

-- 
A computer without a Microsoft operating system is like a dog without
bricks tied to its head.
; Starting demo level:
 
##  #
#   .   #
#   $   #
# .$@$. #
$   #
   #.   #
   #   ##
   #

; 1

   ###
  ## # 
 ##  ###  #
## $  #
#   @$ #  #
### $###  #
  #  #..  #
 ## ##.# ##
 #  ##
 # ##
 ###

; 2

 ## #
## ## . #
# ## $. #
 ## $   #
## $@ ###
# $  ##
#.. ## ##
#   # ##
# #

; 3

   #
  ##   #
  ##
  # $ ##
#  $ $#
# $ $ #
   ## ## $ $ $#
   #  .#  $ $ #
   #  .#  #
# #
# @  #
##
##  ##
 

; 4

  ###
 ## #  @#
### $ $$#   #
# ##$$$ #
#  #  $ #   #
## ##
#.. ..$ #*##
# ..###
#  ..#
#

; 5

  ###
 #####
### $ $#$ $ ###
# #$ $ # $ $# #
# $  ..#..  $ #
#  $...#...$  #
# $ .. * .. $ #
## @ ##
# $ ..   .. $ #
#  $...#...$  #
# $  ..#..  $ #
# #$ $ # $ $# #
### $ $#$ $ ###
 #####
  ###

; 6

  ###
###.  .$.  .###
 ## $  $  $ ##
  ## ..$.. ##
   ##$#$#$##
#.$ $.#
#  @  #
### ###
   ## $ $ ##
   #.  $  .#
   ### . ###
 #

; 7

   ##
  ###
  ###  #  #  ## ###
### #   $ #
#  $ @ ...*..  $  #
# $ $  ## ###   ###
### ###   # #
 #  ###
 #   
 #

; 8

###
# ##
# ###  ##
#   #  ##
#@$***. ##$ #
#  ### .#
##  ##  # $ #
 ##  .$.#
  ###
   ##  ##


; 9

#
#. .#
#.$. .  #
## ###@ #
 #  $  ##
 # $$ ##
 #  $ #
 #  ###
 

; 10

  ##
  ##
  # @  ###
  #  #
#  ..#.#$#
# $ $ ##...  #
# .#$$   #
## ##$## #
 #  $#
  
   #  #
   #  #
 ### $#
 #  $ $   #
 # #$# 
 # #
 ###

; 11

  
###  
#   @   ##
# #. .#.###
# $$$ $$$ #
###.#.#.# #
 ##   #
    ###
 

; 12

  #
  #   #
# #   ###
#   # #   . #
# # ##  # # # # #
# $ $ $ $ $ # ##   ## $ #
# # ##.. ### $$ ###
#  ## * ## #  $$  #
##+$$   ## #  #
 #.$ $# #  
 #.##   #
 

; 13

   ###
 ### ##
 #   ###  #
 #  # #
###$#@  # #
#   # #
#   #  *. #
##$$#  *.##
 # *..#
  #...##
# #$$$ #
#   $  #
#  #


; 14

 ###
## # #
#  *.$.#
#  *.#.###
# #$@$$  #
#   ## # #
##   #
 #

; 15

   
   #@ #
  ##  #
  # .$#
  #$. #
###..$###
#  ..$  #
# $ $ # #
# # #
#   #
#

; 16

  ##
 ## #  ###
## #   # ##
# #   $.# #
##  $ $.# #
# #. ##
# $. @#
# $. 
### # #*# # ###
   .$ #
#  .$ #
## .# #
# #.$ $  ##
# #.$   # #
## #   # ##
 ###  # ##
   ##

; 17

###
   ## . . . . ###
   #  $$ $ $ $  #
   #    # #
  ##  $ # #   #
 ##  $ $ #  ### # #
##  # #    $  #
#...  # $   ###
#... @ $ ##
#... $  $ #
#  #  #
   

; 18


#  #
#  #
#$ $ $ #
#.*.*.*#
#*.*.*.#
# $ $ $#
#..#
#.*.*.*#
#$ $ $ #
# $ $ $#
#$ $ $ #
#  #
#@ #


; 19

#
#   ###
#  $  ##
## ##  ##
 # ## # 
 # # ##$   ##
 # #.   #@## $  ##
 # #.#  ##### $  ##
 # #.#  ## $  ##
 # #.#   #  ##   ## $  ##
## #.#  ##  ###   ## $  #
#  #.#   #  #*##   ##   #
#   .# # #  ##*##   #
##   #  ##
 #

; 20

 
 #  #
##$.#
#   $ $.#
# $@$...#
# $$$..##
#  $ ..#


; 21

# 
#   ### . $  #
#   $ *.. #$ ##
## $# ..* $  @#
 #  $ . ###   #
  #

; 22

   # 
   #@ .###  ###
  $$ $#
#   # . . ##  #
#  $ # . . ## #
## .  $ $$  # #
 # #  ###.  # #
 #  # #
 #   ##
 ### # 
   # .$ #
    #
 ## #
  ###

; 23

 ###
## ##
#  . ..$#$.. .  #
#  $ $  .  $ $  #
###$@$###
#  $ $  .  $ $  #
#  . ..$#$.. .  #
## ##
 ###

; 

[Tutor] Issue With a Python Game

2013-04-14 Thread John Bochicchio
I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noahpython nickeladventuredemo.py
Traceback (most recent call last):
  File nickeladventuredemo.py, line 451, in module
main()
  File nickeladventuredemo.py, line 78, in main
levels = readLevelsFile('levels.txt')
  File nickeladventuredemo.py, line 371, in readLevelsFile
assert startx != None  and starty!= None, 'Level %s (around line %s) in
%s i
s missing a @ or + to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a @ or
+ t
o mark the start point.

The Code:

import random, sys, copy, os, pygame

from pygame.locals import *



FPS = 30

WINWIDTH = 800

WINHEIGHT = 600

HALF_WINWIDTH = int(WINWIDTH / 2)

HALF_WINHEIGHT = int(WINHEIGHT / 2)



TILEWIDTH = 50

TILEHEIGHT = 85

TILEFLOORHEIGHT = 45



CAM_MOVE_SPEED = 5



OUTSIDE_DECORATION_PCT = 20



BRIGHTBLUE = ( 0, 170, 255)

WHITE  = (255, 255, 255)

BGCOLOR = BRIGHTBLUE

TEXTCOLOR = WHITE



UP = 'up'

DOWN = 'down'

LEFT = 'left'

RIGHT = 'right'





def main():

global FPSCLOCK, DISPLAYSURF, IMAGESDICT, TILEMAPPING,
OUTSIDECOMAPPING, BASICFONT, PLAYERIMAGES, currentImage



pygame.init()

FPSCLOCK = pygame.time.Clock()



DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT))



pygame.display.set_caption('Noah Nickel Adventure!')

BASICFONT = pygame.font.Font('freesansbold.ttf', 18)



IMAGESDICT = {'uncovered goal': pygame.image.load('RedSelector.png'),

  'covered goal': pygame.image.load('Selector.png'),

  'star': pygame.image.load('Star.png'),

  'corner': pygame.image.load('Wall Block Tall.png'),

  'wall': pygame.image.load('Wood Block Tall.png'),

  'inside floor': pygame.image.load('Plain Block.png'),

  'outside floor': pygame.image.load('Grass Block.png'),

  'title': pygame.image.load('star_title.png'),

  'solved': pygame.image.load('star_solved.png'),

  'princess': pygame.image.load('princess.png'),

  'boy': pygame.image.load('boy.png'),

  'catgirl': pygame.image.load('catgirl.png'),

  'horngirl': pygame.image.load('horngirl.png'),

  'pinkgirl': pygame.image.load('pinkgirl.png'),

  'rock': pygame.image.load('Rock.png'),

  'short tree': pygame.image.load('Tree_Short.png'),

  'tall tree': pygame.image.load('Tree_Tall.png'),

  'ugly tree': pygame.image.load('Tree_Ugly.png')}



TILEMAPPING = {'X': IMAGESDICT['corner'],

   '#': IMAGESDICT['wall'],

   'o': IMAGESDICT['inside floor'],

   ' ': IMAGESDICT['outside floor']}



OUTSIDECOMAPPING = {'1': IMAGESDICT['rock'],

'2': IMAGESDICT['short tree'],

'3': IMAGESDICT['tall tree'],

'4': IMAGESDICT['ugly tree']}

#Super important to remember:

#DEAR GOD REMEMBER THIS IS AN INDEX OF PLAYER IMAGES.

currentImage = 0

PLAYERIMAGES = [IMAGESDICT['princess'],

IMAGESDICT['boy'],

IMAGESDICT['catgirl'],

IMAGESDICT['horngirl'],

IMAGESDICT['pinkgirl']]

startScreen()



levels = readLevelsFile('levels.txt')

currentLevelIndex = 0



while True:

result = runLevel(levels, currentLevelIndex)



if result in ('solved', 'next'):

currentLevelIndex += 1

if currentLevelIndex = len(levels):

currentLevelIndex = 0



elif result == 'back':

currentLevelIndex -= 1

if currentLevelIndex 0:

currentLevelIndex = len(levels)-1



elif result == 'reset':

pass





def runLevel(levels, levelNum):

global currentImage

level0bj = levels[levelnum]

map0bj = decorateMap(level0bj['map0bj'],
level0bj['startState']['player'])

gameState0bj = copy.deepcopy(level0bj['startState'])

mapNeedsRedraw = True

levelSurf = BASICFONT.render('Level %s of %s' % (level0bj['levelNum']
+1, totalNumOfLevels), 1, TEXTCOLOR)

levelRect = levelSurf.get_rect()

levelRect.bottomleft = (20, WINHEIGHT - 35)

mapWidth = len(map0bj) * TITLEWIDTH

mapHeight = (len(map0bj[0]) - 1) * (TITLEHEIGHT - TILEFLOORHEIGHT) +
TILEHEIGHT

MAX_CAM_X_PAN = abs(HALF_WINHEIGHT - int(mapHeight / 2)) + TILEWIDTH

MAX_CAM_Y_PAN = abs(HALF_WINWIDTH - int(mapWidth / 2)) + TILEHEIGHT



levelIsComplete = False

camera0ffsetX = 0

camera0ffsety = 0

cameraUp = False

cameraDown = False

cameraLeft = False

cameraRight = False



while True:

   

Re: [Tutor] Issue With a Python Game

2013-04-14 Thread Mark Lawrence

On 13/04/2013 14:13, John Bochicchio wrote:

I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noahpython nickeladventuredemo.py
Traceback (most recent call last):
   File nickeladventuredemo.py, line 451, in module
 main()
   File nickeladventuredemo.py, line 78, in main
 levels = readLevelsFile('levels.txt')
   File nickeladventuredemo.py, line 371, in readLevelsFile
 assert startx != None  and starty!= None, 'Level %s (around line
%s) in %s i
s missing a @ or + to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a @
or + t
o mark the start point.

The Code:
import random, sys, copy, os, pygame



I've stripped the remaining 450 lines of code as it's got the dread 
double spaced google disease, please see my signature.  You're also far 
more likely to get responses if your question follows the guidelines 
given here http://www.sscce.org/, particularly if someone already has 
pygame installed, which I don't.


However I did note one area where you can simplfy your code.  You've 
many lines using this type of construct.


for i in range(len(ships)):
doSomething(ships[i])

There's rarely a need for this in Python.  Use this instead.

for ship in ships:
doSomething(ship)

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue With a Python Game

2013-04-14 Thread Walter Prins
Hi John,

On 10 April 2013 15:21, John Bochicchio luckytsuk...@gmail.com wrote:

 I have a question about a game I am making. I finished the overall code,
 but keep getting errors when I try to play. This is my most common error:
 C:\Users\John\Documents\Python Games\Noahpython nickeladventuredemo.py
 Traceback (most recent call last):
   File nickeladventuredemo.py, line 451, in module
 main()
   File nickeladventuredemo.py, line 78, in main
 levels = readLevelsFile('levels.txt')
   File nickeladventuredemo.py, line 371, in readLevelsFile
 assert startx != None  and starty!= None, 'Level %s (around line %s)
 in %s i
 s missing a @ or + to mark the start point.' % (levelNum+1, lineNum,
 filenam
 e)
 AssertionError: Level 1 (around line 10) in levels.txt is missing a @ or
 + t
 o mark the start point.

 The error has something to do with the levels. I will attach the code and
 levels, as they are fairly long.


Firstly please next time include a segment of the failing code in the email
-- not everyone is prepared to or can be bothered to download and wade
through a large source file just to get to the bottom of an program error.

Secondly, re your your first assertion statement: it assumes that the
problem is due to a problem in the levels.txt file, which is not the case
here.  You'd do better IMHO to maybe not be so creative/presumptuous with
 the error message, and rather have it report exactly what the actual
assertion conditions (and maybe variable values at the time) is that failed
(in this case values of startx, starty.)   You might also consider rather
using Exceptions here.

All that said, the problem is you have the code throwing the exception at
the wrong level of indent.  You need to de-indent all the assert statements
as well as the code that follows up to but excluding the return statement
so that it's at the same level of the first for loop.  (Differently put,
the reason the assertion is likely failing is because you're doing your
asserts before the loops have finished processing/reading your mapObj. You
presumably want the asserts once the mapObj's been finished processing by
the loop.)

As an aside,  the next failure you'll likely run into is the third assert,
which expects len(stars) = len(goals), which I assume will fail as you are
not reading anything into stars list anywhere as you do for  goals.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor