robots
This is an old revision of the document!
Table of Contents
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:
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
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)
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: 2023/09/27 00:19 by appledog