Skip to content

Commit

Permalink
Version 0.91 2012/06/27
Browse files Browse the repository at this point in the history
  • Loading branch information
yupswing committed Jan 12, 2015
1 parent 0615a19 commit c86230c
Show file tree
Hide file tree
Showing 33 changed files with 281 additions and 70 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

YET ANOTHER PYTHON SNAKE
========================

YAPS 0.91 [2012/06/27]
+ fullscreen mode on/off
# some fixes to ensure compatibility with python3 [not tested]
# highscore and preferences in "local" folder instead of "data"
# sys.quit() on quit

YAPS 0.9 [2012/06/24]
+ brand new code with awesome features
+ play as a snake that eats apples and moves orthogonally
+ highscores
+ vector graphics
+ resolution independent

YAPS 0.1 [2012/06/21]
+ First prototype
8 changes: 4 additions & 4 deletions README.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
YET ANOTHER PYTHON SNAKE
========================

# YetAnotherPythonSnake 0.9
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
YetAnotherPythonSnake 0.91
Author: Simone Cingano ([email protected])
Web: http://imente.it
Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]


DEPENDENCIES
Expand Down
Empty file modified data/music/boot.mp3
100644 → 100755
Empty file.
Empty file modified data/music/game.mp3
100644 → 100755
Empty file.
Empty file modified data/music/title.mp3
100644 → 100755
Empty file.
Empty file modified data/sfx/choose.wav
100644 → 100755
Empty file.
Empty file modified data/sfx/ding.wav
100644 → 100755
Empty file.
Empty file modified data/sfx/eat.wav
100644 → 100755
Empty file.
Empty file modified data/sfx/fall.wav
100644 → 100755
Empty file.
Empty file modified data/sfx/move.wav
100644 → 100755
Empty file.
Empty file modified data/sfx/splat.wav
100644 → 100755
Empty file.
Empty file modified data/title/background.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified data/title/credits.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified data/title/imente.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/boot_screen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
7 changes: 4 additions & 3 deletions lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand All @@ -22,11 +22,12 @@ class Constants:

START_LENGTH = 3

HIGHSCORE = os.path.join('data','score','score.data')
HIGHSCORES_FILE = os.path.join('local','highscores')
PREFERENCES_FILE = os.path.join('local','preferences')

GROW = 1

CREDITS = """*Yet Another Python Snake (YAPS v0.9)
CREDITS = """*Yet Another Python Snake (YAPS v0.91)
This game was made, as a personal exercise with python
and pygame, in a few days in June 2012
It's free, licensed under Creative Commons BY-NC 3.0
Expand Down
3 changes: 3 additions & 0 deletions lib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def filepath(kind, filename):
'''Determine the path to a file in the data directory.'''
fp = os.path.join(data_dir, kind, filename)
if not os.path.exists(fp):
print('WARNING: Resource not available "%s"' % fp)
return None
return fp

def load(kind, filename, mode='rb'):
Expand Down
19 changes: 10 additions & 9 deletions lib/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand All @@ -22,14 +22,15 @@
from object_foods import Foods
from object_walls import Walls
from score import Score
from highscore import Highscore
from highscores import Highscores
from title_screen import TitleScreen


class Game:
def __init__(self, screen, unit):
def __init__(self, screen, unit, preferences):
self.screen = screen
self.unit = unit
self.preferences = preferences
self.running = True

self.sounds = SoundPlayer((('fall','fall.wav'),('ding','ding.wav'),('eat','eat.wav'),('move','move.wav'),('splat','splat.wav')))
Expand Down Expand Up @@ -59,7 +60,7 @@ def main(self):
self.screen.fill((0,0,0))
self.screen.blit(self.img_background,self.img_background_rect)

highscore = Highscore()
highscores = Highscores()

# Main instances
pavement = Pavement(self.unit)
Expand Down Expand Up @@ -222,7 +223,7 @@ def main(self):

self.print_text("GAME OVER")

if highscore.check(score.score,score.elapse):
if highscores.check(score.score,score.elapse):
current_string = ''
complete = False

Expand Down Expand Up @@ -259,8 +260,8 @@ def main(self):
inputbox.update()
inputbox.draw(self.screen)
pygame.display.update()
position = highscore.insert(current_string,score.score,score.elapse)
highscore.save()
position = highscores.insert(current_string,score.score,score.elapse)
highscores.save()
scored = {'index':position,'scored':True}
else:
counter = Constants.FPS*3 # 3 seconds
Expand All @@ -275,8 +276,8 @@ def main(self):

scored = {'elapse':score.elapse,'score':score.score,'scored':False}

ts = TitleScreen(self.screen,self.unit)
ts.highscore(scored)
ts = TitleScreen(self.screen,self.unit,self.preferences)
ts.highscores(scored)
del ts

self.music.stop()
Expand Down
2 changes: 1 addition & 1 deletion lib/gui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
101 changes: 101 additions & 0 deletions lib/highscores.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
#

import pygame
import random

#YASP common imports
import data
import util
from constants import Constants

class Highscores(object):
def __init__(self):
self.filename = Constants.HIGHSCORES_FILE
self.load()

def cypher(self,text,direction=1):
# stupid shifting to block stupid player from cheating highscore
# Yes, I know, it's very easy to bypass :)
r = 94
o = 32
result = ''
if direction == 1:
#create a seed and put it as first char
seed = random.randint(0,r)+o
result = chr(seed)
else:
#get the seed from first char
seed = ord(text[0])
text = text[1:]

s = seed*direction
ii = 1
for char in text:
x = ord(char)-32
if x > r: continue
x+=s*ii # shift
x=x%r # loop
x+=o # remap
result+=chr(x)
ii+=1
return result

def load(self):
self.scores = []
scores = []
score_file = None
try:
score_file = open(self.filename,"rb")
raw = score_file.read()
try:
raw = raw.decode('ascii') # python3
except:
pass
scores = [self.cypher(x,-1).split(',') for x in raw.split('\n') if x][:Constants.MAXSCORE]
except:
pass
finally:
if score_file: score_file.close()

for el in scores:
self.scores.append({"score":el[2],"elapse":el[1],"name":el[0]})

def save(self):
score_file = None
try:
score_file = open(self.filename,"wb")
for el in self.scores:
raw = self.cypher("%s,%s,%s" % (el["name"],el["elapse"],el["score"]))+'\n'
try:
raw = bytes("raw","ascii") # python3
except:
pass
score_file.write(raw)
except:
pass
finally:
if score_file: score_file.close()

def whereis(self,score,elapse):
ii=-1
for ii in range(len(self.scores)):
el = self.scores[ii]
if int(el["score"]) < int(score) or (int(el["score"]) == int(score) and str(el["elapse"]) > str(elapse)):
return ii
return ii+1

def check(self,score,elapse):
if self.whereis(score,elapse) < Constants.MAXSCORE:
return True
else:
return False

def insert(self,name,score,elapse):
position = self.whereis(score,elapse)
self.scores.insert(position,{"name":name.replace(",",""),"elapse":elapse,"score":str(score)})
return position
46 changes: 36 additions & 10 deletions lib/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand All @@ -10,52 +10,78 @@
#YASP common imports
import data
import util
import sys
from constants import Constants

from title_screen import TitleScreen
from boot_screen import BootScreen
from game import Game
from preferences import Preferences

class Main:
def __init__(self):
pygame.init()
pygame.display.init()
pygame.font.init()

self.mode = pygame.display.list_modes()[0]
self.screen = pygame.display.set_mode(self.mode, pygame.FULLSCREEN)
# self.mode = (1000,600)
# self.screen = pygame.display.set_mode(self.mode)
self.screen_w = pygame.display.Info().current_w
self.screen_h = pygame.display.Info().current_h
self.w = int(self.screen_h * 1.2)
self.h = int(self.screen_h * 0.8)

self.preferences = Preferences()
self.fullscreen = self.preferences.get("fullscreen")
self.go_mode()

pygame.mouse.set_visible(False)

pygame.display.set_caption(Constants.CAPTION)

def go_mode(self):
if self.fullscreen:
self.mode = (self.screen_w,self.screen_h)
if not self.mode in pygame.display.list_modes():
self.mode = pygame.display.list_modes()[0]
self.screen = pygame.display.set_mode(self.mode, pygame.FULLSCREEN)
else:
self.mode = (self.w,self.h)
self.screen = pygame.display.set_mode(self.mode)
self.unit = int(self.mode[1]/Constants.UNITS)
pygame.display.set_caption(Constants.CAPTION)

def main(self):
self.boot_screen()
while True:
if not self.title_screen(): break
self.play_game()
if self.preferences.edit_flag:
self.preferences.save()
fullscreen = self.preferences.get('fullscreen')
if self.fullscreen != fullscreen:
self.fullscreen = fullscreen
self.go_mode()
else:
self.play_game()

def boot_screen(self):
bs = BootScreen(self.screen, self.unit)
bs.main()
return bs.running

def title_screen(self,):
ts = TitleScreen(self.screen, self.unit)
def title_screen(self):
self.go_mode()
ts = TitleScreen(self.screen, self.unit, self.preferences)
ts.main()
return ts.running

def play_game(self):
gm = Game(self.screen, self.unit)
gm = Game(self.screen, self.unit, self.preferences)
gm.main()
return gm.running

def main():
game = Main()
game.main()
pygame.quit()
sys.exit()

if __name__ == "__main__":
main()
Binary file added lib/main.pyo
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/object_foods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
2 changes: 1 addition & 1 deletion lib/object_pavement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
2 changes: 1 addition & 1 deletion lib/object_snake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
2 changes: 1 addition & 1 deletion lib/object_walls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# YetAnotherPythonSnake 0.9
# YetAnotherPythonSnake 0.91
# Author: Simone Cingano ([email protected])
# Web: http://imente.it
# Licence: (CC) BY-NC 3.0 [http://creativecommons.org/licenses/by-nc/3.0/]
Expand Down
Loading

0 comments on commit c86230c

Please sign in to comment.