Commits

Pierre Surply  committed ee8dc03

Added OpenGL

  • Participants
  • Parent commits 416d337

Comments (0)

Files changed (15)

File res/img/biome_cursor.png

Removed
Old image

File res/img/biome_cursor_max.png

Removed
Old image

File res/img/biomes_max.png

Removed
Old image

File res/img/cursor.png

Old
Old image
New
New image

File res/img/floor.png

Old
Old image
New
New image

File res/img/lvl_elts.png

Old
Old image
New
New image

File res/img/robots.png

Old
Old image
New
New image

File src/dashboard.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>. 
 ## 
 ## Started on  Thu Jun 28 21:12:48 2012 Pierre Surply
-## Last update Wed Aug  1 17:47:02 2012 Pierre Surply
+## Last update Sun Aug 26 19:29:33 2012 Pierre Surply
 ##
 
 import pygame
         h = display.window.get_height()
         self.terminal.display(display, (0, 0, w/16-1, h/12-1))
         display.render_terminal()
-        self.worldmap.render(display.window, \
-                                    (w/2+((w/2 - 256) / 2), 16),\
-                                 (self.select_x, self.select_y))
+        self.worldmap.render((w, h), (self.select_x, self.select_y))
         display.flip()
         return events.get_key_once(K_RETURN)
 

File src/display.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>. 
 ## 
 ## Started on  Wed May  9 17:19:46 2012 Pierre Surply
-## Last update Wed Aug  1 17:47:19 2012 Pierre Surply
+## Last update Mon Aug 27 13:16:53 2012 Pierre Surply
 ##
 
 import pygame
 from pygame.locals import *
 
+from OpenGL.GL import *
+from OpenGL.GLU import *
+
 import surface
 
 class Display:
         pygame.init()
         pygame.display.set_caption("BASIC-RoBots")
         self.set_display((640, 480))
-        self.set_bg()
+
+        glEnable(GL_TEXTURE_2D)
+        glEnable (GL_BLEND);
+        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+        #self.set_bg()
         self.set_tile()
         self.ascii = pygame.image.load("res/img/font.png").convert_alpha()
         self.ascii_wb = surface.cut_surface(self.ascii, (8, 12))
                                                                      pygame.Color(255, 255, 255, 255)),\
                                                (8, 12))
     def set_display(self, size):
-        self.window = pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.RESIZABLE)
+        self.window = pygame.display.set_mode(size, pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE)
+        glMatrixMode(GL_PROJECTION)
+        glLoadIdentity()
+        gluOrtho2D(0, self.window.get_width(), self.window.get_height(), 0)
 
     def set_bg(self):
         self.bg = pygame.Surface(self.window.get_size())
         self.env = pygame.Surface((self.window.get_width() / 2, self.window.get_height()))
 
     def set_tile(self):
-        self.tile = [None] * (self.window.get_height() / 12)
-        self.tile = [[None] * (self.window.get_width() / 8) for i in self.tile]
+        self.tile = [[None] * (self.window.get_width() / 8) \
+                         for i in range((self.window.get_height() / 12))]
 
     def set_tile_fullscreen(self):
         self.term_fullscreen = not(self.term_fullscreen)
-
+ 
     def render_terminal(self, fullscreen=False):
-        self.window.blit(self.bg, (0, 0))
+        glMatrixMode(GL_MODELVIEW)
+        glLoadIdentity()
+
         if fullscreen:
             w = len(self.tile[0])
         else:
             w = len(self.tile[0])/2
-        for y in range(len(self.tile)):
+        h = len(self.tile)
+        glDisable(GL_TEXTURE_2D)
+        glBegin(GL_QUADS)
+        glColor4ub(0, 0, 0, 0xCC)
+        glTexCoord2f(0, 0); glVertex2f(0, h*12)
+        glTexCoord2f(0, 1); glVertex2f(0, 0)
+        glTexCoord2f(1, 1); glVertex2f(w*8, 0)
+        glTexCoord2f(1, 0); glVertex2f(w*8, h*12)
+        glEnd()
+        glEnable(GL_TEXTURE_2D)
+        for y in range(h):
             for x in range(w):
                 if self.tile[y][x] != None:
-                    self.window.blit(self.tile2surface(self.tile[y][x]), (x * 8, y * 12))
+                    glBindTexture(GL_TEXTURE_2D, self.tile2surface(self.tile[y][x]))
+                    glBegin(GL_QUADS) 
+                    glColor3d(0xFF, 0xFF, 0xFF)
+                    glTexCoord2f(0, 0); glVertex2f(x*8, y*12+12)
+                    glTexCoord2f(0, 1); glVertex2f(x*8, y*12)
+                    glTexCoord2f(1, 1); glVertex2f(x*8+8, y*12)
+                    glTexCoord2f(1, 0); glVertex2f(x*8+8, y*12+12)
+                   
+                    glEnd()
 
     def flip(self):
         pygame.display.flip()
+        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
 
     def print_char(self, (x, y), tile):
         if len(self.tile) > y and len(self.tile[0]) > x:
     def resize(self, size):
         if size[0] >= 80 and size[1] >= 120: 
             self.set_display(size)
-            self.set_bg()
+            glViewport(0, 0, size[0], size[1])
             self.set_tile()
 
     def tile2surface(self, tile):
 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>. 
 ##
 ## Started on  Thu Jun 28 13:22:05 2012 Pierre Surply
-## Last update Fri Aug 17 23:10:22 2012 Pierre Surply
+## Last update Mon Aug 27 15:28:34 2012 Pierre Surply
 ##
 
 import os
 import random
 import pygame
 from pygame.locals import *
+from OpenGL.GL import *
+from OpenGL.GLU import *
 
 import surface
 import noise
 from robot import mothership, woodcutter
 
 class Env(savable.Savable):
-    temp_tiles = [((255, 255, 255, 255), 0, "Grass"),\
-                  ((150, 100, 0, 255), 1, "Dirt"),\
-                  ((0, 0, 100, 255), 2, "Water"),\
-                  ((255, 255, 150, 255), 3, "Sand"),\
-                  ((0, 0, 150, 255), 4, "Deep water"),\
-                  ((100, 100, 100, 255), 5, "Stone"),\
-                  ((255, 0, 0, 255), 6, "Lava"),\
-                  ((20, 20, 20, 255), 7, "Gravel"),\
-                  ((10, 10, 10, 255), 8, "Volvanic stone"),\
-                  ((100, 0, 100, 255), 9, "Meteorite dirt"),\
-                  ((100, 0, 255, 255), 10, "Meteorite stone"),\
-                  ((101, 101, 101, 255), 11, "Stone")]
+    temp_tiles = [((255, 255, 255, 255), 0, "Grass", 0.7),\
+                  ((150, 100, 0, 255), 1, "Dirt", 0.4),\
+                  ((0, 0, 100, 255), 2, "Water", 0),\
+                  ((255, 255, 150, 255), 3, "Sand", 0.2),\
+                  ((0, 0, 150, 255), 4, "Deep water", 0),\
+                  ((100, 100, 100, 255), 5, "Stone", 1),\
+                  ((255, 0, 0, 255), 6, "Lava", 0),\
+                  ((20, 20, 20, 255), 7, "Gravel", 0.4),\
+                  ((10, 10, 10, 255), 8, "Volvanic stone", 1),\
+                  ((100, 0, 100, 255), 9, "Meteorite dirt", 1),\
+                  ((100, 0, 255, 255), 10, "Meteorite stone", 1),\
+                  ((101, 101, 101, 255), 11, "Stone", 1)]
 
     temp_elts = [((0, 100, 0, 255), 0, "Tree"),\
                  ((150, 150, 150, 255), 1, "Stone"),\
         else:
             self.build(biome)
             self.save()
-        self.sprite_floor = surface.cut_surface(pygame.image.load("res/img/floor.png").convert_alpha(), (32, 32))
+        self.sprite_floor = surface.cut_surface(pygame.image.load("res/img/floor.png").convert_alpha(), (16, 16))
         self.sprite_floor_mini = surface.cut_surface(pygame.image.load("res/img/floor_mini.png").convert_alpha(), (2, 2))
-        self.sprite_elts = surface.cut_surface(pygame.image.load("res/img/lvl_elts.png").convert_alpha(), (32, 32))
-        self.sprite_robots = surface.cut_rotate(pygame.image.load("res/img/robots.png").convert_alpha(), (32, 32))
-        self.cursor = pygame.image.load("res/img/cursor.png").convert_alpha()
-        self.undef = pygame.Surface((32, 32))
-        self.undef.fill(pygame.Color(32,32,32))
+        self.sprite_elts = surface.cut_surface(pygame.image.load("res/img/lvl_elts.png").convert_alpha(), (16, 16))
+        self.sprite_robots = surface.cut_surface(pygame.image.load("res/img/robots.png").convert_alpha(), (32, 32))
+        self.cursor = surface.surface2texture(pygame.image.load("res/img/cursor.png").convert_alpha())
         
     def init_tile(self):
         self.tile = [[0] * self.size for i in range(self.size)]
         else:
             return None
 
-    def render(self, surface, (select_x, select_y, cam_w, cam_h), (dx, dy)):
-        begin_x = select_x - (cam_w/2)
-        begin_y = select_y - (cam_h/2)
-        for y in range(max(begin_y, 0), min(begin_y + cam_h, self.size)):
-            for x in range(max(begin_x, 0), min(begin_x + cam_w, self.size)):
-                surface.blit(self.sprite_floor[self.tile[x][y]], ((x-begin_x)*32 + dx, (y-begin_y)*32 + dy))
-                elts = self.tile_elts[x][y]
-                if elts != None:
-                    surface.blit(self.sprite_elts[elts], ((x-begin_x)*32 + dx, (y-begin_y)*32 + dy))
+    def render_case(self, x, y):
+        glBindTexture(GL_TEXTURE_2D, self.sprite_floor[self.tile[x][y]])
+        z = self.temp_tiles[self.tile[x][y]][3]
+        glBegin(GL_QUADS)
+        glTexCoord2d(0,0); glVertex3d(x, y+1, z)
+        glTexCoord2d(0,1); glVertex3d(x, y, z)
+        glTexCoord2d(1,1); glVertex3d(x+1, y, z)
+        glTexCoord2d(1,0); glVertex3d(x+1, y+1, z)
+        glEnd()
+        if (not self.tile[x][y] in [2, 4]):
+            if (y >= self.size-1 or self.temp_tiles[self.tile[x][y+1]][3] < z):
+                glBegin(GL_QUADS)
+                glTexCoord2d(0,0); glVertex3d(x, y+1, z-1)
+                glTexCoord2d(0,1); glVertex3d(x, y+1, z)
+                glTexCoord2d(1,1); glVertex3d(x+1, y+1, z)
+                glTexCoord2d(1,0); glVertex3d(x+1, y+1, z-1)
+                glEnd()
+            if (y <= 0 or self.temp_tiles[self.tile[x][y-1]][3] < z):
+                glBegin(GL_QUADS)
+                glTexCoord2d(0,0); glVertex3d(x, y, z-1)
+                glTexCoord2d(0,1); glVertex3d(x, y, z)
+                glTexCoord2d(1,1); glVertex3d(x+1, y, z)
+                glTexCoord2d(1,0); glVertex3d(x+1, y, z-1)
+                glEnd()
+            if (x <= 0 or self.temp_tiles[self.tile[x-1][y]][3] < z):
+                glBegin(GL_QUADS)
+                glTexCoord2d(0,0); glVertex3d(x, y, z-1)
+                glTexCoord2d(0,1); glVertex3d(x, y, z)
+                glTexCoord2d(1,1); glVertex3d(x, y+1, z)
+                glTexCoord2d(1,0); glVertex3d(x, y+1, z-1)
+                glEnd()
+            if (x >= self.size-1 or self.temp_tiles[self.tile[x+1][y]][3] < z):
+                glBegin(GL_QUADS)
+                glTexCoord2d(0,0); glVertex3d(x+1, y, z-1)
+                glTexCoord2d(0,1); glVertex3d(x+1, y, z)
+                glTexCoord2d(1,1); glVertex3d(x+1, y+1, z)
+                glTexCoord2d(1,0); glVertex3d(x+1, y+1, z-1)
+                glEnd()
+
+    def render_elt(self, x, y): 
+        glBindTexture(GL_TEXTURE_2D, self.sprite_elts[self.tile_elts[x][y]])
+        z = self.temp_tiles[self.tile[x][y]][3]
+        glBegin(GL_QUADS)
+        glTexCoord2d(0,0); glVertex3d(x, y, z)
+        glTexCoord2d(0,1); glVertex3d(x, y, z+1.41)
+        glTexCoord2d(1,1); glVertex3d(x+1, y+1, z+1.41)
+        glTexCoord2d(1,0); glVertex3d(x+1, y+1, z)
+        glEnd()
+        glBegin(GL_QUADS)
+        glTexCoord2d(0,0); glVertex3d(x, y+1, z)
+        glTexCoord2d(0,1); glVertex3d(x, y+1, z+1.41)
+        glTexCoord2d(1,1); glVertex3d(x+1, y, z+1.41)
+        glTexCoord2d(1,0); glVertex3d(x+1, y, z)
+        glEnd()
+
+    def render_robot(self, r):
+        glBindTexture(GL_TEXTURE_2D, self.sprite_robots[r.id_sprite])
+        z = self.temp_tiles[self.tile[r.pos_x][r.pos_y]][3] + 0.4
+        glPushMatrix()
+        glTranslated(r.pos_x+0.5, r.pos_y+0.5, 0)
+        glRotated(90*r.orient, 0, 0, 1)
+        glBegin(GL_QUADS)
+        glTexCoord2d(0,0); glVertex3d(-0.5, 0.5, z)
+        glTexCoord2d(0,1); glVertex3d(-0.5, -0.5, z)
+        glTexCoord2d(1,1); glVertex3d(0.5, -0.5, z)
+        glTexCoord2d(1,0); glVertex3d(0.5, 0.5, z)
+        glEnd()
+        glPopMatrix()
+
+    def render(self, (select_x, select_y, cam_w, cam_h), (dx, dy)):
+        glMatrixMode(GL_PROJECTION)
+        glPushMatrix()
+        glLoadIdentity()
+        gluPerspective(80, cam_w/cam_h,1,64)
+        glEnable(GL_DEPTH_TEST)
+        glEnable(GL_ALPHA_TEST);
+        glAlphaFunc(GL_GREATER, 127.0/255.0);
+
+        glMatrixMode(GL_MODELVIEW)
+        glLoadIdentity()
+
+        gluLookAt(-3, 5, 10,\
+                      0, 0, 0, \
+                      0, 0, 1)
+
+        z = self.temp_tiles[self.tile[select_x][select_y]][3] + 0.1
+        glBindTexture(GL_TEXTURE_2D, self.cursor)
+        glBegin(GL_QUADS)
+        glTexCoord2d(0,0); glVertex3d(-0.5-dx, 0.5-dy, z)
+        glTexCoord2d(0,1); glVertex3d(-0.5-dx, -0.5-dy, z)
+        glTexCoord2d(1,1); glVertex3d(0.5-dx, -0.5-dy, z)
+        glTexCoord2d(1,0); glVertex3d(0.5-dx, 0.5-dy, z)
+        glEnd()
+        glTranslated(-select_x-0.5-dx, -select_y-0.5-dy, 0);
+
+        for y in range(max(select_y-16, 0), min(select_y + 10, self.size)):
+            for x in range(max(select_x-9, 0), min(select_x + 16, self.size)):
+                self.render_case(x, y)
+                if self.tile_elts[x][y] != None:
+                    self.render_elt(x, y)
         for i in self.robots:
             x = i.pos_x
             y = i.pos_y
-            if x >= begin_x and \
-                    y >= begin_y and \
-                    x < begin_x + cam_w and \
-                    y < begin_y + cam_h:
-                surface.blit(self.render_robot(i), ((x-begin_x)*32 + dx, (y-begin_y)*32 + dy))
-        surface.blit(self.cursor, ((select_x-begin_x)*32 + dx, (select_y-begin_y)*32 + dy))
-        if begin_x < 0:
-            for y in range(0, cam_h):
-                for x in range(0, -begin_x):
-                    surface.blit(self.undef, (x*32 + dx, y*32 + dy))
-        elif begin_x + cam_w > self.size:
-            for y in range(0, cam_h):
-                for x in range(self.size - begin_x, cam_w):
-                    surface.blit(self.undef, (x*32 + dx, y*32 + dy))
-        if begin_y < 0:
-            for y in range(0, -begin_y):
-                for x in range(0, cam_w):
-                    surface.blit(self.undef, (x*32 + dx, y*32 + dy))
-        elif begin_y + cam_h > self.size:
-            for y in range(self.size - begin_y, cam_h):
-                for x in range(0, cam_w):
-                    surface.blit(self.undef, (x*32 + dx, y*32 + dy))
+            if x >= select_x-8 and \
+                    y >= select_y-16 and \
+                    x < select_x+16 and \
+                    y < select_y+8:
+                self.render_robot(i)
+        glMatrixMode(GL_PROJECTION)
+        glPopMatrix()
 
-    def render_robot(self, r):
-        return self.sprite_robots[r.id_sprite][r.orient]
+        glDisable(GL_DEPTH_TEST)
+        glDisable(GL_ALPHA_TEST);
 
     def render_mini(self, surface, (dx, dy)):
         for y in range(self.size):
         return [ i.get_pos() for i in self.robots]
             
     def update_robots(self, n, display, events):
-        self.robots[self.running_robot].update((self.running_robot == n), \
-                                                   display, events)
-        if n != None and self.running_robot != n:
-            self.robots[n].update(True, \
-                                      display, events)
-        self.running_robot += 1
-        if self.running_robot >= len(self.robots):
-            self.running_robot = 0
+        for i in range(len(self.robots)):
+            self.robots[i].update((i == n), \
+                                   display, events)
+        #self.robots[self.running_robot].update((self.running_robot == n), \
+        #                                           display, events)
+        #if n != None and self.running_robot != n:
+        #    self.robots[n].update(True, \
+        #                              display, events)
+        #self.running_robot += 1
+        #if self.running_robot >= len(self.robots):
+        #    self.running_robot = 0
 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ##  
 ## Started on  Thu Jun 28 15:31:47 2012 Pierre Surply
-## Last update Sat Aug 18 10:44:32 2012 Pierre Surply
+## Last update Mon Aug 27 12:36:49 2012 Pierre Surply
 ##
 
 import pygame
         self.env.update_robots(self.select_robot, display, events)
         if self.select_robot != None:
             self.select_x, self.select_y = self.env.get_pos_robot(self.select_robot)
+            self.env.render((self.select_x, self.select_y, \
+                                     display.window.get_width(), \
+                                     display.window.get_height()), \
+                                (3, 1))
             display.render_terminal()
-            self.env.render(display.window, \
-                                (self.select_x, self.select_y, \
-                                     display.window.get_width() / 64, \
-                                     display.window.get_height() / 32), \
-                                (display.window.get_width()/2, 0))
         else:
             self.handle_events(events)
-            self.env.render(display.window, \
-                                (self.select_x, self.select_y, \
-                                     display.window.get_width() / 32, \
-                                     display.window.get_height() / 32), \
+            self.env.render((self.select_x, self.select_y, \
+                                     display.window.get_width(), \
+                                     display.window.get_height()), \
                                 (0,0))
         display.flip()
         return self.goto_dashboard
             self.select_y -= 1
         if arrows[1] and self.select_y < self.env.size-1:
             self.select_y += 1
-        if arrows[2] and self.select_x > 0:
+        if arrows[3] and self.select_x > 0:
             self.select_x -= 1
-        if arrows[3] and self.select_x < self.env.size-1:
+        if arrows[2] and self.select_x < self.env.size-1:
             self.select_x += 1
 
     def incr_select_robot(self, incr):

File src/robot/basic.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Sat May  5 13:04:41 2012 Pierre Surply
-## Last update Sun Aug 19 18:14:41 2012 Pierre Surply
+## Last update Sun Aug 19 20:47:54 2012 Pierre Surply
 ##
 
 import random
         return opr
     
     def print_debug(self):
-        self.terminal.clear()
-        self.terminal.write_line("\x04\x04\x04 Basic Debug \x04\x04\x04", 1)
-        self.terminal.write_line("Press N to execute next instruction")
-        self.terminal.write_line("Press R to quit debugger\n")
-        self.terminal.write_line("Instructions (line " + str(self.line) + ")", 1)
-        for i in self.opr[self.line-2:self.line]:
-            self.terminal.write_line("   " + " ".join(i))
         if self.line < len(self.opr):
+            self.terminal.clear()
+            self.terminal.write_line("\x04\x04\x04 Basic Debug \x04\x04\x04", 1)
+            self.terminal.write_line("Press N to execute next instruction")
+            self.terminal.write_line("Press R to quit debugger\n")
+            self.terminal.write_line("Instructions (line " + str(self.line) + ")", 1)
+            for i in self.opr[self.line-2:self.line]:
+                self.terminal.write_line("   " + " ".join(i))
             self.terminal.write_line("\x1A  " + " ".join(self.opr[self.line]))
-        for i in self.opr[self.line+1:self.line+5]:
-            self.terminal.write_line("   " + " ".join(i))
-        self.terminal.write_line("\n", 1)
-        self.terminal.write_line("Registers", 1)
-        for i in sorted(self.robot.mem.keys()):
-            self.terminal.write(" ")
-            self.terminal.write(i, 1)
-            self.terminal.write(":" + hex(self.robot.mem[i]))
-        self.terminal.write_line("\n")
-        self.terminal.write_line("Registers (RO)", 1)
-        mem_ro = self.robot.get_mem_ro()
-        for i in sorted(mem_ro):
-            self.terminal.write(" ")
-            self.terminal.write(i, 1)
-            self.terminal.write(":" + hex(mem_ro[i]))
-        self.terminal.write_line("\n")
-        self.terminal.write_line("Stack", 1)
-        if self.robot.mem_stack == []:
-            self.terminal.write_line("The stack is empty")
-        else:
-            for i in self.robot.mem_stack[-5::]:
-                self.terminal.write("\xB3" + hex(i))
-            self.terminal.write_line(" \x1B")
-        self.terminal.write_line("\nOut", 1)
+            for i in self.opr[self.line+1:self.line+5]:
+                self.terminal.write_line("   " + " ".join(i))
+            self.terminal.write_line("\n", 1)
+            self.terminal.write_line("Registers", 1)
+            for i in sorted(self.robot.mem.keys()):
+                self.terminal.write(" ")
+                self.terminal.write(i, 1)
+                self.terminal.write(":" + hex(self.robot.mem[i]))
+            self.terminal.write_line("\n")
+            self.terminal.write_line("Registers (RO)", 1)
+            mem_ro = self.robot.get_mem_ro()
+            for i in sorted(mem_ro):
+                self.terminal.write(" ")
+                self.terminal.write(i, 1)
+                self.terminal.write(":" + hex(mem_ro[i]))
+            self.terminal.write_line("\n")
+            self.terminal.write_line("Stack", 1)
+            if self.robot.mem_stack == []:
+                self.terminal.write_line("The stack is empty")
+            else:
+                for i in self.robot.mem_stack[-5::]:
+                    self.terminal.write("\xB3" + hex(i))
+                self.terminal.write_line(" \x1B")
+            self.terminal.write_line("\nOut", 1)
             
     def eval_line(self):
         if self.line < len(self.opr):

File src/robot/robot.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Sun Jul  1 15:34:10 2012 Pierre Surply
-## Last update Sun Aug 19 15:07:02 2012 Pierre Surply
+## Last update Mon Aug 27 15:10:00 2012 Pierre Surply
 ##
 
 import os
         self.ext_cmd = {"forward" : (self.forward, \
                                          "Move the robot forward", \
                                          "1 if the robot can move, 0 otherwise",\
-                                         (1, []),\
+                                         (0, []),\
                                          {}),\
                             "rotleft": (self.rot_left, \
                                             "Rotate the robot counterclockwise",\
                             "sendmsg": (self.sendmsg, \
                                          "Send a message (1 byte) to all robots in a small area",\
                                          "Number of robots which received the message",\
-                                         (5, []),\
+                                         (0, []),\
                                          {"A" : "message"}),\
                             "recvmsg": (self.recvmsg, \
                                             "Read a message sent by other robot",\
             return self.move_to(self.get_pos_forward())
 
     def rot_left(self):
-        return self.rot(-1)
+        return self.rot(1)
 
     def rot_right(self):
-        return self.rot(1)
+        return self.rot(-1)
         
     def rot(self, incr):
         self.orient += incr

File src/surface.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ##
 ## Started on  Thu Jun 28 13:23:22 2012 Pierre Surply
-## Last update Wed Aug  1 17:50:35 2012 Pierre Surply
+## Last update Mon Aug 27 15:23:08 2012 Pierre Surply
 ##
 
 import pygame
 from pygame.locals import *
 
+from OpenGL.GL import *
+from OpenGL.GLU import *
+
+
+def surface2texture(surface): 
+    texture = glGenTextures(1)
+    glBindTexture(GL_TEXTURE_2D, texture)
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, \
+                     surface.get_width(), \
+                     surface.get_height(), \
+                     0, GL_RGBA, GL_UNSIGNED_BYTE, \
+                     pygame.image.tostring(surface, "RGBA", 1))
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
+    return texture
+
 def cut_surface(surface, (w, h)):
     l_surface = []
     for y in range(surface.get_height() / h):
             new = pygame.Surface((w, h))
             new.blit(surface, (0, 0), pygame.Rect(x*w, y*h, w, h))
             new.set_colorkey(pygame.Color(255, 0, 255, 255))
-            l_surface.append(new)
+            l_surface.append(surface2texture(new))
     return l_surface
     
 def change_color(surface, front, back = pygame.Color(255, 0, 255, 255)):
             elif (c == (255, 0, 255, 255)):
                 new_surface.set_at((x, y), back)
     return new_surface
-
-def rotate(surface):
-    return [surface, \
-                pygame.transform.rotate(surface, -90),\
-                pygame.transform.flip(surface, False, True), \
-                pygame.transform.rotate(surface, 90)]
-
-def cut_rotate(surface, (w, h)):
-    return [rotate(i) for i in cut_surface(surface, (w, h))]

File src/worldmap.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Thu Jun 28 20:42:21 2012 Pierre Surply
-## Last update Fri Aug 17 23:12:14 2012 Pierre Surply
+## Last update Mon Aug 27 10:09:07 2012 Pierre Surply
 ##
 
 import os
 import pygame
 from pygame.locals import *
+from OpenGL.GL import *
+from OpenGL.GLU import *
 
 import surface
 import savable
     def __init__(self, path):
         self.path = path
         self.sprite_biomes = surface.cut_surface(pygame.image.load("res/img/biomes.png").convert_alpha(), (8, 8))
-        self.sprite_biomes_maxi = surface.cut_surface(pygame.image.load("res/img/biomes_max.png").convert_alpha(), (16, 16))
-        self.cursor = pygame.image.load("res/img/biome_cursor.png").convert_alpha()
-        self.cursor_max = pygame.image.load("res/img/biome_cursor_max.png").convert_alpha()
+        self.cursor = surface.surface2texture(pygame.image.load("res/img/cursor.png").convert_alpha())
         self.init_tile()
         self.build()
 
         self.env = [[None] * self.size for i in range(self.size)]
         
         
-    def render(self, surface, (dx,dy), (sx, sy)):
+    def render(self, (w, h), (sx, sy)):
+        size_biome = min((w/2) / 34, (h/2) / 34)
+        size_large_biome = min((w/4)/9, (h/2) / 9)
+        dx = (w/2) + ((w/2) - size_biome*32)/2
+        dy = size_biome
+        dlx = dx + size_biome*16 + (size_biome*16)/9
+        dly = dy + (h/2) + (((h/2) - size_large_biome*9)/2)
         for y in range(self.size):
             for x in range(self.size):
-                surface.blit(self.sprite_biomes[self.tile[x][y]], (x*8+dx, y*8+dy))
-        surface.blit(self.cursor, (sx*8-1+dx, sy*8-1+dy))
-        if self.env[sx][sy] != None:
-            self.env[sx][sy].render_mini(surface, (dx-1, (self.size*8) + dy+2))
+                glBindTexture(GL_TEXTURE_2D, self.sprite_biomes[self.tile[x][y]])
+                glBegin(GL_QUADS)
+                
+                glTexCoord2f(0, 0); glVertex2f(x*size_biome+dx, (y+1)*size_biome+dy)
+                glTexCoord2f(0, 1); glVertex2f(x*size_biome+dx, y*size_biome+dy)
+                glTexCoord2f(1, 1); glVertex2f((x+1)*size_biome+dx, y*size_biome+dy)
+                glTexCoord2f(1, 0); glVertex2f((x+1)*size_biome+dx, (y+1)*size_biome+dy)
+                
+                glEnd()
+        glBindTexture(GL_TEXTURE_2D, self.cursor)
+        glBegin(GL_QUADS)
+        
+        glTexCoord2f(0, 0); glVertex2f(sx*size_biome+dx, (sy+1)*size_biome+dy)
+        glTexCoord2f(0, 1); glVertex2f(sx*size_biome+dx, sy*size_biome+dy)
+        glTexCoord2f(1, 1); glVertex2f((sx+1)*size_biome+dx,  sy*size_biome+dy)
+        glTexCoord2f(1, 0); glVertex2f((sx+1)*size_biome+dx, (sy+1)*size_biome+dy)
+        
+        glEnd()
+        #if self.env[sx][sy] != None:
+        #    self.env[sx][sy].render_mini(surface, (dx-1, (self.size*8) + dy+2))
         for y in range(max(0,sy - 4), min(sy + 4, self.size)):
             for x in range(max(0,sx - 4), min(sx + 4, self.size)):
-                surface.blit(self.sprite_biomes_maxi[self.tile[x][y]], \
-                                 ((x-(sx-4))*16+128+dx+1, \
-                                      (y-(sy-4))*16+256+dy+2))
-        surface.blit(self.cursor_max, (dx + 191, dy + 319))
+                glBindTexture(GL_TEXTURE_2D, self.sprite_biomes[self.tile[x][y]])
+                glBegin(GL_QUADS)
+                
+                glTexCoord2f(0, 0); glVertex2f((x-(sx-4))*size_large_biome+dlx, \
+                                                   (y-(sy-4)+1)*size_large_biome+dly)
+                glTexCoord2f(0, 1); glVertex2f((x-(sx-4))*size_large_biome+dlx, \
+                                                   (y-(sy-4))*size_large_biome+dly)
+                glTexCoord2f(1, 1); glVertex2f((x-(sx-4)+1)*size_large_biome+dlx, \
+                                                   (y-(sy-4))*size_large_biome+dly)
+                glTexCoord2f(1, 0); glVertex2f((x-(sx-4)+1)*size_large_biome+dlx, \
+                                                   (y-(sy-4)+1)*size_large_biome+dly)
+            
+                glEnd()
+        glBindTexture(GL_TEXTURE_2D, self.cursor)
+        glBegin(GL_QUADS)
+        
+        glTexCoord2f(0, 0); glVertex2f(dlx+size_large_biome*4, dly+size_large_biome*5)
+        glTexCoord2f(0, 1); glVertex2f(dlx+size_large_biome*4, dly+size_large_biome*4)
+        glTexCoord2f(1, 1); glVertex2f(dlx+size_large_biome*5, dly+size_large_biome*4)
+        glTexCoord2f(1, 0); glVertex2f(dlx+size_large_biome*5, dly+size_large_biome*5)
+        
+        glEnd()
 
     def build(self):
         self.init_tile()