174 lines
3.8 KiB
Python
Executable file
174 lines
3.8 KiB
Python
Executable file
#import roc
|
|
import os
|
|
import sys
|
|
import roc
|
|
import pygame
|
|
from OpenGL.GL import *
|
|
from py3dutil import vect, quat
|
|
from roc import models
|
|
from roc import fonts
|
|
from roc import gametimer
|
|
from roc.platform import *
|
|
from roc import pipeline
|
|
import time
|
|
import collections
|
|
import random
|
|
import math
|
|
|
|
class partycle(object):
|
|
def __init__(self, x, y, xd, yd, rot, rotd, color):
|
|
self.x = x
|
|
self.y = y
|
|
self.xd = xd
|
|
self.yd = yd
|
|
self.rot = rot
|
|
self.rotd = rotd
|
|
self.color = color
|
|
|
|
@classmethod
|
|
def random(cls):
|
|
x, y = [((random.random() * 2.0) - 1.0) * 10.0 for _ in range(2)]
|
|
xd, yd = [((random.random() * 2.0) - 1.0) * 4.0 for _ in range(2)]
|
|
hue = random.random()
|
|
m1 = 1.0
|
|
h1 = hue * 6.0
|
|
s1 = 1.0 - abs((h1 % 2.0) - 1.0)
|
|
if h1 < 1.0:
|
|
r, g, b = 1.0, s1, 0.0
|
|
elif h1 < 2.0:
|
|
r, g, b = s1, 1.0, 0.0
|
|
elif h1 < 3.0:
|
|
r, g, b = 0.0, 1.0, s1
|
|
elif h1 < 4.0:
|
|
r, g, b = 0.0, s1, 1.0
|
|
elif h1 < 5.0:
|
|
r, g, b = s1, 0.0, 1.0
|
|
elif h1 < 6.0:
|
|
r, g, b = 1.0, 0.0, s1
|
|
|
|
rot = random.random() * 90.0
|
|
rotd = ((random.random() * 2.0) - 1.0) * 3.0
|
|
rv = cls(x, y, xd, yd, rot, rotd, (r, g, b, 1.0))
|
|
|
|
return rv
|
|
|
|
def movestep(self):
|
|
self.x += self.xd
|
|
self.y += self.yd
|
|
self.xd *= 0.985
|
|
self.yd *= 0.985
|
|
self.rot += self.rotd
|
|
|
|
class test_engine(roc.engine.base_engine):
|
|
def __init__(self):
|
|
self.font = models.mgr.fontlib["micross20"]
|
|
self.text1 = models.TextModel("micross20", "#$% 0123 ,,,, Hello world!\xa8\xa8\xa8F", (1.0, 1.0, 0.5, 1.0))
|
|
self.string = ""
|
|
self.move = 199.0
|
|
self.moveinc = 1.0
|
|
self.particles = collections.deque()
|
|
self.particles.append(partycle.random())
|
|
|
|
|
|
|
|
def frame(self, events):
|
|
#print "*** Starting frame"
|
|
# pink triangle
|
|
glDisable(GL_BLEND)
|
|
glDisable(GL_TEXTURE_2D)
|
|
glBegin(GL_TRIANGLE_STRIP)
|
|
glNormal3f(0.0, 0.0, 1.0)
|
|
glTexCoord2f(0.0, 0.0)
|
|
glColor4f(1.0, 0.0, 0.5, 0.0)
|
|
glVertex3f( 20.0, 50.0, 1.0)
|
|
glVertex3f( 20.0, 600.0, 1.0)
|
|
glVertex3f( 400.0, 50.0, 1.0)
|
|
glEnd()
|
|
|
|
# yellow square
|
|
glBegin(GL_TRIANGLE_STRIP)
|
|
glNormal3f(0.0, 0.0, 1.0)
|
|
glTexCoord2f(0.0, 0.0)
|
|
glColor4f(0.0, 0.2, 0.5, 0.8)
|
|
glVertex3f( 150.0, 20.0, -50.0)
|
|
glVertex3f( 150.0, 400.0, -50.0)
|
|
glVertex3f( 360.0, 20.0, -50.0)
|
|
glVertex3f( 360.0, 400.0, -50.0)
|
|
glEnd()
|
|
glEnable(GL_BLEND)
|
|
glEnable(GL_TEXTURE_2D)
|
|
glColor4f(1.0, 1.0, 1.0, 1.0)
|
|
|
|
# texture test
|
|
mdl = models.mgr.create("m_test")
|
|
glPushMatrix()
|
|
glTranslate(100.0, 300.0, -5.0)
|
|
mdl.render()
|
|
glPopMatrix()
|
|
|
|
|
|
|
|
|
|
# font test
|
|
glPushMatrix()
|
|
glTranslate(200.0, 200.0, 5.0)
|
|
self.text1.render()
|
|
glPopMatrix()
|
|
|
|
for x in range(gametimer.num_frames(10)):
|
|
self.move = self.move + self.moveinc
|
|
if self.move > 300.0:
|
|
self.moveinc = -1.0
|
|
elif self.move < 200.0:
|
|
self.moveinc = 1.0
|
|
for party in self.particles:
|
|
party.movestep()
|
|
if self.moveinc > 0.0:
|
|
party = partycle.random()
|
|
self.particles.append(party)
|
|
#print party.color
|
|
else:
|
|
self.particles.popleft()
|
|
|
|
|
|
glPushMatrix()
|
|
glTranslate(self.move, 250.0, 5.0)
|
|
|
|
|
|
"""
|
|
if len(self.string) > 61:
|
|
self.string = ""
|
|
|
|
for x in xrange(gametimer.num_frames(1000)):
|
|
self.string = self.string + str(len(self.string) % 10)
|
|
"""
|
|
for x in range(gametimer.num_frames(100)):
|
|
self.string = str(round(gametimer.get_fps(), 1))
|
|
#print len(gametimer.g_framelist)
|
|
|
|
|
|
self.font.render(self.string)
|
|
glPopMatrix()
|
|
|
|
# texture test
|
|
mdl2 = models.mgr.create("m_particle")
|
|
mdl2.layers[0].color = None
|
|
#print mdl2.layers[0].mesh
|
|
for party in self.particles:
|
|
glPushMatrix()
|
|
glTranslate(600.0 + party.x, 350.0 + party.y, 6.0)
|
|
glRotate(party.rot, 0.0, 0.0, 1.0)
|
|
glColor4f(*party.color)
|
|
mdl2.render()
|
|
glPopMatrix()
|
|
|
|
|
|
|
|
roc.video.width = 1024
|
|
roc.video.height = 768
|
|
roc.init2d()
|
|
roc.set_engine(test_engine())
|
|
roc.main()
|
|
|
|
|
|
|