72 lines
No EOL
1.3 KiB
C
72 lines
No EOL
1.3 KiB
C
#include <SDL/SDL.h>
|
|
#include <SDL/SDL_image.h>
|
|
#include <SDL/SDL_ttf.h>
|
|
#include "config.h"
|
|
#include "Engine.h"
|
|
#include "Catbug.h"
|
|
#include "Timer.h"
|
|
#include "Pickups.h"
|
|
#include "extern.h"
|
|
Catbug* newCatbug(int x, int y)
|
|
{
|
|
Catbug* self = malloc(sizeof(Catbug));
|
|
|
|
self->x = x;
|
|
self->y = y;
|
|
|
|
self->vX = 0;
|
|
self->vY = 0;
|
|
|
|
self->HP = STARTING_HP;
|
|
self->frame = 0;
|
|
self->spriteSheet=loadImage("assets/catbug.png");
|
|
|
|
return self;
|
|
}
|
|
|
|
void deleteCatbug(Catbug* target)
|
|
{
|
|
SDL_FreeSurface(target->spriteSheet);
|
|
free(target);
|
|
}
|
|
|
|
void moveCatbug(Catbug* self)
|
|
{
|
|
self->x += self->vX;
|
|
self->y += self->vY;
|
|
|
|
if (self->x <= 0 || self->x >= 320)
|
|
self->x -= self->vX;
|
|
if (self->y <=0 || self->y >= 180)
|
|
self->y -= self->vY;
|
|
}
|
|
|
|
void drawCatbug(Catbug* self)
|
|
{
|
|
SDL_Rect clip;
|
|
clip.x = 0;
|
|
clip.y = 0;
|
|
clip.w = 43;
|
|
clip.h = 39;
|
|
|
|
switch (self->frame)
|
|
{
|
|
case 0:
|
|
clip.x = 0;
|
|
self->frame = 1;
|
|
break;
|
|
case 1:
|
|
clip.x = 43;
|
|
self->frame = 0;
|
|
break;
|
|
}
|
|
applySurface(self->x - 22, self->y - 19, self->spriteSheet, screen, &clip);
|
|
}
|
|
|
|
int isInRect(Catbug* self, SDL_Rect* box)
|
|
{
|
|
if (self->x >= box->x && self->x <= box->x + box->w
|
|
&& self->y >= box->y && self->y <= box->y + box->h)
|
|
return 1;
|
|
else return 0;
|
|
} |