Created
August 29, 2011 11:54
-
-
Save Orpheon/1178249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os, time, random, pygame, math, socket | |
from pygame.locals import * | |
from load_image import load_image | |
import functions | |
from collision import characterCheckCollision, characterHitObstacle | |
from importMapRects import importMapRects | |
pygame.init() | |
# This is to replace the gmk "all" and also to update everything. | |
global globalGameObjectList | |
globalGameObjectList = [] | |
# All drawing should be done on the globalSurface object | |
global globalWindow, globalScreen | |
globalWindow = pygame.display.set_mode((1280, 1024)) | |
globalSurface = pygame.display.get_surface() | |
global globalXview, globalYview, globalWview, globalHview | |
globalXview, globalYview = 0, 0 | |
globalWview = globalWindow.get_width() | |
globalHview = globalWindow.get_height() | |
global globalCollisionRectList | |
globalCollisionRectList = importMapRects() | |
class GameObject(pygame.sprite.Sprite): | |
def __init__(self, xpos, ypos): | |
pygame.sprite.Sprite.__init__(self) | |
self.x = xpos | |
self.y = ypos | |
self.hspeed = 0 | |
self.vspeed = 0 | |
self.sprite = -1 | |
self.rect = -1 | |
globalGameObjectList.append(self) | |
def BeginStep(self): | |
pass | |
def Step(self): | |
pass | |
def EndStep(self): | |
# if self.x < 0.0: | |
# self.x = 0.0 | |
# | |
# if self.y < 0.0: | |
# self.y = 0.0 | |
pass | |
def Collide(self): | |
pass | |
def Draw(self): | |
if self.sprite != -1: | |
globalSurface.blit(self.sprite, (self.rect.topleft[0]-globalXview, self.rect.topleft[1]-globalYview)) | |
class MapObject(GameObject): | |
def __init__(self): | |
GameObject.__init__(self, 0, 0) | |
self.sprite, self.rect = load_image('Maps/MapTesting.png') | |
class Character(GameObject): | |
def __init__(self): | |
GameObject.__init__(self, 200, 200) | |
self.sprite, self.rect = load_image('Sprites/Characters/Scout/Red/ScoutRedS_fr1.png') | |
self.rect.center = (self.x, self.y) | |
self.up, self.left, self.right, self.LMB, self.RMB = 0, 0, 0, 0, 0 | |
def Step(self): | |
if self.up: | |
self.vspeed -= 2 | |
if self.left: | |
self.hspeed -= 1 | |
elif self.right: | |
self.hspeed += 1 | |
self.vspeed += 0.2 | |
if self.vspeed > 5: | |
self.vspeed = 5 | |
elif self.vspeed < -5: | |
self.vspeed = -5 | |
if self.hspeed > 5: | |
self.hspeed = 5 | |
elif self.hspeed < -5: | |
self.hspeed = -5 | |
def EndStep(self): | |
self.x += self.hspeed | |
self.y += self.vspeed | |
if self.rect != -1: | |
self.rect.center = (self.x, self.y) | |
def Collide(self): | |
check = characterCheckCollision(self, globalCollisionRectList) | |
if check: | |
print "Collision Detected" | |
# characterHitObstacle(character, globalCollisionRectList) | |
else: | |
print "No Collision Detected" | |
class PlayerControl(GameObject): | |
def __init__(self): | |
GameObject.__init__(self, 0, 0) | |
def BeginStep(self): | |
up = 0 | |
left = 0 | |
right = 0 | |
LMB = 0 | |
RMB = 0 | |
for event in pygame.event.get(): | |
pass | |
key = pygame.key.get_pressed() | |
if key[K_w]: | |
up = 1 | |
if key[K_a]: | |
left = 1 | |
elif key[K_d]: | |
right = 1 | |
LMB, middleMouseButton, RMB = pygame.mouse.get_pressed() | |
# Send keybyte | |
globalMyself.up = up | |
globalMyself.left = left | |
globalMyself.right = right | |
globalMyself.LMB = LMB | |
globalMyself.RMB = RMB | |
gameMap = MapObject() | |
global globalPlayerControl | |
globalPlayerControl = PlayerControl() | |
global globalMyself | |
globalMyself = Character() | |
while True: | |
for a in range(len(globalGameObjectList)): | |
globalGameObjectList[a].BeginStep() | |
for a in range(len(globalGameObjectList)): | |
globalGameObjectList[a].Step() | |
for a in range(len(globalGameObjectList)): | |
globalGameObjectList[a].EndStep() | |
for a in range(len(globalGameObjectList)): | |
globalGameObjectList[a].Collide() | |
globalXview = globalMyself.x-globalWview/2 | |
globalYview = globalMyself.y-globalHview/2 | |
globalSurface.fill((255, 255, 255)) | |
for a in range(len(globalGameObjectList)): | |
globalGameObjectList[a].Draw() | |
for a in range(len(globalCollisionRectList)): | |
pygame.draw.rect(globalSurface, (255, 0, 0), globalCollisionRectList[a], 1) | |
pygame.display.flip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment