#*************************# # CamelCrusaders v 2.0.0 # # Sept. 21, 2007 # #*************************# #*************************# def display(): #Runs the game and calls act def act(): global lions, Bombs for each in lions: actlion(each) for each in Bombs: actBomb(each) def normalkeys(key, x, y): #Key press Reading #KEY PRESS AND RELEASE ADDED def releasekeys(key, x, y): global keys if keys.has_key(key): if keys[key] == 1: keys[key] = 0 def findPerp(angle): angle +=90 while angle >180: angle -= 360.0 while angle <= 180: angle += 360.0 return angle def drawfunc(): # 3 FUNCTIONS method = 2 #0-local, 1-diminishing squares, 2-constant squares if method == 0: tfunc0() if method == 1: tfunc1() if method == 2: tfunc2() def tfunc0(): #1st terrain function attempt global camerax, cameray, landsize lsize = landsize tempx = camerax-lsize tempy = cameray-lsize d = 1 while tempx < camerax+lsize: while tempy < cameray+ lsize: glColor3f(1.0,1.0,0.0) glBegin(GL_TRIANGLES) glVertex3f(int(tempx),int(tempy),terrainfunc(int(tempx), int(tempy))) glVertex3f(int(tempx+d),int(tempy),getheight(int(tempx+d),int(tempy))) glVertex3f(int(tempx),int(tempy+d),getheight(int(tempx), int(tempy+d))) glEnd() glColor3f(0.0,1.0,0.0) glBegin(GL_TRIANGLES) glVertex3f(int(tempx+d),int(tempy),getheight(int(tempx+d),int(tempy))) glVertex3f(int(tempx),int(tempy+d),getheight(int(tempx),int(tempy+d))) glVertex3f(int(tempx+d),int(tempy+d),getheight(int(tempx+d), int(tempy+d))) glEnd() tempy += d tempx += d tempy = cameray-landsize def tfunc1(): #2nd terrain function attempt def tfunc2(): global camerax, cameray, landsize, xmark, ymark,lions, lionmax, anglea initial = 0.1 rmax = landsize *100 r1 = 0.0 r2 = 0.5 numrows = 2 switchcount = 0 switchmax = 10 lionate = False based = landsize/2.0 cx = int(camerax/based)*based cy = int(cameray/based)*based #cx = camerax #cy = cameray rada = (int(anglea/15)*15*math.pi)/180.0 if abs(xmark-camerax)>10 or abs(ymark-cameray)>10: lionate = True xmark = camerax ymark = cameray if len(lions)>lionmax: lionate = False glColor3f(0.7, 0.6, 0.0) usize = rmax*1000 #drawtree(0,0,2) while r1< rmax: size = r2-r1 #print r1 t = 0 while t < numrows: tempx = cx-r2+size*t tempy = cy-r2 glColor3f(1.0,1.0,0.0) slopex = abs(terrainfunc(tempx+size, tempy)-terrainfunc(tempx, tempy))/size slopey = abs(terrainfunc(tempx, tempy+size)-terrainfunc(tempx, tempy))/size if(slopex<0.2 and slopey < 0.2): glColor3f(0.0, 1.0, 0.0) if(terrainfunc(tempx, tempy) > 200): glColor3f(0.95, 0.95, 0.95) glBegin(GL_TRIANGLES) xa1 = tempx-cx ya1 = tempy-cy xa2 = tempx+size-camerax ya2 = tempy+size-cameray x1 = xa1*math.cos(rada)-ya1*math.sin(rada)+cx y1 = ya1*math.cos(rada)+xa1*math.sin(rada)+cy x2 = xa2*math.cos(rada)-ya2*math.sin(rada)+cx y2 = ya2*math.cos(rada)+xa2*math.sin(rada)+cy x3 = xa1*math.cos(rada)-ya2*math.sin(rada)+cx y3 = ya2*math.cos(rada)+xa1*math.sin(rada)+cy x4 = xa2*math.cos(rada)-ya1*math.sin(rada)+cx y4 = ya1*math.cos(rada)+xa2*math.sin(rada)+cy glVertex3f(x1,y1,terrainfunc(x1, y1)) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3, y3)) glEnd() glColor3f(0.7, 0.6, 0.0) glBegin(GL_TRIANGLES) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3,y3)) glVertex3f(x2,y2,terrainfunc(x2, y2)) glEnd() t+=1 #if t%2 ==0: # drawtree(int((tempx+size)*10.0)/10.0,int(tempy*10.0)/10.0, 2) if (t == 3 or t == 5) and (r1 > 20 and r1< 30) and lionate: lions.append(Lion(tempx, tempy, terrainfunc(tempx, tempy))) t = 1 while t < numrows: tempx = cx-r2 tempy = cy-r2+size*t glColor3f(1.0,1.0,0.0) slopex = abs(terrainfunc(tempx+size, tempy)-terrainfunc(tempx, tempy))/size slopey = abs(terrainfunc(tempx, tempy+size)-terrainfunc(tempx, tempy))/size if(slopex<0.2 and slopey < 0.2): glColor3f(0.0, 1.0, 0.0) if(terrainfunc(tempx, tempy) > 200): glColor3f(0.95, 0.95, 0.95) glBegin(GL_TRIANGLES) xa1 = tempx-cx ya1 = tempy-cy xa2 = tempx+size-camerax ya2 = tempy+size-cameray x1 = xa1*math.cos(rada)-ya1*math.sin(rada)+cx y1 = ya1*math.cos(rada)+xa1*math.sin(rada)+cy x2 = xa2*math.cos(rada)-ya2*math.sin(rada)+cx y2 = ya2*math.cos(rada)+xa2*math.sin(rada)+cy x3 = xa1*math.cos(rada)-ya2*math.sin(rada)+cx y3 = ya2*math.cos(rada)+xa1*math.sin(rada)+cy x4 = xa2*math.cos(rada)-ya1*math.sin(rada)+cx y4 = ya1*math.cos(rada)+xa2*math.sin(rada)+cy glVertex3f(x1,y1,terrainfunc(x1, y1)) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3, y3)) glEnd() glColor3f(0.7, 0.6, 0.0) glBegin(GL_TRIANGLES) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3,y3)) glVertex3f(x2,y2,terrainfunc(x2, y2)) glEnd() t+=1 #if t%2 ==0: # drawtree(int((tempx+size)*10.0)/10.0,int(tempy*10.0)/10.0, 2) if (t == 3 or t == 5) and (r1 > 20 and r1< 30) and lionate: lions.append(Lion(tempx, tempy, terrainfunc(tempx, tempy))) t= 1 while t < numrows: tempx = cx-r2+size*t tempy = cy+r2-size glColor3f(1.0,1.0,0.0) slopex = abs(terrainfunc(tempx+size, tempy)-terrainfunc(tempx, tempy))/size slopey = abs(terrainfunc(tempx, tempy+size)-terrainfunc(tempx, tempy))/size if(slopex<0.2 and slopey < 0.2): glColor3f(0.0, 1.0, 0.0) if(terrainfunc(tempx, tempy) > 200): glColor3f(0.95, 0.95, 0.95) glBegin(GL_TRIANGLES) xa1 = tempx-cx ya1 = tempy-cy xa2 = tempx+size-camerax ya2 = tempy+size-cameray x1 = xa1*math.cos(rada)-ya1*math.sin(rada)+cx y1 = ya1*math.cos(rada)+xa1*math.sin(rada)+cy x2 = xa2*math.cos(rada)-ya2*math.sin(rada)+cx y2 = ya2*math.cos(rada)+xa2*math.sin(rada)+cy x3 = xa1*math.cos(rada)-ya2*math.sin(rada)+cx y3 = ya2*math.cos(rada)+xa1*math.sin(rada)+cy x4 = xa2*math.cos(rada)-ya1*math.sin(rada)+cx y4 = ya1*math.cos(rada)+xa2*math.sin(rada)+cy glVertex3f(x1,y1,terrainfunc(x1, y1)) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3, y3)) glEnd() glColor3f(0.7, 0.6, 0.0) glBegin(GL_TRIANGLES) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3,y3)) glVertex3f(x2,y2,terrainfunc(x2, y2)) glEnd() t+=1 #if t%2 ==0: # drawtree(int((tempx+size)*10.0)/10.0,int(tempy*10.0)/10.0, 2) if (t == 3 or t == 5) and (r1 > 20 and r1< 30) and lionate: lions.append(Lion(tempx, tempy, terrainfunc(tempx, tempy))) t = 1 while t < numrows-1: tempx = cx+r2-size tempy = cy-r2+t*size glColor3f(1.0,1.0,0.0) slopex = abs(terrainfunc(tempx+size, tempy)-terrainfunc(tempx, tempy))/size slopey = abs(terrainfunc(tempx, tempy+size)-terrainfunc(tempx, tempy))/size if(slopex<0.2 and slopey < 0.2): glColor3f(0.0, 1.0, 0.0) if(terrainfunc(tempx, tempy) > 200): glColor3f(0.95, 0.95, 0.95) glBegin(GL_TRIANGLES) xa1 = tempx-cx ya1 = tempy-cy xa2 = tempx+size-camerax ya2 = tempy+size-cameray x1 = xa1*math.cos(rada)-ya1*math.sin(rada)+cx y1 = ya1*math.cos(rada)+xa1*math.sin(rada)+cy x2 = xa2*math.cos(rada)-ya2*math.sin(rada)+cx y2 = ya2*math.cos(rada)+xa2*math.sin(rada)+cy x3 = xa1*math.cos(rada)-ya2*math.sin(rada)+cx y3 = ya2*math.cos(rada)+xa1*math.sin(rada)+cy x4 = xa2*math.cos(rada)-ya1*math.sin(rada)+cx y4 = ya1*math.cos(rada)+xa2*math.sin(rada)+cy glVertex3f(x1,y1,terrainfunc(x1, y1)) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3, y3)) glEnd() glColor3f(0.7, 0.6, 0.0) glBegin(GL_TRIANGLES) glVertex3f(x4,y4,terrainfunc(x4,y4)) glVertex3f(x3,y3,terrainfunc(x3,y3)) glVertex3f(x2,y2,terrainfunc(x2, y2)) glEnd() t+=1 #if t%2 ==0: # drawtree(int((tempx+size)*10.0)/10.0,int(tempy*10.0)/10.0, 2) if (t == 3 or t == 5) and (r1 > 20 and r1< 30) and lionate: lions.append(Lion(tempx, tempy, terrainfunc(tempx, tempy))) r = r1 r1 = r2 if numrows < 3: numrows = 3 if switchcount == 0: switchcount = 1 if r1 >= landsize/2.0: numrows = numrows - 1 else: switchcount += 1 if switchcount == switchmax: switchcount = 0 if r1 < landsize/8.0: numrows = numrows + 2 size = r2*2/(numrows-2) r2 = r2+size r = r1 def buildterrain(heights, txoffset, tyoffset): #Create a terrain height array return heights def terrainfunc(absx, absy): #return absx*absx+absy*absy #SINUSOIDAL #return 15*math.sin((absx)/50.0)+15*math.sin((absy)/50.0)#+5*math.sin((absx)/5.0)+5*math.sin((absy)/5.0) #absx = absx/100.0 #absy = absy/100.0 #return 15*math.sin((absx)/50.0)+15*math.sin((absy)/50.0)#+2*math.sin((absx)/5.0)+2*math.sin((absy)/5.0) #return 40*math.cos((absx)/20.0) #return absx*absx+absy*absy #return math.sqrt(absx*absx+absy*absy)*math.cos(math.sqrt(absx*absx+absy*absy)/10) #if absx == -0: # return 0 #return 1/(absx/100) #SPHERICAL #if math.sqrt(absx*absx+absy*absy) <100: # return math.sqrt(100*100-absx*absx-(absy*absy)/49) #return 0 #return math.ceil(absx/15.0)*15.0 #return (absx*absx*absx+absy*absy*absy)/10000 #if absx< 20: # return 2**absx #return 1000000 #return 10 scale = 10 absx += 30000 htx = 45*scale*math.sin((absx/(1000.0*scale))) widx = abs(200*scale*math.sin((absx)/(1000.0*scale))) if widx<50*scale: widx = 50.0*scale terrx = htx*math.sin((absx)/widx) hty = 45*scale*math.sin((absy/(1000.0*scale))) widy = abs(200*scale*math.sin((absy)/(1000.0*scale))) if widy<50*scale: widy = 50.0*scale terry = hty*math.sin((absy)/widy) xprop = 0.3*math.sin((absx)/(35*scale))+0.5 yprop = 1-xprop return terrx*xprop + terry*yprop def drawlandscape(): #DRAWS FARAWAY TERRAIN FROM TERRAIN ARRAY def drawterrain(heights, txoffset, tyoffset, border): #DRAWS NEARBY TERRAIN FROM TERRAIN HT ARRAY def getheight(x, y): global funcmode return terrainfunc(x, y) def terrainmove(x, y): #GENERATES NEW TERRAIN HEIGHT ARRAYS BASED ON LOCATION def distance2(x, y, a, b): return math.sqrt((a-x)*(a-x)+(b-y)*(b-y)) def distance(x, y, z, a, b, c): return math.sqrt((a-x)*(a-x)+(b-y)*(b-y)+(c-z)*(c-z)) def drawtree(x, y, height): #TREE RENDERER def drawlion(lion): #1000 lines of lion model rendering def framesec(): global lastinstance, spfmax secs = time.time()-lastinstance if(secs > spfmax): print ("+++OVERLOAD+++", secs) return secs def debug(mode, dstring): global debugmode if ((mode == debugmode) or (debugmode == 11) or (debugmode == 0)) and not(debugmode == -1): print dstring class GLOBVARS: def __init__(ang): self.angle=ang class Bomb: def __init__(self, s, tx, ty, tz, tvz, tvx, tvy): global gravity self.mag = s self.size = s self.x = tx self.y = ty self.vx = tvx self.vy = tvy self.az = gravity self.vz = tvz self.z = tz self.pulse = True self.life = 100000 #seconds self.time = 0 self.extime = 1 self.stage = 0 def drawBomb(t): #BOMB RENDERER def actBomb(t): #Bomb physics and explosion, kills nearby lions during explosion class Lion: def __init__(self, tx, ty, tz): global gravity self.h = 10 self.x = tx self.y = ty self.z = tz self.vx = 0 self.vy = 0 self.vz = 0 self.ax = 0 self.ay = 0 self.az = gravity self.mass = 25 self.life = True if tz == -100: self.z = getheight(tx, ty) def actlion(l): #LION PHYSICS AND AI #Physics are similar to user physics in display method #AI is basic and just follows the user class Camel: def __init__(self, health, height): self.h = health self.ht = height #************** #Debugger Class #************** class Debugger: def __init__(self): self.active = False def __init__(self, act): self.active = act def dprint(self, pntstr): if self.active: print(pntstr), return self.active def dprintln(self, pntstr): if self.active: print(pntstr), return self.active #end class Debugger #****************** #****************** #Start program from main() DEBUG = True main(DEBUG) #*************** #END APPLICATION #*************** #***************