from scene import *
import sound
import random
import math
import os
A = Action
class MyScene (Scene):
def setup(self):
self.background_color='white'
self.carlist=[]
self.numlablelist=[]
x=200
y=400
#self.a=self.spawn_car(x,y-199)
#self.b=self.spawn_car(x+199,y-199)
#self.spawn_car(x+398,y-199)
#self.c=self.spawn_car(x,y)
#self.spawn_car(x+199,y)
#self.spawn_car(x+398,y)
#self.spawn_car(x,y+199)
#self.spawn_car(x+199,y+199)
#self.spawn_car(x+398,y+199)
self.a=self.spawn_car(x,y-200,0)
self.b=self.spawn_car(x+200,y-200,0)
self.c=self.spawn_car(x+400,y-200,0)
self.d=self.spawn_car(x,y,0)
self.e=self.spawn_car(x+200,y,4)
self.f=self.spawn_car(x+400,y,0)
self.g=self.spawn_car(x,y+200,0)
self.h=self.spawn_car(x+200,y+200,0)
self.i=self.spawn_car(x+400,y+200,0)
self.fmcarposition=(0,0)
self.atcaryes=True
self.phyes=False
self.pyyes=False
self.choosing=False
self.pickone=False
self.p=self.a.position
self.p1=self.a.position
self.p2=self.a.position
#self.rot=0
#self.radian=0
self.movable=False
self.overlap=False
#self.eatnum=0
self.rottotalnum=0
self.fishtweight=0
#card5Img='5.png'
#card1Img='1.png'
self.cardlistred=['card:DiamondsA','card:Diamonds2','card:Diamonds3','card:Diamonds4','card:Diamonds5','card:Diamonds6','card:Diamonds7','card:Diamonds8','card:Diamonds9','card:Diamonds10','card:DiamondsJ','card:DiamondsQ','card:HeartsK']
#cardlistred.append(card5Img)
#cardlistred.append(card1Img)
#card103Img='103.png'
#card107Img='107.png'
self.cardlistblack=['card:ClubsA','card:Clubs2','card:Clubs3','card:Clubs4','card:Clubs5','card:Clubs6','card:Clubs7','card:Clubs8','card:Clubs9','card:Clubs10','card:ClubsJ','card:ClubsQ','card:ClubsK']
#cardlistblack.append(card103Img)
self.card=self.spawn_card(self.cardlistred,self.a)
self.card2=self.spawn_card(self.cardlistblack,self.d)
self.fishmeat=self.spawn_fishmeat(self.cardlistred,(400,800))
#set car.plusnum
for car in self.carlist:
car.plusnum=random.randint(-1,+3)
self.win_lable=LabelNode(text='playing')
self.win_lable.anchor_point=(-20,0)
self.win_lable.position=(0,718)
self.win_lable.color='black'
self.win_lable.font=('Arial',30)
self.add_child(self.win_lable)
strplusnum=str(self.a.plusnum)
self.num_lable1=LabelNode(text=strplusnum)
self.num_lable1.anchor_point=(0,0)
self.num_lable1.position=self.a.position
self.num_lable1.color='black'
self.num_lable1.font=('Arial',30)
self.add_child(self.num_lable1)
#self.numlablelist.append(self.num_lable)
strplusnum=str(self.b.plusnum)
self.num_lable2=LabelNode(text=strplusnum)
self.num_lable2.anchor_point=(0,0)
self.num_lable2.position=self.b.position
self.num_lable2.color='black'
self.num_lable2.font=('Arial',30)
self.add_child(self.num_lable2)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.c.plusnum)
self.num_lable3=LabelNode(text=strplusnum)
self.num_lable3.anchor_point=(0,0)
self.num_lable3.position=self.c.position
self.num_lable3.color='black'
self.num_lable3.font=('Arial',30)
self.add_child(self.num_lable3)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.d.plusnum)
self.num_lable4=LabelNode(text=strplusnum)
self.num_lable4.anchor_point=(0,0)
self.num_lable4.position=self.d.position
self.num_lable4.color='black'
self.num_lable4.font=('Arial',30)
self.add_child(self.num_lable4)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.e.plusnum)
self.num_lable5=LabelNode(text=strplusnum)
self.num_lable5.anchor_point=(0,0)
self.num_lable5.position=self.e.position
self.num_lable5.color='black'
self.num_lable5.font=('Arial',30)
self.add_child(self.num_lable5)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.f.plusnum)
self.num_lable6=LabelNode(text=strplusnum)
self.num_lable6.anchor_point=(0,0)
self.num_lable6.position=self.f.position
self.num_lable6.color='black'
self.num_lable6.font=('Arial',30)
self.add_child(self.num_lable6)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.g.plusnum)
self.num_lable7=LabelNode(text=strplusnum)
self.num_lable7.anchor_point=(0,0)
self.num_lable7.position=self.g.position
self.num_lable7.color='black'
self.num_lable7.font=('Arial',30)
self.add_child(self.num_lable7)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.h.plusnum)
self.num_lable8=LabelNode(text=strplusnum)
self.num_lable8.anchor_point=(0,0)
self.num_lable8.position=self.h.position
self.num_lable8.color='black'
self.num_lable8.font=('Arial',30)
self.add_child(self.num_lable8)
#self.numlablelist.append(self.num_lable
strplusnum=str(self.i.plusnum)
self.num_lable9=LabelNode(text=strplusnum)
self.num_lable9.anchor_point=(0,0)
self.num_lable9.position=self.i.position
self.num_lable9.color='black'
self.num_lable9.font=('Arial',30)
self.add_child(self.num_lable9)
#self.numlablelist.append(self.num_lable
#self.fmlable=self.spawn_fmlable(self.e)
#self.run_action(A.sequence(A.call(self.movecard),A.wait(1)))
#self.run_action(A.sequence(A.call(self.movecard),A.wait(1)))
#self.run_action(A.sequence(A.call(self.movecard),A.wait(1)))
def newmap(self):
for car in self.carlist:
car.remove_from_parent()
self.carlist=[]
#print(self.carlist)
self.card.remove_from_parent()
self.card2.remove_from_parent()
#x=100
#y=300
x=200
y=400
#self.a=self.spawn_car(x,y-199)
#self.b=self.spawn_car(x+199,y-199)
#self.spawn_car(x+398,y-199)
#self.c=self.spawn_car(x,y)
#self.spawn_car(x+199,y)
#self.spawn_car(x+398,y)
#self.spawn_car(x,y+199)
#self.spawn_car(x+199,y+199)
#self.spawn_car(x+398,y+199)
self.a=self.spawn_car(x,y-200,0)
self.b=self.spawn_car(x+200,y-200,0)
self.c=self.spawn_car(x+400,y-200,0)
self.d=self.spawn_car(x,y,0)
self.e=self.spawn_car(x+200,y,4)
self.f=self.spawn_car(x+400,y,0)
self.g=self.spawn_car(x,y+200,0)
self.h=self.spawn_car(x+200,y+200,0)
self.i=self.spawn_car(x+400,y+200,0)
#print('ok')
#print(self.carlist)
self.atcaryes=True
self.phyes=False
self.pyyes=False
self.p=self.a.position
self.p1=self.a.position
self.p2=self.a.position
#self.rot=0
#self.radian=0
self.movable=False
self.overlap=False
self.rottotalnum=0
self.card=self.spawn_card(self.cardlistred,self.a)
self.card2=self.spawn_card(self.cardlistblack,self.i)
self.fishmeat.remove_from_parent()
self.fishmeat=self.spawn_fishmeat(self.cardlistred,(400,800))
#set car.plusnum
for car in self.carlist:
car.plusnum=random.randint(-1,+3)
#self.win_lable.text=('playing')
self.num_lable1.text=str(self.a.plusnum)
self.num_lable2.text=str(self.b.plusnum)
self.num_lable3.text=str(self.c.plusnum)
self.num_lable4.text=str(self.d.plusnum)
self.num_lable5.text=str(self.e.plusnum)
self.num_lable6.text=str(self.f.plusnum)
self.num_lable7.text=str(self.g.plusnum)
self.num_lable8.text=str(self.h.plusnum)
self.num_lable9.text=str(self.i.plusnum)
self.fmlable.remove_from_parent()
self.fmcarposition=(0,0)
def rotate(self):
#self.collidewithcar()
acar=self.atcar()
if self.atcaryes and acar is not None:
ax=acar.position.x
ay=acar.position.y
#self.rot=(self.rot+90)%360
#self.radian=self.rot*math.pi/180
'''for carname in self.carlist:
if not carname.rotatable:
carname.remove_all_actions() '''
if acar.rotatable:
acar.run_action(A.rotate_by((math.pi/2),0))
acar.rotnum=acar.rotnum+1
self.rottotalnum=(self.rottotalnum+1)%6
acar.calnum=(acar.calnum+1)%4
acar.carnum=(acar.calnum+acar.num)%4
if acar.num==9:
self.new_hitboxh=Rect(ax+acar.hitboxv.y-ay,ay+acar.hitboxv.x-ax,acar.hitboxv.h,acar.hitboxv.w)
self.new_hitboxv=Rect(ax+acar.hitboxh.y-ay,ay+acar.hitboxh.x-ax,acar.hitboxh.h,acar.hitboxh.w)
acar.hitboxh=self.new_hitboxh
acar.hitboxv=self.new_hitboxv
if acar.num==1 or acar.num==2 or acar.num==3 or acar.num==4:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,10,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,5,202)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,202)
if acar.num==5 or acar.num==6 or acar.num==7 or acar.num==8:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
#rotate unrotated
if self.rottotalnum==0:
for acar in self.carlist:
if acar.rotnum==0:
acar.run_action(A.rotate_by((math.pi/2),0))
ax=acar.position.x
ay=acar.position.y
acar.calnum=(acar.calnum+1)%4
acar.carnum=(acar.calnum+acar.num)%4
if acar.num==9:
self.new_hitboxh=Rect(ax+acar.hitboxv.y-ay,ay+acar.hitboxv.x-ax,acar.hitboxv.h,acar.hitboxv.w)
self.new_hitboxv=Rect(ax+acar.hitboxh.y-ay,ay+acar.hitboxh.x-ax,acar.hitboxh.h,acar.hitboxh.w)
acar.hitboxh=self.new_hitboxh
acar.hitboxv=self.new_hitboxv
if acar.num==1 or acar.num==2 or acar.num==3 or acar.num==4:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,10,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,5,202)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,202)
if acar.num==5 or acar.num==6 or acar.num==7 or acar.num==8:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
def movecollidewithcar(self):
acar=self.atcar()
if self.atcaryes and acar is not None:
#print(acar.position)
carmlist=[]
self.carlist.remove(acar)
for car in self.carlist:
if car is not None and acar is not None and car.hitboxh.intersects(acar.hitboxh):
carmlist.append(car)
#self.phyes=True
self.movable=True
#print('hh')
elif car is not None and acar is not None and car.hitboxv.intersects(acar.hitboxv):
carmlist.append(car)
#self.pyyes=True
self.movable=True
#print('vv')
if self.movable:
carm=random.choice(carmlist)
self.p=(carm.position.x,carm.position.y)
#self.card.intfilename=self.card.intfilename+carm.plusnum
#if self.card.intfilename>=13:
#self.card.intfilename=13
#if self.card.intfilename<=1:
#self.card.intfilename=1
#resultstrfilename=str(self.card.intfilename)
#self.card.remove_from_parent()
#self.card=self.change_card(self.card,(resultstrfilename+'.png'))
self.card.index=self.card.index+carm.plusnum
if self.card.index>=12:
self.card.index=12
if self.card.index<=0:
self.card.index=0
#resultstrfilename=str(self.card2.intfilename)
self.card.remove_from_parent()
list=self.c
self.card=self.change_card(self.card,self.cardlistred[self.card.index])
#self.phyes=False
#self.pyyes=False
self.carlist.append(acar)
if self.movable:
self.card.position=self.p
#print(self.card.position)
acar.rotatable=False
self.movable=False
def atcar(self):
for car in self.carlist:
if car is not None and car.bbox.intersects(self.card.bbox):
self.atcaryes=True
car.rotatable=True
#print('at')
#print(car.position)
return car
#card2operation
def rotate2(self):
#self.collidewithcar()
acar=self.atcar2()
if self.atcaryes and acar is not None:
ax=acar.position.x
ay=acar.position.y
#self.rot=(self.rot+90)%360
#self.radian=self.rot*math.pi/180
'''for carname in self.carlist:
if not carname.rotatable:
carname.remove_all_actions() '''
if acar.rotatable:
acar.run_action(A.rotate_by((math.pi/2),0))
acar.rotnum=acar.rotnum+1
self.rottotalnum=(self.rottotalnum+1)%6
acar.calnum=(acar.calnum+1)%4
acar.carnum=(acar.calnum+acar.num)%4
if acar.num==9:
self.new_hitboxh=Rect(ax+acar.hitboxv.y-ay,ay+acar.hitboxv.x-ax,acar.hitboxv.h,acar.hitboxv.w)
self.new_hitboxv=Rect(ax+acar.hitboxh.y-ay,ay+acar.hitboxh.x-ax,acar.hitboxh.h,acar.hitboxh.w)
acar.hitboxh=self.new_hitboxh
acar.hitboxv=self.new_hitboxv
if acar.num==1 or acar.num==2 or acar.num==3 or acar.num==4:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,10,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,5,202)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,202)
if acar.num==5 or acar.num==6 or acar.num==7 or acar.num==8:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
#rotate unrotated
if self.rottotalnum==0:
for acar in self.carlist:
if acar.rotnum==0:
acar.run_action(A.rotate_by((math.pi/2),0))
ax=acar.position.x
ay=acar.position.y
acar.calnum=(acar.calnum+1)%4
acar.carnum=(acar.calnum+acar.num)%4
if acar.num==9:
self.new_hitboxh=Rect(ax+acar.hitboxv.y-ay,ay+acar.hitboxv.x-ax,acar.hitboxv.h,acar.hitboxv.w)
self.new_hitboxv=Rect(ax+acar.hitboxh.y-ay,ay+acar.hitboxh.x-ax,acar.hitboxh.h,acar.hitboxh.w)
acar.hitboxh=self.new_hitboxh
acar.hitboxv=self.new_hitboxv
if acar.num==1 or acar.num==2 or acar.num==3 or acar.num==4:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,10,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,5,202)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,202,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,202)
if acar.num==5 or acar.num==6 or acar.num==7 or acar.num==8:
if acar.carnum==1:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
if acar.carnum==2:
acar.hitboxh=Rect(acar.position.x-101,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==3:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y-101,10,101)
if acar.carnum==0:
acar.hitboxh=Rect(acar.position.x,acar.position.y-5,101,10)
acar.hitboxv=Rect(acar.position.x-5,acar.position.y,5,101)
def movecollidewithcar2(self):
acar=self.atcar2()
if self.atcaryes and acar is not None:
#print(acar.position)
carmlist=[]
self.carlist.remove(acar)
for car in self.carlist:
if car is not None and acar is not None and car.hitboxh.intersects(acar.hitboxh):
carmlist.append(car)
#self.phyes=True
self.movable=True
self.overlap=False
#print('hh')
elif car is not None and acar is not None and car.hitboxv.intersects(acar.hitboxv):
carmlist.append(car)
#self.pyyes=True
self.movable=True
self.overlap=False
#print('vv')
if self.movable:
carm=random.choice(carmlist)
self.p=(carm.position.x,carm.position.y)
#self.card2.intfilename=self.card2.intfilename+carm.plusnum
#if self.card2.intfilename>=113:
#self.card2.intfilename=113
#if self.card2.intfilename<=101:
#self.card2.intfilename=101
#resultstrfilename=str(self.card2.intfilename)
#self.card2.remove_from_parent()
#self.card2=self.change_card(self.card2,(resultstrfilename+'.png'))
self.card2.index=self.card2.index+carm.plusnum
if self.card2.index>=12:
self.card2.index=12
if self.card2.index<=0:
self.card2.index=0
#resultstrfilename=str(self.card2.intfilename)
self.card2.remove_from_parent()
self.card2=self.change_card(self.card2,(self.cardlistblack[self.card2.index]))
#self.phyes=False
#self.pyyes=False
self.carlist.append(acar)
if self.movable:
self.card2.position=self.p
#######################################################
#twocardoverlapped
#if self.card2.position==self.card.position:
#print('overlapp')
#print(self.card2.position)
#self.card2.position=(self.card2.position.x+10,self.card2.position.y)
#print(self.card2.position)
#self.card.position=(self.card.position.x-40,self.card.position.y)
#if not(self.card2.position==self.card.position):
#???##############################################################
#overlap new
if self.atcar().position==self.atcar2().position:
self.overlap=True
self.card2.position=(self.card2.position.x+40,self.card2.position.y)
acar.rotatable=False
self.movable=False
#overlap code
if self.overlap==True:
if not self.atcar()==self.atcar2():
self.card2.position=(self.card2.position.x-40,self.card2.position.y)
self.overlap=False
#overlap code ends
def atcar2(self):
for car in self.carlist:
if car is not None and car.bbox.intersects(self.card2.bbox):
self.atcaryes=True
car.rotatable=True
#print('at')
#print(car.position)
return car
else:self.atcaryes=False
def spawn_fmlable(self,positioncar):
fmlable=LabelNode(text=str(self.fishmeat.index+1))
fmlable.anchor_point=(20,0)
fmlable.position=positioncar.position
fmlable.color='green'
fmlable.font=('Arial',40)
self.add_child(fmlable)
return fmlable
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 spawn_card(self,listname,positioncar):
#file=random.choice(listname)
file=listname[0]
card1=SpriteNode(file)
card1.blend_mode=BLEND_MULTIPLY
card1.position=positioncar.position
#filename=os.path.splitext(file)[0]
#card1.intfilename=int(filename)
card1.index=listname.index(file)
self.add_child(card1)
return card1
def change_card(self,lastcardname,file):
card1=SpriteNode(file)
card1.blend_mode=BLEND_MULTIPLY
card1.position=lastcardname.position
#card1.intfilename=lastcardname.intfilename
card1.index=lastcardname.index
self.add_child(card1)
return card1
def spawn_car(self,x,y,pnum):
randomcarlist=[]
car1=SpriteNode('img1.png')
car1.blend_mode=BLEND_MULTIPLY
car1.position=(x,y)
car1.rotnum=0
car1.num=1
car1.calnum=0
car1.carnum=0
car1.hitboxh=Rect(car1.position.x-101,car1.position.y-5,202,10)
car1.hitboxv=Rect(car1.position.x-5,car1.position.y,10,101)
randomcarlist.append(car1)
car2=SpriteNode('img2.png')
car2.blend_mode=BLEND_MULTIPLY
car2.position=(x,y)
car2.rotnum=0
car2.num=2
car2.calnum=0
car2.carnum=0
car2.hitboxh=Rect(car2.position.x-101,car2.position.y-5,101,10)
car2.hitboxv=Rect(car2.position.x-5,car2.position.y-101,5,202)
randomcarlist.append(car2)
car3=SpriteNode('img3.png')
car3.blend_mode=BLEND_MULTIPLY
car3.position=(x,y)
car3.rotnum=0
car3.num=3
car3.calnum=0
car3.carnum=0
car3.hitboxh=Rect(car3.position.x-101,car3.position.y-5,202,10)
car3.hitboxv=Rect(car3.position.x-5,car3.position.y-101,10,101)
randomcarlist.append(car3)
car4=SpriteNode('img4.png')
car4.blend_mode=BLEND_MULTIPLY
car4.position=(x,y)
car4.rotnum=0
car4.num=4
car4.calnum=0
car4.carnum=0
car4.hitboxh=Rect(car4.position.x,car4.position.y-5,101,10)
car4.hitboxv=Rect(car4.position.x-5,car4.position.y-101,10,202)
randomcarlist.append(car4)
car5=SpriteNode('img5.png')
car5.blend_mode=BLEND_MULTIPLY
car5.position=(x,y)
car5.rotnum=0
car5.num=5
car5.calnum=0
car5.carnum=0
car5.hitboxh=Rect(car5.position.x-101,car5.position.y-5,101,10)
car5.hitboxv=Rect(car5.position.x-5,car5.position.y,5,101)
randomcarlist.append(car5)
car6=SpriteNode('img6.png')
car6.blend_mode=BLEND_MULTIPLY
car6.position=(x,y)
car6.rotnum=0
car6.num=6
car6.calnum=0
car6.carnum=0
car6.hitboxh=Rect(car6.position.x-101,car6.position.y-5,101,10)
car6.hitboxv=Rect(car6.position.x-5,car6.position.y-101,10,101)
randomcarlist.append(car6)
car7=SpriteNode('img7.png')
car7.blend_mode=BLEND_MULTIPLY
car7.position=(x,y)
car7.rotnum=0
car7.num=7
car7.calnum=0
car7.carnum=0
car7.hitboxh=Rect(car7.position.x,car7.position.y-5,101,10)
car7.hitboxv=Rect(car7.position.x-5,car7.position.y-101,10,101)
randomcarlist.append(car7)
car8=SpriteNode('img8.png')
car8.blend_mode=BLEND_MULTIPLY
car8.position=(x,y)
car8.rotnum=0
car8.num=8
car8.calnum=0
car8.carnum=0
car8.hitboxh=Rect(car8.position.x,car8.position.y-5,101,10)
car8.hitboxv=Rect(car8.position.x-5,car8.position.y,5,101)
randomcarlist.append(car8)
car9=SpriteNode('img9.png')
car9.blend_mode=BLEND_MULTIPLY
car9.position=(x,y)
car9.rotnum=0
car9.num=9
car9.calnum=0
car9.carnum=0
car9.hitboxh=Rect(car9.position.x-101,car9.position.y-5,202,10)
car9.hitboxv=Rect(car9.position.x-0.5,car9.position.y-0.5,1,1)
randomcarlist.append(car9)
car10=SpriteNode('img10.png')
car10.blend_mode=BLEND_MULTIPLY
car10.position=(x,y)
car10.rotnum=0
car10.num=9
car10.calnum=0
car10.carnum=0
car10.hitboxh=Rect(car10.position.x-0.5,car10.position.y-0.5,1,1)
car10.hitboxv=Rect(car10.position.x-5,car10.position.y-101,10,202)
randomcarlist.append(car10)
car11=SpriteNode('img11.png')
car11.blend_mode=BLEND_MULTIPLY
car11.position=(x,y)
car11.rotnum=0
car11.num=9
car11.calnum=0
car11.carnum=0
car11.hitboxh=Rect(car11.position.x-101,car11.position.y-5,202,10)
car11.hitboxv=Rect(car11.position.x-5,car11.position.y-101,10,202)
randomcarlist.append(car11)
car=random.choice(randomcarlist)
self.add_child(car)
car.rotatable=False
car.plusnum=pnum
self.carlist.append(car)
return car
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
if self.choosing==True:
for touch in self.touches.values():
for car in self.carlist:
if touch.location in car.bbox:
self.fmlable=self.spawn_fmlable(car)
self.fmcarposition=car.position
#print(self.fmcarposition)
#print((self.fmcarposition[0]-5,self.fmcarposition[1]))
self.pickone=True
self.choosing=False
if self.pickone==True:
for touch in self.touches.values():
for car in self.carlist:
if touch.location in car.bbox:
self.fmlable.remove_from_parent()
self.fmlable=self.spawn_fmlable(car)
self.fmcarposition=car.position
if self.t>=1:
#if not self.card.index==12 and not self.card2.index==12:
self.rotate()
self.movecollidewithcar()
self.rotate2()
self.movecollidewithcar2()
self.t=0
#if self.card.position==(self.fmcarposition[0]-5,self.fmcarposition[1]):
if self.atcar().position==self.fmcarposition:
#print('ok')
if self.card.index>=self.fishmeat.index:
self.fishtweight=self.fishtweight+self.card.index+1
self.win_lable.text='playing,you got one fish,fish total weight'+str(self.fishtweight)
self.newmap()
if self.atcar2().position==self.fmcarposition:
#print('ok')
if self.card2.index<=self.fishmeat.index:
self.win_lable.text='playing,fishmeat got eaten,fish total weight'+str(self.fishtweight)
self.newmap()
'''if self.card.index==12 and not self.card2.index==12:
self.win_lable.text='you win,touch to start a new game'
if self.card2.index==12 and not self.card.index==12:
self.win_lable.text='you lose,touch to start a new game'
if self.card.index==12 and self.card2.index==12:
self.win_lable.text='It is a draw,touch to start a new game'
'''
def touch_began(self, touch):
#self.newgame()
pass
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
if __name__ == '__main__':
run(MyScene(), show_fps=True)