Требуется преобразование из int в нескалярный тип conts Vec2

Я новичок в C ++, и я пытаюсь сделать змею, но у меня есть проблема.

Строки ошибок:

C:\Users\Kcper\Desktop\Snej w allegro\main.cpp||In function 'void display_game()':|
C:\Users\Kcper\Desktop\Snej w allegro\main.cpp|58|warning: left operand of comma operator has no effect [-Wunused-value]|
C:\Users\Kcper\Desktop\Snej w allegro\main.cpp|58|error: conversion from 'int' to non-scalar type 'const Vec2' requested|

И вот код:

#include <allegro.h>
#include <winalleg.h>
#define TICS_PER_SECOND 50
#define MAX_FRAMESKIP 10
#define MAX_MENU_STATES 4
const int SKIP_TICKS = 1000 / TICS_PER_SECOND;

BITMAP * buffer;

struct Vec2
{
int x;
int y;
};

enum States
{
state_menu,
state_game,
state_continue,
state_exit,
state_leaderboard,
};

enum Positions
{
pos_game=30,
pos_continue=50,
pos_exit=70,
pos_leaderboard=90,
};

States menu(int *state)
{
int value;
if (keypressed())
{
value=readkey();
switch(value>>8)
{
case KEY_DOWN:
if(*state<MAX_MENU_STATES)(*state)++;
break;
case KEY_UP:
if(*state>1)(*state)--;
break;
case KEY_ENTER:
return States(*state);
}
}
return state_menu;
}

void display_game()
{
int color_zielony=makecol(0,255,0);
int color_czerwony=makecol(255,0,0);
const Vec2 ARENA_POSITION=(0,50); //<---- There is a problem
rect(buffer,ARENA_POSITION.x,ARENA_POSITION.y,SCREEN_H-1,SCREEN_W-1,color_czerwony);
textout_centre_ex(buffer,font,"Carrotz: ",SCREEN_W/2,SCREEN_H/2,color_zielony,0);
}

void display_menu(States state)
{
int color_bialy=makecol(255,255,255);
int color_czerwony=makecol(255,0,0);
int color_niebieski=makecol(0,0,255);
int color_zielony=makecol(0,255,0);

textout_centre_ex(buffer,font,"SNAKE by Kacper",SCREEN_W/2,10,color_niebieski,0);
textout_centre_ex(buffer,font,"New Game",SCREEN_W/2,30,color_bialy,2);
textout_centre_ex(buffer,font,"Leadrboard",SCREEN_W/2,70,color_bialy,2);
textout_centre_ex(buffer,font,"Continue",SCREEN_W/2,50,color_bialy,2);
textout_centre_ex(buffer,font,"Exit",SCREEN_W/2,90,color_czerwony,2);

int position;
switch(state)
{
case state_game:
position=pos_game;
break;
case state_continue:
position=pos_continue;
break;
case state_leaderboard:
position=pos_leaderboard;
break;
case state_exit:
position=pos_exit;
break;
}
rectfill(buffer,SCREEN_W/2-100,position,SCREEN_H-180,position+10,color_zielony);
}

inline void init()
{
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,760,480,0,0);

install_timer();
install_keyboard();
install_mouse();
}

inline void deinit()
{
destroy_bitmap(buffer);
clear_keybuf();
allegro_exit();
}

int main()
{
init();
States currentState=state_menu;
int currentMenuState=1;
int next_game_tick = GetTickCount();
int loops;
float interpolation;
buffer=create_bitmap (SCREEN_W,SCREEN_H);
while (!key[KEY_ESC])
{
loops=0;
while (GetTickCount()>next_game_tick&&loops<MAX_FRAMESKIP)
{
loops++;
next_game_tick+=SKIP_TICKS;
switch (currentState)
{
case state_menu:
currentState=menu(&currentMenuState);
break;
case state_game:
break;
}
}

clear(buffer);
switch (currentState)
{
case state_menu:
display_menu(States(currentMenuState));
break;
case state_game:
display_game();
break;
}
blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

}
deinit();
return 0;
}
END_OF_MAIN()

Так как я могу решить эту проблему?

0

Решение

const Vec2 ARENA_POSITION = (0, 50);

это не синтаксис для агрегатная инициализация. Это скорее в скобках оператор запятой, какие сбрасывает 0 (предупреждение о том, что операнд оператора запятой не имеет никакого эффекта) и пытается сделать

const Vec2 ARENA_POSITION = 50;

Правильный синтаксис является одним из двух:

const Vec2 ARENA_POSITION = {0, 50};
const Vec2 ARENA_POSITION{0, 50};
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector