void del_naves_screen() { if (nave_parada->on_screen == true) delete_sprite(nave_parada, VIDEO_BASE_ADDRESS); if (nave_esquerda->on_screen == true) delete_sprite(nave_esquerda, VIDEO_BASE_ADDRESS); if (nave_direita->on_screen == true) delete_sprite(nave_direita, VIDEO_BASE_ADDRESS); }
void place_sprite(sprite_t *s, camera_t *c) { bool exist = s->obj != NULL; int screen_x = SCREEN_X(*s, *c); int screen_y = SCREEN_Y(*s, *c); ENGINE_DEBUGFMT("sprite in world at %d, %d on screen at %d, %d, exist: %d, height: %d", s->x, s->height, screen_x, screen_y, exist, SPRITE_HEIGHT(*s)); if ((screen_y + SPRITE_HEIGHT(*s) < 0) || (screen_y > SCREEN_HEIGHT) || (screen_x + SPRITE_WIDTH(*s) < 0) || (screen_x > SCREEN_WIDTH)) { if (exist) { ENGINE_DEBUG("sprite left! deleting it"); delete_sprite(s); } return; } else { if (!exist) { ENGINE_DEBUG("sprite on screen and needs to be created"); s->obj = new_obj(); } } obj_set_attr(s->obj, s->shape | ATTR0_REG, s->size, ATTR2_PALBANK(s->palbank) | s->tile); obj_set_pos(s->obj, screen_x, screen_y); }
bool Bullet::valid_move(char map[20][50], int yMove, int xMove) { //Allow Bullet to move if ((map[yMove][xMove] == ' ') && (yMove >= 0)) { return true; } else { //Delete Bullet delete_sprite(map); return false; } }
SpriteID Stage::new_sprite_from_file(const unicode& filename, uint32_t frame_width, uint32_t frame_height, uint32_t margin, uint32_t spacing, std::pair<uint32_t, uint32_t> padding) { SpriteID s = new_sprite(); TextureID t = new_texture_from_file( filename, kglt::TEXTURE_OPTION_CLAMP_TO_EDGE | kglt::TEXTURE_OPTION_DISABLE_MIPMAPS | kglt::TEXTURE_OPTION_NEAREST_FILTER ); try { sprite(s)->set_spritesheet(t, frame_width, frame_height, margin, spacing, padding); } catch(...) { delete_sprite(s); throw; } return s; }
void move_sprite(Sprite *sprt, int x, int y, char *base) { int xi = (x > sprt->x) ? sprt->x : x; int yi = (y > sprt->y) ? sprt->y : y; int xf = (x > sprt->x) ? x + sprt->width : sprt->x + sprt->width; int yf = (y > sprt->y) ? y + sprt->height : sprt->y + sprt->height; video_buffer = realloc(video_buffer, HRES * VRES); flip_buffer_partial(video_buffer, base, xi, yi, xf - xi, yf - yi); delete_sprite(sprt, video_buffer); sprt->x = x; sprt->y = y; draw_sprite(sprt, video_buffer); flip_buffer_partial(base, video_buffer, xi, yi, xf - xi, yf - yi); }
int move_ball(Sprite *bola, Vector *vec_blocos) { //>>>>>>>>>>>>>>>>>>>>>> actualiza o bloco que simula a nave como um bloco para as colisões Bloco *nave_block = (Bloco*)get_back_element(vec_blocos); nave_block->sprite->x = nave_pos.x; nave_block->sprite->y = nave_pos.y; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> infos speed = sqrt(bola->xspeed * bola->xspeed + bola->yspeed * bola->yspeed); drawIntAt(pontuation, SCORE_X_POS, SCORE_Y_POS, NUMBER_FOREGROUND_COLOR, COUNTER_BACKGROUND, CHAR_SCALE, VIDEO_BASE_ADDRESS, codepage); drawIntAt(speed , SPEED_X_POS, SPEED_Y_POS, NUMBER_FOREGROUND_COLOR, COUNTER_BACKGROUND, CHAR_SCALE, VIDEO_BASE_ADDRESS, codepage); drawIntAt(lives, LIFES_X_POS, LIFES_Y_POS, NUMBER_FOREGROUND_COLOR, COUNTER_BACKGROUND, CHAR_SCALE, VIDEO_BASE_ADDRESS, codepage); //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> colisão com as paredes Bool first_hit = true; //lado direito while ((bola->x + bola->width + COLLISION_DETECTION_OFFSET) > MAX_GAME_WINDOWS_X) { int new_xspeed = -abs(bola->xspeed); bola->xspeed = new_xspeed; animate_sprite(bola, VIDEO_BASE_ADDRESS); if (first_hit == true) play_note(&wall_hit); //mili_sleep(5000); } first_hit = true; //lado esquerdo while ((bola->x - COLLISION_DETECTION_OFFSET) < MIN_GAME_WINDOWS_X) { int new_xspeed = abs(bola->xspeed); bola->xspeed = new_xspeed; animate_sprite(bola, VIDEO_BASE_ADDRESS); if (first_hit == true) play_note(&wall_hit); //mili_sleep(5000); first_hit = false; } first_hit = true; //baixo while ((bola->y + bola->height + COLLISION_DETECTION_OFFSET) > MAX_GAME_WINDOWS_Y) { int new_yspeed = -abs(bola->yspeed); bola->yspeed = new_yspeed; animate_sprite(bola, VIDEO_BASE_ADDRESS); if (first_hit == true) play_note(&ground_hit); --lives; mili_sleep(10); delete_sprite(bola, VIDEO_BASE_ADDRESS); bola->x = (nave_pos.x + nave_parada->width / 2); bola->y = VRES * 0.82; bola->xspeed = 1; bola->yspeed = -2; first_hit = false; } first_hit = true; //cima while ((bola->y - COLLISION_DETECTION_OFFSET) < MIN_GAME_WINDOWS_Y) { int new_yspeed = abs(bola->yspeed); bola->yspeed = new_yspeed; animate_sprite(bola, VIDEO_BASE_ADDRESS); if (first_hit == true) play_note(&wall_hit); //mili_sleep(5000); first_hit = false; } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tipos de movimentos da bola para saber como calcular a colisao com os blocos unsigned int collision_type; if ((bola->xspeed >= 0) && (bola->yspeed <= 0)) collision_type = 0; if ((bola->xspeed <= 0) && (bola->yspeed < 0)) collision_type = 1; if ((bola->xspeed < 0) && (bola->yspeed >= 0)) collision_type = 2; if ((bola->xspeed > 0) && (bola->yspeed > 0)) collision_type = 3; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Calcula se ocorre colisão unsigned int size_vec_blocos = sizeVector(vec_blocos); unsigned int i; switch(collision_type) { case 0: { // bola a mover-se para NE (nordeste) for (i = 0; i < size_vec_blocos; ++i) { Bloco* block = (Bloco*)elementAtVector(vec_blocos, i); //verifica se houve colisão (+-COLLISION_DETECTION_OFFSET para evitar sobreposição da bola com os blocos) if( (block->sprite->on_screen == true) && (abs(bola->x + bola->width) > (block->sprite->x - COLLISION_DETECTION_OFFSET)) && (abs(bola->x) < (block->sprite->x + block->sprite->width)) && (((bola->y + bola->height) > block->sprite->y)) && ((bola->y < (block->sprite->y + block->sprite->height + COLLISION_DETECTION_OFFSET))) ) { //determina o lado em que bateu a bola int dx = abs(bola->x + bola->width - block->sprite->x); int dy = abs(bola->y - (block->sprite->y + block->sprite->height)); //actualiza a velocidade da bola //Caso embata na nave considera apenas a parte da xpm que tem a nave if (block->nave == true) { if ((block->sprite->x < (block->sprite->width - NAVE_LEFT_OFFSET_IN_XPM - NAVE_RIGHT_OFFSET_IN_XPM)) //caso em que a nave esta do lado esquerdo || ((dx > NAVE_LEFT_OFFSET_IN_XPM) && (abs(block->sprite->x + block->sprite->width - bola->x) > NAVE_RIGHT_OFFSET_IN_XPM))) { if (dx > dy) { //bateu da parte de baixo do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado esquerdo do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&nave_hit); } } else { if (dx > dy) { //bateu da parte de baixo do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado esquerdo do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&block_hit); } animate_sprite(bola, VIDEO_BASE_ADDRESS); //apaga bloco se não for a nave if (block->nave == false) { //mili_sleep(5000); block->sprite->on_screen = false; delete_sprite(block->sprite, VIDEO_BASE_ADDRESS); //acrescenta à pontuação o valor do bloco pontuation += block->pontuation; //actualiza o numeros de blocos que já foram destruidos ++blocos_destruidos; } return 0; } } break; } case 1: { // bola a mover-se para NO (noroeste) for (i = 0; i < size_vec_blocos; ++i) { Bloco* block = (Bloco*)elementAtVector(vec_blocos, i); //verifica se houve colisão (+-COLLISION_DETECTION_OFFSET para evitar sobreposição da bola com os blocos) if( (block->sprite->on_screen == true) && (abs(bola->x + bola->width) > block->sprite->x) && (abs(bola->x) < (block->sprite->x + block->sprite->width + COLLISION_DETECTION_OFFSET)) && ((bola->y + bola->height) > block->sprite->y) && ((bola->y < (block->sprite->y + block->sprite->height + COLLISION_DETECTION_OFFSET))) ) { //determina o lado em que bateu a bola int dx = abs(block->sprite->x + block->sprite->width - bola->x); int dy = abs(block->sprite->y + block->sprite->height - bola->y); //actualiza a velocidade da bola //Caso embata na nave considera apenas a parte da xpm que tem a nave if (block->nave == true) { if ((block->sprite->x < (block->sprite->width - NAVE_LEFT_OFFSET_IN_XPM - NAVE_RIGHT_OFFSET_IN_XPM)) //caso em que a nave esta do lado esquerdo || ((dx > NAVE_RIGHT_OFFSET_IN_XPM) && (abs(bola->x + bola->width - block->sprite->x) > NAVE_LEFT_OFFSET_IN_XPM))) { if (dx > dy) { //bateu da parte de baixo do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado direito do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&nave_hit); } } else { if (dx > dy) { //bateu da parte de baixo do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado direito do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&block_hit); } animate_sprite(bola, VIDEO_BASE_ADDRESS); //apaga bloco se não for a nave if (block->nave == false) { //mili_sleep(5000); block->sprite->on_screen = false; delete_sprite(block->sprite, VIDEO_BASE_ADDRESS); //acrescenta à pontuação o valor do bloco pontuation += block->pontuation; //actualiza o numeros de blocos que já foram destruidos ++blocos_destruidos; } return 0; } } break; } case 2: { // bola a mover-se para SO (sudueste) for (i = 0; i < size_vec_blocos; ++i) { Bloco* block = (Bloco*)elementAtVector(vec_blocos, i); //verifica se houve colisão (+-COLLISION_DETECTION_OFFSET para evitar sobreposição da bola com os blocos) if( (block->sprite->on_screen == true) && (abs(bola->x + bola->width) > block->sprite->x) && (abs(bola->x) < (block->sprite->x + block->sprite->width + COLLISION_DETECTION_OFFSET)) && ((bola->y + bola->height) > (block->sprite->y - COLLISION_DETECTION_OFFSET)) && (bola->y < (block->sprite->y + block->sprite->height)) ) { //determina o lado em que bateu a bola int dx = abs(block->sprite->x + block->sprite->width - bola->x); int dy = abs(bola->y + bola->height - block->sprite->y); //actualiza a velocidade da bola //Caso embata na nave considera apenas a parte da xpm que tem a nave if (block->nave == true) { if ((block->sprite->x < (block->sprite->width - NAVE_LEFT_OFFSET_IN_XPM - NAVE_RIGHT_OFFSET_IN_XPM)) //caso em que a nave esta do lado esquerdo || ((dx > NAVE_RIGHT_OFFSET_IN_XPM) && (abs(bola->x + bola->width - block->sprite->x)) > NAVE_LEFT_OFFSET_IN_XPM)) { if (dx > dy) { //bateu da parte de cima do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado direito do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&nave_hit); } } else { if (dx > dy) { //bateu da parte de cima do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado direito do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&block_hit); } animate_sprite(bola, VIDEO_BASE_ADDRESS); //apaga bloco se não for a nave if (block->nave == false) { //mili_sleep(5000); block->sprite->on_screen = false; delete_sprite(block->sprite, VIDEO_BASE_ADDRESS); //acrescenta à pontuação o valor do bloco pontuation += block->pontuation; //actualiza o numeros de blocos que já foram destruidos ++blocos_destruidos; } return 0; } } break; } case 3: { // bola a mover-se para SE (sodeste) for (i = 0; i < size_vec_blocos; ++i) { Bloco* block = (Bloco*)elementAtVector(vec_blocos, i); //verifica se houve colisão (+-COLLISION_DETECTION_OFFSET para evitar sobreposição da bola com os blocos) if( (block->sprite->on_screen == true) && (abs(bola->x + bola->width) > (block->sprite->x - COLLISION_DETECTION_OFFSET)) && (abs(bola->x) < (block->sprite->x + block->sprite->width)) && ((bola->y + bola->height) > (block->sprite->y - COLLISION_DETECTION_OFFSET)) && (bola->y < (block->sprite->y + block->sprite->height)) ) { //determina o lado em que bateu a bola int dx = abs(bola->x + bola->width - block->sprite->x); int dy = abs(bola->y + bola->height - block->sprite->y); //actualiza a velocidade da bola if (block->nave == true) { if ((block->sprite->x < (block->sprite->width - NAVE_LEFT_OFFSET_IN_XPM - NAVE_RIGHT_OFFSET_IN_XPM)) //caso em que a nave esta do lado esquerdo || ((dx > NAVE_LEFT_OFFSET_IN_XPM) && (abs(block->sprite->x + block->sprite->width - bola->x)) > NAVE_RIGHT_OFFSET_IN_XPM)) { if (dx > dy) { //bateu da parte de cima do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado esquerdo do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&nave_hit); } } else { if (dx > dy) { //bateu da parte de cima do bloco int new_yspeed = -bola->yspeed; bola->yspeed = new_yspeed; } else { //bateu do lado esquerdo do bloco int new_xspeed = -bola->xspeed; bola->xspeed = new_xspeed; } play_note(&block_hit); } animate_sprite(bola, VIDEO_BASE_ADDRESS); //apaga bloco se não for a nave if (block->nave == false) { //mili_sleep(5000); block->sprite->on_screen = false; delete_sprite(block->sprite, VIDEO_BASE_ADDRESS); //acrescenta à pontuação o valor do bloco pontuation += block->pontuation; //actualiza o numeros de blocos que já foram destruidos ++blocos_destruidos; } return 0; } } break; } } animate_sprite(bola, VIDEO_BASE_ADDRESS); if (blocos_destruidos == (sizeVector(vec_blocos) - 1)) return 1; else if (lives < 0) return 2; else return 0; }
int main(){ __dpmi_meminfo v_ram; char *bas = enter_graphics(MODE_640X480,&v_ram); create_static_sprite(gif_arkanoid,bas,280,240); delay(3*1000); create_static_sprite(novo_jogo, bas, 280, 240); //menu create_static_sprite(sair_jogo, bas, 280, 270); play_sound(10); //plays a sound delay(10*1000); leave_graphics(v_ram); enter_graphics(MODE_640X480,&v_ram); create_static_sprite(framev, bas, 0, 7); create_static_sprite(framev, bas, 633, 7); create_static_sprite(frameh, bas, 0, 0); create_static_sprite(frameh, bas, 0, 473); create_static_sprite(pic_brick1, bas, 580, 10); create_static_sprite(pic_brick2, bas, 540, 10); create_static_sprite(pic_brick3, bas, 500, 10); create_static_sprite(pic_brick4, bas, 460, 10); create_static_sprite(pic_brick1, bas, 420, 10); create_static_sprite(pic_brick2, bas, 380, 10); create_static_sprite(pic_brick3, bas, 340, 10); create_static_sprite(pic_brick4, bas, 300, 10); create_static_sprite(pic_brick1, bas, 260, 10); create_static_sprite(pic_brick2, bas, 220, 10); create_static_sprite(pic_brick3, bas, 180, 10); create_static_sprite(pic_brick4, bas, 140, 10); create_static_sprite(pic_brick1, bas, 100, 10); create_static_sprite(pic_brick2, bas, 60, 10); create_static_sprite(pic_brick3, bas, 20, 10); create_static_sprite(pic_brick4, bas, 580, 40); create_static_sprite(pic_brick1, bas, 540, 40); create_static_sprite(pic_brick2, bas, 500, 40); create_static_sprite(pic_brick3, bas, 460, 40); create_static_sprite(pic_brick4, bas, 420, 40); create_static_sprite(pic_brick1, bas, 380, 40); create_static_sprite(pic_brick2, bas, 340, 40); create_static_sprite(pic_brick3, bas, 300, 40); create_static_sprite(pic_brick4, bas, 260, 40); create_static_sprite(pic_brick1, bas, 220, 40); create_static_sprite(pic_brick2, bas, 180, 40); create_static_sprite(pic_brick3, bas, 140, 40); create_static_sprite(pic_brick4, bas, 100, 40); create_static_sprite(pic_brick1, bas, 60, 40); create_static_sprite(pic_brick2, bas, 20, 40); create_static_sprite(pic_brick3, bas, 580, 70); create_static_sprite(pic_brick4, bas, 540, 70); create_static_sprite(pic_brick1, bas, 500, 70); create_static_sprite(pic_brick2, bas, 460, 70); create_static_sprite(pic_brick3, bas, 420, 70); create_static_sprite(pic_brick4, bas, 380, 70); create_static_sprite(pic_brick1, bas, 340, 70); create_static_sprite(pic_brick2, bas, 300, 70); create_static_sprite(pic_brick3, bas, 260, 70); create_static_sprite(pic_brick4, bas, 220, 70); create_static_sprite(pic_brick1, bas, 180, 70); create_static_sprite(pic_brick2, bas, 140, 70); create_static_sprite(pic_brick3, bas, 100, 70); create_static_sprite(pic_brick4, bas, 60, 70); create_static_sprite(pic_brick1, bas, 20, 70); create_static_sprite(pic_brick2, bas, 580, 100); create_static_sprite(pic_brick3, bas, 540, 100); create_static_sprite(pic_brick4, bas, 500, 100); create_static_sprite(pic_brick1, bas, 460, 100); create_static_sprite(pic_brick2, bas, 420, 100); create_static_sprite(pic_brick3, bas, 380, 100); create_static_sprite(pic_brick4, bas, 340, 100); create_static_sprite(pic_brick1, bas, 300, 100); create_static_sprite(pic_brick2, bas, 260, 100); create_static_sprite(pic_brick3, bas, 220, 100); create_static_sprite(pic_brick4, bas, 180, 100); create_static_sprite(pic_brick1, bas, 140, 100); create_static_sprite(pic_brick2, bas, 100, 100); create_static_sprite(pic_brick3, bas, 60, 100); create_static_sprite(pic_brick4, bas, 20, 100); Sprite* bola = create_sprite_racket(pic_ball, bas); Sprite* raquete = create_sprite_racket(pic_racket, bas); play_sound(9); if(raquete == NULL) return 1; raquete->x = 271; raquete->y = 450; raquete->xspeed = 10; if(bola == NULL) return 1; bola->x = 320; bola->y = 440; bola->xspeed = 5; bola->yspeed = 5; set_kbd_isr(&prev_isr); while(1){ delete_sprite(bola, bas); delete_sprite(raquete, bas); unsigned char c = keyPress(); if(c==0x01) break; if(c==0x4d){ if(raquete->x + raquete->xspeed < 578) raquete->x = raquete->x +raquete->xspeed; }else if(c == 0x4b){ if(raquete->x + raquete->xspeed > 21) raquete->x = raquete->x - raquete->xspeed; } draw_sprite(raquete,bas); draw_sprite(bola, bas); move_ball(bola, raquete, bas); delay(50); } restore_isr(KBD_IRQ,& prev_isr); leave_graphics(v_ram); //sai do modo grafico return 0; }
int update_sprite(Sprite *sprite){ delete_sprite(sprite); animate_sprite(sprite, h_res, v_res); return 0; }
void destroy_duck(struct duck *duck) { elist_remove(&duck->link); delete_sprite(duck->sprite); }