Skip to main content

News

Topic: Gauntlet clone, with extra features, and also online. (Read 15020 times) previous topic - next topic

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: Gauntlet clone, with extra features, and also online.
Reply #15
There used to be an old multiplayer demo of Bomberman for Sphere that may or may not still be useful for learning multiplayer basics with AttachInput. Somebody here still have that?

  • Mooch
  • [*][*][*]
Re: Gauntlet clone, with extra features, and also online.
Reply #16

GlovePIE looks interesting, though the political messages about green energy and all that make me not really want to download it. :P


Lars Ulrich is a douche. Doesn't mean you shouldn't listen to Metallica :p

Quote
Actually, I thought of having 16 x 16 sprites, but actually making them 16 x 32, but only drawing the sprite as 16 x 16 pixels on the lower half of the sprite area, and having the hitbox only be in that area, and using the top half for expression bubbles, like question marks and exclamation points.

There's absolutely no need to do that! Just make your sprite normally, and have your text balloon as a separate spriteset that you show at the appropriate times with CreatePerson(). This will save you a lot of hassle as you don't have to consider every single character/animation/balloon combination.


Oh, nice.

Quote
I think the main point of confusion is that it's simply not clear at all that the sprite window at the right is part of the process of making a Spriteset.

Agreed; it's not intuitive and causes confusion for pretty much everyone the first time around. I think Radnen's editor does it better (not sure; haven't been able to check it in a while).


I still can't get it working. I'd really prefer to use it, especially so as I write my newbie guide, I can have directions for the vanilla editor and Sphere Studio.

Quote
Oh, it's just 'cause I'm such a novice programmer. If I were experienced, I'd easily be able to do anything I want (I mean, Sphere uses Javascript -- look at all the stuff people do with that). It's just, for now, I have to rely so much on built-in functionality of the IDEs I use that if there's not something there, if I have to resort to doing something on my own, I have to find a workaround.

Look, it's not just you being a novice here. I've used Sphere for a long time, and I can find plenty of faults in the API. Some things just aren't intuitive, and ultimately, they really ought to be. Then again, some of the design decisions are pretty outdated (Sphere is OLD!) and could definitely be replaced by much better solutions at this point. All that said, there's a lot I do like about Sphere's API. :)


A ground-up Sphere rewrite by Radnen, you say?

In all seriousness, you should create an exhaustive list of API features you'd like to see added/modified. If nothing else, then for something to think about. Since I'm just beginning (re-beginning, technically), the only major things that're obvious to me that I'd like to see different in the API is multiplayer support, including multiple AttachInputs (for at least four players) and being able to load multiple maps simultaneously (so when playing online with others, you don't all always have to be on the same map).

Since multiplayer gaming is so popular, I think those would be massive boons for Sphere. Though the web-based implementation Radnen (and others?) are currently working on is definitely the best starting place. I can't wait 'til that's finished.

Actually, ooh! Rad, you said it'd be at least a year, right? It should probably take me that long to get something playable churned out. That'll be a happy coincidence.

(Also, since I didn't find it until 2009/2010, I didn't know Sphere was old. How old we talking?)

Quote
But won't using a for-loop lock up the system?

Why would it? That loop finishes as soon as it's iterated through the entire players array... Only loops that have some condition that can never become false would make the engine get stuck. ;)


Before the site relaunch, when I first joined the old Sphere forum, I was trying to make Chrono Trigger-style text boxes where you could walk around while they type out the text, and I used a for-loop and it froze player input until the text finished typing.


I wouldn't use SetDefaultMapScript since it'll play each time a map is changed. I'd use:

Code: (javascript) [Select]

QueuePersonScript("player1", "code();", true);

// ...

function code() {
    SetPersonXYFloat("player1", x, y);
    SetPersonXYFloat("player2", x, y);
    SetPersonXYFloat("player3", x, y);
    SetPersonXYFloat("player4", x, y);
}


The above is just an example you'll need to set the xy's and make sure to put the QueuePersonScript after you create the person but before you call MapEngine(), and put the code() function (which you can rename to anything) somewhere else in the code file.


Woo hoo! That worked! Radnen, you rock. I'm gonna try to see what I can accomplish on my own for a few days. First of all, your demo script doesn't allow diagonal movement -- the characters can only move one, cardinal direction at a time. Secondly, it'd obviously be preferable to have an event handler for all the input rather than hard-coding it.

This is where I excel -- taking working code and tweaking it to my needs.

Thanks again ^_^


There used to be an old multiplayer demo of Bomberman for Sphere that may or may not still be useful for learning multiplayer basics with AttachInput. Somebody here still have that?


Heh, I wonder if we could do what Nintendo did with the SNES Multitap. It doesn't actually add third and fourth player code or functionality. What it does is rapidly switch what the console is interpreting as players 1 and 2 between the first two controllers plugged in, and the second two plugged in. So controller 3 is actually reporting as controller 1, and controller 4 is reporting as controller 2, just at different times than the proper controllers are.

Which is why a game has to be programmed specifically to use the Multitap, 'cause the game code has to be written to interpret player 1/2 and player 3/4 input at different times.

...

Actually, that sounds like a pretty awesome, totally-doable way to do multiplayer in Sphere. Kinda like how biplanes with machineguns had little stoppers to make sure the bullets only fired when the propellers weren't in the way, someone (not me, not good enough yet) could write code that AttachInputs to one player on millisecond 1, 5, 9, 13, etc.; to a second player on milliseconds 2, 6, 10, 14, etc.; a third player; a fourth player.

That way, everyone can use the useful, pre-programmed AttachInput and get its full functionality (triggers, NPCs).

Re: Gauntlet clone, with extra features, and also online.
Reply #17
It would probably be a lot easier to just manhandle the Map Engine and manually set Person positions, check for obstructions, and such. I used to do that sort of thing a lot, even for single player games.

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Gauntlet clone, with extra features, and also online.
Reply #18
Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)

Quote
(Also, since I didn't find it until 2009/2010, I didn't know Sphere was old. How old we talking?)

It's been around since a bit before 2000, I believe. Also the reason there's reimplementations being made right now; current Sphere with its old engine and editor has a bunch of different issues (some of which being outdated libraries that don't get updated any more).

Quote
Before the site relaunch, when I first joined the old Sphere forum, I was trying to make Chrono Trigger-style text boxes where you could walk around while they type out the text, and I used a for-loop and it froze player input until the text finished typing.

Ah, I see. It does freeze player input since it's a loop and you're not explicitly checking for any input in that loop, so that's something you'd have to implement yourself when desirable. In this case, though, the loop takes shorter than even a single frame, so...

  • Mooch
  • [*][*][*]
Re: Gauntlet clone, with extra features, and also online.
Reply #19

It would probably be a lot easier to just manhandle the Map Engine and manually set Person positions, check for obstructions, and such. I used to do that sort of thing a lot, even for single player games.


Manually setting Person positions is fine. Manually checking for obstructions? Way beyond me. Besides, what would be the point in using the Map Engine at all if not for its default collision detection?


Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)


Oh! I thought Sphere-SFML was merely a thing to make your Sphere games run in a browser, I didn't know it was totally recoding. Will games made with the old Sphere run in SFML (need a catchier name there, Rad) or TurboSphere?

Quote
(Also, since I didn't find it until 2009/2010, I didn't know Sphere was old. How old we talking?)

It's been around since a bit before 2000, I believe. Also the reason there's reimplementations being made right now; current Sphere with its old engine and editor has a bunch of different issues (some of which being outdated libraries that don't get updated any more).

Quote
Before the site relaunch, when I first joined the old Sphere forum, I was trying to make Chrono Trigger-style text boxes where you could walk around while they type out the text, and I used a for-loop and it froze player input until the text finished typing.

Ah, I see. It does freeze player input since it's a loop and you're not explicitly checking for any input in that loop, so that's something you'd have to implement yourself when desirable. In this case, though, the loop takes shorter than even a single frame, so...


I was confused, I see the difference now. Radnen used a for-loop to iterate a task that essentially happens beneath the player's awareness, I was using a for-loop to run an in-game event.

I eventually solved my CT-style text problem, when messing around in Canvas. I'll have to post the code once I get it working in Sphere. Or rather, rewrite it in Sphere.

Quick Question
Is function game() the actual game loop for a Sphere game, or would I have to make my own game loop with Javascript? I'm guessing it's not a loop, since in Radnen's sample code, the CreatePerson commands don't happen over and over again, they only happen once.
...
Or do they keep happening? Are they being called every time function game() loops?

Re: Gauntlet clone, with extra features, and also online.
Reply #20
The function game() occurs once, MapEngine() is what keeps the game running after that, if you want it to loop you'd need game() to call itself at the end.

Re: Gauntlet clone, with extra features, and also online.
Reply #21


It would probably be a lot easier to just manhandle the Map Engine and manually set Person positions, check for obstructions, and such. I used to do that sort of thing a lot, even for single player games.


Manually setting Person positions is fine. Manually checking for obstructions? Way beyond me. Besides, what would be the point in using the Map Engine at all if not for its default collision detection?


You can ask the map engine if things are/would be obstructed.




Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)


Oh! I thought Sphere-SFML was merely a thing to make your Sphere games run in a browser, I didn't know it was totally recoding. Will games made with the old Sphere run in SFML (need a catchier name there, Rad) or TurboSphere?


You need to make minor changes for your Sphere 1.x game to work in TurboSphere. Sphere's objects aren't set up in a JavaScripty way. For instance, in Sphere 1.x:
Code: [Select]

var Red = CreateColor(255, 0, 0);

In TurboSphere:
Code: [Select]

var Red = new Color(255, 0, 0);


Or more interestingly:
Code: [Select]

var Picture = LoadSurface("pic.tga");
var Surf = CreateSurface(16, 16, Red);

TurboSphere overloads constructors:
Code: [Select]

var Picture = new Surface("pic.tga");
var Surf = new Surface(16, 16, Red);


I have tried, and it is pretty easy to write scripts to adapt the TurboSphere to run Sphere 1.x code.

But I rather prefer the more constructor-y way.


Quick Question
Is function game() the actual game loop for a Sphere game, or would I have to make my own game loop with Javascript? I'm guessing it's not a loop, since in Radnen's sample code, the CreatePerson commands don't happen over and over again, they only happen once.
...
Or do they keep happening? Are they being called every time function game() loops?


I'd recommend putting a game loop inside gam(). I wouldn't recommend recursing game. You will quickly run into errors about being too deeply recursed. Plus...it would be kind of weird.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Gauntlet clone, with extra features, and also online.
Reply #22


Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)


Oh! I thought Sphere-SFML was merely a thing to make your Sphere games run in a browser, I didn't know it was totally recoding. Will games made with the old Sphere run in SFML (need a catchier name there, Rad) or TurboSphere?


You should be able to drop in any old Sphere game and it should just work. But of course, there are problems since I'm not finished yet. It seems to handle newer Sphere v1.5+ games better than the old ones (they just simply crash sometimes). :/ (I think it might be in the dataformats, I only support the latest spriteset, windowstyle, formats etc. That said the new formats are pretty much unchanged since the Sphere 1.* days. So only really old games wouldn't work).
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Gauntlet clone, with extra features, and also online.
Reply #23

The function game() occurs once, MapEngine() is what keeps the game running after that, if you want it to loop you'd need game() to call itself at the end.

Yeah, game() occurs only one, but MapEngine() isn't what keeps the game running after that. That's only the case if you actually run the map engine, but if you create any old loop yourself, that will be what keeps the game running instead. Plenty of non-map engine Sphere games do this! :)

  • Mooch
  • [*][*][*]
Re: Gauntlet clone, with extra features, and also online.
Reply #24

The function game() occurs once, MapEngine() is what keeps the game running after that, if you want it to loop you'd need game() to call itself at the end.


...?

If game() only occurs once, and MapEngine() is within game(), how does MapEngine() keep running? Is it hard-coded in the Sphere engine to keep running once called?

Also, if game() only occurs once, is it a necessary function or can I just name it anything?

(Ugh, pretty much every link in the new Sphere wiki API page is a redlink.)

Oh, and can I just use setInterval() for my loop? That's what I did when I was messing around in Canvas.




It would probably be a lot easier to just manhandle the Map Engine and manually set Person positions, check for obstructions, and such. I used to do that sort of thing a lot, even for single player games.


Manually setting Person positions is fine. Manually checking for obstructions? Way beyond me. Besides, what would be the point in using the Map Engine at all if not for its default collision detection?


You can ask the map engine if things are/would be obstructed.


Oh, I see. I thought you meant write my own collision detection code.




Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)


Oh! I thought Sphere-SFML was merely a thing to make your Sphere games run in a browser, I didn't know it was totally recoding. Will games made with the old Sphere run in SFML (need a catchier name there, Rad) or TurboSphere?


You need to make minor changes for your Sphere 1.x game to work in TurboSphere. Sphere's objects aren't set up in a JavaScripty way. For instance, in Sphere 1.x:
Code: [Select]

var Red = CreateColor(255, 0, 0);

In TurboSphere:
Code: [Select]

var Red = new Color(255, 0, 0);


Or more interestingly:
Code: [Select]

var Picture = LoadSurface("pic.tga");
var Surf = CreateSurface(16, 16, Red);

TurboSphere overloads constructors:
Code: [Select]

var Picture = new Surface("pic.tga");
var Surf = new Surface(16, 16, Red);


I have tried, and it is pretty easy to write scripts to adapt the TurboSphere to run Sphere 1.x code.

But I rather prefer the more constructor-y way.


That's not bad at all. Yeah, it sounds like a script could very easily make those conversions.


Quick Question
Is function game() the actual game loop for a Sphere game, or would I have to make my own game loop with Javascript? I'm guessing it's not a loop, since in Radnen's sample code, the CreatePerson commands don't happen over and over again, they only happen once.
...
Or do they keep happening? Are they being called every time function game() loops?


I'd recommend putting a game loop inside gam(). I wouldn't recommend recursing game. You will quickly run into errors about being too deeply recursed. Plus...it would be kind of weird.


Gotcha.




Quote
A ground-up Sphere rewrite by Radnen, you say?

He's doing that; it's called Sphere-SFML. And Flying Jester is writing TurboSphere. Both are pretty promising (and FJ's thing is cross-platform). :)


Oh! I thought Sphere-SFML was merely a thing to make your Sphere games run in a browser, I didn't know it was totally recoding. Will games made with the old Sphere run in SFML (need a catchier name there, Rad) or TurboSphere?


You should be able to drop in any old Sphere game and it should just work. But of course, there are problems since I'm not finished yet. It seems to handle newer Sphere v1.5+ games better than the old ones (they just simply crash sometimes). :/ (I think it might be in the dataformats, I only support the latest spriteset, windowstyle, formats etc. That said the new formats are pretty much unchanged since the Sphere 1.* days. So only really old games wouldn't work).


Sweet! So tell me something -- when Sphere, any ol' version of Sphere, is running, is it actually running the code of the game as Javascript, or is it converting it into something else before its run?

EDIT: Ah. Found out on my own. I tried using addEventListener and it says it's not defined. Unless I just have to use EvaluateScript, but I have no idea what *.js file addEventListener is in, or where or how to obtain it.

Yeah, 'cause I remember using EvaluateScript(math.js) last time I was using Sphere, back in late 2011, so that I could use math.floor for my dice rolling script. Okay, gotta find what js file addEventListener is in. Or Sphere's equivalent, if there is one.



The function game() occurs once, MapEngine() is what keeps the game running after that, if you want it to loop you'd need game() to call itself at the end.

Yeah, game() occurs only one, but MapEngine() isn't what keeps the game running after that. That's only the case if you actually run the map engine, but if you create any old loop yourself, that will be what keeps the game running instead. Plenty of non-map engine Sphere games do this! :)


Well, even if you are using the Map Engine, you need your own game loop, don't you? I mean, I suppose ultra-simplistic games might not need a loop, but I can't imagine say, a platformer or an RPG that doesn't have a game loop constantly running certain kinds of code.
  • Last Edit: December 06, 2013, 01:56:33 am by Mooch

Re: Gauntlet clone, with extra features, and also online.
Reply #25



The function game() occurs once, MapEngine() is what keeps the game running after that, if you want it to loop you'd need game() to call itself at the end.

Yeah, game() occurs only one, but MapEngine() isn't what keeps the game running after that. That's only the case if you actually run the map engine, but if you create any old loop yourself, that will be what keeps the game running instead. Plenty of non-map engine Sphere games do this! :)


Well, even if you are using the Map Engine, you need your own game loop, don't you? I mean, I suppose ultra-simplistic games might not need a loop, but I can't imagine say, a platformer or an RPG that doesn't have a game loop constantly running certain kinds of code.


It depends how you structure it. You can very easily just leave the map engine running the whole time your game runs.

Mostly, you absolutely need a game loop (and not a recursive game function! Don't do that!) if you don't use the map engine in your game, or choose to use it for portions but also close it from time to time and then run it again later.
  • Last Edit: December 06, 2013, 02:25:09 am by Flying Jester

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Gauntlet clone, with extra features, and also online.
Reply #26
Quote from: mooch

Ah. Found out on my own. I tried using addEventListener and it says it's not defined. Unless I just have to use EvaluateScript, but I have no idea what *.js file addEventListener is in, or where or how to obtain it.


What's addEventListener? It sounds more like Java's awt event library to me; not JavaScript.

MapEngine() is a function, so it calls some code. What it calls is something with a while(true) loop in it. That loop is what runs forever and why it doesn't quit. The Map Engine looks something like this, at it's very basic core:

Code: (javascript) [Select]

function MapEngine(file, rate) {
    ChangeMap(file);
    SetFrameRate(rate);
    while (true) {
        UpdateMapEngine();
        CallUpdateScript();
        RenderMap();
        CallRenderScript();
        FlipScreen();
    }
}


So when you call:
Code: (javascript) [Select]

function game()
{
    // ... work ...

    MapEngine("file.rmp", 60);
}


Just know it goes into another loop that runs the correct code. So in order for it to do anything while the map engine is running you will have to se the update and render scripts. Now, in a better MapEngine than I showed you (the one Sphere uses) the RenderScript will run at the framerate, and so is ideal for your drawing operations - they will also be drawn above the map and they will be drawn at the framerate desired. Update scripts on the other hand run as fast as they can, and if you were to do any drawing in them; it'll be drawn below the MapEngine.

Now you know Sphere's MapEngine. :)

Quote from: mooch

Sweet! So tell me something -- when Sphere, any ol' version of Sphere, is running, is it actually running the code of the game as Javascript, or is it converting it into something else before its run?


In the Sphere 1.* engines the code is actually interpreted by the underlying JavaScript engine, so it's just running it. Now, in my SphereSFML, the code is instead compiled to .NET code, so it's quite fast (so it's turning it into something else). TurboSphere on the other hand uses v8 JavaScript and also compiles it, but to assembly and so is faster still, plus it has many keen optimizations in place (because Google is awesome). But the differences in code execution between the two aren't much since graphics are your major bottleneck. /rant
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Gauntlet clone, with extra features, and also online.
Reply #27
addEventListener is not a part of Sphere's JS--but it is used in web JS (something of the same name exists in Java too, I think). But that's web JS, for web browsers. It's part of the DOM (the API that the layout engine exposes...but we have a Sphere, not a layout engine).

What exactly are you trying to do with it?

  • Mooch
  • [*][*][*]
Re: Gauntlet clone, with extra features, and also online.
Reply #28
Two quick questions...
1) Can I access the player's X and Y without using GetPlayerX/Y? Since it's a function, it's inconvenient to use nested deep in my code. I'd prefer to just do player.x and player.y.

If I just did "player.x = GetPlayerX(blah)" would that work?

2) Is there a controller/input object built into the Sphere API? Because one super-easy way to handle custom diagonal movement would be something like...

if DPad && 0 = 1 then player.y --;
if DPad && 1 = 1 then player.x ++;
if DPad && 2 = 1 then player.y ++;
if DPad && 4 = 1 then player.x --;

In that example, obviously, DPad would store player movement in a nibble, and I could simply and-compare it to check which bits were active, so as to move the player around accordingly.

That's what I did in my Wii U Canvas game I was messing around with awhile ago. I could post the full code if anyone wants to look at the kinda programming I'm doing and used to.

It depends how you structure it. You can very easily just leave the map engine running the whole time your game runs.

Mostly, you absolutely need a game loop (and not a recursive game function! Don't do that!) if you don't use the map engine in your game, or choose to use it for portions but also close it from time to time and then run it again later.


Not sure I understand, but then again, I don't really understand how the Map Engine works. Though I get that if you were making, say, an RPG, you could turn off the ME while the player's in battle. Though I can't see what'd be wrong with leaving it running in the background. The computers we're all using are probably plenty powerful enough that that little bit of wasted computing won't cause a noticable slowdown.


Quote from: mooch

Ah. Found out on my own. I tried using addEventListener and it says it's not defined. Unless I just have to use EvaluateScript, but I have no idea what *.js file addEventListener is in, or where or how to obtain it.


What's addEventListener? It sounds more like Java's awt event library to me; not JavaScript.


Oh, it's JavaScript...
http://www.quirksmode.org/js/events_advanced.html
http://help.dottoro.com/ljeuqqoq.php

I was introduced to it here...
http://www.lostdecadegames.com/how-to-make-a-simple-html5-canvas-game/

MapEngine() is a function, so it calls some code. What it calls is something with a while(true) loop in it. That loop is what runs forever and why it doesn't quit. The Map Engine looks something like this, at it's very basic core:

Code: (javascript) [Select]

function MapEngine(file, rate) {
    ChangeMap(file);
    SetFrameRate(rate);
    while (true) {
        UpdateMapEngine();
        CallUpdateScript();
        RenderMap();
        CallRenderScript();
        FlipScreen();
    }
}


So when you call:
Code: (javascript) [Select]

function game()
{
    // ... work ...

    MapEngine("file.rmp", 60);
}


Just know it goes into another loop that runs the correct code. So in order for it to do anything while the map engine is running you will have to se the update and render scripts. Now, in a better MapEngine than I showed you (the one Sphere uses) the RenderScript will run at the framerate, and so is ideal for your drawing operations - they will also be drawn above the map and they will be drawn at the framerate desired. Update scripts on the other hand run as fast as they can, and if you were to do any drawing in them; it'll be drawn below the MapEngine.

Now you know Sphere's MapEngine. :)


I see my problem. I'm thinking in terms of something like BASIC, where the program runs one line of code after another, from the top of the code to the bottom, and only does any looping if you tell it to jump back up in the code. I forgot you can while(true) something and have it keep going while you're doing other things.

You know what'd be really helpful? If the raw code of the API functions were available somewhere. Then one could peer inside and see precisely what's happening.

Quote from: mooch

Sweet! So tell me something -- when Sphere, any ol' version of Sphere, is running, is it actually running the code of the game as Javascript, or is it converting it into something else before its run?


In the Sphere 1.* engines the code is actually interpreted by the underlying JavaScript engine, so it's just running it. Now, in my SphereSFML, the code is instead compiled to .NET code, so it's quite fast (so it's turning it into something else). TurboSphere on the other hand uses v8 JavaScript and also compiles it, but to assembly and so is faster still, plus it has many keen optimizations in place (because Google is awesome). But the differences in code execution between the two aren't much since graphics are your major bottleneck. /rant


Okay, so since Sphere 1x is interpreting, it'll basically run any Javascript I give it the way a webpage would. In SphereSFML (which I'm mentally pronouncing "surf mail"), since it's compiled, will there be some JS stuff that doesn't work?


addEventListener is not a part of Sphere's JS--but it is used in web JS (something of the same name exists in Java too, I think). But that's web JS, for web browsers. It's part of the DOM (the API that the layout engine exposes...but we have a Sphere, not a layout engine).


Phooey! So I'm gonna have to find out how to do what I want to do and pretty much already know how to do, in Sphere's API. That's always a big slowdown for me -- knowing how to do something in one language or implementation of a language, but not another.

What exactly are you trying to do with it?


Have a proper event handler to deal with multiple player input so that I can have diagonal movement. If you try Radnen's sample code he gave me, it only lets players move in one direction at a time. But I've done stuff in Canvas that allows diagonal movement. Something like this...

Code: [Select]
var keysDown = {};

addEventListener("keydown", function (e) {
keysDown[e.keyCode] = true;
}, false);

addEventListener("keyup", function (e) {
delete keysDown[e.keyCode];
}, false);

var update = function (modifier) {
if (38 in keysDown) { // Player holding up
hero.y -= hero.speed * modifier;
}
if (40 in keysDown) { // Player holding down
hero.y += hero.speed * modifier;
}
if (37 in keysDown) { // Player holding left
hero.x -= hero.speed * modifier;
}
if (39 in keysDown) { // Player holding right
hero.x += hero.speed * modifier;
}


That's from the Canvas Tutorial I linked to above. That's ripped raw just for an example, that code won't work on its own, obviously. I have my tweaked code somewhere on another harddrive, I'm just too lazy to look it up. You can take a gander at the link to see how it works in the tutorial game.

Re: Gauntlet clone, with extra features, and also online.
Reply #29

Two quick questions...
1) Can I access the player's X and Y without using GetPlayerX/Y? Since it's a function, it's inconvenient to use nested deep in my code. I'd prefer to just do player.x and player.y.

If I just did "player.x = GetPlayerX(blah)" would that work?




No, sadly you can't. That will just get you the value returned by GetPlayerX(blah) at the time you set player.x. You could wrap it inside a player.getX() function or similar, though.


It depends how you structure it. You can very easily just leave the map engine running the whole time your game runs.

Mostly, you absolutely need a game loop (and not a recursive game function! Don't do that!) if you don't use the map engine in your game, or choose to use it for portions but also close it from time to time and then run it again later.


Not sure I understand, but then again, I don't really understand how the Map Engine works. Though I get that if you were making, say, an RPG, you could turn off the ME while the player's in battle. Though I can't see what'd be wrong with leaving it running in the background. The computers we're all using are probably plenty powerful enough that that little bit of wasted computing won't cause a noticable slowdown.



There's nothing wrong with leaving it running.
I was mostly thinking of games that don't use the map engine. Then I imagined a game that used the map engine for small portions of the gameplay, and wanted to ammend that case since it is possible. It's not important.

About input handling, you can check if keys are pressed using IsKeyPressed in the update script. Or you could use AreKeysLeft and GetKey (this has some advantages) in the update script.
But either way, I would put key checking code in the update script.

===Edit===


I see my problem. I'm thinking in terms of something like BASIC, where the program runs one line of code after another, from the top of the code to the bottom, and only does any looping if you tell it to jump back up in the code. I forgot you can while(true) something and have it keep going while you're doing other things.


while(true) does not keep going while you do other things. It is an infinite loop, meaning that when execution gets to the bottom of the block, it goes right back to the top.
  • Last Edit: December 07, 2013, 07:17:18 am by Flying Jester