Start of a silly Galaga style game - Marcus - 11-07-2024
I'm on a one hour train trip so I started writing something in the style of galaga. I won't conitnue working on it, but I'm still posting the code.
Code: constant ECOLS = 12, EROWS = 8
visible plyImg, enm1Img, enm2Img, enm3Img, enm4Img
set window "Attackers", 256, 224, false, 3
set redraw off
CreateAssets()
randomize 2
enms = dim(ECOLS, EROWS)
for y = 1 to 5 for x = 0 to ECOLS/2 - 1
if rnd(4) > 0
select rnd(4)
case 0
img = enm1Img
stm = 1
case 1
img = enm2Img
stm = 2
case 2
img = enm3Img
stm = 3
default
img = enm4Img
stm = 4
endsel
e = [
img: img,
a: 0,
stm: stm,
pos: Point(0, 0),
size: Point(14, 14),
c: fill(Point(0, 0), 4),
p: unset]
else
e = unset
endif
enms[x][y] = e
enms[ECOLS - 1 - x][y] = copy(e)
next
enmsa = 0
divet = 120
tmp = []
enmbullets = []
enmshoott = 180
ply = []
ply.pos = Point(120, 200)
ply.size = Point(16, 16)
ply.spd = 1
plybullets = []
while not keydown(KEY_ESCAPE, true)
i = 0
while i < sizeof(plybullets)
b = plybullets[i]
b.pos.x = b.pos.x + b.spd.x
b.pos.y = b.pos.y + b.spd.y
if b.pos.x < -b.size.x or b.pos.x >= 256 or b.pos.y < -b.size.y or b.pos.y >= 224
free key plybullets, i
else
hit = false
for y = EROWS - 1 to 0
for x = 0 to ECOLS - 1
e = enms[x][y]
if e and Collides(b, e)
e.stm = e.stm - 1
if e.stm <= 0 enms[x][y] = unset
hit = true
break
endif
next
if hit break
next
if hit free key plybullets, i
else i = i + 1
endif
wend
i = 0
while i < sizeof(enmbullets)
b = enmbullets[i]
b.pos.x = b.pos.x + b.spd.x
b.pos.y = b.pos.y + b.spd.y
if b.pos.x < -b.size.x or b.pos.x >= 256 or b.pos.y < -b.size.y or b.pos.y >= 224
free key enmbullets, i
else
i = i + 1
endif
wend
if keydown(KEY_LEFT) ply.pos.x = max(ply.pos.x - ply.spd, 0)
if keydown(KEY_RIGHT) ply.pos.x = min(ply.pos.x + ply.spd, 240)
if keydown(KEY_SPACE, true)
plybullets[sizeof(plybullets)] = [
pos: Point(ply.pos.x + ply.size.x/2 - 1, ply.pos.y - 4),
size: Point(2, 4),
spd: Point(0, -4)]
endif
divet = divet - 1
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 tmp[sizeof(tmp)] = enms[x][y]
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 = 224
e.c[2].x = rnd(242); e.c[2].y = 224
e.c[3].x = e.pos.x; e.c[3].y = e.pos.y
divet = 120 + rnd(3)*60
else
divet = 60
endif
endif
enmshoott = enmshoott - 1
if enmshoott < 0
enmshoott = 180 + rnd(3)*60
clear tmp
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
if enms[x][y] for i = 0 to enms[x][y].p <> unset tmp[sizeof(tmp)] = enms[x][y]
next
if sizeof(tmp)
e = tmp[rnd(sizeof(tmp))]
dx = ply.pos.x - e.pos.x
dy = ply.pos.y - e.pos.y
k = sqr(dx*dx + dy*dy)
if k > 0
dx = 2*dx/k
dy = 2*dy/k
enmbullets[sizeof(enmbullets)] = [
pos: Point(e.pos.x + e.size.x/2 - 2, e.pos.y + e.size.y/2 - 2),
size: Point(4, 4),
spd: Point(dx, dy)]
endif
endif
endif
enmsa = (enmsa + 1)%360
for y = 0 to EROWS - 1
offsx = 128 - ECOLS*8 + sin(rad(enmsa + y*22.5))*24
offsy = 24
for x = 0 to ECOLS - 1
e = enms[x][y]
if e
gx = x*16 + offsx + 1; gy = y*16 + offsy + 1
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
EvalCBCD(e.pos, e.c, e.p)
e.a = atan2(e.pos.y, e.pos.x) - 0.5*PI
if e.p < 0.2 e.a = e.a*5*e.p
elseif e.p >= 0.8 e.a = e.a*(1 - e.p)/0.2
EvalCBC(e.pos, e.c, e.p)
endif
else
e.pos.x = gx
e.pos.y = gy
endif
endif
next
next
set color 0, 0, 0
cls
set color 255, 255, 255
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
e = enms[x][y]
if e and e.p = unset draw image e.img, e.pos.x, e.pos.y
next
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
e = enms[x][y]
if e and typeof(e.p)
draw image xform e.img, e.pos.x + 7, e.pos.y + 7, 1, 1, e.a, 7, 7
endif
next
draw image plyImg, ply.pos.x, ply.pos.y
set color 255, 255, 255
foreach b in plybullets draw rect b.pos.x, b.pos.y, b.size.x, b.size.y, true
set color 0, 255, 255
foreach b in enmbullets draw rect b.pos.x, b.pos.y, b.size.x, b.size.y, true
set color 255, 255, 255
set caret 0, 0
wln sizeof(plybullets)
wln sizeof(enmbullets)
redraw
fwait 60
wend
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 EvalCBCD(dst, curve, param)
b0 = 3*(1 - param)^2
b1 = 6*(1 - param)*param
b2 = 3*param^2
dst.x = b0*(curve[1].x - curve[0].x) + b1*(curve[2].x - curve[1].x) + b2*(curve[3].x - curve[2].x)
dst.y = b0*(curve[1].y - curve[0].y) + b1*(curve[2].y - curve[1].y) + b2*(curve[3].y - curve[2].y)
endfunc
function Collides(a, b)
return a.pos.x + a.size.x > b.pos.x and a.pos.x < b.pos.x + b.size.x and
a.pos.y + a.size.y > b.pos.y and a.pos.y < b.pos.y + b.size.y
endfunc
function CreateAssets()
plyImg = CreateBitmap(
[[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0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, 1, 0, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0],
[1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1],
[1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1],
[0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0]],
128, 0, 255)
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
RE: Start of a silly Galaga style game - aurel - 11-07-2024
Ok Marcus
I download code and put it into N7 editor then i get this error about xForm
Code: draw image xform e.img, e.pos.x + 7, e.pos.y + 7, 1, 1, e.a, 7, 7
and here is how compiler output looks :
Quote:Welcome to the second most primitive IDE thinkable!
Compiled with n7 version 22.07.08b
Saved "D:\ARCHIVE\N7_220708\N7\Galaga.n7"
Saved "D:\ARCHIVE\N7_220708\N7\Galaga.n7"
Compiling
"D:\ARCHIVE\N7_220708\N7\Galaga.n7"
n7: Galaga.n7:186: error: Undeclared identifier 'xform
so why is undeclared ?
do i must download latest version?
RE: Start of a silly Galaga style game - Marcus - 11-07-2024
(11-07-2024, 05:49 PM)aurel Wrote: Ok Marcus
I download code and put it into N7 editor then i get this error about xForm
Code: draw image xform e.img, e.pos.x + 7, e.pos.y + 7, 1, 1, e.a, 7, 7
and here is how compiler output looks :
Quote:Welcome to the second most primitive IDE thinkable!
Compiled with n7 version 22.07.08b
Saved "D:\ARCHIVE\N7_220708\N7\Galaga.n7"
Saved "D:\ARCHIVE\N7_220708\N7\Galaga.n7"
Compiling
"D:\ARCHIVE\N7_220708\N7\Galaga.n7"
n7: Galaga.n7:186: error: Undeclared identifier 'xform
so why is undeclared ?
do i must download latest version?
Yep, 'draw image xform' is pretty new, so you better download the latest version Nice to see you here
RE: Start of a silly Galaga style game - johnno56 - 11-08-2024
I hour train trip? All that in one hour? Aw man... I need to think and type faster... lol
Continue with it or not... it's still pretty cool... Nicely done...
RE: Start of a silly Galaga style game - 1micha.elok - 12-02-2024
(11-07-2024, 05:38 PM)Marcus Wrote: ...in the style of galaga...
I'm still trying to understand the 'Galaga' ... 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.
RE: Start of a silly Galaga style game - kevin - 12-02-2024
Hi, I have not had a chance to look at your code, but I think a similar problem was discussed here:
https://www.naalaa.com/forum/thread-138.html?highlight=Return
Hope this helps.
Apologies if I have misunderstood the problem.
All the best.. Kevin.
RE: Start of a silly Galaga style game - 1micha.elok - 12-02-2024
(12-02-2024, 10:59 AM)kevin Wrote: ...but I think a similar problem was discussed here:
https://www.naalaa.com/forum/thread-138.html?highlight=Return
Thank you for your response, Kevin. I'll learn the code at the provided link above.
Meanwhile, just another simple silly game is in progress ....
Code: '=====================================================
' ALIENS TOOK MY COWS (updated)
' 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 = 12
divetalien = 1
tmp = []
offsx = 25 ; offsy = 40
countred = 0 'count how many wrong answers
countgreen = 0 'count how many right answers
'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
info.theend = false
'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
'divet animation #1
if countred >=3 then divetalien = EROWS*ECOLS
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
tmp[sizeof(tmp)] = enms[x][y]
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
if info.start = true or countred>=3 then
EvalCBC(e.pos, e.c, e.p)
else
e.pos.x = gx; e.pos.y = gy 'return alien to formation
endif
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 and info.theend = false 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 "
redraw
endif
wln
if info.theend = true then
set color white
set caret 220,20
wln "THE END"
wln "Aliens thank you for the cows"
wln "..."
info.start = true
endif
if countgreen >= 10 then
set color white
set caret 220,20
wln
wln "You get back all your cows"
wln "Thank you for playing"
wln "this silly game :)"
temp=rln()
end
endif
'infobox on game play
if (keydown(KEY_RETURN,true) or info.start=false) and info.theend=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"
countgreen = countgreen + 1
else
info.coor = "Try Again"
e=enms[info.posx][info.posy]
e.mark = "red"
countred = countred + 1
endif
if countred >= 3 then
info.theend = true
endif
'display info.coor
set caret 220,80; wln info.coor
wln
wln "Press ESC to continue"
do;redraw; wait 1;until keydown(KEY_ESCAPE,true)
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
RE: Start of a silly Galaga style game - johnno56 - 12-03-2024
Well... I am totally confused... (not 'that' hard to do actually... lol)
Am I supposed to enter the co-ordinate of the alien listed or guess the co-ordinate of the listed alien? If it is "guess" then my chances are quite remote... 3 attempts... Try #1 is 1 in 45, #2 is 1 on 44 and #3 is 1 in 43... which works out to a 1 in 85,140... mind you, it's WAY less than the lottery... lol or am I over-thinking this... lol
RE: Start of a silly Galaga style game - 1micha.elok - 12-03-2024
(12-03-2024, 12:32 AM)johnno56 Wrote: Well... I am totally confused... (not 'that' hard to do actually... lol)
Am I supposed to enter the co-ordinate of the alien listed or guess the co-ordinate of the listed alien? If it is "guess" then my chances are quite remote... 3 attempts... Try #1 is 1 in 45, #2 is 1 on 44 and #3 is 1 in 43... which works out to a 1 in 85,140... mind you, it's WAY less than the lottery... lol or am I over-thinking this... lol
Co-ordinate based game, it isn't good for aliens (Galaga) ... lol .....
I'm thinking to recreate "Whack-a-mole" or you may call it as "Marsupial Mole".... I don't know if it is the same as "Wombat" ?
RE: Start of a silly Galaga style game - johnno56 - 12-03-2024
Wombat sounds good... Whack-a-wombat... Mash-a-marsupial... it's all fun...
|