Posts: 731
Threads: 76
Joined: Nov 2023
Reputation:
7
I have been testing AI just to see how "clever" it is in creating games.
This is my first attempt at an AI created Space Invaders.
Notes: Even though I specified Naalaa as the base code, there were several "generalised" commands produced, that needed to be changed to N7. The game is FAR from complete... When using AI, you have to be specific in what you need, not just "create space invaders". The more info you give to the AI the better the results.
This attempt has multiple rows of animated invaders; A scoring system (plus hiscore - no saving); Level system (speed increases after each level). No sound (sound files included); No shields; No Super Invader. This is bare-bones.
Over all, it took maybe an hour or so to complete the game. In this instance, AI, has done fine job. Learning to be specific with AI was interesting... I might try some other types of "simple" 2D games... But, I do not think I will rely on AI to create 'all' my games... After all, I would like to eventually learn something... lol
Let me know what you think about AI and its usefulness in regards to N7?
invaders.zip (Size: 142.98 KB / Downloads: 7)
Logic is the beginning of wisdom.
Posts: 438
Threads: 58
Joined: Nov 2023
Reputation:
3
In my opinion, AI is a great tool to help us develop ideas and move things forward. But like you said, we can’t rely on AI alone to build a complete game. Human creativity and judgment are still essential to refine, reshape, and bring everything together into something truly great. The effort you put into showcasing both the AI and your own creativity in just one hour .... it’s super impressive !
Posts: 731
Threads: 76
Joined: Nov 2023
Reputation:
7
"own creativity"? I hardly think so... All I did was to replace a few commands that N7 could recognise. The logic, layout and functions were "created" by the AI. At the moment, I find AI an interesting concept, worthy of research.
Based on what I have seen, when Basic was the 'new kid on the block', up to now when AI can create the programs for us... Yes. I agree. That is super impressive... but I have concerns about this new 'tool'.... Moo Ha Ha Ha....
Logic is the beginning of wisdom.
Posts: 675
Threads: 85
Joined: Nov 2023
Reputation:
7
Okay, I saw this post and had to take a 10 minute break from work to test it.
I am really impressed by this! I certainly see that it can be of help for new beginners. Even more experienced coders could start off with some ai generated code and turn it into something better. I quickly made it more n7ish by getting rid of the separate arrays for all pieces of data for the invaders.
Please do more experiments like this!
Code: set window "Space Invaders", 320, 240, false, 3
set redraw off
randomize clock()
visible MAX_INV, INV_W, INV_H, INV_IMG
MAX_INV = 40
INV_W = 11
INV_H = 8
' Marcus: Fill array inv with tables containing x, y and alive fields.
visible inv = fill([x: 0, y: 0, alive: false], MAX_INV)
visible bg
visible playerX
visible bulletX
visible bulletY
visible bulletAlive
visible score
visible hiscore
visible level
visible invSpeed
visible frameCount
visible shotCount
visible average
visible cellCount
visible cellTimer
shotCount = 0
average = 0
frameCount = 0
hiscore = 0
cellCount = 0
cellTimer = 0
visible black = [0, 0, 16]
visible white = [255, 255, 255]
visible red = [255, 0, 0]
visible green = [0, 255, 0]
visible cyan = [0, 255, 255]
visible yellow = [255, 255, 0]
visible orange = [255, 128, 0]
fnt = createfont("arial", 12)
set font fnt
bg = loadimage("assets/background.png")
player = loadimage("assets/player.png")
invader1 = loadimage("assets/alien1.png", 2, 1)
invader2 = loadimage("assets/alien2.png", 2, 1)
invader3 = loadimage("assets/alien3.png", 2, 1)
explode = loadimage("explode.png")
bullet = loadimage("assets/bullet.png")
dead = loadsound("assets/dead.wav")
laser = loadsound("assets/laser.wav")
InitGame()
do
set color black
cls
set color white
draw image bg, 0, 0
' ====================
' UPDATE STUFF
' --------------------
' Move Player
if keydown(KEY_LEFT) and playerX > 1 playerX = playerX - 3
if keydown(KEY_RIGHT) and playerX < width(primary) - 17 playerX = playerX + 3
' Fire Bullet
if keydown(KEY_SPACE) and bulletAlive = false
play sound laser
shotCount = shotCount + 1
bulletX = playerX + 6
bulletY = 230
bulletAlive = true
endif
' Update Bullet
if bulletAlive
bulletY = bulletY - 6
if bulletY < -7 bulletAlive = false
endif
' Move Invaders
frameCount = frameCount + 1
if frameCount % (15 - level) = 0
for i = 0 to MAX_INV - 1
if inv[i].alive inv[i].x = inv[i].x + invSpeed
next
' Bounce invaders off screen edge
for i = 0 to MAX_INV - 1
if inv[i].alive and (inv[i].x > 300 or inv[i].x < 10)
invSpeed = invSpeed * -1
for j = 0 to MAX_INV - 1
if inv[j].alive inv[j].y = inv[j].y + 5
if inv[j].y > 230
invaded()
end
endif
next
break
endif
next
endif
' Collision Detection
' Marcus: ok, this piece code was kind of ineffective :)
'for i = 0 to MAX_INV - 1
' if invAlive[i] and bulletAlive
' if bulletX > invX[i] and bulletX < invX[i] + INV_W and bulletY > invY[i] and bulletY < invY[i] + INV_H
' play sound dead
' invAlive[i] = false
' bulletAlive = false
' score = score + 10
' if score > hiscore hiscore = score
' endif
' endif
'next
if bulletAlive
for i = 0 to MAX_INV - 1
if inv[i].alive
if bulletX > inv[i].x and bulletX < inv[i].x + INV_W and bulletY > inv[i].y and bulletY < inv[i].y + INV_H
play sound dead
inv[i].alive = false
bulletAlive = false
score = score + 10
if score > hiscore hiscore = score
break
endif
endif
next
endif
' Level Up
allDead = true
for i = 0 to MAX_INV - 1
if inv[i].alive
allDead = false
break
endif
next
if allDead = true
average = int(100 * (40 / shotCount))
results()
shotCount = 0
average = 0
level = level + 1
if invSpeed < 0 invSpeed = invSpeed - 1
if invSpeed = 0 invSpeed = 0
if invSpeed > 0 invSpeed = invSpeed + 1
InitInvaders()
endif
' =====================
' DISPLAY STUFF
' ---------------------
set color white
' Draw Player
draw image player, playerX, 230
' Draw Bullet
if bulletAlive draw image bullet, bulletX, bulletY
' Draw Invaders
cellTimer = cellTimer + 1
if cellTimer > 30
cellCount = cellCount + 1
if cellCount > 1 cellCount = 0
cellTimer = 0
endif
for i = 0 to MAX_INV - 1
if inv[i].alive
if i >= 0 and i < 20 INV_IMG = invader1
if i >= 20 and i < 30 INV_IMG = invader2
if i >= 30 INV_IMG = invader3
draw image INV_IMG, inv[i].x, inv[i].y, cellCount
endif
next
' Heads Up Display (HUD)
set color white
set caret 5, 5; wln "Score:"
set caret 135, 5; wln "Level:"
set caret 235, 5; wln "HiScore:"
set color cyan
set caret 45, 5; wln str(score)
set caret 172, 5; wln str(level)
set color yellow
set caret 282, 5; wln str(hiscore)
redraw
fwait 60
until keydown(KEY_ESCAPE, true)
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function InitInvaders()
for i = 0 to MAX_INV - 1
inv[i].x = 20 + (i % 10) * 30
inv[i].y = 25 + int(i / 10) * 20
inv[i].alive = true
next
endfunc
function InitGame()
playerX = 166
bulletAlive = false
score = 0
level = 1
invSpeed = 1
InitInvaders()
endfunc
function results()
wait 500
set color black
cls
set color white
draw image bg, 0, 0
set color cyan
set caret 160, 50
center "SHOTS FIRED"
set color green
set caret 160, 70
center str(shotCount)
set color cyan
set caret 160, 90
center "ACCURACY"
set color yellow
set caret 160, 110
center str(average)
redraw
wait 4000
endfunc
function invaded()
wait 500
set color black
cls
set color white
draw image bg, 0, 0
set color cyan
set caret 160, 50
center "YOU HAVE BEEN INVADED!!"
set color green
set caret 160, 70
center "BETTER LUCK NEXT TIME!"
redraw
wait 4000
endfunc
Posts: 193
Threads: 14
Joined: Dec 2023
Reputation:
8
This is indeed impressive. I must admit that I have never knowingly used AI except when doing google searches - perhaps I need to check it out too.....
Posts: 675
Threads: 85
Joined: Nov 2023
Reputation:
7
(07-10-2025, 03:32 PM)kevin Wrote: This is indeed impressive. I must admit that I have never knowingly used AI except when doing google searches - perhaps I need to check it out too.....
I don't mind using AI for music and graphics, because having to create those things myself can really make me give up on game projects. On the other hand, when I'm happy with a game like RW3 I might replace all textures with handmade stuff.
I enjoy coding too much to let an AI do it for me. But I'm still impressed and want to see more of it!
Posts: 731
Threads: 76
Joined: Nov 2023
Reputation:
7
Marcus,
I see what you mean by "ineffective" and then incorporating the collision detection with the 'bullet'... cool...
I really need to understand arrays / tables better. I have been using arrays since Moses was a boy and might, just might, be a little set in my ways... lol The "array[].field" thing confuses me to no end. When to use an array or a table? Is there a difference? If there is a difference, how do they differ?
Hmm... "More experiments" you say? Funny that you should ask. I have attempted several games (using several languages - N7, RCBasic and QB64) such as Dino Runner, Asteroids, Breakout, Mario, Checkers with varying degrees of failure... lol The failure stems from my lack of being clear enough with articulating the necessary requirements for each game. Hence, the need for keeping the games "simple"... lol It took several attempts to get "invaders" to where it is today. I suppose it will be just a matter of time...
I will revisit Dino... I have my doubts... lol
Before I forget, thank you for the game mods...
Logic is the beginning of wisdom.
Posts: 675
Threads: 85
Joined: Nov 2023
Reputation:
7
07-10-2025, 08:59 PM
(This post was last modified: 07-10-2025, 09:05 PM by Marcus.)
(07-10-2025, 08:12 PM)johnno56 Wrote: I really need to understand arrays / tables better. I have been using arrays since Moses was a boy and might, just might, be a little set in my ways... lol The "array[].field" thing confuses me to no end. When to use an array or a table? Is there a difference? If there is a difference, how do they differ?
Maybe the word "associative array" is better than "table"? You can simply use strings as "indexes" (keys) in arrays. And array.x is just a prettier way of writing array["x"]. I use string keys when you'd use "structs" or "records" in other languages.
In the space invader game the inv array is a two dimensional array where the inner arrays use the string keys x, y and alive. You could also have used numerical indexes for the inner arrays: inv[i][0] instead of inv[i].x, inv[i][1] instead of inv[i].y ...
|