Here's mine for now. What's the deadline? I still have a few things I wanna do before final submission.
REM ===============================================
REM Title: Looney Lander Challenge
REM Author: Phaelax
REM Date: March 31, 2011
REM ===============================================
set display mode 1024, 768, 32
randomize timer()
#CONSTANT SFX_EXPLODE = 1
#CONSTANT SFX_THRUST = 2
Global GRAV# = 0.01
Global FUEL = 1000
#CONSTANT EPSILON = 0.01
#CONSTANT WHITE = rgb(255,255,255)
#CONSTANT BROWN = rgb(50,30,1)
local slugSpeed = 1
local slugX = -100
REM ==== start variables for terrain ========================
Global DEPTH = 5
numOfPts = 2^DEPTH + 1
Global PT_COUNT = numOfPts
Global LANDING_POINT = 0
Global LANDING_WIDTH = 0
Global LANDING_SEGS = 3
dim points(numOfPts,2)
REM ==== end terrain variables ==============================
REM Background stars
#CONSTANT STARCOUNT = 200
dim stars(STARCOUNT, 3) as float
for i = 1 to STARCOUNT
stars(i, 1) = rnd(screen width())
stars(i, 2) = rnd(screen height())
select rnd(2)
case 0 : stars(i, 3) = 0.2 : endcase
case 1 : stars(i, 3) = 0.4 : endcase
case 2 : stars(i, 3) = 0.6 : endcase
endselect
next i
dim msg$(5)
msg$(1) = "Perfect!" : ` < 0.3
msg$(2) = "Rough Landing" : ` 0.4 > 0.7
msg$(3) = "You got lucky!" : ` 0.7 > 1.0
msg$(4) = "Too hard!" : ` > 1.0
msg$(5) = "Kamikaze!" : ` >= 1.5
dim platform(6,2)
Type ShipObject
x as float
y as float
vx as float
vy as float
thrust as float
EndType
ship as ShipObject
ship.thrust = 0.04
ship.x = 200 : ship.y = 23
`drawShip(32, 40)
`get image 1, 0, 0, 64, 57, 1
`sprite 1, 0, 0, 1 : hide sprite 1
`offset sprite 1, 32, 40
drawShip2(32, 44)
get image 1, 0, 0, 64, 61, 1
sprite 1, 0, 0, 1 : hide sprite 1
offset sprite 1, 32, 44
rem build a random lunar map
buildRandomMap(1)
`frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#
createsound("explosion",SFX_EXPLODE,300,3000,3500,2,0.1,0.05,0,0,0,10)
createsound("thrust",SFX_THRUST,500,41,4000,0.25,8.60,1.00,1,0.0,0,5.82)
REM ==== start fire/thrust particles ==============================
Type Particle
x as float
y as float
sx as integer
sy as integer
vx as float
vy as float
alpha as integer
color as dword
EndType
dim fire(200) as Particle
dim firePalette(4) as dword
firePalette(0) = rgb(255,0,0)
firePalette(1) = rgb(96,0,0)
firePalette(2) = rgb(255,128,0)
firePalette(3) = rgb(180,90,0)
firePalette(4) = rgb(200, 200, 0)
ink rgb(0,0,0), 0
box 0, 0, 20, 20
ink rgb(255,255,255),0
E2DC_Fill_Circle(10, 10, 10)
get image 4, 0, 0, 20, 20
sprite 4, 0, 0, 4 : size sprite 4, 4, 4 : offset sprite 4, 2, 2 : hide sprite 4
set sprite 4, 0, 1
for i = 1 to 200
clone sprite 4, i+4
hide sprite i+4
next i
REM ==== end fire/thrust particles ==============================
dim shipBlow(40, 40) as Particle
hide mouse
sync on
sync rate 60
do
cls
rem background sky
box 0, 0, 1024, 768, rgb(0,41,63),rgb(0,23,35),rgb(0,41,63),rgb(0,23,35)
gosub Controls
rem add gravity to ship's vertical velocity
inc ship.vy, GRAV#
rem cheap form of wind resistance, pushes
rem horizontal movement back to 0 velocity
if ship.vx > 0 then dec ship.vx, 0.01
if ship.vx < 0 then inc ship.vx, 0.01
if abs(ship.vx) < EPSILON then ship.vx = 0
rem check landing
if ship.y+16 >= points(LANDING_POINT, 2)-1
if ship.x-28 >= points(LANDING_POINT, 1) and ship.x+28 <= points(LANDING_POINT+LANDING_SEGS-1, 1)
ship.y = points(LANDING_POINT, 2)-17
if hasLanded# = 0 then hasLanded# = abs(ship.vy)+abs(ship.vx)
if thrust = 0 then ship.vy = 0
endif
endif
rem rotate ship
t# = ship.vx/1.5
if t# > 1 then t# = 1
if t# < -1 then t# = -1
a# = 20*t#
rotate sprite 1, a#
gosub doCollision
rem add velocity forces to ship's current position
inc ship.x, ship.vx
inc ship.y, ship.vy
gosub starBackground
rem platform image
paste image 3, 150, 150, 1
rem check landing
if hasLanded# > 0 and dead = 0
if hasLanded# > 1.0
dead = doDeath()
else
` successful landing
endif
endif
rem controls fire/thrust particles
gosub handleThrustParticles
rem draw the mountains image
paste image 2, 0, screen height()-500, 1
rem draw landing pad
gosub drawLandingPad
rem slug running along ground
gosub handleSlug
if dead = 0
rem draw the ship
paste sprite 1, ship.x, ship.y
else
tt# = doDeathEffect(tt#)
if tt# >= 50 then dead = 0 : tt# = 0 : hasLanded# = 0
endif
`dec rx, 2
`inc rot#, 0.5
`if rx <= 0 then rx = 1124 : ry = rnd(screen height())
`DrawPolyCircle(rx, ry, 60, 5, rot#)
rem Fuel meter
healthBar(412, 10, 200, 30, FUEL/1000.0)
ink 0, 0
center text 513, 19, "Fuel"
ink WHITE, 0
center text 512, 18, "Fuel"
text 645, 10, "(F1)Easy (F2)Medium (F3)Hard (F4)Expert"
if hasLanded# > 0
center text screen width()/2, 40, getLandingMessage$(hasLanded#)
endif
set cursor 0,0
print screen fps()
print "Landed: ", hasLanded#
print "VX: ", ship.vx
print "VY: ", ship.vy
print tt#
sync
loop
REM ===============================================
REM Space slug. Draws slug and checks for collision
REM with ship's landing feet.
REM ===============================================
handleSlug:
rem calculate positions of landing feet
x1 = ship.x + sin(118+a#)*32.249
y1 = ship.y - cos(118+a#)*32.249
x2 = ship.x - sin(62+a#)*32.249
y2 = ship.y + cos(62+a#)*32.249
slugSize# = 200
if hasLanded# = 0 then inc slugX, 2
if slugX > screen width() + slugSize# then slugX = -slugSize#
ba# = ba# + slugSpeed
if ba# >= 20 or ba# <= -30 then slugSpeed = slugSpeed*-1
v# = (sin(ba#)+1)*2
a = slugSize#*0.2
for n = a to slugSize#-a
n#=(b-a)*t+a
c = 255 - 255 * n/slugSize#
c1 = rgb(0,c,0)
c2 = rgb(c,c,0)
x# = (n-(slugSize#/2))/(slugSize#/4)
y# = (0.39894228*v#*exp(-x#*x#*v#))*(slugSize#*0.3)
base = getHeight#(slugX+n)
box slugX+n,base-y#,slugX+n+1,base, c2, c1, c2, c1
if slugX+n = x1
if y1 > base-y# then dead = doDeath()
endif
if slugX+n = x2
if y2 > base-y# then dead = doDeath()
endif
next n
RETURN
REM ===============================================
REM Player's controls
REM ===============================================
Controls:
rem player controls
thrust = 0
if dead = 0 and hasLanded# = 0
if upkey() and FUEL > 0
dec FUEL
thrust = 1
dec ship.vy, ship.thrust
if ship.vy < -1.5 then ship.vy = -1.5
if sound playing(SFX_THRUST) = 0 then play sound SFX_THRUST
endif
if ship.vy <> 0
if rightkey()
inc ship.vx, ship.thrust
endif
if leftkey()
dec ship.vx, ship.thrust
endif
endif
endif
rem Star a new game
rem F1 = easy, F2 = medium, F3 = hard, F4 = Expert
if scancode() = 59 and flag = 0 then buildRandomMap(1) : flag = 1 : hasLanded# = 0
if scancode() = 60 and flag = 0 then buildRandomMap(2) : flag = 1 : hasLanded# = 0
if scancode() = 61 and flag = 0 then buildRandomMap(3) : flag = 1 : hasLanded# = 0
if scancode() = 62 and flag = 0 then buildRandomMap(4) : flag = 1 : hasLanded# = 0
if scancode() = 0 then flag = 0
RETURN
REM ===============================================
REM Moves stars in background
REM ===============================================
starBackground:
rem draw stars
for i = 1 to STARCOUNT
select stars(i, 3)
case 0.2 : ink rgb(96,96,96),0 : endcase
case 0.4 : ink rgb(200,200,200),0 : endcase
case 0.6 : ink rgb(255,255,255),0 : endcase
endselect
box stars(i, 1), stars(i, 2), stars(i, 1)+1, stars(i, 2)+1
stars(i, 2) = stars(i, 2) - stars(i, 3)
if stars(i, 2) < 0 then stars(i, 2) = screen height() : stars(i, 1) = rnd(screen width())
next i
RETURN
REM ===============================================
REM Handles collision between the ship's landing
REM feet and the terrain
REM ===============================================
doCollision:
rem calculate positions of landing feet
x1 = ship.x + sin(118+a#)*32.249
y1 = ship.y - cos(118+a#)*32.249
x2 = ship.x - sin(62+a#)*32.249
y2 = ship.y + cos(62+a#)*32.249
rem screen boundaries
if ship.x > screen width()+21 then ship.x = -20
if ship.x < -20 then ship.x = screen width()+20
rem check collision
for t = 1 to PT_COUNT-1
rem check if ship's left leg is within this terrain segment's region
if x2 >= points(t, 1) and x2 <= points(t+1, 1)
y# = getHeight#(x2)
rem if ship hit ground
if y2 >= y#
ship.vy = 0
ship.y = y#-16
dead = doDeath()
endif
endif
rem check if ship's right leg is within this terrain segment's region
if x1 >= points(t, 1) and x1 <= points(t+1, 1)
y# = getHeight#(x1)
rem if ship hit ground
if y1 >= y#
ship.vy = 0
ship.y = y#-16
dead = doDeath()
endif
endif
next t
Rem platform collision with ship's dome
gosub platformCollision
RETURN
REM ===============================================
REM Handles collision between the ship's dome and
REM the platform
REM ===============================================
platformCollision:
for i = 0 to 6
ax = 150+platform(i,1)
ay = 150+platform(i,2)
if i < 6
bx = 150+platform(i+1,1)
by = 150+platform(i+1,2)
else
bx = 150+platform(0,1)
by = 150+platform(0,2)
endif
n# = (ship.x-ax)*(bx-ax) + ((ship.y-22)-ay)*(by-ay)
x# = bx - ax
y# = by - ay
d# = x#*x# + y#*y#
u# = n# / d#
if u# < 0 then u# = 0
if u# > 1 then u# = 1
ix = ax + (bx-ax)*u#
iy = ay + (by-ay)*u#
dist# = (ship.x-ix)^2 + ((ship.y-22)-iy)^2
if dist# <= 400
dead = doDeath()
endif
if ship.x > 150 and ship.x < 250
if dist# < 1528 and i = 6
if ship.vy > 0 then ship.vy = 0
endif
endif
next i
RETURN
REM ===============================================
REM Draw and animate the landing pad
REM ===============================================
drawLandingPad:
ink 0, 0
box points(LANDING_POINT,1),points(LANDING_POINT,2), points(LANDING_POINT+LANDING_SEGS-1,1),points(LANDING_POINT+LANDING_SEGS-1,2)+3
inc r#, 0.5
if r# > LANDING_WIDTH-3 then r# = 0
ink rgb(255,255,0),0
box points(LANDING_POINT, 1)+LANDING_WIDTH-r#, points(LANDING_POINT, 2), points(LANDING_POINT, 1)+LANDING_WIDTH-r#+3, points(LANDING_POINT, 2)+3
box points(LANDING_POINT, 1)+LANDING_WIDTH+r#, points(LANDING_POINT, 2), points(LANDING_POINT, 1)+LANDING_WIDTH+r#+3, points(LANDING_POINT, 2)+3
RETURN
REM ===============================================
REM handles the fire/thrust particles
REM ===============================================
handleThrustParticles:
for i = 1 to 200
d = (fire(i).x-fire(i).sx)^2 + (fire(i).y-fire(i).sy)^2
if d >= 30*30 or fire(i).vy = 0
if thrust = 1
fire(i).x = ship.x + rnd(20)-10
fire(i).y = ship.y
fire(i).sx = ship.x
fire(i).sy = ship.y
fire(i).alpha = 255
fire(i).color = firePalette(rnd(4))
set sprite diffuse i+4, rgbr(fire(i).color), rgbg(fire(i).color), rgbb(fire(i).color)
a = rnd(40)-20 - sprite angle(1)
v# = (rnd(20)+10) / 10.0
fire(i).vx = sin(a)*v#
fire(i).vy = cos(a)*v#
else
fire(i).vy = 0
endif
else
inc fire(i).x, fire(i).vx
inc fire(i).y, fire(i).vy
t# = (900-d) / 900.0
fire(i).alpha = 128*t#
if fire(i).alpha < 0 then fire(i).alpha = 0 : fire(i).vy = 0
endif
if fire(i).vy <> 0
set sprite alpha i+4, fire(i).alpha
paste sprite i+4, fire(i).x, fire(i).y
endif
next i
RETURN
REM ===============================================
REM begin the death process
REM ===============================================
function doDeath()
initDeathParticles()
play sound SFX_EXPLODE
ship.x = 200 : ship.y = 133
ship.vx = 0 : ship.vy = 0
endfunction 1
REM ===============================================
REM Animates death explosion particles
REM ===============================================
function doDeathEffect(t#)
lock pixels
for x = 1 to 40
for y = 1 to 40
px = shipBlow(x,y).x + shipBlow(x,y).vx*cos(shipBlow(x,y).alpha)*t#
py = shipBlow(x,y).y + shipBlow(x,y).vx*sin(shipBlow(x,y).alpha)*t# + 0.5*2*t#^2
E2DC_Dot(px,py,rgb(200,200,230))
next y
next x
unlock pixels
t# = t# + 0.5
if t# >= 50
`t# = 0
dead = 0
FUEL = 1000
endif
endfunction t#
REM ===============================================
REM initializes particles for death explosion
REM ===============================================
function initDeathParticles()
for x = 1 to 40
for y = 1 to 40
shipBlow(x,y).x = ship.x+x-20
shipBlow(x,y).y = ship.y+y-42
shipBlow(x,y).alpha = rnd(180)+180
shipBlow(x,y).vx = rnd(10)+5
next y
next x
endfunction
REM ===============================================
REM Determine successfullnes of landing
REM ===============================================
function getLandingMessage$(landingValue#)
t$ = "Out of range"
if landingValue# <= 0.3 then t$ = msg$(1)
if landingValue# > 0.3 and landingValue# <= 0.7 then t$ = msg$(2)
if landingValue# > 0.7 and landingValue# <= 1.0 then t$ = msg$(3)
if landingValue# > 1.0 and landingValue# < 1.5 then t$ = msg$(4)
if landingValue# >= 1.5 then t$ = msg$(5)
endfunction t$
REM ===============================================
REM Draws the lunar lander
REM ===============================================
function drawShip(x, y)
ink rgb(255,255,255),0
rem top
DrawPolyCircle(x, y-20, 20, 6, 90)
rem base
box x-20, y-10, x+20, y
rem left leg
line x-20, y-5, x-28, y+8
line x-16, y, x-28, y+8
line x-28, y+8, x-28, y+16
line x-32, y+16, x-24, y+16
rem right leg
line x+20, y-5, x+28, y+8
line x+16, y, x+28, y+8
line x+28, y+8, x+28, y+16
line x+32, y+16, x+24, y+16
endfunction
REM ===============================================
REM Draws the lunar lander
REM ===============================================
function drawShip2(x, y)
rem top
gradientFillCircle(x, y-22,20,x-6, y-30,30,rgb(229,241,243),rgb(123,162,194))
E2DC_Circle_AA_Alpha(x, y-22, 20, rgb(123,162,194))
E2DC_Circle_AA_Alpha(x, y-22, 20, rgb(123,162,194))
rem left leg
E2DC_Line_AA_ALPHA(x-20, y-5, x-28, y+8 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x-16, y, x-28, y+8 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x-28, y+8, x-28, y+16 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x-32, y+16, x-24, y+16 ,rgb(200,200,200))
rem right leg
E2DC_Line_AA_ALPHA(x+20, y-5, x+28, y+8 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x+16, y, x+28, y+8 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x+28, y+8, x+28, y+16 ,rgb(200,200,200))
E2DC_Line_AA_ALPHA(x+32, y+16, x+24, y+16 ,rgb(200,200,200))
rem base
box x-22, y-12, x+22, y, rgb(237,237,237),rgb(237,237,237),rgb(100,100,100),rgb(100,100,100)
endfunction
REM ===============================================
REM Draw polygon with center at [x,y] and
REM a radius of 'r' with 'segs' number of
REM segments and rotated at 'Rot#' angle
REM ===============================================
function DrawPolyCircle(x,y,r,segs,Rot#)
AngStep# = 360.0 / segs
Ang# = Rot#
For s = 1 To segs
OldAng# = Ang#
Ang# = Ang# + AngStep#
x1 = x + (r * Sin(Ang#))
y1 = y + (r * Cos(Ang#))
x2 = x + (r * Sin(OldAng#))
y2 = y + (r * Cos(OldAng#))
line x1,y1,x2,y2
Next s
endfunction
REM ===============================================
REM Creates a random terrain
REM ===============================================
function buildRandomMap(difficulty)
rem set begin and end points
points(1,2) = screen height()-120
points(PT_COUNT,2) = screen height()-120
segLength = screen width() / (PT_COUNT-1)
for i = 1 to PT_COUNT
points(i, 1) = (i-1)*segLength
next i
rem call the midpoint displacement function
midpoint(points(1,1),points(1,2),points(PT_COUNT,1),points(PT_COUNT,2),screen height()-50,500,0.6,DEPTH,1,PT_COUNT)
rem smooth the terrain
smooth(4)
rem set landing point
LANDING_POINT = rnd(PT_COUNT-4)+1
rem set landing pad length
if difficulty = 1 : LANDING_SEGS = 4 : else : LANDING_SEGS = 3 : endif
rem flatten landing pad
for i = 1 to LANDING_SEGS-1
points(LANDING_POINT+i, 2) = points(LANDING_POINT, 2)
next i
rem easy
if difficulty = 1
points(LANDING_POINT-1, 2) = points(LANDING_POINT, 2) + (rnd(40)+40)
if LANDING_POINT+LANDING_SEGS <= PT_COUNT then points(LANDING_POINT+LANDING_SEGS, 2) = points(LANDING_POINT+2, 2) + (rnd(40)+40)
GRAV# = 0.01
endif
rem medium
if difficulty = 2
GRAV# = 0.01
endif
rem hard
if difficulty = 3
points(LANDING_POINT-1, 2) = points(LANDING_POINT, 2) - (rnd(40)+40)
points(LANDING_POINT+LANDING_SEGS, 2) = points(LANDING_POINT+2, 2) - (rnd(40)+40)
GRAV# = 0.02
endif
rem expert
if difficulty = 4
points(LANDING_POINT-1, 2) = points(LANDING_POINT, 2) - (rnd(50)+100)
points(LANDING_POINT+LANDING_SEGS, 2) = points(LANDING_POINT+2, 2) - (rnd(50)+100)
GRAV# = 0.03
endif
FUEL = 1000
LANDING_WIDTH = (points(LANDING_POINT+LANDING_SEGS-1, 1)-points(LANDING_POINT, 1)) / 2
ship.x = 200 : ship.y = 123
ship.vx = 0 : ship.vy = 0
cls
drawPlatform()
if image exist(3) then delete image 3
get image 3, 0, 0, 100, 70, 1
cls
drawTerrain()
blur bitmap 0, 2
if image exist(2) then delete image 2
get image 2, 0, screen height()-500, screen width(), screen height(), 1
endfunction
REM ===============================================
REM Draws the terrain previously created by
REM buildRandomTerrain()
REM ===============================================
function drawTerrain()
segLength# = screen width() / (PT_COUNT-1)
for t = 1 to PT_COUNT-1
rem fill the terrain
ink BROWN,0
y2 = max(points(t, 2), points(t+1, 2))
for x = points(t,1) to points(t+1,1)
t# = (x - points(t, 1)) / segLength#
y = points(t, 2) + (points(t+1, 2)-points(t, 2))*t#
ink BROWN,0
box x, y, x+1, screen height()
`ink rgb(60,36,1),0
for i = y to screen height()
if rnd(1) = 1
h# = (screen height() - y)
r# = (h#-(screen height() - i)) / h#
`if r# < 0 then r# = 0
`if r# > 1 then r# = 1
c = getTransitionalColor(rgb(138,83,5), BROWN, r#)
ink c, 0
box x, i, x+1, i+1
endif
next i
next x
`box points(t,1),y2, points(t+1,1),screen height()
next t
rem show landing score
ink WHITE, 0
center text points(LANDING_POINT, 1)+LANDING_WIDTH, points(LANDING_POINT+1, 2)+4, "10"
endfunction
REM ===============================================
REM Draws a randomly-shaped platform
REM ===============================================
function drawPlatform()
tx = 0 : ty = 0
for i = 0 to 5
ax = 10+i*18
ay = 50+(rnd(40)-20)
if i = 5 then ax = 99 : ay = 0
platform(i,1) = tx : platform(i,2) = ty
ink BROWN, 0
for j = tx to ax
l# = ax-tx
t# = (j-tx)/l#
k = ty + (ay-ty)*t#
box j, 0, j+1, k
next j
tx = ax : ty = ay
next i
platform(i,1) = tx : platform(i,2) = ty
endfunction
REM ===============================================
REM recursive method using midpoint displacement
REM (x1,y1) - starting point of line
REM (x2,y2) - ending point of line
REM baseline - the base or ground of where the points start
REM height# - places midpoint Y-coord randomly between 0 and height#
REM h# - 0 < h# <= 1 : higher makes a very ridged line, lower makes smoother
REM depth - how many times should the line be split
REM arr1 - used for storing values in array
REM arr2 - used for storing values in array
REM ===============================================
function midpoint(x1,y1,x2,y2,baseline,height#,h#,depth, arr1,arr2)
y = baseline - rnd(height#)
arrIndex = arr1 + (arr2-arr1)/2
points(arrIndex,2) = y
dec depth, 1
if depth > 0
midpoint(x1,y1,x,y,baseline,height#*h#,h#,depth,arr1,arrIndex)
midpoint(x,y,x2,y2,baseline,height#*h#,h#,depth,arrIndex,arr2)
endif
endfunction
REM ===============================================
REM Smooths out terrain
REM ===============================================
function smooth(factor)
rem define an array to temporarily store the points.
local dim temp(PT_COUNT)
for k = 1 to factor
for i = 2 to PT_COUNT - 1
y = points(i,2)
y1 = points(i-1,2)
y2 = points(i+1,2)
temp(i) = (y+y1+y2)/3
next i
for i = 2 to PT_COUNT - 1
points(i,2) = temp(i)
next i
next k
endfunction
REM ===============================================
REM Returns the height on the terrain at point X
REM ===============================================
function getHeight#(x as float)
mapWidth# = points(PT_COUNT, 1) - points(1, 1)
segLength# = mapWidth# / (PT_COUNT-1)
p1 = ceil(x / segLength#)
if p1 <= 0 then p1 = 1
if p1 > PT_COUNT-1 then p1 = PT_COUNT-1
p2 = p1+1
t# = (x - points(p1, 1)) / segLength#
h# = points(p1, 2) + (points(p2, 2)-points(p1, 2))*t#
endfunction h#
REM ===============================================
REM x,y is the upper left corner of meter
REM P# ranges from 0 to 1
REM ===============================================
function healthBar(x, y, width, height, P#)
rem gradient bar
seg = width / 3
box x, y, x+seg, y+height, rgb(255,0,0),rgb(255,0,0),rgb(255,128,0),rgb(255,128,0)
box x+seg, y, x+seg+seg, y+height, rgb(255,128,0),rgb(255,128,0), rgb(255,255,0),rgb(255,255,0)
box x+seg+seg, y, x+width, y+height, rgb(255,255,0),rgb(255,255,0), rgb(0,255,0),rgb(0,255,0)
rem empty bit
ink rgb(0,24,35),0
box x+width*P#, y, x+width, y+height
rem highlight
c1 = 0xCCFFFFFF
c2 = 0x33FFFFFF
box x, y, x+width, y+height*0.5, c2,c1,c2,c1
endfunction
REM **************************************************
REM Gracefully swiped from Ric!
REM **************************************************
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)
outWord as word
dword1 as dword: dword2 as dword: dword3 as dword: dword4 as dword
dword5 as dword: dword6 as dword: dword7 as dword
samples=int((length#/1000)*44100)
if memblock exist(1) then delete memblock 1
make memblock 1,samples*2+28
` write 28 memblock header bytes
dword1=1 ` gg query: is this the number of channels?
dword2=2 ` gg query: is this the number of bytes per sample?
dword3=22050 ` gg query: seems to be half the number of samples per second - why?
dword4=88200 ` gg query: is this the number of bytes per second?
dword5=4 ` gg query: what does this represent?
dword6=16 ` gg query: (ditto) ?
dword7=0 ` gg query: (ditto) ?
position=0
write memblock dword 1, position, dword1 : inc position,4
write memblock dword 1, position, dword2 : inc position,4
write memblock dword 1, position, dword3 : inc position,4
write memblock dword 1, position, dword4 : inc position,4
write memblock dword 1, position, dword5 : inc position,4
write memblock dword 1, position, dword6 : inc position,4
write memblock dword 1, position, dword7 : inc position,4
rem generate and write wave
riseinloudness#=loudness#
for x=1 to samples
outInteger=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#-fallinloudness#-riseinloudness#+tremelodepth#*sin(phi#)))*3.0
if outInteger <-32767 then outInteger=-32767 ` gg query: is this the valid range?
if outInteger>32767 then outInteger=32767 ` gg query: (ditto) ?
outWord=outInteger
inc theta#,vibratospeed#
inc phi#,tremelospeed#
dec frequency#,bend#
if fallinloudness#<loudness#
inc fallinloudness#,decay#
endif
if riseinloudness#>0
dec riseinloudness#,attack#
endif
write memblock word 1, position, outWord : inc position,2
next x
if sound exist(soundnumber)=1 then delete sound soundnumber
make sound from memblock 999, 1
clone sound soundnumber, 999
delete sound 999
` memblock no longer required
delete memblock 1
endfunction
REM ***********************************************************************************************
REM ***********************************************************************************************
REM
REM ENHANCED 2D COMMANDS
REM
REM ***********************************************************************************************
REM ***********************************************************************************************
REM **************************************************
REM Fills circle with center [cx1,cy1] and radius r1
REM with a radial gradient starting from [cx2,cy2] and
REM a radius of r2.
REM **************************************************
function gradientFillCircle(cx1,cy1,r1,cx2,cy2,r2,gradient1,gradient2)
for x = cx1-r1 to cx1+r1
for y = cy1-r1 to cy1+r1
if (x-cx1)^2 + (y-cy1)^2 <= r1^2
p# = ((cx2-x)^2 + (cy2-y)^2+0.0) / r2^2
if p# > 1 then p#=1.0
ink getTransitionalColor(gradient1,gradient2,p#),0
box x,y,x+1,y+1
endif
next y
next x
endfunction
REM **************************************************
REM Draws an anti-aliased circle with alpha values
REM Based on Xiaolin Wu method
REM Unlike the above method, this uses true alpha
REM values but is slower
REM **************************************************
function E2DC_Circle_AA_Alpha(cx as integer, cy as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
x = r
xx = r
y = -1
yy = -1
t# = 0
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
rem anti-aliased pixels inside the circle
c = 127*cur_dist# : alpha1 = E2DC_ARGB(c, red, green, blue)
rem anit-aliased pixels outside the circle
c = 127 - c : alpha2 = E2DC_ARGB(c, red, green, blue)
rem octant 1
box cx-y, cy-x,cx-y+1, cy-x+1, color, color, color, color
box cx-y, cy-x-1,cx-y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx-y, cy-x+1,cx-y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
rem octant 2
box cx-x, cy-y,cx-x+1, cy-y+1, color, color, color, color
box cx-x-1, cy-y, cx-x, cy-y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy-y,cx-x+2, cy-y+1, alpha1, alpha1, alpha1, alpha1
rem octant 3
box cx-x, cy+y,cx-x+1, cy+y+1, color, color, color, color
box cx-x-1, cy+y, cx-x, cy+y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy+y,cx-x+2, cy+y+1, alpha1, alpha1, alpha1, alpha1
rem octant 4
box cx-y, cy+x, cx-y+1, cy+x+1, color, color, color, color
box cx-y, cy+x+1,cx-y+1, cy+x+2, alpha2, alpha2, alpha2, alpha2
box cx-y, cy+x-1,cx-y+1, cy+x, alpha1, alpha1, alpha1, alpha1
rem octant 5
box cx+y, cy+x,cx+y+1, cy+x+1, color, color, color, color
box cx+y, cy+x-1,cx+y+1, cy+x, alpha1, alpha1, alpha1, alpha1
box cx+y, cy+x+1,cx+y+1, cy+x+2, alpha2, alpha2, alpha2, alpha2
rem octant 6
box cx+x, cy+y,cx+x+1, cy+y+1, color, color, color, color
box cx+x-1, cy+y,cx+x, cy+y+1, alpha1, alpha1, alpha1, alpha1
box cx+x+1, cy+y,cx+x+2, cy+y+1, alpha2, alpha2, alpha2, alpha2
rem octant 7
box cx+x, cy-y, cx+x+1, cy-y+1, color, color, color, color
box cx+x-1, cy-y,cx+x, cy-y+1, alpha1, alpha1, alpha1, alpha1
box cx+x+1, cy-y,cx+x+2, cy-y+1, alpha2, alpha2, alpha2, alpha2
rem octant 8
box cx+y, cy-x,cx+y+1, cy-x+1, color, color, color, color
box cx+y, cy-x-1,cx+y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx+y, cy-x+1,cx+y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
t# = cur_dist#
endwhile
endfunction
REM **************************************************
REM Returns fractional part of distance
REM * Needed for Xiaolin Wu functions
REM **************************************************
function E2DC_Distance#(a, b)
real# = sqrt(a^2 - b^2)
d# = ceil(real#) - real#
endfunction d#
REM **************************************************
REM Returns a linear interpolated color between base
REM color and target color. Percent ranges from 0 to 1
REM **************************************************
function getTransitionalColor(base, target, percent#)
br = rgbr(base)
bg = rgbg(base)
bb = rgbb(base)
tr = rgbr(target)
tg = rgbg(target)
tb = rgbb(target)
tr = br + (tr-br)*percent#
tg = bg + (tg-bg)*percent#
tb = bb + (tb-bb)*percent#
color = rgb(tr,tg,tb)
endfunction color
REM **************************************************
REM Xiaolin Wu's line algorithm.
REM **************************************************
function E2DC_Line_AA_ALPHA(x1, y1, x2, y2, color as dword)
local dx as float
local dy as float
local xend as float
local yend as float
local xgap as float
local ygap as float
local xpxl1 as float
local ypxl1 as float
local xpxl2 as float
local ypxl2 as float
local intery as float
local interx as float
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
dx = x2-x1
dy = y2-y1
if abs(dx) > abs(dy)
rem handle horizontal lines
if x2 < x1
ax = x1
x1 = x2
x2 = ax
ay = y1
y1 = y2
y2 = ay
endif
gradient# = dy / dx
rem handle first endpoint
xend = ceil(x1)
yend = y1 + gradient# * (xend-x1)
xgap = 1.0 - fract#(x1 + 0.5)
xpxl1 = xend : `used in main loop
ypxl1 = int(yend)
f# = 1-fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1, xpxl1+1, ypxl1+1, c, c, c, c
rem brightness: fract#(yend)*xgap
f# = fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1+1, xpxl1+1, ypxl1+2, c, c, c, c
intery = yend + gradient# : `first y-intersection for main loop
rem handle second endpoint
xend = ceil(x2)
yend = y2 + gradient# * (xend-x2)
xgap = 1.0 - fract#(x2 + 0.5)
xpxl2 = xend : `used in main loop
ypxl2 = int(yend)
f# = 1-fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2, xpxl2+1, ypxl2+1, c, c, c, c
f# = fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2+1, xpxl2+1, ypxl2+2, c, c, c, c
rem main loop
a = xpxl1+1
b = xpxl2-1
for x = a to b
f# = 1-fract#(intery) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box x, intery, x+1, intery+1, c, c, c, c
f# = fract#(intery) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box x, intery+1, x+1, intery+2, c, c, c, c
intery = intery + gradient#
next x
else
rem handle vertical lines
if y2 < y1
ax = x1
x1 = x2
x2 = ax
ay = y1
y1 = y2
y2 = ay
endif
gradient# = dx / dy
rem handle first endpoint
yend = ceil(y1)
xend = x1 + gradient# * (yend-y1)
ygap = 1.0 - fract#(y1 + 0.5)
xpxl1 = int(xend)
ypxl1 = yend
f# = 1-fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1, xpxl1+1, ypxl1+1, c, c, c, c
intery = intery + gradient#
f# = fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1+1, xpxl1+1, ypxl1+2, c, c, c, c
interx = xend + gradient# : `first y-intersection for main loop
rem handle second endpoint
yend = ceil(y2)
xend = x2 + gradient# * (yend-y2)
ygap = fract#(y2 + 0.5)
xpxl2 = int(xend)
ypxl2 = yend
f# = 1-fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2, xpxl2+1, ypxl2+1, c, c, c, c
f# = fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2+1, xpxl2+1, ypxl2+2, c, c, c, c
rem main loop
a = ypxl1+1
b = ypxl2-1
for y = a to b
f# = 1-fract#(interx) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box interx, y, interx+1, y+1, c, c, c, c
f# = fract#(interx) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box interx+1, y, interx+2, y+1, c, c, c, c
interx = interx + gradient#
next y
endif
endfunction
REM **************************************************
REM quicker dot function
REM **************************************************
function E2DC_Dot(x as integer, y as integer, color as dword )
if x > 0 and x < screen width() and y > 0 and y < screen height()
offset = get pixels pointer()
pitch = get pixels pitch()
bitsPerPixel = bitmap depth(0)/8
pointer = offset + y*pitch + x*bitsPerPixel
*pointer = color
endif
endfunction
REM **************************************************
REM Draws a filled-in circle
REM **************************************************
function E2DC_Fill_Circle(x,y,r)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)*(xx-x) + (yy-y)*(yy-y)
if d# <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
next yy
endfunction
REM **************************************************
REM Just a little helper function
REM **************************************************
function fract#(x as float)
a# = x - int(x)
endfunction a#
REM **************************************************
REM Returns a color with an alpha value
REM **************************************************
function E2DC_ARGB(a,r,g,b)
local c as dword
c = (a*16777216)+(r*65536)+(g*256)+b
endfunction c