Advertisement

12.18.2006 at 08:37AM PST, ID: 22096747
[x]
Attachment Details

Making a simple game in C !

Asked by patriciaeldridge in Game Programming User Interface

Tags: simple, game

This is what I got working so far .. next problem is .. I'd like an event when my ship hits an enemy ship .. also .. I'd like a #defined number of enemies on my screen at all times .. I don't know how to do any of the above things .. any example or modifications on my lil thingy are welcome..


#include <stdio.h>
#include <dos.h>
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

#define PAS 20

struct time t;
int keye=250;
int coordX=0;
int coordXe=0;
int coordY=0;
int coordYe=0;
int tmp=0;
int tmp2=0;
int i;

void moveMyShipLeft(void);
void moveMyShipRight(void);
void moveMyShipUp(void);
void moveMyShipDown(void);
void desenMyShip(int, int, int);

void getConflict(int coordX, int coordXe, int coordY, int coordYe){
      int stuffz,stuffy;
      stuffz=coordX;
}

int getSecTime(void){
      gettime(&t);
      return t.ti_hund;
}

int pressedKey(void){
      keye=getch();
      return(keye);
}

void desenEnemyShip(int coordXe, int coordYe, int culoare){
      setfillstyle(1,culoare);
      bar(0+coordXe,0+coordYe,60+coordXe,40+coordYe);
}

void initDefault(void){
}


void desenMyShip(int coordX, int coordY, int culoare){
      setfillstyle(1,culoare);
      bar(coordX,coordY,60+coordX,40+coordY);
      getConflict(coordX,coordY,coordXe,coordYe);
}

void moveMyShip(void){
            if ((keye==75) && coordX > getmaxx()-1023){
                  moveMyShipLeft();
            }
            if ((keye==77) && coordX < getmaxx()-60){
                  moveMyShipRight();
            }
            if ((keye==80) && coordY < getmaxy()-40){
                  moveMyShipUp();
            }
            if ((keye==72) && coordY > getmaxy()-767){
                  moveMyShipDown();
            }
}

void moveEnemyShips(int coordXe, int coordYe, int culoare){
            desenEnemyShip(coordXe,coordYe,0);
            coordYe=coordYe+1;
            desenEnemyShip(coordXe,coordYe,culoare);
            tmp=getSecTime();
}

void initEnamies(void){
}

void moveMyShipLeft(void){
      desenMyShip(coordX,coordY,0);
      coordX=coordX-PAS;
      desenMyShip(coordX,coordY,2);
}
void moveMyShipRight(void){
      desenMyShip(coordX,coordY,0);
      coordX=coordX+PAS;
      desenMyShip(coordX,coordY,3);
}
void moveMyShipUp(void){
      desenMyShip(coordX,coordY,0);
      coordY=coordY+PAS;
      desenMyShip(coordX,coordY,4);
}
void moveMyShipDown(void){
      desenMyShip(coordX,coordY,0);
      coordY=coordY-PAS;
      desenMyShip(coordX,coordY,5);
}

int huge DetectVGA256(void){
      int vid=4;
      return vid;
}

void doGame(void){
            initDefault();
            coordYe = 1000;
      do{
            if (coordYe > 800){
              coordXe = rand() % 1023;
              coordYe = 40;
            }
            if (kbhit()){
                  pressedKey();
                  moveMyShip();
            }
            desenMyShip(coordX,coordY,4);
            if (getSecTime()+10 != tmp+10){
                        desenEnemyShip(coordXe,coordYe-15,0);
                        moveEnemyShips(coordXe,coordYe,12);
                        coordYe=coordYe+15;
                  }
      }while (keye != 27);
}


void main(void){
      int gdriver, gmode, errorcode;
      gdriver = installuserdriver("svga256",DetectVGA256);
      gdriver = DETECT;
      initgraph(&gdriver, &gmode, "..\bgi\svga256.bgi");
      errorcode = graphresult();
      if (errorcode != grOk){
            printf("Graphics error: %s\n", grapherrormsg(errorcode));
            printf("Press any key to halt:");
            getch();
            exit(1);
      }
      doGame();
}Start Free Trial
 
Loading Advertisement...
 
[+][-]01.04.2007 at 11:09AM PST, ID: 18245572

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2007 at 11:18AM PST, ID: 18245652

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.05.2007 at 12:36AM PST, ID: 18249892

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Game Programming User Interface
Tags: simple, game
Sign Up Now!
Solution Provided By: ged325
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.08.2007 at 10:37AM PST, ID: 18681367

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]03.13.2007 at 08:02PM PDT, ID: 18715731

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32