camera scroller ?

BlitzMax Forums/BlitzMax Programming/camera scroller ?

Twinprogrammer(Posted 2011) [#1]
Hey guys,

I am making a scrolling game, and the concept is i am making the entire map and using a camera that zooms in and scrolls. I know how to do this,but it is also multiplayer. Please explain how to do this while kepping the position of the other players. thanks !


Czar Flavius(Posted 2011) [#2]
Seperate the idea of players and clients. Each client controls a player (and ship), and there is one-to-one match, but it's good to think of them seperately.

Make your game so that it is processed without favouring any one player. Have a player type which the ship positon, lives etc. Have the player object take input from general functions such as change direction, not hardcode keyboard presses into the player object.

Now create a client type. This has a reference to that client's player type, and details such as the client's scrolling position. When detecting input, redirect this to the player within the current client rather than a hardcoded player object.

I hope this has some ideas for you.


Twinprogrammer(Posted 2011) [#3]
How do you make a client ?


Czar Flavius(Posted 2011) [#4]
Client is a type with methods to control a player object. For one client, the methods will be called by input from the keyboard, whereas the others will be called by input from over the network.

I just realised I may have misunderstood the problem. Is this same-computer multiplayer or network multiplayer?

Last edited 2011


Twinprogrammer(Posted 2011) [#5]
Network multiplayer.


Czar Flavius(Posted 2011) [#6]
Please explain more about how your game works as I don't have a clear picture.


Czar Flavius(Posted 2011) [#7]
twinprogrammer, here is a 2d scrolling tile map I helped with in ancient histories.

http://blitzbasic.com/Community/posts.php?topic=90762#1033024

Run the code in the last source code box. Press enter to begin the game. Use the arrow keys to scroll.

You can get some ideas from there.

I wonder what ever came from Fred's egg hunt..

Last edited 2011


Midimaster(Posted 2011) [#8]
Also in a 'scrolling' game the positions of the players are a part of the map and always keep relative to the 0/0-point of the map.

It is not like many programmers think, that the player is always in the center of the screen... It is more like: the camera is moved, so that the player seems to keep in the center of the screen. So also 'your' player changes his coordinates, when moving.

Each client has a individual camera, that depents on 'its players' position and shows a part of the the map. It is placed half of the screen left and up of the player.

In total there is no confusion about communication about players position. They are always exact:

Here are two screen 400x400 and a camera positioned -200/-200 from the player. You will see a 30x30 scrolling ground floor and 2 figurs.
Blue is your Player, move it with the Arrow-Key:

Graphics 900,400
Global Player1_X#=400
Global Player1_Y#=400

Global Player2_X#=500
Global Player2_Y#=500


Repeat
	
	'player 1 moves automatic 
	Player1_Y:+.3
	
	' you control he player 2
	If KeyDown(KEY_LEFT) Player2_X:-.5
	If KeyDown(KEY_RIGHT) Player2_X:+.5
	If KeyDown(KEY_UP) Player2_Y:-.5
	If KeyDown(KEY_DOWN) Player2_Y:+.5
	Cls
	
	' camera 1 for Player 1:
	CameraPicture (Player1_X-200 , Player1_Y-200, 0)
	
	
	' camera 2 for player 2:
	  	' the '500' is only necessary to simulte a 2nd monitor on one screen
	CameraPicture (Player2_X-200 , Player2_Y-200, 500)
	
	'some painting to have the feeling of two monitors:
	SetColor 111,111,111	
	DrawRect 0,0,900,30
	DrawRect 0,370,900,30
	DrawRect 0,0,30,400
	DrawRect 370,0,160,400
	DrawRect 870,0,30,400
	Flip 1
Forever



Function CameraPicture (CamX, CamY, OffX)
	SetColor 1,99,1
	
	' simulates a moving ground floor
	For j=0 To 90
		For I=0 To 90
			RealX=i*30-CamX+1
			If RealX>0 And RealX<400
				DrawRect OffX + (i*30)-CamX+1,(j*30)-CamY+1,29,29
			EndIf
		Next
	Next
	
	' the players:
	SetColor 255,0,0
	DrawOval OffX + Player1_X-CamX , Player1_Y-CamY ,15,15
	SetColor 0,0,255
	DrawOval OffX + Player2_X-CamX , Player2_Y-CamY ,15,15


End Function


Last edited 2011


Matt Merkulov(Posted 2011) [#9]
You can use DWLab framework for this. These techniques are already implemented in MindStorm demo but I'll make some explanations too:

First you should create a world in editor and dispose players on the game field (on the only layer). Set these classes to TPlayer and set the "num" parameter to corresponding player number. You can also all more sprites and tilemaps to the layer.

Then you should create some classes ing code files for you project including TGame project class and TPlayer class.

Next step will be loading and initializing level, how to do this is explained in DWLab tutorial. Then you can move the camera in code with L_CurrentCamera.JumpTo( Player ) method to the player position or to point with L_CurrentCamera.SetCoords() method. And set magnification by L_CurrentCamera.SetMagnification() method.

Then you have to synchronize network player coordinates with server. Add Level.Act() method to the TGame Logic() method to enable shape acting and add synchronization commands to TPlayer Act() method. You can retrieve player number by GetParameter( "num" ) method inside TPlayer.