예제 #1
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.color3(1.0, 0.0, 1.0);
        font = ol.getDefaultFont()
        s = "Lux!"
        w = ol.getStringWidth(font, 0.2, s)
        ol.drawString(font, (-w/2,0.1), 0.2, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        for i in range(2):

            if (i == 1):
                ol.color3(1.0,1.0,0.0);
            else:
                ol.color3(0.0,1.0,1.0);
                    
            ol.scale3((0.6, 0.6, 0.6))
            ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
            ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
            ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)
            
            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1, -1, -1))
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1,  1, -1))
            ol.vertex3((-1,  1, -1))
            ol.vertex3((-1, -1, -1))
            ol.vertex3((-1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP);
            ol.vertex3(( 1,  1,  1))
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1, -1,  1))
            ol.vertex3(( 1, -1,  1))
            ol.vertex3(( 1,  1,  1))
            ol.vertex3(( 1,  1, -1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1,  1, -1))
            ol.end()
예제 #2
0
파일: tweet.py 프로젝트: sgnls/openlase
    def run(self):
        if ol.init(10) < 0:
            return
        params = ol.RenderParams()
        params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
        params.on_speed = 2 / 120.0
        params.off_speed = 2 / 30.0
        params.flatness = 0.000001
        ol.setRenderParams(params)
        ol.setPixelShader(self.shade)
        time = 0
        frames = 0
        cur_tweets = self.tweets
        xpos = 0
        idx = 0
        startpos = 1.3
        while not self.die:
            ol.loadIdentity3()
            ol.loadIdentity()

            if cur_tweets is None and self.tweets is not None:
                cur_tweets = self.tweets
                idx = 0
                xpos = startpos

            w = 0
            #print cur_tweets
            if cur_tweets is not None:
                font = ol.getDefaultFont()
                w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
                col = ol.C_WHITE
                #print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
                ol.drawString(font, (xpos, 0.1), 0.4, col, cur_tweets[idx])

            #print "render"
            ftime = ol.renderFrame(60)
            #print "done"
            xpos -= 0.6 * ftime
            if xpos < (-w - 1) and cur_tweets is not None:
                xpos = startpos
                idx += 1
                idx %= len(cur_tweets)
                if self.tweets != cur_tweets:
                    idx = 0
                    cur_tweets = self.tweets
                    print("Reset and update")
                print("Finished, new idx: %d" % idx)
            frames += 1
            time += ftime
        ol.shutdown()
예제 #3
0
파일: tweet.py 프로젝트: marcan/openlase
	def run(self):
		if ol.init(10) < 0:
			return
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
		params.on_speed = 2/120.0
		params.off_speed = 2/30.0
		params.flatness = 0.000001
		ol.setRenderParams(params)
		ol.setPixelShader(self.shade)
		time = 0
		frames = 0
		cur_tweets = self.tweets
		xpos = 0
		idx = 0
		startpos = 1.3
		while not self.die:
			ol.loadIdentity3()
			ol.loadIdentity()

			if cur_tweets is None and self.tweets is not None:
				cur_tweets = self.tweets
				idx = 0
				xpos = startpos

			w = 0
			#print cur_tweets
			if cur_tweets is not None:
				font = ol.getDefaultFont()
				w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
				col = ol.C_WHITE
				#print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
				ol.drawString(font, (xpos,0.1), 0.4, col, cur_tweets[idx])
	
			#print "render"
			ftime = ol.renderFrame(60)
			#print "done"
			xpos -= 0.6*ftime
			if xpos < (-w-1) and cur_tweets is not None:
				xpos = startpos
				idx += 1
				idx %= len(cur_tweets)
				if self.tweets != cur_tweets:
					idx = 0
					cur_tweets = self.tweets
					print("Reset and update")
				print("Finished, new idx: %d"%idx)
			frames += 1
			time += ftime
		ol.shutdown()
예제 #4
0
    def draw(self):
        self.tweener.add_tween(self, scale_factor=0.25, time_scale = 1.0, duration=0.1, \
                               easing=pytweener.Easing.Expo.ease_in_out)

        ol.loadIdentity()
        ol.loadIdentity3()
        ol.translate3((-0.1, 0.0, 0.0))
        ol.scale3((self.scale_factor, self.scale_factor, self.scale_factor))

        # Spawn photons randomly
        if len(self.photons) < MAX_PHOTONS and random.random(
        ) < SPAWN_THRESHOLD:
            p = Photon()
            self.photons.append(p)

        # Draw photons
        dt = self.time_scale * (lux.time - self.last_time)
        self.last_time = lux.time
        self.tweener.update(lux.time - self.last_time)

        for p in self.photons:
            p.update(dt, self.photon_speed)
            p.draw()

        ol.color3(1.0, 1.0, 1.0)
        font = ol.getDefaultFont()
        s = "LASER"
        w = ol.getStringWidth(font, 1.0, s)
        ol.drawString(font, (-w / 2, 1.1), 1.0, s)

        # Draw the bounding box, with a very small hole in it.
        ol.color3(0.0, 1.0, 0.0)
        ol.begin(ol.LINESTRIP)
        ol.vertex3((CAVITY_SIZE[0] / 2, 0.1, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0] / 2, CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0] / 2, -CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, -CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, -0.1, 0.0))
        ol.end()
예제 #5
0
    def draw(self):
        self.tweener.add_tween(self, scale_factor=0.25, time_scale = 1.0, duration=0.1, \
                               easing=pytweener.Easing.Expo.ease_in_out)

        
        ol.loadIdentity()
        ol.loadIdentity3()
        ol.translate3((-0.1, 0.0, 0.0))
        ol.scale3((self.scale_factor, self.scale_factor, self.scale_factor))

        # Spawn photons randomly
        if len(self.photons) < MAX_PHOTONS and random.random() < SPAWN_THRESHOLD:
            p = Photon();
            self.photons.append(p)

        # Draw photons
        dt = self.time_scale * (lux.time - self.last_time)
        self.last_time = lux.time
        self.tweener.update(lux.time - self.last_time)
        
        for p in self.photons:
            p.update(dt, self.photon_speed)
            p.draw()

        ol.color3(1.0, 1.0, 1.0);
        font = ol.getDefaultFont()
        s = "LASER"
        w = ol.getStringWidth(font, 1.0, s)
        ol.drawString(font, (-w/2,1.1), 1.0, s)

        # Draw the bounding box, with a very small hole in it.
        ol.color3(0.0, 1.0, 0.0);
        ol.begin(ol.LINESTRIP)
        ol.vertex3(( CAVITY_SIZE[0]/2,  0.1, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2,  CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0]/2,  CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0]/2, -CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2, -CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2,  -0.1, 0.0))
        ol.end()
예제 #6
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.color3(1.0, 0.0, 1.0)
        font = ol.getDefaultFont()
        s = "davidad"
        x = sin(lux.time) * 0.5
        w = ol.getStringWidth(font, x, s)
        #ol.drawString(font, (-w/2,0), x, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        t = lux.time * 2
        lx = 0
        ly = 0
        for i in range(8):

            c = floor(t * 2 + i) % 3
            c = 3
            if (c == 1):
                #if(1):
                ol.color3(1.0, 1.0, 0.0)
            if (c == 2):
                ol.color3(0.0, 1.0, 1.0)
            if (c == 3):
                ol.color3(1.0, 0.0, 1.0)

            ol.scale3((0.6, 0.6, 0.6))
            #ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
            #ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
            #ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

            z = 2 * sin(t * 2)
            z = -1 + 4 * (t * 2 - floor(t * 2))
            #z = 4
            x = 0.5 * sin(t + i / 1.0)
            y = 0.5 * cos(t + i / 1.0)

            ol.begin(ol.LINESTRIP)
            ol.vertex3((x - 1, y - 1, z))
            ol.vertex3((x - 1, y + 1, z))
            ol.vertex3((x + 1, y + 1, z))
            ol.vertex3((x + 1, y - 1, z))
            ol.vertex3((x - 1, y - 1, z))
            ol.end()

            if i != 0:
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x - 1, y - 1, z))
                ol.vertex3((lx - 1, ly - 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x - 1, y + 1, z))
                ol.vertex3((lx - 1, ly + 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x + 1, y + 1, z))
                ol.vertex3((lx + 1, ly + 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x + 1, y - 1, z))
                ol.vertex3((lx + 1, ly - 1, z + 4))
                ol.end()

            lx = x
            ly = y
예제 #7
0
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol

import sys

if ol.init(10) < 0:
    sys.exit(1)
params = ol.RenderParams()
params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
params.on_speed = 2 / 120.0
params.off_speed = 2 / 30.0
params.flatness = 0.000001
ol.setRenderParams(params)

lines = sys.argv[1:]

SIZE = 0.4

while True:
    lc = len(lines)

    font = ol.getDefaultFont()
    yoff = (lc / 2.0) * 0.4

    for i, line in enumerate(lines):
        w = ol.getStringWidth(font, 0.4, line)
        ol.drawString(font, (-w / 2, yoff - i * 0.4), 0.4, ol.C_WHITE, line)

    ftime = ol.renderFrame(60)
예제 #8
0
import pylase as ol
from math import pi

ol.init()

time = 0
frames = 0

while True:
	ol.loadIdentity3()
	ol.loadIdentity()

	font = ol.getDefaultFont()
	s = "Hi!"
	w = ol.getStringWidth(font, 0.2, s)
	ol.drawString(font, (-w/2,0.1), 0.2, ol.C_WHITE, s)

	ol.perspective(60, 1, 1, 100)
	ol.translate3((0, 0, -3))

	for i in range(2):
		if (i == 1):
                    ol.color3(1.0,0.0,0.0);
                else:
                    ol.color3(0.0,1.0,0.0);

		ol.scale3((0.6, 0.6, 0.6))
		ol.rotate3Z(time * pi * 0.1)
		ol.rotate3X(time * pi * 0.8)
		ol.rotate3Y(time * pi * 0.73)
예제 #9
0
import pylase as ol
from math import pi

ol.init()

time = 0
frames = 0

while True:
    ol.loadIdentity3()
    ol.loadIdentity()

    font = ol.getDefaultFont()
    s = "Hi!"
    w = ol.getStringWidth(font, 0.2, s)
    ol.drawString(font, (-w / 2, 0.1), 0.2, ol.C_WHITE, s)

    ol.perspective(60, 1, 1, 100)
    ol.translate3((0, 0, -3))

    for i in range(2):
        ol.scale3((0.6, 0.6, 0.6))
        ol.rotate3Z(time * pi * 0.1)
        ol.rotate3X(time * pi * 0.8)
        ol.rotate3Y(time * pi * 0.73)

        ol.begin(ol.LINESTRIP)
        ol.vertex3((-1, -1, -1), ol.C_WHITE)
        ol.vertex3((1, -1, -1), ol.C_WHITE)
        ol.vertex3((1, 1, -1), ol.C_WHITE)
예제 #10
0
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol

import sys

if ol.init(10) < 0:
	sys.exit(1)
params = ol.RenderParams()
params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
params.on_speed = 2/120.0
params.off_speed = 2/30.0
params.flatness = 0.000001
ol.setRenderParams(params)

lines = sys.argv[1:]

SIZE = 0.4

while True:
	lc = len(lines)

	font = ol.getDefaultFont()
	yoff = (lc/2.0) * 0.4

	for i,line in enumerate(lines):
		w = ol.getStringWidth(font, 0.4, line)
		ol.drawString(font, (-w/2,yoff-i*0.4), 0.4, ol.C_WHITE, line)

	ftime = ol.renderFrame(60)
예제 #11
0
params = ol.RenderParams()
params.rate = 48000;
params.start_wait = 4
params.start_dwell = 2
params.curve_dwell = 1
params.corner_dwell = 2
params.end_dwell = 4
params.end_wait = 2
ol.setRenderParams(params)


if banner != "":
    font = ol.getDefaultFont()
    fsize = 10000.0
    yoff = (1/2.0) * fsize
    w = ol.getStringWidth(font, fsize, banner)

repeatCount = 1
startFrame = 1
endFrame = -1

for token in pairs(command.split()):
    if token[0] == 'repeat':
        repeatCount = int(token[1])
    elif token[0] == 'start':
        startFrame = int(token[1])
    elif token[0] == 'end':
        endFrame = int(token[1])

openPath = False
renderFrame = False
예제 #12
0
params.flatness = 0.000001
ol.setRenderParams(params)

height = float(sys.argv[1])
xpos = float(sys.argv[2])
ypos = float(sys.argv[3])
x_scroll_rate = float(sys.argv[4])
y_scroll_rate = float(sys.argv[5])
lines = sys.argv[6:]
lc = len(lines)

font = ol.getDefaultFont()
yoff = (lc/2.0) * height

while True:
	for i,line in enumerate(lines):
		w = ol.getStringWidth(font, height, line)
		ol.drawString(font, (-w/2+xpos,yoff-i*height+ypos), height, ol.C_WHITE, line)

	ftime = ol.renderFrame(30)
        xpos = xpos + x_scroll_rate
        if xpos < -3.0:
           xpos = 3.0
        if xpos > 3.0:
           xpos = -3.0
        ypos = ypos + y_scroll_rate
        if ypos < -3.0:
           ypos = 3.0
        if ypos > 3.0:
           ypos = -3.0
예제 #13
0
def game_thread():
	global DRAW
	global STATE
        global PLAYERS
        global player
	global numEnemies
	global numBullets
	global bulletSpawnOk

	def spawn_enemy():
		x, y, xVel, yVel = (0, 0, 0, 0)
		spawnType = random.randint(0, 7)

		"""
		SPAWN LOCATION -- corners and edges
		"""
		if spawnType == 0:
			# TOP RIGHT
			x = MIN_X
			y = MAX_Y
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 1:
			# BOTTOM RIGHT
			x = MIN_X
			y = MIN_Y
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 2:
			# BOTTOM LEFT
			x = MAX_X
			y = MIN_Y
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 3:
			# TOP LEFT
			x = MAX_X
			y = MAX_Y
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 4:
			# TOP EDGE
			x = random.uniform(MIN_X, MAX_X)
			y = MAX_Y
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			xVel *= 1 if random.randint(0, 1) else -1
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 5:
			# RIGHT EDGE
			x = MIN_X
			y = random.uniform(MIN_Y, MAX_Y)
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel *= 1 if random.randint(0, 1) else -1

		elif spawnType == 6:
			# BOTTOM EDGE
			x = random.uniform(MIN_X, MAX_X)
			y = MIN_Y
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			xVel *= 1 if random.randint(0, 1) else -1
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 7:
			# LEFT EDGE
			x = MAX_X
			y = random.uniform(MIN_Y, MAX_Y)
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel *= 1 if random.randint(0, 1) else -1

		#radius = random.uniform(ASTEROID_MIN_RADIUS, ASTEROID_MAX_RADIUS)
                radius = ASTEROID_MAX_RADIUS

		e = Asteroid(x, y, r=CMAX, g=CMAX, b=0, radius=radius)
		e.xVel = xVel
		e.yVel = yVel
		#e.thetaRate = random.uniform(-math.pi/100, math.pi/100)

		e.thetaRate = random.uniform(ASTEROID_SPIN_VEL_MAG_MIN,
									ASTEROID_SPIN_VEL_MAG_MAX)
		e.thetaRate *= 1 if random.randint(0, 1) else -1

		DRAW.objects.append(e)
		STATE.asteroids.append(e)
                
	def spawn_child(asteroid):
		x, y, xVel, yVel = (0, 0, 0, 0)
		spawnType = random.randint(0, 7)

		"""
		SPAWN LOCATION -- corners and edges
		"""
		if spawnType == 0:
			# TOP RIGHT
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 1:
			# BOTTOM RIGHT
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 2:
			# BOTTOM LEFT
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 3:
			# TOP LEFT
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 4:
			# TOP EDGE
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			xVel *= 1 if random.randint(0, 1) else -1
			yVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 5:
			# RIGHT EDGE
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel *= 1 if random.randint(0, 1) else -1

		elif spawnType == 6:
			# BOTTOM EDGE
			xVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			xVel *= 1 if random.randint(0, 1) else -1
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)

		elif spawnType == 7:
			# LEFT EDGE
			xVel = -random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel = random.uniform(ASTEROID_VEL_MAG_MIN, ASTEROID_VEL_MAG_MAX)
			yVel *= 1 if random.randint(0, 1) else -1

		radius = asteroid.radius / 2

		e = Asteroid(asteroid.x, asteroid.y, r=CMAX, g=CMAX, b=0, radius=radius)
		e.xVel = xVel * (ASTEROID_MAX_RADIUS / radius)
		e.yVel = yVel * (ASTEROID_MAX_RADIUS / radius)
		#e.thetaRate = random.uniform(-math.pi/100, math.pi/100)

		e.thetaRate = random.uniform(ASTEROID_SPIN_VEL_MAG_MIN,
									ASTEROID_SPIN_VEL_MAG_MAX)
		e.thetaRate *= 1 if random.randint(0, 1) else -1

		DRAW.objects.append(e)
		STATE.asteroids.append(e)
                
	def spawn_particles(x, y):
		np = random.randint(PARTICLE_SPAWN_MIN,
							PARTICLE_SPAWN_MAX)
		for i in range(np):
			p = Particle(x, y, CMAX, CMAX, CMAX)
			p.xVel = random.uniform(PARTICLE_MIN_X_VEL,
									PARTICLE_MAX_X_VEL)
			p.yVel = random.uniform(PARTICLE_MIN_Y_VEL,
									PARTICLE_MAX_Y_VEL)
			DRAW.objects.append(p)

        def start_new_game():
                ship = Ship(0, 0, rgb=COLOR_PINK, radius=SHIP_SIZE)
                healthbar = HealthBar(0, 0, r=0, g=CMAX, b=0, radius=BALL_RADIUS)

                # Initial placement
                ship.x = (MIN_X + MAX_X) /2
                ship.y = (MAX_Y + MIN_Y) /2
                healthbar.x = 0.75
                healthbar.y = 0.9

                DRAW.objects.append(ship)
                DRAW.objects.append(healthbar)

                STATE.ship = ship
                STATE.healthbar = healthbar
                if player:
                        player.score = 0
                for obj in DRAW.objects:
                        if type(obj) == Asteroid:
                                obj.destroy = True
                STATE.gameOver = False
                STATE.startNewGame = False

	# Player Object
	font = ol.getDefaultFont()
        start_new_game()
 	thread.start_new_thread(joystick_thread, ())

	while True:
		try:

			"""
			Game Events
			"""
			if numEnemies < MAX_NUM_ENEMIES and random.randint(0, 5) == 0:
				spawn_enemy()

			if not STATE.gameOver and numBullets < MAX_NUM_BULLETS:
				bulletSpawnOk = True
			else:
				bulletSpawnOk = False

			if STATE.gameOver and random.randint(0, 20) == 0:
				x = random.uniform(MIN_X, MAX_X)
				y = random.uniform(MIN_Y, MAX_Y)
				spawn_particles(x, y)

			"""
			Collision Detection
			"""
			# Populate lists
			# TODO: Let's not have to continually rebuild these
			ship = None
			healthbar = None
			bullets = []
			enemies = []
			particles = []

			for obj in DRAW.objects:
				if type(obj) == Asteroid:
					enemies.append(obj)
				elif type(obj) == Particle:
					particles.append(obj)
				elif type(obj) == Bullet:
					bullets.append(obj)
				elif type(obj) == Ship:
					ship = obj
				elif type(obj) == HealthBar:
					healthbar = obj

			# Bullet-enemy collisions
			for b in bullets:
				for e in enemies:
					if e.checkCollide(b) and not e.destroy:
						b.destroy = True
						e.subtract(ASTEROID_HEALTH_BULLET_HIT)
 						if e.health <= 0:
							e.destroy = True
                                                        if not STATE.gameOver:
                                                                player.score += 100
							spawn_particles(e.x, e.y)
                                                        if (e.radius > ASTEROID_MAX_RADIUS / 4):
                                                            spawn_child(e)
                                                            spawn_child(e)
                                                elif not STATE.gameOver:
                                                        player.score += 10


			# Player-enemy collisions
			# XXX/FIXME -- nesting hell! ahhh! cleanup, cleanup!
			if not ship:
				pass

			else:
				for e in enemies:
					if e.destroy:
						continue
					if e.checkCollide(ship):
						e.destroy = True
						spawn_particles(e.x, e.y)
                                                if (e.radius > ASTEROID_MAX_RADIUS / 4):
                                                        spawn_child(e)
                                                        spawn_child(e)

						if not SHIP_IS_INVINCIBLE:
							STATE.healthbar.subtract(SHIP_HEALTH_ASTEROID_HIT)

							# GAME OVER!
							if STATE.healthbar.health <= 0:
								ship.destroy = True
								healthbar.destroy = True
								spawn_particles(ship.x, ship.y)
								STATE.gameOver = True
								print "Game Over!"

                        if STATE.gameOver:
                                text = "GAME OVER!"
                                w = ol.getStringWidth(font, 0.3, text)
                                ol.drawString(font, (-w/2,0.15), 0.3, ol.C_WHITE, text)
                                if STATE.startNewGame:
                                        start_new_game()


			numEnemies = 0
			numBullets = 0

			"""
			Handle Onscreen Objects
			"""
			for i in range(len(DRAW.objects)):

				# XXX/FIXME/ANNOYING -- multithreaded, 
				# sometimes 'i' disappears from list
				# XXX -- find out where this happens and fix
				if i >= len(DRAW.objects):
					print "Weird out of range error at i=%d" %i
					break

				obj = DRAW.objects[i]

				# PLAYER
				if type(obj) == Ship:
					x = obj.x
                                        y = obj.y
 					x += obj.xVel
					y += obj.yVel
					if x < MIN_X:
                                                x = MAX_X
                                        if x > MAX_X:
                                                x = MIN_X
                                        if y < MIN_Y:
                                                y = MAX_Y
                                        if y > MAX_Y:
                                                y = MIN_Y
					obj.x = x
					obj.y = y
                                        #print "ship x,y = ", obj.x, obj.y

				# BULLETS
				elif type(obj) == Bullet:
					# XXX Recounted each iter due to terrible design 
					numBullets += 1
					x = obj.x
					y = obj.y
					x += BULLET_SPEED * math.cos(obj.theta)
					y += BULLET_SPEED * math.sin(obj.theta)
					if x < MIN_X:
                                                x = MAX_X
                                                obj.life -= 1
                                        if x > MAX_X:
                                                x = MIN_X
                                                obj.life -= 1
                                        if y < MIN_Y:
                                                y = MAX_Y
                                                obj.life -= 1
                                        if y > MAX_Y:
                                                y = MIN_Y
                                                obj.life -= 1
                                        if obj.life <= 0:
                                                obj.destroy = True
					obj.x = x
					obj.y = y

				elif type(obj) == Asteroid:
					# XXX Recounted each iter due to terrible design 
					numEnemies += 1
					x = obj.x
					y = obj.y
					x += obj.xVel
					y += obj.yVel
					if x < MIN_X:
                                                x = MAX_X
                                        if x > MAX_X:
                                                x = MIN_X
                                        if y < MIN_Y:
                                                y = MAX_Y
                                        if y > MAX_Y:
                                                y = MIN_Y
					obj.x = x
					obj.y = y
					obj.theta += obj.thetaRate

				elif type(obj) == Particle:
					x = obj.x
					y = obj.y
					x += obj.xVel
					y += obj.yVel

					if x < MIN_X or x > MAX_X or y < MIN_Y or y > MAX_Y :
						obj.destroy = True
						continue
					obj.x = x
					obj.y = y

					obj.life -= 1
					if obj.life <= 0:
						obj.destroy = True
						continue

                        if player:
                                score_string = str(player.score)
                                w = ol.getStringWidth(font, 0.2, score_string)
                                ol.drawString(font, (-w/2,0.9), 0.2, ol.C_WHITE, score_string)
                        draw_frame()
			time.sleep(0.02)

		except Exception as e:
			import sys, traceback
			print '\n---------------------'
			print 'GAME Exception: %s' % e
			traceback.print_tb(sys.exc_info()[2])
			print "---------------------\n"
			time.sleep(0.02)
예제 #14
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.color3(1.0, 0.0, 1.0);
        font = ol.getDefaultFont()
        s = "davidad"
	x = sin(lux.time)*0.5;
        w = ol.getStringWidth(font, x, s)
        #ol.drawString(font, (-w/2,0), x, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        t = lux.time*2
        lx = 0
        ly = 0
        for i in range(8):

            c = floor(t*2+i)%3
            c = 3
            if (c==1):
	    #if(1):
                ol.color3(1.0,1.0,0.0);
            if (c==2):
                ol.color3(0.0,1.0,1.0);
            if (c==3):
                ol.color3(1.0,0.0,1.0);
                    
            ol.scale3((0.6, 0.6, 0.6))
            #ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
            #ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
            #ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

	    z = 2*sin(t*2)
            z = -1+4*(t*2-floor(t*2))
            #z = 4
            x = 0.5*sin(t+i/1.0);
            y = 0.5*cos(t+i/1.0);

            ol.begin(ol.LINESTRIP)
            ol.vertex3((x-1,y-1,z))
            ol.vertex3((x-1,y+1,z))
            ol.vertex3((x+1,y+1,z))
            ol.vertex3((x+1,y-1,z))
            ol.vertex3((x-1,y-1,z))
            ol.end()

            if i != 0:
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x-1,y-1,z))
                ol.vertex3((lx-1,ly-1,z+4))
                ol.end()
            
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x-1,y+1,z))
                ol.vertex3((lx-1,ly+1,z+4))
                ol.end()
            
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x+1,y+1,z))
                ol.vertex3((lx+1,ly+1,z+4))
                ol.end()
            
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x+1,y-1,z))
                ol.vertex3((lx+1,ly-1,z+4))
                ol.end()

            lx = x
            ly = y
예제 #15
0
ol.setRenderParams(params)

height = float(sys.argv[1])
xpos = float(sys.argv[2])
ypos = float(sys.argv[3])
x_scroll_rate = float(sys.argv[4])
y_scroll_rate = float(sys.argv[5])
lines = sys.argv[6:]
lc = len(lines)

font = ol.getDefaultFont()
yoff = (lc / 2.0) * height

while True:
    for i, line in enumerate(lines):
        w = ol.getStringWidth(font, height, line)
        ol.drawString(font, (-w / 2 + xpos, yoff - i * height + ypos), height,
                      ol.C_WHITE, line)

    ftime = ol.renderFrame(30)
    xpos = xpos + x_scroll_rate
    if xpos < -3.0:
        xpos = 3.0
    if xpos > 3.0:
        xpos = -3.0
    ypos = ypos + y_scroll_rate
    if ypos < -3.0:
        ypos = 3.0
    if ypos > 3.0:
        ypos = -3.0
예제 #16
0
파일: timer.py 프로젝트: nomad2012/openlase
params.off_speed = 2/30.0
params.flatness = 0.000001
ol.setRenderParams(params)

if len(sys.argv) > 1:
    height = float(sys.argv[1])
else:
    height = 0.5

yoff = (1.0/2.0) * height
t0 = time.time()
t = 0.0
t1 = -2.0
text = "{0:02d}:{1:02d}.{2:02d}".format(int(t//60),int(t%60), int((t - int(t)) * 100))
font = ol.getDefaultFont()
width = ol.getStringWidth(font, height, text)
state = RESET
penalty = 0.0
new_penalty = False

while True:
    
    # check for input
    input_bytes = serial_port.readline()
    if len(input_bytes) > 0:
        print input_bytes,
        if input_bytes[0] == START_COMMAND:
            if state != RUNNING:
                t0 = time.time()
                penalty = 0.0
                state = RUNNING
예제 #17
0
params.flatness = 0.000001
ol.setRenderParams(params)

if len(sys.argv) > 1:
    height = float(sys.argv[1])
else:
    height = 0.5

yoff = (1.0 / 2.0) * height
t0 = time.time()
t = 0.0
t1 = -2.0
text = "{0:02d}:{1:02d}.{2:02d}".format(int(t // 60), int(t % 60),
                                        int((t - int(t)) * 100))
font = ol.getDefaultFont()
width = ol.getStringWidth(font, height, text)
state = RESET
penalty = 0.0
new_penalty = False

while True:

    # check for input
    input_bytes = serial_port.readline()
    if len(input_bytes) > 0:
        print input_bytes,
        if input_bytes[0] == START_COMMAND:
            if state != RUNNING:
                t0 = time.time()
                penalty = 0.0
                state = RUNNING