Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <tice.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <graphx.h>
- #include <keypadc.h>
- #include <fileioc.h>
- #include "gfx/sprites.h"
- typedef struct {
- int x;
- int y;
- int xdir;
- int ydir;
- } bullet_t;
- static bullet_t bullet[20];
- typedef struct {
- int x;
- int y;
- int xdir;
- int ydir;
- int vel;
- int bvel;
- bool detected;
- int health;
- bullet_t laser[1];
- } robot_t;
- static robot_t robots[10];
- void UpdateRobots(int *numrobots, int x, int y) {
- int i;
- for(i = 0; i < *numrobots ; i ++) {
- if (robots[i].xdir == 1) {
- gfx_TransparentSprite_NoClip(robotR,robots[i].x,robots[i].y);
- } else {
- gfx_TransparentSprite_NoClip(robotL,robots[i].x,robots[i].y);
- }
- if (abs(x-robots[i].x) > abs(y-robots[i].y)) {
- if (x > robots[i].x) {
- robots[i].x ++;
- robots[i].xdir = 1;
- } else {
- robots[i].x --;
- robots[i].xdir = -1;
- }
- }
- if (abs(y-robots[i].y) >= abs(x-robots[i].x)) {
- if (y > robots[i].y) {
- robots[i].y ++;
- } else {
- robots[i].y --;
- }
- }
- }
- }
- void UpdateBullets(int *numbullets, int *numrobots, int bvel) {
- int i, j;
- for(i = 0; i < *numbullets ; i ++) {
- gfx_TransparentSprite_NoClip(ball_bullet,bullet[i].x,bullet[i].y);
- for(j = 0; j < *numrobots; j ++) {
- if (gfx_CheckRectangleHotspot(bullet[i].x, bullet[i].y, ball_bullet_width, ball_bullet_height, robots[j].x, robots[j].y, robotL_width, robotL_height)){
- }
- }
- if (bullet[i].x + bullet[i].xdir * bvel > 0 && bullet[i].x + bullet[i].xdir * bvel < 320-8 &&
- bullet[i].y + bullet[i].ydir * bvel > 0 && bullet[i].y + bullet[i].ydir * bvel < 240-8) {
- bullet[i].x += bullet[i].xdir * bvel;
- bullet[i].y += bullet[i].ydir * bvel;
- } else {
- bullet[i].x = bullet[*numbullets-1].x;
- bullet[i].y = bullet[*numbullets-1].y;
- bullet[i].xdir = bullet[*numbullets-1].xdir;
- bullet[i].ydir = bullet[*numbullets-1].ydir;
- *numbullets -= 1;
- }
- }
- }
- void main(void) {
- float x=152, y=112;
- int numbullets=0, bulletcap = 20, bulletDamage = 50;
- int loadtimer=0, loadtime=5;
- int gunxdir = 1, gunydir = 0;
- int robotspawntimer = 0, robotspawntime = 50;
- int numrobots = 0;
- int vel = 2, bvel = 4;
- int pause, dirs;
- int xspawn, yspawn;
- bool quit = false;
- gfx_sprite_t *Character = redseed;
- gfx_sprite_t RobotL;
- srand(rtc_Time());
- gfx_Begin();
- gfx_SetPalette(sprites_pal, sizeof_sprites_pal, 0);
- gfx_FillScreen(0);
- while (quit == false) {
- loadtimer ++;
- robotspawntimer ++;
- dirs = 0;
- gfx_ZeroScreen();
- gfx_SetDrawBuffer();
- //character sprite
- gfx_TransparentSprite_NoClip(Character, x, y);
- //update robot and bullet positions
- UpdateRobots(&numrobots, x, y);
- UpdateBullets(&numbullets, &numrobots, bvel);
- //spawn robots
- if (robotspawntimer == robotspawntime && numrobots < 10) {
- robotspawntimer = 0;
- xspawn = randInt(0,320-32);
- yspawn = randInt(0,240-32);
- if (abs(x - xspawn) > 40 && abs(y - yspawn) > 40) {
- robots[numrobots].x = xspawn;
- robots[numrobots].y = yspawn;
- robots[numrobots].xdir = 0;
- robots[numrobots].ydir = 0;
- robots[numrobots].vel = 1;
- robots[numrobots].bvel = 1;
- robots[numrobots].health = 100;
- numrobots ++;
- }
- }
- kb_Scan();
- if (kb_Data[1] & kb_2nd && numbullets<bulletcap && loadtimer > loadtime) {
- loadtimer = 0;
- bullet[numbullets].x = x + 8;
- bullet[numbullets].y = y + 8;
- bullet[numbullets].xdir = gunxdir;
- bullet[numbullets].ydir = gunydir;
- numbullets++;
- }
- gfx_SwapDraw();
- if (kb_Data[6] & kb_Clear)
- quit = true;
- if (kb_Data[7] & kb_Left && x>0+2*vel) {
- x-=vel;
- if (!(kb_Data[2] & kb_Alpha))
- gunxdir = -1;
- dirs++;
- }
- if (kb_Data[7] & kb_Right && x<320-32-2*vel) {
- x+=vel;
- if (!(kb_Data[2] & kb_Alpha))
- gunxdir = 1;
- dirs++;
- }
- if (kb_Data[7] & kb_Up && y>0+2*vel) {
- y-=vel;
- if (!(kb_Data[2] & kb_Alpha))
- gunydir = -1;
- dirs++;
- }
- if (kb_Data[7] & kb_Down && y<240-32-2*vel) {
- y+=vel;
- if (!(kb_Data[2] & kb_Alpha))
- gunydir = 1;
- dirs++;
- }
- if (!(kb_Data[2] & kb_Alpha)) {
- if ((dirs==1) && ((kb_Data[7] & kb_Left) || (kb_Data[7] & kb_Right)))
- gunydir = 0;
- if ((dirs==1) && ((kb_Data[7] & kb_Up) || (kb_Data[7] & kb_Down)))
- gunxdir = 0;
- }
- }
- gfx_End();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement