Create player object
This commit is contained in:
		@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"database/sql"
 | 
						"database/sql"
 | 
				
			||||||
	"github.com/heroiclabs/nakama-common/runtime"
 | 
						"github.com/heroiclabs/nakama-common/runtime"
 | 
				
			||||||
 | 
						"github.com/josephbmanley/family/server/plugin/entities"
 | 
				
			||||||
	"github.com/josephbmanley/family/server/plugin/gamemap"
 | 
						"github.com/josephbmanley/family/server/plugin/gamemap"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -26,9 +27,8 @@ type Match struct{}
 | 
				
			|||||||
// Nakama match methods
 | 
					// Nakama match methods
 | 
				
			||||||
type MatchState struct {
 | 
					type MatchState struct {
 | 
				
			||||||
	presences map[string]runtime.Presence
 | 
						presences map[string]runtime.Presence
 | 
				
			||||||
 | 
						players   map[string]entities.PlayerEntity
 | 
				
			||||||
	inputs    map[string]string
 | 
						inputs    map[string]string
 | 
				
			||||||
	positions map[string]map[string]int
 | 
					 | 
				
			||||||
	names     map[string]string
 | 
					 | 
				
			||||||
	worldMap  *gamemap.WorldMap
 | 
						worldMap  *gamemap.WorldMap
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,8 +38,7 @@ func (m *Match) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB
 | 
				
			|||||||
	state := &MatchState{
 | 
						state := &MatchState{
 | 
				
			||||||
		presences: map[string]runtime.Presence{},
 | 
							presences: map[string]runtime.Presence{},
 | 
				
			||||||
		inputs:    map[string]string{},
 | 
							inputs:    map[string]string{},
 | 
				
			||||||
		positions: map[string]map[string]int{},
 | 
							players:   map[string]entities.PlayerEntity{},
 | 
				
			||||||
		names:     map[string]string{},
 | 
					 | 
				
			||||||
		worldMap:  gamemap.IntializeMap(),
 | 
							worldMap:  gamemap.IntializeMap(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	tickRate := 10
 | 
						tickRate := 10
 | 
				
			||||||
@ -79,13 +78,15 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
 | 
				
			|||||||
		// Add presence to map
 | 
							// Add presence to map
 | 
				
			||||||
		mState.presences[precense.GetUserId()] = precense
 | 
							mState.presences[precense.GetUserId()] = precense
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Set player spawn pos
 | 
							player := entities.PlayerEntity{
 | 
				
			||||||
		mState.positions[precense.GetUserId()] = map[string]int{"x": 16, "y": 16}
 | 
								X: 16,
 | 
				
			||||||
 | 
								Y: 16,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		mState.names[precense.GetUserId()] = "User"
 | 
							mState.players[precense.GetUserId()] = player
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get intial tile data around player
 | 
							// Get intial tile data around player
 | 
				
			||||||
		if regionData, err := mState.worldMap.GetJSONRegionAround(16, 16, maxRenderDistance); err != nil {
 | 
							if regionData, err := mState.worldMap.GetJSONRegionAround(player.X, player.Y, maxRenderDistance); err != nil {
 | 
				
			||||||
			logger.Error(err.Error())
 | 
								logger.Error(err.Error())
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										7
									
								
								server/plugin/entities/entities.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								server/plugin/entities/entities.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					package entities
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PlayerEntity is the go struct representing the player's location
 | 
				
			||||||
 | 
					type PlayerEntity struct {
 | 
				
			||||||
 | 
						X int
 | 
				
			||||||
 | 
						Y int
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user