Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Baklazhan, Ayumi, Hanky27), 1,387 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
2D Space-Shooter #432912
11/19/13 08:22
11/19/13 08:22
Joined: Oct 2008
Posts: 341
R
ratz Offline OP
Senior Member
ratz  Offline OP
Senior Member
R

Joined: Oct 2008
Posts: 341
Hallo heute möchte ich euch mein Spaceshooter vorstellen
ich hab mir das Aum82 angeguckt und versucht ein
einfachen und recht sauberen code zu schreiben
danke auch ans forum wink

-> eine health-bar
-> leben
-> score
-> sound
-> Feind
-> Kollision
-> Player
-> Schuss (500)
-> Bewegter Hintergrund



und hier der Code
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>


BMAP* ship_bmp = "ship.bmp";
BMAP* enemy_bmp = "enemy2.bmp";

BMAP* explo1_tga = "explo1.tga";
BMAP* explo2_tga = "explo2.tga";
BMAP* explo3_tga = "explo3.tga";
BMAP* explo4_tga = "explo4.tga";

SOUND* explo = "explo.wav";
SOUND* laser = "laser.wav";

#define enemy_width 40
#define enemy_height 20
#define bullet_width 5 
#define bullet_height 11

///////////////////////////////
var i = 1;
var i_2 = 1;
var s;

var lives = 3;
var score = 0;

var shoot_var = 1;
var players_health = 100;

var game_over_var = 0;

function move_background();

function space_ship();

function shoot_1_event();
function shoot_1(i);

function create_enemy(i_2);
function enemy_event(i_2);
function enemy_collisions(i_2);

function level1();

FONT* arial_font = "Arial#20b";


///////////////////


PANEL* score_pan =
{
	layer = 20;
	digits (10, 20, "Score: %.f", arial_font, 1, score);
   digits (10, 35, "Leben: %.f", arial_font, 1, lives);
	digits (10, 55, "Schuss: %.f", arial_font, 1, i);
	flags = visible;
}

PANEL* game_over_pan =
{
	layer = 20;
	pos_x = 300;
	pos_y = 200;
	digits (10, 10, "GAME OVER !", arial_font, 1, 0);
}

PANEL* reset_pan =
{
	layer = 20;
	pos_x = 300;
	pos_y = 200;
	digits (10, 30, "Drücke Enter ...", arial_font, 1, 0);
}


PANEL* background1 =
{
 bmap = "back_1.bmp";
 pos_x = 0;
 pos_y = 0;
 flags = SHOW;	
}

PANEL* background2 =
{
 bmap = "back_1.bmp";
 pos_x = 0;
 pos_y = -768;
 flags = SHOW;	
}

PANEL* _ship =
{
 bmap = "ship.bmp";
 pos_x = 100;
 pos_y = 100;
 flags = SHOW | OVERLAY;	
}


PANEL* health_pan = 
{
	bmap = "health.bmp";
	pos_x = -12; 
	pos_y = 0;
	layer = 25;
	flags = SHOW;
}	

PANEL* _shoot[500];
PANEL* enemies[50];


function main()
{
 //fps_max = 240; // limit the frame rate to 60 fps
 vec_set(screen_size,vector(800,600,0));
 vec_set(screen_color,vector(50,1,1)); // dark blue
 vec_set(sky_color,vector(50,1,1)); // dark blue
 video_window(NULL,NULL,0,"Space Shooter - written by Patrick Ratz");
 d3d_antialias = 1;
 shadow_stencil = 3;
 level_load(NULL);
  move_background();
 level1();
 
 while (1)
	{
	 wait (1);
	 health_pan.scale_x = maxv(0.01, players_health / 100);	 
	}
}

function level1()
{
 
 create_enemy(i_2);
 space_ship();
}

function game_over()
{
 _shoot[i] = NULL;
 enemies[i_2] = NULL;
  
 reset(enemies[i_2],SHOW);	

   
 set(game_over_pan,SHOW);	
 wait(-2);
 
 game_over_var = 1;
 
 set(reset_pan,SHOW);	
 
 while(1)
 {
  if(key_enter) 
  {
   reset(reset_pan,SHOW);	
   reset(game_over_pan,SHOW);
   
   players_health = 100;
   score = 0;
   
   set(_ship,SHOW);	
   level1();
   break;
  }
  wait(1);
 }	
}


function move_background()
{
	while (1)
	{
		background1.pos_y += 3 * time_step; 
		background2.pos_y = background1.pos_y - 767; 
				if (background1.pos_y > 767)
		{
			background1.pos_y -= 767; 
		}
		wait (1);
	 
	}
}

function space_ship()
{
 while(lives > 0)
 {
 	
  if(players_health < 1)
  {
   players_health = 100;
   lives -= 1;
   _ship.pos_x = 100;
   _ship.pos_y = 100;
   
  }

  //UP	
  if (key_cuu == 1)
  {
  	_ship.pos_y --;
  }
  
  //DOWN
  if (key_cud == 1)
  {
  	_ship.pos_y ++;
  }
 
  //LEFT
  if (key_cul == 1)
  {
  	_ship.pos_x --;
  }
 
  //RIGHT
  if (key_cur == 1)
  {
  	_ship.pos_x ++;
  }
  
  //SPACE && SHOOT == 0
  if ((key_space) && (!_shoot[i]))  
  {
   shoot_1_event();
  }

  //COLLISION WITH ENEMY

  if ((((_ship.pos_x + 67 >= enemies[i_2].pos_x) && (_ship.pos_x + 67 <= enemies[i_2].pos_x + 37)) ||
  ((enemies[i_2].pos_x + 37 >= _ship.pos_x) && (enemies[i_2].pos_x + 37 <= _ship.pos_x + 67)))&&
  (((_ship.pos_y + 67 >= enemies[i_2].pos_y) && (_ship.pos_y + 67 <= enemies[i_2].pos_y + 37)) ||
  ((enemies[i_2].pos_y + 37 >= _ship.pos_y) && (enemies[i_2].pos_y + 37 <= _ship.pos_y + 67))))
  {
   if(score > 1)
   {
    score -= 10;	
   }
   
   players_health -= 10;
	snd_play(explo, 90, 0); 
   
   enemies[i_2].bmap = explo1_tga; 
	wait (6);
	enemies[i_2].bmap = explo2_tga;
	wait (6);
	enemies[i_2].bmap = explo3_tga;
	wait (6);
	enemies[i_2].bmap = explo4_tga;
	wait (6);
   enemies[i_2].bmap = enemy_bmp;

   reset(enemies[i_2],SHOW);

   enemies[i_2].pos_x = random(400);
   enemies[i_2].pos_y = random(400);
   wait (3);
   
   set(enemies[i_2],SHOW);
  }

  wait(1);
 }
 
   snd_play(explo, 100, 0); 
	_ship.bmap = explo1_tga; 
	wait (6);
	_ship.bmap = explo2_tga;
	wait (6);
	_ship.bmap = explo3_tga;
	wait (6);
	_ship.bmap = explo4_tga;
	wait (6);
	_ship.bmap = ship_bmp;
	
	reset(_ship, VISIBLE);
	game_over();
}

function shoot_1_event()
{
 
 shoot_1(i);
  wait(35);
 i++;	
}

function shoot_1(i)
{    
  snd_play(laser, 90, 0); 

  _shoot[i] = pan_create("bmap = shot.bmp;",5);
  _shoot[i].pos_x = _ship.pos_x+30  - bullet_width / 2;
  _shoot[i].pos_y = _ship.pos_y-20;  
  _shoot[i].flags |= VISIBLE;
    
//  shoot_var = 1;	
  
  
  
 while(_shoot[i] != NULL)
 {
  if(_shoot[i].pos_y > 5)
  {
   _shoot[i].pos_y -= 1;	      
  }
  else
  {
   reset(_shoot[i],VISIBLE); 
   i = 0;
   break;
  }   

  if ((((_shoot[i].pos_x + bullet_width >= enemies[i_2].pos_x) && (_shoot[i].pos_x + bullet_width <= enemies[i_2].pos_x + enemy_width)) ||
			((enemies[i_2].pos_x + enemy_width >= _shoot[i].pos_x) && (enemies[i_2].pos_x + enemy_width <= _shoot[i].pos_x + bullet_width)))
			&& (((_shoot[i].pos_y + bullet_height >= enemies[i_2].pos_y) && (_shoot[i].pos_y + bullet_height <= enemies[i_2].pos_y + enemy_height)) ||
			((enemies[i_2].pos_y + enemy_height >= _shoot[i].pos_y) && (enemies[i_2].pos_y + enemy_height <= _shoot[i].pos_y + bullet_height))))
   {
				score += 20; 
			   snd_play(explo, 90, 0); 
			     
				reset(_shoot[i], VISIBLE); 
				_shoot[i] = NULL; 
			    
				
				enemies[i_2].bmap = explo1_tga; 
				wait (6);
				enemies[i_2].bmap = explo2_tga;
				wait (6);
				enemies[i_2].bmap = explo3_tga;
				wait (6);
				enemies[i_2].bmap = explo4_tga;
				wait (6);
				
				reset(enemies[i_2], VISIBLE); 
   	
	}	
  
  wait(1);
 } 
  _shoot[i] = NULL;	
 //} 
}

//

function create_enemy(i_2)
{
enemies[i_2] = pan_create("bmap = enemy2.bmp; flags = VISIBLE;", 20);
enemies[i_2].pos_x = random(650);
enemies[i_2].pos_y = random(150);
enemy_event(i_2);
enemy_collisions(i_2);
i_2++;
}


function enemy_event(i_2)
{
 var enemy_y;
 	
 while(is (enemies[i_2], VISIBLE))
 {
	enemy_y = enemies[i_2].pos_y; 
  	
  while((enemies[i_2].pos_y < enemy_y + 80) && (is (enemies[i_2], VISIBLE)))
  {	
   if(enemies[i_2].pos_y < 780)
   {
	 enemies[i_2].pos_y += 0.5;	      
   }  
   else
   {
    reset(enemies[i_2], VISIBLE); 
	 break;
   } 
   wait(1);
  }
  wait(1);
 }	
 create_enemy(i_2);	
}


function enemy_collisions(i_2)
{
 while (is (enemies[i_2], VISIBLE))
	{
		
         
		if (_shoot[i]) 
		{
			if (is (enemies[i_2], INVISIBLE)) {break;} 
						
      	 
				if ((((_shoot[i].pos_x + bullet_width >= enemies[i_2].pos_x) && (_shoot[i].pos_x + bullet_width <= enemies[i_2].pos_x + enemy_width)) ||
			((enemies[i_2].pos_x + enemy_width >= _shoot[i].pos_x) && (enemies[i_2].pos_x + enemy_width <= _shoot[i].pos_x + bullet_width)))
			&& (((_shoot[i].pos_y + bullet_height >= enemies[i_2].pos_y) && (_shoot[i].pos_y + bullet_height <= enemies[i_2].pos_y + enemy_height)) ||
			((enemies[i_2].pos_y + enemy_height >= _shoot[i].pos_y) && (enemies[i_2].pos_y + enemy_height <= _shoot[i].pos_y + bullet_height))))
			{
				
				score += 20; 
			   snd_play(explo, 90, 0); 
			     
				reset(_shoot[i], VISIBLE); 
				_shoot[i] = NULL; 
			    
				
				enemies[i_2].bmap = explo1_tga; 
				wait (6);
				enemies[i_2].bmap = explo2_tga;
				wait (6);
				enemies[i_2].bmap = explo3_tga;
				wait (6);
				enemies[i_2].bmap = explo4_tga;
				wait (6);
				
				reset(enemies[i_2], VISIBLE);
				 
			}  
			
		}
		wait (1);
	}
	
}



download ->

http://www.file-upload.net/download-8297508/Space-shooter.rar.html

(rechts der kleine "Download" Button (auf der seite !))

Last edited by ratz; 11/19/13 08:23.
Re: 2D Space-Shooter [Re: ratz] #432930
11/19/13 14:33
11/19/13 14:33
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
the page is disliked by Eset Nod32 (probably because of some advertisments), but download is fine.


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1