Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-05-2001, 03:05 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Asteroids.

Well... I made this asteroidsish game script a while ago.
It's hardly done, but i haven't had time to work on it for a long time. So I'll just see what ya think as it is.

NPC Code:

// NPC made by Rogue Shadow -TT-*C* (TCN)
if (playerenters&&isleader) {
lives=10;
playerx=0;
playery=0;
hideplayer 10000;
disabledefmovement;
setvars();
}
function setvars(){
rocks=0;
maxshots=50;
maxrocks=15;
setarray shots,4*maxshots;
setarray ship,5;
ship[0] = (screenwidth/16)/2;
ship[1] = (screenheight/16)/2;
ship[2] = 0;
ship[3] = 0;
showship();
timeout=.05;
}
if (timeout){
if (keydown(1))ship[4]+=.314;
if (keydown(3))ship[4]-=.314;
if (keydown(5)&&!warped==1)warpship();
if (keydown(4))shoot();
move();
showship();
drawshots();
timeout=.05;
}

function showship(){
this.tx=ship[0]+sin(ship[4])*2;
this.ty=ship[1]+cos(ship[4])*2;
this.dx=(this.tx-ship[0]);
this.dy=(this.ty-ship[1]);
this.dist = (this.dx^2+this.dy^2)^0.5;
addx=(this.dx/this.dist);
addy=(this.dy/this.dist);
for (this.b=0;this.b<npcscount;this.b++){
if (testnpc(ship[0],ship[1])==this.b){
putexplosion 0,ship[0],ship[1];
gamepoints-=50;
setvars();
if (lives<=0){
set gaveover;
}else lives--;
}
}
showimg 200,icemateria.gif,ship[0],ship[1];
showimg 201,watermateria.gif,ship[0]+addx,ship[1]+addy;
}
function warpship(){
this.warped=1;
ship[0]=random(0,screenwidth/16);
ship[1]=random(0,screenheight/16);
ship[2]=0;
ship[3]=0;
}
function move(){
if (keydown(0)){
if (!warped==0)warped=0;
ship[2]+=addx*.1;
ship[3]+=addy*.1;
}
ship[0]+=ship[2];
ship[1]+=ship[3];
if (ship[0]<0)ship[0]=screenwidth/16;
if (ship[0]>screenwidth/16)ship[0]=0;
if (ship[1]<0)ship[1]=screenheight/16;
if (ship[1]>screenheight/16)ship[1]=0;
}

function shoot(){
shots[bllt]=ship[0]+addx;
shots[bllt+1]=ship[1]+addy;
shots[bllt+2]=addx;
shots[bllt+3]=addy;
if (bllt<maxshots*4){bllt+=4}else{ bllt=0;}
}

function drawshots(){
for (this.i=0;this.i<maxshots*4;this.i+=4){
showimg this.i,kstar.gif,shots[this.i],shots[this.i+1];
shots[this.i]+=shots[this.i+2];
shots[this.i+1]+=shots[this.i+3];
if (shots[this.i]<0)shots[this.i]=screenwidth/16;
if (shots[this.i]>screenwidth/16)shots[this.i]=0;
if (shots[this.i+1]<0)shots[this.i+1]=screenheight/16;
if (shots[this.i+1]>screenheight/16)shots[this.i+1]=0;
for (this.b=0;this.b<npcscount;this.b++){
if (testnpc(shots[this.i],shots[this.i+1])==this.b){
putexplosion 0,shots[this.i]-.5,shots[this.i+1]-.5;
hideimg this.i;
}
}
}
}



If this is totally confusing to you. aw well.
If this looks too easy. aw well.
Fact is I scripted this a while ago and If I put some real work into it I could do it a lot better im sure.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.