Graphics 640,480,0 Global instance_count=0 Include "Enemy.bmx" Include "Tplayer.bmx" Include "shot.bmx" Include "fragment.bmx" Include "star.bmx" SeedRnd MilliSecs () SetBlend LIGHTBLEND SetAlpha 1 Player.Create(400,240,90) '___________________________________variables____________________________________________________ rings_position#=1 cycletimer#=0 Global score=0 Global game_state=0 '0=title,1=game,2=gasme over '____________________________________functions____________________________________________________ ' draw rect unfilled Function draw_rect_hollow#(x1#,y1#,width#,Height#) DrawLine x1,y1,x1+width-1,y1 DrawLine x1,y1,x1,y1+Height-1 DrawLine x1+width-1,y1,x1+width-1,y1+Height-1 DrawLine x1,y1+Height-1,x1+width-1,y1+Height-1 EndFunction ' draw circle unfilled Function draw_ellipse_hollow#(x1#,y1#,width#,Height#,segments:Int,rotation#) Local center_x#=x1+(width/2) Local center_y#=y1+(Height/2) Local x_radius#=((width-1)/2) Local y_radius#=((Height-1)/2) Local angle#=360/segments For i=0 To segments-1 Step 1 DrawLine center_x+Sin((i*angle)+rotation)*x_radius,center_y+Cos((i*angle)+rotation)*y_radius,center_x+Sin(((i+1)*angle)+rotation)*x_radius,center_y+Cos(((i+1)*angle)+rotation)*y_radius Next EndFunction ' draw lines from center Function draw_ellipse_lines#(x1#,y1#,width#,Height#,segments:Int) Local center_x#=x1+(width/2) Local center_y#=y1+(Height/2) Local x_radius#=((width-1)/2) Local y_radius#=((Height-1)/2) Local angle#=360/segments For i=0 To segments-1 Step 1 DrawLine center_x+Sin(i*angle)*x_radius,center_y+Cos(i*angle)*y_radius,center_x,center_y Next EndFunction ' compute the distance between two points Function point_distance#(x1#,y1#,x2#,y2#) Local x_distance#=x1-x2 Local y_distance#=y1-y2 Local distance#=Sqr((x_distance*x_distance)+(y_distance*y_distance)) Return distance EndFunction 'compute the angle between 2 points Function point_direction#(x1#,y1#,x2#,y2#) Local Angle# = ATan2(y2-y1,x2-x1) If angle<0 angle:+ 360 End If Return angle End Function While not KeyDown(KEY_ESCAPE) While game_state=0 Cls ' set the general crapps SetColor 255,255,255 DrawText"Instances"+instance_count,0,0 'draw background color SetColor 0,0,0 DrawRect 0,0,640,480 ' set the positions of the flamming burrons ' 1st button start_button_x=320+Cos(270)*64 start_button_y=240+Sin(270)*64 SetColor 255,255,255 If point_distance(start_button_x,start_button_y,MouseX(),MouseY())<48 fragment.Create(start_button_x,start_button_y,3,270,90,96,8,16,24,60,-1.5) Else fragment.Create(start_button_x,start_button_y,3,270,90,96,5,5,5,60,-1.5) EndIf SetColor 255,255,255 '2nd button option_button_x=320+Cos(150)*64 option_button_y=240+Sin(150)*64 If point_distance(option_button_x,option_button_y,MouseX(),MouseY())<48 fragment.Create(option_button_x,option_button_y,3,150,90,96,24,8,16,60,-1.5) Else fragment.Create(option_button_x,option_button_y,3,150,90,96,5,5,5,60,-1.5) EndIf '3rd button quit_button_x=320+Cos(30)*64 quit_button_y=240+Sin(30)*64 If point_distance(quit_button_x,quit_button_y,MouseX(),MouseY())<48 fragment.Create(quit_button_x,quit_button_y,3,30,90,96,16,24,8,60,-1.5) Else fragment.Create(quit_button_x,quit_button_y,3,30,90,96,5,5,5,60,-1.5) EndIf ' check to see what the player has selected If MouseDown (MOUSE_LEFT)=True and point_distance(start_button_x,start_button_y,MouseX(),MouseY())<48 game_state=1 End If ' update fragments For Local m:fragment=EachIn fragment.fragment_list m.Update() Next Flip Wend '____Main Game_Loop_________________________________________________ While game_state=1 ' make sure the user hasn't quit Cls 'FPS_Counter <> Runs And displays the FPS '-------------------------------------------- SetRotation 0 'Undo rotation SetScale 1,1 'Undo scale FPS_Counter=FPS_Counter+1 If FPS_Counter_time+1000 =< MilliSecs() FPS=FPS_Counter' <- Frames/Sec FPS_Counter=0 FPS_Counter_time=MilliSecs() EndIf DrawText ""+score,20,20 '-------------------------------------------- ' draw step ' draw background SetColor 2,6,73 DrawRect 0,0,640,480 SetColor 45,56,68 draw_ellipse_hollow(160,0,480,480,36,0) draw_ellipse_lines(160,0,480,480,36) draw_ellipse_hollow(400-rings_position,240-rings_position,rings_position*2,rings_position*2,18,0) 'the font please SetScale 2,2 DrawText "Instances: "+instance_count,0,0 SetScale 1,1 ' make the enemies If cycletimer=0 Enemy.Create(400,240,Rand(360)+RndFloat(),1) EndIf ' make the stars Star.Create(400,240) ' update enemy For Local E:Enemy=EachIn Enemy.Enemy_List E.Update() Next ' update player For Local f:Player=EachIn Player.Player_List f.Update() Next ' update shots For Local g:Shot=EachIn Shot.shot_list g.Update() Next ' update fragments For Local k:fragment=EachIn fragment.fragment_list k.Update() Next ' update stazrs For Local l:Star=EachIn Star.Star_list l.Update() Next ' set the cycle timer +1 If cycletimer<10 cycletimer:+1 Else cycletimer=0 EndIf rings_position:*1.03 ' draw the movement lines If rings_position>240 rings_position=1 EndIf Flip Wend Wend
I hate to throw that whole thing at you at once but now it's doing it again, I think it's happening in the lower while loops.
the global game_state value is first set to 0
then in the firsst while loop it execuces code untill the player presses a button which sets game_state to 1. This should exit the first while loop and move to the second while loop. But it never does and it says there is a memory error and shuts down.
