Consultas, desarrollo de programas y petición de presupuestos:

martes, 13 de enero de 2015

1945 the game


1945: The game



One of the things I have always liked is being able to play games (albeit simple) made ​​by myself ... Well, I'm looking for intenet found this book: "Programming Games for phones with J2ME" Alberto García Serrano, who even explains how to make games for Java, is perfectly adaptable to Gambas3.


1945: Versión realizada en Gambas3



Our plane is controlled with the cursor keys, and the game takes included:
  - Movement of the airplane and the enemies (different types of enemies)
  - Scrolling the map background.
  - Shooting and explosions
  - Artificial Intelligence: Using a state machine controlled enemy aircraft.
  - Calculate Collision (between enemies and flew between our enemies and bombs and bombs among the enemy with our plane)

We see a bit of the code:
The project outline is as follows:
As you can see we have the Sprite class, which is the father of several classes. This class is responsible to handle images (sprites or tiled). Then we have several that inherit from it, which are responsible for specifying concrete as they move or aircraft type (in the case of the enemies we have several types of movements)

The "game loop", the heart of the game is done by a Timer object, which updates the position of objects (airplanes, gunshots, explosions, collisions calculation)
-
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Public Sub TimerRedibujar_Timer()
  2.  
  3.   Dim aviontmp As Sprite
  4.   Dim disparotmp As Sprite
  5.   Dim explosion As Explode
  6.  
  7.   If ciclo > 200 Then
  8.     creaenemigo()
  9.     ciclo = 0
  10.   Else
  11.     ciclo += 1
  12.   Endif
  13.  
  14.   'mover los aviones....
  15.   For Each aviontmp In grupoAviones
  16.     aviontmp.mover()
  17.   Next
  18.  
  19.   'mover disparos
  20.   For Each disparotmp In grupoDisparosPropios
  21.     disparotmp.mover()
  22.   Next
  23.  
  24.   'mover disparos enemigos
  25.   For Each disparotmp In grupoDisparosEnemigos
  26.     disparotmp.mover()
  27.   Next
  28.  
  29.   analizaColisiones()
  30.   'mover explosiones
  31.   For Each explosion In grupoExplosiones
  32.     explosion.mover()
  33.   Next
  34.  
  35.   DrawingArea1.Refresh()
  36.  
  37. End

-

and then calls the event _draw DrawingArea to repaint all
-
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Public Sub DrawingArea1_Draw()
  2.   'dibujar los objetos que haya....
  3.  
  4.  Dim aviontmp As Sprite
  5.  Dim disparo As Sprite
  6.  Dim explosion As Explode
  7.  'dubjar elementos de la pantalla
  8.   fondo.dibuja()
  9.  
  10.   For Each aviontmp In grupoAviones
  11.     aviontmp.dibuja()
  12.   Next
  13.  
  14.   For Each disparo In grupoDisparosPropios
  15.     disparo.dibuja()
  16.   Next
  17.  
  18.   For Each disparo In grupoDisparosEnemigos
  19.     disparo.dibuja()
  20.   Next
  21.  
  22.   For Each explosion In grupoExplosiones
  23.     explosion.dibuja()
  24.   Next
  25.  
  26. End

-

Download the source code and installer book: alojado en https://drive.google.com


Hope you like it.

greetings

Julio




No hay comentarios:

Publicar un comentario