Tweaks, changes, and bugfixes

This commit is contained in:
Layla 2020-05-04 23:09:39 -04:00
parent cc443704f8
commit c980235726
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
5 changed files with 94 additions and 10 deletions

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://assets/images/character/iron_player.png" type="Texture" id=1]
[ext_resource path="res://scripts/entities/Player.gd" type="Script" id=2]
[ext_resource path="res://scripts/entities/Camera.gd" type="Script" id=3]
[sub_resource type="RectangleShape2D" id=1]
@ -36,3 +37,4 @@ __meta__ = {
[node name="Camera" type="Camera2D" parent="."]
zoom = Vector2( 0.5, 0.5 )
script = ExtResource( 3 )

View File

@ -0,0 +1,35 @@
extends Camera2D
#-------------#
# Camera Zoom #
#-------------#
export var zoomDecelration = 4
export var zoomCapSpeed = 0.125
export var minZoom = 0.25
export var maxZoom = 0.5
var zoomChange = 0
func _ready():
zoom.x = (minZoom + maxZoom) / 2
zoom.y = (minZoom + maxZoom) / 2
func _process(delta):
CameraZoom(delta)
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed():
if event.button_index == BUTTON_WHEEL_UP:
zoomChange = -zoomCapSpeed
if event.button_index == BUTTON_WHEEL_DOWN:
zoomChange = zoomCapSpeed
func CameraZoom(delta):
if(zoomChange > 0):
zoomChange = clamp(zoomChange - zoomDecelration * delta, 0, zoomCapSpeed)
elif(zoomChange < 0):
zoomChange = clamp(zoomChange + zoomDecelration * delta, -zoomCapSpeed, 0)
zoom.x = clamp(zoom.x + zoomChange, minZoom, maxZoom)
zoom.y = clamp(zoom.y + zoomChange, minZoom, maxZoom)

View File

@ -23,6 +23,7 @@ var packetQueue = []
var error_info = ""
var world_data : String = ""
var last_move_time = null
var connection_timer : Timer
@ -111,9 +112,12 @@ func send_packet(packet : PoolByteArray, channel = 0, pck_type = GDNetMessage.RE
packetQueue.append({'channel':channel, 'packet' : packet, 'type' : pck_type})
func move_player(x,y):
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
if last_move_time == null || OS.get_ticks_msec() - last_move_time > 50:
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
send_packet(pckt, 0, GDNetMessage.SEQUENCED)
send_packet(pckt, 0, GDNetMessage.SEQUENCED)
last_move_time = OS.get_ticks_msec()
func _process(delta):
process_events()

View File

@ -32,9 +32,25 @@ void * console_logic(void *)
{
game_is_running = false;
}
else if (input_string.length() > 2 && input_string.substr(0,3) == "say")
{
if(input_string.length() > 4)
{
gameserver::BroadcastMessage("Server: " + input_string.substr(4));
}
else
{
std::cout << "Must pass a valid message!" << std::endl;
}
}
else
{
std::cout << "Invalid console command!" << std::endl;
std::cout << std::endl
<< "Invalid console command!" << std::endl
<< "Valid commands are:" << std::endl
<< "stop" << std::endl
<< "say [message]" << std::endl;
}
}
}

View File

@ -121,6 +121,37 @@ namespace gameserver
}
}
void SendPlayerMessage(ENetPeer* peer, std::string message)
{
const char* data = message.c_str();
ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(peer, 1, packet);
}
bool SendPlayerMessage(std::string username, std::string message)
{
for(int i = 0; i < MAX_PLAYERS; i++)
{
if(usernames[i] == username)
{
SendPlayerMessage(&(server->peers[i]), message);
return true;
}
}
return false;
}
void BroadcastMessage(std::string message)
{
const char* data = message.c_str();
std::cout << data << std::endl;
ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(server, 1, packet);
}
void ProcessChatMessage(ENetEvent* event)
{
int peer_id = event->peer -> incomingPeerID;
@ -131,12 +162,8 @@ namespace gameserver
std::string chat_message;
std::getline(ss, chat_message, '\n');
std::string resp = "<" + usernames[peer_id] + "> " + chat_message;
const char* data = resp.c_str();
BroadcastMessage(resp);
std::cout << data << std::endl;
ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(server, 1, packet);
}
}
@ -184,7 +211,7 @@ namespace gameserver
{
while(game_is_running)
{
usleep(50000);
usleep(50000*3);
std::string data_string = "2|"+gamemap.world_tick();
const char* data = data_string.c_str();
ENetPacket* packet = enet_packet_create(data, strlen(data), ENET_PACKET_FLAG_UNSEQUENCED);