Applications

Android Apps

Zombies and Such



This was my first attempt at a game as well as an android app. Its just a simple zombie killer game. I probably shouldn't have done it in python, since it's a bit difficult to package it up for android. (big thanks to the guys over at http://pygame.renpy.org/ for their work on the pygame subset for android). It's gotten easier, but it's still somewhat limited in what it can do. 

I should also give props to the creative commons artists who did the music. It wasn't done specifically for this game, but I felt that it was a rather good fit.

Thanks to Alex Beroza (Ein Schoner Tag), Ruin Roads (Basement #8, and Death March to Sun-fun City) and Sleeper Space Born (redlight riot). Check out these and other great artists here: http://dig.ccmixter.org/ 














Here's the link(s) to the game:
APK: docs.google.com/file/d/0B1YM7iEbRygaeWF4SElGRFM0bms/edit?usp=sharing
Source Code: docs.google.com/file/d/0B1YM7iEbRygaaDhuNmJmUjY2WEE/edit?usp=sharing


Python Apps

Untitled Matching Game


I made this game to help my 3-year-old with using the mouse. He loves matching games, and I figured it would be a good way to get him used to the peripheral. After just a few minutes of trial and error, he got it down. I'm really not sure what else to do with the game now. Maybe use the pygame subset for android and package it up? it needs some improvements, maybe some effects. But it would make a good ad-free app to keep little ones busy when you're out at a restaurant or something...


Here's the source:

Click here to expand Source
import pygame, sys, random

black = (0,0,0)
white = (255,255,255)
blue = (0,0,255)
red = (255,0,0)
green = (0,255,0)
maroon = (128,0,0)
yellow = (255,255,0)
purple = (128,0,128)
pink = (255,20,147)
orange = (255,69,0)
slate = (106,90,205)
spring = (0,255,127)

listocolors = []
listocolors.append(yellow)
listocolors.append(yellow)
listocolors.append(maroon)
listocolors.append(maroon)
listocolors.append(blue)
listocolors.append(blue)
listocolors.append(red)
listocolors.append(red)
listocolors.append(green)
listocolors.append(green)
listocolors.append(pink)
listocolors.append(pink)
listocolors.append(orange)
listocolors.append(orange)
listocolors.append(slate)
listocolors.append(slate)
listocolors.append(spring)
listocolors.append(spring)

 
random.shuffle(listocolors)

def createCards(targetlist):
  startx =40
  starty =20
  for i in listocolors:
    if startx < screen.get_width()-100:
      card = Card(startx,starty,i)
      targetlist.append(card)
      startx +=120
    else:
      startx = 40
      starty+=120
      card = Card(startx,starty,i)
      targetlist.append(card)
      startx += 120

def drawText(text, color, font, surface, x, y, center):
  textobj = font.render(text, 1, color)
  textrect = textobj.get_rect()
  textrect.topleft = (x, y)
  if center:
    textrect.center = (x, y)
  surface.blit(textobj, textrect)

def waitForPlayerToPressKey():
  while True:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:  # window X quits
        pygame.quit()
        sys.exit()
      if event.type == pygame.MOUSEBUTTONDOWN:
        return False

class Card():
  def __init__(self,x,y,color):
    self.rect = pygame.rect.Rect(x,y,100,100)
    self.color = white
    self.othercolor = color
    self.locked = False
  def changecolor(self):
    if self.locked:
      pass
    else:
      tmp = self.color
      self.color = self.othercolor
      self.othercolor = tmp
  def update(self,scrn):
    pygame.draw.rect(scrn, self.color, self.rect)
   
class Message():
  def __init__(self,x,y):
    self.x = x
    self.y = y
    self.rect = pygame.rect.Rect(x,y, 200, 60)
    self.message1 = 'Match!!!'
    self.message2 = 'No match :('
    self.disp = 'blah'
  def match(self,state):
    if state == 'match':
      self.disp = self.message1
      #self.rect.topleft = [self.x,self.y]
    elif state == 'nomatch':
      self.disp = self.message2
      #self.rect.topleft = [self.x,self.y]
    else:
      self.disp = 'blah'
      #self.rect.topleft = [-200,-200]
  def update(self,scrn):
    if self.disp == 'Match!!!' or self.disp == 'No match :(':
      self.rect.topleft = [self.x,self.y]
      pygame.draw.rect(scrn,white,self.rect)
      print 'disp set to match or nomatch'
    if self.disp == 'blah':
      #self.disp = ''
      self.rect.topleft = [-200,-200]
      pygame.draw.rect(scrn,white,self.rect)
   


def main():
  global cardList
  reset = pygame.rect.Rect(150,550,200,100)
  shuff = pygame.rect.Rect(400, 550, 200, 100)
  color = white
  click = 0
  message = Message((screen.get_width()/3), 450)
  tmp = 0
  unlockCode = [2,2,2,4]
  playerInput = []
  while True:
   
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit()

      if event.type == pygame.MOUSEBUTTONDOWN:
        for i in range(len(cardList)):
          if cardList[i].rect.collidepoint(event.pos):
            playerInput.append(i)
            if len(playerInput) > len(unlockCode):
              playerInput = playerInput[:len(unlockCode)]
          if cardList[i].rect.collidepoint(event.pos) and cardList[i].locked == False:
            click+=1
            if click ==2:
              print 'should have changed 2nd color'
              cardList[i].changecolor()
              print str(cardList[i].color)
              if cardList[tmp].color == cardList[i].color:
                message.match('match')
                click = 0
                cardList[i].locked = True
              else:
                message.match('nomatch')
                click = 0
                cardList[tmp].locked = False
               
            if click==1:
              cardList[i].changecolor()
              print 'should have changed color'
              print str(cardList[i].color)
              cardList[i].locked=True
              tmp = i
              #click+=1
           
            print 'tmp is set to:'
            print str(cardList[tmp].color)
            color = cardList[i].color
        if reset.collidepoint(event.pos):
          for i in cardList:
            if i.color != white:
              i.locked = False
              i.changecolor()
        if shuff.collidepoint(event.pos):
          random.shuffle(listocolors)
          cardList = []
          createCards(cardList)
    screen.fill(black)
    for i in cardList:
      i.update(screen)
   
    pygame.draw.rect(screen, white, shuff)
    pygame.draw.rect(screen, white, reset)
    drawText("New Game",black,font,screen,shuff.center[0],shuff.center[1],True)
    drawText("Reset",black,font,screen,reset.center[0],reset.center[1],True)
    message.update(screen)
    #pygame.draw.rect(screen, white, message.rect)
    drawText(message.disp, black, font, screen, message.rect.center[0],message.rect.center[1],True)
   
    for card in cardList:
      if card.locked:
        pass
      else:
        if card.color != white:
          card.changecolor()
   
    pygame.display.flip()
    if message.disp != 'blah':
      waitForPlayerToPressKey()
      message.disp = 'blah'
    #print str(playerInput)
    if unlockCode==playerInput:
      pygame.quit()
      sys.exit()
pygame.init()
screen = pygame.display.set_mode((800, 700))
screen.fill(black)
global cardList
cardList = []       
createCards(cardList)
font = pygame.font.Font(None, 36)
main()

No comments:

Post a Comment