Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Norby

#1
I am new to GL Basic.  I like to try out different languages.

I created the following program, but when I run the code, the screen appears, then closes.  Nothin appears or happens but it appears and disappears.

Could anyone explain to me what I am doin wrong?

Code (glbasic) Select


// --------------------------------- //
// Project: Time Bot
// Start: Sunday, June 14, 2015
// IDE Version: 12.308
// --------------------------------- //

// Note: Program Uptime: Uptime# = GETTIMERALL()
// PRINT Msg$, X, Y

SEEDRND GETTIMERALL()

SETSCREEN 640, 400, 0
CLEARSCREEN RGB(0, 0, 0)

LOADANIM "Font.png", FontSprite, 8, 16
LOADSPRITE "Sun.png", SunSprite
LOADSPRITE "Moon.png", MoonSprite

// Global Variables
GLOBAL SunSprite=1
GLOBAL MoonSprite=2
GLOBAL FontSprite=3

GLOBAL Angle = 0
GLOBAL Planet = 318
GLOBAL Reds = 0
GLOBAL Greens = 0
GLOBAL Blues = 0
GLOBAL Increment = .004365 * 3
GLOBAL NumStars = 1000

GLOBAL StarRad[]
GLOBAL StarAngle[]

DIM StarRad[NumStars]
DIM StarAngle[NumStars]

LOCAL X, Y
FOR i = 1 TO NumStars
  X = (RND(640) - 320)
  Y = (RND(400) - 200)
  // Convert StarX, StarY
  StarRad[i] = X
  StarAngle[i] = Y
NEXT

GLOBAL StarIncrement = Increment / 5

LOCAL Touch$
LOCAL Quit = 0
WHILE Quit=0
  GOSUB SkyUpdate
  Touch$ = INKEY$()
  IF Touch$="Q" THEN Quit = 1
WEND
END

SUB SkyUpdate:
LOCAL StarX, StarY
LOCAL SunX, SunY
LOCAL MoonX, MoonY
LOCAL Time$, Hours, Minutes, Seconds, Timer

Greens = 255 * .5 * SIN(Angle)
IF Greens < 0 THEN Greens = 0

Blues = 255 * 1 * SIN(Angle)
IF Blues < 0 THEN Blues = 0
DRAWRECT 0, 0, 640, 400, RGB(0, Greens, Blues)

// Rotate AND redraw stars.
FOR i = 1 TO NumStars
   StarX = StarRad[i] * COS(StarAngle[i])
   StarY = StarRad[i] * SIN(StarAngle[i]) - 200
   // Convert X,Y

   SETPIXEL StarX, StarY, RGB(150, 150, 200)
   StarAngle[i] = StarAngle[i] + StarIncrement
NEXT

// Draw the Sun
SunX = Planet * COS(Angle)
SunY = Planet * SIN(Angle) + 158
// Convert X, Y

ZOOMSPRITE SunSprite, SunX, SunY, 2, 2

// Draw the Moon
MoonX = Planet * COS(Angle + 3.14159)
MoonY = Planet * SIN(Angle + 3.14159) + 158
//Convert X, Y

ZOOMSPRITE MoonSprite, MoonX, MoonY, 2, 2

// Roate the sun/moon angle.
Time$ = PLATFORMINFO$("TIME")
Hours# = 3600 * LEFT$(Time$, 2)
Minutes# = 60 * MID$(Time$, 3, 2)
Seconds# = RIGHT$(Time$, 2)
Timer = Hours + Minutes + Seconds

Angle = (2 * 3.14159) * (Timer / 86400) - 3.14159 / 2

SHOWSCREEN
RETURN

ENDSUB