Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Going Further Into Python and Game Development


  • Please log in to reply
1 reply to this topic

#1 WaterNode

WaterNode

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 69 posts
  • Location:Seattle, WA, United States of America
  • Programming Language:C, Java, C++, C#, Python
  • Learning:C, Java, C++, C#, Python, Lua, Assembly, Others

Posted 06 September 2012 - 05:48 PM

I highly recommend this tutorial if you haven't seen it already: http://forum.codecal...me-development/
This tutorial is currently Windows only due to this version of Pygame being used only supporting Windows, when you read this, it might be changed other wise.

Remember to get Pygame 1.9.2a0!
http://www.pygame.org/download.shtml
Windows 64 bit Users, just simply get the 32 bit Python and use the 32 bit Pygame.
Please the so called "tutorials" here: http://www.pygame.org/docs/
Please read this: http://inventwithpyt...e/chapter2.html


Now, lets start actually programming.

So, please download: wintheworlddev_logo.png
Remember to put them in the same folder, I will explain why later.

Look at the source code for test.py
I'll paste it here for reference:
import pygame, sys
from pygame.locals import *

screen = pygame.display.set_mode((960, 960))
# Sets the size of the screen.
char = pygame.image.load("VoidWalker.png")
# Loads the VoidWalker
pic = pygame.image.load("wintheworlddev_logo.png")
# Loads the logo.
# Make sure you use .png files!
charx = 32
chary = 32
# Bases the character at 32x, 32y, and the top left pixel is the pixel that it is based on.
picx = 0
picy = 0
# Sets the x, y coords for the top left pixel of the logo.
mov = 32
# Amount the Voidwalker moves when movement key is pressed.

while True:
for event in pygame.event.get():
	 if event.type == QUIT:
# Checks to see if the user has presses the exit button.
		 sys.exit()
# Ends the application
	 if event.type == KEYDOWN:
# Looks too see if you pressed down a key.
		 if event.key == K_ESCAPE:
# When you press the Esc key.
			 sys.exit()
		 if event.key == K_s:
# When you press the s key.
			 if not chary > 95:
# Makes sure the character is not going out of the WinTheWorld logo.
				 chary += mov
		 if event.key == K_a:
			 if not charx <= 1:
				 charx -= mov
		 if event.key == K_w:
			 if chary >= 1:
				 chary -= mov
		 if event.key == K_d:
			 if not charx >= 95:
				 charx += mov

screen.fill((255,255,255))
# Makes the backround white.
screen.blit(pic, (picx, picy))
# Loads the WinTheWorld logo.
screen.blit(char, (charx, chary))
# Loads the Voidwalker/Character sprite.
pygame.display.update()
# Updates the screen.

So how does the simple program work?
Well, this is loading the game, setting where the sprites start, and how they move.
Also, you put the sprites in the same folder because then you would have to use the specific directory the sprites are in, which would be a pain.
import pygame, sys
from pygame.locals import *
screen = pygame.display.set_mode((960, 960))
# Sets the size of the screen.
char = pygame.image.load("VoidWalker.png")
# Loads the VoidWalker
pic = pygame.image.load("wintheworlddev_logo.png")
# Loads the logo.
# Make sure you use .png files!
charx = 32
chary = 32
# Bases the character at 32x, 32y, and the top left pixel is the pixel that it is based on.
picx = 0
picy = 0
# Sets the x, y coords for the top left pixel of the logo.
mov = 32
# Amount the Voidwalker moves when movement key is pressed.
The while loop
while True:
Makes an constant forever game loop, unless you press the exit button or the Esc key.
for event in pygame.event.get():
	 if event.type == QUIT:
# Checks to see if the user has presses the exit button.
		 sys.exit()
# Ends the application
	 if event.type == KEYDOWN:
# Looks too see if you pressed down a key.
		 if event.key == K_ESCAPE:
# When you press the Esc key.
			 sys.exit()
		 if event.key == K_s:
# When you press the s key.
			 if not chary > 95:
# Makes sure the character is not going out of the WinTheWorld logo.
				 chary += mov
		 if event.key == K_a:
			 if not charx <= 1:
				 charx -= mov
		 if event.key == K_w:
			 if chary >= 1:	
				 chary -= mov
		 if event.key == K_d:
			 if not charx >= 95:
				 charx += mov
And as you can see, you can move using the wasd keys.

screen.fill((255,255,255))
# Makes the backround white.
screen.blit(pic, (picx, picy))
# Loads the WinTheWorld logo.
screen.blit(char, (charx, chary))
# Loads the Voidwalker/Character sprite.
pygame.display.update()
# Updates the screen.
Updates the screen.

How do you make smoother moment and such?
I will post another tutorial by me in posts below in the future, stay tuned!

Attached Thumbnails

  • VoidWalker.png

Attached Files

  • Attached File  test.py   1.65KB   128 downloads

  • 0

#2 WaterNode

WaterNode

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 69 posts
  • Location:Seattle, WA, United States of America
  • Programming Language:C, Java, C++, C#, Python
  • Learning:C, Java, C++, C#, Python, Lua, Assembly, Others

Posted 07 September 2012 - 05:17 PM

It got a little buggy, there is 2 other downloads at the bottom.
  • 0