Jump to content

  • Log In with Google      Sign In   
  • Create Account

Kurai Tsubasa

Member Since 22 Aug 2013
Offline Last Active Jul 21 2015 01:44 AM

Topics I've Started

What is enumerate?

27 April 2015 - 05:47 AM

Hi,i just read a code and there is an enumerate function but i don't know what enumerate do?I read some question and it appear that enumerate is giving index for each loops but if i delete the enumerate it give me an error so i think there are some things that i missed.

Here the error:

 too many values to unpack(expected 2) 

And here here the code:

def load_tile_table(filename, width, height):
	image = pygame.image.load(filename).convert()
	image_width, image_height = image.get_size()
	tile_table = []
	for tile_x in range(0, image_width//width):
		line = []
		for tile_y in range(0, image_height//height):
			rect = (tile_x*width, tile_y*height, width, height)
	return tile_table

if __name__ == '__main__':
	screen = pygame.display.set_mode((128,98))
	screen.fill((255, 255, 255))
	table = load_tile_table('ground.png', 24, 16)
	for x, row in enumerate(table):
		for y,tile in enumerate(row):
			screen.blit(tile, (x*32, y*24))
	while pygame.event.wait().type != pygame.locals.QUIT:

Thank you very much smile.png

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() 

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

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

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

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"])


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


for line in self.lyric:
        print line

is do for .Sorry for asking to muchunsure.png