Code:
'=========================================================================
' WINTER CHRISTMAS
' It's almost Christmas ! Santa Claus is running to the north pole.
' Collect gifts as many as possible for children around the world.
' Please be careful, Yeti didn't like Santa Claus.
'
' CONTROL KEYS
' - UP = jump
' - ESC / ENTER = continue
'
' ACKNOWLEDGMENTS
' - Game Speed / Slow motion effect by Marcus
' https://naalaa.com/forum/thread-155-post-1124.html#pid1124
' - How to code efficiently by Marcus
' https://naalaa.com/forum/thread-162-post-1190.html#pid1190
' - Wind moderate strong JPN by freesound community
' https://pixabay.com/sound-effects/wind-moderate-strong-jpn-78086/
' - Yeti King sprite sheet submitter by madhattervx
' https://www.spriters-resource.com/pc_computer/spelunky2/sheet/182550/
' - Cartoon Character Sneeze
' https://mixkit.co/free-sound-effects/sneeze/
' - Santa Claus Sprite Sheet
' https://www.gameart2d.com/santa-claus-free-sprites.html
' - Jump sound effect
' https://mixkit.co/free-sound-effects/jump/
' - Retro Arcade Lose
' https://mixkit.co/free-sound-effects/lose/
'
' DISCLAIMER
' This tiny game is a work of fiction.
' It is not intended for commercial use and not for sale
' No person or entity associated with this game received payment
' or anything of value, or entered into any agreement,
' in connection with any game assets used in this game.
' Names, characters, places, events and incidents
' are either the products of the author’s imagination
' or used in a fictitious manner.
' Any resemblance to actual persons, animals, and creatures,
' living or dead, or actual events is purely coincidental.
'
'=========================================================================
'----------------
' INITIALIZATION
'----------------
#win32
randomize time()
set window "Winter Christmas", 512, 256,false,2
set redraw off
'color definition
visible deepblue = [20,30,40]
visible white = [255,255,255]
grey = [200,200,200]
'font
bigfont = createfont("arial", 24, true, false, false, true)
' snow
snow = []
for i = 1 to 1000
c = 64 + rnd(256) 'color
snow[sizeof(snow)] =
[
'properties
x: rnd(512), y: rnd(512),
dy: 25 + rnd(200),
c: [c, c, c],
'functions
Update: function(dt)
this.y = (this.y + this.dy*dt)%230
if this.x > 0 then
this.x = this.x - rnd(0,1)
else
this.x = 512
endif
endfunc,
Draw: function()
set color this.c
draw pixel this.x, this.y
endfunc
]
next
' misc variables
visible gameSpeed = 1
visible answer ="N"
prevTime = clock()
' Sound effect
visible soundEffect = true
wind = loadmusic("assets/wind1.wav")
if soundEffect then play music wind,1
' Santa Claus
visible santa = []
santa.run = loadimage("assets/santaclaus.png",11,1)
santa.head = loadimage("assets/head.png",1,1)
santa.cell = 0
santa.x = 20
santa.y = 175
santa.pos = 0 'santa position 0=stay 1=up 2=down
santa.jump = loadsound("assets/jump.wav")
santa.lose = loadsound("assets/lose.wav")
santa.life = 5
santa.deltay = 0
' Yeti
yetis = []
for i = 1 to 5
yetis[sizeof(yetis)] =
[
'properties
x: rnd(0,700), y: 170,
walk:loadimage("assets/yeti_walk.png",8,1),
cell:rnd(0,7),
'functions
Update: function(dt)
this.x = this.x - dt*20
if this.x < -50 then
this.x = rnd(500,800)
endif
endfunc,
Draw: function(dt)
set color white
draw image this.walk,this.x,this.y, this.cell
if this.cell <8 then
this.cell = this.cell + dt*5
else
this.cell = rnd(0,7)
endif
'collision detection
if santa.pos = 0 and int(santa.x+30) = int(this.x) then
santa.life = santa.life - 1
do
set color deepblue
draw rect 0,230,512,20,1
set color white
message("Press ENTER to Continue")
if soundEffect then play sound santa.lose,1
wait 1
until keydown(KEY_RETURN,true)
endif
endfunc
]
next
'box
visible boxCount = 0
box = []
for i = 1 to 20
box[sizeof(box)] =
[
'properties
img: loadimage("assets/box.png"),
x: rnd(500,800), y: rnd(80,160),
'functions
Update: function(dt)
this.x = this.x - dt*50
if this.x < -50 then
this.x = rnd(500,800)
endif
'collision detection
if santa.pos = 1 and int(santa.x+30) = int(this.x) then
boxCount = boxCount + 1
this.x = rnd(500,800)
endif
endfunc,
Draw: function()
set color rnd(100,255),rnd(100,255),rnd(100,255)
draw image this.img, this.x, this.y
endfunc
]
next
'--------------
' MAIN PROGRAM
'--------------
do
while not keydown(KEY_ESCAPE)
' Delta time
t = clock()
dt = (min(t - prevTime, 66))/1000
prevTime = t
dt = dt*gameSpeed
gameSpeed = gameSpeed + dt*0.025
' background scene
set color deepblue ; cls
set color white ; draw rect 0,220,512,10,1 'white ground
'snow animation
foreach s in snow s.Update(dt)
foreach s in snow s.Draw()
'santa claus animation
set color white
draw image santa.run,santa.x,santa.y,santa.cell
santa.cell = (santa.cell+dt*20)%11
if keydown(KEY_UP) and santa.pos = 0
santa.deltay = -200
santa.pos = 1
if soundEffect then
play sound santa.jump,1
endif
elseif santa.pos
santa.deltay = santa.deltay + dt*200
santa.y = santa.y + santa.deltay*dt
if santa.y >= 175
santa.y = 175
santa.pos = 0
endif
endif
'info
set color grey
draw image box[1].img,430,10
set caret 465,10 ; set font bigfont; write boxCount
set color white
if santa.life > 0 then
for k = 1 to santa.life
draw image santa.head,25*k-20,10
next
else
exit()
if upper(answer) = "Y" then santa.life = 5
endif
set color deepblue
draw rect 0,230,512,20,1
set color white
set caret 10,235
set font 0; write "Game Speed :"+ int(gameSpeed)
'yeti animation
foreach y in yetis y.Update(dt)
foreach y in yetis y.Draw(dt)
'box animation
foreach b in box b.Update(dt)
foreach b in box b.Draw()
redraw
wait 1
wend
exit()
loop
'-----------
' FUNCTIONS
'-----------
function message(text)
set color deepblue
draw rect 0,230,512,20,1
set color white
set caret 10,235; set font 0; write text
redraw
endfunc
function exit()
set color deepblue
draw rect 0,230,512,20,1
set color white
set font 0
do
message("Continue ? (Y/N)")
answer = rln(1,TYPE_STRING)
if upper(answer) = "N" then end
wait 1
until upper(answer) ="Y"
gameSpeed = 1
endfunc