Commits

Pierre Surply committed 11fed08

Added spherical representation of robots

  • Participants
  • Parent commits 4f018a8

Comments (0)

Files changed (5)

res/img/lvl_elts.png

Old
Old image
New
New image

res/img/robots.png

Old
Old image
New
New image
 ##    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 Sun Sep  2 16:50:51 2012 Pierre Surply
+## Last update Mon Sep  3 15:30:29 2012 Pierre Surply
 ##
 
 import os
 import random
+import math
 import pygame
 from pygame.locals import *
 from OpenGL.GL import *
 import savable
 from robot import mothership, woodcutter
 
+time_day = 64000
+
 class Env(savable.Savable):
     temp_tiles = [((255, 255, 255, 255), 0, "Grass", 0.5),\
                   ((150, 100, 0, 255), 1, "Dirt", 0.4),\
                   ((101, 101, 101, 255), 11, "Stone", 0.6)]
 
     temp_elts = [((0, 100, 0, 255), 0, "Tree", 0),\
-                 ((200, 200, 200, 255), 1, "Snow tree", 0),\
-                 ((0, 50, 0, 255), 2, "Dead tree", 0),\
-                 ((0, 150, 0, 255), 3, "Infected tree", 0),\
-                 ((150, 150, 150, 255), 4, "Stone", 1),\
-                 ((253, 253, 253, 255), 5, "Snow", 2)]
+                     ((200, 200, 200, 255), 1, "Snow tree", 0),\
+                     ((0, 50, 0, 255), 2, "Dead tree", 0),\
+                     ((0, 150, 0, 255), 3, "Infected tree", 0),\
+                     ((0, 90, 0, 255), 4, "Cut tree", 0),\
+                     ((150, 150, 150, 255), 5, "Stone", 0),\
+                     ((253, 253, 253, 255), 6, "Snow", 2),\
+                     ((255, 255, 0, 255), 7, "Light", 0)]
 
     biomes = [([(0.3, 4),\
                    (0.8,2),\
                        (0.33, 3),\
                        (0.6, 1),\
                        (1.0, 0)], \
-                       [(0.2, 4), (0.25, 2), (0.4, 0)]),\
+                       [(0.2, 5), (0.25, 2), (0.4, 0)]),\
                   ([(0.1, 2),\
                        (0.2, 1),\
                        (0.4, 11),\
                        (1.0, 6)], \
                        [(0.3, 0), \
                             (0.4, 2),\
-                            (0.5, 4)]),\
+                            (0.5, 5)]),\
                   ([(0.5, 6),\
                        (0.8, 8),\
-                       (1.0, 5)], [(0.3, 4),\
+                       (1.0, 5)], [(0.3, 5),\
                                        (0.5, 2)]),\
                   ([(0.2, 2),\
                        (0.5, 1),\
                        (0.7, 11),\
                        (1.0, 5)], \
                        [(0.5, 1), \
-                            (0.9, 5)]),\
+                            (0.9, 6)]),\
                   ([(0.2, 2),\
                        (0.21,3),\
                        (0.4,1),\
         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(), (16, 16))
-        self.sprite_robots = surface.cut_surface(pygame.image.load("res/img/robots.png").convert_alpha(), (32, 32))
+        self.sprite_robots = surface.cut_surface(pygame.image.load("res/img/robots.png").convert_alpha(), (64, 32))
         self.tps_anim_sprite = 0
         self.id_sprite_water = 0
         self.sprite_water = surface.cut_surface(pygame.image.load("res/img/water.png").convert_alpha(), (16, 16))
 
         self.list_elt = glGenLists(3)
         glNewList(self.list_elt,GL_COMPILE)
+        #glBegin(GL_QUADS)
+        #glTexCoord2d(0,0); glVertex3d(-0.5, -0.5, 0)
+        #glTexCoord2d(0,1); glVertex3d(-0.5, -0.5, 1)
+        #glTexCoord2d(1,1); glVertex3d(0.5, 0.5, 1)
+        #glTexCoord2d(1,0); glVertex3d(0.5, 0.5, 0)
+        #glEnd()
+        #glBegin(GL_QUADS)
+        #glTexCoord2d(0,0); glVertex3d(-0.5, 0.5, 0)
+        #glTexCoord2d(0,1); glVertex3d(-0.5, 0.5, 1)
+        #glTexCoord2d(1,1); glVertex3d(0.5, -0.5, 1)
+        #glTexCoord2d(1,0); glVertex3d(0.5, -0.5, 0)
+        #glEnd()
         glBegin(GL_QUADS)
-        glTexCoord2d(0,0); glVertex3d(0, 0, 0)
-        glTexCoord2d(0,1); glVertex3d(0, 0, 1.41)
-        glTexCoord2d(1,1); glVertex3d(1, 1, 1.41)
-        glTexCoord2d(1,0); glVertex3d(1, 1, 0)
-        glEnd()
-        glBegin(GL_QUADS)
-        glTexCoord2d(0,0); glVertex3d(0, 1, 0)
-        glTexCoord2d(0,1); glVertex3d(0, 1, 1.41)
-        glTexCoord2d(1,1); glVertex3d(1, 0, 1.41)
-        glTexCoord2d(1,0); glVertex3d(1, 0, 0)
+        glTexCoord2d(0,0); glVertex3d(0, 0.5, 0)
+        glTexCoord2d(0,1); glVertex3d(0, 0.5, 1)
+        glTexCoord2d(1,1); glVertex3d(0, -0.5, 1)
+        glTexCoord2d(1,0); glVertex3d(0, -0.5, 0)
         glEnd()
         glEndList()
 
         glEnd()
         glEndList()
 
-        self.list_robot = glGenLists(3)
-        glNewList(self.list_robot,GL_COMPILE)
+        self.list_select = glGenLists(3)
+        glNewList(self.list_select,GL_COMPILE)
         glBegin(GL_QUADS)
         glTexCoord2d(0,0); glVertex3d(-0.5, 0.5, 0)
         glTexCoord2d(0,1); glVertex3d(-0.5, -0.5, 0)
         glTexCoord2d(1,0); glVertex3d(0.5, 0.5, 0)
         glEnd()
         glEndList()
+
+        self.quad = gluNewQuadric()
+        gluQuadricDrawStyle(self.quad, GLU_FILL)
+        gluQuadricTexture(self.quad, GL_TRUE);
+        self.list_robot = glGenLists(3)
+        glNewList(self.list_robot,GL_COMPILE)
+        gluSphere(self.quad, 0.4, 10, 10)
+        glEndList()
         
     def init_tile(self):
         self.tile = [[0] * self.size for i in range(self.size)]
         else:
             return None
 
+    def get_daylight(self):
+        t = pygame.time.get_ticks() % time_day
+        if t < time_day / 4 or t > 3 * time_day / 4:
+            return 0
+        elif time_day / 4 <= t <= time_day / 2:
+            return 0xFF * (4 * (t-time_day/4))/time_day
+        else:
+            return 0xFF - (0xFF * (4 * (t-time_day/2))/time_day)
+
     def calculate_light(self):
         self.light = [[0] * self.size for i in range(self.size)]
         for i in self.robots:
-            self.rec_calculate_light((i.pos_x, i.pos_y), 0, 0xEE)
+            self.rec_calculate_light((i.pos_x, i.pos_y), 0, 0xB0)
         for y in range(self.size):
             for x in range(self.size):
                 if self.tile[x][y] == 6:
-                    self.rec_calculate_light((x, y), 0, 0x55)
+                    self.rec_calculate_light((x, y), 0, 0x80)
 
     def rec_calculate_light(self, (org_x, org_y), dist, intens):
         if intens > 0:
                 self.set_light((org_x, y), intens)
                 if org_x+dist < self.size:
                     self.set_light((org_x+dist, y), intens)
-            self.rec_calculate_light((org_x-1, org_y-1), dist+2, intens-0x33)
+            self.rec_calculate_light((org_x-1, org_y-1), dist+2, intens-0x44)
 
     def set_light(self, (x, y), intens):
         org = self.light[x][y]
         l = 0
         if x >= 0 and x < self.size and\
                 y >=0 and y < self.size:
-            l = self.light[x][y]
+            l = self.light[x][y] + self.get_daylight()
+            if l > 0xFF:
+                l = 0xFF
         glColor3ub(l, l, l)
 
     def set_color_corner(self, (x, y)):
             lbl = self.light[x-1][y]
         if x < self.size and y < self.size:
             lbl = self.light[x][y]
-        l = (ltl + ltr + lbl + ltr) / 4
+        l = (ltl + ltr + lbl + ltr) / 4 + self.get_daylight()
         if l > 0xFF:
             glColor3ub(0xFF, 0xFF, 0xFF)
         else:
                 glPopMatrix()
         glPopMatrix()
 
-    def render_elt(self, x, y): 
+    def render_elt(self, x, y, p_x, p_y): 
         id_elt = self.tile_elts[x][y]
         glBindTexture(GL_TEXTURE_2D, self.sprite_elts[id_elt])
         z = self.temp_tiles[self.tile[x][y]][3]
             glScalef(1, 1, 0.2)
             glCallList(self.list_elt_cube)
         else:
+            glTranslated(0.5, 0.5, 0)
+            if (p_x-x != 0):
+                if (p_x >= x):
+                    glRotated(math.atan(float(p_y-y)/float(p_x-x))*180.0/3.14, 0, 0, 1)
+                else:
+                    glRotated(math.atan(float(p_y-y)/float(p_x-x))*180.0/3.14 + 180, 0, 0, 1)
+            else:
+                glRotated(90, 0, 0, 1)
             glCallList(self.list_elt)
         glPopMatrix()
 
     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
+        z = self.temp_tiles[self.tile[r.pos_x][r.pos_y]][3] + 0.5
         glPushMatrix()
         glTranslated(r.pos_x+0.5, r.pos_y+0.5, z)
         glRotated(90*r.orient, 0, 0, 1)
         glPopMatrix()
 
     def render(self, (select_x, select_y, cam_w, cam_h), (dx, dy)):
+        p_x = -2.5
+        p_y = 8
+        p_z = 12
         glMatrixMode(GL_PROJECTION)
         glPushMatrix()
         glLoadIdentity()
         glMatrixMode(GL_MODELVIEW)
         glLoadIdentity()
 
-        gluLookAt(-2, 6, 16,\
+        gluLookAt(p_x, p_y, p_z,\
                       0, 0, 0, \
                       0, 0, 1)
         glRotated(self.angle, 0, 0, 1)
         glBindTexture(GL_TEXTURE_2D, self.cursor)
         glPushMatrix()
         glTranslated(-dx, -dy, z)
-        glCallList(self.list_robot)
+        glCallList(self.list_select)
         glPopMatrix()
         glTranslated(-select_x-0.5-dx, -select_y-0.5-dy, 0);
 
-        for y in range(max(select_y-8, 0), min(select_y+9, self.size)):
-            for x in range(max(select_x-7, 0), min(select_x+11, self.size)):
+        for y in range(max(select_y-12, 0), min(select_y+8, self.size)):
+            for x in range(max(select_x-7, 0), min(select_x+12, self.size)):
                 self.render_case(x, y)
                 if self.tile_elts[x][y] != None:
-                    self.render_elt(x, y)
+                    self.render_elt(x, y, p_x+select_x, p_y+select_y)
         glColor3ub(0xFF, 0xFF, 0xFF)
         for i in self.robots:
             x = i.pos_x

src/robot/woodcutter.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Tue Jul  3 14:38:15 2012 Pierre Surply
-## Last update Sun Aug 12 11:56:44 2012 Pierre Surply
+## Last update Mon Sep  3 14:02:18 2012 Pierre Surply
 ##
 
 import robot
 
     def cut_wood(self):
         pos = self.get_pos_forward()
-        if self.env.tile_elts[pos[0]][pos[1]] == 0:
-            self.env.tile_elts[pos[0]][pos[1]] = None
-            self.add_item(0, 8)
-            self.add_item_rnd(1, 2, 2)
+        elt = self.env.tile_elts[pos[0]][pos[1]]
+        if elt in [0, 1, 2, 3, 4]:
+            if elt == 4: 
+                self.env.tile_elts[pos[0]][pos[1]] = None
+                self.add_item(0, 2)
+            else:
+                self.env.tile_elts[pos[0]][pos[1]] = 4
+                if elt in [2, 3]:
+                    self.add_item(0, 4)
+                    self.add_item_rnd(1, 2, 3)
+                else:
+                    self.add_item(0, 8)
+                    self.add_item_rnd(1, 2, 2)
             return 1
         else:
             return 0
 ##    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 Mon Aug 27 15:23:08 2012 Pierre Surply
+## Last update Sun Sep  2 20:06:12 2012 Pierre Surply
 ##
 
 import pygame