|
@@ -2,8 +2,40 @@
|
|
|
#include "raylib.h"
|
|
|
#include <math.h>
|
|
|
|
|
|
+#define MAXCOMMANDS 10
|
|
|
+#define MAXENTITIES 10
|
|
|
+
|
|
|
Texture2D sprites;
|
|
|
|
|
|
+typedef struct entity{
|
|
|
+ bool active;
|
|
|
+ int command[MAXCOMMANDS];
|
|
|
+ int value[MAXCOMMANDS];
|
|
|
+ int command2[MAXCOMMANDS];
|
|
|
+ int value2[MAXCOMMANDS];
|
|
|
+ Vector2 position;
|
|
|
+ int maxcommand;
|
|
|
+ int maxcommand2;
|
|
|
+ float angle;
|
|
|
+ float angle2;
|
|
|
+ int valuecount;
|
|
|
+ int valuecount2;
|
|
|
+ int pos;
|
|
|
+ int pos2;
|
|
|
+ int time;
|
|
|
+ int timemax;
|
|
|
+ int time2;
|
|
|
+ int timemax2;
|
|
|
+
|
|
|
+}entity;
|
|
|
+
|
|
|
+static struct entity ent[MAXENTITIES];
|
|
|
+
|
|
|
+
|
|
|
+void updateentities();
|
|
|
+void drawentities();
|
|
|
+void inientity(int entity,int x, int y);
|
|
|
+
|
|
|
int main(void)
|
|
|
{
|
|
|
// Initialization
|
|
@@ -16,40 +48,10 @@ int main(void)
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
- int maxcommand=3;
|
|
|
- int maxcommand2=3;
|
|
|
-
|
|
|
- int command[maxcommand];
|
|
|
- int value[maxcommand];
|
|
|
-
|
|
|
-
|
|
|
- int command2[maxcommand];
|
|
|
- int value2[maxcommand];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for(int i=0;i<maxcommand;i++){
|
|
|
- command[i]=GetRandomValue(1,3);
|
|
|
- value[i]=GetRandomValue(0,100);
|
|
|
- }
|
|
|
-
|
|
|
- for(int i=0;i<maxcommand;i++){
|
|
|
- command2[i]=GetRandomValue(2,3);
|
|
|
- value2[i]=GetRandomValue(0,100);
|
|
|
- }
|
|
|
-
|
|
|
- Vector2 position={320.0f,200.0f};
|
|
|
- float angle=0;
|
|
|
- float angle2=0;
|
|
|
- int valuecount=-1;
|
|
|
- int valuecount2=-1;
|
|
|
- int pos=0;
|
|
|
- int pos2=0;
|
|
|
- int time=0;
|
|
|
- int timemax=1;
|
|
|
- int time2=0;
|
|
|
- int timemax2=1;
|
|
|
|
|
|
+ for(int i=0;i<MAXENTITIES;i++){
|
|
|
+ inientity(i,GetRandomValue(200,400),GetRandomValue(200,400));
|
|
|
+ }
|
|
|
|
|
|
int debug=0;
|
|
|
// Main game loop
|
|
@@ -60,138 +62,198 @@ int main(void)
|
|
|
// TODO: Update your variables here
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
- if(pos==maxcommand){
|
|
|
- pos=0;
|
|
|
- for(int i=0;i<maxcommand;i++){
|
|
|
- command[i]=GetRandomValue(1,3);
|
|
|
- value[i]=GetRandomValue(10,100);
|
|
|
+ updateentities();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Draw
|
|
|
+ //----------------------------------------------------------------------------------
|
|
|
+ BeginDrawing();
|
|
|
+
|
|
|
+ ClearBackground(RAYWHITE);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ drawentities();
|
|
|
+
|
|
|
+ DrawText(FormatText("%i",debug), 100, 20, 20, BLACK);
|
|
|
+
|
|
|
+ EndDrawing();
|
|
|
+ //----------------------------------------------------------------------------------
|
|
|
+ }
|
|
|
+
|
|
|
+ // De-Initialization
|
|
|
+ UnloadTexture(sprites);
|
|
|
+ //--------------------------------------------------------------------------------------
|
|
|
+ CloseWindow(); // Close window and OpenGL context
|
|
|
+ //--------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void inientity(int entity,int x, int y){
|
|
|
+ ent[entity].active = true;
|
|
|
+ ent[entity].position.x = x;
|
|
|
+ ent[entity].position.y = y;
|
|
|
+ ent[entity].timemax = 1;
|
|
|
+ ent[entity].timemax2 = 1;
|
|
|
+ ent[entity].angle = 0;
|
|
|
+ ent[entity].angle2 = 0;
|
|
|
+ ent[entity].pos = 0;
|
|
|
+ ent[entity].pos2 = 0;
|
|
|
+ ent[entity].time = 0;
|
|
|
+ ent[entity].time2 = 0;
|
|
|
+ ent[entity].valuecount = -1;
|
|
|
+ ent[entity].valuecount2 = -1;
|
|
|
+ ent[entity].maxcommand = MAXCOMMANDS;
|
|
|
+ ent[entity].maxcommand2 = MAXCOMMANDS;
|
|
|
+ for(int i=0;i<ent[entity].maxcommand;i++){
|
|
|
+ ent[entity].command[i]=GetRandomValue(1,3);
|
|
|
+ ent[entity].value[i]=GetRandomValue(10,100);
|
|
|
+ }
|
|
|
+ for(int i=0;i<ent[entity].maxcommand2;i++){
|
|
|
+ ent[entity].command2[i]=GetRandomValue(2,3);
|
|
|
+ ent[entity].value2[i]=GetRandomValue(10,100);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void drawentities(){
|
|
|
+ for(int i=0;i<MAXENTITIES;i++){
|
|
|
+ DrawTexturePro(sprites, (Rectangle){0,0,16,16},// the -96 (-)means mirror on x axis
|
|
|
+ (Rectangle){ent[i].position.x,ent[i].position.y,64,64},
|
|
|
+ (Vector2){32,32},ent[i].angle,WHITE);
|
|
|
+ DrawTexturePro(sprites, (Rectangle){16,0,16,16},// the -96 (-)means mirror on x axis
|
|
|
+ (Rectangle){ent[i].position.x,ent[i].position.y,64,64},
|
|
|
+ (Vector2){32,32},ent[i].angle2,WHITE);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void updateentities(){
|
|
|
+
|
|
|
+ for(int i=0;i<MAXENTITIES;i++){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(ent[i].pos==ent[i].maxcommand){
|
|
|
+ ent[i].pos=0;
|
|
|
+ for(int ii=0;i<ent[i].maxcommand;i++){
|
|
|
+ ent[i].command[ii]=GetRandomValue(1,3);
|
|
|
+ ent[i].value[ii]=GetRandomValue(10,100);
|
|
|
}
|
|
|
}
|
|
|
- if(pos2==maxcommand2){
|
|
|
- debug = GetRandomValue(0,100);
|
|
|
- pos2=0;
|
|
|
- for(int i=0;i<maxcommand2;i++){
|
|
|
- command2[i]=GetRandomValue(2,3);
|
|
|
- value2[i]=GetRandomValue(10,100);
|
|
|
+ if(ent[i].pos2==ent[i].maxcommand2){
|
|
|
+
|
|
|
+ ent[i].pos2=0;
|
|
|
+ for(int ii=0;i<ent[i].maxcommand2;i++){
|
|
|
+ ent[i].command2[ii]=GetRandomValue(2,3);
|
|
|
+ ent[i].value2[ii]=GetRandomValue(10,100);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- time++;
|
|
|
- if(time>timemax && pos<maxcommand){
|
|
|
- time=0;
|
|
|
+
|
|
|
+ ent[i].time++;
|
|
|
+ if(ent[i].time>ent[i].timemax && ent[i].pos<ent[i].maxcommand){
|
|
|
+ ent[i].time=0;
|
|
|
//
|
|
|
- switch (command[pos]){
|
|
|
+ switch (ent[i].command[ent[i].pos]){
|
|
|
case 1://forward
|
|
|
- if(valuecount==-1){
|
|
|
- valuecount=value[pos];
|
|
|
+ if(ent[i].valuecount==-1){
|
|
|
+ ent[i].valuecount=ent[i].value[ent[i].pos];
|
|
|
}
|
|
|
- if(valuecount>0){
|
|
|
- valuecount--;
|
|
|
- position.x += cos(angle*DEG2RAD)*1;
|
|
|
- position.y += sin(angle*DEG2RAD)*1;
|
|
|
+ if(ent[i].valuecount>0){
|
|
|
+ ent[i].valuecount--;
|
|
|
+ ent[i].position.x += cos(ent[i].angle*DEG2RAD)*1;
|
|
|
+ ent[i].position.y += sin(ent[i].angle*DEG2RAD)*1;
|
|
|
}
|
|
|
- if(valuecount==0){
|
|
|
- pos++;
|
|
|
- valuecount=-1;
|
|
|
+ if(ent[i].valuecount==0){
|
|
|
+ ent[i].pos++;
|
|
|
+ ent[i].valuecount=-1;
|
|
|
}
|
|
|
break;
|
|
|
case 2://left
|
|
|
- if(valuecount==-1){
|
|
|
- valuecount=value[pos];
|
|
|
+ if(ent[i].valuecount==-1){
|
|
|
+ ent[i].valuecount=ent[i].value[ent[i].pos];
|
|
|
}
|
|
|
- if(valuecount>0){
|
|
|
- valuecount--;
|
|
|
- angle--;
|
|
|
+ if(ent[i].valuecount>0){
|
|
|
+ ent[i].valuecount--;
|
|
|
+ ent[i].angle--;
|
|
|
}
|
|
|
- if(valuecount==0){
|
|
|
- pos++;
|
|
|
- valuecount=-1;
|
|
|
+ if(ent[i].valuecount==0){
|
|
|
+ ent[i].pos++;
|
|
|
+ ent[i].valuecount=-1;
|
|
|
}
|
|
|
break;
|
|
|
case 3://right
|
|
|
- if(valuecount==-1){
|
|
|
- valuecount=value[pos];
|
|
|
+ if(ent[i].valuecount==-1){
|
|
|
+ ent[i].valuecount=ent[i].value[ent[i].pos];
|
|
|
}
|
|
|
- if(valuecount>0){
|
|
|
- valuecount--;
|
|
|
- angle++;
|
|
|
+ if(ent[i].valuecount>0){
|
|
|
+ ent[i].valuecount--;
|
|
|
+ ent[i].angle++;
|
|
|
}
|
|
|
- if(valuecount==0){
|
|
|
- pos++;
|
|
|
- valuecount=-1;
|
|
|
+ if(ent[i].valuecount==0){
|
|
|
+ ent[i].pos++;
|
|
|
+ ent[i].valuecount=-1;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- time2++;
|
|
|
- if(time2>timemax2 && pos2<maxcommand2){
|
|
|
- time2=0;
|
|
|
+
|
|
|
+ ent[i].time2++;
|
|
|
+ if(ent[i].time2>ent[i].timemax2 && ent[i].pos2<ent[i].maxcommand2){
|
|
|
+ ent[i].time2=0;
|
|
|
//
|
|
|
- switch (command2[pos2]){
|
|
|
+ switch (ent[i].command2[ent[i].pos2]){
|
|
|
case 2://left
|
|
|
- if(valuecount2==-1){
|
|
|
- valuecount2=value2[pos2];
|
|
|
+ if(ent[i].valuecount2==-1){
|
|
|
+ ent[i].valuecount2=ent[i].value2[ent[i].pos2];
|
|
|
}
|
|
|
- if(valuecount2>0){
|
|
|
- valuecount2--;
|
|
|
- angle2--;
|
|
|
+ if(ent[i].valuecount2>0){
|
|
|
+ ent[i].valuecount2--;
|
|
|
+ ent[i].angle2--;
|
|
|
}
|
|
|
- if(valuecount2==0){
|
|
|
- pos2++;
|
|
|
- valuecount2=-1;
|
|
|
+ if(ent[i].valuecount2==0){
|
|
|
+ ent[i].pos2++;
|
|
|
+ ent[i].valuecount2=-1;
|
|
|
}
|
|
|
break;
|
|
|
case 3://right
|
|
|
- if(valuecount2==-1){
|
|
|
- valuecount2=value2[pos2];
|
|
|
+ if(ent[i].valuecount2==-1){
|
|
|
+ ent[i].valuecount2=ent[i].value2[ent[i].pos2];
|
|
|
}
|
|
|
- if(valuecount2>0){
|
|
|
- valuecount2--;
|
|
|
- angle2++;
|
|
|
+ if(ent[i].valuecount2>0){
|
|
|
+ ent[i].valuecount2--;
|
|
|
+ ent[i].angle2++;
|
|
|
}
|
|
|
- if(valuecount2==0){
|
|
|
- pos2++;
|
|
|
- valuecount2=-1;
|
|
|
+ if(ent[i].valuecount2==0){
|
|
|
+ ent[i].pos2++;
|
|
|
+ ent[i].valuecount2=-1;
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- // Draw
|
|
|
- //----------------------------------------------------------------------------------
|
|
|
- BeginDrawing();
|
|
|
|
|
|
- ClearBackground(RAYWHITE);
|
|
|
|
|
|
|
|
|
|
|
|
- DrawTexturePro(sprites, (Rectangle){0,0,16,16},// the -96 (-)means mirror on x axis
|
|
|
- (Rectangle){position.x,position.y,64,64},
|
|
|
- (Vector2){32,32},angle,WHITE);
|
|
|
- DrawTexturePro(sprites, (Rectangle){16,0,16,16},// the -96 (-)means mirror on x axis
|
|
|
- (Rectangle){position.x,position.y,64,64},
|
|
|
- (Vector2){32,32},angle2,WHITE);
|
|
|
-
|
|
|
-
|
|
|
- DrawText(FormatText("%i",pos2), 10, 20, 20, BLACK);
|
|
|
- DrawText(FormatText("%i",debug), 100, 20, 20, BLACK);
|
|
|
|
|
|
- EndDrawing();
|
|
|
- //----------------------------------------------------------------------------------
|
|
|
}
|
|
|
|
|
|
- // De-Initialization
|
|
|
- UnloadTexture(sprites);
|
|
|
- //--------------------------------------------------------------------------------------
|
|
|
- CloseWindow(); // Close window and OpenGL context
|
|
|
- //--------------------------------------------------------------------------------------
|
|
|
|
|
|
- return 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|