from scene import *
import sound
import random
import math
import time
import os
A = Action
class MyScene (Scene):
def setup(self):
self.background_color=('white')
self.cardlistred=('emj:Anchor','emj:American_Football')
self.fishmeat=self.spawn_fishmeat(self.cardlistred,(400,800))
img=('emj:Artist_Palette','emj:Astonished')
self.ground=SpriteNode('test:Sailboat')
self.ground.anchor_point=(0,0)
self.ground.position=(0,0)
self.ground.size=(800,400)
self.add_child(self.ground)
self.choosing=False
self.pickone=False
self.spawnone=False
self.fmcpos=(-5,-5)
#first run
#open('fishmeatcopy.txt','w')
#open('position.txt','w')
#open('time.txt','w')
#open('cropindex.txt','w')
file=open('fishmeatcopy.txt','r')
str1=file.readline()
str1=str1.strip(',')
size=os.path.getsize('fishmeatcopy.txt')
if size==0:
str1='typb:Unknown'
file2=open('position.txt','r')
str2=file2.readline()
str2=str2.strip(',')
size=os.path.getsize('position.txt')
if size==0:
self.fmcpos=(-5,-5)
else:
self.fmcpos=(float(str2.split(';')[0]),float(str2.split(';')[1]))
self.spawn_fishmeatcopy(str1,self.fmcpos)
self.crop=self.spawn_crop()
self.spawn_stoplable()
#print(time.time())
file3=open('time.txt','r')
lasttime=file3.readline()
lasttime=lasttime.strip(',')
size=os.path.getsize('time.txt')
if size==0:
lasttime=0
#print(lasttime)
else:
lasttime=float(lasttime)
timelap=time.time()//1-lasttime
#print(timelap)
if timelap>=300:
self.cat=SpriteNode('emj:Cat_Face_Heart-Shaped_Eyes')
self.cat.blend_mode=BLEND_MULTIPLY
self.cat.position=(1000,100)
self.add_child(self.cat)
if not self.fmcpos==(-5,-5):
self.cat.run_action(A.move_to(self.fishmeatcopy.position.x,self.fishmeatcopy.position.y,5))
file4=open('cropindex.txt','r')
str4=file4.readline()
str4=str4.strip(',')
size=os.path.getsize('cropindex.txt')
if size==0:
self.texindex=0
else:
self.texindex=int(str4)
if self.texindex<3:
indexnum=int(timelap)//5+self.texindex
if indexnum<3:
self.texindex=indexnum
else:
self.texindex=3
#self.crop.texture=self.crop_texture[self.texindex]
file4=open('cropindex.txt','w')
file4.write(str(self.texindex))
file4.write(',')
file3=open('time.txt','w')
file3.write(str(time.time()//1))
file3.write(',')
#print(str)
#print(img[2:])
def spawn_crop(self):
self.crop_texture=[Texture('emj:Cat_Face'),Texture('emj:Cat_Face_Crying'),Texture('emj:Cat_Face_Grinning'),Texture('emj:Cat_Face_Heart-Shaped_Eyes')]
crop=SpriteNode(self.crop_texture[0])
crop.blend_mode=BLEND_MULTIPLY
crop.position=(400,300)
self.add_child(crop)
return crop
def spawn_fishmeatcopy(self,strname,pos):
self.fishmeatcopy=SpriteNode(strname)
self.fishmeatcopy.blend_mode=BLEND_MULTIPLY
self.fishmeatcopy.position=pos
self.add_child(self.fishmeatcopy)
def spawn_stoplable(self):
self.stoplable=LabelNode()
self.stoplable.text=('')
self.stoplable.position=(400,600)
self.stoplable.font=('Arial',30)
self.stoplable.color='black'
self.add_child(self.stoplable)
def spawn_fishmeat(self,listname,position):
file=random.choice(listname)
#file=listname[0]
card1=SpriteNode(file)
card1.blend_mode=BLEND_MULTIPLY
card1.position=position
#filename=os.path.splitext(file)[0]
#card1.intfilename=int(filename)
card1.index=listname.index(file)
self.add_child(card1)
return card1
def did_change_size(self):
pass
def update(self):
for touch in self.touches.values():
if touch.location in self.fishmeat.bbox:
self.choosing=True
self.stoplable.text=('stop')
if self.choosing==True and self.pickone==False:
for touch in self.touches.values():
if touch.location in self.ground.bbox:
if not self.spawnone==True:
self.fishmeatcopy=SpriteNode(self.cardlistred[self.fishmeat.index])
self.fishmeatcopy.blend_mode=BLEND_MULTIPLY
self.fishmeatcopy.position=touch.location
self.add_child(self.fishmeatcopy)
self.spawnone=True
self.pickone=True
self.choosing=False
else:
self.fishmeatcopy.position=touch.location
self.spawnone=True
self.pickone=True
self.choosing=False
if self.pickone==True:
for touch in self.touches.values():
if touch.location in self.ground.bbox:
self.fishmeatcopy.position=touch.location
for touch in self.touches.values():
if touch.location in self.stoplable.bbox:
self.stoplable.text=('')
self.choosing=False
self.pickone=False
for touch in self.touches.values():
if touch.location in self.crop.bbox:
if self.choosing==False and self.pickone==False:
if self.texindex==3:
self.texindex=0
if self.texindex<3:
if self.t>=5:
self.texindex=1+self.texindex
self.t=0
if self.texindex>=3:
self.texindex=3
self.crop.texture=self.crop_texture[self.texindex]
if self.t>=5:
file4=open('cropindex.txt','w')
file4.write(str(self.texindex))
file4.write(',')
def touch_began(self, touch):
pass
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
if self.pickone==True:
self.fmcpos=self.fishmeatcopy.position
file=open('fishmeatcopy.txt','w')
file.write(self.cardlistred[self.fishmeat.index])
file.write(',')
file2=open('position.txt','w')
file2.write(str(self.fmcpos[0]))
file2.write(';')
file2.write(str(self.fmcpos[1]))
file2.write(',')
file3=open('time.txt','w')
file3.write(str(time.time()//1))
file3.write(',')
file4=open('cropindex.txt','w')
file4.write(str(self.texindex))
file4.write(',')
if __name__ == '__main__':
run(MyScene(), show_fps=False)