Making a real-time multiplayer minigame - html

I have a very simple concept of minigame that I want to be playable by up to four players at once. It will be played on an HTML5 canvas, and I already have it working in single-player with three CPU-controlled "players".
The game itself is simple, it just relies on timing and pushing your button as the arrow points towards it. In theory I could just have the game focus on the user's own button, and then just show how everyone did at the end, but what I'd really like to do is for the arrow to move faster the better people are doing - this will essentially allow the difficulty of the game to adjust itself.
So I'm thinking I need to use WebSockets. Only trouble is, I've never used them before and I can't find a single resource that isn't insanely confusing.
By my understanding, I just need the client to send a message to the server when the player pushes their button, and on receipt of that message the server can compute how accurate the player was, and adjust the speed accordingly, passing on that result to the other players.
I'm just worried about what effect lag could have on this setup. What if the arrow reaches the next player before their browser has received the message from the server informing them of how the last player did (and therefore what speed the arrow is going at)?
Am I just being too ambitious with this? Should I just stick with the idea of having four individual games whose total scores are tallied together?

Related

Interpolation with consistent speed

I'm making an multiplayer game and I bumped into a problem, I want to interpolate player position so it would not look jittery when player is having bigger ping/latency, I'm using vector2 interpolation but every single of the interpolation formula is decreasing/increasing speed in the middle/beginning/middle and I need so that interpolation speed would always be the same (so it would look like player is moving not floating)
The thing you want is the dead reckoning alghoritm which is unfortunately not supported by Libgdx by default. There are many ways to implement this basing on what kind of game you are creating.
There is no one good answer for your question but let say you are making a simple runner where players are going forward and they can jump. The naive implementation for multiplayer like this would be to change opponent's position due to notification he is sending. Now you are interpolating the position between notifications however you should rather assume that the opponent is still runing and when get notification that he jumps then correct position and perform jump an so on...
There are dozens of articles about dead reckoning in the internet. You can start with this one.

ConcurrentModificationException in a Java game

I am at the early stages of developing a 2d shooter game (Picture Metal Slug) using JAVA. I want to be able to shoot many bullets at the time. In order to do so i use a Set to control the current bullets on the screen, each time you click you spam a bullet, adding it to the screen and to the set of bullets (so in each frame, you move each bullet in the set according to their speed).
My problem is that if I click fast enough I get an
ConcurrentModificationException
Is there a data structure able to add and remove fast enough different objects without getting such exception? I can not find any that suit me.
Thanks in advance
The data structure able to suit your requirements is a ConcurrentHashMap, check:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html

Video, that lets user control the camera angle

The scenario: A guy walks along a route, through the crowd at a pool party.
The camera setup, is a customised rig with an array of GoPro's covering 360 degrees of rotation.
The end result needs to be a video that'll let the user
click & drag the video to change his viewpoint on the video. So for eg, he can turn the angle to behind him, and will see where the guy has walked from. Or he can look sideways as he walks. (Likely some up/down movement too)
pause playback
zoom in/out
So for eg, you spot a hot girl in the crowd. You'd pause, zoom in and then play the video watching her as the guy walks past her.
How could this be achieved with HTML5 (non-Flash) methods?
I don't even know what technologies would be required to achieve something like this, so I'm hoping that someone with a bit of experience in something similar could give me some pointers as to required
coding languages
server technologies
bandwidth considerations
etc
Thanks for your help!
(ps: this is a paid client job. so if you can do exactly this, lets talk about a quote?)
You'd be attempting something quite state-of-the-art.
The way I'd experiment with is to stream a video to the client and display it using WebGL, which the client can then manipulate without latency.
http://riaconnection.wordpress.com/2011/11/03/testing-live-video-streaming-to-webgl-and-html5-video-tag/
One way might be to stream 6 feeds - top, bottom, left, right, back front. These would be pre-processed so when displayed as a cube viewed from the center of the cube, the perspectives are corrected.
If the client can zoom in and out, then that means you'll need higher resolution stream. Six of them would mean very large bandwidth. You'll have to decide on a trade-off between bandwidth, quality and latency. If the client zooms in and changes pan / tilt, you could trade off latency and get better quality and bandwidth, but at the cost of higher server resource requirements.
There are plenty of video processing libraries for PHP, which would probably be my choice of server, but I'm biased.

In AS3, how can I dynamically load and unload sequential SWF animations to the stage seamlessly?

I am working on a project that will have the user seeming to fly in 3D from point to point in an architectural model, based on choices. It is a tree-flow, with everything starting from one point and branching out from there, and it only needs to animate in one direction, which makes things easier.
The thing is that the animations from place to place are C4D animations rendered as PNG sequences, and in total they will be VERY large, so I want to package each segment as an individual SWF and load and unload them dynamically as needed.
I expect the first thing to do will be to see if I can have my upstream guy render them as JPG sequences instead... is that a good idea performance-wise? I imagine it will be in terms of bandwidth.
The main question, however, is how I can dynamically load one of these sequences, have it play and stop on its final frame (over which data and choices will display), and then - based on the user's selection - load and play the next animation seamlessly from the first, without endlessly stacking up loaded clips. When the user goes back a level, I only need to jump to the first frame of the animation, but going forward always involves a smooth flight.
I suspect the solution may have to do with adding, say, to the loader by specific names, then as we transition out, load the next one with a specific name, and then unloadChild() and do whatever other kind of garbage collection I need to do to purge from memory entirely. I want to be as cognizant of memory usage and performance as I can, because at certain spots there will be other images and videos loaded on top of the flight animations.
Does anyone have any ideas about this? I'm sure it's a common need, I've just never done it before, and I want to do this as timeline-free as possible.
Thanks in advance for any advice!
Mattynabib

How do video games get on my screen?

When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame? this strikes me as a bit of a slow way to go about such a thing though.
EDIT: as a follow up question:
How does the computer doing the rendering define the frame both for rendering graphis and for doing in game activites like having a character walk across a room slowly. Like is there some clock t that keeps increasing and every render and every movment hapens as a function of t? If so how is t defined relative to the system that it runs on?
I intend this question to be somewhat synonomous to: When my cursor in the screen right now blinks twice every second how does it know what a second is? Also in java how would i make a program that displays a line of text then waits a second and desplays another line? (perahps this is getting too spacific)
They have a loop. Inside this loop it's called a method for rendering graphics and another for processing logic (and getting input). So this method will calculate everything based on the input and the graphics method print on screen based on the data already computed -- like what should be printed and its position.
Is that what you asked?
Questions about game development should be made here: https://gamedev.stackexchange.com/ :)
When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame?
Depends on the game. 2D games may be able to keep part of scenes rendered in previous frames, especially old games without scrolling screens. 3D game most likely redraws entire screen. Also good game never renders everything - only visible objects. Because rendering everything is slow, while rendering only visible objects is significantly faster.
this strikes me as a bit of a slow way to go about such a thing though.
You are free to try to find different way. Normal game repaints every visible object. Non-hardware-accelerated game may track unmodified screen regions, and repaint only objects that changed, moved, etc. Hardware accelerated game doesn't have to do that - it can redraw everything on screen every frame. As game/frame/scene complexity increases, it is much easier to simply repaint every visible object during every frame instead of tracking things that changed from previous frame.
That's basically it. The 'video game' is effectively a big state machine where all state is updated according to a frame rate. User input combined with game rules and enemy AI affect the state of the game. Once every frame the players view of the game, not the complete view of the game, is rendered.
Download the quake source, it makes for some interesting reading in the comments and also gives excellent insight as to how a game is constructed.