changeset 5:0e3a5cc5ce23

Make single player selection start up a new single user game committer: Jeff Sipek <jeffpc@jeff.(none)> 1120698501 -0400
author Jeff Sipek <jeffpc@jeff.(none)>
date Thu, 07 Jul 2005 01:08:21 -0400
parents 1a8d3bc29749
children f346ce878117
files atc.py atc_single.py atc_utils.py
diffstat 3 files changed, 86 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/atc.py	Thu Jul 07 01:07:12 2005 -0400
+++ b/atc.py	Thu Jul 07 01:08:21 2005 -0400
@@ -9,6 +9,8 @@
 	import atc_utils
 	import atc_plane
 	import atc_message
+	
+	import atc_single
 except ImportError, err:
 	print "Couldn't load module %s" % (err)
 	sys.exit()
@@ -25,9 +27,7 @@
 	
 	# background music
 	pygame.mixer.init()
-	#pygame.mixer.music.load('data/sound/music.mp3')
-	#pygame.mixer.music.set_volume(0.1)
-	#pygame.mixer.music.play()
+	#atc_utils.playmusic("some.mp3");
 
 	# Set background
 	background = pygame.Surface(screen.get_size()).convert()
@@ -65,8 +65,9 @@
 		pygame.display.flip()
 		
 		if (optsel & 0x10):
+			optsel = optsel & 3
 			if (optsel == 0): # single player
-				pass
+				atc_single.single(screen)
 			if (optsel == 1): # multi player
 				pass
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/atc_single.py	Thu Jul 07 01:08:21 2005 -0400
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+
+import pygame
+import sys
+
+import atc_colors
+import atc_utils
+import atc_plane
+import atc_message
+
+def single(screen):
+	""" Main fn to run the single player game """
+	
+	# background music
+	#atc_utils.playmusic("some.mp3");
+
+	# Set background
+	background = pygame.Surface(screen.get_size()).convert()
+	background.fill(atc_colors.black)
+	
+	(back_image, back_rect) = atc_utils.load_png('data/image/background.png')
+	background.blit(back_image, (0, 0))
+
+	# Some text
+#	font = pygame.font.Font(None, 36)
+#	text = font.render("Air Traffic Controller", 1, atc_colors.red)
+#	textpos = text.get_rect()
+#	textpos.centerx = background.get_rect().centerx
+#	background.blit(text, textpos)
+
+	#blit!
+	screen.blit(background, (0, 0))
+	pygame.display.flip()
+
+	planes = [atc_plane.Plane(callsign="N12422",vel=(atc_plane.m2pix(50), atc_plane.m2pix(50), atc_plane.m2pix(10))),]
+	
+	mess = atc_message.Message()
+	
+	cmd = ""
+	
+	while 1:
+		for event in pygame.event.get():
+			if event.type == pygame.QUIT:
+				mess.pickup_kill = 1
+				sys.exit()
+			if event.type == pygame.KEYDOWN:
+				# commands
+				if event.key == pygame.K_q:
+					mess.pickup_kill = 1
+					return
+				if event.key == pygame.K_a:
+					cmd += 'A'
+				if event.key == pygame.K_ESCAPE:
+					cmd = ""
+				if event.key == pygame.K_BACKSPACE:
+					cmd = cmd[:-1]
+		
+		screen.blit(background, (0, 0))
+		
+		for plane in planes:
+			plane.display(screen)
+			plane.update()
+			if (plane.status == atc_plane.plane_CRASHED):
+				mess.write(screen,plane.callsign + ": PLANE CRASHED")
+				plane.status = atc_plane.plane_DEAD
+		
+		if (cmd):
+			font = pygame.font.Font(None, 18)
+			text = font.render(cmd, 1, atc_colors.white)
+			screen.blit(text, (25, 567))
+		
+		pygame.display.flip()
+
+if (__name__ == '__main__'):
+	print "Don't do it!"
--- a/atc_utils.py	Thu Jul 07 01:07:12 2005 -0400
+++ b/atc_utils.py	Thu Jul 07 01:08:21 2005 -0400
@@ -19,3 +19,9 @@
 def todeg(rad):
 	""" Convert radians to degrees """
 	return rad*180.0/pi
+
+def playmusic(name,vol=0.1):
+	""" Start playing background music """
+	pygame.mixer.music.load('data/sound/' + name)
+	pygame.mixer.music.set_volume(vol)
+	pygame.mixer.music.play()