View Single Post
  #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, 205 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