=begin
================================================================================
■ Scene_game
par chaipokoi
--------------------------------------------------------------------------------
le script qui suit vous permet d'inserrer un space invaders a votre programme
rpg maker xp.
toutes les ressources neccessaire sont a plcer dans le dossier picture des
ressources graphiques de votre jeu.
Lisez tout les script, je vous indique quels sont les lignes a modifier sans
risque pour personnaliser votre space invader.
pour le moment le script ne propose que 2 bonus, mais je vais bientot en creer
d'autres.
Pour tout probleme,
klio17@live.fr================================================================================
=end
class Scene_Game
def main
@fond=Sprite.new
#-------------------------------------------------------------------------------
#vous poubez modifier l'image de fond du space invader en modifier le mot entre
#guillement ci-dessous
@fond.bitmap=RPG::Cache.picture("fond")
#-------------------------------------------------------------------------------
$gold=0
@rand_bonus=0
@vie=3
@taille_tir=50
@barre_vie=Barre_vie.new
@move_droite=0
@move_gauche=0
@move_tir=0
@move_bonus_3_tir=0
@move_bonus_reparation=0
@bonus_3_tir=Bonus.new("3_tir")
@bonus_reparation=Bonus.new("reparation")
@rand_tir_ennemy_1=2
@rand_tir_ennemy_2=2
@move_tir_ennemy_1=0
@move_tir_ennemy_2=0
@rand_repos=2
@barre=Barre.new
@tir_ennemy_1=Missile.new("ennemy",4)
@tir_ennemy_1.x=-50
@tir_ennemy_2=Missile.new("ennemy",4)
@tir_ennemy_2.x=0
@tir_ennemy_2.y=-50
@move_tir_ennemy_2=0
#-------------------------------------------------------------------------------
#vous pouvez modifier l'image du vaisseau du joueur en modifiant la ligne ci-des
#sous.
#IMPORTANT!!!!!!!!!!!!!!
#LE NOM DE VOTRE IMAGE REPRESENTANT LE VAISSEAU DU JOUEUR DOIT TOUJOURS COMMENCER
#PAR "vaisseau_".
@vaisseau=Vaisseau.new("gris",2)
#-------------------------------------------------------------------------------
@gold=Window_point.new
#-------------------------------------------------------------------------------
#vous pouvez modifier l'image du tir du joueur en modifiant la ligne ci-des
#sous.
#IMPORTANT!!!!!!!!!!!!!!
#LE NOM DE VOTRE IMAGE REPRESENTANT LE TIR DU JOUEUR DOIT TOUJOURS COMMENCER
#PAR "tir_".
@tir_allie=Missile.new("allie",4)
#-------------------------------------------------------------------------------
@tir_allie.x=-50
#-------------------------------------------------------------------------------
#vous pouvez modifier les images des 4 ennemis en modifiant les lignes ci-des
#sous.
#IMPORTANT!!!!!!!!!!!!!!
#POUR L'ANNIMATION, VOUS DEVEZ DESSINER 3 POSTURES PAR ENNEMIS.
#TOUTES LES POSTURES DOIVENT CE TERMINER PAR "_ext","_nor","_int".
#ici si vos image se nomment "truc_ext","truc_nor" et "truc_int", vous ne devez ecrire
#que "truc" sur les lignes qui suivent.
@ennemy_1=Ennemy.new("crane",1)
@ennemy_2=Ennemy.new("tama1",3)
@ennemy_3=Ennemy.new("tama2",2)
@ennemy_4=Ennemy.new("tama2",2)
#-------------------------------------------------------------------------------
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@ennemy_1.dispose
@ennemy_2.dispose
@ennemy_3.dispose
@ennemy_4.dispose
@vaisseau.dispose
@barre.dispose
@gold.dispose
@barre_vie.dispose
end
def update
#tir des ennemis
if @move_tir_ennemy_1==0
@rand_tir_ennemy_1=rand(41)
if @rand_tir_ennemy_1==0
@move_tir_ennemy_1=1
@tir_ennemy_1.y=@ennemy_3.y
@tir_ennemy_1.x=@ennemy_3.x
end
end
if @move_tir_ennemy_1==1
@tir_ennemy_1.tir_ennemy
if @tir_ennemy_1.y>480
@tir_ennemy_1.y=-50
@move_tir_ennemy_1=0
end
end
if @move_tir_ennemy_2==0
@rand_tir_ennemy_2=rand(41)
if @rand_tir_ennemy_2==0
@move_tir_ennemy_2=1
@tir_ennemy_2.y=@ennemy_4.y
@tir_ennemy_2.x=@ennemy_4.x
end
end
if @move_tir_ennemy_2==1
@tir_ennemy_2.tir_ennemy
if @tir_ennemy_2.y>480
@tir_ennemy_2.y=-50
@move_tir_ennemy_2=0
end
end
#déplacement des bonus
if @move_bonus_3_tir==1
@bonus_3_tir.move
if @bonus_3_tir.y>480
@move_bonus_3_tir=0
end
end
if @move_bonus_reparation==1
@bonus_reparation.move
if @bonus_reparation.y>480
@move_bonus_reparation=0
end
end
@gold.refresh
# Animation du Sprite
@ennemy_1.update
@ennemy_2.update
@ennemy_3.update
@ennemy_4.update
# Déplacement du Sprite
@ennemy_1.move
@ennemy_2.move
@ennemy_3.move
@ennemy_4.move
@barre.move
@barre_vie.refresh(@vie)
#_____________________________________________________________________________________
#déplacement du vaisseau
if Input.trigger?(Input::C)
@move_tir=1
end
if Input.trigger?(Input::RIGHT)
@move_gauche=0
@move_droite=1
end
if Input.trigger?(Input::LEFT)
@move_droite=0
@move_gauche=1
end
if @move_droite==1
@vaisseau.droite
end
if @move_gauche==1
@vaisseau.gauche
end
if @move_tir==1
if @taille_tir==50
@tir_allie.tir(@vaisseau.x)
end
if @taille_tir==200
@tir_allie.tir(@vaisseau.x-80)
end
if @tir_allie.y<-50
@tir_allie.y=480-60
@tir_allie.x=-200
@move_tir=0
end
end
#_______________________________________________________________________________
superposition
end
#-------------------------------------------------------------------------------
#gestion de la superposition lors de l'appartition des ennemis
def superposition
if @ennemy_1.x>=@ennemy_2.x and @ennemy_1.x<=@ennemy_2.x+50
@ennemy_1.y-=1
@ennemy_2.x+=10
end
if @ennemy_2.x>=@ennemy_3.x and @ennemy_2.x<=@ennemy_3.x+50
@ennemy_2.y-=3
@ennemy_3.x-=5
end
if @ennemy_3.x>=@ennemy_4.x and @ennemy_3.x<=@ennemy_4.x+50
@ennemy_3.y-=2
@ennemy_4.x+=5
end
if @ennemy_1.x>=@ennemy_3.x and @ennemy_1.x<=@ennemy_3.x+50
@ennemy_1.y-=1
@ennemy_3.x-=5
end
if @ennemy_1.x>=@ennemy_4.x and @ennemy_1.x<=@ennemy_4.x+50
@ennemy_1.y-=1
@ennemy_4.x+=5
end
if @ennemy_2.x>=@ennemy_4.x and @ennemy_2.x<=@ennemy_4.x+50
@ennemy_2.y-=3
@ennemy_4.x-=5
end
if @ennemy_2.x>=@ennemy_1.x and @ennemy_2.x<=@ennemy_1.x+50
@ennemy_2.y-=3
@ennemy_1.x-=5
end
if @ennemy_3.x>=@ennemy_2.x and @ennemy_3.x<=@ennemy_2.x+50
@ennemy_3.y-=2
@ennemy_2.x+=5
end
if @ennemy_4.x>=@ennemy_3.x and @ennemy_4.x<=@ennemy_3.x+50
@ennemy_4.y-=2
@ennemy_3.x-=5
end
if @ennemy_3.x>=@ennemy_1.x and @ennemy_3.x<=@ennemy_1.x+50
@ennemy_3.y-=2
@ennemy_1.x+=5
end
if @ennemy_4.x>=@ennemy_1.x and @ennemy_4.x<=@ennemy_1.x+50
@ennemy_4.y-=2
@ennemy_1.x-=5
end
if @ennemy_4.x>=@ennemy_2.x and @ennemy_4.x<=@ennemy_2.x+50
@ennemy_4.y-=2
@ennemy_2.x+=5
end
collision
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#gestion des collisions
def collision
#_______________________________________________________________________________
#entre le joueur et les ennemis
if @ennemy_1.y>=480-90 and @ennemy_1.x>=@vaisseau.x-30 and @ennemy_1.x<=@vaisseau.x+90
@vie=@vie-1
replace
end
if @ennemy_2.y>=480-90 and @ennemy_2.x>=@vaisseau.x-30 and @ennemy_2.x<=@vaisseau.x+90
@vie=@vie-1
replace
end
if @ennemy_3.y>=480-90 and @ennemy_3.x>=@vaisseau.x-30 and @ennemy_3.x<=@vaisseau.x+90
@vie=@vie-1
replace
end
if @ennemy_4.y>=480-90 and @ennemy_4.x>=@vaisseau.x-30 and @ennemy_4.x<=@vaisseau.x+90
@vie=@vie-1
replace
end
#_______________________________________________________________________________
#entre le tir allie et les ennemis
if @tir_allie.y<=@ennemy_1.y+50 and @tir_allie.x>=@ennemy_1.x-@taille_tir/2-10 and @tir_allie.x<=@ennemy_1.x+@taille_tir+10
bonus(@ennemy_1.x,@ennemy_1.y)
$gold=$gold+10
@ennemy_1.y=-50
@ennemy_1.x = rand(640-50).succ
end
if @tir_allie.y<=@ennemy_2.y+50 and @tir_allie.x>=@ennemy_2.x-@taille_tir/2-10 and @tir_allie.x<=@ennemy_2.x+@taille_tir+10
bonus(@ennemy_2.x,@ennemy_2.y)
$gold=$gold+10
@ennemy_2.y=-50
@ennemy_2.x = rand(640-50).succ
end
if @tir_allie.y<=@ennemy_3.y+50 and @tir_allie.x>=@ennemy_3.x-@taille_tir/2-20 and @tir_allie.x<=@ennemy_3.x+@taille_tir+10
bonus(@ennemy_3.x,@ennemy_3.y)
$gold=$gold+10
@ennemy_3.y=-50
@ennemy_3.x = rand(640-50).succ
@tir_ennemy_1.y=-50
@move_tir_ennemy_1=0
end
if @tir_allie.y<=@ennemy_4.y+50 and @tir_allie.x>=@ennemy_4.x-@taille_tir/2-20 and @tir_allie.x<=@ennemy_4.x+@taille_tir+10
bonus(@ennemy_4.x,@ennemy_4.y)
$gold=$gold+10
@ennemy_4.y=-50
@ennemy_4.x = rand(640-50).succ
@tir_ennemy_2.y=-50
@move_tir_ennemy_2=0
end
#_______________________________________________________________________________
#entre le tir ennemie et le joueur
if @tir_ennemy_1.y>=480-50 and @tir_ennemy_1.x>=@vaisseau.x-10 and @tir_ennemy_1.x<=@vaisseau.x+60
@vie=@vie-1
replace
@tir_ennemy_1.y=-50
@move_tir_ennemy_1=0
end
if @tir_ennemy_2.y>=480-50 and @tir_ennemy_2.x>=@vaisseau.x-10 and @tir_ennemy_2.x<=@vaisseau.x+60
@vie=@vie-1
replace
@tir_ennemy_2.y=-50
@move_tir_ennemy_2=0
end
#_______________________________________________________________________________
#entre le joueur et les bonus
#bonus_3_tir
if @bonus_3_tir.y>=480-50 and @bonus_3_tir.x>=@vaisseau.x-10 and @bonus_3_tir.x<=@vaisseau.x+60
@taille_tir=200
@tir_allie.bitmap= RPG::Cache.picture("tir_allie_grand")
@move_bonus_3_tir=0
@bonus_3_tir.y=-50
end
if @bonus_reparation.y>=480-50 and @bonus_reparation.x>=@vaisseau.x-10 and @bonus_reparation.x<=@vaisseau.x+60
@vie+=1
if @vie>3
@vie=3
end
@move_bonus_reparation=0
@bonus_reparation.y=-50
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#replacement des ennemis
def replace
@ennemy_1.y=10
@ennemy_2.y=10
@ennemy_3.y=10
@ennemy_4.y=10
@vaisseau.x=640/2-25
@barre_vie.refresh(@vie)
Graphics.update
sleep 2
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#gestion des bonus
def bonus(x,y)
@rand_bonus=rand(20)
if @move_bonus_3_tir==0
if @rand_bonus==1
@bonus_3_tir.placement(x,y)
@move_bonus_3_tir=1
end
end
if @move_bonus_reparation==0
if @rand_bonus==10
@bonus_reparation.placement(x,y)
@move_bonus_reparation=1
end
end
end
end
#===============================================================================
=begin
==========================================================================
■ Ennemy
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère les mouvements et l'animation des ennemy du space invader.
============================================================================
=end
class Ennemy < Sprite
def initialize(image,vitesse)
super ()
@image=image
@vitesse=vitesse
self.bitmap = RPG::Cache.picture(@image+"_ext")
self.x = rand(640-50).succ
self.y = 10
self.src_rect.set(0, 0, 50, 50)
@i = 0
@nb_Frame = 0
end
def update
super
# Incrémentaion de nombre de Frame
if @nb_Frame >0
self.bitmap = RPG::Cache.picture(@image+"_ext")
end
@nb_Frame += 1
if @nb_Frame >10
self.bitmap = RPG::Cache.picture(@image+"_nor")
end
if @nb_Frame >20
self.bitmap = RPG::Cache.picture(@image+"_int")
end
if @nb_Frame >30
self.bitmap = RPG::Cache.picture(@image+"_nor")
end
# Quand les frames vaut 5
if @nb_Frame > 40
# On remet le nombre de Frame à 0
@nb_Frame = 0
# Affichage de la prochaine séquence d'animation
self.src_rect.set(0, 0, 50, 50)
end
end
def move
# Déplacement de 10px vers le bas
self.y+=@vitesse
# Suppression du Sprite quand on sort de l'écran
if self.y>480
self.x = rand(640-50).succ
self.y=-50
end
end
end
#===============================================================================
=begin
==========================================================================
■ Vaisseau
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère les mouvements et l'animation du vaisseau du space invader.
============================================================================
=end
class Vaisseau < Sprite
def initialize(image,vitesse)
super ()
@couleur=image
@vitesse=vitesse
self.bitmap = RPG::Cache.picture("vaisseau_"+@couleur)
self.y = 480-50
self.src_rect.set(0, 0, 50, 50)
end
def droite
# Déplacement de 10px vers le bas
self.x+=@vitesse
# Suppression du Sprite quand on sort de l'écran
if self.x>640-50
self.x-=@vitesse
end
end
def gauche
# Déplacement de 10px vers le bas
self.x-=@vitesse
# Suppression du Sprite quand on sort de l'écran
if self.x<0
self.x+=@vitesse
end
end
end
#===============================================================================
=begin
==========================================================================
■ Window_point
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère l'affichage des points du joueur.
============================================================================
=end
class Window_point<Window_Base
def initialize
super(-05, 0, 160, 60)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.opacity=0
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(10, 0, 160, 30,"gold:"+$gold.to_s)
end
end
#===============================================================================
=begin
==========================================================================
■ Missile
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère les mouvements du tir du joueur et des ennemis.
============================================================================
=end
class Missile< Sprite
def initialize(image,vitesse)
super ()
@camp=image
@vitesse=vitesse
self.bitmap = RPG::Cache.picture("tir_"+@camp)
self.y = 480-50
self.src_rect.set(0, 0, 50, 50)
end
def tir(x)
@x=x
self.x=@x
self.y-=30
end
def tir_ennemy
self.y+=5
end
end
#===============================================================================
=begin
==========================================================================
■ Barre
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère l'annimation de la barre située sous les points du joueur
============================================================================
=end
class Barre< Sprite
def initialize
super()
@stop_down=0
@stop_up=1
self.bitmap = RPG::Cache.picture("barre")
self.y=10
self.x=-5
end
def move
if @stop_up==1
self.y+=1
if self.y>15
@stop_up=0
@stop_down=1
end
end
if @stop_down==1
self.y-=1
if self.y<10
@stop_up=1
@stop_down=0
end
end
end
end
#===============================================================================
=begin
==========================================================================
■ Barre_vie
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère l'annimation de la barre de vie.
============================================================================
=end
class Barre_vie< Sprite
def initialize
super()
@stop_down=0
@stop_up=1
self.bitmap = RPG::Cache.picture("vie_3")
self.y=14
self.x=530
end
def refresh(vie)
@vie=vie
if @vie>=1 and @vie<=3
self.bitmap = RPG::Cache.picture("vie_"+@vie.to_s)
end
if @vie<2
move
end
if @vie<1
print "game over"
exit
end
end
def move
if @stop_up==1
self.y+=1
if self.y>15
@stop_up=0
@stop_down=1
end
end
if @stop_down==1
self.y-=1
if self.y<10
@stop_up=1
@stop_down=0
end
end
end
end
#===============================================================================
=begin
==========================================================================
■ Bonus
par chaipokoi
--------------------------------------------------------------------------------
cette classe gère l'affichage et la chute des bonus.
============================================================================
=end
class Bonus< Sprite
def initialize(type)
@type=type
super()
self.bitmap = RPG::Cache.picture("bonus_"+@type)
self.y=-50
self.x=-50
end
def placement(x,y)
@x=x
@y=y
self.y=@y
self.x=@x
end
def move
self.y+=4
end
end
#===============================================================================
#OUF!!!! c'est la fin.