Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Santa by Marcus
#1
Here is a blast from the past (2017)  Almost seasonal... how coincidental... lol


.zip   santa.zip (Size: 3.8 KB / Downloads: 3)
Logic is the beginning of wisdom.
Reply
#2
(11-16-2024, 04:32 AM)johnno56 Wrote: Here is a blast from the past (2017)  Almost seasonal... how coincidental... lol

I am waiting for the N7 version, too  Big Grin
Reply
#3
(11-16-2024, 04:58 AM)1micha.elok Wrote:
(11-16-2024, 04:32 AM)johnno56 Wrote: Here is a blast from the past (2017)  Almost seasonal... how coincidental... lol

I am waiting for the N7 version, too  Big Grin


Here you go, a quick conversion (but ... didn't someone already port this?):

Code:
' ==============================================================================
' Santa, by Marcus 2017.
'
' Santa sprite by gamesbyangelina, mike@gamesbyangelina.org, found at
' opengameart.org
' ==============================================================================


' Import libraries.
'import "Speed.lib"
'import "Keycodes.lib"

' Constants.
'constant:
    ' We declare out image identifiers as constants for clarity.
'    IMG_SANTA 0
'    IMG_SNOWFLAKE 1
'    IMG_PRESENT 2
'    IMG_GROUND 3

    ' Max live fallers (snowflakes and presents).
'    MAX_FALLERS 64

    ' Max live snow particles.
'    MAX_SNOW 128
constant MAX_FALLERS = 64, MAX_SNOW = 128

'hidden:

' Set up window and turn off automatic redraw.
'set window 64, 64, 160, 120, false, 4
set window "Santa's Crush", 160, 120, false, 4
set redraw off

' Load images.
'load image IMG_SANTA, "assets/santa.png"
'set image grid IMG_SANTA, 8, 2
'load image IMG_SNOWFLAKE, "assets/snowflake.png"
'load image IMG_PRESENT, "assets/present.png"
'load image IMG_GROUND, "assets/ground.png"
santaImage = loadimage("assets/santa.png", 8, 2)
snowflakeImage = loadimage("assets/snowflake.png")
presentImage = loadimage("assets/present.png")
groundImage = loadimage("assets/ground.png")

' Santa's variables.
santaX = (width(primary) - width(santaImage))/2
santaY = height(primary) - height(groundImage) - height(santaImage)
santaBaseFrame = 0
santaFrame = 0
santaFrameTimer = 0

' Falling things.
'fallers?[MAX_FALLERS]
'for i = 0 to MAX_FALLERS - 1
    ' Set the img field to 0, indicating that it's not a live faller.
'    fallers[i].img = 0
'next
fallers = fill([img: 0], MAX_FALLERS)

fallTimer = 60*2
fallDelay = 60*2
fallDelayTimer = 0

' Falling snow, just a visual effect.
'snow?[MAX_SNOW]
'for i = 0 to MAX_SNOW - 1
'    snow[i].x = rnd(width(primary))
'    snow[i].y = rnd(height(primary))
'    snow[i].spd = 1 + rnd(2)
'    snow[i].a# = float(rnd(360))
'next
snow = dim(MAX_SNOW)
for i = 0 to MAX_SNOW - 1
    snow[i] = [x: rnd(width(primary)), y: rnd(height(primary)), spd: 1 + rnd(2), a: rnd(360)]
next

' Game.
score = 0
gameOver = false


' Game loop.
do
    ' Update game logic --------------------------------------------------------

    ' Santa.

    ' Walk left?
    if keydown(KEY_LEFT)
        ' Let santaFrame cycle in the range [0..4] if santaFrameTimer = 0.
        if santaFrameTimer = 0 then santaFrame = (santaFrame + 1)%5
        ' Move left, stop at screen edge.
        santaX = max(santaX - 1, 0)
        ' Set base frame to 8. That's the first cell in the sprite sheet where
        ' Santa's turned right.
        santaBaseFrame = 8
    ' Walk right?
    elseif keydown(KEY_RIGHT)
        ' Let santaFrame cycle in the range [0..4] if santaFrameTimer = 0.
        if santaFrameTimer = 0 then santaFrame = (santaFrame + 1)%5
        ' Move right, stop at screen edge.
        santaX = min(santaX + 1, width(primary) - width(santaImage))
        ' Set base frame to 0. That's the first cell in the sprite sheet where
        ' Santa's turned left.
        santaBaseFrame = 0
    ' Not moving.
    else
        ' Set santaFrame to 0.
        santaFrame = 0
    endif

    ' Let santaFrameTimer cycle in the range [0..3].
    santaFrameTimer = (santaFrameTimer + 1)%4


    ' Fallers.

    ' Time for a new faller?
    fallTimer = fallTimer - 1
    if fallTimer <= 0
        ' Set time until next faller.
        fallTimer = fallDelay + rnd(30)
       
        ' Find an unused object in the faller array.
        for i = 0 to MAX_FALLERS - 1
            if fallers[i].img = 0 then break
        next
        ' Did we find one?
        if i < MAX_FALLERS
            ' One out of 3 fallers should be a present.
            if rnd(3) = 0
                fallers[i].img = presentImage
            else
                fallers[i].img = snowflakeImage
            endif
            ' Position.
            fallers[i].x = rnd(width(primary) - width(fallers[i].img))
            fallers[i].y = -height(fallers[i].img)
            ' Speed.
            if fallDelay < 10
                fallers[i].spd = 1 + rnd(2)
            else
                fallers[i].spd = 1
            endif
        endif
    endif

    ' Decrease the delay between fallers once every second second, making the
    ' game go harder and harder.
    fallDelayTimer = (fallDelayTimer + 1)%120
    if fallDelayTimer = 0
        fallDelay = max(fallDelay - 3, 0)
    endif

    ' Update active fallers.
    for i = 0 to MAX_FALLERS - 1
        if fallers[i].img > 0
            ' Move down.
            fallers[i].y = fallers[i].y + fallers[i].spd

            ' Out of screen?
            if fallers[i].y > height(primary)
                ' Remove by setting the img field to 0.
                fallers[i].img = 0
            ' Collision with player?
            else
                if ImageCol(santaImage, santaX, santaY, fallers[i].img, fallers[i].x, fallers[i].y)
                    ' Present?
                    if fallers[i].img = presentImage
                        fallers[i].img = 0
                        score = score + 10
                    ' Snowflake.
                    else
                        gameOver = true
                    endif
                endif
            endif
        endif
    next

    ' Update falling snow.
    for i = 0 to MAX_SNOW - 1
        snow[i].y = snow[i].y + snow[i].spd
        'snow[i].a = snow[i].a + 2.0
        'if snow[i].a > 360.0 then snow[i].a = snow[i].a - 360.0
        snow[i].a = (snow[i].a + 2)%360
        if snow[i].y > height(primary)
            snow[i].y = 0
            snow[i].x = rnd(width(primary))
        endif
    next


    ' Draw ---------------------------------------------------------------------

    ' Make the background blue.
    set color 64, 64, 128
    cls

    set color 255, 255, 255
   
    ' Draw Santa.
    draw image santaImage, santaX, santaY, santaBaseFrame + santaFrame

    ' Draw fallers.
    for i = 0 to MAX_FALLERS - 1
        if fallers[i].img > 0
            draw image fallers[i].img, fallers[i].x, fallers[i].y
        endif
    next

    ' Draw falling snow.
    for i = 0 to MAX_SNOW - 1
        draw pixel snow[i].x + int(sin(rad(snow[i].a))*8.0), snow[i].y
    next

    ' Draw ground.
    set color 255, 255, 255
    draw image groundImage, 0, height(primary) - height(groundImage)

    ' Write score.
    set caret width(primary)/2, 2
    center "SCORE"
    center score

    ' Copy backbuffer to the window.
    redraw
    ' Lock FPS at 60.
    '_SPD_HoldFrame 60
    fwait 60

until gameOver or keydown(KEY_ESCAPE, true)

' Game over?
if gameOver
    set color 0, 0, 0, 128
    cls
    set caret width(primary)/2, (height(primary) - fheight(0))/2
    set color 255, 0, 0
    center "GAME OVER!"
    redraw
    wait 2000
endif


' ==============================================================================
' Return true if the images intersect.
' ==============================================================================
function ImageCol(img1, x1, y1, img2, x2, y2)
    if x1 > x2 + width(img2) or x1 + width(img1) < x2 then return false
    if y1 > y2 + height(img2) or y1 + height(img1) < y2 then return false
    return true
endfunc

But it's time to write a new Christmas game, isn't it? Should it be a platformer, a puzzle game or a  first person shooter this year?
Reply
#4
(11-17-2024, 06:45 AM)Marcus Wrote: ...
But it's time to write a new Christmas game, isn't it? Should it be a platformer, a puzzle game or a  first person shooter this year?

I may request a N7 game for this Chiristmas, is it really ?
I wish I could have a kind of 
1. Karateka (1980s, created by Jordan Mechner)
2. Street Fighter

Thank you in advance !

Big Grin Big Grin Big Grin
Reply
#5
(11-17-2024, 09:28 AM)1micha.elok Wrote:
(11-17-2024, 06:45 AM)Marcus Wrote: ...
But it's time to write a new Christmas game, isn't it? Should it be a platformer, a puzzle game or a  first person shooter this year?

I may request a N7 game for this Chiristmas, is it really ?
I wish I could have a kind of 
1. Karateka (1980s, created by Jordan Mechner)
2. Street Fighter

Thank you in advance !

Big Grin Big Grin Big Grin

I think I played a version of Karateka on NES. I had a cartridge with 31 games (pirate stuff) and Karateka was one of them.

If I had to make a fighting game, I think I'd prefer something like double dragon, streets of rage or golden axe Smile
Reply
#6
why not comedy game...
Reply
#7
(11-17-2024, 04:13 PM)aurel Wrote: why not comedy game...

You mean like Monkey Island or Larry? Those were awesome? Smile
Reply
#8
Guybrush Threepwood rules!
Logic is the beginning of wisdom.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)