Jump to content

  • Log In with Google      Sign In   
  • Create Account

Kurai Tsubasa

Member Since 22 Aug 2013
Offline Last Active Oct 11 2014 05:30 AM

Topics I've Started

What happen if "self" in second argument

20 September 2014 - 05:12 AM

Hi i tried to read this code but i don't really understand what "self" being in second argument.Here is the example:





class Player(pygame.sprite.Sprite): 
    def update(self, dt, game): 
        game.tilemap.set_focus(new.x, new.y) 

class Game(object): 
    def initArea(self, mapFile): 
        self.tilemap = tmx.load(mapFile, screen.get_size()) 
        self.sprites = tmx.SpriteLayer() 
        self.tilemap.layers.append(self.sprites) 

def main(self):
    while 1: 
        self.tilemap.update(dt / 1000., self)

if __name__ == '__main__':
    pygame.init()
    screen = pygame.display.set_mode((640, 480))
    pygame.display.set_caption("Pyllet Town")
    Game(screen).main()

I already tried to ask others they said game is being an instance of Game(),but i really don't get it can you explain me a bit detailed?Thank you very much biggrin.png any help will be very appreciated

 

P.S:i cut some line but i hope you could still understand this code smile.png


What is super().__init()

26 July 2014 - 04:56 AM

Hi,i just found a TMX library but i can't find any tutorial that explain it clearly so i tried to understand the library myself but i don't know what is super().__init__().I already tried to search about it but i don't really understand it,the explaination is to advance for me sad.png  because i'm still new in programming world so this is code:

class Player(pygame.sprite.Sprite):
    def __init__(self, location, orientation, *groups):
        super(Player, self).__init__(*groups)
        self.image = pygame.image.load('sprites/player.png')
        self.imageDefault = self.image.copy()
        self.rect = pygame.Rect(location, (64,64))
        self.orient = orientation 
        self.holdTime = 0
        self.walking = False
        self.dx = 0
        self.step = 'rightFoot'
        # Set default orientation
        self.setSprite()
        

Any helps will be very appreciate and please explain it using easy example biggrin.png if it possible also if you need a full code i will add it since the code is too long.Thank you so much


Help me learn Pygame

21 May 2014 - 11:26 PM

hello, it's been a while since I postedbiggrin.png .i have national exam this early month but it's already over now ^^(i need to study hard to pass the exams so a few month ago i can't open my computer to long but now i have 1 month holiday).So,i think i already know the basics of the python and want to move on to game developing,i tried Invent Your Game with Python book but i feel like it is still hard to understandunsure.png.So i'm looking some book that easy to understand,to read in this holiday or video/tutorial online that can improve both python and pygame.(i really need collision detection and tile map because i only want to make a simple RPG)

 

I already tried(Python):

-New boston video

-byte of python

-learn Python the hard way

-and some web(i forgot the web ^^a)

 

And for pygame i only tried Invent Your Game with Python.Sometimes i feel down because i can't understand what that code dosad.png(but i feel i can't stop trying) .If you have great tutorial to help me or advice i'm really appreciate thatsmile.png.Thank You


OOP is so confusing[wrong question]

10 January 2014 - 05:39 AM

Hi guys i want to know the process of object orientated programming(OOP) i tried my best to understand what is exactly the process but i have no idea what is it.I have a code like this:







class Song(object):

	def __init__(self, lyrics):
		self.lyrics = lyrics
	
	def sing_me_a_song(self):
		for line in self.lyrics:
			print line
			
happy_bday = Song(["Happy birthday to you",
		   "I don't want to get sued",
                   "So I'll stop right there"])	
	   
bulls_on_parade = Song(["They rally around the family",
			"With pockets full of shell"])
						
happy_bday.sing_me_a_song()

bulls_on_parade.sing_me_a_song()

And i don't understand what is "for" and "in" statement it is really confusing me. and i don't understand what :







self.lyrics = lyrics

and 







for line in self.lyric:
        print line

is do for .Sorry for asking to muchunsure.png


[Solved]How to make variable for item[Adventure Text Game]

04 January 2014 - 01:36 AM

Hi everyone biggrin.png i tried to make item in adventure text based game but it seems not working i make the variable for key so when the variable go to number 1 it would open the door but when i tried it.It show me an error : Name:Global name key_work_room is not defined

 

here my script(fixed for global variable):

from sys import exit

global key_work_room

key_work_room = 0

def work_room():
	global key_work_room
	if key_work_room == 1:
		print "There is a book."
		print"""Choices:
		1.Read
		2.Leave
		"""
		
		next = raw_input(">")
		
		if next == "1":
			print """
			Go to the Dark corridor and there is a door that
			keep a magic sword.It can used to kill demon 
			in that door there is a key
			541
			"""
		elif next== "2":
			stair()
		else:
			print "Check your spelling."
			print " "
			work_room()
	else:
			print "Check your spelling."
			print " "	
			work_room()
def bed_room():
	print "there is a key in the desk."
	print """choices:
	1.Take.
	2.leave.
	"""
	
	next = raw_input("> ")

	if next == "1":
		global key_work_room
		key_work_room += 1
		stair()
	
	elif next == "2":
		stair()
	else:
		print "Check your spelling."
		print " "
		bed_room()

def second_floor():
	print "There is so many torch in this room but there is a dark side."
	print """Choices:
	1.Take the torch.
	2.Go to the dark side.
	3.back
	"""
	
	next = raw_input("> ")
	
	if next == "1":
		print "You get the torch"
		torch = 1
		second_floor()
	elif next == "2":
		print "Something lurking in the dark attack you..."
	elif next == "3":
		stair()
	else:
		print "Check your spelling."
		print " "
		second_floor()

def stair():
	print key_work_room
	print "Now you're in the 2nd floor."
	print "There are 4 room."
	print "which one do you choose? or Do you want take a look around?"
	print "1. to look door 1."
	print "2. to look door 2."
	print "3. to look door 3."
	print "4. to look door 4."
	print "5. to look around."
	
	next = raw_input("> ")
	
	if next == "1":
		king_throne()
	elif next == "2":
		bed_room()
	elif next == "3":
		veranda()
	elif next == "4":
		work_room()
	elif next == "5":
		second_floor()
	elif next == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		stair()
		
def living_room():
	print "you find yourself in living room."
	print "You don't remember anything it looks like something hit your head."
	print "You now fully regain your consciousness."
	print "You start to walking and you found a stair and dark corridor."
	
	next = raw_input("> ")
	
	if next == "stair":
		stair()
	elif next == "dark corridor":
		dark_corridor
	elif next == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		living_room()

def start():
	print "Welcome in Fantasy World."
	print "This is simple game type 'exit' to exit."
	print "choose your destination by type the destination name."
	print "Are you boy or girl?"
	character = raw_input("> ")
	
	if character == "boy" in character or "girl" in character:
		living_room()
	elif character == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		start()

def dead():
	print "you died and the mystery still uncovered."
	print """Choices:
	1.Play again
	2.Take a rest.
	"""
	choice = raw_input("> ")
	
	if choice == "1":
		start()
	elif choice == "2":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		dead()

start()

it haven't finished yet but i need key to know how make the variable for item work also if you find anything weird in my script please tell mesmile.png .Thank youbiggrin.png


PARTNERS