Skip to content
Snippets Groups Projects
Commit 29c97630 authored by belkhiritaha's avatar belkhiritaha
Browse files

speed + longueure du tir variable en fct de la durée du click

parent d60e9d6f
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ void ennemyHitBall(){
}
void manageEnnemy(){
if (SDL_GetTicks() % 1000 < 200)
if (SDL_GetTicks() % 1000 < 20)
{
manageEnnemyMovement();
}
......
......@@ -68,11 +68,11 @@ void gestGame()
}
if (event.motion.yrel > 0)
{
player.viewAngle -= 0.01 * RD;
player.viewAngle -= 0.05 * RD;
}
if (event.motion.yrel < 0)
{
player.viewAngle += 0.01 * RD;
player.viewAngle += 0.05 * RD;
}
player.deltax = cos(player.angle);
player.deltay = sin(player.angle);
......@@ -152,21 +152,20 @@ void gestGame()
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_LEFT)
{
if (player.isHitting)
{
player.isHitting = 0;
}
else
{
player.isHitting = 1;
}
player.isHoldingClick = 1;
player.startHitTimer = timer;
player.startHitBool = 0;
}
break;
case SDL_MOUSEBUTTONUP:
if (event.button.button == SDL_BUTTON_LEFT)
{
player.isHitting = 0;
player.endHitTimer = timer;
player.startHitBool = 1;
player.hitIntensity = (player.endHitTimer - player.startHitTimer) / 200;
player.isHoldingClick = 0;
}
break;
......
......@@ -9,6 +9,9 @@ int landingPointPlayerY = 0;
int lastHitPointPlayerX;
int lastHitPointPlayerY;
int rxWall, ryWall;
float distanceWall;
int landingPointPlayerIsFind = 0;
void initPlayer()
......@@ -25,19 +28,16 @@ void initPlayer()
ennemy.angle = -pi;
player.speed = 100;
player.isMoving = 0;
player.HPMax = 3;
player.currentHP = player.HPMax;
player.coins = 0;
player.angle = 0;
player.deltax = 1;
player.deltay = 0;
player.viewAngle = 0;
}
int generatelandingPointPlayer(int rxWall)
int generatelandingPointPlayer(int rxWall, float hitIntensity)
{
int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2));
int randomPointX = MAP_WIDTH/2 + hitIntensity * 5;
landingPointPlayerIsFind = 1;
landingPointEnnemyIsFind = 0;
......@@ -49,12 +49,10 @@ void hitBall()
{
if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE)
{
int rxWall, ryWall;
float distanceWall;
int rxNet, ryNet;
float distanceNet;
if (player.isHitting)
if (player.startHitBool)
{
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
// printf("hit\n");
......@@ -64,16 +62,18 @@ void hitBall()
//cherche et trouve point de chute, UNE SEULE FOIS!
if(landingPointPlayerIsFind == 0){
landingPointPlayerX = generatelandingPointPlayer(rxWall);
landingPointPlayerX = generatelandingPointPlayer(rxWall, player.hitIntensity);
lastHitPointPlayerX = ball.x;
lastHitPointPlayerY = player.h;
ball.angle = player.angle;
ball.speed = HIT_FORCE;
ball.speed = player.hitIntensity * 5;
ball.z = player.h;
ball.isHit = 1;
ball.isTravelingTo = AI;
player.startHitBool = 0;
}
}
......@@ -112,4 +112,5 @@ void managePlayer()
manageMovement();
hitBall();
updateBall();
player.hitIntensityTimer = timer - player.startHitTimer;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
#define HIT_RANGE 2
#define HIT_FORCE 2
#define MOVEMENT_SPEED 10
#define MAX_HIT_TIME 3
typedef struct player
{
......@@ -23,16 +24,18 @@ typedef struct player
int w;
int speed;
int isMoving;
int isHitting;
int startHitBool;
int isHit;
int direction;
int HPMax;
int currentHP;
int coins;
float angle;
float deltax;
float deltay;
float viewAngle;
float startHitTimer;
float endHitTimer;
float hitIntensity;
float hitIntensityTimer;
int isHoldingClick;
} player_t;
extern player_t player;
......@@ -44,6 +47,9 @@ extern int lastHitPointPlayerX;
extern int lastHitPointPlayerY;
extern int landingPointPlayerIsFind;
extern int rxWall;
int generatelandingPointPlayer(int rxWall, float hitIntensity);
void initPlayer();
void managePlayer();
void freeIntList(int *list);
......
#include "render.h"
float timer = 0;
SDL_Window *window;
SDL_Renderer *renderer;
......@@ -942,6 +944,16 @@ void drawString(char *str, int x, int y, int w, int h, int r, int g, int b, int
SDL_DestroyTexture(texture);
}
void drawHitIntensity(){
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
rect.w = screenDimension.w/20;
rect.x = screenDimension.w - rect.w;
//printf("%f\n", player.hitIntensityTimer);
rect.h = 2 * screenDimension.h/2 * ( player.hitIntensityTimer/1000);
rect.y = 3 * screenDimension.h/4 - rect.h;
SDL_RenderFillRect(renderer, &rect);
}
void drawFPS()
{
char str[10];
......@@ -1005,22 +1017,26 @@ void drawGame()
if (ball.x < MAP_WIDTH * BLOCK_SIZE / 2)
{
drawVerticalWalls();
drawEnnemy();
drawHorizentalWalls();
drawEnnemy();
drawVerticalNet();
drawBall();
}
else
{
drawVerticalWalls();
drawEnnemy();
drawHorizentalWalls();
drawEnnemy();
// todo bonus : draw point de chute de la balle
drawBall();
drawVerticalNet();
}
drawMap2D(map);
drawRacket();
if (player.isHoldingClick){
drawHitIntensity();
}
drawFPS();
// affiche le hub
if (showHub)
......@@ -1067,6 +1083,7 @@ void mainLoop()
if (delta > 1000 / FPS_TO_GET)
{
fps = 1000 / delta;
timer += delta;
b = a;
switch (game_state)
{
......
......@@ -35,8 +35,7 @@ extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_DisplayMode screenDimension;
extern int *ray1;
extern int *ray2;
extern float timer;
extern int showHub;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment