Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Start of a silly Galaga style game
#5
(11-07-2024, 05:38 PM)Marcus Wrote: ...in the style of galaga...

I'm still trying to understand the 'Galaga'  Big Grin ... so I reused most of your codes to make a new game.
But I can't find a way to achieve what I want.
Could you please advice me ? 

               
click each image to zoom in

1. Picture #1 : the start of the game
2. Picture #2 : what I've achived, but it doesn't go with my plan
3. Picture #3 : This is what I want. How to achieve this ?

Code:
'=====================================================
' ALIENS TOOK MY COWS
'  Aliens are coming...
'  They are abducting your cows.
'  Now, they challenge you,everytime they tell you ...
'  a number of alien's spaceship, find out its
'  coordinate and they'll return your cow one by one
'  ... Good luck !
'
' REFERENCES
' - Some codes of the Attackers,Galaga Style by Marcus
' - Cow, author:reivaxcorp
'   https://opengameart.org/content/cow-run-cycle
'
'=====================================================

'-----------------
' INITIALIZATION
'-----------------
set window "Aliens Took My Cows", 500, 224, false, 2
set redraw off

'color definition
black  = [0,0,0]
white  = [255,255,255]
red    = [255,0,0]
yellow = [255,254,0]
green  = [0,200,0]

'constants
constant ECOLS =10, EROWS = 5

'variables
visible enm1Img
divet = 120
divetalien = ECOLS*EROWS
tmp = []
offsx = 25 ; offsy = 40
whichx = 0 ; whichy = 0

'enemies class
CreateAssets()
randomize time()
enms = dim(ECOLS, EROWS)
for y = 0 to EROWS-1  for x = 0 to ECOLS-1
    e = [
        img: enm1Img,            'image   
        a: 0,                    'angle
        pos: Point(0, 0),        'position   
        c: fill(Point(0, 0), 4), 'curve
        p: unset,                'parameter
        mark:"yellow"            'green = right answer, red = wrong answer
        ]
    enms[x][y] = e
next

'info box
info = []
info.x = 0
info.y = 0
info.number = 0
info.guessx = 0
info.guessy = 0
info.posx = 0
info.posy = 0
info.start = true

'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
   
    'divet animation #1
    divet = divet - divetalien
    if divet <= 0
        clear tmp
        for y = 0 to EROWS - 1  for x = 0 to ECOLS - 1
            if enms[x][y] and enms[x][y].p = unset 
                if info.start = true then
                    tmp[sizeof(tmp)] = enms[x][y]
                else
                    tmp[sizeof(tmp)]=enms[info.posx][info.posy]
                    divetalien = 1
                endif
            endif
        next
        if sizeof(tmp)
            e = tmp[rnd(sizeof(tmp))]
            e.p = 0
            e.c[0].x = e.pos.x; e.c[0].y = e.pos.y
            e.c[1].x = rnd(242) ; e.c[1].y = 400
            divet = 120 + rnd(3)*60
            whichx = (e.pos.x - offsx) / 16
            whichy = (e.pos.y - offsy) / 16
        endif
    endif
   
    'divet animation #2
    for y = 0 to EROWS - 1
        for x = 0 to ECOLS - 1
            e = enms[x][y]
            if e
                gx = x*16 + offsx ; gy = y*16 + offsy
                if typeof(e.p)
                    e.p = e.p + 0.005
                    if e.p >= 1
                        e.p = unset
                        e.pos.x = gx; e.pos.y = gy
                    else
                        e.c[3].x = gx; e.c[3].y = gy
                        EvalCBC(e.pos, e.c, e.p)
                    endif
                else
                    e.pos.x = gx
                    e.pos.y = gy
                endif
            endif
        next
    next
   
    'clear screen
    set color black
    cls
   
    'reference numbers on columns and rows
    set color white
    for i = 0 to ECOLS-1
        set caret 27+16*i,20 ; write i
    next
    for i = 0 to EROWS-1
        set caret 10,41+16*i ; write i
    next
   
    'draw enemies
    set color white
    for y = 0 to EROWS - 1  for x = 0 to ECOLS - 1
        e = enms[x][y]
        e.row = y
        e.col = x
        if e.mark="green" then
            set color green
        else if e.mark = "red" then
            set color red   
        else
            set color yellow
        endif
        draw image e.img, e.pos.x, e.pos.y
    next

    'infobox on start
    if info.start = true then
        set color white
        set caret 220,20
        wln "Aliens are coming..."
        wln "They are abducting your cows."
        wln "Now, they challenge you,"
        wln "everytime they tell you ..."
        wln "a number of alien's spaceship,"
        wln "find out its coordinate and"
        wln "they'll return your cow"
        wln "one by one... Good luck !"
        wln
        wln "Press ENTER to continue"
    endif
    wln

    'infobox on game play
    if keydown(KEY_RETURN,true) or info.start=false then
        info.start = false
             
        'clear info box       
        set color black; draw rect 220,20,width()-220,height()-20,true
        set color white

        'guess coordinate
        set caret 220,20; write "Enemy number : "; info.number=rnd(1,50);write info.number
        set caret 220,40; write "Enemy["+info.number+"].x = "; info.guessx = rln(1,TYPE_NUMBER)
        set caret 220,60; write "Enemy["+info.number+"].y = "; info.guessy = rln(1,TYPE_NUMBER)

        'calculate the real coordinate       
        if info.number%10 > 0 then   
            info.posx = info.number%10-1; info.posy = floor(info.number/10)
        else
            info.posx = 9; info.posy = floor(info.number/10)-1       
        endif

        'mark green if guess coordinate is true       
        if info.posx = info.guessx and info.posy = info.guessy then
            info.coor = "("+info.posx+","+info.posy+")"
            e=enms[info.posx][info.posy]
            e.mark = "green"
        else
            info.coor = "Try Again"
            e=enms[info.posx][info.posy]
            e.mark = "red"
        endif
       
        'display info.coor                                         
        set caret 220,80; wln "Coordinate   : "+info.coor
        wln
        wln "Press ENTER to continue"
        temp = rln()
    endif
                       
    redraw
    fwait 60
wend


'------------
' FUNCTIONS
'------------
function Point(x, y)
    return [x: x, y: y]
endfunc

function EvalCBC(dst, curve, param)
    b0 = (1 - param)^3
    b1 = 3*(1 - param)^2*param
    b2 = 3*(1 - param)*param^2
    b3 = param^3
    dst.x = b0*curve[0].x + b1*curve[1].x + b2*curve[2].x + b3*curve[3].x
    dst.y = b0*curve[0].y + b1*curve[1].y + b2*curve[2].y + b3*curve[3].y
endfunc

function CreateAssets()
    bitdata =[[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
              [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
              [0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0],
              [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1],
              [1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1],
              [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1],
              [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
              [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
              [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
              [0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0],
              [0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0],
              [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0]]
    enm1Img = CreateBitmap(bitdata,255, 224, 0)
endfunc

function CreateBitmap(data, r, g, b)
    img = createimage(sizeof(data[0]), sizeof(data))
    set image img
    for y = 0 to sizeof(data) - 1  for x = 0 to sizeof(data[0]) - 1
        set color data[y][x]*r, data[y][x]*g, data[y][x]*b
        set pixel x, y
    next
    set image primary
    set image colorkey img, 0, 0, 0
    return img
endfunc


Thank you.
Reply


Messages In This Thread
Start of a silly Galaga style game - by Marcus - 11-07-2024, 05:38 PM
RE: Start of a silly Galaga style game - by aurel - 11-07-2024, 05:49 PM
RE: Start of a silly Galaga style game - by 1micha.elok - 12-02-2024, 05:02 AM
RE: Start of a silly Galaga style game - by kevin - 12-02-2024, 10:59 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)