Commits

Pierre Surply committed b4bbbd9

Added README

Comments (0)

Files changed (10)

-BASIC-RoBots
-============
+# BASIC-RoBots
+
+## What is BASIC-RoBots ?
+
+BASIC-RoBots is a real-time strategy game about programming robots to colonize a planet.
+
+## How to launch this game ?
+
+BASIC-RoBots depends on Python2, PyGame and PyOpenGL.
+
+For Debian/Ubuntu Linux:
+    $ sudo apt-get install python2.6 python-pygame python-opengl
+    $ cd /path/to/basic-robots/
+    $ make
+
+## How to control robots ?
+
+The robots can only be controlled with command line. Press [Ctrl+N], or [ENTER] key when you select a robot, to open a terminal on the selected robot.
+
+### File system
+
+Each robot has its own file system. So, feel free to create folders and files in the robots with the commands `mkdir`, `touch`, `edit`, ...
+
+### Registers
+
+#### Read-write
+
+A robot owns 4 registers of 1 byte each that can be written with the command `let` (usable in BASIC-script and in terminal) :
+
+  - `A`
+  - `B`
+  - `C`
+  - `D`
+
+#### Read only
+
+The read-only registers can only be used in expressions. It's forbidden to assign value to this registers.
+  - `O` : Overflow flag. Gets the value 1 if an arithmetic overflow has occurred in the last expression, 0 otherwise.
+  - `SH` : Shield value of the robot. Not use in this version
+  - `EN` : Energy value of the robot.
+  - `X` : first component (in Cartesian coordinates) of the position of the robot
+  - `Y` : second component (in Cartesian coordinates) of the position of the robot
+  - `K` : contains keyboard inputs
+
+### Stack
+
+A robot also owns a LIFO memory, useful for storing data temporarily. You can see the content of the stack with the command `stack`. See the BASIC commands `PUSH` and `POP` for details on usage.
+
+## BASIC Programming Language
+
+The robots can be programmed with a specific language based on [BASIC][1]. You can edit a program with the command `edit FILE`, run it with `run FILE` and debug it with `debug FILE`.
+
+### Syntax
+
+#### Input and Output
+  - `PRINT` : displays a message on the terminal
+  - `READ` : asks the user to enter the value of a register
+  - `LET` : assigns a value (which may be the result of an expression) to a register
+  - `CALL` : call an external command and assigns the return to a register
+  - `PUSH` : push the value of a register in the stack
+  - `POP` : pop the value from the top of the stack to a register
+
+#### Program flow control
+  - `IF ... THEN ... ELSE` : used to perfoms comparaisons or make decisions
+  - `WHILE ... ENDWHILE` : repeat a section of code while the specified condition is true
+  - `LABEL` : labels current line
+  - `GOTO` : jumps to a labelled line in the program
+  - `GOTOSUB` : temporarily jumps to a labelled line, returning to the following line after encountering the RETURN command
+
+#### Miscellaneous
+  - `REM` : holds a programmer's comment
+  - `INCLUDE` : includes the content of an other file to the current program
+
+### Examples
+
+
+[1]: http://en.wikipedia.org/wiki/BASIC

res/lib/keyboard

-REM BASIC-RoBots
-REM Standard Library
-REM * Pierre Surply
-
-REM keyboard
-
-GOTO end_keyboard
-
-LABEL :KeyPressed
-   IF (K & 1)      THEN b1
-   IF (K >> 1 & 1) THEN b2
-   IF (K >> 2 & 1) THEN b3
-   IF (K >> 3 & 1) THEN b4
-   IF (K >> 4 & 1) THEN b5
-   IF (K >> 5 & 1) THEN b6
-   IF (K >> 6 & 1) THEN b7
-   IF (K >> 7 & 1) THEN b8
-
-LABEL end_keyboard
      LABEL start_set_orient
         PUSH C
         LET C (OR-A) % 4
-        IF C == 1 THEN set_orient_left
+        IF C == 1 THEN set_orient_right
         IF C == 2 THEN set_orient_back
-        IF C == 3 THEN set_orient_right
+        IF C == 3 THEN set_orient_left
      LABEL end_set_orient
         POP C
    RETURN
    LABEL move_to
       GOTO start_move_to
          LABEL error_move_to
-            PRINT Cannot find path to ( $A , $B )
+            PRINT Cannot find path
       GOTO end_move_to
       LABEL start_move_to
       PUSH C
 ##    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 Mon Sep  3 18:11:22 2012 Pierre Surply
+## Last update Wed Sep  5 14:12:21 2012 Pierre Surply
 ##
 
 import pygame
 
 class Dashboard:
     commands = [("ENTER", "land at the selected place"),\
-                    (chr(24)+chr(25)+chr(26)+chr(27), "move cursor"),\
-                    ("ESC", "cancel")]
+                    (chr(24)+chr(25)+chr(26)+chr(27), "move cursor")]
     def __init__(self, worldmap, events):
         self.worldmap = worldmap
         self.terminal = terminal.Terminal(events)
         self.terminal.write("Name",1)
         self.terminal.write_line(": " + self.worldmap.path)
         self.terminal.write("  ")
-        self.terminal.write("Mothership",1)
-        self.terminal.write(": " + str(self.nbr_mothership))
+        #self.terminal.write("Mothership",1)
+        #self.terminal.write(": " + str(self.nbr_mothership))
         self.terminal.write("\n\nSelected place\n", 1)
         for i in self.worldmap.biomes:
             if i[1] == n:
 ##    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 Mon Sep  3 17:25:44 2012 Pierre Surply
+## Last update Wed Sep  5 13:51:30 2012 Pierre Surply
 ##
 
 import pygame
 
 import surface
 
+show_fps = False
+
 class Display:
     def __init__(self):
         pygame.init()
                     glPopMatrix()
 
     def flip(self):
-        self.frame += 1
-        if self.frame >= 100:
-            self.frame = 0
-            current_ticks = pygame.time.get_ticks()
-            pygame.display.set_caption("BASIC-RoBots - " + \
-                                           str(100000 / (current_ticks - self.last_ticks)) + " fps")
-            self.last_ticks = pygame.time.get_ticks()
+        if show_fps:
+            self.frame += 1
+            if self.frame >= 100:
+                self.frame = 0
+                current_ticks = pygame.time.get_ticks()
+                pygame.display.set_caption("BASIC-RoBots - " + \
+                                               str(100000 / (current_ticks - self.last_ticks)) + " fps")
+                self.last_ticks = pygame.time.get_ticks()
         pygame.display.flip()
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
 
 ##    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 Tue Sep  4 10:57:45 2012 Pierre Surply
+## Last update Wed Sep  5 13:50:20 2012 Pierre Surply
 ##
 
 import os
         while r.move_to((x, y)) == 0:
             x = random.randint(0, self.size-1)
             y = random.randint(0, self.size-1)
+        r.real_pos_x = float(x)
+        r.real_pos_y = float(y)
         self.robots.append(r)
         self.calculate_light()
 
 ##    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 Tue Sep  4 11:00:38 2012 Pierre Surply
+## Last update Tue Sep  4 11:10:51 2012 Pierre Surply
 ##
 
 import pygame
 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ##
 ## Started on  Sat Jun 30 12:05:55 2012 Pierre Surply
-## Last update Sat Aug 11 20:42:25 2012 Pierre Surply
+## Last update Wed Sep  5 14:13:17 2012 Pierre Surply
 ##
 
 import os
             self.terminal.write("   \x10  ")
             self.terminal.write_line(i)
         self.terminal.write("\n\n")
-        self.terminal.start_prompt(">")
+        self.terminal.start_prompt("?")

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 Tue Sep  4 11:04:18 2012 Pierre Surply
+## Last update Wed Sep  5 12:28:50 2012 Pierre Surply
 ##
 
 import os
 import pathfinding
 
 class Robot:
+    items = [(0, "Wood", [0, 1, 2, 3, 4])]
     def __init__(self, new, world, name, env, (x, y), events):
         self.env = env
         self.pos_x = x
                                              "",\
                                              "",\
                                              (0, []),\
+                                             {}), \
+                            "items": (self.ls_items, \
+                                             "",\
+                                             "",\
+                                             (0, []),\
                                              {})}
         self.os = robotsos.RoBotsOS(self, "saves/"+world+"/robots/"+self.name+"/fs", \
                                         self.mem, \
         th_angle = 90 * self.orient
         if (self.angle%360 != th_angle):
             if (th_angle-self.angle)%360 < 180:
-                self.angle += 10
+                self.angle += 15
             else:
-                self.angle -= 10
+                self.angle -= 15
         if self.pos_x - 0.1 > self.real_pos_x:
             self.real_pos_x += 0.1
         elif self.pos_x + 0.1 < self.real_pos_x:
 
     def radar_item(self):
         item = self.mem["A"]
-        nearest = None
-        dist = None
-        for y in range(self.env.size):
-            for x in range(self.env.size):
-                if self.env.tile_elts[x][y] == item and \
-                        (nearest == None or dist > (x-self.pos_x)**2 + (y-self.pos_y)**2):
-                    nearest = (x, y)
-                    dist = (x-self.pos_x)**2 + (y-self.pos_y)**2
-        if nearest is not None:
-            self.mem_stack.append(nearest[1])
-            self.mem_stack.append(nearest[0])
-            return 1
+        if item < len(self.items):
+            nearest = None
+            dist = None
+            for y in range(self.env.size):
+                for x in range(self.env.size):
+                    if self.env.tile_elts[(y*self.env.size)+x] in self.items[item][2] and \
+                            (nearest == None or dist > (x-self.pos_x)**2 + (y-self.pos_y)**2):
+                        nearest = (x, y)
+                        dist = (x-self.pos_x)**2 + (y-self.pos_y)**2
+            if nearest is not None:
+                self.mem_stack.append(nearest[1])
+                self.mem_stack.append(nearest[0])
+                return 1
+            else:
+                return 0
         else:
             return 0
+
+
+    def ls_items(self):
+        self.os.terminal.write("Id", 1)
+        self.os.terminal.write("  ")
+        self.os.terminal.write_line("Name", 1)
+        for i in range(len(self.items)):
+            s_id = str(i)
+            self.os.terminal.write_line(s_id + (" " * (4-len(s_id))) + self.items[i][1])
+        return 0

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 Mon Sep  3 14:02:18 2012 Pierre Surply
+## Last update Wed Sep  5 12:16:39 2012 Pierre Surply
 ##
 
 import robot
 
     def cut_wood(self):
         pos = self.get_pos_forward()
-        elt = self.env.tile_elts[pos[0]][pos[1]]
+        elt = self.env.tile_elts[(pos[1]*self.env.size)+pos[0]]
         if elt in [0, 1, 2, 3, 4]:
             if elt == 4: 
-                self.env.tile_elts[pos[0]][pos[1]] = None
+                self.env.tile_elts[(pos[1]*self.env.size)+pos[0]] = None
                 self.add_item(0, 2)
             else:
-                self.env.tile_elts[pos[0]][pos[1]] = 4
+                self.env.tile_elts[(pos[1]*self.env.size)+pos[0]] = 4
                 if elt in [2, 3]:
                     self.add_item(0, 4)
                     self.add_item_rnd(1, 2, 3)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.