view test/putenemy.c @ 927:b491db049d74

Added tag current-release for changeset 4e73a22327a8
author kono
date Sun, 13 Apr 2014 10:20:02 +0900
parents c55337499f96
children
line wrap: on
line source

#include <math.h>

// for rand
#include <stdlib.h>

extern int printf(const char *,...);
#define SANKAKU 100000
#ifndef M_PI
#define M_PI 3.1415962
#endif

static const double pi2 = M_PI * 2.0;

int mysin[181];
int mycos[181];

void sankakuf()
{
    int i;
    for(i=0;i<181;i++)
    {
        mysin[i]=sin(i /360.0*pi2)*SANKAKU;
    }
    for(i=0;i<181;i++)
    {
        mycos[i]=cos(i /360.0*pi2)*SANKAKU;
    }
}

int Mycos0(int c)
{
    c%=360;
    if(c<0) c+=360;
    if((c<=180))
        return(mycos[c]);
    if(c>180)
        return(mycos[180-(c-180)]);
    return(0);
}

int Mycos(int c) {
    printf("#0041:Mycos %d=%d\n",c,Mycos0(c));
    return Mycos0(c);
}

int Mysin0(int c)
{
    c%=360;
    if(c<0) c+=360;
    if(c<=180)
        return(mysin[c]);
    if(c>180)
        return(mysin[180-(c-180)]*-1);
    return(0);
}

int Mysin(int c) {
    printf("#0057:Mysin %d=%d\n",c,Mysin0(c));
    return Mysin0(c);
}

void
Putenemy(int charno,float x,float y,float sx,float sy,int move) {
     if(x)
          printf("#0064:%d %f %f %f %f %d\n",charno,x,y,sx,sy,move);
     else
          printf("#0066:check\n");
}
int
main()
{
     int ix=32,iy=32; float fx=32,fy=32;
     srand(55555);
     sankakuf();
     printf("#0074:%d %d\n", Mysin(45),Mycos(-30));
     {
         float x=10,y=20;
         Putenemy(3,x,y,(float) Mysin(15)*2/SANKAKU,(float)Mycos(15)*2/SANKAKU,0);
         //Putenemy(3,x,y,(float) Mysin(15)*2.0/SANKAKU,(float)Mycos(15)*2.0/SANKAKU,0);
         Putenemy(3,x,y,(float) Mysin(rand()%15*-1)*2/SANKAKU,(float)Mycos(rand()%15*-1)*2/SANKAKU,0);
         // Putenemy(3,x,y,(float) Mysin(rand()%15*-1)*2.0/SANKAKU,(float)Mycos(rand()%15*-1)*2.0/SANKAKU,0);
     }
     Putenemy(0,ix,iy,1,0,10);
     Putenemy(1,(float)ix,(float)iy,1,0,10);
     Putenemy(2,(float)ix,(float)iy,(float)ix,(float)iy,ix);
     Putenemy(3,(float)ix,(float)iy,(float)ix,0,ix);
     Putenemy(4,fx,fy,1,0,10);
     return(0);
}