From 88a70248b352f94b831911b5f2f81bcb9c09c5cc Mon Sep 17 00:00:00 2001 From: cecilkorik Date: Mon, 22 Jan 2007 20:04:41 +0000 Subject: [PATCH] made vssg.py executable, converted line endings to unix --HG-- branch : vssg --- vssg.py | 250 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 126 insertions(+), 124 deletions(-) diff --git a/vssg.py b/vssg.py index c3c5880..91fb7eb 100644 --- a/vssg.py +++ b/vssg.py @@ -1,124 +1,126 @@ -import pygame -from pygame.locals import * -import os -import sys -import math -import random -import starmap -import starmap_gen - -pygame.init() - -def handle_keys(keys): - global bounce, speed_player, trails, dir_player, color_player - for key in keys: - if key == K_b: - bounce = not bounce - elif key == K_q: - sys.exit(0) - elif key == K_c: - color_player = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) - elif key == K_t: - trails = not trails - elif key == K_UP: - speed_player += 0.01 - elif key == K_DOWN: - speed_player -= 0.01 - elif key == K_LEFT: - dir_player -= (math.pi / 180.0) - elif key == K_RIGHT: - dir_player += (math.pi / 180.0) - -def move(coords, dir, mag): - return [coords[0] + (math.sin(dir) * mag), coords[1] - (math.cos(dir) * mag)] - -def limitdir(dir): - while dir < 0: - dir += math.pi*2.0 - while dir > math.pi*2.0: - dir -= math.pi*2.0 - return dir - -def bouncedir(normal, dir): - inv_normal = limitdir(normal + math.pi) - return limitdir(normal + (inv_normal - dir)) - - -loc_player = [100.0,150.0] -dir_player = math.pi * 0.80 - -size = width, height = (800,600) -scr = pygame.display.set_mode(size) - -#options -color_player = (255,255,255) -bounce = True -speed_player = 5.0 -trails = False - -scr.fill((0,0,0)) - -keys = [] -do_quit = False - -map = starmap_gen.starmap_generate() - -while True: - events = pygame.event.get((KEYDOWN, KEYUP, QUIT)) - for ev in events: - if ev.type == QUIT: - do_quit = True - break - elif ev.type == KEYUP: - try: - del keys[keys.index(ev.key)] - except IndexError: - pass - else: - keys += [ev.key] - - if do_quit: - break - - handle_keys(keys) - pygame.event.pump() - """ - loc_new = move(loc_player, dir_player, speed_player) - - if loc_new[0] < 5: - if not bounce: - loc_new[0] = width-6 - else: - dir_player = bouncedir(math.pi*0.5, dir_player) - elif loc_new[1] < 5: - if not bounce: - loc_new[1] = height-6 - else: - dir_player = bouncedir(math.pi, dir_player) - elif loc_new[0] > width - 5: - if not bounce: - loc_new[0] = 6 - else: - dir_player = bouncedir(math.pi*1.5, dir_player) - elif loc_new[1] > height - 5: - if not bounce: - loc_new[1] = 6 - else: - dir_player = bouncedir(0, dir_player) - - if bounce: - loc_new = move(loc_player, dir_player, speed_player) - - if not trails: - pygame.draw.circle(scr, (0,0,0), loc_player, 2, 1) - pygame.draw.circle(scr, color_player, loc_new, 2, 1) - - - loc_player = loc_new - """ - - for star in map.get_all_stars(): - star.draw(scr) - - - pygame.display.flip() \ No newline at end of file +#!/usr/bin/python + +import pygame +from pygame.locals import * +import os +import sys +import math +import random +import starmap +import starmap_gen + +pygame.init() + +def handle_keys(keys): + global bounce, speed_player, trails, dir_player, color_player + for key in keys: + if key == K_b: + bounce = not bounce + elif key == K_q: + sys.exit(0) + elif key == K_c: + color_player = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) + elif key == K_t: + trails = not trails + elif key == K_UP: + speed_player += 0.01 + elif key == K_DOWN: + speed_player -= 0.01 + elif key == K_LEFT: + dir_player -= (math.pi / 180.0) + elif key == K_RIGHT: + dir_player += (math.pi / 180.0) + +def move(coords, dir, mag): + return [coords[0] + (math.sin(dir) * mag), coords[1] - (math.cos(dir) * mag)] + +def limitdir(dir): + while dir < 0: + dir += math.pi*2.0 + while dir > math.pi*2.0: + dir -= math.pi*2.0 + return dir + +def bouncedir(normal, dir): + inv_normal = limitdir(normal + math.pi) + return limitdir(normal + (inv_normal - dir)) + + +loc_player = [100.0,150.0] +dir_player = math.pi * 0.80 + +size = width, height = (800,600) +scr = pygame.display.set_mode(size) + +#options +color_player = (255,255,255) +bounce = True +speed_player = 5.0 +trails = False + +scr.fill((0,0,0)) + +keys = [] +do_quit = False + +map = starmap_gen.starmap_generate() + +while True: + events = pygame.event.get((KEYDOWN, KEYUP, QUIT)) + for ev in events: + if ev.type == QUIT: + do_quit = True + break + elif ev.type == KEYUP: + try: + del keys[keys.index(ev.key)] + except IndexError: + pass + else: + keys += [ev.key] + + if do_quit: + break + + handle_keys(keys) + pygame.event.pump() + """ + loc_new = move(loc_player, dir_player, speed_player) + + if loc_new[0] < 5: + if not bounce: + loc_new[0] = width-6 + else: + dir_player = bouncedir(math.pi*0.5, dir_player) + elif loc_new[1] < 5: + if not bounce: + loc_new[1] = height-6 + else: + dir_player = bouncedir(math.pi, dir_player) + elif loc_new[0] > width - 5: + if not bounce: + loc_new[0] = 6 + else: + dir_player = bouncedir(math.pi*1.5, dir_player) + elif loc_new[1] > height - 5: + if not bounce: + loc_new[1] = 6 + else: + dir_player = bouncedir(0, dir_player) + + if bounce: + loc_new = move(loc_player, dir_player, speed_player) + + if not trails: + pygame.draw.circle(scr, (0,0,0), loc_player, 2, 1) + pygame.draw.circle(scr, color_player, loc_new, 2, 1) + + + loc_player = loc_new + """ + + for star in map.get_all_stars(): + star.draw(scr) + + + pygame.display.flip()