|
Programming Guru
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 
|
That's wierd...I put it in a different stand alone program, and it worked. I don't know what makes it any different then in the program I wrote it in...
Here's the entire code that's needed to run it from battle_screen.py
battle_screen
#
import random
import pygame
pygame.font.init()
from game_settings import*
#
def figure_exp(lvl):
experience = 0
for a in range(1, lvl+1):experience += (a/2*500 + a*10)
b = str(experience)
return b
def check_status(party, enemy, status):
if int(party[0][3])< 1:
status = "dead"
elif enemy[2] < 1:
status = "e_dead"
else: status = status
return status
def enemy_turn(dec, party, enemy, screen):
if dec == "run":
status = "e_run"
print "Enemy Ran Away!"
##animation & print results of run
elif dec == "attack":
party[0][3] = party[0][3] - ( enemy[4] + random.randrange(-enemy[1], +enemy[1]) - party[0][7]/enemy[1]+random.randrange(0, party[0][1]))
status="0"
print party[0][3]
print "Enemy Attack!"
##animation & print results of attack
##allow random interval of magic use for enemy, unless not allowed by area
elif dec == "item":
print "poo"
else: status="0"
return status, party, enemy
def your_turn(dec, party, enemy, screen):
if dec == "run":
for a in range(party[0][9]*500):
b = random.randrange(0, (party[0][9]-enemy[1])*500)
if a == b:status="run";break
else:status="0"
return status, party, enemy
def battle(party, enemy, area):
screen = video_settings()
status = "0"
##create screen
##create background based on area variable
##load music, random, based on area
if party[0][8] < (enemy[6]+1):
turn = "enemy"
else:
turn = "you"
battle_return = 0
while battle_return == 0:
#Turk = [name, lvl, maxhp, curhp, maxmp, curmp, str, defn, agi, luck, accuracy, exp, weapon, armor, magic]
#enemy = [name, e_lvl, e_hp, e_mp, e_str, e_defn, e_agi, e_luck, magic
def draw_HP(party, enemy, screen, percent):
for a in range(2, percent-1):
if a%2 == 0:
pygame.draw.rect(screen, (0, 0, (percent-a+50) ), ((235+a, 296), (0, 13)), 0)
else:
pygame.draw.rect(screen, (0, 0, (a+50) ), ((235+a, 296), (0, 13)), 0)
font=pygame.font.Font(None,14)
b = "HP: "+party[0][3]+" / "+party[0][2]
text=font.render(b,2,(0,0,0))
screen.blit(text, (240, 323))
def draw_MP(party, enemy, screen, percent):
for a in range(2, percent-1):
if a%2 == 0:
pygame.draw.rect(screen, ((percent-a+50), (percent-a+50), 0), ((335+a, 314), (0, 5)), 0)
else:
pygame.draw.rect(screen, ((a+50), (a+50), 0), ((335+a, 314), (0, 5)), 0)
font=pygame.font.Font(None,14)
b = "MP: "+party[0][5]+" / "+party[0][4]
text=font.render(b,2,(0,0,0))
screen.blit(text, (340, 323))
def draw_EXP(party, enemy, screen, percent):
for a in range(2, percent-1):
if a%2 == 0:
pygame.draw.rect(screen, ((percent-a+50), (percent-a+50), (percent-a+50)), ((235+a, 314), (0, 5)), 0)
else:
pygame.draw.rect(screen, ((a+50), (a+50), (a+50)), ((235+a, 314), (0, 5)), 0)
font=pygame.font.Font(None,14)
EXPneed = figure_exp(lvl+1)
b = "EXP: "+party[0][11]+" / "+EXPneed
text=font.render(b,2,(0,0,0))
screen.blit(text, (240, 323))
def draw_battle(party, screen, enemy):
window = pygame.image.load("window.png");gamescreen = pygame.image.load("gamescreen.bmp");draw_windows(gamescreen, window, "battle", screen, party)
pygame.draw.rect(screen, (0, 0, 0), ((235, 295), (149, 15)), 0)
percent = 150/int(party[0][2])*int(party[0][3])
draw_HP(party, enemy, screen, percent)
percent = 50/int(party[0][4])*int(party[0][5])
pygame.draw.rect(screen, (0, 0, 0), ((335, 313), (49, 6)), 0)
draw_MP(party, enemy, screen, percent)
EXPneed = figure_exp(lvl+1)
percent = 80/EXPneed*int(party[0][11])
pygame.draw.rect(screen, (0, 0, 0), ((235, 313), (80, 6)), 0)
draw_EXP(party, enemy, screen, percent)
if turn == "enemy":
print "Enemy's turn"
if area[5] == "1":status, party, enemy = enemy_turn("attack", party,enemy, screen)
elif area[5] == "2":
if random.randrange(1,15)==7:status,party,enemy = enemy_turn("run", party,enemy, screen)
else:status,party,enemy = enemy_turn("attack", party,enemy, screen)
elif area[5] == "3":status, party, enemy = enemy_turn("attack", party,enemy, screen)
elif area[5] == "4":status, party, enemy = enemy_turn("attack", party,enemy, screen)
draw_battle(party, screen, enemy);turn = "you"
if status != "0":
battle_return = 1
status = check_status(party, enemy, status)
if status != "0":
battle_return = 1
if turn == "you":
print "Your turn"
choice = "none"
choicea = "none"
cursorX=310
cursorY=350
font=pygame.font.Font(None,14)
text=font.render("Attack",2,(0,0,0))
texta=font.render("Switch",2,(0,0,0))
textb=font.render("Item",2,(0,0,0))
textc=font.render("Run",2,(0,0,0))
textpos=(320, 350)
textapos=(370, 350)
textbpos=(420, 350)
textcpos=(470, 350)
while choice == "none":
pygame.draw.rect(screen, (255, 255, 255), ((0, 0), (800, 700)), 0)
screen.blit(text,textpos)
screen.blit(texta,textapos)
screen.blit(textb,textbpos)
screen.blit(textc,textcpos)
cursor=pygame.image.load("cursor_.bmp")
screen.blit(cursor,(cursorX, cursorY))
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_UP:
choice = "none"
elif event.key == K_DOWN:
choice = "none"
elif event.key == K_LEFT:
if cursorX!=310:cursorX=cursorX-50
elif event.key == K_RIGHT:
if cursorX!=460:cursorX=cursorX+50
elif event.key == K_RETURN:
decision = (cursorX-310)/50
if decision == 0:
choicea = "none"
cursorX=310
cursorY=350
font=pygame.font.Font(None,14)
text=font.render("Weapon",2,(0,0,0))
texta=font.render("Magic",2,(0,0,0))
textb=font.render("Special",2,(0,0,0))
textc=font.render("Back",2,(0,0,0))
textpos=(320, 350)
textapos=(370, 350)
textbpos=(420, 350)
textcpos=(470, 350)
while choicea == "none":
pygame.draw.rect(screen, (255, 255, 255), ((0, 0), (800, 700)), 0)
screen.blit(text,textpos)
screen.blit(texta,textapos)
screen.blit(textb,textbpos)
screen.blit(textc,textcpos)
cursor=pygame.image.load("cursor_.bmp")
screen.blit(cursor,(cursorX, cursorY))
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_UP:
choice = "none"
elif event.key == K_DOWN:
choice = "none"
elif event.key == K_LEFT:
if cursorX!=190:cursorX=cursorX-50
elif event.key == K_RIGHT:
if cursorX!=340:cursorX=cursorX+50
elif event.key == K_RETURN:
decisiona = (cursorX-310)/50
print decisiona
if decisiona == 3:
cursorX=310
cursorY=350
font=pygame.font.Font(None,14)
text=font.render("Attack",2,(0,0,0))
texta=font.render("Switch",2,(0,0,0))
textb=font.render("Item",2,(0,0,0))
textc=font.render("Run",2,(0,0,0))
textpos=(320, 350)
textapos=(370, 350)
textbpos=(420, 350)
textcpos=(470, 350)
choicea = "back"
draw_battle(party, screen, enemy)
pygame.display.flip()
elif decision == 3:
status, party, enemy = your_turn("run", party, enemy, screen)
if status == "run":choice = "run"
else:print "Run Failed";choice = "gone"
draw_battle(party, screen, enemy)
pygame.display.flip()
choice = "none"
choicea = "none"
turn = "enemy"
if status != "0":
battle_return = 1
status = check_status(party, enemy, status)
if status != "0":
battle_return = 1
if status == "run":
print "You ran away"
#print enemy
#print party
#print status
##
##return party variable
#########################################
name="Turk"
lvl = 5
maxhp = "30"
curhp = "30"
maxmp = "5"
curmp = "5"
str = 12
defn = 8
agi = 7
luck = 9
accuracy = 7
exp = figure_exp(lvl)
weapon = "Rusty Sword"
armor = "Rusty Armor"
magic = ["ice"]
Turk = [name, lvl, maxhp, curhp, maxmp, curmp, str, defn, agi, luck, accuracy, exp, weapon, armor, magic]
party = [Turk]
area = "area_2"
def average_enemy_stats(name, e_lvl, e_hp, e_mp, e_str, e_defn, e_agi, e_luck, e_acc, magic):
enemy = [name, e_lvl, e_hp, e_mp, e_str, e_defn, e_agi, e_luck, e_acc, magic]
return enemy
e_lvl = (random.randrange(1,3))
enemy = average_enemy_stats( "Goblin",
(random.randrange(1,3)),
(((e_lvl + 5) * 2) + random.randrange(0, 3)),
(0),
((e_lvl) * 2),
((e_lvl) * 2) + random.randrange(-2, 2),
((e_lvl) * 2) + random.randrange(-2, 4),
((e_lvl) * 2) + random.randrange(-3, 1),
((e_lvl) +30) / 10 + random.randrange(0, e_lvl),
["fire"])
battle(party, enemy, area)
#########################################
game_settings
import os, pygame, time
from pygame.locals import *
from quit_game import *
if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'
def load_image(name, colorkey=None):
fullname = os.path.join('', name)
try:
image = pygame.image.load(fullname)
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()
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('sound', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', fullname
raise SystemExit, message
return sound
def video_settings():
pygame.init()
pygame.display.set_caption('Soulodine v 0.2')
screen = pygame.display.set_mode((800, 500))
pygame.mouse.set_visible(0)
return screen
def draw_windows(gamescreen, window, active, screen, party):
if active == "area":
pygame.draw.rect(screen, (0, 0, 0), ((0, 0), (800, 123)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((0, 0), (211+7, 500)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((0, 382), (800, 500)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((580+4, 0), (800, 500)), 0)
screen.blit(gamescreen, (50+7, 123) )
screen.blit(gamescreen, (600+7, 123) )
screen.blit(window, (210+5, 122) )
elif active == "battle":
pygame.draw.rect(screen, (0, 0, 0), ((0, 0), (800, 123)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((0, 0), (211+7, 500)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((0, 382), (800, 500)), 0)
pygame.draw.rect(screen, (0, 0, 0), ((580+4, 0), (800, 500)), 0)
screen.blit(gamescreen, (50+7, 123) )
screen.blit(gamescreen, (600+7, 123) )
screen.blit(window, (210+5, 122) )
font=pygame.font.Font(None,22)
text=font.render(party[0][0],2,(255,255,255))
chara=pygame.image.load(party[0][0]+".png")
font=pygame.font.Font(None,14)
text1=font.render("Level:",2,(255,255,255));screen.blit(text1, (75, 190+20))
text2=font.render("Strength:",2,(255,255,255));screen.blit(text2, (75, 190+40))
text3=font.render("Defense:",2,(255,255,255));screen.blit(text3, (75, 190+60))
text4=font.render("Agility:",2,(255,255,255));screen.blit(text4, (75, 190+80))
text5=font.render("Accuracy:",2,(255,255,255));screen.blit(text5, (75, 190+100))
text6=font.render("Luck:",2,(255,255,255));screen.blit(text6, (75, 190+120))
text1=font.render(str(party[0][1]),2,(255,255,255));screen.blit(text1, (155, 190+20))
text2=font.render(str(party[0][6]),2,(255,255,255));screen.blit(text2, (155, 190+40))
text3=font.render(str(party[0][7]),2,(255,255,255));screen.blit(text3, (155, 190+60))
text4=font.render(str(party[0][8]),2,(255,255,255));screen.blit(text4, (155, 190+80))
text5=font.render(str(party[0][10]),2,(255,255,255));screen.blit(text5, (155, 190+100))
text6=font.render(str(party[0][9]),2,(255,255,255));screen.blit(text6, (155, 190+120))
screen.blit(chara, (70, 135))
screen.blit(text, (130, 148))
quit_game
from game_settings import *
import random, sys
def load_image(name, colorkey=None):
fullname = os.path.join('', name)
try:
image = pygame.image.load(fullname)
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()
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('sound', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', fullname
raise SystemExit, message
return sound
class logo_jdi_2(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('logo_jdi_2.bmp')
self.rect.topleft = 325, 320
def quit_game():
time.sleep(3.5)
pygame.font.init()
while 1:
pygame.init()
screen = pygame.display.set_mode((800, 700))
pygame.display.set_caption('Soulodine v 0.2')
pygame.mouse.set_visible(1)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 0))
layer1 = logo_jdi_2()
layers = pygame.sprite.RenderPlain((layer1))
layers.update()
font = pygame.font.Font(None, 40)
font_2 = pygame.font.Font(None, 20)
text = font.render("Thankyou for Playing Soulodine", 2, (250, 250, 250))
text_2 = font_2.render("www.JDI.coms.ph", 1, (250, 250, 250))
textpos = (195, 170)
textpos_2 = (650, 650)
background.blit(text, textpos)
background.blit(text_2, textpos_2)
screen.blit(background, (0, 0))
layers.draw(screen)
pygame.display.flip()
sound1 = load_sound('game_over.wav')
sound1.play()
time.sleep(9)
sound1.fadeout(2000)
background.fill((0, 0, 0))
sys.exit()
return
Edit: Oh crap, you need the images too. Well if you can't figure out what's wrong by looking at it
(it returns this error:
Traceback (most recent call last):
File "C:\Documents and Settings\Owner\My Documents\Soulodine\battle_screen.py", line 255, in -toplevel-
exp = figure_exp(lvl)
File "C:\Documents and Settings\Owner\My Documents\Soulodine\battle_screen.py", line 11, in figure_exp
b = str(experience)
TypeError: 'int' object is not callable
), then I'll send you the images or something.
|