Yksinkertainen tasohyppely testi Hollywoodilla. Normaalisti pelin kartta olisi varmaankin tallennettuna tile-pohjaisesti muistin ja tilan säästämiseksi, eikä suoraan kuviksi.
Hollywood on syntaksiltaan selkokielisen helppo ja dokumentaatio on niin kattava, että tuosta esimerkistä varmaan joku tasohyppelyn tekemistä miettivä aloittelija voi jotain irti saadakin.
Lataa esimerkki datatiedostoineen tuolta: http://www.mediafire.com/?8s29f1zfxolohix
Hollywoodin voit tutustua ja ladata demo version, millä esimerkkikin toimii: http://www.hollywood-mal.com/
@APPICON {Ic16x16 = "my16x16icon.png",
Ic24x24 = "my24x24icon.png",
Ic32x32 = "my32x32icon.png",
Ic48x48 = "my48x48icon.png",
Ic128x128 = "my128x128icon.png",
Ic256x256 = "my256x256icon.png",
Ic512x512 = "my512x512icon.png"}
@SCREEN {Mode = "Windowed"}
@VERSION 2,0 /* Hollywood 2.0 strictly required */
/*
** External data
*/
@MUSIC 1, "1-01_main_theme_and_overworld.mp3"
@MUSIC 2, "intro.mod"
@SAMPLE 1, "smb_jumpsmall.wav"
@SAMPLE 2, "smb_coin.wav"
@SAMPLE 3, "smb_stomp.wav"
@BRUSH 5, "mario_world3.png", {LoadAlpha = True}
@BRUSH 11, "sky.png", {LoadAlpha = True}
@BRUSH 12, "bg.png", {LoadAlpha = True}
@BRUSH 13, "mountains.png", {LoadAlpha = True}
@BRUSH 9, "mario.png", {LoadAlpha = True}
@BRUSH 10, "baddie.png", {LoadAlpha = True}
@BRUSH 8, "coin.png", {LoadAlpha = True}
@BRUSH 15, "gcm.png", {LoadAlpha = True}
@DISPLAY {Width = 640, Height = 480, Title = "Another poor quality release from jalski's game factory: Shitty Mario World"}
Const #GRAVITY = 0.45
mario = {}
mario.x = 32
mario.y = 400 + 32
mario.xs = 0
mario.vy = 0
mario.frame = 0
mario.flipx = 0
mario.jumping = False
mario.scrollx = 0
mario.scrolling = False
mario.cpx = { bottom = { -11, 9 }, top = { 21, 41}, right = { 26, 30 }, left = { -30, -28 } }
mario.cpy = { bottom = { 32, 32 }, top = { 0, 0 }, right = { -10, -17}, left = {-17, -10} }
Function mario:move()
If mario.scrolling = False Then self.x = self.x + self.xs
If self.x < 32 Then self.x = 32
If self.x > 640 - 32 Then self.x = 640 - 32
self.vy = self.vy + #GRAVITY
If self.vy <> 0 Then mario.jumping = True
self.y = self.y + self.vy
self:CheckLevelCollision()
EndFunction
Function mario:animate()
Local time = GetTimer(3)
If time > 1000/6
If self.jumping
self.frame = 2
ElseIf self.xs <> 0 Or mario.scrolling = True
self.frame = self.frame + 1
self.frame = Wrap(self.frame, 0, 2)
Else
self.frame = 0
EndIf
ResetTimer(3)
EndIf
EndFunction
Function mario:draw()
Local framesy = { 0, 65, 129 }
DisplayBrushPart(9, 0, framesy[self.frame], self.x, self.y, 64, 64, {AnchorX = 0.5, AnchorY = 0.5})
EndFunction
Function mario:CheckLevelCollision()
Local col
SelectBrush(15)
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx])
While col = #RED
self.y = self.y - 0.5
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx])
Wend
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx] + 1)
If col = #RED
self.vy = 0
self.jumping = False
EndIf
If self.vy > 0
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx])
While col = $26FF
self.y = self.y - 0.5
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx])
Wend
col = ReadPixel(self.scrollx + self.x + self.cpx.bottom[self.flipx], self.y + self.cpy.bottom[self.flipx] + 1)
If col = $26FF
self.vy = 0
self.jumping = False
EndIf
EndIf
col = ReadPixel(self.scrollx + self.x + self.cpx.right[self.flipx], self.y + self.cpy.right[self.flipx])
While col = #RED
self.x = self.x - 1
col = ReadPixel(self.scrollx + self.x + self.cpx.right[self.flipx], self.y + self.cpy.right[self.flipx])
Wend
col = ReadPixel(self.scrollx + self.x + self.cpx.left[self.flipx], self.y + self.cpy.left[self.flipx])
While col = #RED
self.x = self.x + 1
col = ReadPixel(self.scrollx + self.x + self.cpx.left[self.flipx], self.y + self.cpy.left[self.flipx])
Wend
EndSelect
EndFunction
coins = {}
coins.coins = { { x = 100, y = 200}, { x = 350, y = 250 }, { x = 900, y = 300 }, { x = 1500, y = 200 }, { x = 1500, y = 280 }, { x= 1500, y = 360} }
Function coins:draw()
Local a, b = NextItem(self.coins)
While GetType(a) <> #NIL
If b.x >= mario.scrollx - 16 And mario.scrollx <= b.x + 640 + 16
DisplayBrush(8, b.x - mario.scrollx, b.y, {AnchorX = 0.5, AnchorY = 0.5})
EndIf
a, b = NextItem(self.coins, a)
Wend
EndFunction
Function coins:del(pos)
RemoveItem(self.coins, pos)
EndFunction
Function coins:collision()
Local framesy = { 0, 65, 129 }
CopyBrush(9, 20)
CropBrush(20, 0, framesy[mario.frame], 64, 64)
Local w1 = GetAttribute(#BRUSH,20,#ATTRWIDTH)
Local h1 = GetAttribute(#BRUSH,20,#ATTRHEIGHT)
Local w2 = GetAttribute(#BRUSH,8,#ATTRWIDTH)
Local h2 = GetAttribute(#BRUSH,8,#ATTRHEIGHT)
Local a, b = NextItem(self.coins)
While GetType(a) <> #NIL
If b.x >= mario.scrollx - 16 And mario.scrollx <= b.x + 640 + 16
If Collision(#BRUSH, 20, mario.scrollx + mario.x - w1/2, mario.y - h1/2, 8, b.x - w2/2, b.y - h2/2)
self:del(a)
ccount = ccount + 1
PlaySample(2)
Break
EndIf
EndIf
a, b = NextItem(self.coins, a)
Wend
EndFunction
baddies = {}
baddies.baddies = { { x = 1500, y = 25, sx = -1, vy = 0, alpha = 255, minx = 1300, maxx = 1500, frame = 0, dying = False, cpx = { bottom = 0, top = 0, left = -10, right = 10 }, cpy = { bottom = 25, top = -25, left = -25, right = 25 } },
{ x = 600, y = 400, sx = -1, vy = 0, alpha = 255, minx = 25, maxx = 800, frame = 0, dying = False, cpx = { bottom = 0, top = 0, left = -10, right = 10 }, cpy = { bottom = 25, top = -25, left = -25, right = 25 } },
{ x = 200, y = 300, sx = -1, vy = 0, alpha = 255, minx = 25, maxx = 800, frame = 0, dying = False, cpx = { bottom = 0, top = 0, left = -10, right = 10 }, cpy = { bottom = 25, top = -25, left = -25, right = 25 } },
{ x = 2500, y = 300, sx = -1, vy = 0, alpha = 255, minx = 25, maxx = 2500, frame = 0, dying = False, cpx = { bottom = 0, top = 0, left = -10, right = 10 }, cpy = { bottom = 25, top = -25, left = -25, right = 25 } } }
Function baddies:del(pos)
RemoveItem(self.baddies, pos)
EndFunction
Function baddies:move()
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
b.x = b.x + b.sx
If b.x <= b.minx Then b.sx = -b.sx
If b.x >= b.maxx Then b.sx = -b.sx
b.vy = b.vy + #GRAVITY
b.y = b.y + b.vy
self:CheckLevelCollision()
a, b = NextItem(self.baddies, a)
Wend
EndFunction
Function baddies:animate()
Local time = GetTimer(2)
If time > 1000/2
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
If b.dying = True
b.frame = 2
b.alpha = b.alpha - 0.75
If b.alpha < 0 Then self:del(a)
Else
b.frame = b.frame + 1
b.frame = Wrap(b.frame, 0, 2)
EndIf
a, b = NextItem(self.baddies, a)
Wend
ResetTimer(2)
Else
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
If b.dying = True
b.frame = 2
b.alpha = b.alpha - 4.5
If b.alpha < 0 Then self:del(a)
EndIf
a, b = NextItem(self.baddies, a)
Wend
EndIf
EndFunction
Function baddies:draw()
Local framesx = { 0, 50, 100 }
;CopyBrush(10, 25)
;CropBrush(25, 100, 0, 50, 50)
;CopyBrush(25, 26)
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
If b.x >= mario.scrollx - 25 And mario.scrollx <= b.x + 640 + 25
If b.dying = True
; Really should pre-calculate!
SelectAlphaChannel(26)
SetAlphaIntensity(0)
Cls
SetAlphaIntensity(b.alpha)
DisplayBrush(25, #CENTER, #CENTER)
EndSelect
DisplayBrush(26, b.x - mario.scrollx, b.y, {AnchorX = 0.5, AnchorY = 0.5})
Else
DisplayBrushPart(10, framesx[b.frame], 0, b.x - mario.scrollx, b.y, 50, 50, {AnchorX = 0.5, AnchorY = 0.5})
EndIf
EndIf
a, b = NextItem(self.baddies, a)
Wend
EndFunction
Function baddies:collision()
Local framesy = { 0, 65, 129 }
CopyBrush(9, 20)
CropBrush(20, 0, framesy[mario.frame], 64, 64)
Local w1 = GetAttribute(#BRUSH,20,#ATTRWIDTH)
Local h1 = GetAttribute(#BRUSH,20,#ATTRHEIGHT)
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
If b.x >= mario.scrollx - 50 And mario.scrollx <= b.x + 640 + 50
If Collision(#BRUSH_VS_BOX, 20, mario.scrollx + mario.x - w1/2, mario.y - h1/2, b.x + b.cpx.left, b.y + b.cpy.top, 20, 50)
If (mario.y + mario.cpy.bottom[mario.flipx]) <= (b.y + b.cpy.top + mario.vy) And mario.vy >= 0
b.dying = True
b.sx = 0
PlaySample(3)
Break
Else
;mario dies!
EndIf
EndIf
EndIf
a, b = NextItem(self.baddies, a)
Wend
EndFunction
Function baddies:CheckLevelCollision()
Local col
SelectBrush(15)
Local a, b = NextItem(self.baddies)
While GetType(a) <> #NIL
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom)
While col = #RED
b.y = b.y - 0.5
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom)
Wend
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom + 1)
If col = #RED
b.vy = 0
EndIf
If b.vy > 0
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom)
While col = $26FF
b.y = b.y - 0.5
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom)
Wend
col = ReadPixel(b.x + b.cpx.bottom, b.y + b.cpy.bottom + 1)
If col = $26FF
b.vy = 0
EndIf
EndIf
col = ReadPixel(b.x + b.cpx.right, b.y + b.cpy.right)
While col = #RED
b.x = b.x - 1
col = ReadPixel(b.x + b.cpx.right, b.y + b.cpy.right)
Wend
col = ReadPixel(b.x + b.cpx.right + 1, b.y + b.cpy.right)
If col = #RED
b.sx = -b.sx
b.x = b.x + b.sx
EndIf
col = ReadPixel(b.x + b.cpx.left, b.y + b.cpy.left)
While col = #RED
b.x = b.x + 1
col = ReadPixel(b.x + b.cpx.left, b.y + b.cpy.left)
Wend
col = ReadPixel(b.x + b.cpx.left - 1, b.y + b.cpy.left)
If col = #RED
b.sx = -b.sx
b.x = b.x + b.sx
EndIf
a, b = NextItem(self.baddies, a)
Wend
EndSelect
EndFunction
Function p_MainLoop()
If IsKeyDown("LEFT")
If(mario.flipx <> 1)
mario.flipx = 1
FlipBrush(9, True)
EndIf
mario.xs = mario.xs - 0.5
If mario.xs < -2.5 Then mario.xs = -2.5
If mario.x < 0 + 128 And mario.scrollx > 0 + Abs(mario.xs)
mario.scrolling = True
mario.scrollx = mario.scrollx + mario.xs
Else
mario.scrolling = False
EndIf
ElseIf IsKeyDown("RIGHT")
If(mario.flipx <> 0)
mario.flipx = 0
FlipBrush(9, True)
EndIf
mario.xs = mario.xs + 0.5
If mario.xs > 2.5 Then mario.xs = 2.5
If mario.x >= 640 - 128 And mario.scrollx < 1920 - Abs(mario.xs)
mario.scrolling = True
mario.scrollx = mario.scrollx + mario.xs
Else
mario.scrolling = False
EndIf
Else
mario.xs = 0
mario.scrolling = False
EndIf
If IsKeyDown("UP") And mario.jumping = False
mario.vy = -10.5
PlaySample(1)
EndIf
mario:move()
baddies:move()
coins:collision()
baddies:collision()
p_DrawBackground(mario.scrollx)
coins:draw()
baddies:animate()
baddies:draw()
mario:animate()
mario:draw()
Box(#LEFT, #TOP, boxw, boxh, #BLACK)
TextOut(#LEFT, #TOP, "COINS: " .. ccount)
Flip
EndFunction
Function p_DrawBackGround(sx)
DisplayBrushPart(11, sx/3, 0, 0, 0, 640, 480)
DisplayBrushPart(13, sx/2, 0, 0, 480-290, 640, 290)
DisplayBrushPart(12, sx, 0, 0, 480-242, 640, 242)
EndFunction
Function p_Zoomit(t$)
Local sx, sy, trans = 1, 1, 0
TextOut(#CENTER, #CENTER, t$, {AnchorX = 0.5, AnchorY = 0.5})
For Local k = 1 To 20
sx = sx + 0.2
sy = sy + 0.2
trans = trans + (255 / 20)
SetLayerStyle(1, {ScaleX = sx, ScaleY = sy, Transparency = trans})
WaitTimer(1, 1000/25)
Next
EndFunction
Function p_RotoZoom()
Local framesx = { 0, 50, 100 }
Local sx, sy, trans, ang = 1, 1, 0, 0
DisplayBrushPart(10, framesx[0], 0, #CENTER, #CENTER, 50, 50, {AnchorX = 0.5, AnchorY = 0.5})
For Local k = 1 To 20
sx = sx + 0.5
sy = sy + 0.5
trans = trans + (255 / 20)
ang = ang + 18
ang = Wrap(ang, 0, 360)
SetLayerStyle(1, {ScaleX = sx, ScaleY = sy, Rotate = ang, Transparency = trans})
WaitTimer(1, 1000/25)
Next
EndFunction
SetFillStyle(#FILLCOLOR)
SetFont(#TRUETYPE_DEFAULT, 50)
SetFontColor(#WHITE)
; Dying frame for fading out the squashed enemy
CopyBrush(10, 25)
CropBrush(25, 100, 0, 50, 50)
CopyBrush(25, 26)
EscapeQuit(True)
PlayMusic(2)
StartTimer(1)
EnableLayers
WaitPatternPosition(23)
p_ZoomIt("Get ready")
RemoveLayer(1)
WaitPatternPosition(30)
p_ZoomIt("for some")
RemoveLayer(1)
WaitPatternPosition(37)
p_ZoomIt("old school")
RemoveLayer(1)
WaitPatternPosition(44)
p_ZoomIt("gaming action")
RemoveLayer(1)
p_RotoZoom()
RemoveLayer(1)
DisableLayers
; Display start screen
MoveBrush(5, #CENTER, #BOTTOMOUT, #CENTER, #CENTER, 1)
WaitKeyDown("SPACE")
ResetTimer(1)
PlaySample(2)
WaitTimer(1, 1500)
StopTimer(1)
StopMusic(2)
SetFont(#TRUETYPE_DEFAULT, 18)
boxw = TextWidth("coins: 10000")
boxh = TextHeight("coins: 10000")
ccount = 0
; Game time!
BeginDoubleBuffer
StartTimer(2)
StartTimer(3)
SetVolume(1, 30)
SetVolume(2, 30)
SetVolume(3, 30)
PlayMusic(1)
SetInterval(1, p_MainLoop, 1000/50) ; 50fps
Repeat
WaitEvent
ForeverAihe on jo aika vanha, joten et voi enää vastata siihen.