We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys, i'm trying to make a mario Game with processingand(python mode) and i have a few questions. To make it easier for me I have my map saved as .txt file which looks like that:
00000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000
0=air _=grass -=dirt/stone
Now i have a function which reads this file and builds the map after that which is named worldloader(). Do i need to make a for lood for every line?/is there a way to compress that into two for loops?
Second question when I try to make my mario move with four pictures the pictures run firstly too fast and secondly they are all shown at the same time. How can I avoid this problem?
from time import sleep
txt = open("welt_grundausstattung.txt")
level = txt.read()
print len(level)
sp = level.splitlines()
line1 = sp[0]
line2 = sp[1]
line3 = sp[2]
line4 = sp[3]
line5 = sp[4]
line6 = sp[5]
line7 = sp[6]
line8 = sp[7]
line9 = sp[8]
line10 = sp[9]
line11 = sp[10]
line12 = sp[11]
line13 = sp[12]
line14 = sp[13]
line15 = sp[14]
line16 = sp[15]
line17 = sp[16]
line18 = sp[17]
line19 = sp[18]
line20 = sp[19]
line21 = sp[20]
line22 = sp[21]
line23 = sp[22]
Counter=0
mar0= loadImage("Standing-mario.png")
mar1= loadImage("mov1.png")
mar2= loadImage("mov2.png")
mar3= loadImage("mov3.png")
mar4= loadImage("mov4.png")
gr = loadImage("Grass.png")
di = loadImage("Ground.png")
print(line22)
print(line22[2:3])
def setup():
size( 1280 , 720 )
background(0,204,0)
mariost(612)
frameRate(30)
def draw():
global Counter
a=0
b=0
worldloader(0)
if keyPressed:
if key=="w":
print("w")
if key=="a":
print("a")
if key=="s":
print("s")
if key=="d":
print("d")
if Counter==0:
mario1(612)
Counter=Counter+1
elif Counter==5:
mario2(612)
counter=Counter+1
elif Counter==10:
mario3(612)
Counter=Counter+1
elif Counter==15:
mario4(612)
Counter=0
if key!="w" or key!="a" or key!="s" or key!="d":
mariost(612)
print("NOTHING")
Counter=0
def mariost(y):
image(mar0,96,y)
def mario1(y):
image(mar1,96,y)
def mario2(y):
image(mar2,96,y)
def mario3(y):
image(mar3,96,y)
def mario4(y):
image(mar4,96,y)
def grass(x,y):
image(gr,x,y)
def dirt(x,y):
image(di,x,y)
def air(x,y): # just a placeholder
pass
def worldloader(c):
for i in range(0,len(line1)):
b=0
if (line1[i]=="0"):
air((i*32)+c,b)
if(line1[i]=="-"):
dirt((i*32)+c,b)
if(line1[i]=="_"):
grass((i*32)+c,b)
for i in range(0,len(line2)):
b=32*1
if (line2[i]=="0"):
air(i*32+c,b)
if(line2[i]=="-"):
dirt((i*32)+c,b)
if(line2[i]=="_"):
grass((i*32)+c,b)
for i in range(0,len(line3)):
b=32*2
if (line3[i]=="0"):
air(i*32+c,b)
if(line3[i]=="-"):
dirt((i*32)+c,b)
if(line3[i]=="_"):
grass((i*32)+c,b)
for i in range(0,len(line4)):
b=32*3
if (line4[i]=="0"):
air(i*32+c,b)
if(line4[i]=="-"):
dirt((i*32)+c,b)
if(line4[i]=="_"):
grass((i*32)+c,b)
for i in range(0,len(line5)): #goes on till line 23
b=32*4
if (line5[i]=="0"):
air(i*32+c,b)
if(line5[i]=="-"):
dirt((i*32)+c,b)
if(line5[i]=="_"):
grass((i*32)+c,b)
Greetings from Germany
Bastian
Comments
Sorry for the format of the .txt example it should look like this: 00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
http://py.processing.org/reference/ & http://processing.org/reference/
from time import sleep
I don't know py
but instead of using line1, line2 etc.
why not stick to sp[0], sp[1] etc.?
then you can for-loop over it
That's 1 of the remarks I wanted to mention too! But realized that he doesn't understand Processing framework nor OOP principles! He should at least read these 2 basic tutorials: :-B
http://forum.processing.org/two/discussion/8082/from-several-variables-to-arrays is an excellent article too.
Though it's for "Java Mode"! ~:>
I see.... very good hints.... ;-)