Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

Snowman's Stars »

You do not own this project, so changes will not be saved

/* 
 * The AGameAWeek/PMC Template thing
 * Week 4 edition!
*/


/* Brief File Layout
 * 
 *          Tweaks at the Top
 * 
 * Variables
 * Sprite/Sound Loader
 * Default Inks
 * 
 * Menu : Tweak name / brief instructions
 * 
 * 
 * ^^^^^^^^^^^^^^^^
 *          Ignore the Middle
 * Main Loop
 * Loading screen
 * Messy function stuff that can be ignored forever
 * vvvvvvvvvvvvvvv
 * 
 * 
 * 
 *          Code the End
 * Gamey bit goes at the bottom.
 * Don't forget to set $Score, to save highscores.
*/






// Globals
$jscrw=getScreenWidth();
$jscrh=getScreenHeight();

$MyUser = new User();
$MyName=$MyUser.getName();

$j_scaleX=1;
$j_scaleY=1;
$flipat=120;
$flipcred=0;$creds=0;

$titletick=0;$tune=0;

$GameType=2;
$GameMode=-2;
$EndofGame=0;
$MenuIn=-32;
$Debug='';

$kdown=0;

$waiter=0;

$score=0;
$level=0;

// Arrays!  Hurray!
$Palette=[];
$img=[];
$imgData=[];
$sfx=[];
$grid=[];
$on=[];
$on2=[];
$obj=[];


$score_table=[];

50.times() do |n|
    $score_table[n]=0;
end;

Load();


// Defaults
LoadImage(99,'bg_smash_blue',512,1,1);
LoadImage(1,'sprites_001',16,32,32);
LoadImage(2,'sprites_002',16,32,32);

LoadSFX(1);
LoadSFX(95);
LoadSFX(97);
LoadSFX(98);
LoadSFX(99);


// Default Colour Scheme
AddInk( 0,  0,  0,  0) //  0 Black
AddInk( 1,  0,  0,128) //  1 Blue
AddInk( 2,  0,  0,255) //  2 Bright Blue
AddInk( 3,128,  0,  0) //  3 Red
AddInk( 4,128,  0,128) //  4 Magenta 
AddInk( 5,128,  0,255) //  5 Mauve
AddInk( 6,255,  0,  0) //  6 Bright Red
AddInk( 7,255,  0,128) //  7 Purple
AddInk( 8,255,  0,255) //  8 Bright Magenta

AddInk( 9,  0,128,  0) //  9 Green
AddInk(10,  0,128,128) // 10 Cyan
AddInk(11,  0,128,255) // 11 Sky Blue
AddInk(12,128,128,  0) // 12 Yellow
AddInk(13,128,128,128) // 13 White 
AddInk(14,128,128,255) // 14 Pastel Blue
AddInk(15,255,128,  0) // 15 Orange
AddInk(16,255,128,128) // 16 Pink
AddInk(17,255,128,255) // 17 Pastel Magenta

AddInk(18,  0,255,  0) // 18 Bright Green
AddInk(19,  0,255,128) // 19 Sea Green
AddInk(20,  0,255,255) // 20 Bright Cyan
AddInk(21,128,255,  0) // 21 Lime
AddInk(22,128,255,128) // 22 Pastel Green
AddInk(23,128,255,255) // 23 Pastel Cyan
AddInk(24,255,255,  0) // 24 Bright Yellow
AddInk(25,255,255,128) // 25 Pastel Yellow
AddInk(26,255,255,255) // 26 Bright White



Font(32)


// -=-=-=-=-=-=-=-=-
//  Menu Stuff         (Up top : once it's done I can ignore it)
// -=-=-=-=-=-=-=-=-

def RunMenu(delta)    
    Options=3

    
    ResetDraw()
    SetSize(2);
    DrawImg(99,(($jscrw-((40*3)+20))/2),$jscrh/2+44,0)
    
    ResetDraw()
    if ($MenuIn<0) $MenuIn=$MenuIn+(delta);end;
    if ($MenuIn>0) $MenuIn=0;end;
    
    Ribbon(0,$jscrw*.25,64,"Snowman's Stars",24,15,26,$MenuIn,1,0.75)
    Ribbon(1,$jscrw-(20*3)-10,$jscrh*.5,"Sidebar?",26,0,0,-$MenuIn,3,0.5)
    Ink(15);font(32)
    text(($jscrw-70)-($MenuIn*8),64,"HTML5",1,1)
    
    Ribbonb(0,40,$jscrh-16,"Z to start, Cursors to move",0,26,14,-$MenuIn*2,0.7,0.2)
    font(32);
    x=(($jscrw-((40*3)+20))/2)
    y=((($jscrh/2)+64)-(Options*20))-($MenuIn*16)
    
    Ink(14);if ($GameType==1) ink(26);end;
    ShadowText(x,y,"Easy",1,1);y=y+40
    Ink(14);if ($GameType==2) ink(26);end;
    ShadowText(x,y,"Normal",1,1);y=y+40
    Ink(14);if ($GameType==3) ink(26);end;
    ShadowText(x,y,"Hard",1,1);y=y+40
    
    if (playkey(0) && $kdown==0) $GameType=$GameType-1;$kdown=1;playsfx(99);end;
    if (playkey(8) && $kdown==0) $GameType=$GameType+1;$kdown=2;playsfx(99);end;

    if ((playkey(10) || playkey(11)) && $kdown==0) $GameMode=10;$kdown=3;playsfx(98);end; 
    if ($GameType<1) $GameType=Options;end;
    if ($GameType>Options) $GameType=1;end;

    Font(16);Ink(26)
    10.times() do |n|
        d=240-(n*14)
        if ($GameType==1) SetColor(d,d,d/4);end;
        if ($GameType==2) SetColor(d,d/2,d/4);end;
        if ($GameType==3) SetColor(d,d/4,d/4);end;
            
        Text($jscrw-30,(108+($MenuIn*40))+(n*26),PadRight($score_table[n+(($GameType-1)*10)],'0',8),:right,0)
    end;
    
    if ($but.getmousex()>$jscrw-120 && $but.getmousey()<80 && $MenuIn==0)
        ink(15)
        FillRoundedRect($jscrw/2,$jscrh/2,$jscrw*0.8,$jscrh*0.8,38,1,1)
        ink(24)
        FillRoundedRect($jscrw/2,$jscrh/2,($jscrw*0.8)-32,($jscrh*0.8)-32,32,1,1)
        
        ink(0);font(20)
        y=80;
        Text($jscrw/2,y,"PlayMyCode.com uses Quby to",1,1);y=y+22
        Text($jscrw/2,y,"generate HTML5 based games.",1,1);y=y+32
        Text($jscrw/2,y,"",1,1);y=y+24
        Text($jscrw/2,y,"Simply log in, click Build, and start coding.",1,1);y=y+16
        Text($jscrw/2,y,"",1,1);y=y+30
        Text($jscrw/2,y,"Once you're done, you can embed",1,1);y=y+22
        Text($jscrw/2,y,"your game onto your own site.",1,1);y=y+58
        font(32)
        Text($jscrw/2,y,"PlayMyCode.com",1,1);y=y+42
        font(20)
        Text($jscrw/2,y,"Like YouTube, but for Games!",1,1);y=y+28
        font(12)
        Text($jscrw/2,y,"Game created by Jayenkai : AGameAWeek.com",1,1);
    end;
    
    
ResetDraw();
$flipat=$flipat-delta
if ($flipat<-75) $flipat=75;end;
if ($flipat>-8 && $flipat<8) $creds=rand(12,23.9).floor();end;
    $flipcred=dcos($flipat*1.2)*64;
    if ($flipcred<32) $flipcred=32;end;
    
    a=($creds/16).floor()+1;b=($creds%16)*64;
    16.times() do |x|
        DrawImg(a,($jscrw-(16*16))+(x*16),(($jscrh-48)-$MenuIn)+$flipcred,b+x)
    end;
    
end;



// Main Loop
onEachFrame() do |delta|
$but=getControls();
fill( 0, 0, 0 )
    if ($GameMode==-2) Title(delta); end;
    if ($GameMode==-1) GotoMenu(delta); end;
    if ($GameMode==0) RunMenu(delta); end;

    if ($GameMode==10) GotoGame(delta); end;
    if ($GameMode==11) RunGame(delta); end;
    if ($GameMode==12) EndGame(delta); end;


    if (!(playkey(0) || playkey(3) || playkey(5) || playkey(8) || playkey(10) || playkey(11) || playkey(12) || playkey(13) )) $kdown=0;end;
    ink(26);font(12);Shadowtext($jscrw-1,1,$debug,:right,0);
end

def Title(delta)
    ResetDraw()
            
    if ($titletick>140)
        SetSize(2);
        d=($titletick-140)*3
        if (d>255) d=255;end;
        SetColor(d,d,d)
        DrawImg(99,(($jscrw-((40*3)+20))/2),$jscrh/2+44,0)
    end;
    if ($titletick>30 && $tune==0) PlaySFX(95);$tune=1;end;
    $titletick=$titletick+delta
    if ($titletick>240) $GameMode=-1; end;
    
    in=($titletick-60)
    if ($titletick>59 and $titletick<161) in=0;end;
    if ($titletick>160) in=$titletick-160;end;
    if ($titletick<240)
        Ribbon(0,$jscrw*.5,$jscrh*.25,"AGameAWeek.com",24,15,0,in,1.5,0.8)
        Ribbon(0,$jscrw*.5,$jscrh*.75,"PlayMyCode.com",8,26,0,-in,1.5,0.8)
    end;
    
end;

def GotoMenu(delta)
    $GameMode=0;
    $MenuIn=-32;
    $kdown=1;
    Debug('');
end;





// -=-=-=-=-=-=-=-=-
//  Function Stuff       (Middle : Pretty much ignore, always!)
// -=-=-=-=-=-=-=-=-

// Stuffs
def Debug(ftxt)
    $Debug=ftxt;
end;

def Save()
    savetext='';
    50.times() do |n|
        savetext=savetext+PadRight($score_table[n],' ',32);
    end;
    $myUser.saveGame(savetext);
end;

def Load()
    loadtext=$myUser.LoadGame();
    if (loadtext!=null)
    50.times() do |n|
        loadbit='';
        32.times() do |m|
            c=loadtext.GetChar((n*32)+m);
            if (c!=' ' && c!=null) loadbit=loadbit+c;end;
            $score_table[n]=loadbit;
        end;
    end;
    end;
end;

def dsin(fdeg) return (fdeg/57.29577866666166).sin(); end;
def dcos(fdeg) return (fdeg/57.29577866666166).cos(); end;
def rnd(fa,fb) return rand(fa,fb+0.999999).floor();end;

// Doodley

def Ribbon(horvert,cx,cy,txt,ink1,ink2,ink3,in,size,alpha)
    Ink(ink2,alpha)
    if (horvert==0) FillRect((cx-$jscrw)+(in*64),(cy-(20*size)),$jscrw*2,(40*size)); end;
    if (horvert==1) FillRect((cx-(20*size)),(cy-$jscrh)+(in*64),(40*size),$jscrh*2); end;

    Ink(ink1,alpha)
    if (horvert==0) 
        FillRect((cx-$jscrw)-(in*48),(cy-(20*size))+in,$jscrw*2,(4))
        FillRect((cx-$jscrw)-(in*32),(cy+((20*size)-4))-in,$jscrw*2,(4))
    end;
    if (horvert==1) 
        FillRect((cx-(20*size))-in,(cy-$jscrh)-(in*48),(4),$jscrh*2)
        FillRect((cx+((20*size)-4))+in,(cy-$jscrh)-(in*32),(4),$jscrh*2)
    end;
    
    Font(32);
    Ink(ink3)
    if (horvert==0) ShadowText(cx-(in*16),cy,txt,1,1);end;
//    if (horvert=1) ShadowText(cx-(in*16),cy,txt,1,1);end;
        
end;


def Ribbonb(horvert,cx,cy,txt,ink1,ink2,ink3,in,size,alpha)
    Ink(ink2,alpha)
    if (horvert==0) FillRect((cx-$jscrw)+(in*64),(cy-(20*size)),$jscrw*2,(40*size)); end;
    if (horvert==1) FillRect((cx-(20*size)),(cy-$jscrh)+(in*64),(40*size),$jscrh*2); end;

    Ink(ink1,alpha)
    if (horvert==0) 
        FillRect((cx-$jscrw)-(in*48),(cy-(20*size))+in,$jscrw*2,(4))
        FillRect((cx-$jscrw)-(in*32),(cy+((20*size)-4))-in,$jscrw*2,(4))
    end;
    if (horvert==1) 
        FillRect((cx-(20*size))-in,(cy-$jscrh)-(in*48),(4),$jscrh*2)
        FillRect((cx+((20*size)-4))+in,(cy-$jscrh)-(in*32),(4),$jscrh*2)
    end;
    
    Font(16);
    Ink(ink3)
    if (horvert==0) ShadowText(cx-(in*16),cy,txt,0,1);end;
//    if (horvert=1) ShadowText(cx-(in*16),cy,txt,1,1);end;
        
end;

// Palettey

def AddInk(n,r,g,b)
    $Palette[(n*3)+1]=r;
    $Palette[(n*3)+2]=g;
    $Palette[(n*3)+3]=b;
end;
def Ink(n)
    SetColor($Palette[(n*3)+1],$Palette[(n*3)+2],$Palette[(n*3)+3]);
end;
def Ink(n,alpha)
    SetColor($Palette[(n*3)+1],$Palette[(n*3)+2],$Palette[(n*3)+3],alpha);
end;

// Wordy
def Text(fx,fy,ftxt,fcx,fcy)
    FillText(ftxt,fx,fy,fcx,fcy)
end;
def ShadowText(fx,fy,ftxt,fcx,fcy)
    SetColor(0,0,0) do
        FillText(ftxt,fx+1,fy+1,fcx,fcy)
    end;
    FillText(ftxt,fx,fy,fcx,fcy)
end;
def font(size)
    setFont( 'Arial', size,'bold');// Yeah, I'm lazy, so what!!?
end;

def PadRight(ftxta,pad,len)
    ftxt=''+ftxta;
    while (ftxt.length()0)
        sx=((frame % $imgData[(n*10)+1]).floor())*sz;
        sy=((frame / $imgData[(n*10)+1]).floor())*sz;
    end;

    if (frame>$imgData[(n*10)+1]*$imgData[(n*10)+2]) frame=$imgData[(n*10)+1]*$imgData[(n*10)+2]; end;
    DrawImage($img[n],sx,sy,sz,sz,x,y,sz*$j_scaleX,sz*$j_scaleY,1)
end;

def SetSize(fx)
    $j_scaleX=fx;$j_scaleY=fx;
end;
def SetSize(fx,fy)
    $j_scaleX=fx;$j_scaleY=fy;
end;

def ResetDraw()
    SetColor(255,255,255,1);
    SetSize(1);
    Font(32);
end;


// SFX
def LoadSFX(fn)
    $sfx[fn]=new sound(PadRight(fn,'0',3)+'.mp3');
end;

def PlaySFX(fn)
    if ($sfx[fn]==null) LoadSFX(fn);end;
    if ($sfx[fn]) $sfx[fn].Play();end;
end;


// Keys
def PlayKey(fn)
    if (fn==0) return ($but.isKeyDown('up') || $but.isKeyDown('w') ); end; 
    if (fn==8) return ($but.isKeyDown('down') || $but.isKeyDown('s') ); end; 
        
    if (fn==3) return ($but.isKeyDown('left') || $but.isKeyDown('a') ); end; 
    if (fn==5) return ($but.isKeyDown('right') || $but.isKeyDown('d') ); end; 

    if (fn==10) return ($but.isKeyDown('z') || $but.isKeyDown('space') || $but.isKeyDown('enter') || $but.isKeyDown('j') ); end; 
    if (fn==11) return ($but.isKeyDown('x') || $but.isKeyDown('k') ); end; 
    if (fn==12) return ($but.isKeyDown('c') || $but.isKeyDown('l') ); end; 
    if (fn==13) return ($but.isKeyDown('v') || $but.isKeyDown('i') ); end; 

    if (fn==1) return ($but.isKeyDown('backspace') || $but.isKeyDown('tab') ); end; 
end;

// -=-=-=-=-=-=-=-=-
//       Game             (Hit End to skip to the bottom, do codeystuff)
// -=-=-=-=-=-=-=-=-

def EndGame(delta)
    
    alpha=($waiter)/40
    if (alpha<0) alpha=0;end;
    if (alpha>0.7) alpha=0.7;end;
        
    fill(0,0,0,alpha)
    
    $waiter=$waiter+delta;
    usewait=($waiter-20)*2;
    if (usewait>0) usewait=0;end;
    if ($waiter>160) usewait=($waiter-160)*3; end;
        
    put=10;
    10.times() do |n|
        if ($score>$score_table[n+(($GameType-1)*10)] && put==10) put=n;end;
    end;
        
    Ribbon(0,$jscrw*.25,$jscrh*.4,"Game Over",6,3,6,-usewait,2,0.5)    
    Ribbon(0,$jscrw*.7,$jscrh*.6,"Score : "+$score,2,11,26,usewait,1,0.7)
    
if (put<10) 
    nth='First';
    if (put==1) nth='Second';end;
    if (put==2) nth='Third';end;
    if (put==3) nth='Forth';end;
    if (put==4) nth='Fifth';end;
    if (put==5) nth='Sixth';end;
    if (put==6) nth='Seventh';end;
    if (put==7) nth='Eighth';end;
    if (put==8) nth='Ninth';end;
    if (put==9) nth='Tenth';end;

    Ribbon(0,$jscrw*.5,($jscrh*.8)+((usewait.abs())*4),"Highscore : "+nth,9,18,26,-usewait,1,0.4)
end;


    if ($waiter>180)
        if (put<10) 
            10.times() do |n|
                m=9-n;
                if (m<10 && m>put) $score_table[m+(($GameType-1)*10)]=$score_table[(m-1)+(($GameType-1)*10)];end;
            end;
            $score_table[put+(($GameType-1)*10)]=$score;
        end;
        
        Save();
        $GameMode=-1; $waiter=0;
    end;
end;

def Make()
        
    
    10.times() do |y|
        $on[y]=rnd(0,4);
        $on2[y]=rnd(6,16);
    end;
    
    512.times() do |x|
        10.times() do |y|
            if (x<256) $grid[y*256+(x%256)]=0;end;
            if ($on[y]==1) $grid[y*256+(x%256)]=1;end;
            $on2[y]=$on2[y]-1;
            if ($on2[y]<0) $on2[y]=rnd(6,16);$on[y]=rnd(0,4);end;
        end;
    end;
    
    25.times() do |n|
        fin=0;
        while (fin==0)
            x=rnd(35,220)
            y=rnd(0,9)
            if ($grid[y*256+(x-2)]==1 && $grid[y*256+(x-1)]==1 && $grid[y*256+(x)]==1 && $grid[y*256+(x+1)]==1 && $grid[y*256+(x+2)]==1)
                fin=1;
                $grid[y*256+(x)]=n+2;
            end;
        end;
    end;
    
    $px=6144;
    $psx=0;
    $here=0;

    $py=$jscrh/2;
    $pjump=0;
    $pf=10;
    $pd=1;
    $pfall=0;
    
    $bonus=(120*60)-(900*$GameType);
    $pf2=0;
    $gets=2;
end;


def GotoGame(delta)
    Debug('');
    $score=0;$level=1;
    $GameMode=11;
    $EndofGame=0;
    $waiter=0;
    Make();
    
end;


def RunGame(delta)
    if (delta>3) delta=3;end;
    ResetDraw();
    SetSize(2);
    DrawImg(99,(($jscrw/2)-($px/4))+2048,$jscrh/2,0)
    DrawImg(99,(($jscrw/2)-($px/4))+1024,$jscrh/2,0)
    
    if ($endofgame==0) $bonus=$bonus-delta;end;
    if ($bonus<0 && $endofgame==0) $bonus=0;$endofgame=1;end;
    
    if ($px<4096) $px=$px+4096;end;
    if ($px>8192) $px=$px-4096;end;
        
    lx=((($px.floor()/16)%256)-20)+256
    rx=(($px/16)%256)+19
    ox=-($px%16);
    SetSize(1)
    $pf=$pf2;
    $pf2=-1;
    40.times() do |x|
        11.times() do |y|
            if ($grid[y*256+((x+lx)%256)]==1 || y==10)
                DrawImg(2,(x*16)+ox,(y*36)+32,392+(y==10));
                if ( (((x*16)+ox)-($jscrw/2)).abs()<18 && $pjump==0 && (((y*36)+16)-$py).abs()<9)
                    if (playkey(8)==0 || y==10) $pf2=y;$py=((y*36)+32)-16;$pfall=0;end;
                end;
                
            end;
            if ($grid[y*256+((x+lx)%256)]>1)
                s=392;
                if ((((x*16)+ox)-($jscrw/2)).abs()<18 && $pjump==0 && (((y*36)+16)-$py).abs()<9)
                    $pf2=y;$py=((y*36)+32)-16;$pfall=0;
                end;
                s2=0;
                if (($here-(x+lx)).abs()<24) s2=398;end;
                if ($here>(x+lx)) s2=397;end;
                    
                if ($gets==$grid[y*256+((x+lx)%256)])
                    s=333;$here=x+lx;s2=0;
                    if ((((x*16)+ox)-($jscrw/2)).abs()<24 && $pf==y && $endofgame==0)
                        $gets=$gets+1;
                        $score=$score+$bonus.floor();
                        $score=$score+5;
                        PlaySFX(1);
                        $here=0;
                    end;
                end;
                if ($gets>$grid[y*256+((x+lx)%256)]) s=381;end;
                DrawImg(2,(x*16)+ox,(y*36)+32,s);
                if ($here==0) s2=0;end;
                    
                if (s2>0) DrawImg(2,(x*16)+ox,(y*36)+16,s2);end;
            end;
            
        end;
    end;

    
    
    if (playkey(3)) $psx=$psx-1;$pd=0;end;
    if (playkey(5)) $psx=$psx+1;$pd=1;end;
    if (playkey(3)==0 && $psx<0) $psx=$psx+1.5;if ($psx>0) $psx=0;end;end;
    if (playkey(5)==0 && $psx>0) $psx=$psx-1.5;if ($psx<0) $psx=0;end;end;

    if ($psx<-24) $psx=-24;end;
    if ($psx>24) $psx=24;end;

$px=$px+$psx*delta;
    Drawimg(2,$jscrw/2,$py,394+(($pd==1)*8));


if ($pfall<12) $pfall=$pfall+1.5;end;
if ($pfall>12) $pfall=12;end;
if ($pjump>0) $pfall=0;$pjump=$pjump+6*delta;$py=$py-(dcos($pjump)*12*delta);if ($pjump>90) $pjump=0;end;end;
$py=$py+($pfall*delta);

if ((playkey(0) || playkey(10)) && $pf>-1) $pjump=6;end;

if ($gets==27 && $endofgame==0) $score=$score+$bonus*10;$endofgame=1;end;

    ink(26,0.8);font(12);
    Shadowtext(1,1,'[DEL] to quit',0,0);
    
    ink(1,1);font(16)
    
    Text($jscrw*.25,$jscrh-2,'Time : '+PadRight($bonus.floor(),'0',4),1,:bottom);
    ink(1,1);font(16)
    Text($jscrw*.75,$jscrh-2,'Score : '+PadRight($score,'0',8),1,:bottom);
    

    // For the minute, no pause..  must fix
    if (playkey(1) && $EndofGame==0) $EndofGame=99; end;
    if ($EndofGame!=0) EndGame(delta);end;
end;



ERRORS

YOUR BROWSER DOES NOT SUPPORT HTML5!

Please use one of these instead

Our games cannot run in your browser