#1
by ポテト » 5年前
避けゲーを作っています。学校の課題です。
内容は上にUFOを飛ばし自分で下に表示されている人を方向キーで操作して、飛行機から落とされる爆弾を避けていくっていうかんじです。
途中までやったのですが、爆弾が表示されなくて、原因もわかりません。
本当に困ってます。どなたかわかる方お願いします。
コード:
#include <stdio.h>
#include <handy.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#define WINDOWSIZE 600
//人間を描く関数
void humanA1(int x1,int x2);
void humanA2(int x1,int x2);
void humanB1(int x1,int x2);
void humanB2(int x1,int x2);
//UFO
void UFO(int a);
//背景
void view(void);
//爆弾
void bom1(int side1, int high1);
void bom2(int side2, int high2);
void bom3(int side3, int high3);
//void plane1(int a, int gid1);
//void plane2( int gid2);
//void Flag(int a, int gid1, int gid2);
int main(){
int x1=0;
int x2=0;
int a=0;
int v=0;
int key;
//bomのx座標
int side1;
int side2;
int side3;
//bomのy座標
int high1;
int high2;
int high3;
int count1=0;
int count2=0;
int random;
hgevent *event;
srand(time(NULL));//乱数を現在時刻で初期化
int mainwindow;//windowID
doubleLayer layers; // (1)ダブルレイヤの変数を宣言する
/* mainwindow=HgOpen(WINDOWSIZE,WINDOWSIZE);
layers = HgWAddDoubleLayer(0); // (2)ダブルレイヤを作成する
HgWSetFillColor(0, HG_DGRAY); // ベースレイヤに背景を描く
HgWSetEventMask(mainwindow,HG_KEY_DOWN);
int key;
HgSetFont(HG_M,50);//フォントの設定
HgText(50, 300, "スペースキーを押してね");// 最初
for(;;){//スペースキーを押すまでループ
key= HgGetChar();
if(key==' ') {
HgClear();
break;
}
}*/
HgOpen(WINDOWSIZE,WINDOWSIZE);
//背景
view();
for (a=0;; a+=v) {
HgClear();
UFO(a);
view();
HgSleep(0.05);
if(a>=570){
v=-10;
}
if(a<=30){
v=10;
}
HgSetEventMask(HG_KEY_DOWN);
event=HgEventNonBlocking(); //キー入力
if(event!=NULL){
switch(event->ch){
case HG_R_ARROW://右カーソル
printf("%d : %d\n",a, random);
count2++;
if(count2%2==0){
humanA1(x1,x2);
x1=x1+10;
}else if(count2%2==1){
humanB1(x1,x2);
x2=x2+10;
}
break;
case HG_L_ARROW://左カーソル
printf("%d\n",a);
count1++;
if(count1%2==0){
humanA2(x1,x2);
x1=x1-10;
}else if(count1%2==1){
humanB2(x1, x2);
x1=x1-10;
}
break;
}
}//ここまでが人を動かすプログラム
//爆弾
random = rand()%20;
/* if(random==0){
side1=30+a;
for(high1=0; high1>415; high1=high1+10){
bom1(side1, high1);
HgClear();
}
}*/
switch(random){
case 0:
side1=30+a;
for(high1=0; high1>415; high1=high1+10){
bom1(side1, high1);
HgClear();
}
break;
case 1:
side2=30+a;
for(high2=0; high2>410; high2=high2+15){
bom2(side2, high2);
HgClear();
}
break;
case 2:
side3=30+a;
for(high3=0; high3>410; high3=high3+20){
bom3(side3, high3);
HgClear();
}
break;
}
//当たり判定
if((side1==300+x1+x2)&&(415-high1==100)){
break;
}
}
HgGetChar();
HgClose();
}
void humanA1(int x1,int x2){//右向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(275+x1+x2, 38, 325+x1+x2, 38);//肩から手首
HgLine(275+x1+x2, 38, 275+x1+x2, 25);//左手
HgLine(325+x1+x2, 38, 325+x1+x2, 50);//みぎ手
HgLine(300+x1+x2, 25, 275+x1+x2,0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 25);//みぎ太もも
HgLine(325+x1+x2, 25, 325+x1+x2, 0);//右足
}
void humanA2(int x1,int x2){//左向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(275+x1+x2, 38, 325+x1+x2, 38);//肩から手首
HgLine(275+x1+x2, 38, 275+x1+x2, 50);//左手
HgLine(325+x1+x2, 38, 325+x1+x2, 25);//みぎ手
HgLine(300+x1+x2, 25, 275+x1+x2, 25);//左足太もも
HgLine(275+x1+x2, 25, 275+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 0);//右足
}
void humanB1(int x1,int x2){//右向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(300+x1+x2, 38, 275+x1+x2, 30);//左手首
HgLine(275+x1+x2, 30, 290+x1+x2, 25);//左手
HgLine(300+x1+x2, 38, 325+x1+x2, 30);//みぎ手首
HgLine(325+x1+x2, 30, 325+x1+x2, 35);//右手
HgLine(300+x1+x2, 25, 290+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 13);//右足首
HgLine(325+x1+x2, 13, 312+x1+x2, 0);//右足
}
void humanB2(int x1,int x2){//左向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(300+x1+x2, 38, 275+x1+x2, 30);//左手首
HgLine(275+x1+x2, 30, 290+x1+x2, 35);//左手
HgLine(300+x1+x2, 38, 325+x1+x2, 30);//みぎ手首
HgLine(325+x1+x2, 30, 310+x1+x2, 25);//右手
HgLine(300+x1+x2, 25, 280+x1+x2, 13);//左足太もも
HgLine(280+x1+x2, 13, 290+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 310+x1+x2, 0);//右足
}
void UFO(int a){
HgSetFillColor(HG_GRAY);
HgFanFill(30+a, 550, 30, 0, M_PI, 1);
HgSetFillColor(HG_PURPLE);
HgBoxFill(a, 485, 60, 40, 1);
HgSetFillColor(HG_PURPLE);
HgOvalFill(30+a, 530, 50, 25, 0, 1);
}
void view(void){
HgSetFillColor(HG_GREEN);
HgFanFill(50, 200, 300, 1.25*M_PI, 1.75*M_PI,1);
HgFanFill(300, 300, 500, 1.25*M_PI, 1.75*M_PI,1);
HgFanFill(550, 200, 300, 1.25*M_PI, 1.75*M_PI,1);
}
void bom1(int side1, int high1){
//爆弾1
HgCircle(side1, 415-high1, 30);
HgSetFillColor(HG_BLACK);
HgBoxFill(side1-10, 435-high1, 17, 20, 1);
HgSetFillColor(HG_RED);
HgBoxFill(side1-10, 455-high1, 17, 10, 1);
}
void bom2(int side2, int high2){
//爆弾2
HgSetFillColor(HG_BLACK);
HgFanFill(side2, 410-high2, 25, M_PI, 2*M_PI, 1);
HgBox(side2-25, 410-high2, 50, 75);
}
void bom3(int side3, int high3){
//爆弾3
HgSetFillColor(HG_BLACK);
HgFanFill(side3, 410-high3, 25, M_PI, 2*M_PI, 1);
HgBox(side3-25, 410-high3, 50, 75);
HgSetFillColor(HG_RED);
HgBoxFill(side3-25, 475-high3, 50, 10, 1);
}
/*から*/で囲っているところはコメントになっているのでプログラムには何も関係ないです。
避けゲーを作っています。学校の課題です。
内容は上にUFOを飛ばし自分で下に表示されている人を方向キーで操作して、飛行機から落とされる爆弾を避けていくっていうかんじです。
途中までやったのですが、爆弾が表示されなくて、原因もわかりません。
本当に困ってます。どなたかわかる方お願いします。
[code]
#include <stdio.h>
#include <handy.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#define WINDOWSIZE 600
//人間を描く関数
void humanA1(int x1,int x2);
void humanA2(int x1,int x2);
void humanB1(int x1,int x2);
void humanB2(int x1,int x2);
//UFO
void UFO(int a);
//背景
void view(void);
//爆弾
void bom1(int side1, int high1);
void bom2(int side2, int high2);
void bom3(int side3, int high3);
//void plane1(int a, int gid1);
//void plane2( int gid2);
//void Flag(int a, int gid1, int gid2);
int main(){
int x1=0;
int x2=0;
int a=0;
int v=0;
int key;
//bomのx座標
int side1;
int side2;
int side3;
//bomのy座標
int high1;
int high2;
int high3;
int count1=0;
int count2=0;
int random;
hgevent *event;
srand(time(NULL));//乱数を現在時刻で初期化
int mainwindow;//windowID
doubleLayer layers; // (1)ダブルレイヤの変数を宣言する
/* mainwindow=HgOpen(WINDOWSIZE,WINDOWSIZE);
layers = HgWAddDoubleLayer(0); // (2)ダブルレイヤを作成する
HgWSetFillColor(0, HG_DGRAY); // ベースレイヤに背景を描く
HgWSetEventMask(mainwindow,HG_KEY_DOWN);
int key;
HgSetFont(HG_M,50);//フォントの設定
HgText(50, 300, "スペースキーを押してね");// 最初
for(;;){//スペースキーを押すまでループ
key= HgGetChar();
if(key==' ') {
HgClear();
break;
}
}*/
HgOpen(WINDOWSIZE,WINDOWSIZE);
//背景
view();
for (a=0;; a+=v) {
HgClear();
UFO(a);
view();
HgSleep(0.05);
if(a>=570){
v=-10;
}
if(a<=30){
v=10;
}
HgSetEventMask(HG_KEY_DOWN);
event=HgEventNonBlocking(); //キー入力
if(event!=NULL){
switch(event->ch){
case HG_R_ARROW://右カーソル
printf("%d : %d\n",a, random);
count2++;
if(count2%2==0){
humanA1(x1,x2);
x1=x1+10;
}else if(count2%2==1){
humanB1(x1,x2);
x2=x2+10;
}
break;
case HG_L_ARROW://左カーソル
printf("%d\n",a);
count1++;
if(count1%2==0){
humanA2(x1,x2);
x1=x1-10;
}else if(count1%2==1){
humanB2(x1, x2);
x1=x1-10;
}
break;
}
}//ここまでが人を動かすプログラム
//爆弾
random = rand()%20;
/* if(random==0){
side1=30+a;
for(high1=0; high1>415; high1=high1+10){
bom1(side1, high1);
HgClear();
}
}*/
switch(random){
case 0:
side1=30+a;
for(high1=0; high1>415; high1=high1+10){
bom1(side1, high1);
HgClear();
}
break;
case 1:
side2=30+a;
for(high2=0; high2>410; high2=high2+15){
bom2(side2, high2);
HgClear();
}
break;
case 2:
side3=30+a;
for(high3=0; high3>410; high3=high3+20){
bom3(side3, high3);
HgClear();
}
break;
}
//当たり判定
if((side1==300+x1+x2)&&(415-high1==100)){
break;
}
}
HgGetChar();
HgClose();
}
void humanA1(int x1,int x2){//右向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(275+x1+x2, 38, 325+x1+x2, 38);//肩から手首
HgLine(275+x1+x2, 38, 275+x1+x2, 25);//左手
HgLine(325+x1+x2, 38, 325+x1+x2, 50);//みぎ手
HgLine(300+x1+x2, 25, 275+x1+x2,0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 25);//みぎ太もも
HgLine(325+x1+x2, 25, 325+x1+x2, 0);//右足
}
void humanA2(int x1,int x2){//左向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(275+x1+x2, 38, 325+x1+x2, 38);//肩から手首
HgLine(275+x1+x2, 38, 275+x1+x2, 50);//左手
HgLine(325+x1+x2, 38, 325+x1+x2, 25);//みぎ手
HgLine(300+x1+x2, 25, 275+x1+x2, 25);//左足太もも
HgLine(275+x1+x2, 25, 275+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 0);//右足
}
void humanB1(int x1,int x2){//右向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(300+x1+x2, 38, 275+x1+x2, 30);//左手首
HgLine(275+x1+x2, 30, 290+x1+x2, 25);//左手
HgLine(300+x1+x2, 38, 325+x1+x2, 30);//みぎ手首
HgLine(325+x1+x2, 30, 325+x1+x2, 35);//右手
HgLine(300+x1+x2, 25, 290+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 325+x1+x2, 13);//右足首
HgLine(325+x1+x2, 13, 312+x1+x2, 0);//右足
}
void humanB2(int x1,int x2){//左向き
HgSetFillColor(HG_ORANGE);
HgCircleFill(300+x1+x2, 75, 25,0);//頭
HgLine(300+x1+x2, 50, 300+x1+x2, 25);//胴体
HgLine(300+x1+x2, 38, 275+x1+x2, 30);//左手首
HgLine(275+x1+x2, 30, 290+x1+x2, 35);//左手
HgLine(300+x1+x2, 38, 325+x1+x2, 30);//みぎ手首
HgLine(325+x1+x2, 30, 310+x1+x2, 25);//右手
HgLine(300+x1+x2, 25, 280+x1+x2, 13);//左足太もも
HgLine(280+x1+x2, 13, 290+x1+x2, 0);//左足
HgLine(300+x1+x2, 25, 310+x1+x2, 0);//右足
}
void UFO(int a){
HgSetFillColor(HG_GRAY);
HgFanFill(30+a, 550, 30, 0, M_PI, 1);
HgSetFillColor(HG_PURPLE);
HgBoxFill(a, 485, 60, 40, 1);
HgSetFillColor(HG_PURPLE);
HgOvalFill(30+a, 530, 50, 25, 0, 1);
}
void view(void){
HgSetFillColor(HG_GREEN);
HgFanFill(50, 200, 300, 1.25*M_PI, 1.75*M_PI,1);
HgFanFill(300, 300, 500, 1.25*M_PI, 1.75*M_PI,1);
HgFanFill(550, 200, 300, 1.25*M_PI, 1.75*M_PI,1);
}
void bom1(int side1, int high1){
//爆弾1
HgCircle(side1, 415-high1, 30);
HgSetFillColor(HG_BLACK);
HgBoxFill(side1-10, 435-high1, 17, 20, 1);
HgSetFillColor(HG_RED);
HgBoxFill(side1-10, 455-high1, 17, 10, 1);
}
void bom2(int side2, int high2){
//爆弾2
HgSetFillColor(HG_BLACK);
HgFanFill(side2, 410-high2, 25, M_PI, 2*M_PI, 1);
HgBox(side2-25, 410-high2, 50, 75);
}
void bom3(int side3, int high3){
//爆弾3
HgSetFillColor(HG_BLACK);
HgFanFill(side3, 410-high3, 25, M_PI, 2*M_PI, 1);
HgBox(side3-25, 410-high3, 50, 75);
HgSetFillColor(HG_RED);
HgBoxFill(side3-25, 475-high3, 50, 10, 1);
}
/*から*/で囲っているところはコメントになっているのでプログラムには何も関係ないです。