Forum Fighters: Rewritten (Discontinued)

I changed the place where the characters are cloned because they were messed up from adding new layers. it is fixed now to my knowledge.

FFR 1.2.1 (niceness and notes mini update)4-21-2021_9-07-48.wick (301.5 KB)

@pumpkinhead @Hamzah_Alani @KringlePrinkles just remind me of the contributions you made, then we can put you guys in the credits. please also remind me of any contributors i missed. i’ll be the one to put in the credits so that we don’t have 2-3 files of slightly different credits.

then, i’ll change the title of this post to have a link the newest file.

@nuggetofwisdom @pumpkinhead how do you 2 think you will do the online play? is there anything we have to do in the wick project to make it work?

1 Like

All we need is @pumpkinhead and his enormous brain
networking-test.html (2.1 MB)
And after the client is set up I can edit the original server code:

Server code
//Very useful website: https://www.gabrielgambetta.com/client-server-game-architecture.html

const HTTP = require("http");
const WebSocket = require("ws");

const UPDATE_TIME = 5; // in frames per second

class Player {
  constructor(ws, id) {
    this.x = 0;
    this.y = 0;
    this.ws = ws; // WebSocket connection
    this.id = id;
    ws.player = this;
  }
}

var players = {}; //A list of all the players
//This is a dictionary. The key will be the players' unique IDs,
//and the values will be the players themselves

var requestQueue = [];
//Instead of processing each request as they're made,
//only actually process them a few times per second
//Put them in a queue for processing when it is time

//This is a utility function that sends data to all the clients
function sendToAllPlayers(dat) {
  if (typeof dat === "object") dat = JSON.stringify(dat);

  for (let pid in players) {
    players[pid].ws.send(dat);
  }
}

//This function handles information sent from a client
function handleRequest(player, req) {
  if (req === "disconnect") {
    delete players[player.id];
    
    sendToAllPlayers({ type: "player_disconnected", id: player.id });
    return;
  }

  if (req === "connection") {
    sendToAllPlayers({ type: "player_connected", id: player.id });
    return;
  }

  if (req.type === "position") {
    player.x = +req.x; //unary plus operator converts things into numbers
    player.y = +req.y;
    return;
  }
}

var lastUpdate = 0;
//This function handles all the requests in the request queue
function handleRequests() {
  //get the time since the last update
  var now = Date.now();
  var dt = (now - lastUpdate) / 1000;
  lastUpdate = now;

  //console.log("Update");

  for (let req of requestQueue) {
    //console.log(req);
    handleRequest(req[0], req[1]);
  }

  //clear request queue
  requestQueue = [];

  //send the positions of all the players to every player, if there are any
  //to check if there are any players, check if the player list has keys
  //using .length on the player list won't work because length only works on numbered arrays
  //it is not an array, so it will not work.
  if (Object.keys(players).length > 0) {
    var posData = [];
    for (let i in players) {
      let player = players[i];
      let id = player.id;
      posData.push({
        id: id,
        x: player.x,
        y: player.y,
      });
    }

    sendToAllPlayers({ type: "positions", positions: posData, dt: dt });

    //i need to give the client the server update timestep for entity interpolation
    //entity interpolation is used to make movement look smooth, despite
    //the positions only updating a few times per second. this works by
    //simulating what happened for the player between server updates
    //in the client by interpolating the player's position, which is why
    //i must send the dt to the client
  }

  setTimeout(handleRequests, 1000 / UPDATE_TIME);
  //Not using setInterval, since if it takes longer than usual to run the function,
  //the function might execute while setInterval already ran the function again
  //overlapping the two's execution :O
}

///////////////////
// Create Server //
///////////////////

/*
//I will create an HTTP server which the WebSocket server will use for connecting...
//I think only HTTP server
const https = HTTP.createServer((req, res) => {
  res.statusCode = 400;
  res.end("This is the HTTP server for the websocket. There is nothing here in terms of HTTP content.");
});

https.listen(8080, () => {
  console.log("HTTP server running at port 8080");
})*/

const wss = new WebSocket.Server({ port: 8080 });

wss.on("connection", function(ws) { //When someone connections
  //Player limit, up to 4 people 
  if (Object.keys(players).length >= 4) {
    console.log("Server full!");
    ws.close(1013, "Server is full -- max of 4 players"); //code 1013 means "Try Again Later"
    return;
  }

  console.log("New socket opened");

  //Generate random identifier ID for the player
  var id = Math.floor(Math.random() * 99999);
  var player = new Player(ws, id);
  players[id] = player;

  ws.on("message", function(msg) { //When the server receives a message from client
    var json;

    try {
      json = JSON.parse(msg);
    } catch(err) {
      console.log("Invalid json data from " + id);
      return;
    }

    requestQueue.push([player, json]);
  })

  ws.on("close", function() { //When the player disconnects
    console.log("Socket closed");
    requestQueue.push([player, "disconnect"]);
  })

  //Tell all other clients a new player joined
  requestQueue.push([player, "connection"]);

  //Send client's ID and other players' ids and position to the client
  var posData = [];

  for (let i in players) {
    let p = players[i];
    if (p.id === id) continue; //ignore own client

    posData.push({
      id: p.id,
      x: p.x,
      y: p.y
    });
  }

  var initData = {
    type: "init",
    id: id,
    players: posData
  }

  //console.log(initData);
  ws.send(JSON.stringify(initData));
});

wss.on("listening", function() {
  console.log("Websocket server listening on port 8080");

  lastUpdate = Date.now();
  handleRequests();
})
1 Like

So the left of the menu screen is a bit bland, once we get bots working could we have 2 bots fighting there?

1 Like

Also how easy would it be to implement down attack and up attack?

i guess we check if down is pressed and attack is pressed at the same time, then do a down attack. same for the up attack.

2 Likes

That should be relatively easy.
Also, I think we should implement multiplayer soon so we can test it together

@mlgcoolguys_1 Said finish story mode first than multiplayer cause with story mode done we get all the main mechanics down and its easier to add multiplayer

4 Likes

Speaking of @MrDashell we should get to work on writing

Alright, Just where do we go.

Here’s the current html url: https://forum-fighters.glitch.me/

question where do we put the game when its finished cause I wanted it to be put on Newgrounds or something any ideas?

Newgrounds, itch.io, and everybody’s website probably
And maybe it could get feature on the wick community page

Nyet, I have plans for that

1 Like

I’m thinking of itch,new grounds, and the com page. They allwork

I did a “mini-update” where I made some adjustments to the project.
I added some code to the character selecting menu as well

I also made the cursor turn to “pointer” when over buttons
(which is useful since it helps the user know if they can click on something or not)

Not much, but that’s all

FFR.wick (308.2 KB)

6 Likes

it’s subtle but very effective. i like it a lot.

oh yeah, are we gonna do, like, any gender balance? most of us are guys and i don’t want anyone thinking that we’re sexist by only putting male characters. yeah there’s toria and nina and fat_clouds but that’s still a very small ratio. we can create our own characters too, that’s always an option.

1 Like

@Watrmeln @nuggetofwisdom @mlgcoolguys_1 @MrDashell @gamer_boi @KringlePrinkles @pumpkinhead @Hamzah_Alani @BSA_15 @butt

I’m sorry for pinging basically everyone working on this project, but this is important.

I went through this whole post by filtering by username, this is what i have.

General

  • Luxapodular, zrispo, nick - wick editor
  • awc95014, Hamzah_Al_Ani, mlgcoolguys_1 - project leading

Code

  • awc95014, pumpkinhead - fighting engine
  • Jovanny, Hamzah_Al_Ani, awc95014 - placeholder characters
  • Hamzah_Al_Ani - AI ideas

Story

  • Watermeln, butt, other people i don’t remember - story ideas
  • people - final story

Interface, Designs, and Art

  • awc95014 - basic interface skeleton
  • Hamzah_Al_Ani, Watrmeln, Kringle_Prinkles - better interface
  • mlgcoolguys_1 - some kind of art
  • Nina - Toria’s character design
  • workers with characters - their own character designs
  • Fat_Clouds - miscallaneous designer

music

  • nuggetofwisdom, Kringle_Prinkles - music that is most likely to be used

gamer_boi and BSA_15, I see that you didn’t really do anything.

If I missed anything in the credits or I put you in the wrong spot, please tell me. You can tell me for other people, not just yourself. I do want proof though. Don’t just say “I did music” and leave, I want to hear the actual music you made.

5 Likes

I might come up with the backstory of a female character later

1 Like

I’m apart of making the story I think here’s my proof I guess