User Tools

Site Tools


robots

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
robots [2023/09/27 00:19] appledogrobots [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-= Robots 
-Part one of this class was taught to [[Roger]] on Sep. 19th 2023. 
- 
-== PyGame Console Starter 
-We begin with the standard PyGame console starter program: 
- 
-* [[PyGame Terminal]] 
- 
-== Defining the World 
-The first step is to define the world. We start small, with baby steps. We want a map and a player which can move around. Add the following code after "self.running = True" in Class Game: __init__(self): 
- 
-=== Setting it up in Class Game 
- 
-<Code:Python|Added to Class Game __init__(self):> 
-        # create map 
-        self.gameW = 60 
-        self.gameH = 21 
-        self.gameMap = [[' ' for _ in range(self.gameW)] for _ in range(self.gameH)] 
- 
-        # add walls 
-        for x in range(self.gameW): 
-            self.gameMap[0][x] = '#' 
-            self.gameMap[self.gameH-1][x] = '#' 
- 
-        for y in range(self.gameH): 
-            self.gameMap[y][0] = '#' 
-            self.gameMap[y][self.gameW-1] = '#' 
- 
-        self.px = 3 #random.randint(1, self.gameW-2) 
-        self.py = 3 #random.randint(1, self.gameH-2) 
-</Code> 
- 
-I left code inside for a random position, but you can also just make the player start wherever you want for testing purposes. You will also have to set gameW and gameH based on your screen size and other factors. The numbers shown work well on my screen but yours may be different. 
- 
-The two for loops will draw walls at the edges of the map. 
- 
  
robots.1695773943.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki