Yesterday, I challenged myself to build a demo of our Fishfish game in a single night. At some undisclosed hour, I finished up with this:
You can move the player fish around, and ‘eat’ the smaller fish, and the shark can eat you and all other fish. Its pretty rough, and collision detection is done using the image bounding boxes, but not bad for three hours of work. This version is written in python using pygame. And yes, the inspiration for dragging this one out again is to port it to the Wii.
Source here and after the break.
Beware: This is a pretty horrid hack!!! You will need the graphics from the above project file to be able to run the program.
#!/usr/bin/env python # # Fishfish Proof of Concept # By Matt Mets, completed in 2008 # # This code is released into the public domain. Attribution is appreciated. # # Example code taken from: # http://www.pygame.org/docs/tut/intro/intro.html # http://kai.vm.bytemark.co.uk/~piman/writing/sprite-tutorial.shtml # http://www.devshed.com/c/a/Python/PyGame-for-Game-Development-Font-and-Sprites/2/ import sys, pygame, random from pygame.locals import * pygame.init() # Seed the random number generator using the system time random.seed() # Set up the game screen size = width, height = 800, 600 screen = pygame.display.set_mode(size) pygame.display.set_caption('FishFish demo') class PlayerFish(pygame.sprite.Sprite): def __init__(self, initial_position = (width/2, height/2)): pygame.sprite.Sprite.__init__(self) self.image_left = pygame.image.load("sprites/player_left.png").convert_alpha() self.image_right = pygame.image.load("sprites/player_right.png").convert_alpha() self.image = self.image_left self.rect = self.image.get_rect() self.rect.topleft = initial_position self.x_dist = 3 self.y_dist = 3 # self.speed = [-3,3] self.points = 0 def update(self): xMove = 0; yMove = 0; keystate = pygame.key.get_pressed() if (keystate[K_LEFT]): xMove = -self.x_dist self.image = self.image_left elif (keystate[K_RIGHT]): xMove = self.x_dist self.image = self.image_right if (keystate[K_UP]): yMove = -self.y_dist elif (keystate[K_DOWN]): yMove = self.y_dist self.rect.move_ip(xMove,yMove); if self.rect.left < 0: self.rect.left = 0 if self.rect.right > width: self.rect.right = width if self.rect.top < 0: self.rect.top = 0 if self.rect.bottom > height: self.rect.bottom = height def add_points(self, points): self.points += points score.set_score(self.points) def reset_points(self): self.points = 0 score.set_score(self.points) class SpikeyFish(pygame.sprite.Sprite): # Keep a master copy of the spikeyfish images so that they only need to # be loaded once image_left = None image_right = None def __init__(self): pygame.sprite.Sprite.__init__(self) # The first time a fish of this class is loaded, we need to load the # data associated with it. if SpikeyFish.image_left is None: SpikeyFish.image_left = pygame.image.load("sprites/spikey_left.png").convert_alpha() SpikeyFish.image_right = pygame.image.load("sprites/spikey_right.png").convert_alpha() # Randomly chose right or left motion if random.choice([True, False]): self.image = SpikeyFish.image_left self.rect = self.image.get_rect() self.rect.topleft = (width, random.randint(0,height)) self.speed = [-random.randint(2,4), 0] else: self.image = SpikeyFish.image_right self.rect = self.image.get_rect() self.rect.topleft = (-self.rect.right, random.randint(0,height)) self.speed = [random.randint(2,4),0] def update(self): self.rect = self.rect.move(self.speed) # The fish moved off of the screen, so kill it. if self.rect.right < 0 or self.rect.left > width: self.kill() class Shark(pygame.sprite.Sprite): # Keep a master copy of the spikeyfish images so that they only need to # be loaded once image_left = None image_right = None def __init__(self): pygame.sprite.Sprite.__init__(self) # The first time a fish of this class is loaded, we need to load the # data associated with it. if Shark.image_left is None: Shark.image_left = pygame.image.load("sprites/shark_left.png").convert_alpha() Shark.image_right = pygame.image.load("sprites/shark_right.png").convert_alpha() # Randomly chose right or left motion if random.choice([True, False]): self.image = Shark.image_left self.rect = self.image.get_rect() self.rect.topleft = (width, random.randint(0,height)) self.speed = [random.randint(-4,-2), random.randint(-2,2)] else: self.image = Shark.image_right self.rect = self.image.get_rect() self.rect.topleft = (-self.rect.right, random.randint(0,height)) self.speed = [random.randint(2,4), random.randint(-2,2)] def update(self): self.rect = self.rect.move(self.speed) # The fish moved off of the screen, so kill it. if self.rect.right < 0 or self.rect.left > width: self.kill() class Score(): def __init__(self): # Create a font self.font = pygame.font.Font(None, 50) # The score value self.score = 0 # Call update so we have a valid display self.update() def update(self): self.image = self.font.render(str(self.score), True, (255, 255, 255)) # Create a rectangle and position it self.rect = self.image.get_rect() self.rect.topright= (width - 10,10) def set_score(self, score): self.score = score background = pygame.image.load("sprites/kimbg.png").convert() fishes = pygame.sprite.Group() sharks = pygame.sprite.Group() player = PlayerFish() score = Score() while 1: # Check our event queue for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Update the fish player.update() fishes.update() sharks.update() # check for player-fish collisions (bounding boxes) collided = pygame.sprite.spritecollide(player, fishes, False) if collided.__len__() > 0: for fish in collided: fish.kill() player.add_points(10) # check for shark-anything collisions (bounding boxes) if sharks.__len__() > 0: # Nuke fishes collided = pygame.sprite.spritecollide(shark, fishes, True) # check player collided = pygame.sprite.spritecollide(player,sharks,False) if collided.__len__() > 0: player.reset_points() fishes.remove(fishes.sprites()) sharks.remove(sharks.sprites()) # Update the score display score.update() # Try to repopulate... only one fish at a time, and only if we are lucky. if fishes.__len__() < 20: if random.randint(1, 100) == 1: fishes.add(SpikeyFish()) # And sometimes we get a shark if sharks.__len__() == 0: if random.randint(1, 200) == 1: shark = Shark() sharks.add(shark) # Draw the background screen.blit(background, [0,0]) # Then the fish fishes.draw(screen) screen.blit(player.image, player.rect) sharks.draw(screen) # And the score screen.blit(score.image, score.rect) # And display pygame.display.flip() |
How will you port it to the wii?
Some nice hacker folks have made a tool kit that we will use, called DevkitPPC. The Twilight Hack can be used to load games without a modchip, and the Homebrew Channel can be used to launch homemade software.
Pingback: C i b o M a h t o . c o m » Old project: Intellaboy, a portable Intellivision