' 1942 like Game ID: KJW676
' Copyright (C) 2010, Laurent GIRAUD laurent.giraud1@free.fr
' License: MIT license http://www.opensource.org/licenses/mit-license.php
'most of Game artwork created by Ari Feldman ari@arifeldman.com"
' and others grabed from free web sprites
'-------------------------
'replace by your directory path
'Path ="file://C:/Users/Laurent/Desktop/small basic/images1942/"
Path= "http://imode.free.fr/images1942/"
'replace by your directory path
'-------------------------
' Game area controls
gameWidth = 640
gameHeight = 480
fps = 50
bgs = 2 'backgroundspeed
Player_Lives = 10
nbrisland = 5 'nomber of island images
islandcount = 5 'nomber of island in the wall field
enemy_Array = "EnemyArray" 'Array that contain all the enemies
' every enemy in tha array has 5 informations
' TimeLine: each enemy has its own timeline
' PathNBR: the precalculated path defineing the movement
' the movement is decomposed in LineNbr differents lines
' each line is define in the enemy_path table with rotation, deltaY and deltaY
' PositonX, PositonY: position in space
'
'
enemy_TimeLine = "EnemyTimeLine"
enemy_line = "enemyLineNbr"
enemy_PosX = "enemyPositonX"
enemy_PosY = "enemyPositonY"
enemy_PathNBR="enemy_PathNBR"
fond= Shapes.AddImage(background)
Array.SetValue(island_Array,1,Shapes.AddImage(island1))
Array.SetValue(island_Array,2,Shapes.AddImage(island2))
Array.SetValue(island_Array,3,Shapes.AddImage(island3))
Array.SetValue(island_Array,4,Shapes.AddImage(island4))
Array.SetValue(island_Array,5,Shapes.AddImage(island5))
For i = 6 to islandcount
Array.SetValue(island_Array,i,Array.getValue(island_Array,Math.Remainder(i,4)))
Endfor
' Main gane routine
Sub Play
GraphicsWindow.Show()
' Main loop
play = 1
pause = 0
incx =0 ' X-axis increment for background
incy = 0 ' Y-axis increment for background
incbx = 0 'increment for bullets and all objects on X
incby = 0 'increment for bullets and all objects on Y
squadron = 1
' Island initial position
j= 0
If (paddleX < 0) then
paddleX = 0
endif
Shapes.Move(player, paddleX , paddleY )
EndSub
Sub OnMouseDown
ShootX = GraphicsWindow.MouseX - 15 ' in order to be from the neck of the plane
ShootY = GraphicsWindow.MouseY - 80
Fire()
EndSub
If (paddleX >(gameWidth-62) ) Then
incx = incx - bgs
incbx = incbx - bgs
For i= 1 To islandcount
incislandx[i] = incislandx[i] - bgs
EndFor
If (incx = -32 ) Then
incx =0
Endif
Endif
If (paddleX < 64 ) Then
incx = incx + bgs
incbx = incbx + bgs
For i= 1 To islandcount
incislandx[i] = incislandx[i] + bgs
EndFor
If (incx = 32 ) Then
incx =0
Endif
Endif
Shapes.Move(fond,incx -32 ,incy - 32)
For i= 1 To islandcount
islx = posx[i]+incislandx[i]
isly = posy[i]+incislandy[i]
Shapes.Move(Array.GetValue(island_Array,i),islx,isly)
EndFor
incy = incy + bgs
incby = incby+ bgs
For i= 1 To islandcount
incislandy[i] = incislandy[i] + bgs
EndFor
If (incy = 32) Then
incy =0
Endif
For i= 1 To islandcount
If ((posy[i]+incislandy[i]) > (gameHeight+15)) Then 'relaunch island if no more visible
R= Math.Round(Math.GetRandomNumber(nbrisland))
AA = Math.Remainder(TimePlay,6)
'give new coordinates
posx[i]= islandPos[AA][2]
posy[i]= islandPos[AA][3]
Shapes.move(Array.GetValue(island_Array,R),posx[i],posy[i])
incislandy[i]=0
incislandx[i]=0
EndIf
ENDFOR
' Move playerammo
For i = 1 To Player_AmmoCount
Player_Ammox = Shapes.GetLeft(Array.GetValue(Player_Ammo, i)) +incbx
Player_Ammoy = Shapes.GetTop(Array.GetValue(Player_Ammo, i)) - Player_Ammospeed
Shapes.Move(Array.GetValue(Player_Ammo, i), Player_Ammox, Player_Ammoy)
Array.SetValue(Player_AmmoAge, i, Array.GetValue(Player_AmmoAge, i) + 1)
EndFor
' Move Enemy ammo
For iea = 1 To Enemy_AmmoCount
dx =(Math.Sin((Array.GetValue(Enemy_Ammo_Angle, iea) )) * Enemy_Ammospeed)
dy =(Math.Cos((Array.GetValue(Enemy_Ammo_Angle, iea) ))* Enemy_Ammospeed)
Enemy_Ammox = Shapes.GetLeft(Array.GetValue(Enemy_Ammo, iea)) +dx+incbx
Enemy_Ammoy = Shapes.GetTop(Array.GetValue(Enemy_Ammo, iea)) +dy+incby*0.1
Shapes.Move(Array.GetValue(Enemy_Ammo, iea), Enemy_Ammox, Enemy_Ammoy)
Array.SetValue(Enemy_AmmoAge, iea, Array.GetValue(Enemy_AmmoAge, iea) + 1)
EndFor
' move ennemies
For i=1 To enemy_Count
' move as TimeLine and Path say
eNBR= Array.GetValue(enemy_PathNBR,i)
uu =Array.GetValue(enemy_line,i)
Time= Array.GetValue(enemy_TimeLine, i)
etl=enemyPath[eNBR][1][uu] 'enemy own timeLine
IF (Time=etl) Then 'it's time to rotate enemy
rr = enemyPath[eNBR][2][uu+1]
Shapes.Rotate(Array.GetValue(enemy_Array,i),rr)
EndIf
IF (Time > etl) Then
uu = uu+1
Array.SetValue(enemy_line,i,uu) ' next line for enemy move
EndIf
xx1=Array.GetValue(enemy_PosX,i)
yy1= Array.GetValue(enemy_PosY,i)
xx = xx1+enemyPath[eNBR][3][uu]+incbx
yy = yy1+enemyPath[eNBR][4][uu]+incby*0.1
' Randomly fire-enemy
If (Math.GetRandomNumber(Enemy_Agresivity)=1) Then
Enemy_ShootX = xx1 + 16
Enemy_ShootY = yy1 + 4
If (yy1 > 0 AND xx1 > 0 And yy1< gameHeight And xx1 < gameWidth) then
'this avoid enemy fire from outside the screen
fire_Enemy()
Endif
EndIf
Shapes.Move(Array.GetValue(enemy_Array,i),xx,yy)
Array.SetValue(enemy_PosX,i,xx)
Array.SetValue(enemy_PosY,i,yy)
Array.SetValue(enemy_TimeLine, i, Time + 1)
If ((uu > enemyPath[eNBR][0][0]) And (Time > etl)) Then ' if last timelife remove the enemy sprite
next_enemy_remove = i
remove_enemy()
endif
Collision_pbe()
Collision_ep()
EndFor
EndSub
Sub RemovePlayer_Ammo
Shapes.Remove(Array.GetValue(Player_Ammo, Player_Ammo_nextRemove))
For iz = Player_Ammo_nextRemove To Player_AmmoCount - 1
Array.SetValue(Player_Ammo, iz, Array.GetValue(Player_Ammo, iz+1))
Array.SetValue(Player_AmmoAge, iz, Array.GetValue(Player_AmmoAge, iz+1))
EndFor
Array.RemoveValue(Player_Ammo, Player_AmmoCount)
Array.RemoveValue(Player_AmmoAge, Player_AmmoCount)
Player_AmmoCount = Player_AmmoCount - 1
EndSub
Sub RemoveEnemy_Ammo
Shapes.Remove(Array.GetValue(Enemy_Ammo, Enemy_Ammo_nextRemove))
For irea = Enemy_Ammo_nextRemove To Enemy_AmmoCount - 1
Array.SetValue(Enemy_Ammo, irea, Array.GetValue(Enemy_Ammo, irea+1))
Array.SetValue(Enemy_AmmoAge, irea, Array.GetValue(Enemy_AmmoAge, irea+1))
Array.SetValue(Enemy_Ammo_Angle, irea, Array.GetValue(Enemy_Ammo_Angle,irea+1))
'Check playerammo age
Sub AgePlayer_Ammo
While (Array.GetValue(Player_AmmoAge, 1) > Player_AmmoLife)
Player_Ammo_nextRemove = 1
RemovePlayer_Ammo()
EndWhile
EndSub
'Check enemy ammo age
Sub AgeEnemy_Ammo
While (Array.GetValue(Enemy_AmmoAge, 1) > Enemy_AmmoLife)
Enemy_Ammo_nextRemove = 1
RemoveEnemy_Ammo()
EndWhile
EndSub
Sub remove_enemy
Shapes.remove(Array.GetValue(enemy_Array,next_enemy_remove))
' Remove all references from the arrays
For ii = next_enemy_remove To enemy_Count - 1
Array.SetValue(enemy_Array, ii, Array.GetValue(enemy_Array, ii+1))
Array.SetValue(enemy_line, ii, Array.GetValue(enemy_line, ii+1))
Array.SetValue(enemy_PosX, ii, Array.GetValue(enemy_PosX, ii+1))
Array.SetValue(enemy_PosY, ii, Array.GetValue(enemy_PosY, ii+1))
Array.SetValue(enemy_TimeLine, ii, Array.GetValue(enemy_TimeLine, ii+1))
Array.SetValue(enemy_PathNBR, ii , Array.GetValue(enemy_PathNBR, ii+1))
EndFor
Array.RemoveValue(enemy_Array, enemy_Count)
Array.RemoveValue(enemy_line, enemy_Count)
Array.RemoveValue(enemy_PosX, enemy_Count)
Array.RemoveValue(enemy_PosY, enemy_Count)
Array.RemoveValue(enemy_TimeLine, enemy_Count)
Array.RemoveValue(enemy_PathNBR,enemy_Count)
enemy_Count = enemy_Count - 1
EndSub
Sub create_enemies_left
TimeLine1 =0
For i=1 To enemy_Nbr
enemy_Count= enemy_Count + 1
Array.SetValue(enemy_PathNBR,enemy_Count,pathNBR)
If (enemy_type = 2) Then
Array.SetValue(enemy_Array, enemy_Count,Shapes.AddImage(enemy2))
Else
Array.SetValue(enemy_Array, enemy_Count,Shapes.AddImage(enemy))
EndIf
Array.SetValue(enemy_line,enemy_Count,1)
Array.SetValue(enemy_PosX, enemy_Count,enemyPosX1)
Array.SetValue(enemy_PosY, enemy_Count,enemyPosY1)
Array.SetValue(enemy_TimeLine, enemy_Count, TimeLine1)
enemyPosX1 = enemyPosX1 - 64 'distance between ennemies
TimeLine1 = TimeLine1 - 64 / enemy_speed
EndFor
For i=(enemy_Count-enemy_Nbr+1) To enemy_Count
xxx=Array.GetValue(enemy_PosX,i)
yyy= Array.GetValue(enemy_PosY,i)
Shapes.Move(Array.GetValue(enemy_Array,i),xxx,yyy)
EndFor
EndSub
Sub create_enemies_right
enemyPosX1 = enemyPosX1 + 64 'distance between ennemies
TimeLine1 = TimeLine1 - 64 / enemy_speed
EndFor
For i=(enemy_Count-enemy_Nbr+1) To enemy_Count
xxx=Array.GetValue(enemy_PosX,i)
yyy= Array.GetValue(enemy_PosY,i)
Shapes.Move(Array.GetValue(enemy_Array,i),xxx,yyy)
EndFor
EndSub
Sub Collision_pbe 'for player-bullet and enemies
For i1 = 1 To Player_AmmoCount
' player bullet position
Player_Ammox = Shapes.GetLeft(Array.GetValue(Player_Ammo, i1))
Player_Ammoy = Shapes.GetTop(Array.GetValue(Player_Ammo, i1))
px1=Player_Ammox+player_bullet_size/3 'in order to have a more precise collison than the bullet image size
py1=Player_Ammoy+player_bullet_size/3
px2=px1+2*player_bullet_size/3
py2=py1+2*player_bullet_size/3
If ( (ax1 < px1 And ax2 > px1) Or (ax1 < px2 And ax2 > px2) ) Then
If ( (ay1 < py1 And ay2 > py1) Or (ay1 < py2 And ay2 > py2) ) Then
' collision between enemy nbr i2 and player bullet i
' remove bullet i and animate explosion and remove enemy i2
Player_Ammo_nextRemove = i1
RemovePlayer_Ammo()
next_enemy_remove = i2
remove_enemy()
' begin animation for explosion at coordinate ax1, ay1
toto= Shapes.AddImage(enemy_expl1)
Shapes.move(toto,ax1,ay1)
Program.Delay(30)
Shapes.Remove(toto)
toto= Shapes.AddImage(enemy_expl2)
Shapes.move(toto,ax1,ay1)
Program.Delay(30)
Shapes.Remove(toto)
score = score +100
EndIf
EndIf
EndFor
Endfor
EndSub
Sub Collision_ep 'for enemies and player
px1 = Shapes.GetLeft(player)
py1 = Shapes.GetTop(player)
px2 = px1 + player_size
py2 = py1 + player_size
'Shapes.Move(Shapes.AddRectangle(px2-px1 ,py2-py1), px1, py1)
For i2 = 1 to enemy_Count
' enemy position
If ( (px1 < ax1 And px2 > ax1) Or (px1 < ax2 And px2 > ax2) ) Then
If ( (py1 < ay1 And py2 > ay1) Or (py1 < ay2 And py2 > ay2) ) Then
' collision between enemy ammo nbr i3 and player
' animate explosion and decrease lives
Enemy_Ammo_nextRemove = i3
RemoveEnemy_Ammo()
' begin animation for explosion at coordinate ax1, ay1
toto= Shapes.AddImage(enemy_expl1)
Shapes.move(toto,paddleX+ player_size/2,paddleY+ player_size/2)
Program.Delay(30)
Shapes.Remove(toto)
toto= Shapes.AddImage(player_expl)
Shapes.move(toto,paddleX+ player_size/2,paddleY+ player_size/2)
Program.Delay(300)
Shapes.Remove(toto)
Player_Lives = Player_Lives -1
If (Player_Lives = 0) THEN
Program.End()
EndIf
EndIf
EndIf
EndFor
EndSub
Sub IslandsPosition
' island positions, avoid randomGeneration and islands overlap
islandPos[0][1]=1
islandPos[0][2]=0
islandPos[0][3]=-150
Sub define_paths
enemyPath[0][0][0] = 3 'nbr of strait lines of path
enemyPath[0][1][1] = 30 'from 0 to this in timeline
enemyPath[0][1][2] = 100 ' from this to next in timeline
enemyPath[0][1][3] = 400 'sprite goes up
enemyPath[0][2][1] = 0 'first line rotation = 0
enemyPath[0][2][2] = 45 ' second line rotation = 45
enemyPath[0][2][3] = 45
enemyPath[0][3][1] = enemy_speed ' first line x movment
enemyPath[0][3][2] = enemy_speed 'second line x movment
enemyPath[0][3][3] = enemy_speed ' third line ...
enemyPath[0][4][1] = 0 ' first line y movment
enemyPath[0][4][2] = enemy_speed
enemyPath[0][4][3] = enemy_speed
'---------- second path
enemyPath[1][0][0] = 4
enemyPath[1][1][1] = 1
enemyPath[1][1][2] = 1
enemyPath[1][1][3] = 100
enemyPath[1][1][4] = 400