Game Maker's Garage Forum

Game Creation => Other Languages & Tools => Topic started by: Silverwind on August 01, 2009, 05:04:11 PM

Title: JavaScript
Post by: Silverwind on August 01, 2009, 05:04:11 PM
I suppose after studying Java for 3 months this is moving down, but I can't for the life of me comprehend anything Java related. *snarls at Sun Microsystems* JavaScript on the other hand looks delightfully simple, and after making the click that cookies are variables I don't see any reason why I can't make simple games with JavaScript and HTML.

So, anyone else ever tried game making with JC?
Title: Re: JavaScript
Post by: WarHampster on August 01, 2009, 06:00:42 PM
I wouldn't use a scripting language to do an entire game, but I don't really know anything about JavaScript.

EDIT - Also, I don't know why Java seems so difficult to you... if you have questions or need some good resources just ask.
Title: Re: JavaScript
Post by: Silverwind on August 02, 2009, 03:31:22 AM
Quote
I wouldn't use a scripting language to do an entire game, but I don't really know anything about JavaScript.
Any reason in particular? (just out of curiosity) Do you mean because of actual limitations with JC or because anyone could read the source?

Quote
EDIT - Also, I don't know why Java seems so difficult to you... if you have questions or need some good resources just ask.
Well, for example, after reading Beginning Programming with Java For Dummies 2nd Edition (http://www.dummies.com/store/product/Beginning-Programming-with-Java-For-Dummies-2nd-Edition.productCd-0764588745,navId-322467.html), which is over 390 pages, I still haven't learned how to use a single interface element or graphical component. Further more, I have no visual conception of how objects are made from classes. I know what to type to make an instance of a class, but I don't really see the object.

I suppose allot of my troubles result from not being able to ask a book questions. I'd be overjoyed if you could explain to me how to make a simple GUI app, even something as simple as a text field and a button to print stuff into it.
Title: Re: JavaScript
Post by: Silverwind on August 02, 2009, 08:49:30 AM
WOW! JavaScript is awesome beyond anything I've ever seen! The syntax is the nearest thing to GM and SC that I've ever seen, and it does everything! Here, don't waste time reading the rest of my post, go here: http://www.w3schools.com/js/default.asp

I can't believe how easily and quickly I'm learning, and even more amazing is how you can test your code online instantly. I'm nearly on the advanced tutorials already and I've gone through all of the HTML ones just to refresh my memory. Once I figure out how to manipulate graphics I'll be able to make online games!

Rejoice, for the collapse of civiliza- er, I mean... the finding of this wonderful language!
Title: Re: JavaScript
Post by: Gan on August 02, 2009, 09:09:53 AM
Quote
Well, for example, after reading Beginning Programming with Java For Dummies 2nd Edition, which is over 390 pages, I still haven't learned how to use a single interface element or graphical component. Further more, I have no visual conception of how objects are made from classes. I know what to type to make an instance of a class, but I don't really see the object.
 
I suppose allot of my troubles result from not being able to ask a book questions. I'd be overjoyed if you could explain to me how to make a simple GUI app, even something as simple as a text field and a button to print stuff into it.
Oh my... Java isn't nearly that hard. If you had iChat, AIM, MSN, or Yahoo; I could teach you a bit. Simplest thing to do is graphics.

Quote
I can't believe how easily and quickly I'm learning, and even more amazing is how you can test your code online instantly. I'm nearly on the advanced tutorials already and I've gone through all of the HTML ones just to refresh my memory. Once I figure out how to manipulate graphics I'll be able to make online games!
 
Rejoice, for the collapse of civiliza- er, I mean... the finding of this wonderful language!
:) Glad you like it. I've played a few JS games and they don't seem that bad, maybe a bit not as powerful but still pretty good. I've even talked to a guy who created a online chat room in the chat room he built all using JS.


-Gandolf
Title: Re: JavaScript
Post by: Silverwind on August 02, 2009, 12:51:16 PM
Quote
I've played a few JS games and they don't seem that bad, maybe a bit not as powerful but still pretty good.
I haven't played any that were particularly impressive looking, (and not a single RPG) but I guess that's because most developers don't like the idea of someone else being able to copy their code and host the game on their own site. I'm not too thrilled at the thought either as I despise copyright infringement with a vengeance, but JavaScript's simplicity and surprisingly vast list of features have drawn me into its lair. And now... well, now it sets to consume me, at first offering warmth, comfort and cross platform compatibilities... but all the time it waits... waits... and just when I've been lulled into a false sense of security, it STRIKES, biting my head clean off!

Or... something like that. Anyways, it's a pretty cool language. :)
Title: Re: JavaScript
Post by: WarHampster on August 02, 2009, 02:05:11 PM
Quote
Any reason in particular? (just out of curiosity) Do you mean because of actual limitations with JC or because anyone could read the source?

Mostly because anyone could read the source, but also because scripting languages are really designed to interface with code written in other languages, not to act alone.

EDIT -

Quote
I'd be overjoyed if you could explain to me how to make a simple GUI app, even something as simple as a text field and a button to print stuff into it.


I think Gandolf wrote a tutorial on how to do something like that... check the code exchange section.
Title: Re: JavaScript
Post by: Silverwind on August 02, 2009, 03:28:45 PM
Quote
Mostly because anyone could read the source, but also because scripting languages are really designed to interface with code written in other languages, not to act alone.
Ah. I'm using Dreamweaver to design the interface, and JC code can be inserted straight into interface elements. :D
 
Quote
I think Gandolf wrote a tutorial on how to do something like that... check the code exchange section.
Yeah, he PM'd it to me. It looks cool. :)

EDIT:

Progress goes delightfully well. I've got sprites moving in the browser and I've almost got V6 working. I'll post the code soon so you can see it.
Title: Re: JavaScript
Post by: Silverwind on August 05, 2009, 07:11:42 AM
Here's a Jing Cast of what I've got so far:
http://screencast.com/t/eu92aBUMAPS

Here's the code for it:
Code: [Select]
<html>
<head>
<title>Image Manipulation Test</title>
<style type = "text/css">
#Obj_roomSprite {
visibility:visible;
position:absolute;
left:5;
top:5;
z-index:1;
}
#Obj_enemySprite {
visibility:visible;
position:absolute;
left:489;
top:489;
z-index:2;
}
#Obj_playerSprite {
visibility:visible;
position:absolute;
left:181;
top:181;
z-index:3;
}
</style>
<script type = "text/javascript">
// Set grid vars.
gridMap$ = new Array (14);
gridMap$  [1] = " 11111111111111";
gridMap$  [2] = " 11110011110011";
gridMap$  [3] = " 11000001000001";
gridMap$  [4] = " 10000020000001";
gridMap$  [5] = " 10000000000101";
gridMap$  [6] = " 11111100000000";
gridMap$  [7] = " 11000000010001";
gridMap$  [8] = " 10100111111001";
gridMap$  [9] = " 10000001001111";
gridMap$ [10] = " 10010000001001";
gridMap$ [11] = " 11000100100101";
gridMap$ [12] = " 10010010000001";
gridMap$ [13] = " 11001000010011";
gridMap$ [14] = " 11111111111111";
var gridSize = 14

// Set player vars.
var playerSpriteX;
var playerSpriteY;
//var playerNewSpriteX
//var playerNewSpriteY
var playerGridX = 14;
var playerGridY = 6;
//var playerNewGridX;
//var playerNewGridX;

var enemySpriteX = 93;
var enemySpriteY = 93;

// Determine the player's sprite coordinates based on its grid coordinates.
playerSpriteX = playerGridX * 44
playerSpriteX = playerSpriteX - 39
playerSpriteY = playerGridY * 44
playerSpriteY = playerSpriteY - 39


function handleKeydown (ev) {
// Work out which keyboard key was typed and store it in the "key" variable.
df = document.forms [0];
key = ( (ev.which) || (ev.keyCode) );
// Reset the newTile$ related vars.
playerNewGridX = playerGridX;
playerNewGridY = playerGridY;

// Check which direction the player is trying to move in.
switch (key) {
case 38: // Up Arrow was pressed.
playerNewGridY = playerGridY - 1;
break;
case 40: // Down Arrow was pressed.
playerNewGridY = playerGridY + 1;
break;
case 37: // Left Arrow was pressed.
playerNewGridX = playerGridX - 1;
break;
case 39: // Right Arrow was pressed.
playerNewGridX = playerGridX + 1;
break;
}

// Check what kind of tile the player is trying to move onto.
gridMapRowX$ = gridMap$ [playerNewGridY];
playerTile$ = gridMapRowX$.charAt (playerNewGridX);
if (playerTile$ == "0") {playerTile$ = "Empty"}
if (playerTile$ == "1") {playerTile$ = "Wall"}
if (playerTile$ == "2") {playerTile$ = "Signpost"}

// Check if the player is walking off the grid.
if (playerNewGridX < 1) {playerTile$ = "Wall"}
if (playerNewGridX > gridSize) {playerTile$ = "Wall"}
if (playerNewGridY < 1) {playerTile$ = "Wall"}
if (playerNewGridY > gridSize) {playerTile$ = "Wall"}

// If the new tile is traversable, move the player onto it.
if (playerTile$ == "Signpost") {
alert ("Signpost: Silver was 'ere!")
}
if (playerTile$ == "Empty") {
playerGridX = playerNewGridX;
playerGridY = playerNewGridY;
}
if (playerTile$ == "Wall") {
playerNewGridX = playerGridX;
playerNewGridY = playerGridY;
}

// Determine the player's sprite coordinates based on its grid coordinates.
playerSpriteY = playerGridY * 44;
playerSpriteY = playerSpriteY - 39;
playerSpriteX = playerGridX * 44;
playerSpriteX = playerSpriteX - 39;
// Reposition the player sprite.

if (key >= 37 && key <= 40) {
element = document.getElementById ("Obj_playerSprite");
element.style.left = playerSpriteX;
element.style.top = playerSpriteY;
}
}
</script>
</head>
<body onkeydown = "handleKeydown (event)" >

    <span id = "Obj_roomSprite"> <img src = "http://209.85.48.12/11610/159/upload/p4557688.gif" /> </span>
    <span id = "Obj_enemySprite"> <img src = "http://209.85.48.12/11610/159/upload/p4557408.gif" /> </span>
    <span id = "Obj_playerSprite"> <img src = "http://209.85.48.12/11610/159/upload/p4557156.gif" /> </span>
    
</body>
</html>

If anyone's got the hankering to get cranking on an online game, learn with me! I'll gladly explain anything I've learnt so far and I assure you that JavaScript is not hard, the language just looks a little confusing at first if (like me) you're only used to GM or SC syntax.

Check out W3S for some brilliant tutorials on both HTML and JavaScript: http://www.w3schools.com/JS/default.asp

Man, I can't believe I'm finally making an online RPG! ;D
Title: Re: JavaScript
Post by: GMG Kurt on March 18, 2011, 08:30:05 PM
where do you even find java script. I might not learn it for a long, long while, but I'm curious as to where to get it
Title: Re: JavaScript
Post by: Gan on March 18, 2011, 08:39:05 PM
JavaScript is in every web browser. Built in, just gotta code and run it in your browser.
Title: Re: JavaScript
Post by: x on March 18, 2011, 09:36:29 PM
You could also turn your javascript game into an iPhone game: http://www.phonegap.com/
Title: Re: JavaScript
Post by: Silverwind on March 19, 2011, 07:13:41 AM
Wow! I'm gonna look into this! :o I know JS better than I know GM.
Title: Re: JavaScript
Post by: x on March 19, 2011, 08:19:26 AM
Quote
Wow! I'm gonna look into this! :o I know JS better than I know GM.

I am currently using it to convert a web app for a wine company, its pretty cool as it basically converts JS/HTML/CSS to Objective-C "intermediate" code and compiles it. Thus you don't have the RAM restriction of normal web-browser JS.

Just throw in a HTML 5 canvass and use JS and you have you're self a nifty iPhone dev platform.

It supports the accelerometer as well as just about anything you can think of, and the best bit is once your done you can just compile it for Android OS, or whatever the hell you like!

http://www.phonegap.com/features
Title: Re: JavaScript
Post by: Silverwind on March 19, 2011, 09:19:08 AM
I've not jumped onto the HTML5 bandwagon yet. What's the idea with canvas?
Title: Re: JavaScript
Post by: Charlo on March 19, 2011, 12:01:45 PM
Hmm, I missed this thread the first time around.  I know JavaScript quite well and have toyed with the idea of making a game with it, using an HTML table as the "screen".  However, the canvas element changes that.  I think the idea of the canvas element is that you can draw whatever you want to it with JavaScript, so you're not limited to presenting your graphics with only basic HTML elements.
Title: Re: JavaScript
Post by: Silverwind on March 19, 2011, 12:04:47 PM
Quote
I think the idea of the canvas element is that you can draw whatever you want to it with JavaScript, so you're not limited to presenting your graphics with only basic HTML elements.
What do you mean? Is it just like a div?
Title: Re: JavaScript
Post by: Charlo on March 19, 2011, 02:25:33 PM
Quote
What do you mean? Is it just like a div?
A good comparison would be the paint commands in SC, I think.  You can draw rectangles, circles, lines, etc. on the canvas element.
Title: Re: JavaScript
Post by: Silverwind on March 19, 2011, 05:32:26 PM
Oh, I'm not too pushed on that sort of thing. As long as Phonegap supports div and img tags I'll be a happy chappy. ;D
Title: Re: JavaScript
Post by: x on March 19, 2011, 10:53:26 PM
The HTML5 canvas supports sprites, and animated sprites natively.

http://codeutopia.net/blog/2009/08/21/using-canvas-to-do-bitmap-sprite-animation-in-javascript/

Thats why its cool. Its also a lot faster than using JS to change div/img properties, but I guess thats not really an issue here.

Having said that, a html table makes perfect sense with the roguesoft grid engine!

PS: Just so you know, Phonegap supports anything safari can render. Since it gets safari to "render" each "frame".