Fix bullets offsets
Add keyboard offset
This commit is contained in:
parent
0a42b24f09
commit
b3c789303b
2
main.go
2
main.go
@ -60,6 +60,7 @@ type Config struct {
|
|||||||
DoJoyStickPlayers bool `json:"do_joystick_players"`
|
DoJoyStickPlayers bool `json:"do_joystick_players"`
|
||||||
DoKeymapPlayer bool `json:"do_keymap_player"`
|
DoKeymapPlayer bool `json:"do_keymap_player"`
|
||||||
RecentlyDugBlocksClearInterval uint16 `json:"recently_dug_blocks_clear_interval"`
|
RecentlyDugBlocksClearInterval uint16 `json:"recently_dug_blocks_clear_interval"`
|
||||||
|
KeyBindOffset uint16 `json:"key_bind_offset"`
|
||||||
ServerConfig ServerConfig `json:"server_config"`
|
ServerConfig ServerConfig `json:"server_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +82,7 @@ func loadOrCreateConfig(filename string) (*Config, error) {
|
|||||||
DoJoyStickPlayers: true,
|
DoJoyStickPlayers: true,
|
||||||
DoKeymapPlayer: true,
|
DoKeymapPlayer: true,
|
||||||
RecentlyDugBlocksClearInterval: 20,
|
RecentlyDugBlocksClearInterval: 20,
|
||||||
|
KeyBindOffset: 0,
|
||||||
ServerConfig: ServerConfig{
|
ServerConfig: ServerConfig{
|
||||||
MapWidth: 1000,
|
MapWidth: 1000,
|
||||||
MapHeight: 1000,
|
MapHeight: 1000,
|
||||||
|
55
player.go
55
player.go
@ -290,6 +290,11 @@ func (player *Player) getRGBAColor(colorIndex uint8, format *sdl.PixelFormat) ui
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Point struct {
|
||||||
|
X int32
|
||||||
|
Y int32
|
||||||
|
}
|
||||||
|
|
||||||
func (player *Player) shoot(super bool, bullets map[uint32]*Bullet) {
|
func (player *Player) shoot(super bool, bullets map[uint32]*Bullet) {
|
||||||
if (super && (player.energy <= serverConfig.SuperShotCost || player.ammunition < serverConfig.MaxAmmunition)) || (!super && (player.energy <= serverConfig.NormalShotCost || player.ammunition < 1)) {
|
if (super && (player.energy <= serverConfig.SuperShotCost || player.ammunition < serverConfig.MaxAmmunition)) || (!super && (player.energy <= serverConfig.NormalShotCost || player.ammunition < 1)) {
|
||||||
return
|
return
|
||||||
@ -297,41 +302,21 @@ func (player *Player) shoot(super bool, bullets map[uint32]*Bullet) {
|
|||||||
if player.shootCooldown == 0 {
|
if player.shootCooldown == 0 {
|
||||||
var shootX, shootY int32
|
var shootX, shootY int32
|
||||||
|
|
||||||
switch player.gameObject.orientation {
|
offsets := []Point{
|
||||||
case 0: // Up
|
{X: 2, Y: 0}, // 0: Up
|
||||||
shootY = player.gameObject.baseRect.Y - 1
|
{X: 6, Y: 2}, // 1: Right
|
||||||
shootX = player.gameObject.baseRect.X + 2
|
{X: 2, Y: 6}, // 2: Down
|
||||||
break
|
{X: 0, Y: 2}, // 3: Left
|
||||||
case 1: // Right
|
{X: 6, Y: 0}, // 4: Up-Right
|
||||||
shootY = player.gameObject.baseRect.Y + 3
|
{X: 0, Y: 0}, // 5: Up-Left
|
||||||
shootX = player.gameObject.baseRect.X + 8
|
{X: 5, Y: 5}, // 6: Down-Right
|
||||||
break
|
{X: 0, Y: 6}, // 7: Down-Left
|
||||||
case 2: // Down
|
|
||||||
shootX = player.gameObject.baseRect.X + 2
|
|
||||||
shootY = player.gameObject.baseRect.Y + 8
|
|
||||||
break
|
|
||||||
case 3: // Left
|
|
||||||
shootY = player.gameObject.baseRect.Y + 3
|
|
||||||
shootX = player.gameObject.baseRect.X - 2
|
|
||||||
break
|
|
||||||
case 4: // Up-Right
|
|
||||||
shootY = player.gameObject.baseRect.Y
|
|
||||||
shootX = player.gameObject.baseRect.X + 5
|
|
||||||
break
|
|
||||||
case 5: // Up-Left
|
|
||||||
shootY = player.gameObject.baseRect.Y
|
|
||||||
shootX = player.gameObject.baseRect.X - 1
|
|
||||||
break
|
|
||||||
case 6: // Down-Right
|
|
||||||
shootY = player.gameObject.baseRect.Y + 5
|
|
||||||
shootX = player.gameObject.baseRect.X + 5
|
|
||||||
break
|
|
||||||
case 7: // Down-Left
|
|
||||||
shootY = player.gameObject.baseRect.Y + 5
|
|
||||||
shootX = player.gameObject.baseRect.X - 1
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Access the offset based on the player's orientation
|
||||||
|
shootX = player.gameObject.baseRect.X + offsets[player.gameObject.orientation].X
|
||||||
|
shootY = player.gameObject.baseRect.Y + offsets[player.gameObject.orientation].Y
|
||||||
|
|
||||||
player.shootCooldown = serverConfig.ShootCooldown
|
player.shootCooldown = serverConfig.ShootCooldown
|
||||||
// Set cooldown and decrease energy
|
// Set cooldown and decrease energy
|
||||||
if super {
|
if super {
|
||||||
@ -446,7 +431,7 @@ func createPlayers(amount uint8, playerColors []PlayerColors, keyMaps []KeyMap,
|
|||||||
var joyStick *sdl.Joystick
|
var joyStick *sdl.Joystick
|
||||||
|
|
||||||
if (config.DoAllKeymapsPlayers && i <= uint8(len(keyMaps))) || (config.DoKeymapPlayer && i == 0) || (uint8(joyStickCount) <= i) {
|
if (config.DoAllKeymapsPlayers && i <= uint8(len(keyMaps))) || (config.DoKeymapPlayer && i == 0) || (uint8(joyStickCount) <= i) {
|
||||||
keyMap = keyMaps[addedKeyboardPlayers]
|
keyMap = keyMaps[(addedKeyboardPlayers+int(config.KeyBindOffset))%(len(keyMaps)-1)]
|
||||||
addedKeyboardPlayers++
|
addedKeyboardPlayers++
|
||||||
} else {
|
} else {
|
||||||
joyStickIndex := i - uint8(addedKeyboardPlayers)
|
joyStickIndex := i - uint8(addedKeyboardPlayers)
|
||||||
@ -1416,7 +1401,7 @@ func handleConnectionClient(conn *net.TCPConn, players map[uint32]*Player, bases
|
|||||||
}
|
}
|
||||||
gameMap.createGameMap(false)
|
gameMap.createGameMap(false)
|
||||||
lastPlayerID = serverInfo.PlayerID
|
lastPlayerID = serverInfo.PlayerID
|
||||||
createPlayer(true, playerColors[serverInfo.PlayerColorID], conn, keyMaps[0], JoyMap{}, nil, gameMap, players, bases)
|
createPlayer(true, playerColors[serverInfo.PlayerColorID], conn, keyMaps[config.KeyBindOffset], JoyMap{}, nil, gameMap, players, bases)
|
||||||
playersMutex.RLock()
|
playersMutex.RLock()
|
||||||
player = players[serverInfo.PlayerID]
|
player = players[serverInfo.PlayerID]
|
||||||
playersMutex.RUnlock()
|
playersMutex.RUnlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user