Commits

Anonymous committed 93b429d

Fixed camera centering and added zooming on user input

Comments (0)

Files changed (1)

roguelike/main.py

 				int2d(sum2d(hat_center, flipY2d(mag_scale_2d(joy.get_hat(hat), 15)))),
 				3
 			)
-on_event(lambda a: a.type == EVENT_DRAW, draw_joy_input)
+#on_event(lambda a: a.type == EVENT_DRAW, draw_joy_input)
 
 colorBG = pygame.Color(255, 220, 255)
 colorDebug0 = pygame.Color(190, 170, 170)
 
 
 #camera = (0, 0, 6, 4) # (left, top, width, height)
-camera = (0, 0, 5) # (centerX, centerY, height) ~~~ width depends on screen
+camera = (0, 0, 7) # (centerX, centerY, height) ~~~ width depends on screen
 def move_camera(delta):
 	global camera
 	camera = (camera[0] + delta[0], camera[1] + delta[1], camera[2])
+def zoom_camera(delta):
+	global camera
+	camera = (camera[0], camera[1], max(1, camera[2] + delta))
 
 blocks = [] # contains: ((x, y, z), tile)
 def draw_environment(event):
 						scale_world2screen
 					),
 					### camera registration (center)
-					scale2d(
-						(
-							#( camera[2] * surface_screen.get_height() / surface_screen.get_width()) / 2,
-							(camera[2] / 2 - .5) * surface_screen.get_width() / surface_screen.get_height(),
-							(camera[2] ) / 2 - .5
-						),
-						scale_world2screen
-					)
+					#scale2d(
+					#	(
+					#		#( camera[2] * surface_screen.get_height() / surface_screen.get_width()) / 2,
+					#		(camera[2] / 2) * surface_screen.get_width() / surface_screen.get_height(),
+					#		(camera[2] ) / 2
+					#	),
+					#	scale_world2screen
+					#)
+					
+					#scale2d(
+					#	((camera[2] - 1) * TILE_W * surface_screen.get_width() / surface_screen.get_height() / 2, (camera[2] - .5) * TILE_L / 2),
+					#	scale_world2screen
+					#)
+					
+					#(300, 200)
+					
+					(surface_screen.get_width() / 2, surface_screen.get_height() / 2)
 				)
 			)
 		)
+		
+	#pygame.draw.rect(surface_screen, colorHud, pygame.Rect(300 - 2, 200 - 2, 4, 4)) # centered guide dot
 on_event(lambda a: a.type == EVENT_DRAW, draw_environment)
 
 
 	previous_hat = event.value
 on_event(lambda a: a.type == pygame.JOYHATMOTION, on_hat)
 
-pygame.key.set_repeat() # disables key repetition
+#pygame.key.set_repeat(1, 1)
 on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_UP, lambda a: move_camera((0, -1)))
 on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_RIGHT, lambda a: move_camera((1, 0)))
 on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_DOWN, lambda a: move_camera((0, 1)))
 on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_LEFT, lambda a: move_camera((-1, 0)))
+on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_EQUALS, lambda a: zoom_camera(-1))
+on_event(lambda a: a.type == pygame.KEYDOWN and a.key == pygame.K_MINUS, lambda a: zoom_camera(1))
 
 blocks.append([(1, 1, 2), tile_gray])
 blocks.append([(1, 1, 1), tile_gray])
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.