; Turret Defense Oyunu
; Oyun Başlangıcı
Init:
Cls
Call LoadGraphics
Call LoadMusic
Call LoadSounds
Call ShowLoadingScreen
PlayMusic
score = 0
enemiesDestroyed = 0
enemySpawnTime = 50
enemySpeed = 2
turretX = 320
turretY = 440
enemyCount = 0
bulletCount = 0
maxLives = 3
lives = maxLives
backgroundColor = 0
gameOver = False
GoTo MainLoop
; Grafikleri Yükle
LoadGraphics:
LoadSprite(1, "enemy_sprite.iff") ; Düşman grafiği
LoadSprite(2, "turret_sprite.iff") ; Taret grafiği
LoadSprite(3, "bullet_sprite.iff") ; Mermi grafiği
Return
; Müzik Yükleme
LoadMusic:
LoadMod("background_music.mod") ; Arka plan müziği
Return
; Ses Efekti Yükleme
LoadSounds:
LoadSample(1, "shot_sound.iff") ; Ateş sesi
LoadSample(2, "explosion_sound.iff") ; Patlama sesi
Return
; Yükleme Ekranı
ShowLoadingScreen:
Cls
Print "Loading..."
Wait(100)
Return
; Düşmanı Tanımla
CreateEnemy:
enemyType = Rnd(3) ; 0 = Düşük, 1 = Orta, 2 = Yüksek
enemyX = Rnd(640)
enemyY = 0
enemyList[enemyCount] = enemyX + enemyY * 640 + enemyType * 1000 ; Düşman konumu ve tipini sakla
enemyCount = enemyCount + 1
Return
; Oyun Döngüsü
MainLoop:
Cls
DrawTurret
DrawEnemy
DrawBullet
If gameOver Then
Print "Game Over! Score: " + score
Print "Press Fire to Restart"
If MouseButton(1) Then
GoTo Init
EndIf
Wait(1)
GoTo MainLoop
EndIf
; Ara birimler (input)
If MouseButton(1) Then
Call FireBullet(turretX, turretY)
EndIf
; Düşman yarat
If FrameCount Mod enemySpawnTime = 0 Then
Call CreateEnemy
EndIf
; Düşmanları hareket ettir
Call MoveEnemies
; Düşmanları kontrol et
For i = 0 To enemyCount - 1
enemyPos = enemyList[i]
enemyX = enemyPos Mod 640
enemyY = enemyPos / 640 Mod 1000
enemyType = enemyPos / 1000
; Düşman ekranın dışına çıktı mı?
If enemyY > 480 Then
lives = lives - 1 ; Yaşam kaybet
enemyList[i] = enemyCount * -1 ; Bu düşmanı yok say
If lives <= 0 Then
gameOver = True
EndIf
EndIf
; Puan güncelleme bilgisi
Print "Score: " + score
Print "Enemies Destroyed: " + enemiesDestroyed
Print "Lives: " + lives
; Mermiler ile çarpışma kontrolü
For j = 0 To bulletCount - 1
If Collides(enemyX, enemyY, bulletX[j], bulletY[j]) Then
enemiesDestroyed = enemiesDestroyed + 1
score = score + (enemyType + 1) * 10 ; Düşman türüne göre puan ver
enemyList[i] = enemyCount * -1 ; Düşmanı yok say
bulletY[j] = -1 ; Mermiyi yok say
Call PlayExplosionSound ; Patlama sesi çal
Exit
EndIf
Next j
Next i
If enemiesDestroyed Mod 10 = 0 Then
Call LevelUp ; Seviye artışı
EndIf
Call CleanEnemies ; Temizleme işlemi
Wait(1)
GoTo MainLoop
; Mermi Ateşleme
FireBullet(x, y):
bulletX[bulletCount] = x
bulletY[bulletCount] = y
bulletCount = bulletCount + 1
Call PlayShotSound ; Ateş sesi çal
Return
; Çarpışma Kontrol Fonksiyonu
Collides(enemyX, enemyY, bulletX, bulletY):
If (bulletY > 0) And (bulletX > enemyX - 20) And (bulletX < enemyX + 20) And (bulletY > enemyY - 20) And (bulletY < enemyY + 20) Then
Return True
EndIf
Return False
; Düşmanları Temizle
CleanEnemies:
For i = 0 To enemyCount - 1
If enemyList[i] < 0 Then
enemyList[i] = enemyList[enemyCount - 1]
enemyCount = enemyCount - 1
EndIf
Next i
Return
; Düşmanları Hareket Ettir
MoveEnemies:
For i = 0 To enemyCount - 1
enemyPos = enemyList[i]
enemyX = enemyPos Mod 640
enemyY = enemyPos / 640 Mod 1000
; Rastgele sağa sola hareket
If Rnd(1) > 0.5 Then
enemyX = enemyX + enemySpeed
Else
enemyX = enemyX - enemySpeed
EndIf
; Ekran sınırlarını kontrol et
If enemyX < 0 Then enemyX = 0
If enemyX > 640 Then enemyX = 640
enemyY = enemyY + enemySpeed
enemyList[i] = enemyX + enemyY * 640 + (enemyType * 1000); Yeni konumu güncelle
Next i
Return
; Seviye Geçişi
LevelUp:
enemySpawnTime = Max(10, enemySpawnTime - 5) ; Zamanı azalt
enemySpeed = enemySpeed + 0.5 ; Hızı artır
Print "Level Up! New level..."
Wait(100)
Return
; Ekrana Çizme
DrawTurret:
Blit(2, turretX - 16, turretY - 16) ; Taret
Return
DrawEnemy:
For i = 0 To enemyCount - 1
enemyPos = enemyList[i]
enemyX = enemyPos Mod 640
enemyY = enemyPos / 640 Mod 1000
Blit(1, enemyX - 16, enemyY - 16) ; Düşman
Next i
Return
DrawBullet:
For j = 0 To bulletCount - 1
Blit(3, bulletX[j] - 4, bulletY[j] - 4) ; Mermi
Next j
Return
; Oyun Başlangıcını Başlat
bulletCount = 0
enemyCount = 0
lives = maxLives
gameOver = False
GoTo Init
Descriptions
Graphics and Sounds: In the code, functions have been added to load the necessary graphics and sound files. These functions are called at the start of the game. You will need to place your own graphics and sound files in the appropriate directory.
Enemy Types: Defined how points are given based on the type of enemies. Also, enemies can now randomly move left or right on the screen.
Level Transitions: Configured to level up when a certain enemigo is destroyed, increasing the speed at which enemies are created and the speed at which they move.
Game Over Status: When the game is over, a "Game Over" message is displayed. To restart, the fire button (Mouse Button 1) must be pressed.
You can make improvements to this code using your own graphics and sounds. The game becomes more dynamic and fun. Now, you can test more and customize your game to add additional features. Have fun!)