Inspiration
It is a combination of GO and Chess. We mixed in aspects of starcraft and a unique method of deploying the sharks.
What it does
That is a valid question. Thanks for asking.
How we built it
Two of us played video games while providing moral support to our single coder.
Challenges we ran into
Having sharks follow the user input due to the multi-user and multi-touch inputs.
Accomplishments that we're proud of
The sharks moving and following user placed currents.
What we learned
Two of us learned the basics of coding using Greenfoot.
What's next for SharkChess
Having the Sharks fight each other.
this is the source code
coding: utf-8
from scene import * import sound import random import math A = Action
class MyScene (Scene): def setup(self): self.gridSize = [20,16] self.grid = [] self.square = self.size[0]/(self.gridSize[0]+2) self.corner = [self.square, self.size[1] - self.square * (self.gridSize[1]-1)] self.mines = [] for x in xrange(self.gridSize[0]): self.grid += [[]] for y in xrange(self.gridSize[1]): if x == 0: self.grid[x] += [[1]] elif x == 10 or x == 9 or x == 2 or x == 17: self.grid[x] += [[3]] #mine = SpriteNode("Mine.JPG", scale = .0777, position = ((x+1)*self.square, y*self.square + self.corner[1])) #mine.anchor_point = (0,0) #self.mines += [mine] #self.add_child(mine) elif x == self.gridSize[0]-1: self.grid[x] += [[2]] else: self.grid[x] += [[0]]
self.upCorner = [self.size[0]-self.square, self.size[1]]
self.listTower1 = []
self.listTower2 = []
self.selecting1 = SpriteNode("Shade.JPG", alpha = .5,position = (-100,-100), scale = .3022)
self.selecting2 = SpriteNode("Shade.JPG", alpha = .5,position = (-100,-100), scale = .3022)
self.add_child(self.selecting1)
self.add_child(self.selecting2)
for x in xrange(self.gridSize[1]-1):
self.makeTower1(0,x)
for x in xrange(self.gridSize[1]-1):
self.makeTower2(self.gridSize[0]-1,x)
self.select1disable = False
self.select2disable = False
self.drag1listChildren = [[],0]
self.drag2listChildren = [[],0]
self.drag1allow = False
self.drag2allow = False
self.soldierSpeed = 1
self.soldierCounter = 0
self.drag1list = []
self.drag2list = []
self.drag1go = []
self.drag2go = []
self.active_touch = {}
self.touchCount = 0
self.didMove1 = False
self.didMove2 = False
def did_change_size(self):
pass
def update(self):
stroke(1,1,1)
stroke_weight(1)
for x in xrange(self.gridSize[0]+1):
line(self.corner[0]+x*self.square,self.corner[1], self.corner[0]+x*self.square ,self.upCorner[1])
for y in xrange(self.gridSize[1]):
line(self.corner[0], self.corner[1]+y*self.square,self.upCorner[0], self.corner[1]+y*self.square)
self.soldierCounter += 1
if self.soldierCounter == 1:
self.soldierCounter = 0
for m in self.drag1list:
if m[0]!= "hi" and len(m[1])!=0:
goal = self.pointConvert(m[1][0][0],m[1][0][1])
mx = m[0].position[0]
my = m[0].position[1]
if self.distance(mx, my,goal[0],goal[1])<2:
m[0].position = goal
m[1].pop(0)
else:
if int(mx) < int(goal[0]):
mx += self.soldierSpeed
elif int(mx)>int(goal[0]):
mx -= self.soldierSpeed
if int(my) < int(goal[1]):
my += self.soldierSpeed
elif int(my)>int(goal[1]):
my -= self.soldierSpeed
m[0].position = (mx,my)
#print self.drag2list
for n in self.drag2list:
if n[0]!= "hi" and len(n[1])!=0:
goal = self.pointConvert(n[1][0][0],n[1][0][1])
nx = n[0].position[0]
ny = n[0].position[1]
if self.distance(nx, ny,goal[0],goal[1])<2:
n[0].position = goal
n[1].pop(0)
else:
if int(nx) < int(goal[0]):
nx += self.soldierSpeed
elif int(nx)>int(goal[0]):
nx -= self.soldierSpeed
if int(ny) < int(goal[1]):
ny += self.soldierSpeed
elif int(ny)>int(goal[1]):
ny -= self.soldierSpeed
n[0].position = (nx,ny)
def distance(self,x1,y1,x2,y2):
return ((x1-x2)**2 + (y1-y2)**2)**.5
def makeSoldier(self):
self.soldier = SpriteNode("Shark1.JPG", scale = .0576, position = (200,200))
self.add_child(self.soldier)
def makeTower1(self,row,col):
x = (row+1)*self.square
y = (col)*self.square + self.corner[1];
self.tower1 = SpriteNode("Tower1.JPG", scale = .1582, position = (x,y))
self.tower1.anchor_point = (0,0)
self.add_child(self.tower1)
def makeTower2(self,row,col):
x = (row+1)*self.square
y = (col)*self.square + self.corner[1];
self.tower2 = SpriteNode("Tower1.JPG", scale = .1582, position = (x,y))
self.tower2.anchor_point = (0,0)
self.add_child(self.tower2)
def touch_began(self, touch):
self.touchCount += 1
self.active_touch[touch.touch_id] = self.touchCount
x = int((touch.location[0] - touch.location[0]%self.square+1)/self.square)-1
y = int((touch.location[1]-self.corner[1] - (touch.location[1]-self.corner[1])%self.square+1)/self.square)
if 0<=x<self.gridSize[0] and 0<=y<self.gridSize[1]:
if x < self.gridSize[0]/2:
for child in self.drag1listChildren[0]:
child.remove_from_parent()
self.drag1listChildren = [[],0]
self.drag1listChildren[1] = self.active_touch[touch.touch_id]
# print self.drag1listChildren
self.drag1list += [["hi",[(x,y)]]]
if self.select1disable == False:
self.select1(x,y)
else:#create selection menu
self.selected = True
if x==-1 and 0<=y<=1:
pass
if self.grid[x][y] == [1]:
self.drag1allow = True
else: self.drag1allow = False
else:
for child in self.drag2listChildren[0]:
child.remove_from_parent()
self.drag2listChildren = [[],0]
self.drag2listChildren[1] = self.active_touch[touch.touch_id]
self.drag2list += [["hi",[(x,y)]]]
if self.select2disable == False:
self.select2(x,y)
else:#create selection menu
self.selected = True
if x==-1 and 0<=y<=1:
pass
if self.grid[x][y] == [2]:
self.drag2allow = True
else: self.drag2allow = False
def select1(self,x,y):
self.selecting1.remove_from_parent()
self.selecting1.anchor_point = (0,0)
self.selecting1.position = self.pointConvert(x,y)
self.add_child(self.selecting1)
def select2(self,x,y):
self.selecting2.remove_from_parent()
self.selecting2.anchor_point = (0,0)
self.selecting2.position = self.pointConvert(x,y)
self.add_child(self.selecting2)
def pointConvert(self,x,y):
return ((x+1)*self.square, y*self.square + self.corner[1])
def drag1(self,x,y):
self.drag1list[len(self.drag1list)-1][1] += [(x,y)]
drag1 = SpriteNode("path1.JPG", scale = .03499, alpha = .5)
drag1.anchor_point = (0,0)
drag1.position = self.pointConvert(x,y)
self.drag1listChildren[0] += [drag1]
self.add_child(drag1)
def drag2(self,x,y):
self.drag2list[len(self.drag2list)-1][1] += [(x,y)]
drag2 = SpriteNode("path1.JPG", scale = .03499, alpha = .5)
drag2.anchor_point = (0,0)
drag2.position = self.pointConvert(x,y)
self.drag2listChildren[0] += [drag2]
self.add_child(drag2)
def touch_moved(self, touch):
x = int((touch.location[0] - touch.location[0]%self.square+1)/self.square)-1
y = int((touch.location[1]-self.corner[1] - (touch.location[1]-self.corner[1])%self.square+1)/self.square)
if 0<=x<self.gridSize[0] and 0<=y<self.gridSize[1]:
if x< self.gridSize[0]/2 and self.drag1listChildren[1] == self.active_touch[touch.touch_id]:
self.didMove1 = True
le = len(self.drag1list)-1
if (x,y) != self.drag1list[le][1][len(self.drag1list[le][1])-1] and self.drag1allow:
self.drag1(x,y)
elif x>= self.gridSize[0]/2 and self.drag2listChildren[1] == self.active_touch[touch.touch_id]:
self.didMove2 = True
le = len(self.drag2list)-1
if (x,y) != self.drag2list[le][1][len(self.drag2list[le][1])-1] and self.drag2allow:
self.drag2(x,y)
def touch_ended(self, touch):
if self.drag1listChildren[1] == self.active_touch[touch.touch_id]:
if self.didMove1 == True:
soldier = SpriteNode("Shark1.JPG", scale = .0614, position = self.pointConvert(self.drag1list[len(self.drag1list)-1][1][0][0],self.drag1list[len(self.drag1list)-1][1][0][1]))
soldier.anchor_point = (0,0)
self.drag1list[len(self.drag1list)-1][0] = soldier
#self.drag1go += self.drag1list
#drag1list = []
self.add_child(soldier)
del self.active_touch[touch.touch_id]
self.didMove1 = False
else: pass
#miner = SpriteNode("Miner.JPG", scale = .0431,position = self.pointConvert(self.drag1list[len(self.drag1list)-1][1][0][0],self.drag1list[len(self.drag1list)-1][1][0][1]))
#self.drag1list[len(self.drag1list)-1][0] = miner
#miner.anchor_point = (0,0)
#self.add_child(miner)
elif self.drag2listChildren[1] == self.active_touch[touch.touch_id]:
if self.didMove2 == True:
del self.active_touch[touch.touch_id]
soldier = SpriteNode("Shark1.JPG", scale = .0614, position = self.pointConvert(self.drag2list[len(self.drag2list)-1][1][0][0],self.drag2list[len(self.drag2list)-1][1][0][1]))
soldier.anchor_point = (0,0)
self.drag2list[len(self.drag2list)-1][0] = soldier
#self.drag2go += self.drag2list
#self.drag2list = []
#print self.drag2list
self.add_child(soldier)
self.didMove2 = False
else: pass
# miner = SpriteNode("Miner.JPG", scale = .0431,position = self.pointConvert(self.drag2list[len(self.drag2list)-1][1][0][0],self.drag2list[len(self.drag2list)-1][1][0][1]))
#self.drag2list[len(self.drag2list)-1][0] = miner
#count = 0
#for x in xrange(self.gridSize[0]):
#if self.grid[2][x] == [3]:
#self.drag2list[len(self.drag2list)-1][1] += [(self.drag2list[len(self.drag2list)-1][1][0],count)]
#break
#count += 1
#miner.anchor_point = (0,0)
#self.add_child(miner)
#print self.drag2list
if name == 'main': run(MyScene(), show_fps=False)
Built With
- pythonista
Log in or sign up for Devpost to join the conversation.