2d First Person Shooting Gallery

You can post your code snippets here for others to use and learn from
Post Reply
oceanarts
Posts: 58
Joined: Mon May 27, 2024 10:42 pm

2d First Person Shooting Gallery

Post by oceanarts »

A starting point for a 2d First-Person Shooter type game.

Code: Select all

@VERSION 10,0
@APPTITLE "First-Person Shooting Gallery Template"
@APPVERSION "$VER: FPS-Gallery v0.1"
@APPAUTHOR "OceanArts"
@APPCOPYRIGHT "CC0 - Creative Commons."
@APPDESCRIPTION "A starting point for a 2d first-person shooter type game.'"


@DISPLAY{WIDTH = 960, HEIGHT = 540, MODE = "FULLSCREEN", TITLE = "FPS-Gallery", COLOR = #BLACK}


; PRE-LOAD RESOURCES:

@BRUSH 1, "reticle.png", {LoadAlpha = True}
CreatePointer(1, #BRUSH, 1, 32, 22)

@BRUSH 2, "fps_hand.png", {LoadAlpha = True}
@BRUSH 3, "bkg_icftd.png"

@SAMPLE 1, "Slam.wav"
@SAMPLE 2, "EmptyMag.iff"
@SAMPLE 3, "GunReload.iff"

; SET SOME VARIABLES:

_is_firing = False
_bullets = 10

; FUNCTIONS:

Function p_MoveMouse()

    If hand_x < 0 Then hand_x = 0
    If hand_x > 960 Then hand_x = 960  
    
    DisplayBrush(2, hand_x - 80, 400)

        ; Handle mouse pointer if it moves outside window in windowed mode:
        if MouseX() < 0 Then MovePointer(MouseX() + 8, MouseY())
        if MouseX() > 960 Then MovePointer(MouseX() - 8, MouseY())
        if MouseY() > 540 Then MovePointer(MouseX(), MouseY() - 8)
        if MouseY() < 0 Then MovePointer(MouseX(), MouseY() + 8)
        hand_x = MouseX()

EndFunction


Function p_Shoot()

    _is_firing = True

    If _is_firing = True and _bullets > 0
        ?PlaySample(1, {Volume = 18})
        _bullets = _bullets - 1
    Else
        ?PlaySample(2, {Volume = 10})
    EndIf

EndFunction

Function p_StopShoot()
    _is_firing = False
EndFunction

Function p_Reload()
    ?PlaySample(3, {Volume = 18})
    _bullets = 10
EndFunction


Function p_HandlerFunc(msg)
    Switch(msg.action)
        Case "OnMouseMove":
            p_MoveMouse()
        Case "OnMouseDown":
           p_Shoot()
        Case "OnMouseUp":
            p_StopShoot()
        Case "OnRightMouseDown":
            p_Reload()
    EndSwitch
EndFunction

BeginDoubleBuffer()
EscapeQuit(True)

InstallEventHandler({OnMouseMove = p_MoveMouse, OnMouseDown = p_HandlerFunc, OnMouseUp = p_HandlerFunc, OnRightMouseDown = p_HandlerFunc})

; SOME INITIAL SET-UP:

SetFont(#SANS, 64)
SetPointer(1)
MovePointer(#CENTER, #CENTER)

; MAIN LOOP

Repeat
    
    Cls()
    If _bullets < 6 Then SetFontColor(#RED)
    If _bullets > 6 Then SetFontColor(#LIME)
    DisplayBrush(3, 0, 0)
    Locate(8,8)
    Print(_bullets)
    p_MoveMouse()
    Flip()
    WaitEvent

Forever

    EndDoubleBuffer()
Probably not the best way to do things, and lots of things to add and improve.... Like things to actually shoot. :lol:

Video Preview Here: https://odysee.com/@oceancrafts:e/Holly ... SL9Mdxf65i
plouf
Posts: 581
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: 2d First Person Shooting Gallery

Post by plouf »

Intresting good old school!

Waiting for the final game !!
Welldone
Christos
User avatar
Juan Carlos
Posts: 920
Joined: Mon Sep 06, 2010 1:02 pm

Re: 2d First Person Shooting Gallery

Post by Juan Carlos »

Interesting result, I tryed to make a similar game with terminators in a farmer, but in my case the result was very poor and bad, at least your game looks a game, the mine looks some cutre and ridiculous.
oceanarts
Posts: 58
Joined: Mon May 27, 2024 10:42 pm

Re: 2d First Person Shooting Gallery

Post by oceanarts »

Thanks, guys. Much appreciated. :)

This isn't much of anything, yet... Placeholder graphics and absent gameplay. Hoping it will evolve into something someday.
But it's surprising how fast one can get fairly decent results in Hollywood.
Post Reply