3 Replies - 421 Views - Last Post: 13 January 2013 - 01:06 PM Rate Topic: -----

#1 crowtongue  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-January 13

Python Roguelike Help - Making Circular Rooms

Posted 10 January 2013 - 07:23 PM

Hi there!

I've been making games for a while with free non-programmy tools (Construct and the like) and wanted to move to programming, but NOT right into C++ since I don't have any experience and want to learn an easier language first.

Other than general reading and some books I bought, my first project was going through this Python Libtcod tutorial, coding everything by hand (no copy pasting) and resolving all the errors. I've gotten through it, and made some changes of my own and am looking to expand this project and make it my own. Here's the tutorial:

Python Libtcod Tutorial

One change I've wanted to make is to come up with circular rooms instead of square rooms that every roguelike seems to use.

This tutorial uses a list called "map" to store what tiles are what. My first thought was to use two loops, one for the left side of the circle and one for the right, and have them go through the map object at the appropriate coordinates and change the tiles to not be blocked. It would shift down each time this happened, creating a circle

I've read more threads on Stack Overflow then I can remember and a whole bunch of the Python Documentation but wasn't able to find a way to do this. There is also a python libtcod forum, which seems to be all but abandoned.

The best I've managed to come up with is a cross and 4 lines connecting each arm of the cross so I have an outline of a circle(it looks more like a diamond actually.) But I still have 4 crops of blocked tiles, and worse my methods seem cumbersome and the one to draw the outline has a gazillion variables.


Here's a few things to hopefully make this easier

Circle is a class with x1,y1,x2,y2 and r attributes.

x,y and r are randomly generated.

x1 and y1 represent the top corner (think of it like a rectangle), and x2 and y2 the bottom right corner.

R represents "radius" or how big I want the circle to be.



Code for the "cross":

if room_type == Circ:
		
	#start the circle by making a giant cross
		for x in range(room.x1, room.x2):
			map[x][room.y1+room.r].blocked = False
			map[x][room.y1+room.r].block_sight = False
		for y in range(room.y1, room.y2):
			map[room.x1+room.r][y].blocked = False
			map[room.x1][y].block_sight = False
		


Code for the outline:

	count = room.r 
		r2 =room.x1 + room.r 
		r3 = room.x2 - room.r
		r4 = room.x2 
		r5 = room.x1
		roomy1 = room.y1
		roomy2 = room.y1 +room.r
		roomy3 = room.y1
		roomy4 = room.y1 + room.r
		roomy5 = room.y1 + room.r
		roomy6 = room.y2
		roomy7 = room.y1 + room.r
		roomy8 = room.y2
		while (count > 0):
			
			for y in range(roomy1, roomy2):
				map[r2][y].blocked = False
				map[r2][y].block_sight = False
				roomy1 = roomy1-1
				roomy2 = roomy2-1
				r2 = r2 - 1
				count = count - 1
				
			
			for y in range(roomy3, roomy4):
				map[r3][y].blocked = False
				map[r3][y].block_sight = False
				r3 = r3 +1
				roomy3 = roomy3-1
				roomy4 = roomy4-1
				
			
			for y in range(roomy5, roomy6):
				map[r4][y].blocked = False
				map[r4][y].block_sight = False
				r4 = r4 -1
				roomy5 = roomy5+1
				roomy6 = roomy6+1
				
			for y in range(roomy7,roomy8):
				map[r5][y].blocked = False
				map[r5][y].blocked = False
				r5 = r5+1
				roomy7 =roomy7 + 1
				roomy8 = roomy8 +1
	


I know it's awful code, so as well as helping me with my problem, any tips or good sites to read are also much appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Python Roguelike Help - Making Circular Rooms

#2 woooee  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 78
  • Joined: 21-November 12

Re: Python Roguelike Help - Making Circular Rooms

Posted 10 January 2013 - 09:40 PM

What toolkit are you using to draw the room, or are you drawing it? Also, a cross will outline an ellipse not a circle but that is not real important.
Was This Post Helpful? 0
  • +
  • -

#3 crowtongue  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-January 13

Re: Python Roguelike Help - Making Circular Rooms

Posted 10 January 2013 - 09:51 PM

View Postwoooee, on 10 January 2013 - 09:40 PM, said:

What toolkit are you using to draw the room, or are you drawing it? Also, a cross will outline an ellipse not a circle but that is not real important.


By default the map is set to have all blocked tiles. A room just uses a class like Rectangle, or in my case, Circle, and a seperate function called create_room to make the room itself. The map is just a list and changing a part of the list changes the tile. For example:

map[25][20].blocked = True

would make a blocked tile at those map coordinates.
Was This Post Helpful? 0
  • +
  • -

#4 crowtongue  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-January 13

Re: Python Roguelike Help - Making Circular Rooms

Posted 13 January 2013 - 01:06 PM

So I'm still stumped on this. Can I provide anything that would make it easier to help me?

Anyone have any thoughts?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1