robots
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| robots [2023/09/27 00:19] – appledog | robots [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 " | ||
| - | |||
| - | === Setting it up in Class Game | ||
| - | |||
| - | < | ||
| - | # 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 # | ||
| - | self.py = 3 # | ||
| - | </ | ||
| - | |||
| - | 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
