-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yupswing
committed
Jan 12, 2015
1 parent
0615a19
commit c86230c
Showing
33 changed files
with
281 additions
and
70 deletions.
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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/] | ||
|
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
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/] | ||
|
@@ -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 | ||
|
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
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
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/] | ||
|
@@ -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'))) | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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() | ||
|
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
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/] | ||
|
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
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 |
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
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/] | ||
|
@@ -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 not shown.
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
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/] | ||
|
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
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/] | ||
|
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
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/] | ||
|
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
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/] | ||
|
Oops, something went wrong.