view ppe/asteroid.cc @ 70:cee55c8365e9 default tip

fix
author Kazuma
date Thu, 19 May 2016 18:52:26 +0900
parents 21ac9f57a6d4
children
line wrap: on
line source

#include "task_base.h"
#include "task_object.h"

SchedDefineTask1(Asteroid, asteroid_task);

static int
asteroid_task(SchedTask *smanager, void *rbuf, void *wbuf)
{
    long asteroidi = (long)smanager->get_param(0);

    CHARACTER *p = (CHARACTER*)smanager->get_input(rbuf, 0);
    
    p->x += p->vx;
    p->y += p->vy;
    
    if (asteroidi > 0) {
	CHARACTER* asteroiddt = (CHARACTER*)smanager->get_input(rbuf, 1);

	for (int i = 0; i < asteroidi; i++) {
	    if ((asteroiddt[i].x + 32 > p->x)
		&& (p->x + 32 > asteroiddt[i].x)
		&& (asteroiddt[i].y + 32 > p->y)
		&& (asteroiddt[i].y < p->y + 32)) {
		p->vx *= -1;
		p->vy *= -1;
	    }
	}
    }
    CHARACTER *q = (CHARACTER*)smanager->get_output(wbuf, 0);

    *q = *p;
    return 0;
}