Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-14-2012, 11:00 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
We all love Asteroids! hopefully...

Well we do don't we?
Anyway, I loved this game as a kid, so I decided to try and re-create it.
My aim is to only use showimg's for rendering.
I will be adding the default sound for shooting too.
There is still a main issue, of the projectile system.
But I have some form of it.
Anyway here is what I have so far, any suggestions/improvements are welcome.
PHP Code:
//#CLIENTSIDE
function onCreated(){
  const 
Fire_Rate 3//Fire rate/reload time in seconds
  
const Rotation_Speed 0.12;  //How fast you rotate
  
const Max_Stars 300;
  
HideGUI();
  
DrawBackground();
  
this.started false;
  
this.menu false;
  
this.pressedspace false;
}
function 
onShowGUI(){
  
this.started false;
  
this.menu false;
  
findimg(250).alpha 0;
  
findimg(251).alpha 0;
  
findimg(252).alpha 0;
  
findimg(253).alpha 0;
  
Game_Close_Button.destroy();
  
enabledefmovement();
  
HideStars();
}
function 
HideGUI(){
  
disabledefmovement();
}
function 
DrawBackground(){
  
this.menu true;
  
with(findimg(250)){
    
polygon = {00screenwidth00screenheightscreenwidthscreenheight};
    
red blue green 0;
    
layer 3;
    
alpha 1;
  }
  
GenerateStarMap();
  
with(findimg(251)){
    
text "Press space to start.";
    
font "tempus sans";
    
screenwidth/text.length()*3.5;
    
screenheight/2;
    
red green blue 1;
    
alpha 1;
    
layer 4;
  }
  new 
GuiTextCtrl("Game_Close_Button"){
    
useownprofile true;
    
profile.fontsize 20;
    
profile.fontcolor = {255255255255};
    
text "Exit";
    
width 35;
    
height 20;
    
screenwidth 40;
    
screenheight 25;
    
thiso.catchevent(this"onMouseDown""onShowGUI");
  }
  
this.starting true;
  
FlickerText();
}
function 
FlickerText(){
  if(
this.menu){
    
this.flickermode = !this.flickermode;
  }
  if(
this.flickermode){
    while(
findimg(251).alpha 0){
      
findimg(251).alpha -= 0.02;
      
sleep(0.05);
    }
  }else{
    while(
findimg(251).alpha 1){
      
findimg(251).alpha += 0.02;
      
sleep(0.05);
    }
  }
  if(
this.menu){
    
FlickerText();
  }
}
function 
onKeyPressed(codekeyscan){
  if(
code == 32){
    if(
this.menu){
      
this.flickermode true;
      
this.menu false;
      
with(findimg(251)){
        
text "Starting";
         
screenwidth/text.length()*3;
       }
       
FlickerText();
      
scheduleevent(2"StartGame");
    }
  }
}
function 
onStartGame(){
  
with(findimg(252)){
    
text "V";
    
rotation 3169.91;
    
rotationcenter = {(screenwidth/2) +0, (screenheight/2)};
    
screenwidth/2;
    
screenheight/2;
    
alpha 1;
    
red blue green 1;
    
layer 4;
    
style "c";
  }
  
this.started true;
  
onTimeout();
}
function 
onTimeout(){
  if(
this.started){
    if(
keydown2(37true)){
     
findimg(252).rotation += Rotation_Speed;
    }
    if(
keydown2(39true)){
     
findimg(252).rotation -= Rotation_Speed;
    }
    if(
keydown2(32true)){
      if(!
this.pressedspace){
        
this.pressedspace true;
      }
      if(!
this.lastshot){
        
this.lastshot Fire_Rate*10;
        
this.rot findimg(252).rotation;
        
Shoot();
      }
    }
    if(
this.lastshot 0){
      
this.lastshot -= 0.5;
      if(
this.lastshot 0){
        
this.lastshot 0;
      }
    }
    if(
this.pressedspace){
      
this.moved += 15;
      
temp.sx = (screenwidth/2) + sin(this.rot)*this.moved;
      
temp.sy = (screenheight/2) + cos(this.rot)*this.moved;
      
with(findimg(253)){
        
zoom 3;
        
polygon = {sxsysx+zoomsysx+zoomsy+zoomsxsy+zoom};
        
layer 4;
        
alpha 1;
        
blue green 0;
        
red 1;
      }
    }
    
settimer(0.05);
  }
}
function 
Shoot(){
  
this.sx = (screenwidth/2) + sin(this.rot)*12;
  
this.sy = (screenheight/2) + cos(this.rot)*12;
  
this.moved 0;
}
function 
GenerateStarMap(){
  
this.stars null;
  while(
this.stars Max_Stars){
    
this.stars ++;
    
with(findimg(253+this.stars)){
      
random(0screenwidth);
      
random(0screenheight);
      
alpha random(0.50.8);
      
zoom random(0.030.5);
      
text "*";
      
layer 4;
    }
  }
}
function 
HideStars(){
  for(
temp.0temp.253+Max_Starstemp.++){
    
findimg((@temp.i)).hide();
  }

Also in need of some help with findimg's.
I have added a star map function but I can't hide them, probably a silly little error. anywho..
And Max_Stars is set as a constant of 400 if it makes any difference..

A video of this is attached in a zip folder.
I would of uploaded the avi but it isn't in the allowed list..
Attached Files
File Type: zip recording.zip (606.8 KB, 204 views)
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 05-15-2012 at 08:12 AM..
Reply With Quote
  #2  
Old 05-15-2012, 02:37 AM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan
Pics?
Reply With Quote
  #3  
Old 05-15-2012, 03:34 AM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Multiplayer?
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
Reply


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 03:43 AM.


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