...

View Full Version : javascript Space Invaders.... little help?



JSlime
07-10-2004, 05:30 AM
Hello everyone, I recently found this script at: http://js-x.com/javascript/?view=671 . It's a javascript version of space invaders (l'm sure most of you have seen it before). I was attempting to adapt the script to run in <textarea> that is <TEXTAREA rows=18 cols=25> instead of the
rows=20 cols=60 that the game currently runs on. So basically l'd want to remove one (or two) aliens from each row so that they fit in the resized text area, and probably remove one entire row of aliens just so they fit a little better. Problem is l can't seem to find that portion of the script for myself, l've been racking my brain for a couple nights trying to get this resized, but l just can't seem to get it done, would any of you be willing to help me out w/this? Here is the code, if so:



<html>
<head>

<SCRIPT LANGUAGE="JavaScript">
<!--
var timerID = null
var patno=1
var cr="\r\n" //for windows
var blankno=0
var totalblank=""
var lr=1 //if lr=-1 then left , lr=1 then right
var lowerlf="" //lower side space
var downlf="" //upper side space
var downno=0
var inplay=0
var missilex=99 //missile position
var missiley=99
var mychrx=1 //my chractor position
var myblank=""
var mymove=0
var spcf1=""
var spcf2=""
var spcf3=""
var hitflag=0
var score=0
var selec=0 //machine select
var mname=" Windows is"
var rsmiss="" //missile no hit R side

function array1(arn) { //hanyou hairetu sakusei
this.length = arn;
for (var ar1 = 0; ar1 <= arn; ar1++) {
this[ar1] = 1 }
return this
}

function onloadmes(){
document.fmark.win.value=" "
cr = unescape("%0A")
ver=navigator.appVersion
len=ver.length
for(iln=0;iln<len;iln++) if(ver.charAt(iln)=="(") break
systm = ver.charAt(iln+1).toUpperCase()
if(systm=="M"){cr = unescape("%0D")}
if(systm=="W"){cr = unescape("%0D")+cr}
if(systm=="C"){
cr = unescape("%0D")+cr
tmpsys = ver.charAt(0).toUpperCase()
if (tmpsys == 4){cr = unescape("%0D")}
}
// document.fmark.win.value=ver
starter()
}

function initThis(){ //syokika
blankx = new array1(63) //Dim blankx(63)
for (var makeblank = 0;makeblank < 63;makeblank++){
blankx[makeblank]=""
for (var addBlank = 0; addBlank < makeblank; addBlank++) {
blankx[makeblank] = blankx[makeblank] + " "
}
}
faker = new array1(24); //faker(1) to (24) = facemark active flag
face = new array1(2); //Dim face(2)
face[1]=" (^O^) "
face[2]=" (^-^) "
mestotal =new array1(4) //Dim mestotal(4)

interval1()
}

function restarter(){
inplay=0
blankno=0
totalblank=""
lr=1
lowerlf=""
downlf=""
downno=0
missilex=99
missiley=99
mychrx=1
myblank=""
mymove=0
selec=1
starter()
}

function starter(){
document.fmark.win.value=cr+cr+cr+cr+cr+cr+cr+" Are you ready?"+cr+cr+cr+" Click FIRE!"
selec=1
}

function goleft(){
mymove=0
mychrx=mychrx-1
if (mychrx <= 0){mychrx=1}
}
function goright(){
mymove=0
mychrx=mychrx+1
if (mychrx >= 56){mychrx=55}
}

function golmax(){
if (inplay == 1){mymove=-1}
}

function gormax(){
if (inplay == 1){mymove=1}
}

function fire(){
if (inplay == 0){if (selec == 1){selec=9
inplay=1
initThis()}
}else{
if (missiley == 99){missiley=18
missilex=mychrx+3}
}
}

function gameover(){ //GAME OVER syori
score=0
for (var enerme=1;enerme<25;enerme++){
if (faker[enerme] == 1){score=score+1}
}
if (score == 0){
document.fmark.win.value=cr+cr+cr+cr+cr+cr+cr+cr+" Congratulation!"+cr+cr+" ALL CREAR!!"
}else{
document.fmark.win.value=cr+cr+cr+cr+cr+cr+cr+cr+" GAME OVER"+cr+cr+" "+score+" ENEMY REMAINED"


}
inplay=0
}

function interval1(){ //warikomisyori 1
if (missiley != 99) {missiley=missiley-1}
if (missiley < 0){missiley=99}

mychrx=mychrx+mymove
if (mychrx <= 0){mychrx=1}
if (mychrx >= 56){mychrx=55}
blankno=blankno+lr //offset count up
totalblank = blankx[blankno] //offset syori
if (blankno >= 20) {lr=-1
downno=downno+1
blankno=20
}
if (blankno <= 0) {lr=1
downno=downno+1
blankno=0
}
if (downno >= 12) {gameover()}

//upper side aria
downlf=""
for (var upperspc=0;upperspc<downno;upperspc++){
if (missiley == upperspc){
downlf=downlf+blankx[missilex]+"|"+cr
}else{downlf=downlf+cr}
}


//facemark change
if (inplay == 1){
patno=patno+1
if (patno >= 3) {patno = 1}

//face aria

for (var addline = 1; addline < 5; addline++){
mestotal[addline]=totalblank
rsmiss=""
if (missiley == (downno+addline*2-2)){
if (blankno <= missilex){
hitflag=parseInt((missilex-blankno)/7,10)
if (hitflag < 6){
if ((missilex-blankno-(hitflag*7)) >= 1){
if ((missilex-blankno-(hitflag*7)) <= 5){
if (faker[(addline*6)+hitflag-5] == 1){
faker[(addline*6)+hitflag-5] = 0
missiley=99
}
}
}
}else{if (missilex > (blankno+42)){
rsmiss=blankx[missilex-blankno-42]+"|"
}
}
}else{
mestotal[addline]=blankx[missilex]+"|"
if (missilex < (blankno-1)){
mestotal[addline]=mestotal[addline]+blankx[blankno-1-missilex]
}
}
}

for (var addfaker = 1; addfaker < 7; addfaker++){
if (faker[(addline*6)+addfaker-6] == 1){
mestotal[addline]=mestotal[addline]+face[patno]
}else{mestotal[addline]=mestotal[addline]+" "}
}
mestotal[addline]=mestotal[addline]+rsmiss
}

//space line in face aria
spcf1=cr
spcf2=cr
spcf3=cr
if (missiley == (downno+1)){spcf1=blankx[missilex]+"|"+cr}
if (missiley == (downno+3)){spcf2=blankx[missilex]+"|"+cr}
if (missiley == (downno+5)){spcf3=blankx[missilex]+"|"+cr}

//lower side aria
lowerlf=""
for (var lowerspc=0;lowerspc<(11-downno);lowerspc++){
if (missiley == (downno+7+lowerspc)){
lowerlf=lowerlf+blankx[missilex]+"|"+cr
}else{lowerlf=lowerlf+cr}
}
myblank=blankx[mychrx]

document.fmark.win.value = downlf+mestotal[1]+cr+spcf1+mestotal[2]+cr+spcf2+mestotal[3]+cr+spcf3+mestotal[4]+cr+lowerlf+myblank+" _A_ "+cr+myblank+" [___] "

timerID = setTimeout("interval1()",250)
}
}

//-->
</SCRIPT>


</head>
<body>

Put this in the body tag:<BR>
<BODY onload="onloadmes()"><BR><BR>
or <a href="javascript:onloadmes()">click here</a>


<FORM NAME="fmark">
<center>
<textarea NAME="win" rows=20 cols=60>
You must get Netscape2.0 or later.
If you use Netscape 4.0b1, CLICK RESET!
</textarea>
</center>
<center>
<pre><INPUT TYPE="button" VALUE=" " ONCLICK="golmax()"><INPUT TYPE="button" VALUE=" LEFT " ONCLICK="goleft()"> <INPUT TYPE="button" VALUE="FIRE" ONCLICK="fire()"> <INPUT TYPE="button" VALUE="RIGHT" ONCLICK="goright()"><INPUT TYPE="button" VALUE=" " ONCLICK="gormax()"></pre>
</center>
<br><p>
<center><pre><INPUT TYPE="button" VALUE=" RESET " ONCLICK="restarter()"></pre>

<hr>
<input type=button value=Close onClick='window.close()'>
</center>

</FORM>

<BR><center><a href='http://www.js-x.com'>JS-X.com</a></center>
</body>
</html>

Willy Duitt
07-10-2004, 07:02 AM
Firstly, please edit your post and return the credits to the script so that additional copies of this script are not distibuted without due credit......

I would also hope that you return the credits to the page you are using this script on. ;)



<!--
This file retrieved from the JS-Examples archives
http://www.js-x.com
1000s of free ready to use scripts, tutorials, forums.
Author: Artem - http://javascript4free.by.ru
-->


......Willy

JSlime
07-11-2004, 12:09 AM
Firstly, please edit your post and return the credits to the script so that additional copies of this script are not distibuted without due credit......


zoinks, guess ya can't read very well....



Hello everyone, I recently found this script at: http://js-x.com/javascript/?view=671




I would also hope that you return the credits to the page you are using this script on.

It's something l'm working on for personal use, but thanks for the umm... 'errrrrr (?) help l guess.

~JSlime

Basscyst
07-11-2004, 01:24 AM
zoinks, guess ya can't read very well....

It's something l'm working on for personal use, but thanks for the umm... 'errrrrr (?) help l guess.

~JSlime

I think it is you who perhaps can't read very well.
http://js-x.com/user_agreement/

By posting the code in this forum without the credits in tact you are technically distributing the code in that way. Making it no longer just for your personal use.

Basscyst

Willy Duitt
07-11-2004, 02:37 AM
I read fine and even between the lines. And it does not take a rocket scientist to see that someone spent quite a bit of time writing that script and experience shows that there should have been credits within all those comments somewhere....

And even if you did not provide a link to the site you found the script on.
It would take me less than 10 seconds to do a search using one of the functions such as: document.fmark.win.value=" "
To return http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=document%2Efmark%2Ewin%2Evalue%3D%22+%22

It's a shame you did not find my help helpful. But all you would have had to do was respect both the orginal author and this forum by editting your post to include the credits which you removed.....

Have a nice day;
.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum